PartMC  2.5.0
partmc.F90
Go to the documentation of this file.
1 ! Copyright (C) 2007-2012, 2016, 2017, 2018 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 partmc program.
7 
8 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9 
10 !> \mainpage PartMC Code Documentation
11 !!
12 !! \subpage input_format - Input file format description.
13 !!
14 !! \subpage output_format - Output file format description.
15 !!
16 !! \subpage module_diagram - Diagram of modules and dependencies.
17 !!
18 !! \subpage coding_style - Description of code conventions and style.
19 !!
20 !! \subpage publications - Publications about PartMC.
21 
22 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
23 
24 !> \page input_format Input File Format
25 !!
26 !! The input file format is plain text:
27 !!
28 !! \subpage spec_file_format "Spec File Format"
29 !!
30 !! When running PartMC with the command <tt>partmc input.spec</tt> the
31 !! first line of the <tt>input.spec</tt> file must define the \c
32 !! run_type with:
33 !! <pre>
34 !! run_type &lt;type&gt;
35 !! </pre>
36 !! where <tt>&lt;type&gt;</tt> is one of \c particle, \c exact, or \c
37 !! sectional. This determines the type of run as well as the format of the
38 !! remainder of the spec file. The rest of the spec file is described by:
39 !!
40 !! \subpage input_format_particle "Particle-resolved simulation"
41 !!
42 !! \subpage input_format_exact "Exact (analytical) solution"
43 !!
44 !! \subpage input_format_sectional "Sectional model simulation"
45 
46 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
47 
48 !> \page module_diagram Module Diagram
49 !!
50 !! \dotfile partmc_modules.gv
51 
52 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
53 
54 !> \page coding_style Coding Style
55 !!
56 !! The code is mainly modern Fortran, with a few parts still clearly
57 !! showing their Fortran 77 heritage. Fortran 2003 features are used
58 !! heavily (especially allocatable array features). The code needs to
59 !! be processed with \c cpp or a compatible pre-processor.
60 !!
61 !! \section oo_fortran Object Oriented Fortran
62 !!
63 !! Extensive use is made of Fortran 90 derived types. Derived types
64 !! are named \c my_type_t and are generally defined in modules named
65 !! \c pmc_my_type within files named \c my_type.F90. Almost all
66 !! subroutines and function in each \c my_type.F90 file have names of
67 !! the form \c my_type_*() and take an object of type \c my_type_t
68 !! (called \c my_type) as the first argument on which to operate.
69 !!
70 !! Module names are always the same as the name of the containing
71 !! file, but prefixed with \c pmc_. Thus the module \c
72 !! pmc_condense is contained in the file \c condense.F90.
73 !!
74 !! \section mem_manage Memory Management
75 !!
76 !! The memory allocation policy to is to always use \c allocatable
77 !! arrays and to do the allocation in the lowest-level routine
78 !! possible. Explicit \c allocate() and \c deallocate() statements are
79 !! discouraged in favor of automatic memory management, where
80 !! possible.
81 
82 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
83 
84 !> \page publications PartMC Publications
85 !!
86 !! - M.&nbsp;Hughes, J.&nbsp;K.&nbsp;Kodros, J.&nbsp;R.&nbsp;Pierce,
87 !! M.&nbsp;West, and N.&nbsp;Riemer (2018) Machine learning to
88 !! predict the global distribution of aerosol mixing state
89 !! metrics, <i>Atmosphere</i> <b>9</b>(1), 15, DOI: <a
90 !! href="http://dx.doi.org/10.3390/atmos9010015">10.3390/atmos9010015</a>.
91 !! - J.&nbsp;Ching, M.&nbsp;West, and N.&nbsp;Riemer (2018)
92 !! Quantifying impacts of aerosol mixing state on
93 !! nucleation-scavenging of black carbon aerosol particles,
94 !! <i>Atmosphere</i> <b>9</b>(1), 17, DOI: <a
95 !! href="http://dx.doi.org/10.3390/atmos9010017">10.3390/atmos9010017</a>.
96 !! - J.&nbsp;H.&nbsp;Curtis, N.&nbsp;Riemer, and M.&nbsp;West,
97 !! (2017) A single-column particle-resolved model for simulating
98 !! the vertical distribution of aerosol mixing state:
99 !! WRF-PartMC-MOSAIC-SCM v1.0, <i>Geoscientific Model
100 !! Development</i> <b>10</b>, 4057-4079, DOI: <a
101 !! href="http://dx.doi.org/10.5194/gmd-10-4057-2017">10.5194/gmd-10-4057-2017</a>.
102 !! - J.&nbsp;Tian, B.&nbsp;T.&nbsp;Brem, M.&nbsp;West,
103 !! T.&nbsp;C.&nbsp;Bond, M.&nbsp;J.&nbsp;Rood, and N.&nbsp;Riemer
104 !! (2017) Simulating aerosol chamber experiments with the
105 !! particle-resolved aerosol model PartMC, <i>Aerosol Science and
106 !! Technology</i> <b>51</b>(7), 856-867, DOI: <a
107 !! href="http://dx.doi.org/10.1080/02786826.2017.1311988">10.1080/02786826.2017.1311988</a>.
108 !! - J.&nbsp;Ching, J.&nbsp;Fast, M.&nbsp;West, and N.&nbsp;Riemer
109 !! (2017) Metrics to quantify the importance of mixing state for
110 !! CCN activity, <i>Atmospheric Chemistry and Physics</i>
111 !! <b>17</b>, 7445-7458, DOI: <a
112 !! href="http://dx.doi.org/10.5194/acp-17-7445-2017">10.5194/acp-17-7445-2017</a>.
113 !! - J.&nbsp;Ching, N.&nbsp;Riemer, and M.&nbsp;West (2016) Black
114 !! carbon mixing state impacts on cloud microphysical properties:
115 !! Effects of aerosol plume and environmental conditions,
116 !! <i>Journal of Geophysical Research</i> <b>121</b>(10),
117 !! 5990-6013, DOI: <a
118 !! href="http://dx.doi.org/10.1002/2016JD024851">10.1002/2016JD024851</a>.
119 !! - J.&nbsp;H.&nbsp;Curtis, M.&nbsp;D.&nbsp;Michelotti,
120 !! N.&nbsp;Riemer, M.&nbsp;Heath, and M.&nbsp;West (2016)
121 !! Accelerated simulation of stochastic particle removal processes
122 !! in particle-resolved aerosol models, <i>Journal of
123 !! Computational Physics</i> <b>322</b>, 21-32, DOI: <a
124 !! href="http://dx.doi.org/10.1016/j.jcp.2016.06.029">10.1016/j.jcp.2016.06.029</a>.
125 !! - R.&nbsp;M.&nbsp;Healy, N.&nbsp;Riemer, J.&nbsp;C.&nbsp;Wenger,
126 !! M.&nbsp;Murphy, M.&nbsp;West, L.&nbsp;Poulain,
127 !! A.&nbsp;Wiedensohler, I.&nbsp;P.&nbsp;O'Connor,
128 !! E.&nbsp;McGillicuddy, J.&nbsp;R.&nbsp;Sodeau, and
129 !! G.&nbsp;J.&nbsp;Evans, Single particle diversity and mixing
130 !! state measurements, <i>Atmospheric Chemistry and Physics</i>
131 !! <b>14</b>, 6289-6299, DOI: <a
132 !! href="http://dx.doi.org/10.5194/acp-14-6289-2014">10.5194/acp-14-6289-2014</a>.
133 !! - J.&nbsp;Tian, N.&nbsp;Riemer, M.&nbsp;West,
134 !! L.&nbsp;Pfaffenberger, H.&nbsp;Schlager, and A.&nbsp;Petzold
135 !! (2014) Modeling the evolution of aerosol particles in a ship
136 !! plume using PartMC-MOSAIC, <i>Atmospheric Chemistry and
137 !! Physics</i> <b>14</b>, 5327-5347, DOI: <a
138 !! href="http://dx.doi.org/10.5194/acp-14-5327-2014">10.5194/acp-14-5327-2014</a>.
139 !! - N.&nbsp;Riemer and M.&nbsp;West (2013) Quantifying aerosol mixing
140 !! state with entropy and diversity measures, <i>Atmospheric
141 !! Chemistry and Physics</i> <b>13</b>, 11423-11439, DOI: <a
142 !! href="http://dx.doi.org/10.5194/acp-13-11423-2013">10.5194/acp-13-11423-2013</a>.
143 !! - M.&nbsp;D.&nbsp;Michelotti, M.&nbsp;T.&nbsp;Heath, and
144 !! M.&nbsp;West (2013) Binning for efficient stochastic multiscale
145 !! particle simulations, <i>Atmospheric Chemistry and Physics</i>
146 !! <b>11</b>(4), 1071-1096, DOI: <a
147 !! href="http://dx.doi.org/10.1137/130908038">10.1137/130908038</a>.
148 !! - J.&nbsp;Ching, N.&nbsp;Riemer, and M.&nbsp;West (2012) Impacts of
149 !! black carbon mixing state on black carbon nucleation scavenging:
150 !! Insights from a particle-resolved model, <i>Journal of
151 !! Geophysical Research</i> <b>117</b>(D23209), DOI: <a
152 !! href="http://dx.doi.org/10.1029/2012JD018269">10.1029/2012JD018269</a>.
153 !! - R.&nbsp;E.&nbsp;L.&nbsp;DeVille, N.&nbsp;Riemer, and
154 !! M.&nbsp;West (2011) Weighted Flow Algorithms (WFA) for
155 !! stochastic particle coagulation, <i>Journal of Computational
156 !! Physics</i> <b>230</b>(23), 8427-8451, DOI: <a
157 !! href="http://dx.doi.org/10.1016/j.jcp.2011.07.027">10.1016/j.jcp.2011.07.027</a>.
158 !! - R.&nbsp;A.&nbsp;Zaveri, J.&nbsp;C.&nbsp;Barnard,
159 !! R.&nbsp;C.&nbsp;Easter, N.&nbsp;Riemer, and M.&nbsp;West (2010)
160 !! Particle-resolved simulation of aerosol size, composition,
161 !! mixing state, and the associated optical and cloud condensation
162 !! nuclei activation properties in an evolving urban plume,
163 !! <i>Journal of Geophysical Research</i> <b>115</b>(D17210), DOI: <a
164 !! href="http://dx.doi.org/10.1029/2009JD013616">10.1029/2009JD013616</a>.
165 !! - N.&nbsp;Riemer, M.&nbsp;West, R.&nbsp;A.&nbsp;Zaveri, and
166 !! R.&nbsp;C.&nbsp;Easter (2010) Estimating black carbon aging
167 !! time-scales with a particle-resolved aerosol model, <i>Journal
168 !! of Aerosol Science</i> <b>41</b>(1), 143-158, DOI: <a
169 !! href="http://dx.doi.org/10.1016/j.jaerosci.2009.08.009">10.1016/j.jaerosci.2009.08.009</a>
170 !! - N.&nbsp;Riemer, M.&nbsp;West, R.&nbsp;A.&nbsp;Zaveri, and
171 !! R.&nbsp;C.&nbsp;Easter (2009) Simulating the evolution of soot
172 !! mixing state with a particle-resolved aerosol model, <i>Journal
173 !! of Geophysical Research</i> <b>114</b>(D09202), DOI: <a
174 !! href="http://dx.doi.org/10.1029/2008JD011073">10.1029/2008JD011073</a>
175 !! - R.&nbsp;McGraw, L.&nbsp;Leng, W.&nbsp;Zhu, N.&nbsp;Riemer, and
176 !! M.&nbsp;West (2008) Aerosol dynamics using the quadrature
177 !! method of moments: Comparing several quadrature schemes with
178 !! particle-resolved simulation, <i>Journal of Physics: Conference
179 !! Series</i> <b>125</b>(012020), DOI: <a
180 !! href="http://dx.doi.org/10.1088/1742-6596/125/1/012020">10.1088/1742-6596/125/1/012020</a>
181 
182 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
183 
184 !> Top level driver.
185 program partmc
186 
187  use pmc_mpi
188  use pmc_bin_grid
189  use pmc_aero_state
190  use pmc_aero_dist
191  use pmc_aero_binned
192  use pmc_coag_kernel
193  use pmc_aero_data
194  use pmc_scenario
195  use pmc_env_state
196  use pmc_run_part
197  use pmc_run_exact
198  use pmc_run_sect
199  use pmc_spec_file
200  use pmc_gas_data
201  use pmc_gas_state
202  use pmc_util
203 #ifdef PMC_USE_SUNDIALS
204  use pmc_condense
205 #endif
206 
207  character(len=300) :: spec_name
208 
209  call pmc_mpi_init()
210 
211  if (pmc_mpi_rank() == 0) then
212  ! only the root process accesses the commandline
213 
214  if (command_argument_count() /= 1) then
215  call print_usage()
216  call die_msg(739173192, "invalid commandline arguments")
217  end if
218 
219  call get_command_argument(1, spec_name)
220  end if
221 
222  call pmc_mpi_bcast_string(spec_name)
223  call partmc_run(spec_name)
224 
225  call pmc_mpi_finalize()
226 
227 contains
228 
229 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
230 
231  !> Print the usage text to stderr.
232  subroutine print_usage()
234  write(*,*) 'Usage: partmc <spec-file>'
235 
236  end subroutine print_usage
237 
238 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
239 
240  !> Do a PartMC run.
241  subroutine partmc_run(spec_name)
243  !> Spec filename.
244  character(len=*), intent(in) :: spec_name
245 
246  type(spec_file_t) :: file
247  character(len=100) :: run_type
248  integer :: i
249 
250  ! check filename (must be "filename.spec")
251  i = len_trim(spec_name)
252  if (spec_name((i-4):i) /= '.spec') then
253  call die_msg(710381938, "input filename must end in .spec")
254  end if
255 
256  if (pmc_mpi_rank() == 0) then
257  ! only the root process does I/O
258  call spec_file_open(spec_name, file)
259  call spec_file_read_string(file, 'run_type', run_type)
260  end if
261 
262  call pmc_mpi_bcast_string(run_type)
263  if (trim(run_type) == 'particle') then
264  call partmc_part(file)
265  elseif (trim(run_type) == 'exact') then
266  call partmc_exact(file)
267  elseif (trim(run_type) == 'sectional') then
268  call partmc_sect(file)
269  else
270  call die_msg(719261940, "unknown run_type: " // trim(run_type))
271  end if
272 
273  end subroutine partmc_run
274 
275 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
276 
277  !> Run a Monte Carlo simulation.
278  subroutine partmc_part(file)
279 
280  !> Spec file.
281  type(spec_file_t), intent(inout) :: file
282 
283  type(gas_data_t) :: gas_data
284  type(gas_state_t) :: gas_state
285  type(gas_state_t) :: gas_state_init
286  type(aero_data_t) :: aero_data
287  type(aero_dist_t) :: aero_dist_init
288  type(aero_state_t) :: aero_state
289  type(aero_state_t) :: aero_state_init
290  type(scenario_t) :: scenario
291  type(env_state_t) :: env_state
292  type(env_state_t) :: env_state_init
293  type(run_part_opt_t) :: run_part_opt
294  integer :: i_repeat, i_group
295  integer :: rand_init
296  character, allocatable :: buffer(:)
297  integer :: buffer_size, max_buffer_size
298  integer :: position
299  logical :: do_restart, do_init_equilibriate, aero_mode_type_exp_present
300  character(len=PMC_MAX_FILENAME_LEN) :: restart_filename
301  integer :: dummy_index, dummy_i_repeat
302  real(kind=dp) :: dummy_time, dummy_del_t, n_part
303  character(len=PMC_MAX_FILENAME_LEN) :: sub_filename
304  type(spec_file_t) :: sub_file
305 
306  !> \page input_format_particle Input File Format: Particle-Resolved Simulation
307  !!
308  !! See \ref spec_file_format for the input file text format.
309  !!
310  !! A particle-resolved simulation spec file has the parameters:
311  !! - \b run_type (string): must be \c particle
312  !! - \b output_prefix (string): prefix of the output filenames
313  !! --- see \ref output_format for the full name format
314  !! - \b n_repeat (integer): number of repeats
315  !! - \b n_part (integer): number of computational particles to
316  !! simulate (actual number used will vary between <tt>n_part /
317  !! 2</tt> and <tt>n_part * 2</tt> if \c allow_doubling and \c
318  !! allow_halving are \c yes)
319  !! - \b restart (logical): whether to restart the simulation from
320  !! a saved output data file. If \c restart is \c yes, then the
321  !! following parameters must also be provided:
322  !! - \b restart_file (string): name of file from which to load
323  !! restart data, which must be a PartMC output NetCDF file
324  !! - \b t_max (real, unit s): total simulation time
325  !! - \b del_t (real, unit s): timestep size
326  !! - \b t_output (real, unit s): the interval on which to
327  !! output data to disk (see \ref output_format)
328  !! - \b t_progress (real, unit s): the interval on which to
329  !! write summary information to the screen while running
330  !! - \b gas_data (string): name of file from which to read the gas
331  !! material data (only provide if \c restart is \c no) --- the
332  !! file format should be \subpage input_format_gas_data
333  !! - \b gas_init (string): name of file from which to read the
334  !! initial gas state at the start of the simulation (only
335  !! provide option if \c restart is \c no) --- the file format
336  !! should be \subpage input_format_gas_state
337  !! - \b aerosol_data (string): name of file from which to read the
338  !! aerosol material data (only provide if \c restart is \c no)
339  !! --- the file format should be \subpage input_format_aero_data
340  !! - \b do_fractal (logical): whether to consider particles
341  !! as fractal agglomerates. If \c do_fractal is \c no, then all the
342  !! particles are treated as spherical. If \c do_fractal is \c yes,
343  !! then the following parameters must also be provided:
344  !! - \subpage input_format_fractal
345  !! - \b aerosol_init (string): filename containing the initial
346  !! aerosol state at the start of the simulation (only provide
347  !! option if \c restart is \c no) --- the file format should
348  !! be \subpage input_format_aero_dist
349  !! - \subpage input_format_scenario
350  !! - \subpage input_format_env_state
351  !! - \b do_coagulation (logical): whether to perform particle
352  !! coagulation. If \c do_coagulation is \c yes, then the
353  !! following parameters must also be provided:
354  !! - \subpage input_format_coag_kernel
355  !! - \b do_condensation (logical): whether to perform explicit
356  !! water condensation (requires SUNDIALS support to be compiled
357  !! in; cannot be used simultaneously with MOSAIC). If \c
358  !! do_condensation is \c yes, then the following parameters must
359  !! also be provided:
360  !! - \b do_init_equilibriate (logical): whether to equilibriate
361  !! the water content of each particle before starting the
362  !! simulation
363  !! - \b do_mosaic (logical): whether to use the MOSAIC chemistry
364  !! code (requires support to be compiled in; cannot be used
365  !! simultaneously with condensation). If \c do_mosaic is \c
366  !! yes, then the following parameters must also be provided:
367  !! - \b do_optical (logical): whether to compute optical
368  !! properties of the aersol particles for the output files ---
369  !! see output_format_aero_state
370  !! - \b do_nucleation (logical): whether to perform particle
371  !! nucleation. If \c do_nucleation is \c yes, then the following
372  !! parameters must also be provided:
373  !! - \subpage input_format_nucleate
374  !! - \b rand_init (integer): if greater than zero then use as
375  !! the seed for the random number generator, or if zero then
376  !! generate a random seed for the random number generator ---
377  !! two simulations on the same machine with the same seed
378  !! (greater than 0) will produce identical output
379  !! - \b allow_doubling (logical): if \c yes, then whenever the
380  !! number of simulated particles falls below <tt>n_part /
381  !! 2</tt>, every particle is duplicated to give better
382  !! statistics
383  !! - \b allow_halving (logical): if \c yes, then whenever the
384  !! number of simulated particles rises above <tt>n_part *
385  !! 2</tt>, half of the particles are removed (chosen randomly)
386  !! to reduce the computational expense
387  !! - \b do_select_weighting (logical): whether to explicitly select
388  !! the weighting scheme. If \c do_select_weighting is \c yes, then the
389  !! following parameters must also be provided:
390  !! - \subpage input_format_weight_type
391  !! - \b record_removals (logical): whether to record information
392  !! about aerosol particles removed from the simulation --- see
393  !! \ref output_format_aero_removed
394  !! - \b do_parallel (logical): whether to run in parallel mode
395  !! (requires MPI support to be compiled in). If \c do_parallel
396  !! is \c yes, then the following parameters must also be
397  !! provided:
398  !! - \subpage input_format_output
399  !! - \b mix_timescale (real, unit s): timescale on which to mix
400  !! aerosol particle information amongst processes in an
401  !! attempt to keep the aerosol state consistent (the mixing
402  !! rate is inverse to \c mix_timescale)
403  !! - \b gas_average (logical): whether to average the gas state
404  !! amongst processes each timestep, to ensure uniform gas
405  !! concentrations
406  !! - \b env_average (logical): whether to average the
407  !! environment state amongst processes each timestep, to
408  !! ensure a uniform environment
409  !! - \subpage input_format_parallel_coag
410 
411  if (pmc_mpi_rank() == 0) then
412  ! only the root process does I/O
413 
414  call spec_file_read_string(file, 'output_prefix', &
415  run_part_opt%output_prefix)
416  call spec_file_read_integer(file, 'n_repeat', run_part_opt%n_repeat)
417  call spec_file_read_real(file, 'n_part', n_part)
418  call spec_file_read_logical(file, 'restart', do_restart)
419  if (do_restart) then
420  call spec_file_read_string(file, 'restart_file', restart_filename)
421  end if
422 
423  call spec_file_read_real(file, 't_max', run_part_opt%t_max)
424  call spec_file_read_real(file, 'del_t', run_part_opt%del_t)
425  call spec_file_read_real(file, 't_output', run_part_opt%t_output)
426  call spec_file_read_real(file, 't_progress', run_part_opt%t_progress)
427 
428  if (do_restart) then
429  call input_state(restart_filename, dummy_index, dummy_time, &
430  dummy_del_t, dummy_i_repeat, run_part_opt%uuid, aero_data, &
431  aero_state_init, gas_data, gas_state_init, env_state_init)
432  end if
433 
434  if (.not. do_restart) then
435  env_state_init%elapsed_time = 0d0
436 
437  call spec_file_read_string(file, 'gas_data', sub_filename)
438  call spec_file_open(sub_filename, sub_file)
439  call spec_file_read_gas_data(sub_file, gas_data)
440  call spec_file_close(sub_file)
441 
442  call spec_file_read_string(file, 'gas_init', sub_filename)
443  call spec_file_open(sub_filename, sub_file)
444  call spec_file_read_gas_state(sub_file, gas_data, &
445  gas_state_init)
446  call spec_file_close(sub_file)
447 
448  call spec_file_read_string(file, 'aerosol_data', sub_filename)
449  call spec_file_open(sub_filename, sub_file)
450  call spec_file_read_aero_data(sub_file, aero_data)
451  call spec_file_close(sub_file)
452 
453  call spec_file_read_fractal(file, aero_data%fractal)
454 
455  call spec_file_read_string(file, 'aerosol_init', sub_filename)
456  call spec_file_open(sub_filename, sub_file)
457  call spec_file_read_aero_dist(sub_file, aero_data, aero_dist_init)
458  call spec_file_close(sub_file)
459  end if
460 
461  call spec_file_read_scenario(file, gas_data, aero_data, scenario)
462  call spec_file_read_env_state(file, env_state_init)
463 
464  call spec_file_read_logical(file, 'do_coagulation', &
465  run_part_opt%do_coagulation)
466  if (run_part_opt%do_coagulation) then
467  call spec_file_read_coag_kernel_type(file, &
468  run_part_opt%coag_kernel_type)
469  else
470  run_part_opt%coag_kernel_type = coag_kernel_type_invalid
471  end if
472 
473  call spec_file_read_logical(file, 'do_condensation', &
474  run_part_opt%do_condensation)
475 #ifndef PMC_USE_SUNDIALS
476  call assert_msg(121370218, &
477  run_part_opt%do_condensation .eqv. .false., &
478  "cannot use condensation, SUNDIALS support is not compiled in")
479 #endif
480  if (run_part_opt%do_condensation) then
481  call spec_file_read_logical(file, 'do_init_equilibriate', &
482  do_init_equilibriate)
483  else
484  do_init_equilibriate = .false.
485  end if
486 
487  call spec_file_read_logical(file, 'do_mosaic', run_part_opt%do_mosaic)
488  if (run_part_opt%do_mosaic .and. (.not. mosaic_support())) then
489  call spec_file_die_msg(230495365, file, &
490  'cannot use MOSAIC, support is not compiled in')
491  end if
492  if (run_part_opt%do_mosaic .and. run_part_opt%do_condensation) then
493  call spec_file_die_msg(599877804, file, &
494  'cannot use MOSAIC and condensation simultaneously')
495  end if
496  if (run_part_opt%do_mosaic) then
497  call spec_file_read_logical(file, 'do_optical', &
498  run_part_opt%do_optical)
499  else
500  run_part_opt%do_optical = .false.
501  end if
502 
503  call spec_file_read_logical(file, 'do_nucleation', &
504  run_part_opt%do_nucleation)
505  if (run_part_opt%do_nucleation) then
506  call spec_file_read_nucleate_type(file, aero_data, &
507  run_part_opt%nucleate_type, run_part_opt%nucleate_source)
508  else
509  run_part_opt%nucleate_type = nucleate_type_invalid
510  end if
511 
512  call spec_file_read_integer(file, 'rand_init', rand_init)
513  call spec_file_read_logical(file, 'allow_doubling', &
514  run_part_opt%allow_doubling)
515  call spec_file_read_logical(file, 'allow_halving', &
516  run_part_opt%allow_halving)
517  if (.not. do_restart) then
518  call spec_file_read_logical(file, 'do_select_weighting', &
519  run_part_opt%do_select_weighting)
520  if (run_part_opt%do_select_weighting) then
521  call spec_file_read_aero_state_weighting_type(file, &
522  run_part_opt%weighting_type, run_part_opt%weighting_exponent)
523  else
524  run_part_opt%weighting_type = aero_state_weight_nummass_source
525  run_part_opt%weighting_exponent = 0.0d0
526  end if
527  end if
528  call spec_file_read_logical(file, 'record_removals', &
529  run_part_opt%record_removals)
530 
531  call spec_file_read_logical(file, 'do_parallel', &
532  run_part_opt%do_parallel)
533  if (run_part_opt%do_parallel) then
534 #ifndef PMC_USE_MPI
535  call spec_file_die_msg(929006383, file, &
536  'cannot use parallel mode, support is not compiled in')
537 #endif
538  call spec_file_read_output_type(file, run_part_opt%output_type)
539  call spec_file_read_real(file, 'mix_timescale', &
540  run_part_opt%mix_timescale)
541  call spec_file_read_logical(file, 'gas_average', &
542  run_part_opt%gas_average)
543  call spec_file_read_logical(file, 'env_average', &
544  run_part_opt%env_average)
545  call spec_file_read_parallel_coag_type(file, &
546  run_part_opt%parallel_coag_type)
547  else
548  run_part_opt%output_type = output_type_single
549  run_part_opt%mix_timescale = 0d0
550  run_part_opt%gas_average = .false.
551  run_part_opt%env_average = .false.
552  run_part_opt%parallel_coag_type = parallel_coag_type_local
553  end if
554 
555  call spec_file_close(file)
556  end if
557 
558  ! finished reading .spec data, now broadcast data
559 
560  ! initialize RNG with random seed for UUID generation
561  call pmc_srand(0, pmc_mpi_rank())
562 
563  if (.not. do_restart) then
564  call uuid4_str(run_part_opt%uuid)
565  end if
566 
567 #ifdef PMC_USE_MPI
568  if (pmc_mpi_rank() == 0) then
569  ! root process determines size
570  max_buffer_size = 0
571  max_buffer_size = max_buffer_size &
572  + pmc_mpi_pack_size_run_part_opt(run_part_opt)
573  max_buffer_size = max_buffer_size &
574  + pmc_mpi_pack_size_real(n_part)
575  max_buffer_size = max_buffer_size &
576  + pmc_mpi_pack_size_gas_data(gas_data)
577  max_buffer_size = max_buffer_size &
578  + pmc_mpi_pack_size_gas_state(gas_state_init)
579  max_buffer_size = max_buffer_size &
580  + pmc_mpi_pack_size_aero_data(aero_data)
581  max_buffer_size = max_buffer_size &
582  + pmc_mpi_pack_size_aero_dist(aero_dist_init)
583  max_buffer_size = max_buffer_size &
584  + pmc_mpi_pack_size_scenario(scenario)
585  max_buffer_size = max_buffer_size &
586  + pmc_mpi_pack_size_env_state(env_state_init)
587  max_buffer_size = max_buffer_size &
588  + pmc_mpi_pack_size_integer(rand_init)
589  max_buffer_size = max_buffer_size &
590  + pmc_mpi_pack_size_logical(do_restart)
591  max_buffer_size = max_buffer_size &
592  + pmc_mpi_pack_size_logical(do_init_equilibriate)
593  max_buffer_size = max_buffer_size &
594  + pmc_mpi_pack_size_aero_state(aero_state_init)
595 
596  allocate(buffer(max_buffer_size))
597 
598  position = 0
599  call pmc_mpi_pack_run_part_opt(buffer, position, run_part_opt)
600  call pmc_mpi_pack_real(buffer, position, n_part)
601  call pmc_mpi_pack_gas_data(buffer, position, gas_data)
602  call pmc_mpi_pack_gas_state(buffer, position, gas_state_init)
603  call pmc_mpi_pack_aero_data(buffer, position, aero_data)
604  call pmc_mpi_pack_aero_dist(buffer, position, aero_dist_init)
605  call pmc_mpi_pack_scenario(buffer, position, scenario)
606  call pmc_mpi_pack_env_state(buffer, position, env_state_init)
607  call pmc_mpi_pack_integer(buffer, position, rand_init)
608  call pmc_mpi_pack_logical(buffer, position, do_restart)
609  call pmc_mpi_pack_logical(buffer, position, do_init_equilibriate)
610  call pmc_mpi_pack_aero_state(buffer, position, aero_state_init)
611  call assert(181905491, position <= max_buffer_size)
612  buffer_size = position ! might be less than we allocated
613  end if
614 
615  ! tell everyone the size
616  call pmc_mpi_bcast_integer(buffer_size)
617 
618  if (pmc_mpi_rank() /= 0) then
619  ! non-root processes allocate space
620  allocate(buffer(buffer_size))
621  end if
622 
623  ! broadcast data to everyone
624  call pmc_mpi_bcast_packed(buffer)
625 
626  if (pmc_mpi_rank() /= 0) then
627  ! non-root processes unpack data
628  position = 0
629  call pmc_mpi_unpack_run_part_opt(buffer, position, run_part_opt)
630  call pmc_mpi_unpack_real(buffer, position, n_part)
631  call pmc_mpi_unpack_gas_data(buffer, position, gas_data)
632  call pmc_mpi_unpack_gas_state(buffer, position, gas_state_init)
633  call pmc_mpi_unpack_aero_data(buffer, position, aero_data)
634  call pmc_mpi_unpack_aero_dist(buffer, position, aero_dist_init)
635  call pmc_mpi_unpack_scenario(buffer, position, scenario)
636  call pmc_mpi_unpack_env_state(buffer, position, env_state_init)
637  call pmc_mpi_unpack_integer(buffer, position, rand_init)
638  call pmc_mpi_unpack_logical(buffer, position, do_restart)
639  call pmc_mpi_unpack_logical(buffer, position, do_init_equilibriate)
640  call pmc_mpi_unpack_aero_state(buffer, position, aero_state_init)
641  call assert(143770146, position == buffer_size)
642  end if
643 
644  ! free the buffer
645  deallocate(buffer)
646 #endif
647 
648  ! re-initialize RNG with the given seed
649  call pmc_rand_finalize()
650  call pmc_srand(rand_init, pmc_mpi_rank())
651 
652  call cpu_time(run_part_opt%t_wall_start)
653 
654  do i_repeat = 1,run_part_opt%n_repeat
655  run_part_opt%i_repeat = i_repeat
656 
657  gas_state = gas_state_init
658  if (do_restart) then
659  aero_state = aero_state_init
660  call aero_state_set_n_part_ideal(aero_state, n_part)
661  else
662  call aero_state_zero(aero_state)
663  aero_mode_type_exp_present &
664  = aero_dist_contains_aero_mode_type(aero_dist_init, &
665  aero_mode_type_exp) &
666  .or. scenario_contains_aero_mode_type(scenario, &
667  aero_mode_type_exp)
668  if (aero_mode_type_exp_present) then
669  call warn_msg(245301880, "using flat weighting only due to " &
670  // "presence of exp aerosol mode")
671  call aero_state_set_weight(aero_state, aero_data, &
673  else
674  call aero_state_set_weight(aero_state, aero_data, &
675  run_part_opt%weighting_type, run_part_opt%weighting_exponent)
676  end if
677  call aero_state_set_n_part_ideal(aero_state, n_part)
678  call aero_state_add_aero_dist_sample(aero_state, aero_data, &
679  aero_dist_init, 1d0, 0d0, run_part_opt%allow_doubling, &
680  run_part_opt%allow_halving)
681  end if
682  env_state = env_state_init
683  call scenario_init_env_state(scenario, env_state, &
684  env_state_init%elapsed_time)
685 
686 #ifdef PMC_USE_SUNDIALS
687  if (do_init_equilibriate) then
688  call condense_equilib_particles(env_state, aero_data, aero_state)
689  end if
690 #endif
691 
692  call run_part(scenario, env_state, aero_data, aero_state, gas_data, &
693  gas_state, run_part_opt)
694 
695  end do
696 
697  call pmc_rand_finalize()
698 
699  end subroutine partmc_part
700 
701 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
702 
703  !> Run an exact solution simulation.
704  subroutine partmc_exact(file)
705 
706  !> Spec file.
707  type(spec_file_t), intent(inout) :: file
708 
709  character(len=100) :: soln_name
710  type(aero_data_t) :: aero_data
711  type(scenario_t) :: scenario
712  type(env_state_t) :: env_state
713  type(aero_dist_t) :: aero_dist_init
714  type(run_exact_opt_t) :: run_exact_opt
715  type(bin_grid_t) :: bin_grid
716  type(gas_data_t) :: gas_data
717  character(len=PMC_MAX_FILENAME_LEN) :: sub_filename
718  type(spec_file_t) :: sub_file
719 
720  !> \page input_format_exact Exact (Analytical) Solution
721  !!
722  !! The coagulation kernel and initial distribution must be matched
723  !! for an exact solution to exist. The valid choices are:
724  !!
725  !! <table>
726  !! <tr><th>Coagulation kernel</th>
727  !! <th>Initial aerosol distribution</th></tr>
728  !! <tr><td>Additive</td>
729  !! <td>Single exponential mode</td></tr>
730  !! <tr><td>Constant</td>
731  !! <td>Single exponential mode</td></tr>
732  !! <tr><td>Zero</td>
733  !! <td>Anything</td></tr>
734  !! </table>
735  !!
736  !! See \ref spec_file_format for the input file text format.
737  !!
738  !! An exact (analytical) simulation spec file has the parameters:
739  !! - \b run_type (string): must be \c exact
740  !! - \b output_prefix (string): prefix of the output filenames ---
741  !! the filenames will be of the form \c PREFIX_SSSSSSSS.nc where
742  !! \c SSSSSSSS is is the eight-digit output index (starting at 1
743  !! and incremented each time the state is output)
744  !! - \b t_max (real, unit s): total simulation time
745  !! - \b t_output (real, unit s): the interval on which to output
746  !! data to disk and to print progress information to the screen
747  !! (see \ref output_format)
748  !! - \subpage input_format_diam_bin_grid
749  !! - \b gas_data (string): name of file from which to read the
750  !! gas material data --- the file format should be
751  !! \subpage input_format_gas_data
752  !! - \b aerosol_data (string): name of file from which to read the
753  !! aerosol material data --- the file format should be
754  !! \subpage input_format_aero_data
755  !! - \b do_fractal (logical): whether to consider particles
756  !! as fractal agglomerates. If \c do_fractal is \c no, then all the
757  !! particles are treated as spherical. If \c do_fractal is \c yes,
758  !! then the following parameters must also be provided:
759  !! - \subpage input_format_fractal
760  !! - \b aerosol_init (string): filename containing the initial
761  !! aerosol state at the start of the simulation --- the file
762  !! format should be \subpage input_format_aero_dist
763  !! - \subpage input_format_scenario
764  !! - \subpage input_format_env_state
765  !! - \b do_coagulation (logical): whether to perform particle
766  !! coagulation. If \c do_coagulation is \c yes, then the
767  !! following parameters must also be provided:
768  !! - \subpage input_format_coag_kernel
769  !!
770  !! Example:
771  !! <pre>
772  !! run_type exact # exact solution
773  !! output_prefix additive_exact # prefix of output files
774  !!
775  !! t_max 600 # total simulation time (s)
776  !! t_output 60 # output interval (0 disables) (s)
777  !!
778  !! n_bin 160 # number of bins
779  !! d_min 1e-8 # minimum diameter (m)
780  !! d_max 1e-3 # maximum diameter (m)
781  !!
782  !! gas_data gas_data.dat # file containing gas data
783  !!
784  !! aerosol_data aero_data.dat # file containing aerosol data
785  !! do_fractal no # whether to do fractal treatment
786  !! aerosol_init aero_init_dist.dat # aerosol initial condition file
787  !!
788  !! temp_profile temp.dat # temperature profile file
789  !! height_profile height.dat # height profile file
790  !! gas_emissions gas_emit.dat # gas emissions file
791  !! gas_background gas_back.dat # background gas mixing ratios file
792  !! aero_emissions aero_emit.dat # aerosol emissions file
793  !! aero_background aero_back.dat # aerosol background file
794  !!
795  !! rel_humidity 0.999 # initial relative humidity (1)
796  !! pressure 1e5 # initial pressure (Pa)
797  !! latitude 0 # latitude (degrees, -90 to 90)
798  !! longitude 0 # longitude (degrees, -180 to 180)
799  !! altitude 0 # altitude (m)
800  !! start_time 0 # start time (s since 00:00 UTC)
801  !! start_day 1 # start day of year (UTC)
802  !!
803  !! do_coagulation yes # whether to do coagulation (yes/no)
804  !! kernel additive # Additive coagulation kernel
805  !! </pre>
806 
807  ! only serial code here
808  if (pmc_mpi_rank() /= 0) then
809  return
810  end if
811 
812  call spec_file_read_string(file, 'output_prefix', run_exact_opt%prefix)
813 
814  call spec_file_read_real(file, 't_max', run_exact_opt%t_max)
815  call spec_file_read_real(file, 't_output', run_exact_opt%t_output)
816 
817  call spec_file_read_radius_bin_grid(file, bin_grid)
818 
819  call spec_file_read_string(file, 'gas_data', sub_filename)
820  call spec_file_open(sub_filename, sub_file)
821  call spec_file_read_gas_data(sub_file, gas_data)
822  call spec_file_close(sub_file)
823 
824  call spec_file_read_string(file, 'aerosol_data', sub_filename)
825  call spec_file_open(sub_filename, sub_file)
826  call spec_file_read_aero_data(sub_file, aero_data)
827  call spec_file_close(sub_file)
828 
829  call spec_file_read_fractal(file, aero_data%fractal)
830 
831  call spec_file_read_string(file, 'aerosol_init', sub_filename)
832  call spec_file_open(sub_filename, sub_file)
833  call spec_file_read_aero_dist(sub_file, aero_data, aero_dist_init)
834  call spec_file_close(sub_file)
835 
836  call spec_file_read_scenario(file, gas_data, aero_data, scenario)
837  call spec_file_read_env_state(file, env_state)
838 
839  call spec_file_read_logical(file, 'do_coagulation', &
840  run_exact_opt%do_coagulation)
841  if (run_exact_opt%do_coagulation) then
842  call spec_file_read_coag_kernel_type(file, &
843  run_exact_opt%coag_kernel_type)
844  else
845  run_exact_opt%coag_kernel_type = coag_kernel_type_invalid
846  end if
847 
848  call spec_file_close(file)
849 
850  ! finished reading .spec data, now do the run
851 
852  call pmc_srand(0, 0)
853 
854  call uuid4_str(run_exact_opt%uuid)
855 
856  call scenario_init_env_state(scenario, env_state, 0d0)
857 
858  call run_exact(bin_grid, scenario, env_state, aero_data, &
859  aero_dist_init, gas_data, run_exact_opt)
860 
861  call pmc_rand_finalize()
862 
863  end subroutine partmc_exact
864 
865 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
866 
867  !> Run a sectional code simulation.
868  subroutine partmc_sect(file)
869 
870  !> Spec file.
871  type(spec_file_t), intent(inout) :: file
872 
873  type(run_sect_opt_t) :: run_sect_opt
874  type(aero_data_t) :: aero_data
875  type(aero_dist_t) :: aero_dist_init
876  type(aero_state_t) :: aero_init
877  type(scenario_t) :: scenario
878  type(env_state_t) :: env_state
879  type(bin_grid_t) :: bin_grid
880  type(gas_data_t) :: gas_data
881  character(len=PMC_MAX_FILENAME_LEN) :: sub_filename
882  type(spec_file_t) :: sub_file
883 
884  !> \page input_format_sectional Sectional Model Simulation
885  !!
886  !! See \ref spec_file_format for the input file text format.
887  !!
888  !! A sectional simulation spec file has the parameters:
889  !! - \b run_type (string): must be \c sectional
890  !! - \b output_prefix (string): prefix of the output filenames ---
891  !! the filenames will be of the form \c PREFIX_SSSSSSSS.nc where
892  !! \c SSSSSSSS is is the eight-digit output index (starting at 1
893  !! and incremented each time the state is output)
894  !! - \b del_t (real, unit s): timestep size
895  !! - \b t_output (real, unit s): the interval on which to
896  !! output data to disk (see \ref output_format)
897  !! - \b t_progress (real, unit s): the interval on which to
898  !! write summary information to the screen while running
899  !! - \subpage input_format_diam_bin_grid
900  !! - \b gas_data (string): name of file from which to read the
901  !! gas material data --- the file format should be
902  !! \subpage input_format_gas_data
903  !! - \b aerosol_data (string): name of file from which to read the
904  !! aerosol material data --- the file format should be
905  !! \subpage input_format_aero_data
906  !! - \b do_fractal (logical): whether to consider particles
907  !! as fractal agglomerates. If \c do_fractal is \c no, then all the
908  !! particles are treated as spherical. If \c do_fractal is \c yes,
909  !! then the following parameters must also be provided:
910  !! - \subpage input_format_fractal
911  !! - \b aerosol_init (string): filename containing the initial
912  !! aerosol state at the start of the simulation --- the file
913  !! format should be \subpage input_format_aero_dist
914  !! - \subpage input_format_scenario
915  !! - \subpage input_format_env_state
916  !! - \b do_coagulation (logical): whether to perform particle
917  !! coagulation. If \c do_coagulation is \c yes, then the
918  !! following parameters must also be provided:
919  !! - \subpage input_format_coag_kernel
920  !!
921  !! Example:
922  !! <pre>
923  !! run_type sectional # sectional code run
924  !! output_prefix brown_sect # prefix of output files
925  !!
926  !! t_max 86400 # total simulation time (s)
927  !! del_t 60 # timestep (s)
928  !! t_output 3600 # output interval (0 disables) (s)
929  !! t_progress 600 # progress printing interval (0 disables) (s)
930  !!
931  !! n_bin 220 # number of bins
932  !! d_min 1e-10 # minimum diameter (m)
933  !! d_max 1e-4 # maximum diameter (m)
934  !!
935  !! gas_data gas_data.dat # file containing gas data
936  !! aerosol_data aero_data.dat # file containing aerosol data
937  !! do_fractal no # whether to do fractal treatment
938  !! aerosol_init aero_init_dist.dat # initial aerosol distribution
939  !!
940  !! temp_profile temp.dat # temperature profile file
941  !! height_profile height.dat # height profile file
942  !! gas_emissions gas_emit.dat # gas emissions file
943  !! gas_background gas_back.dat # background gas mixing ratios file
944  !! aero_emissions aero_emit.dat # aerosol emissions file
945  !! aero_background aero_back.dat # aerosol background file
946  !!
947  !! rel_humidity 0.999 # initial relative humidity (1)
948  !! pressure 1e5 # initial pressure (Pa)
949  !! latitude 0 # latitude (degrees_north, -90 to 90)
950  !! longitude 0 # longitude (degrees_east, -180 to 180)
951  !! altitude 0 # altitude (m)
952  !! start_time 0 # start time (s since 00:00 UTC)
953  !! start_day 1 # start day of year (UTC)
954  !!
955  !! do_coagulation yes # whether to do coagulation (yes/no)
956  !! kernel brown # coagulation kernel
957  !! </pre>
958 
959  ! only serial code here
960  if (pmc_mpi_rank() /= 0) then
961  return
962  end if
963 
964  call spec_file_read_string(file, 'output_prefix', run_sect_opt%prefix)
965 
966  call spec_file_read_real(file, 't_max', run_sect_opt%t_max)
967  call spec_file_read_real(file, 'del_t', run_sect_opt%del_t)
968  call spec_file_read_real(file, 't_output', run_sect_opt%t_output)
969  call spec_file_read_real(file, 't_progress', run_sect_opt%t_progress)
970 
971  call spec_file_read_radius_bin_grid(file, bin_grid)
972 
973  call spec_file_read_string(file, 'gas_data', sub_filename)
974  call spec_file_open(sub_filename, sub_file)
975  call spec_file_read_gas_data(sub_file, gas_data)
976  call spec_file_close(sub_file)
977 
978  call spec_file_read_string(file, 'aerosol_data', sub_filename)
979  call spec_file_open(sub_filename, sub_file)
980  call spec_file_read_aero_data(sub_file, aero_data)
981  call spec_file_close(sub_file)
982 
983  call spec_file_read_fractal(file, aero_data%fractal)
984 
985  call spec_file_read_string(file, 'aerosol_init', sub_filename)
986  call spec_file_open(sub_filename, sub_file)
987  call spec_file_read_aero_dist(sub_file, aero_data, aero_dist_init)
988  call spec_file_close(sub_file)
989 
990  call spec_file_read_scenario(file, gas_data, aero_data, scenario)
991  call spec_file_read_env_state(file, env_state)
992 
993  call spec_file_read_logical(file, 'do_coagulation', &
994  run_sect_opt%do_coagulation)
995  if (run_sect_opt%do_coagulation) then
996  call spec_file_read_coag_kernel_type(file, &
997  run_sect_opt%coag_kernel_type)
998  else
999  run_sect_opt%coag_kernel_type = coag_kernel_type_invalid
1000  end if
1001 
1002  call spec_file_close(file)
1003 
1004  ! finished reading .spec data, now do the run
1005 
1006  call pmc_srand(0, 0)
1007 
1008  call uuid4_str(run_sect_opt%uuid)
1009 
1010  call scenario_init_env_state(scenario, env_state, 0d0)
1011 
1012  call run_sect(bin_grid, gas_data, aero_data, aero_dist_init, scenario, &
1013  env_state, run_sect_opt)
1014 
1015  call pmc_rand_finalize()
1016 
1017  end subroutine partmc_sect
1018 
1019 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1020 
1021 end program partmc
subroutine assert_msg(code, condition_ok, error_msg)
Errors unless condition_ok is true.
Definition: util.F90:77
An input file with extra data for printing messages.
Definition: spec_file.F90:59
program partmc
Top level driver.
Definition: partmc.F90:185
subroutine partmc_run(spec_name)
Do a PartMC run.
Definition: partmc.F90:242
integer function pmc_mpi_rank()
Returns the rank of the current process.
Definition: mpi.F90:117
Options controlling the execution of run_exact().
Definition: run_exact.F90:24
Exact solution simulation.
Definition: run_exact.F90:9
subroutine pmc_mpi_pack_run_part_opt(buffer, position, val)
Packs the given value into the buffer, advancing position.
Definition: run_part.F90:442
elemental logical function scenario_contains_aero_mode_type(scenario, aero_mode_type)
Whether any of the contained aerosol modes are of the given type.
Definition: scenario.F90:735
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
subroutine spec_file_close(file)
Close a spec file.
Definition: spec_file.F90:135
The bin_grid_t structure and associated subroutines.
Definition: bin_grid.F90:9
integer function pmc_mpi_pack_size_aero_dist(val)
Determines the number of bytes required to pack the given value.
Definition: aero_dist.F90:397
integer, parameter coag_kernel_type_invalid
Type code for an undefined or invalid kernel.
Definition: coag_kernel.F90:29
subroutine uuid4_str(uuid)
Generate a version 4 UUID as a string.
Definition: rand.F90:600
subroutine warn_msg(code, warning_msg, already_warned)
Prints a warning message.
Definition: util.F90:37
subroutine pmc_srand(seed, offset)
Initializes the random number generator to the state defined by the given seed plus offset...
Definition: rand.F90:67
subroutine run_sect(bin_grid, gas_data, aero_data, aero_dist, scenario, env_state, run_sect_opt)
Run a sectional simulation.
Definition: run_sect.F90:58
The env_state_t structure and associated subroutines.
Definition: env_state.F90:9
The aero_dist_t structure and associated subroutines.
Definition: aero_dist.F90:18
integer function pmc_mpi_pack_size_env_state(val)
Determines the number of bytes required to pack the given value.
Definition: env_state.F90:314
subroutine pmc_mpi_pack_scenario(buffer, position, val)
Packs the given value into the buffer, advancing position.
Definition: scenario.F90:1041
Water condensation onto aerosol particles.
Definition: condense.F90:29
Generic coagulation kernel.
Definition: coag_kernel.F90:9
The gas_data_t structure and associated subroutines.
Definition: gas_data.F90:9
subroutine aero_state_add_aero_dist_sample(aero_state, aero_data, aero_dist, sample_prop, create_time, allow_doubling, allow_halving, n_part_add)
Generates a Poisson sample of an aero_dist, adding to aero_state, with the given sample proportion...
Definition: aero_state.F90:713
subroutine assert(code, condition_ok)
Errors unless condition_ok is true.
Definition: util.F90:103
subroutine condense_equilib_particles(env_state, aero_data, aero_state)
Call condense_equilib_particle() on each particle in the aerosol to ensure that every particle has it...
Definition: condense.F90:747
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:562
subroutine pmc_mpi_unpack_gas_data(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
Definition: gas_data.F90:235
integer function pmc_mpi_pack_size_aero_state(val)
Determines the number of bytes required to pack the given value.
The aero_state_t structure and assocated subroutines.
Definition: aero_state.F90:9
subroutine aero_state_set_n_part_ideal(aero_state, n_part)
Set the ideal number of particles to the given value. The aero_state%awa must be already set correctl...
Definition: aero_state.F90:214
A complete aerosol distribution, consisting of several modes.
Definition: aero_dist.F90:33
1D sectional simulation.
Definition: run_sect.F90:17
integer function pmc_mpi_pack_size_scenario(val)
Determines the number of bytes required to pack the given value.
Definition: scenario.F90:985
subroutine spec_file_read_integer(file, name, var)
Read an integer from a spec file that must have the given name.
Definition: spec_file.F90:540
integer function pmc_mpi_pack_size_real(val)
Determines the number of bytes required to pack the given value.
Definition: mpi.F90:365
Current environment state.
Definition: env_state.F90:26
Options controlling the execution of run_part().
Definition: run_part.F90:40
subroutine pmc_mpi_unpack_scenario(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
Definition: scenario.F90:1100
subroutine pmc_mpi_pack_logical(buffer, position, val)
Packs the given value into the buffer, advancing position.
Definition: mpi.F90:638
subroutine pmc_rand_finalize()
Cleanup the random number generator.
Definition: rand.F90:119
subroutine die_msg(code, error_msg)
Error immediately.
Definition: util.F90:134
subroutine pmc_mpi_pack_aero_dist(buffer, position, val)
Packs the given value into the buffer, advancing position.
Definition: aero_dist.F90:419
elemental logical function aero_dist_contains_aero_mode_type(aero_dist, aero_mode_type)
Whether any of the modes are of the given type.
Definition: aero_dist.F90:155
Options controlling the operation of run_sect().
Definition: run_sect.F90:32
subroutine pmc_mpi_unpack_aero_data(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
Definition: aero_data.F90:516
subroutine pmc_mpi_pack_aero_state(buffer, position, val)
Packs the given value into the buffer, advancing position.
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:583
subroutine pmc_mpi_pack_real(buffer, position, val)
Packs the given value into the buffer, advancing position.
Definition: mpi.F90:586
The current collection of aerosol particles.
Definition: aero_state.F90:63
subroutine spec_file_die_msg(code, file, msg)
Exit with an error message containing filename and line number.
Definition: spec_file.F90:74
subroutine pmc_mpi_unpack_aero_state(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
Scenario data.
Definition: scenario.F90:54
subroutine pmc_mpi_pack_aero_data(buffer, position, val)
Packs the given value into the buffer, advancing position.
Definition: aero_data.F90:485
The aero_data_t structure and associated subroutines.
Definition: aero_data.F90:9
integer, parameter parallel_coag_type_local
Type code for local parallel coagulation.
Definition: run_part.F90:35
subroutine pmc_mpi_pack_gas_data(buffer, position, val)
Packs the given value into the buffer, advancing position.
Definition: gas_data.F90:211
integer, parameter aero_state_weight_nummass_source
Coupled number/mass weighting by source.
Definition: aero_state.F90:51
1D grid, either logarithmic or linear.
Definition: bin_grid.F90:33
subroutine pmc_mpi_pack_integer(buffer, position, val)
Packs the given value into the buffer, advancing position.
Definition: mpi.F90:561
The gas_state_t structure and associated subroutines.
Definition: gas_state.F90:9
Reading formatted text input.
Definition: spec_file.F90:43
integer function pmc_mpi_pack_size_logical(val)
Determines the number of bytes required to pack the given value.
Definition: mpi.F90:407
subroutine spec_file_open(filename, file)
Open a spec file for reading.
Definition: spec_file.F90:112
subroutine pmc_mpi_unpack_real(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
Definition: mpi.F90:843
subroutine aero_state_zero(aero_state)
Resets an aero_state to have zero particles per bin.
Definition: aero_state.F90:317
subroutine pmc_mpi_unpack_logical(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
Definition: mpi.F90:896
Current state of the gas mixing ratios in the system.
Definition: gas_state.F90:30
subroutine print_usage()
Print the usage text to stderr.
Definition: partmc.F90:233
integer, parameter aero_state_weight_flat
Single flat weighting scheme.
Definition: aero_state.F90:41
subroutine pmc_mpi_unpack_env_state(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
Definition: env_state.F90:370
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
subroutine pmc_mpi_bcast_integer(val)
Broadcast the given value from process 0 to all other processes.
Definition: mpi.F90:288
integer function pmc_mpi_pack_size_integer(val)
Determines the number of bytes required to pack the given value.
Definition: mpi.F90:345
Constant gas data.
Definition: gas_data.F90:29
subroutine pmc_mpi_unpack_gas_state(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
Definition: gas_state.F90:502
subroutine pmc_mpi_pack_env_state(buffer, position, val)
Packs the given value into the buffer, advancing position.
Definition: env_state.F90:337
subroutine pmc_mpi_unpack_integer(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
Definition: mpi.F90:818
integer function pmc_mpi_pack_size_run_part_opt(val)
Determines the number of bytes required to pack the given value.
Definition: run_part.F90:401
integer function pmc_mpi_pack_size_aero_data(val)
Determines the number of bytes required to pack the given value.
Definition: aero_data.F90:464
integer function pmc_mpi_pack_size_gas_data(val)
Determines the number of bytes required to pack the given value.
Definition: gas_data.F90:197
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:604
subroutine pmc_mpi_bcast_packed(val)
Broadcast the given value from process 0 to all other processes.
Definition: mpi.F90:326
subroutine pmc_mpi_unpack_aero_dist(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
Definition: aero_dist.F90:449
subroutine aero_state_set_weight(aero_state, aero_data, weight_type, exponent)
Sets the weighting functions for an aero_state.
Definition: aero_state.F90:169
subroutine pmc_mpi_finalize()
Shut down MPI.
Definition: mpi.F90:89
subroutine pmc_mpi_init()
Initialize MPI.
Definition: mpi.F90:56
Aerosol material properties and associated data.
Definition: aero_data.F90:41
subroutine pmc_mpi_bcast_string(val)
Broadcast the given value from process 0 to all other processes.
Definition: mpi.F90:307
subroutine pmc_mpi_pack_gas_state(buffer, position, val)
Packs the given value into the buffer, advancing position.
Definition: gas_state.F90:479
Common utility subroutines.
Definition: util.F90:9
The aero_binned_t structure and associated subroutines.
Definition: aero_binned.F90:9
Wrapper functions for MPI.
Definition: mpi.F90:13
integer function pmc_mpi_pack_size_gas_state(val)
Determines the number of bytes required to pack the given value.
Definition: gas_state.F90:466
subroutine pmc_mpi_unpack_run_part_opt(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
Definition: run_part.F90:493
subroutine run_part(scenario, env_state, aero_data, aero_state, gas_data, gas_state, run_part_opt)
Do a particle-resolved Monte Carlo simulation.
Definition: run_part.F90:108
Monte Carlo simulation.
Definition: run_part.F90:9
The scenario_t structure and associated subroutines.
Definition: scenario.F90:9