PartMC  2.8.0
run_exact.F90
Go to the documentation of this file.
1 ! Copyright (C) 2005-2016 Nicole Riemer and Matthew West
2 ! Licensed under the GNU General Public License version 2 or (at your
3 ! option) any later version. See the file COPYING for details.
4 
5 !> \file
6 !> The pmc_run_exact module.
7 
8 !> Exact solution simulation.
10 
11  use pmc_aero_dist
12  use pmc_bin_grid
13  use pmc_aero_state
14  use pmc_scenario
15  use pmc_env_state
16  use pmc_aero_data
17  use pmc_output
18  use pmc_aero_binned
19  use pmc_gas_data
20  use pmc_gas_state
21  use pmc_exact_soln
22 
23  !> Options controlling the execution of run_exact().
25  !> Total simulation time.
26  real(kind=dp) :: t_max
27  !> Interval to output info (s).
28  real(kind=dp) :: t_output
29  !> Output prefix.
30  character(len=300) :: prefix
31  !> Whether to do coagulation.
32  logical :: do_coagulation
33  !> Type of coagulation kernel.
34  integer :: coag_kernel_type
35  !> UUID of the simulation.
36  character(len=PMC_UUID_LEN) :: uuid
37  end type run_exact_opt_t
38 
39 contains
40 
41 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
42 
43  !> Run an exact simulation.
44  subroutine run_exact(bin_grid, scenario, env_state, aero_data, &
45  aero_dist_init, gas_data, run_exact_opt)
46 
47  !> Bin grid.
48  type(bin_grid_t), intent(in) :: bin_grid
49  !> Environment data.
50  type(scenario_t), intent(in) :: scenario
51  !> Environment state.
52  type(env_state_t), intent(inout) :: env_state
53  !> Aerosol data.
54  type(aero_data_t), intent(in) :: aero_data
55  !> Initial aerosol distribution.
56  type(aero_dist_t), intent(in) :: aero_dist_init
57  !> Gas data.
58  type(gas_data_t), intent(in) :: gas_data
59  !> Options.
60  type(run_exact_opt_t), intent(in) :: run_exact_opt
61 
62  integer :: i_time, n_time, ncid
63  type(aero_binned_t) :: aero_binned
64  real(kind=dp) :: time
65  type(gas_state_t) :: gas_state
66 
67  call check_time_multiple("t_max", run_exact_opt%t_max, &
68  "t_output", run_exact_opt%t_output)
69 
70  call gas_state_set_size(gas_state, gas_data_n_spec(gas_data))
71 
72  n_time = nint(run_exact_opt%t_max / run_exact_opt%t_output)
73  do i_time = 0,n_time
74  time = real(i_time, kind=dp) / real(n_time, kind=dp) &
75  * run_exact_opt%t_max
76  call scenario_update_env_state(scenario, env_state, time)
77  call exact_soln(bin_grid, aero_data, run_exact_opt%do_coagulation, &
78  run_exact_opt%coag_kernel_type, aero_dist_init, scenario, &
79  env_state, time, aero_binned)
80  call output_sectional(run_exact_opt%prefix, bin_grid, aero_data, &
81  aero_binned, gas_data, gas_state, env_state, i_time + 1, &
82  time, run_exact_opt%t_output, run_exact_opt%uuid)
83  end do
84 
85  end subroutine run_exact
86 
87 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
88 
89  !> Read the specification for a run_exact simulation from a spec file.
90  subroutine spec_file_read_run_exact(file, run_exact_opt, aero_data, &
91  bin_grid, gas_data, env_state, aero_dist_init, scenario)
92 
93  !> Spec file.
94  type(spec_file_t), intent(inout) :: file
95  !> Options controlling the operation of run_exact().
96  type(run_exact_opt_t), intent(inout) :: run_exact_opt
97  !> Aerosol data.
98  type(aero_data_t), intent(out) :: aero_data
99  !> Bin grid.
100  type(bin_grid_t), intent(out) :: bin_grid
101  !> Initial aerosol state.
102  type(aero_dist_t), intent(out) :: aero_dist_init
103  !> Scenario data.
104  type(scenario_t), intent(out) :: scenario
105  !> Environmental state.
106  type(env_state_t), intent(out) :: env_state
107  !> Gas data.
108  type(gas_data_t), intent(out) :: gas_data
109 
110  character(len=PMC_MAX_FILENAME_LEN) :: sub_filename
111  type(spec_file_t) :: sub_file
112 
113  call spec_file_read_string(file, 'output_prefix', run_exact_opt%prefix)
114 
115  call spec_file_read_real(file, 't_max', run_exact_opt%t_max)
116  call spec_file_read_real(file, 't_output', run_exact_opt%t_output)
117 
118  call spec_file_read_radius_bin_grid(file, bin_grid)
119 
120  call spec_file_read_string(file, 'gas_data', sub_filename)
121  call spec_file_open(sub_filename, sub_file)
122  call spec_file_read_gas_data(sub_file, gas_data)
123  call spec_file_close(sub_file)
124 
125  call spec_file_read_string(file, 'aerosol_data', sub_filename)
126  call spec_file_open(sub_filename, sub_file)
127  call spec_file_read_aero_data(sub_file, aero_data)
128  call spec_file_close(sub_file)
129 
130  call spec_file_read_fractal(file, aero_data%fractal)
131 
132  call spec_file_read_string(file, 'aerosol_init', sub_filename)
133  call spec_file_open(sub_filename, sub_file)
134  call spec_file_read_aero_dist(sub_file, aero_data, .false., aero_dist_init)
135  call spec_file_close(sub_file)
136 
137  call spec_file_read_scenario(file, gas_data, aero_data, .false., scenario)
138  call spec_file_read_env_state(file, env_state)
139 
140  call spec_file_read_logical(file, 'do_coagulation', &
141  run_exact_opt%do_coagulation)
142  if (run_exact_opt%do_coagulation) then
143  call spec_file_read_coag_kernel_type(file, &
144  run_exact_opt%coag_kernel_type)
145  if (run_exact_opt%coag_kernel_type == coag_kernel_type_additive) then
146  call spec_file_read_real(file, 'additive_kernel_coeff', &
147  env_state%additive_kernel_coefficient)
148  end if
149  else
150  run_exact_opt%coag_kernel_type = coag_kernel_type_invalid
151  end if
152 
153  call spec_file_close(file)
154 
155  ! finished reading .spec data, now do the run
156 
157  call pmc_srand(0, 0)
158 
159  call uuid4_str(run_exact_opt%uuid)
160 
161  call scenario_init_env_state(scenario, env_state, 0d0)
162 
163  end subroutine spec_file_read_run_exact
164 
165 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
166 
167 end module pmc_run_exact
pmc_exact_soln::exact_soln
subroutine exact_soln(bin_grid, aero_data, do_coagulation, coag_kernel_type, aero_dist_init, scenario, env_state, time, aero_binned)
Definition: exact_soln.F90:31
pmc_gas_data::gas_data_t
Constant gas data.
Definition: gas_data.F90:35
pmc_exact_soln
Exact solutions for various simulations.
Definition: exact_soln.F90:9
pmc_spec_file::spec_file_close
subroutine spec_file_close(file)
Close a spec file.
Definition: spec_file.F90:135
pmc_gas_state::gas_state_set_size
subroutine gas_state_set_size(gas_state, n_spec)
Sets the sizes of the gas state.
Definition: gas_state.F90:56
pmc_scenario
The scenario_t structure and associated subroutines.
Definition: scenario.F90:9
pmc_scenario::scenario_t
Scenario data.
Definition: scenario.F90:54
pmc_gas_data
The gas_data_t structure and associated subroutines.
Definition: gas_data.F90:9
pmc_output::output_sectional
subroutine output_sectional(prefix, bin_grid, aero_data, aero_binned, gas_data, gas_state, env_state, index, time, del_t, uuid)
Write the current sectional data.
Definition: output.F90:665
pmc_constants::dp
integer, parameter dp
Kind of a double precision real number.
Definition: constants.F90:12
pmc_spec_file::spec_file_read_logical
subroutine spec_file_read_logical(file, name, var)
Read a logical from a spec file that must have a given name.
Definition: spec_file.F90:584
pmc_env_state::env_state_t
Current environment state.
Definition: env_state.F90:29
pmc_aero_state
The aero_state_t structure and assocated subroutines.
Definition: aero_state.F90:9
pmc_scenario::scenario_update_env_state
subroutine scenario_update_env_state(scenario, env_state, time)
Update time-dependent contents of the environment. scenario_init_env_state() should have been called ...
Definition: scenario.F90:134
pmc_spec_file::spec_file_t
An input file with extra data for printing messages.
Definition: spec_file.F90:59
pmc_rand::pmc_srand
subroutine pmc_srand(seed, offset)
Initializes the random number generator to the state defined by the given seed plus offset....
Definition: rand.F90:67
pmc_gas_state
The gas_state_t structure and associated subroutines.
Definition: gas_state.F90:9
pmc_spec_file::spec_file_read_real
subroutine spec_file_read_real(file, name, var)
Read a real number from a spec file that must have the given name.
Definition: spec_file.F90:563
pmc_util::check_time_multiple
subroutine check_time_multiple(first_name, first_time, second_name, second_time)
Check that the first time interval is close to an integer multiple of the second, and warn if it is n...
Definition: util.F90:377
pmc_aero_dist
The aero_dist_t structure and associated subroutines.
Definition: aero_dist.F90:18
pmc_spec_file::spec_file_open
subroutine spec_file_open(filename, file)
Open a spec file for reading.
Definition: spec_file.F90:112
pmc_env_state
The env_state_t structure and associated subroutines.
Definition: env_state.F90:9
pmc_run_exact::run_exact
subroutine run_exact(bin_grid, scenario, env_state, aero_data, aero_dist_init, gas_data, run_exact_opt)
Run an exact simulation.
Definition: run_exact.F90:46
pmc_gas_state::gas_state_t
Current state of the gas mixing ratios in the system.
Definition: gas_state.F90:33
pmc_rand::uuid4_str
subroutine uuid4_str(uuid)
Generate a version 4 UUID as a string.
Definition: rand.F90:661
pmc_aero_data::aero_data_t
Aerosol material properties and associated data.
Definition: aero_data.F90:55
pmc_output
Write data in NetCDF format.
Definition: output.F90:68
pmc_run_exact::run_exact_opt_t
Options controlling the execution of run_exact().
Definition: run_exact.F90:24
pmc_aero_dist::aero_dist_t
A complete aerosol distribution, consisting of several modes.
Definition: aero_dist.F90:33
pmc_run_exact::spec_file_read_run_exact
subroutine spec_file_read_run_exact(file, run_exact_opt, aero_data, bin_grid, gas_data, env_state, aero_dist_init, scenario)
Read the specification for a run_exact simulation from a spec file.
Definition: run_exact.F90:92
pmc_gas_data::gas_data_n_spec
elemental integer function gas_data_n_spec(gas_data)
Return the number of gas species.
Definition: gas_data.F90:109
pmc_scenario::scenario_init_env_state
subroutine scenario_init_env_state(scenario, env_state, time)
Initialize the time-dependent contents of the environment. Thereafter scenario_update_env_state() sho...
Definition: scenario.F90:111
pmc_aero_binned
The aero_binned_t structure and associated subroutines.
Definition: aero_binned.F90:9
pmc_spec_file::spec_file_read_string
subroutine spec_file_read_string(file, name, var)
Read a string from a spec file that must have a given name.
Definition: spec_file.F90:605
pmc_aero_binned::aero_binned_t
Aerosol number and volume distributions stored per bin.
Definition: aero_binned.F90:37
pmc_bin_grid
The bin_grid_t structure and associated subroutines.
Definition: bin_grid.F90:9
pmc_aero_data
The aero_data_t structure and associated subroutines.
Definition: aero_data.F90:9
pmc_bin_grid::bin_grid_t
1D grid, either logarithmic or linear.
Definition: bin_grid.F90:33
pmc_run_exact
Exact solution simulation.
Definition: run_exact.F90:9