CAMP 1.0.0
Chemistry Across Multiple Phases
part_3_code/box_model.F90
Go to the documentation of this file.
1program box_model
2
7
8 !! [NO2 photolysis modules]
13
14 !! [NO2 photolysis modules]
15
16#ifdef CAMP_USE_MPI
17 use mpi
18 use camp_mpi
19#endif
20
21 implicit none
22
23 type(camp_core_t), pointer :: camp_core
24 type(camp_state_t), pointer :: camp_state
25
26 integer(kind=i_kind) :: idx_o3, idx_no, idx_no2, idx_o2
27 type(chem_spec_data_t), pointer :: chem_spec_data
28
29 character(len=*), parameter :: fmt_hdr = "(A10,',',A10,',',A10,',',A10,',',A10)"
30 character(len=*), parameter :: fmt_dat = "(ES10.4,',',ES10.4,',',ES10.4,',',ES10.4,',',ES10.4)"
31
32 integer(kind=i_kind) :: i_time
33
34 !! [NO2 photolysis variables]
35 integer(kind=i_kind) :: i_rxn
36 character(len=:), allocatable :: photo_label
37 type(mechanism_data_t), pointer :: mechanism
38 type(rxn_factory_t) :: rxn_factory
39 class(rxn_data_t), pointer :: photo_rxn
40 type(rxn_update_data_photolysis_t) :: no2_photolysis
41
42 !! [NO2 photolysis variables]
43
44 ! allows example to run with MPI supprt compiled in
45#ifdef CAMP_USE_MPI
46 call camp_mpi_init( )
47#endif
48
49 camp_core => camp_core_t( "my_config_file.json" )
50 call camp_core%initialize( )
51
52 if( .not.camp_core%get_chem_spec_data( chem_spec_data ) ) then
53 write(*,*) "Something's gone wrong!"
54 stop 3
55 end if
56
57 idx_o3 = chem_spec_data%gas_state_id( "O3" )
58 idx_no = chem_spec_data%gas_state_id( "NO" )
59 idx_no2 = chem_spec_data%gas_state_id( "NO2" )
60 idx_o2 = chem_spec_data%gas_state_id( "O2" )
61 if( idx_o3.eq.0 .or. idx_no2.eq.0 .or.idx_o2.eq.0 ) then
62 write(*,*) "Missing species!"
63 stop 3
64 end if
65
66 !! [Find NO2 photolysis]
67 if( .not.camp_core%get_mechanism( "my simple mechanism", mechanism ) ) then
68 write(*,*) "Missing mechanism!"
69 stop 3
70 end if
71
72 do i_rxn = 1, mechanism%size( )
73 photo_rxn => mechanism%get_rxn( i_rxn )
74 select type( photo_rxn )
75 class is( rxn_photolysis_t )
76 if( photo_rxn%property_set%get_string( "my photo label", photo_label ) ) then
77 if( photo_label .eq. "NO2 photolysis" ) then
78 call camp_core%initialize_update_object( photo_rxn, no2_photolysis )
79 end if
80 end if
81 end select
82 end do
83 !! [Find NO2 photolysis]
84
85 call camp_core%solver_initialize( )
86 camp_state => camp_core%new_state( )
87
88 call camp_state%env_states(1)%set_temperature_K( 275.4_dp )
89 call camp_state%env_states(1)%set_pressure_Pa( 101532.2_dp )
90
91 camp_state%state_var( idx_o3 ) = 0.13 ! [O3] in ppm
92 camp_state%state_var( idx_no ) = 0.02 ! [NO] in ppm
93 camp_state%state_var( idx_no2 ) = 0.053 ! [NO2] in ppm
94 camp_state%state_var( idx_o2 ) = 2.1e5 ! [O2] in ppm
95
96 !! [Set NO2 photolysis]
97 call no2_photolysis%set_rate( 12.2d0 ) ! rate in s-1
98 call camp_core%update_data( no2_photolysis )
99 !! [Set NO2 photolysis]
100
101 write(*,fmt_hdr) "time", "O3", "NO", "NO2", "O2"
102 do i_time = 1, 100
103 call camp_core%solve( camp_state, 1.0d-15 ) ! time step in s
104 write(*,fmt_dat) i_time*1.0e-15, &
105 camp_state%state_var( idx_o3 ), &
106 camp_state%state_var( idx_no ), &
107 camp_state%state_var( idx_no2 ), &
108 camp_state%state_var( idx_o2 )
109 end do
110
111 deallocate( camp_core )
112 deallocate( camp_state )
113
114#ifdef CAMP_USE_MPI
115 call camp_mpi_finalize( )
116#endif
117
118end program box_model
The camp_core_t structure and associated subroutines.
Definition camp_core.F90:87
The camp_state_t structure and associated subroutines.
Definition camp_state.F90:9
The chem_spec_data_t structure and associated subroutines.
Physical constants.
Definition constants.F90:9
The mechanism_data_t structure and associated subroutines.
Wrapper functions for MPI.
Definition mpi.F90:13
subroutine camp_mpi_init()
Initialize MPI.
Definition mpi.F90:58
subroutine camp_mpi_finalize()
Shut down MPI.
Definition mpi.F90:91
The rxn_data_t structure and associated subroutines.
Definition rxn_data.F90:60
The abstract rxn_factory_t structure and associated subroutines.
The rxn_photolysis_t type and associated functions.
program box_model
Part-MC model data.
Abstract reaction data type.
Definition rxn_data.F90:98
Factory type for chemical reactions.
Generic test reaction data type.