PB3D [2.47]
Ideal linear high-n MHD stability in 3-D
Loading...
Searching...
No Matches
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!------------------------------------------------------------------------------!
11!> Peeling Ballooning in 3D
12!------------------------------------------------------------------------------!
13!> \author
14!! Toon Weyens,
15!! Contact: weyenst@gmail.com
16!------------------------------------------------------------------------------!
17!> \version 2.41
18!! \date 2012-2020
19!! Copyright (C) 2020Toon Weyens
20!!
21!! This program is free software: you can redistribute it and/or modify
22!! it under the terms of the GNU General Public License as published by
23!! the Free Software Foundation, either version 3 of the License, or
24!! (at your option) any later version.
25!!
26!! This program is distributed in the hope that it will be useful,
27!! but WITHOUT ANY WARRANTY; without even the implied warranty of
28!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29!! GNU General Public License for more details.
30!!
31!! You should have received a copy of the License along with this program.
32!! If not, contact weyenst@gmail.com
33!------------------------------------------------------------------------------!
34!> \see
35!! References:
36!! \cite weyens2014theory
37!! \cite Weyens2017PB3D
38!------------------------------------------------------------------------------!
39#define CHCKERR if(ierr.ne.0) then; call sudden_stop(ierr); end if
40program 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
59 use eq_utilities, only: do_eq, eq_info
62 use rich_vars, only: rich_info, &
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
250end program pb3d
Driver of the equilibrium part of PB3D.
Definition driver_eq.f90:4
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
Driver of the solution part of PB3D.
Definition driver_sol.f90:4
integer function, public run_driver_sol(grid_eq, grid_x, grid_sol, x, vac, sol)
Main driver of PB3D solution part.
Driver of the perturbation part of PB3D.
Definition driver_X.f90:4
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
Operations on the equilibrium variables.
Definition eq_ops.f90:4
subroutine, public normalize_input()
Normalize input quantities.
Definition eq_ops.f90:5643
integer function, public calc_normalization_const()
Sets up normalization constants.
Definition eq_ops.f90:5405
Numerical utilities related to equilibrium variables.
elemental character(len=max_str_ln) function, public eq_info()
Returns string with possible extension with equilibrium job as well as parallel job,...
logical function, public do_eq()
If this equilibrium job should be done, also increment eq_job_nr.
Variables that have to do with equilibrium quantities and the grid used in the calculations:
Definition eq_vars.f90:27
Operations related to files !
Definition files_ops.f90:4
integer function, public parse_args()
Parses the command line arguments.
Definition files_ops.f90:79
subroutine, public init_files()
Initialize the variables for the module.
Definition files_ops.f90:25
subroutine, public close_output()
Closes the output file.
integer function, public open_input()
Open the input files.
integer function, public open_output()
Open the output files.
Variables pertaining to the different grids used.
Definition grid_vars.f90:4
Variables pertaining to HDF5 and XDMF.
Definition HDF5_vars.f90:4
subroutine, public init_hdf5
Initializes the HDF5 types.
Definition HDF5_vars.f90:82
Operations concerning giving input.
Definition input_ops.f90:4
integer function, public read_input_opts()
Reads input options from user-provided input file.
Definition input_ops.f90:23
integer function, public read_input_eq()
Reads the equilibrium input file if no Richardson restart.
integer function, public print_output_in(data_name, remove_previous_arrs)
Print input quantities to an output file.
Numerical utilities related to input.
subroutine, public dealloc_in()
Cleans up input from equilibrium codes.
Numerical utilities related to giving output.
Definition messages.f90:4
subroutine, public passed_time()
Display the time that has passed between t1 and t2.
Definition messages.f90:152
subroutine, public print_goodbye()
Prints last messag.
Definition messages.f90:99
subroutine, public init_output()
Initialize the variables for the module.
Definition messages.f90:32
subroutine, public print_hello()
Prints first message.
Definition messages.f90:61
subroutine, public lvl_ud(inc)
Increases/decreases lvl of output.
Definition messages.f90:254
subroutine, public start_time()
Start a timer.
Definition messages.f90:121
subroutine, public init_time()
Intialize the time passed to 0.
Definition messages.f90:113
subroutine, public writo(input_str, persistent, error, warning, alert)
Write output to file identified by output_i.
Definition messages.f90:275
subroutine, public stop_time()
Stop a timer.
Definition messages.f90:132
Operations related to MPI.
Definition MPI_ops.f90:4
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
subroutine, public sudden_stop(ierr)
Suddenly stops the computations, aborting MPI, etc.
Definition MPI_ops.f90:483
integer function, public start_mpi()
Start MPI and gather information.
Definition MPI_ops.f90:22
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
Numerical variables used by most other modules.
Definition num_vars.f90:4
logical, public ltest
whether or not to call the testing routines
Definition num_vars.f90:112
integer, public prog_style
program style (1: PB3D, 2: PB3D_POST)
Definition num_vars.f90:53
character(len=4), public prog_name
name of program, used for info
Definition num_vars.f90:54
integer, public eq_style
either 1 (VMEC) or 2 (HELENA)
Definition num_vars.f90:89
integer, public rank
MPI rank.
Definition num_vars.f90:68
integer, public rich_restart_lvl
starting Richardson level (0: none [default])
Definition num_vars.f90:173
Operations concerning Richardson extrapolation.
Definition rich_ops.f90:4
subroutine, public stop_rich_lvl()
Stop a Richardson level.
Definition rich_ops.f90:405
subroutine, public term_rich()
Terminate the Richardson extrapolation system.
Definition rich_ops.f90:220
logical function, public do_rich()
Tests whether this Richardson level should be done.
Definition rich_ops.f90:313
integer function, public start_rich_lvl()
Start a Richardson level.
Definition rich_ops.f90:327
integer function, public init_rich()
Initialize Richardson extrapolation system.
Definition rich_ops.f90:28
Variables concerning Richardson extrapolation.
Definition rich_vars.f90:4
integer, public rich_lvl
current level of Richardson extrapolation
Definition rich_vars.f90:19
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
Variables pertaining to the solution quantities.
Definition sol_vars.f90:4
Operations on strings.
elemental character(len=max_str_ln) function, public i2str(k)
Convert an integer to string.
elemental character(len=max_str_ln) function, public r2str(k)
Convert a real (double) to string.
Generic tests.
Definition test.f90:4
integer function, public generic_tests()
Performs generic tests.
Definition test.f90:39
Variables pertaining to the vacuum quantities.
Definition vac_vars.f90:4
Variables pertaining to the perturbation quantities.
Definition X_vars.f90:4
flux equilibrium type
Definition eq_vars.f90:63
metric equilibrium type
Definition eq_vars.f90:114
Type for grids.
Definition grid_vars.f90:59
solution type
Definition sol_vars.f90:30
vacuum type
Definition vac_vars.f90:46
vectorial perturbation type
Definition X_vars.f90:51
tensorial perturbation type
Definition X_vars.f90:81