PB3D  [2.45]
Ideal linear high-n MHD stability in 3-D
PB3D.f90
Go to the documentation of this file.
1 ! (from http://patorjk.com/software/taag/ ANSI shadow)
2 
3 ! ██████╗ ██████╗ ██████╗ ██████╗
4 ! ██╔══██╗██╔══██╗╚════██╗██╔══██╗
5 ! ██████╔╝██████╔╝ █████╔╝██║ ██║
6 ! ██╔═══╝ ██╔══██╗ ╚═══██╗██║ ██║
7 ! ██║ ██████╔╝██████╔╝██████╔╝
8 ! ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝
9 
10 !------------------------------------------------------------------------------!
12 !------------------------------------------------------------------------------!
16 !------------------------------------------------------------------------------!
33 !------------------------------------------------------------------------------!
38 !------------------------------------------------------------------------------!
39 #define CHCKERR if(ierr.ne.0) then; call sudden_stop(ierr); end if
40 program pb3d
42  use str_utilities, only: r2str, i2str
43  use messages
44  use grid_vars, only: grid_type
45  use eq_vars, only: eq_1_type, eq_2_type
46  use x_vars, only: x_1_type, x_2_type
47  use vac_vars, only: vac_type
48  use sol_vars, only: sol_type
49  use hdf5_vars, only: init_hdf5
50  use driver_eq, only: run_driver_eq
51  use driver_x, only: run_driver_x
52  use driver_sol, only: run_driver_sol
56  use input_utilities, only: dealloc_in
59  use eq_utilities, only: do_eq, eq_info
62  use rich_vars, only: rich_info, &
63  &rich_lvl
64 #if ldebug
65  use num_vars, only: ltest
66  use test, only: generic_tests
67 #endif
68 
69  implicit none
70 
71  ! local variables
72  integer :: ierr ! error
73  type(grid_type), target :: grid_eq ! equilibrium grid
74  type(grid_type), pointer :: grid_eq_b => null() ! field-aligned equilibrium grid
75  type(grid_type), target :: grid_x ! perturbation grid
76  type(grid_type), pointer :: grid_x_b => null() ! field-aligned perturbation grid
77  type(grid_type) :: grid_sol ! solution grid
78  type(eq_1_type) :: eq_1 ! flux equilibrium variables
79  type(eq_2_type) :: eq_2 ! metric equilibrium variables
80  type(x_1_type) :: x_1 ! vectorial perturbation variables
81  type(x_2_type) :: x_2 ! integrated tensorial perturbation variables
82  type(vac_type) :: vac ! vacuum variables
83  type(sol_type) :: sol ! solution variables
84 
85  !------------------------------!
86  ! Initialize some routines !
87  !------------------------------!
88  ierr = start_mpi() ! start MPI
89  chckerr
90  prog_name = 'PB3D' ! program name
91  prog_style = 1 ! main part
92  call print_hello() ! print message with time, etc
93  call init_output() ! initialize output utilities
94  call init_files() ! initialize file operations
95  call init_time() ! initialize time
96  call init_hdf5() ! initialize HDF5
97 
98  !-----------------------------------------------------------------------!
99  ! Read the user-provided input file and the equilibrium code output !
100  !-----------------------------------------------------------------------!
101  call start_time
102  call writo('Initialization')
103  call lvl_ud(1)
104  if (rank.eq.0) then ! only master
105  ierr = parse_args() ! parse argument (options are used in open_input)
106  chckerr
107  ierr = open_input() ! open the input files
108  chckerr
109  ierr = read_input_opts() ! read input options file
110  chckerr
111  if (rich_restart_lvl.eq.1) then ! start at first level
112  ierr = read_input_eq() ! read input equilibrium file
113  chckerr
114  ierr = calc_normalization_const() ! set up normalization constants
115  chckerr
116  call normalize_input() ! normalize the input
117  ierr = open_output() ! open output file
118  chckerr
119  ierr = print_output_in('in') ! print input outputs
120  chckerr
121  call dealloc_in() ! clean up input from equilibrium codes
122  else ! restart at higher level
123  ierr = open_output() ! open output file
124  chckerr
125  end if
126  end if
127  ierr = broadcast_input_opts() ! broadcast input options to other processors
128  chckerr
129  call writo('')
130  call passed_time
131  call writo('')
132  call lvl_ud(-1)
133 
134 #if ldebug
135  !-------------------!
136  ! Do some tests !
137  !-------------------!
138  if (ltest) then
139  call start_time
140  call writo('Generic Tests')
141  call lvl_ud(1)
142  ierr = generic_tests() ! run generic test
143  chckerr
144  call writo('')
145  call passed_time
146  call writo('')
147  call lvl_ud(-1)
148  end if
149 #endif
150 
151  !----------------------------------------------!
152  ! Initialize Richardson Extrapolation Loop !
153  !----------------------------------------------!
154  call start_time
155  ierr = init_rich()
156  chckerr
157  call stop_time
158 
159  rich: do while(do_rich())
160  !----------------------------!
161  ! Start Richardson level !
162  !----------------------------!
163  call start_time
164  call writo('Richardson level '//trim(i2str(rich_lvl)))
165  call lvl_ud(1)
166  ierr = start_rich_lvl() ! start Richardson level, setting n_r_sol and other variables
167  chckerr
168  call stop_time
169  call writo('')
170  call lvl_ud(-1)
171 
172  par: do while(do_eq())
173  !-----------------------------------!
174  ! Main Driver: Equilibrium part !
175  !-----------------------------------!
176  call start_time
177  call writo('Equilibrium driver'//trim(rich_info())//&
178  &trim(eq_info()))
179  call lvl_ud(1)
180  ierr = run_driver_eq(grid_eq,grid_eq_b,eq_1,eq_2,vac) ! equilibrium driver
181  chckerr
182  call writo('')
183  call passed_time
184  call writo('')
185  call lvl_ud(-1)
186 
187  !------------------------------------!
188  ! Main driver: Perturbation part !
189  !------------------------------------!
190  call start_time
191  call writo('Perturbation driver'//trim(rich_info())//&
192  &trim(eq_info()))
193  call lvl_ud(1)
194  ierr = run_driver_x(grid_eq,grid_eq_b,grid_x,grid_x_b,eq_1,eq_2,&
195  &x_1,x_2) ! perturbation driver
196  chckerr
197  call writo('')
198  call passed_time
199  call writo('')
200  call lvl_ud(-1)
201  end do par
202 
203  !--------------------------------!
204  ! Main driver: Solution part !
205  !--------------------------------!
206  call start_time
207  call writo('Solution driver'//trim(rich_info()))
208  call lvl_ud(1)
209  ierr = run_driver_sol(grid_eq,grid_x,grid_sol,x_2,vac,sol) ! solution driver
210  chckerr
211  call writo('')
212  call passed_time
213  call writo('')
214  call lvl_ud(-1)
215 
216  call start_time
217  call stop_rich_lvl()
218  call stop_time
219  end do rich
220 
221  !---------------------------------------!
222  ! Stop Richarson Extrapolation Loop !
223  !---------------------------------------!
224  call start_time
225  call term_rich() ! stop Richardson loop
226  call stop_time
227 
228  !--------------!
229  ! Clean up !
230  !--------------!
231  call writo('Clean up')
232  call lvl_ud(1)
233  if (eq_style.eq.2) call eq_2%dealloc()
234  ierr = stop_mpi(grid_eq=grid_eq,&
235  &grid_eq_b=grid_eq_b,&
236  &grid_x=grid_x,&
237  &grid_x_b=grid_x_b,&
238  &grid_sol=grid_sol,&
239  &eq_1=eq_1,&
240  &eq_2=eq_2,&
241  &x_1=x_1,&
242  &x_2=x_2,&
243  &vac=vac,&
244  &sol=sol)
245  chckerr
246  call close_output
247  call lvl_ud(-1)
248 
249  call print_goodbye
250 end program pb3d
rich_vars::rich_info
elemental character(len=max_str_ln) function, public rich_info()
Returns string with possible extension with Richardson level or nothing if only one level and one par...
Definition: rich_vars.f90:35
mpi_ops::stop_mpi
integer function, public stop_mpi(grid_eq, grid_eq_B, grid_X, grid_X_B, grid_sol, eq_1, eq_2, X_1, X_2, vac, sol)
Stop MPI.
Definition: MPI_ops.f90:81
rich_ops::stop_rich_lvl
subroutine, public stop_rich_lvl()
Stop a Richardson level.
Definition: rich_ops.f90:405
eq_vars
Variables that have to do with equilibrium quantities and the grid used in the calculations:
Definition: eq_vars.f90:27
mpi_ops
Operations related to MPI.
Definition: MPI_ops.f90:4
num_vars
Numerical variables used by most other modules.
Definition: num_vars.f90:4
rich_ops::init_rich
integer function, public init_rich()
Initialize Richardson extrapolation system.
Definition: rich_ops.f90:28
driver_sol
Driver of the solution part of PB3D.
Definition: driver_sol.f90:4
rich_ops::start_rich_lvl
integer function, public start_rich_lvl()
Start a Richardson level.
Definition: rich_ops.f90:327
rich_vars
Variables concerning Richardson extrapolation.
Definition: rich_vars.f90:4
messages::passed_time
subroutine, public passed_time()
Display the time that has passed between t1 and t2.
Definition: messages.f90:152
str_utilities::i2str
elemental character(len=max_str_ln) function, public i2str(k)
Convert an integer to string.
Definition: str_utilities.f90:18
pb3d
program pb3d
Peeling Ballooning in 3D.
Definition: PB3D.f90:40
eq_ops::normalize_input
subroutine, public normalize_input()
Normalize input quantities.
Definition: eq_ops.f90:5643
messages::start_time
subroutine, public start_time()
Start a timer.
Definition: messages.f90:121
hdf5_vars
Variables pertaining to HDF5 and XDMF.
Definition: HDF5_vars.f90:4
messages::stop_time
subroutine, public stop_time()
Stop a timer.
Definition: messages.f90:132
files_ops::open_input
integer function, public open_input()
Open the input files.
Definition: files_ops.f90:178
str_utilities
Operations on strings.
Definition: str_utilities.f90:4
grid_vars::grid_type
Type for grids.
Definition: grid_vars.f90:59
rich_ops::term_rich
subroutine, public term_rich()
Terminate the Richardson extrapolation system.
Definition: rich_ops.f90:220
num_vars::prog_style
integer, public prog_style
program style (1: PB3D, 2: PB3D_POST)
Definition: num_vars.f90:53
num_vars::prog_name
character(len=4), public prog_name
name of program, used for info
Definition: num_vars.f90:54
eq_vars::eq_1_type
flux equilibrium type
Definition: eq_vars.f90:63
eq_utilities
Numerical utilities related to equilibrium variables.
Definition: eq_utilities.f90:4
num_vars::ltest
logical, public ltest
whether or not to call the testing routines
Definition: num_vars.f90:112
driver_x::run_driver_x
integer function, public run_driver_x(grid_eq, grid_eq_B, grid_X, grid_X_B, eq_1, eq_2, X_1, X_2)
Main driver of PB3D perturbation part.
Definition: driver_X.f90:59
vac_vars
Variables pertaining to the vacuum quantities.
Definition: vac_vars.f90:4
files_ops::parse_args
integer function, public parse_args()
Parses the command line arguments.
Definition: files_ops.f90:79
sol_vars::sol_type
solution type
Definition: sol_vars.f90:30
test
Generic tests.
Definition: test.f90:4
eq_ops::calc_normalization_const
integer function, public calc_normalization_const()
Sets up normalization constants.
Definition: eq_ops.f90:5405
files_ops::init_files
subroutine, public init_files()
Initialize the variables for the module.
Definition: files_ops.f90:25
hdf5_vars::init_hdf5
subroutine, public init_hdf5
Initializes the HDF5 types.
Definition: HDF5_vars.f90:82
rich_ops::do_rich
logical function, public do_rich()
Tests whether this Richardson level should be done.
Definition: rich_ops.f90:313
num_vars::rich_restart_lvl
integer, public rich_restart_lvl
starting Richardson level (0: none [default])
Definition: num_vars.f90:173
x_vars::x_2_type
tensorial perturbation type
Definition: X_vars.f90:81
eq_utilities::eq_info
elemental character(len=max_str_ln) function, public eq_info()
Returns string with possible extension with equilibrium job as well as parallel job,...
Definition: eq_utilities.f90:974
driver_eq
Driver of the equilibrium part of PB3D.
Definition: driver_eq.f90:4
num_vars::eq_style
integer, public eq_style
either 1 (VMEC) or 2 (HELENA)
Definition: num_vars.f90:89
x_vars
Variables pertaining to the perturbation quantities.
Definition: X_vars.f90:4
mpi_ops::start_mpi
integer function, public start_mpi()
Start MPI and gather information.
Definition: MPI_ops.f90:22
input_ops
Operations concerning giving input.
Definition: input_ops.f90:4
str_utilities::r2str
elemental character(len=max_str_ln) function, public r2str(k)
Convert a real (double) to string.
Definition: str_utilities.f90:42
messages::writo
subroutine, public writo(input_str, persistent, error, warning, alert)
Write output to file identified by output_i.
Definition: messages.f90:275
messages
Numerical utilities related to giving output.
Definition: messages.f90:4
input_ops::read_input_opts
integer function, public read_input_opts()
Reads input options from user-provided input file.
Definition: input_ops.f90:23
mpi_ops::broadcast_input_opts
integer function, public broadcast_input_opts()
Broadcasts options (e.g. user-prescribed) that are not passed through the HDF5 output file (i....
Definition: MPI_ops.f90:247
files_ops
Operations related to files !
Definition: files_ops.f90:4
vac_vars::vac_type
vacuum type
Definition: vac_vars.f90:46
messages::print_goodbye
subroutine, public print_goodbye()
Prints last messag.
Definition: messages.f90:99
input_ops::read_input_eq
integer function, public read_input_eq()
Reads the equilibrium input file if no Richardson restart.
Definition: input_ops.f90:1104
grid_vars
Variables pertaining to the different grids used.
Definition: grid_vars.f90:4
messages::lvl_ud
subroutine, public lvl_ud(inc)
Increases/decreases lvl of output.
Definition: messages.f90:254
files_ops::close_output
subroutine, public close_output()
Closes the output file.
Definition: files_ops.f90:703
mpi_ops::sudden_stop
subroutine, public sudden_stop(ierr)
Suddenly stops the computations, aborting MPI, etc.
Definition: MPI_ops.f90:483
driver_eq::run_driver_eq
integer function, public run_driver_eq(grid_eq_out, grid_eq_B_out, eq_1_out, eq_2_out, vac)
Main driver of PB3D equilibrium part.
Definition: driver_eq.f90:49
rich_vars::rich_lvl
integer, public rich_lvl
current level of Richardson extrapolation
Definition: rich_vars.f90:19
messages::init_time
subroutine, public init_time()
Intialize the time passed to 0.
Definition: messages.f90:113
x_vars::x_1_type
vectorial perturbation type
Definition: X_vars.f90:51
sol_vars
Variables pertaining to the solution quantities.
Definition: sol_vars.f90:4
eq_utilities::do_eq
logical function, public do_eq()
If this equilibrium job should be done, also increment eq_job_nr.
Definition: eq_utilities.f90:949
driver_sol::run_driver_sol
integer function, public run_driver_sol(grid_eq, grid_X, grid_sol, X, vac, sol)
Main driver of PB3D solution part.
Definition: driver_sol.f90:43
messages::init_output
subroutine, public init_output()
Initialize the variables for the module.
Definition: messages.f90:32
input_ops::print_output_in
integer function, public print_output_in(data_name, remove_previous_arrs)
Print input quantities to an output file.
Definition: input_ops.f90:1175
num_vars::rank
integer, public rank
MPI rank.
Definition: num_vars.f90:68
input_utilities::dealloc_in
subroutine, public dealloc_in()
Cleans up input from equilibrium codes.
Definition: input_utilities.f90:268
input_utilities
Numerical utilities related to input.
Definition: input_utilities.f90:4
test::generic_tests
integer function, public generic_tests()
Performs generic tests.
Definition: test.f90:39
files_ops::open_output
integer function, public open_output()
Open the output files.
Definition: files_ops.f90:529
eq_vars::eq_2_type
metric equilibrium type
Definition: eq_vars.f90:114
eq_ops
Operations on the equilibrium variables.
Definition: eq_ops.f90:4
rich_ops
Operations concerning Richardson extrapolation.
Definition: rich_ops.f90:4
driver_x
Driver of the perturbation part of PB3D.
Definition: driver_X.f90:4
messages::print_hello
subroutine, public print_hello()
Prints first message.
Definition: messages.f90:61