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