176 #ifdef PMC_USE_SUNDIALS 180 character(len=300) :: spec_name
187 if (command_argument_count() /= 1)
then 189 call die_msg(739173192,
"invalid commandline arguments")
192 call get_command_argument(1, spec_name)
207 write(*,*)
'Usage: partmc <spec-file>' 217 character(len=*),
intent(in) :: spec_name
220 character(len=100) :: run_type
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")
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)
243 call die_msg(719261940,
"unknown run_type: " // trim(run_type))
251 subroutine partmc_part(file)
267 integer :: i_repeat, i_group
269 character,
allocatable :: buffer(:)
270 integer :: buffer_size, max_buffer_size
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
388 run_part_opt%output_prefix)
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)
407 if (.not. do_restart)
then 408 env_state_init%elapsed_time = 0d0
412 call spec_file_read_gas_data(sub_file, gas_data)
417 call spec_file_read_gas_state(sub_file, gas_data, &
423 call spec_file_read_aero_data(sub_file, aero_data)
426 call spec_file_read_fractal(file, aero_data%fractal)
430 call spec_file_read_aero_dist(sub_file, aero_data, aero_dist_init)
434 call spec_file_read_scenario(file, gas_data, aero_data, scenario)
435 call spec_file_read_env_state(file, env_state_init)
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)
447 run_part_opt%do_condensation)
448 #ifndef PMC_USE_SUNDIALS 450 run_part_opt%do_condensation .eqv. .false., &
451 "cannot use condensation, SUNDIALS support is not compiled in")
453 if (run_part_opt%do_condensation)
then 455 do_init_equilibriate)
457 do_init_equilibriate = .false.
461 if (run_part_opt%do_mosaic .and. (.not. mosaic_support()))
then 463 'cannot use MOSAIC, support is not compiled in')
465 if (run_part_opt%do_mosaic .and. run_part_opt%do_condensation)
then 467 'cannot use MOSAIC and condensation simultaneously')
469 if (run_part_opt%do_mosaic)
then 471 run_part_opt%do_optical)
473 run_part_opt%do_optical = .false.
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)
482 run_part_opt%nucleate_type = nucleate_type_invalid
487 run_part_opt%allow_doubling)
489 run_part_opt%allow_halving)
490 if (.not. do_restart)
then 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)
498 run_part_opt%weighting_exponent = 0.0d0
502 run_part_opt%record_removals)
505 run_part_opt%do_parallel)
506 if (run_part_opt%do_parallel)
then 509 'cannot use parallel mode, support is not compiled in')
511 call spec_file_read_output_type(file, run_part_opt%output_type)
513 run_part_opt%mix_timescale)
515 run_part_opt%gas_average)
517 run_part_opt%env_average)
518 call spec_file_read_parallel_coag_type(file, &
519 run_part_opt%parallel_coag_type)
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.
536 if (.not. do_restart)
then 544 max_buffer_size = max_buffer_size &
546 max_buffer_size = max_buffer_size &
548 max_buffer_size = max_buffer_size &
550 max_buffer_size = max_buffer_size &
552 max_buffer_size = max_buffer_size &
554 max_buffer_size = max_buffer_size &
556 max_buffer_size = max_buffer_size &
558 max_buffer_size = max_buffer_size &
560 max_buffer_size = max_buffer_size &
562 max_buffer_size = max_buffer_size &
564 max_buffer_size = max_buffer_size &
566 max_buffer_size = max_buffer_size &
569 allocate(buffer(max_buffer_size))
584 call assert(181905491, position <= max_buffer_size)
585 buffer_size = position
593 allocate(buffer(buffer_size))
614 call assert(143770146, position == buffer_size)
625 call cpu_time(run_part_opt%t_wall_start)
627 do i_repeat = 1,run_part_opt%n_repeat
628 run_part_opt%i_repeat = i_repeat
630 gas_state = gas_state_init
632 aero_state = aero_state_init
636 aero_mode_type_exp_present &
638 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")
648 run_part_opt%weighting_type, run_part_opt%weighting_exponent)
652 aero_dist_init, 1d0, 0d0, run_part_opt%allow_doubling, &
653 run_part_opt%allow_halving)
655 env_state = env_state_init
657 env_state_init%elapsed_time)
659 #ifdef PMC_USE_SUNDIALS 660 if (do_init_equilibriate)
then 665 call run_part(scenario, env_state, aero_data, aero_state, gas_data, &
666 gas_state, run_part_opt)
672 end subroutine partmc_part
677 subroutine partmc_exact(file)
682 character(len=100) :: soln_name
690 character(len=PMC_MAX_FILENAME_LEN) :: sub_filename
790 call spec_file_read_radius_bin_grid(file, bin_grid)
794 call spec_file_read_gas_data(sub_file, gas_data)
799 call spec_file_read_aero_data(sub_file, aero_data)
802 call spec_file_read_fractal(file, aero_data%fractal)
806 call spec_file_read_aero_dist(sub_file, aero_data, aero_dist_init)
809 call spec_file_read_scenario(file, gas_data, aero_data, scenario)
810 call spec_file_read_env_state(file, env_state)
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)
831 call run_exact(bin_grid, scenario, env_state, aero_data, &
832 aero_dist_init, gas_data, run_exact_opt)
836 end subroutine partmc_exact
841 subroutine partmc_sect(file)
854 character(len=PMC_MAX_FILENAME_LEN) :: sub_filename
944 call spec_file_read_radius_bin_grid(file, bin_grid)
948 call spec_file_read_gas_data(sub_file, gas_data)
953 call spec_file_read_aero_data(sub_file, aero_data)
956 call spec_file_read_fractal(file, aero_data%fractal)
960 call spec_file_read_aero_dist(sub_file, aero_data, aero_dist_init)
963 call spec_file_read_scenario(file, gas_data, aero_data, scenario)
964 call spec_file_read_env_state(file, env_state)
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)
985 call run_sect(bin_grid, gas_data, aero_data, aero_dist_init, scenario, &
986 env_state, run_sect_opt)
990 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.