203 #ifdef PMC_USE_SUNDIALS 207 character(len=300) :: spec_name
214 if (command_argument_count() /= 1)
then 216 call die_msg(739173192,
"invalid commandline arguments")
219 call get_command_argument(1, spec_name)
234 write(*,*)
'Usage: partmc <spec-file>' 244 character(len=*),
intent(in) :: spec_name
247 character(len=100) :: run_type
251 i = len_trim(spec_name)
252 if (spec_name((i-4):i) /=
'.spec')
then 253 call die_msg(710381938,
"input filename must end in .spec")
263 if (trim(run_type) ==
'particle')
then 264 call partmc_part(file)
265 elseif (trim(run_type) ==
'exact')
then 266 call partmc_exact(file)
267 elseif (trim(run_type) ==
'sectional')
then 268 call partmc_sect(file)
270 call die_msg(719261940,
"unknown run_type: " // trim(run_type))
278 subroutine partmc_part(file)
294 integer :: i_repeat, i_group
296 character,
allocatable :: buffer(:)
297 integer :: buffer_size, max_buffer_size
299 logical :: do_restart, do_init_equilibriate, aero_mode_type_exp_present
300 character(len=PMC_MAX_FILENAME_LEN) :: restart_filename
301 integer :: dummy_index, dummy_i_repeat
302 real(kind=dp) :: dummy_time, dummy_del_t, n_part
303 character(len=PMC_MAX_FILENAME_LEN) :: sub_filename
415 run_part_opt%output_prefix)
429 call input_state(restart_filename, dummy_index, dummy_time, &
430 dummy_del_t, dummy_i_repeat, run_part_opt%uuid, aero_data, &
431 aero_state_init, gas_data, gas_state_init, env_state_init)
434 if (.not. do_restart)
then 435 env_state_init%elapsed_time = 0d0
439 call spec_file_read_gas_data(sub_file, gas_data)
444 call spec_file_read_gas_state(sub_file, gas_data, &
450 call spec_file_read_aero_data(sub_file, aero_data)
453 call spec_file_read_fractal(file, aero_data%fractal)
457 call spec_file_read_aero_dist(sub_file, aero_data, aero_dist_init)
461 call spec_file_read_scenario(file, gas_data, aero_data, scenario)
462 call spec_file_read_env_state(file, env_state_init)
465 run_part_opt%do_coagulation)
466 if (run_part_opt%do_coagulation)
then 467 call spec_file_read_coag_kernel_type(file, &
468 run_part_opt%coag_kernel_type)
474 run_part_opt%do_condensation)
475 #ifndef PMC_USE_SUNDIALS 477 run_part_opt%do_condensation .eqv. .false., &
478 "cannot use condensation, SUNDIALS support is not compiled in")
480 if (run_part_opt%do_condensation)
then 482 do_init_equilibriate)
484 do_init_equilibriate = .false.
488 if (run_part_opt%do_mosaic .and. (.not. mosaic_support()))
then 490 'cannot use MOSAIC, support is not compiled in')
492 if (run_part_opt%do_mosaic .and. run_part_opt%do_condensation)
then 494 'cannot use MOSAIC and condensation simultaneously')
496 if (run_part_opt%do_mosaic)
then 498 run_part_opt%do_optical)
500 run_part_opt%do_optical = .false.
504 run_part_opt%do_nucleation)
505 if (run_part_opt%do_nucleation)
then 506 call spec_file_read_nucleate_type(file, aero_data, &
507 run_part_opt%nucleate_type, run_part_opt%nucleate_source)
509 run_part_opt%nucleate_type = nucleate_type_invalid
514 run_part_opt%allow_doubling)
516 run_part_opt%allow_halving)
517 if (.not. do_restart)
then 519 run_part_opt%do_select_weighting)
520 if (run_part_opt%do_select_weighting)
then 521 call spec_file_read_aero_state_weighting_type(file, &
522 run_part_opt%weighting_type, run_part_opt%weighting_exponent)
525 run_part_opt%weighting_exponent = 0.0d0
529 run_part_opt%record_removals)
532 run_part_opt%do_parallel)
533 if (run_part_opt%do_parallel)
then 536 'cannot use parallel mode, support is not compiled in')
538 call spec_file_read_output_type(file, run_part_opt%output_type)
540 run_part_opt%mix_timescale)
542 run_part_opt%gas_average)
544 run_part_opt%env_average)
545 call spec_file_read_parallel_coag_type(file, &
546 run_part_opt%parallel_coag_type)
548 run_part_opt%output_type = output_type_single
549 run_part_opt%mix_timescale = 0d0
550 run_part_opt%gas_average = .false.
551 run_part_opt%env_average = .false.
563 if (.not. do_restart)
then 571 max_buffer_size = max_buffer_size &
573 max_buffer_size = max_buffer_size &
575 max_buffer_size = max_buffer_size &
577 max_buffer_size = max_buffer_size &
579 max_buffer_size = max_buffer_size &
581 max_buffer_size = max_buffer_size &
583 max_buffer_size = max_buffer_size &
585 max_buffer_size = max_buffer_size &
587 max_buffer_size = max_buffer_size &
589 max_buffer_size = max_buffer_size &
591 max_buffer_size = max_buffer_size &
593 max_buffer_size = max_buffer_size &
596 allocate(buffer(max_buffer_size))
611 call assert(181905491, position <= max_buffer_size)
612 buffer_size = position
620 allocate(buffer(buffer_size))
641 call assert(143770146, position == buffer_size)
652 call cpu_time(run_part_opt%t_wall_start)
654 do i_repeat = 1,run_part_opt%n_repeat
655 run_part_opt%i_repeat = i_repeat
657 gas_state = gas_state_init
659 aero_state = aero_state_init
663 aero_mode_type_exp_present &
665 aero_mode_type_exp) &
668 if (aero_mode_type_exp_present)
then 669 call warn_msg(245301880,
"using flat weighting only due to " &
670 //
"presence of exp aerosol mode")
675 run_part_opt%weighting_type, run_part_opt%weighting_exponent)
679 aero_dist_init, 1d0, 0d0, run_part_opt%allow_doubling, &
680 run_part_opt%allow_halving)
682 env_state = env_state_init
684 env_state_init%elapsed_time)
686 #ifdef PMC_USE_SUNDIALS 687 if (do_init_equilibriate)
then 692 call run_part(scenario, env_state, aero_data, aero_state, gas_data, &
693 gas_state, run_part_opt)
699 end subroutine partmc_part
704 subroutine partmc_exact(file)
709 character(len=100) :: soln_name
717 character(len=PMC_MAX_FILENAME_LEN) :: sub_filename
817 call spec_file_read_radius_bin_grid(file, bin_grid)
821 call spec_file_read_gas_data(sub_file, gas_data)
826 call spec_file_read_aero_data(sub_file, aero_data)
829 call spec_file_read_fractal(file, aero_data%fractal)
833 call spec_file_read_aero_dist(sub_file, aero_data, aero_dist_init)
836 call spec_file_read_scenario(file, gas_data, aero_data, scenario)
837 call spec_file_read_env_state(file, env_state)
840 run_exact_opt%do_coagulation)
841 if (run_exact_opt%do_coagulation)
then 842 call spec_file_read_coag_kernel_type(file, &
843 run_exact_opt%coag_kernel_type)
858 call run_exact(bin_grid, scenario, env_state, aero_data, &
859 aero_dist_init, gas_data, run_exact_opt)
863 end subroutine partmc_exact
868 subroutine partmc_sect(file)
881 character(len=PMC_MAX_FILENAME_LEN) :: sub_filename
971 call spec_file_read_radius_bin_grid(file, bin_grid)
975 call spec_file_read_gas_data(sub_file, gas_data)
980 call spec_file_read_aero_data(sub_file, aero_data)
983 call spec_file_read_fractal(file, aero_data%fractal)
987 call spec_file_read_aero_dist(sub_file, aero_data, aero_dist_init)
990 call spec_file_read_scenario(file, gas_data, aero_data, scenario)
991 call spec_file_read_env_state(file, env_state)
994 run_sect_opt%do_coagulation)
995 if (run_sect_opt%do_coagulation)
then 996 call spec_file_read_coag_kernel_type(file, &
997 run_sect_opt%coag_kernel_type)
1012 call run_sect(bin_grid, gas_data, aero_data, aero_dist_init, scenario, &
1013 env_state, run_sect_opt)
1017 end subroutine partmc_sect
subroutine assert_msg(code, condition_ok, error_msg)
Errors unless condition_ok is true.
An input file with extra data for printing messages.
program partmc
Top level driver.
subroutine partmc_run(spec_name)
Do a PartMC run.
integer function pmc_mpi_rank()
Returns the rank of the current process.
Options controlling the execution of run_exact().
Exact solution simulation.
subroutine pmc_mpi_pack_run_part_opt(buffer, position, val)
Packs the given value into the buffer, advancing position.
elemental logical function scenario_contains_aero_mode_type(scenario, aero_mode_type)
Whether any of the contained aerosol modes are of the given type.
subroutine run_exact(bin_grid, scenario, env_state, aero_data, aero_dist_init, gas_data, run_exact_opt)
Run an exact simulation.
subroutine spec_file_close(file)
Close a spec file.
The bin_grid_t structure and associated subroutines.
integer function pmc_mpi_pack_size_aero_dist(val)
Determines the number of bytes required to pack the given value.
integer, parameter coag_kernel_type_invalid
Type code for an undefined or invalid kernel.
subroutine uuid4_str(uuid)
Generate a version 4 UUID as a string.
subroutine warn_msg(code, warning_msg, already_warned)
Prints a warning message.
subroutine pmc_srand(seed, offset)
Initializes the random number generator to the state defined by the given seed plus offset...
subroutine run_sect(bin_grid, gas_data, aero_data, aero_dist, scenario, env_state, run_sect_opt)
Run a sectional simulation.
The env_state_t structure and associated subroutines.
The aero_dist_t structure and associated subroutines.
integer function pmc_mpi_pack_size_env_state(val)
Determines the number of bytes required to pack the given value.
subroutine pmc_mpi_pack_scenario(buffer, position, val)
Packs the given value into the buffer, advancing position.
Water condensation onto aerosol particles.
Generic coagulation kernel.
The gas_data_t structure and associated subroutines.
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...
subroutine assert(code, condition_ok)
Errors unless condition_ok is true.
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...
subroutine spec_file_read_real(file, name, var)
Read a real number from a spec file that must have the given name.
subroutine pmc_mpi_unpack_gas_data(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
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.
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...
A complete aerosol distribution, consisting of several modes.
integer function pmc_mpi_pack_size_scenario(val)
Determines the number of bytes required to pack the given value.
subroutine spec_file_read_integer(file, name, var)
Read an integer from a spec file that must have the given name.
integer function pmc_mpi_pack_size_real(val)
Determines the number of bytes required to pack the given value.
Current environment state.
Options controlling the execution of run_part().
subroutine pmc_mpi_unpack_scenario(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
subroutine pmc_mpi_pack_logical(buffer, position, val)
Packs the given value into the buffer, advancing position.
subroutine pmc_rand_finalize()
Cleanup the random number generator.
subroutine die_msg(code, error_msg)
Error immediately.
subroutine pmc_mpi_pack_aero_dist(buffer, position, val)
Packs the given value into the buffer, advancing position.
elemental logical function aero_dist_contains_aero_mode_type(aero_dist, aero_mode_type)
Whether any of the modes are of the given type.
Options controlling the operation of run_sect().
subroutine pmc_mpi_unpack_aero_data(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
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.
subroutine pmc_mpi_pack_real(buffer, position, val)
Packs the given value into the buffer, advancing position.
The current collection of aerosol particles.
subroutine spec_file_die_msg(code, file, msg)
Exit with an error message containing filename and line number.
subroutine pmc_mpi_unpack_aero_state(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
subroutine pmc_mpi_pack_aero_data(buffer, position, val)
Packs the given value into the buffer, advancing position.
The aero_data_t structure and associated subroutines.
integer, parameter parallel_coag_type_local
Type code for local parallel coagulation.
subroutine pmc_mpi_pack_gas_data(buffer, position, val)
Packs the given value into the buffer, advancing position.
integer, parameter aero_state_weight_nummass_source
Coupled number/mass weighting by source.
1D grid, either logarithmic or linear.
subroutine pmc_mpi_pack_integer(buffer, position, val)
Packs the given value into the buffer, advancing position.
The gas_state_t structure and associated subroutines.
Reading formatted text input.
integer function pmc_mpi_pack_size_logical(val)
Determines the number of bytes required to pack the given value.
subroutine spec_file_open(filename, file)
Open a spec file for reading.
subroutine pmc_mpi_unpack_real(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
subroutine aero_state_zero(aero_state)
Resets an aero_state to have zero particles per bin.
subroutine pmc_mpi_unpack_logical(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
Current state of the gas mixing ratios in the system.
subroutine print_usage()
Print the usage text to stderr.
integer, parameter aero_state_weight_flat
Single flat weighting scheme.
subroutine pmc_mpi_unpack_env_state(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
subroutine scenario_init_env_state(scenario, env_state, time)
Initialize the time-dependent contents of the environment. Thereafter scenario_update_env_state() sho...
subroutine pmc_mpi_bcast_integer(val)
Broadcast the given value from process 0 to all other processes.
integer function pmc_mpi_pack_size_integer(val)
Determines the number of bytes required to pack the given value.
subroutine pmc_mpi_unpack_gas_state(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
subroutine pmc_mpi_pack_env_state(buffer, position, val)
Packs the given value into the buffer, advancing position.
subroutine pmc_mpi_unpack_integer(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
integer function pmc_mpi_pack_size_run_part_opt(val)
Determines the number of bytes required to pack the given value.
integer function pmc_mpi_pack_size_aero_data(val)
Determines the number of bytes required to pack the given value.
integer function pmc_mpi_pack_size_gas_data(val)
Determines the number of bytes required to pack the given value.
subroutine spec_file_read_string(file, name, var)
Read a string from a spec file that must have a given name.
subroutine pmc_mpi_bcast_packed(val)
Broadcast the given value from process 0 to all other processes.
subroutine pmc_mpi_unpack_aero_dist(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
subroutine aero_state_set_weight(aero_state, aero_data, weight_type, exponent)
Sets the weighting functions for an aero_state.
subroutine pmc_mpi_finalize()
Shut down MPI.
subroutine pmc_mpi_init()
Initialize MPI.
Aerosol material properties and associated data.
subroutine pmc_mpi_bcast_string(val)
Broadcast the given value from process 0 to all other processes.
subroutine pmc_mpi_pack_gas_state(buffer, position, val)
Packs the given value into the buffer, advancing position.
Common utility subroutines.
The aero_binned_t structure and associated subroutines.
Wrapper functions for MPI.
integer function pmc_mpi_pack_size_gas_state(val)
Determines the number of bytes required to pack the given value.
subroutine pmc_mpi_unpack_run_part_opt(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
subroutine run_part(scenario, env_state, aero_data, aero_state, gas_data, gas_state, run_part_opt)
Do a particle-resolved Monte Carlo simulation.
The scenario_t structure and associated subroutines.