175 #ifdef PMC_USE_SUNDIALS
179 character(len=300) :: spec_name
186 if (command_argument_count() /= 1)
then
188 call
die_msg(739173192,
"invalid commandline arguments")
191 call get_command_argument(1, spec_name)
206 write(*,*)
'Usage: partmc <spec-file>'
216 character(len=*),
intent(in) :: spec_name
219 character(len=100) :: run_type
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")
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)
242 call
die_msg(719261940,
"unknown run_type: " // trim(run_type))
250 subroutine partmc_part(file)
266 integer :: i_repeat, i_group
268 character,
allocatable :: buffer(:)
269 integer :: buffer_size, max_buffer_size
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
393 run_part_opt%output_prefix)
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)
412 if (.not. do_restart)
then
415 call spec_file_read_gas_data(sub_file, gas_data)
420 call spec_file_read_gas_state(sub_file, gas_data, &
426 call spec_file_read_aero_data(sub_file, aero_data)
431 call spec_file_read_aero_dist(sub_file, aero_data, aero_dist_init)
435 call spec_file_read_scenario(file, gas_data, aero_data, scenario)
436 call spec_file_read_env_state(file, env_state_init)
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)
444 run_part_opt%coag_kernel_type = coag_kernel_type_invalid
448 if (run_part_opt%do_loss)
then
449 call spec_file_read_loss_function_type(file, &
450 run_part_opt%loss_function_type)
452 run_part_opt%loss_function_type = scenario_loss_function_invalid
456 run_part_opt%do_condensation)
457 #ifndef PMC_USE_SUNDIALS
459 run_part_opt%do_condensation .eqv. .false., &
460 "cannot use condensation, SUNDIALS support is not compiled in")
462 if (run_part_opt%do_condensation)
then
464 do_init_equilibriate)
466 do_init_equilibriate = .false.
472 'cannot use MOSAIC, support is not compiled in')
474 if (run_part_opt%do_mosaic .and. run_part_opt%do_condensation)
then
476 'cannot use MOSAIC and condensation simultaneously')
478 if (run_part_opt%do_mosaic)
then
480 run_part_opt%do_optical)
482 run_part_opt%do_optical = .false.
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)
491 run_part_opt%nucleate_type = nucleate_type_invalid
496 run_part_opt%allow_doubling)
498 run_part_opt%allow_halving)
500 run_part_opt%record_removals)
503 run_part_opt%do_parallel)
504 if (run_part_opt%do_parallel)
then
507 'cannot use parallel mode, support is not compiled in')
509 call spec_file_read_output_type(file, run_part_opt%output_type)
511 run_part_opt%mix_timescale)
513 run_part_opt%gas_average)
515 run_part_opt%env_average)
516 call spec_file_read_parallel_coag_type(file, &
517 run_part_opt%parallel_coag_type)
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
534 if (.not. do_restart)
then
542 max_buffer_size = max_buffer_size &
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 &
567 allocate(buffer(max_buffer_size))
582 call
assert(181905491, position <= max_buffer_size)
583 buffer_size = position
591 allocate(buffer(buffer_size))
612 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
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")
645 aero_state_weight_flat)
648 aero_state_weight_nummass_source)
652 aero_dist_init, 1d0, 0d0, run_part_opt%allow_doubling, &
653 run_part_opt%allow_halving)
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)
683 end subroutine partmc_part
688 subroutine partmc_exact(file)
693 character(len=100) :: soln_name
701 character(len=PMC_MAX_FILENAME_LEN) :: sub_filename
802 call spec_file_read_radius_bin_grid(file, bin_grid)
806 call spec_file_read_gas_data(sub_file, gas_data)
811 call spec_file_read_aero_data(sub_file, aero_data)
816 call spec_file_read_aero_dist(sub_file, aero_data, aero_dist_init)
819 call spec_file_read_scenario(file, gas_data, aero_data, scenario)
820 call spec_file_read_env_state(file, env_state)
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)
828 run_exact_opt%coag_kernel_type = coag_kernel_type_invalid
832 if (run_exact_opt%do_loss)
then
833 call spec_file_read_loss_function_type(file, &
834 run_exact_opt%loss_function_type)
836 run_exact_opt%loss_function_type = scenario_loss_function_invalid
849 call
run_exact(bin_grid, scenario, env_state, aero_data, &
850 aero_dist_init, run_exact_opt)
861 end subroutine partmc_exact
866 subroutine partmc_sect(file)
879 character(len=PMC_MAX_FILENAME_LEN) :: sub_filename
970 call spec_file_read_radius_bin_grid(file, bin_grid)
974 call spec_file_read_gas_data(sub_file, gas_data)
979 call spec_file_read_aero_data(sub_file, aero_data)
984 call spec_file_read_aero_dist(sub_file, aero_data, aero_dist_init)
987 call spec_file_read_scenario(file, gas_data, aero_data, scenario)
988 call spec_file_read_env_state(file, env_state)
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)
996 run_sect_opt%coag_kernel_type = coag_kernel_type_invalid
1009 call
run_sect(bin_grid, gas_data, aero_data, aero_dist_init, scenario, &
1010 env_state, run_sect_opt)
1021 end subroutine partmc_sect
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...
subroutine pmc_mpi_unpack_gas_data(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
The scenario_t structure and associated subroutines.
integer function pmc_mpi_pack_size_real(val)
Determines the number of bytes required to pack the given value.
An input file with extra data for printing messages.
subroutine pmc_mpi_pack_logical(buffer, position, val)
Packs the given value into the buffer, advancing position.
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.
The aero_data_t structure and associated subroutines.
integer function pmc_mpi_pack_size_integer(val)
Determines the number of bytes required to pack the given value.
subroutine run_part(scenario, env_state, aero_data, aero_state, gas_data, gas_state, run_part_opt)
Do a particle-resolved Monte Carlo simulation.
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.
subroutine pmc_mpi_pack_gas_data(buffer, position, val)
Packs the given value into the buffer, advancing position.
program partmc
Top level driver.
subroutine partmc_run(spec_name)
Do a PartMC run.
subroutine pmc_mpi_pack_env_state(buffer, position, val)
Packs the given value into the buffer, advancing position.
subroutine pmc_rand_finalize()
Cleanup the random number generator.
subroutine pmc_mpi_unpack_run_part_opt(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
subroutine aero_state_reset(aero_state)
Resets an aero_state to an empty state.
integer function pmc_mpi_pack_size_gas_state(val)
Determines the number of bytes required to pack the given value.
subroutine pmc_mpi_bcast_string(val)
Broadcast the given value from process 0 to all other processes.
subroutine pmc_mpi_unpack_real(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
Options controlling the execution of run_exact().
integer function pmc_mpi_pack_size_aero_dist(val)
Determines the number of bytes required to pack the given value.
subroutine pmc_mpi_pack_aero_data(buffer, position, val)
Packs the given value into the buffer, advancing position.
The aero_dist_t structure and associated subroutines.
subroutine spec_file_open(filename, file)
Open a spec file for reading.
Water condensation onto aerosol particles.
The env_state_t structure and associated subroutines.
subroutine aero_state_allocate(aero_state)
Allocates aerosol arrays.
subroutine scenario_init_env_state(scenario, env_state, time)
Initialize the time-dependent contents of the environment. Thereafter scenario_update_env_state() sho...
integer function pmc_mpi_pack_size_aero_data(val)
Determines the number of bytes required to pack the given value.
subroutine pmc_mpi_pack_gas_state(buffer, position, val)
Packs the given value into the buffer, advancing position.
subroutine assert_msg(code, condition_ok, error_msg)
Errors unless condition_ok is true.
subroutine pmc_mpi_bcast_packed(val)
Broadcast the given value from process 0 to all other processes.
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 aero_dist_deallocate(aero_dist)
Free all storage.
subroutine pmc_mpi_unpack_aero_data(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
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...
integer function pmc_mpi_pack_size_scenario(val)
Determines the number of bytes required to pack the given value.
subroutine pmc_mpi_finalize()
Shut down MPI.
integer function pmc_mpi_pack_size_run_part_opt(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.
subroutine pmc_mpi_init()
Initialize MPI.
subroutine gas_data_deallocate(gas_data)
Free all storage.
subroutine bin_grid_allocate(bin_grid)
Allocates a bin_grid.
subroutine pmc_mpi_pack_integer(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 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...
The gas_data_t structure and associated subroutines.
subroutine aero_state_set_weight(aero_state, aero_data, weight_type, exponent)
Sets the weighting functions for an aero_state.
subroutine aero_data_deallocate(aero_data)
Frees all storage.
subroutine scenario_allocate(scenario)
Allocate an scenario.
A complete aerosol distribution, consisting of several modes.
Common utility subroutines.
Current environment state.
subroutine pmc_mpi_unpack_integer(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
Options controlling the execution of run_part().
logical function mosaic_support()
Whether MOSAIC support is compiled in.
subroutine env_state_deallocate(env_state)
Free all storage.
The aero_state_t structure and assocated subroutines.
subroutine pmc_mpi_unpack_env_state(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
integer function pmc_mpi_rank()
Returns the rank of the current process.
Wrapper functions for MPI.
subroutine pmc_mpi_bcast_integer(val)
Broadcast the given value from process 0 to all other processes.
Options controlling the operation of run_sect().
subroutine gas_state_deallocate(gas_state)
Free all storage.
subroutine run_sect(bin_grid, gas_data, aero_data, aero_dist, scenario, env_state, run_sect_opt)
Run a sectional simulation.
subroutine spec_file_read_string(file, name, var)
Read a string from a spec file that must have a given name.
subroutine pmc_mpi_unpack_logical(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
The gas_state_t structure and associated subroutines.
subroutine gas_state_allocate(gas_state)
Allocate storage for gas species.
subroutine spec_file_read_logical(file, name, var)
Read a logical from a spec file that must have a given name.
The current collection of aerosol particles.
subroutine pmc_mpi_pack_aero_state(buffer, position, val)
Packs the given value into the buffer, advancing position.
1D grid, either logarithmic or linear.
subroutine env_state_copy(env_from, env_to)
env_to = env_from
Exact solution simulation.
The bin_grid_t structure and associated subroutines.
subroutine aero_state_deallocate(aero_state)
Deallocates a previously allocated aerosol.
Reading formatted text input.
subroutine spec_file_close(file)
Close a spec file.
subroutine uuid4_str(uuid)
Generate a version 4 UUID as a string.
elemental logical function aero_dist_contains_aero_mode_type(aero_dist, aero_mode_type)
Whether any of the modes are of the given type.
The aero_binned_t structure and associated subroutines.
subroutine warn_msg(code, warning_msg, already_warned)
Prints a warning message.
subroutine gas_data_allocate(gas_data)
Allocate storage for gas species.
subroutine pmc_mpi_pack_real(buffer, position, val)
Packs the given value into the buffer, advancing position.
subroutine spec_file_die_msg(code, file, msg)
Exit with an error message containing filename and line number.
subroutine pmc_mpi_unpack_aero_dist(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
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.
subroutine print_usage()
Print the usage text to stderr.
subroutine aero_data_allocate(aero_data)
Allocate storage for aero_data.
subroutine pmc_mpi_pack_scenario(buffer, position, val)
Packs the given value into the buffer, advancing position.
subroutine pmc_mpi_pack_aero_dist(buffer, position, val)
Packs the given value into the buffer, advancing position.
integer function pmc_mpi_pack_size_gas_data(val)
Determines the number of bytes required to pack the given value.
subroutine gas_state_allocate_size(gas_state, n_spec)
Allocate storage for gas species of the given size.
subroutine env_state_allocate(env_state)
Allocate an empty environment.
subroutine pmc_mpi_pack_run_part_opt(buffer, position, val)
Packs the given value into the buffer, advancing position.
subroutine spec_file_read_real(file, name, var)
Read a real number from a spec file that must have the given name.
Aerosol material properties and associated data.
subroutine assert(code, condition_ok)
Errors unless condition_ok is true.
subroutine pmc_srand(seed, offset)
Initializes the random number generator to the state defined by the given seed plus offset...
subroutine pmc_mpi_unpack_scenario(buffer, position, val)
Unpacks the given value from the buffer, advancing position.
subroutine run_exact(bin_grid, scenario, env_state, aero_data, aero_dist_init, run_exact_opt)
Run an exact simulation.
subroutine aero_dist_allocate(aero_dist)
Allocates an aero_dist.
subroutine bin_grid_deallocate(bin_grid)
Frees all memory.
integer function pmc_mpi_pack_size_env_state(val)
Determines the number of bytes required to pack the given value.
Generic coagulation kernel.
integer function pmc_mpi_pack_size_logical(val)
Determines the number of bytes required to pack the given value.
subroutine scenario_deallocate(scenario)
Free all storage.
subroutine gas_state_copy(from_state, to_state)
Copy to an already allocated to_state.
subroutine pmc_mpi_unpack_gas_state(buffer, position, val)
Unpacks the given value from the buffer, advancing position.