driver.f90
Go to the documentation of this file.
1 !> @file driver.f90
2 !!
3 !! The error file code for this file is ***W14***.
4 !! @brief Contains the main \ref driver routine
5 !!
6 #include "macros.h"
7 program driver
8 
9  use global_class, only: net_size
10  use winnse_module, only: pf
13  use nucstuff_class, only: el_ab
15  use gear_module, only: init_gear_solver
16  use parameter_class
19  use nuclear_heating
20  use readini
22  use hdf5_module
24  use timestep_module
25  use analysis
26  implicit none
27 
28  integer :: cnt !< Iteration count
29  character(max_fname_len) :: parameter_file !< Path to parameter file
30  character(max_fname_len) :: binary_out_dir !< Path to binary dir to safe the rates
31  logical :: init !< Flag to indicate whether the
32  ! time step has to be set to the
33  ! initial value.
34 
35 !---
36 ! Parameter setup
37 !---
38  if (iargc().eq.1) then
39  call getarg(1, parameter_file)
40  elseif (iargc().eq.2) then
41  call getarg(1, parameter_file)
42  call getarg(2, binary_out_dir)
43  ! If the binary_out_dir is given,
44  ! the code is in rate creation mode
45  ! and the print statements will be different
46  data_creation_mode = .true.
47  else
48  print '(A)', "ERROR: wrong number of command-line arguments"
49  print '(A)', "Syntax for network calculation: ./winnet <parameter-file>"
50  print '(A)', "Syntax for network data creation: ./winnet <parameter-file> <binary-out-dir>"
51  stop
52  endif
53 
54 
55  call set_default_param()
56  call read_param (trim(parameter_file))
57  call output_param()
58 
59 !---
60 ! Initializations
61 !---
62  if (iargc() .eq. 2) then
63  ! Dont use a prepared network when trying to prepare one
64  use_prepared_network = .false.
65  call create_rate_folder(trim(binary_out_dir))
66  ! Output final stats
68  ! Dont run the network
69  stop
70  else
71  init=.true. !! local variable, TODO: get rid of it
72  call prepare_simulation()
73  end if
74 
75 
76 
77 ! initial output
79 
80 !
81 ! --- MAIN EVOLUTION LOOP
82 !
83 
84  cnt = 0
85  evolution_loop: do while (evolution_mode.ne.em_terminate)
86 
87  !-- Select timestep
89 
90  !-- Compute the next step
91  ! switch between different solvers
92  select case (solver)
93  case (0) ! implicit Euler
94  call advance_implicit_euler(cnt)
95  case(1) ! Gear's method
96  call advance_gear(cnt)
97  case default
98  call raise_exception("Invalid solver. Choose either solver = 0 or 1.","driver",&
99  140003)
100  end select
101 
102  !-- Switch between modes
103  call switch_evolution_mode(init)
104 
105  !-- Rotate timelevels: save the 'previous step' quantities
106  call el_ab (y, ye)
108 
109  !-- Periodic output
110  call output_iteration(cnt+1,time,t9,rhob,ent,rkm,y,pf)
111 
112  ! rotate timelevels
113  y_p(1:net_size)= y(1:net_size)
114  ye_p= ye
115  ent_p= ent
116  t9_p= t9
117  t9h_p= t9h
118  cnt= cnt+1
119  time_p= time
120 
121 
122  end do evolution_loop
123 
124  ! output final step
125  call output_final_step(cnt,time,t9,rhob,ent,rkm,y,pf)
126 
127  ! decay to stability
128  call el_ab(y, ye)
129  ! call decay_init(Ye,T9,rhob)
130  ! write (*,'(A)',advance='no') 'Decaying to stable'
131  ! do i=1,40
132  ! call decay(Y)
133  ! call printsnap (t,T9,rhob,Y)
134  ! write (*,'(A)',advance='no') '.'
135  ! end do
136 
137  ! output final abundances
138 #ifndef USE_HDF5
139  call finab(y)
140 #else
141  if (.not. h_finab) then
142  call finab(y)
143  else
144  call write_finab(y)
145  endif
146 #endif
147 
148 
149  ! finalize modules
150  call readini_finalize()
151  call expansion_finalize()
152  call analysis_finalize()
153  call mergesort_finalize()
154 #ifdef USE_HDF5
155  call hdf5_module_finalize()
156 #endif
157  ! stop timing
158  call system_clock(cl_end)
159 
160  ! output final statistics
161  call output_final_stats(cnt,time)
162 
163  ! Keep the folder clean with as few files as possible.
164  ! If the code reaches this line here, no error has occured.
165  ! Therefore delete the error file.
166  call delete_io_file("ERR")
167 end program driver
timestep_module
The timestep_module contains all timestep subroutines and newton-raphsons to solve the ODE system.
Definition: timestep_module.f90:20
single_zone_vars::y
real(r_kind), dimension(:), allocatable y
Definition: single_zone_vars.f90:21
winnse_module::pf
real(r_kind), dimension(:), allocatable, public pf
Partition function for a given temperature.
Definition: winnse_module.f90:38
timestep_module::select_optimistic_timestep
subroutine, public select_optimistic_timestep(init)
Selects the timestep.
Definition: timestep_module.f90:489
winnse_module
Module to calculate NSE.
Definition: winnse_module.f90:34
hdf5_module
Module that contains necessary subroutines to write abundances to an hdf5 file.
Definition: hdf5_module.f90:24
parameter_class::use_prepared_network
logical use_prepared_network
Use a prepared folder with all necessary data in binary format.
Definition: parameter_class.f90:94
parameter_class::output_param
subroutine output_param
Output parameters to a file.
Definition: parameter_class.f90:1050
expansion_module::expansion_finalize
subroutine expansion_finalize()
Close debug files of the module.
Definition: expansion_module.f90:361
gear_module::init_gear_solver
subroutine, public init_gear_solver(Y, t_init, h_init)
Initialize iteration variables.
Definition: gear_module.f90:131
single_zone_vars::rhob
real(r_kind) rhob
Definition: single_zone_vars.f90:17
timestep_module::advance_implicit_euler
subroutine, public advance_implicit_euler(cnt)
Advance system to the next step for the implicit Euler method.
Definition: timestep_module.f90:628
single_zone_vars::t9
real(r_kind) t9
Definition: single_zone_vars.f90:15
nuclear_heating
Takes care of the temperature and entropy updates due to the nuclear energy release.
Definition: nuclear_heating.f90:11
single_zone_vars::rkm
real(r_kind) rkm
Definition: single_zone_vars.f90:18
readini::readini_finalize
subroutine, public readini_finalize()
Readini cleanup subroutine.
Definition: readini.f90:1415
analysis::output_iteration
subroutine, public output_iteration(cnt, ctime, T9, rho_b, entropy, Rkm, Y, pf)
Periodic output of analysis data for current iteration.
Definition: analysis.f90:309
analysis::output_final_step
subroutine, public output_final_step(cnt, ctime, T9, rho_b, entropy, Rkm, Y, pf)
Output final step.
Definition: analysis.f90:258
single_zone_vars::ent
real(r_kind) ent
Definition: single_zone_vars.f90:20
file_handling_class::delete_io_file
subroutine, public delete_io_file(file_name, raise_error)
Delete a file.
Definition: file_handling_class.f90:192
error_msg_class
Error handling routines.
Definition: error_msg_class.f90:16
expansion_module
Subroutines to handle parametric evolution of hydrodynamic quantities after the final timestep of the...
Definition: expansion_module.f90:16
single_zone_vars::t9h_p
real(r_kind) t9h_p
Temperature [GK] storage for heating mode 2.
Definition: single_zone_vars.f90:16
analysis::finab
subroutine, public finab(Y)
Compute final abundances and write final output.
Definition: analysis.f90:1878
parameter_class::read_param
subroutine read_param(parfile)
This function reads the parameter file.
Definition: parameter_class.f90:268
analysis::output_final_stats
subroutine, public output_final_stats(cnt, ctime)
Print final statistics.
Definition: analysis.f90:820
single_zone_vars::evolution_mode
integer evolution_mode
NSE, network hot/cold, etc.
Definition: single_zone_vars.f90:23
error_msg_class::raise_exception
subroutine, public raise_exception(msg, sub, error_code)
Raise a exception with a given error message.
Definition: error_msg_class.f90:245
network_init_module::switch_evolution_mode
subroutine, public switch_evolution_mode(init)
Switches between NSE and network modes (EM_NSE / EM_NETHOT / EM_NETCOLD)
Definition: network_init_module.f90:524
readini
Subroutines for initialization and parameter parsing.
Definition: readini.f90:15
network_init_module
Module to prepare the reaction network.
Definition: network_init_module.f90:22
parameter_class::h_finab
logical h_finab
Store the finab in hdf5 format rather than in ascii format.
Definition: parameter_class.f90:146
network_init_module::create_rate_folder
subroutine create_rate_folder(path)
Create a folder with binary files that contain all necessary reaction data.
Definition: network_init_module.f90:448
single_zone_vars::time_p
real(r_kind) time_p
Time.
Definition: single_zone_vars.f90:13
nucstuff_class
Module with helper functions such as rate tabulation, partition functions, and theoretical weak rates...
Definition: nucstuff_class.f90:11
mergesort_module::mergesort_finalize
subroutine, public mergesort_finalize()
Close files and finalize this module.
Definition: mergesort_module.f90:637
hdf5_module::write_finab
subroutine, public write_finab(Y)
Write final abundances into hdf5 file.
Definition: hdf5_module.f90:1217
error_msg_class::data_creation_mode
logical, public data_creation_mode
Flag for rate creation mode.
Definition: error_msg_class.f90:23
single_zone_vars::ent_p
real(r_kind) ent_p
Entropy [kB/baryon].
Definition: single_zone_vars.f90:20
error_msg_class::write_final_stats_rate_creation
subroutine, public write_final_stats_rate_creation
Write the final stats for rate creation.
Definition: error_msg_class.f90:98
parameter_class::solver
integer solver
solver flag (0 - implicit Euler, 1 - Gear's method, ...), is integer as it is faster than comparing s...
Definition: parameter_class.f90:147
nucstuff_class::el_ab
subroutine, public el_ab(Y, Ye)
Computes the electron fraction.
Definition: nucstuff_class.f90:219
analysis::cl_end
integer cl_end
Definition: analysis.f90:24
global_class::net_size
integer, public net_size
total number of isotopes (network size)
Definition: global_class.f90:93
file_handling_class
Provide some basic file-handling routines.
Definition: file_handling_class.f90:18
network_init_module::prepare_simulation
subroutine, public prepare_simulation
All the necessary initializations and settings before the main loop.
Definition: network_init_module.f90:166
analysis
Contains various routines for analysis and diagnostic output.
Definition: analysis.f90:9
single_zone_vars::time
real(r_kind) time
Definition: single_zone_vars.f90:13
single_zone_vars::stepsize
real(r_kind) stepsize
Stepsize.
Definition: single_zone_vars.f90:14
single_zone_vars::dydt
real(r_kind), dimension(:), allocatable dydt
Time derivative of the abundances.
Definition: single_zone_vars.f90:22
analysis::analysis_finalize
subroutine, public analysis_finalize()
Close files at the end of the calculation.
Definition: analysis.f90:2015
single_zone_vars::y_p
real(r_kind), dimension(:), allocatable y_p
Abundances.
Definition: single_zone_vars.f90:21
hdf5_module::hdf5_module_finalize
subroutine, public hdf5_module_finalize()
Finalize the hdf5 module.
Definition: hdf5_module.f90:2091
global_class
Contains types and objects shared between multiple modules.
Definition: global_class.f90:19
single_zone_vars::ye
real(r_kind) ye
Definition: single_zone_vars.f90:19
parameter_class::set_default_param
subroutine set_default_param
Sets default parameters Parameters are sorted in alphabetical order.
Definition: parameter_class.f90:881
mergesort_module
Module mergesort_module for merging arrays of rates.
Definition: mergesort_module.f90:16
single_zone_vars
Simulation variables for a single zone model.
Definition: single_zone_vars.f90:11
analysis::output_initial_step
subroutine, public output_initial_step(ctime, T9, rho_b, entropy, Rkm, Y, pf)
Output first step.
Definition: analysis.f90:233
timestep_module::advance_gear
subroutine, public advance_gear(cnt)
Advance system to the next step using the Gear method (using gear_module)
Definition: timestep_module.f90:820
gear_module
gear_module contains adaptive high-order Gear solver
Definition: gear_module.f90:37
driver
program driver
Definition: driver.f90:7
single_zone_vars::t9_p
real(r_kind) t9_p
Temperature [GK].
Definition: single_zone_vars.f90:15
parameter_class
Contains all runtime parameters as well as phys and math constants.
Definition: parameter_class.f90:24
single_zone_vars::ye_p
real(r_kind) ye_p
Electron fraction [mol/g].
Definition: single_zone_vars.f90:19
single_zone_vars::t9h
real(r_kind) t9h
Definition: single_zone_vars.f90:16