10 use ai_aerosol,
only : aerosol_t
11 use ai_aerosol_state,
only : aerosol_state_t
12 use ai_wavelength_grid,
only : wavelength_grid_t
23 type(wavelength_grid_t) :: shortwave_grid_
24 type(wavelength_grid_t) :: longwave_grid_
25 type(
mode_t),
allocatable :: modes_(:)
59 use musica_assert,
only : assert_msg
60 use musica_config,
only : config_t
61 use musica_iterator,
only : iterator_t
62 use musica_string,
only : string_t
64 type(
core_t),
pointer :: new_core
65 class(config_t),
intent(inout) :: config
67 character(len=*),
parameter :: my_name =
"MAM core_t constructor"
68 type(config_t) :: modes, mode
69 type(string_t) :: file_name
70 class(iterator_t),
pointer :: iter
72 type(wavelength_grid_t) :: mode_grid
75 call config%get(
"modes", modes, my_name )
76 allocate( new_core%modes_( modes%number_of_children( ) ) )
77 iter => modes%get_iterator( )
79 do while( iter%next( ) )
80 call modes%get( iter, mode, my_name )
81 new_core%modes_( i_mode ) =
mode_t( mode )
82 if( i_mode .eq. 1 )
then
83 new_core%shortwave_grid_ = new_core%modes_( i_mode )%shortwave_grid( )
84 new_core%longwave_grid_ = new_core%modes_( i_mode )%longwave_grid( )
86 call assert_msg( 253107950, new_core%shortwave_grid_ .eq. &
87 new_core%modes_( i_mode )%shortwave_grid( ), &
88 "MAM is not currently set up to use different "// &
89 "shortwave wavelength grids for individual modes." )
90 call assert_msg( 525506880, new_core%longwave_grid_ .eq. &
91 new_core%modes_( i_mode )%longwave_grid( ), &
92 "MAM is not currently set up to use different "// &
93 "longwave wavelength grids for individual modes." )
106 class(aerosol_state_t),
pointer ::
new_state
107 class(
core_t),
intent(in) :: this
109 class(aerosol_state_t),
pointer :: mode_state
115 allocate(
new_state%mode_states_(
size( this%modes_ ) ) )
116 do i_mode = 1,
size( this%modes_ )
117 mode_state => this%modes_( i_mode )%new_state( )
118 select type( mode_state )
120 new_state%mode_states_( i_mode ) = mode_state
122 deallocate( mode_state )
131 function new_optics( this, property, output_grid, interpolation_strategy )
133 use ai_optics,
only : optics_t
134 use ai_wavelength_grid,
only : wavelength_grid_t
136 use musica_interpolator,
only : interpolation_strategy_i
137 use musica_property,
only : property_t
140 class(
core_t),
intent(in) :: this
141 class(property_t),
intent(in) :: property
142 type(wavelength_grid_t),
intent(in) :: output_grid
143 procedure(interpolation_strategy_i),
optional :: interpolation_strategy
146 create_optics( property, this%shortwave_grid_, this%longwave_grid_, &
147 output_grid, interpolation_strategy )
155 aerosol_state, optics )
157 use ai_environmental_state,
only : environmental_state_t
158 use ai_optics,
only : optics_t, optics_ptr
160 class(
core_t),
intent(in) :: this
161 class(environmental_state_t),
intent(in) :: environmental_state
162 class(aerosol_state_t),
intent(in) :: aerosol_state
163 class(optics_t),
target,
intent(inout) :: optics
165 type(optics_ptr) :: optics_set(1)
167 optics_set(1)%ptr_ => optics
168 call this%shortwave_optics( environmental_state, aerosol_state, &
170 nullify( optics_set(1)%ptr_ )
178 aerosol_state, optics )
180 use ai_environmental_state,
only : environmental_state_t
181 use ai_optics,
only : optics_ptr
182 use musica_assert,
only : die_msg
184 class(
core_t),
intent(in) :: this
185 class(environmental_state_t),
intent(in) :: environmental_state
186 class(aerosol_state_t),
intent(in) :: aerosol_state
187 type(optics_ptr),
intent(inout) :: optics(:)
189 integer :: i_mode, i_prop
191 select type( aerosol_state )
193 do i_prop = 1,
size( optics )
194 call optics( i_prop )%ptr_%reset_values( )
196 do i_mode = 1,
size( this%modes_ )
197 associate( mode_state => aerosol_state%mode_states_( i_mode ), &
198 mode => this%modes_( i_mode ) )
199 call mode%add_shortwave_optics( environmental_state, &
205 call die_msg( 822004975,
"Invalid state passed to MAM shortwave "// &
206 "optics calculator" )
215 aerosol_state, optics )
217 use ai_environmental_state,
only : environmental_state_t
218 use ai_optics,
only : optics_t, optics_ptr
220 class(
core_t),
intent(in) :: this
221 class(environmental_state_t),
intent(in) :: environmental_state
222 class(aerosol_state_t),
intent(in) :: aerosol_state
223 class(optics_t),
target,
intent(inout) :: optics
225 type(optics_ptr) :: optics_set(1)
227 optics_set(1)%ptr_ => optics
228 call this%longwave_optics( environmental_state, aerosol_state, &
230 nullify( optics_set(1)%ptr_ )
238 aerosol_state, optics )
240 use ai_environmental_state,
only : environmental_state_t
241 use ai_optics,
only : optics_ptr
242 use musica_assert,
only : die_msg
244 class(
core_t),
intent(in) :: this
245 class(environmental_state_t),
intent(in) :: environmental_state
246 class(aerosol_state_t),
intent(in) :: aerosol_state
247 type(optics_ptr),
intent(inout) :: optics(:)
249 integer :: i_mode, i_prop
251 select type( aerosol_state )
253 do i_prop = 1,
size( optics )
254 call optics( i_prop )%ptr_%reset_values( )
256 do i_mode = 1,
size( this%modes_ )
257 associate( mode_state => aerosol_state%mode_states_( i_mode ), &
258 mode => this%modes_( i_mode ) )
259 call mode%add_longwave_optics( environmental_state, &
265 call die_msg( 466350541,
"Invalid state passed to MAM longwave "// &
266 "optics calculator" )
276 use musica_assert,
only : die_msg
277 use musica_string,
only : to_char
280 class(
core_t),
intent(in) :: this
282 class(aerosol_state_t),
intent(in) :: aerosol_state
284 integer,
optional,
intent(in) :: io_unit
286 integer :: lunit, i_mode
289 if(
present( io_unit ) ) lunit = io_unit
290 select type( aerosol_state )
292 write(lunit,*)
"**** MAM Aerosol State ****"
293 if( .not.
allocated( this%modes_ ) )
then
294 write(lunit,*)
"--- Uninitialized MAM core ---"
295 write(lunit,*)
"**** End MAM Aerosol State ****"
298 if( .not.
allocated( aerosol_state%mode_states_ ) )
then
299 write(lunit,*)
"--- Uninitialized MAM state ---"
300 write(lunit,*)
"**** End MAM Aerosol State ****"
303 do i_mode = 1,
size( this%modes_ )
304 write(lunit,*)
"*** Mode "//trim( to_char( i_mode ) )//
" ***"
305 call this%modes_( i_mode )%print_state( &
306 aerosol_state%mode_states_( i_mode ), io_unit )
308 write(lunit,*)
"**** End MAM Aerosol State ****"
310 call die_msg( 970908819,
"Invalid state passed to MAM aerosol" )
324 class(
state_t),
intent(in) :: this
329 do i_mode = 1,
size( this%mode_states_ )
340 use musica_constants,
only : musica_dk
342 class(
state_t),
intent(inout) :: this
343 real(kind=musica_dk),
intent(in) :: raw_state(:)
344 integer,
optional,
intent(inout) :: index
346 integer :: i_mode, lindex
349 if(
present( index ) ) lindex = index
350 do i_mode = 1,
size( this%mode_states_ )
351 call this%mode_states_( i_mode )%load_state( raw_state, lindex )
353 if(
present( index ) ) index = lindex
362 use musica_constants,
only : musica_dk
364 class(
state_t),
intent(in) :: this
365 real(kind=musica_dk),
intent(inout) :: raw_state(:)
366 integer,
optional,
intent(inout) :: index
368 integer :: i_mode, lindex
371 if(
present( index ) ) lindex = index
372 do i_mode = 1,
size( this%mode_states_ )
373 call this%mode_states_( i_mode )%dump_state( raw_state, lindex )
375 if(
present( index ) ) index = lindex
384 use musica_assert,
only : assert_msg
386 class(
state_t),
intent(inout) :: this
390 call assert_msg( 652075662,
allocated( this%mode_states_ ), &
391 "Trying to randomize uninitialized MAM state" )
392 do i_mode = 1,
size( this%mode_states_ )
393 call this%mode_states_( i_mode )%randomize( )
The core_t type and related functions.
subroutine print_state(this, aerosol_state, io_unit)
Ouptuts the current aerosol state.
subroutine randomize(this)
Sets the MAM state to a random, but reasonable, state. For testing only.
subroutine load_state(this, raw_state, index)
Loads raw MAM state data to the state_t object.
subroutine shortwave_optics_scalar(this, environmental_state, aerosol_state, optics)
Returns shortwave optical properties.
type(core_t) function, pointer constructor(config)
Constructor of the MAM core.
class(optics_t) function, pointer new_optics(this, property, output_grid, interpolation_strategy)
Creates an optics_t object for a given property.
subroutine longwave_optics_scalar(this, environmental_state, aerosol_state, optics)
Returns longwave optical properties.
integer function raw_size(this)
Returns the number of doubles needed to hold the raw MAM aerosol state.
subroutine longwave_optics_array(this, environmental_state, aerosol_state, optics)
Returns longwave optical properties.
class(aerosol_state_t) function, pointer new_state(this)
Creates a new state object for the modal aerosol.
subroutine shortwave_optics_array(this, environmental_state, aerosol_state, optics)
Returns shortwave optical properties.
subroutine dump_state(this, raw_state, index)
Dumps the raw MAM state data to an array.
The mode_t type and related functions.
Constants used to calculate MAM optical properties.
class(optics_t) function, pointer, public create_optics(property, native_shortwave_grid, native_longwave_grid, output_grid, interpolation_strategy)
Returns an optics_t object for a given property.
The species_t type and related functions.
The Modal Aerosol Model core.