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