40 use json_module,
only : json_file
62 character(:),
allocatable :: name
67 generic :: init_base_from_components => &
68 init_base_from_controllers_properties, &
69 init_base_from_controllers
73 procedure, pass(this) :: init_base_from_controllers => &
78 procedure, pass(this) :: init_base_from_controllers_properties => &
87 procedure, pass(this) :: preprocess => &
119 type(json_file),
intent(inout) :: json
120 class(
case_t),
intent(inout),
target :: case
138 module subroutine simulation_component_factory(object, json,
case)
139 class(simulation_component_t),
allocatable,
intent(inout) :: object
140 type(json_file),
intent(inout) :: json
141 class(
case_t),
intent(inout),
target :: case
142 end subroutine simulation_component_factory
149 module subroutine simulation_component_allocator(object, type_name)
150 class(simulation_component_t),
allocatable,
intent(inout) :: object
151 character(len=*),
intent(in):: type_name
152 end subroutine simulation_component_allocator
163 subroutine simulation_component_allocate(obj)
164 import simulation_component_t
165 class(simulation_component_t),
allocatable,
intent(inout) :: obj
166 end subroutine simulation_component_allocate
171 module subroutine register_simulation_component(type_name, allocator)
172 character(len=*),
intent(in) :: type_name
173 procedure(simulation_component_allocate),
pointer,
intent(in) :: &
175 end subroutine register_simulation_component
181 character(len=20) :: type_name
182 procedure(simulation_component_allocate),
pointer,
nopass :: allocator
183 end type allocator_entry
186 type(allocator_entry),
allocatable :: simcomp_registry(:)
189 integer :: simcomp_registry_size = 0
191 public :: simulation_component_factory, simulation_component_allocator, &
192 register_simulation_component, simulation_component_allocate
197 subroutine simulation_component_init_base(this, json, case)
198 class(simulation_component_t),
intent(inout) :: this
199 type(json_file),
intent(inout) :: json
200 class(
case_t),
intent(inout),
target :: case
201 character(len=:),
allocatable :: preprocess_control, compute_control, &
203 real(kind=
rp) :: preprocess_value, compute_value, output_value
206 call this%parse_json(json,
case%params, preprocess_control, &
207 preprocess_value, compute_control, compute_value, output_control, &
212 call this%init_base_from_components(
case, order, &
213 preprocess_control, preprocess_value, compute_control, compute_value, &
214 output_control, output_value)
216 end subroutine simulation_component_init_base
228 subroutine simulation_component_init_base_from_controllers_properties(this, &
229 case, order, preprocess_control, preprocess_value, compute_control, &
230 compute_value, output_control, output_value)
231 class(simulation_component_t),
intent(inout) :: this
232 class(
case_t),
intent(inout),
target :: case
234 character(len=*),
intent(in) :: preprocess_control
235 real(kind=
rp),
intent(in) :: preprocess_value
236 character(len=*),
intent(in) :: compute_control
237 real(kind=
rp),
intent(in) :: compute_value
238 character(len=*),
intent(in) :: output_control
239 real(kind=
rp),
intent(in) :: output_value
244 call this%preprocess_controller%init(
case%time%start_time, &
245 case%time%end_time, preprocess_control, preprocess_value)
246 call this%compute_controller%init(
case%time%start_time,
case%time%end_time,&
247 compute_control, compute_value)
248 call this%output_controller%init(
case%time%start_time,
case%time%end_time, &
249 output_control, output_value)
251 end subroutine simulation_component_init_base_from_controllers_properties
259 subroutine simulation_component_init_base_from_controllers(this, case, order,&
260 preprocess_controller, compute_controller, output_controller)
261 class(simulation_component_t),
intent(inout) :: this
262 class(
case_t),
intent(inout),
target :: case
270 this%preprocess_controller = preprocess_controller
271 this%compute_controller = compute_controller
273 end subroutine simulation_component_init_base_from_controllers
284 subroutine simulation_component_parse_json(this, json, case_params, &
285 preprocess_control, preprocess_value, compute_control, compute_value, &
286 output_control, output_value)
287 class(simulation_component_t),
intent(inout) :: this
288 type(json_file),
intent(inout) :: json
289 type(json_file),
intent(inout) :: case_params
290 character(len=:),
allocatable,
intent(inout) :: preprocess_control
291 real(kind=
rp),
intent(out) :: preprocess_value
292 character(len=:),
allocatable,
intent(inout) :: compute_control
293 real(kind=
rp),
intent(out) :: compute_value
294 character(len=:),
allocatable,
intent(inout) :: output_control
295 real(kind=
rp),
intent(out) :: output_value
296 integer :: preprocess_value_int, compute_value_int, output_value_int
297 character(len=:),
allocatable :: json_path
298 type(json_file) :: json_object
309 json_path =
"preprocess_value"
311 if (preprocess_control .eq.
"fluid_output")
then
312 call json_get(case_params,
'case.fluid.output_control', &
314 json_path =
"case.fluid.output_value"
315 json_object = case_params
319 if ((preprocess_control .eq.
"tsteps") .or. &
320 (preprocess_control .eq.
"nsamples"))
then
323 preprocess_value_int, 1)
324 preprocess_value =
real(preprocess_value_int, kind=
rp)
325 else if (preprocess_control .eq.
"simulationtime")
then
328 preprocess_value, 1.0_rp)
329 else if (preprocess_control .eq.
"never")
then
331 preprocess_value = 0.0_rp
343 json_path =
"compute_value"
345 if (compute_control .eq.
"fluid_output")
then
346 call json_get(case_params,
'case.fluid.output_control', &
348 json_path =
"case.fluid.output_value"
349 json_object = case_params
353 if ((compute_control .eq.
"tsteps") .or. &
354 (compute_control .eq.
"nsamples"))
then
357 compute_value_int, 1)
358 compute_value =
real(compute_value_int, kind=
rp)
359 else if (compute_control .eq.
"simulationtime")
then
362 compute_value, 1.0_rp)
363 compute_value_int = int(compute_value)
364 else if (compute_control .eq.
"never")
then
366 compute_value = 0.0_rp
367 compute_value_int = 0
378 json_path =
"output_value"
380 if (output_control .eq.
"global")
then
381 call json_get(case_params,
'case.fluid.output_control', &
383 json_path =
"case.fluid.output_value"
384 json_object = case_params
389 if ((output_control .eq.
"tsteps") .or. &
390 (output_control .eq.
"nsamples"))
then
393 output_value_int, compute_value_int)
394 output_value =
real(output_value_int, kind=
rp)
395 else if (output_control .eq.
"simulationtime")
then
398 output_value, compute_value)
399 else if (output_control .eq.
"never")
then
401 output_value = 0.0_rp
404 deallocate(json_path)
405 end subroutine simulation_component_parse_json
408 subroutine simulation_component_free_base(this)
409 class(simulation_component_t),
intent(inout) :: this
413 if (
allocated(this%name))
then
414 deallocate(this%name)
417 call this%preprocess_controller%free()
418 call this%compute_controller%free()
419 call this%output_controller%free()
420 end subroutine simulation_component_free_base
425 subroutine simulation_component_preprocess_wrapper(this, time)
426 class(simulation_component_t),
intent(inout) :: this
429 if (this%preprocess_controller%check(time))
then
430 call this%preprocess_(time)
431 call this%preprocess_controller%register_execution()
433 end subroutine simulation_component_preprocess_wrapper
438 subroutine simulation_component_compute_wrapper(this, time)
439 class(simulation_component_t),
intent(inout) :: this
442 if (this%compute_controller%check(time))
then
443 call this%compute_(time)
444 call this%compute_controller%register_execution()
446 end subroutine simulation_component_compute_wrapper
450 subroutine simulation_component_restart_wrapper(this, time)
451 class(simulation_component_t),
intent(inout) :: this
454 call this%compute_controller%set_counter(time)
455 call this%output_controller%set_counter(time)
456 call this%restart_(time)
458 end subroutine simulation_component_restart_wrapper
462 subroutine restart_(this, time)
463 class(simulation_component_t),
intent(inout) :: this
467 end subroutine restart_
471 subroutine preprocess_(this, time)
472 class(simulation_component_t),
intent(inout) :: this
476 end subroutine preprocess_
480 subroutine compute_(this, time)
481 class(simulation_component_t),
intent(inout) :: this
485 end subroutine compute_
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Retrieves a parameter by name or throws an error.
The common constructor using a JSON dictionary.
Defines a simulation case.
Utilities for retrieving parameters from the case files.
integer, parameter, public rp
Global precision used in computations.
Implements output_controller_t
Simulation components are objects that encapsulate functionality that can be fit to a particular comp...
subroutine simulation_component_free_base(this)
Destructor for the simulation_component_t (base) class.
subroutine restart_(this, time)
Dummy restart function.
subroutine simulation_component_restart_wrapper(this, time)
Wrapper for calling set_counter_ based for the controllers.
subroutine simulation_component_init_base_from_controllers(this, case, order, preprocess_controller, compute_controller, output_controller)
Constructor for the simulation_component_t (base) class from components.
subroutine preprocess_(this, time)
Dummy preprocessing function.
subroutine simulation_component_init_base_from_controllers_properties(this, case, order, preprocess_control, preprocess_value, compute_control, compute_value, output_control, output_value)
Constructor for the simulation_component_t (base) class via the properties of the time_based_controll...
subroutine simulation_component_init_base(this, json, case)
Constructor for the simulation_component_t (base) class.
subroutine compute_(this, time)
Dummy compute function.
subroutine simulation_component_preprocess_wrapper(this, time)
Wrapper for calling preprocess_ based on the preprocess_controller. Serves as the public interface.
subroutine simulation_component_parse_json(this, json, case_params, preprocess_control, preprocess_value, compute_control, compute_value, output_control, output_value)
Parse JSON to determine the properties of the time_based_controllers.
subroutine simulation_component_compute_wrapper(this, time)
Wrapper for calling compute_ based on the compute_controller. Serves as the public interface.
Contains the time_based_controller_t type.
Module with things related to the simulation time.
Base abstract class for simulation components.
A helper type that is needed to have an array of polymorphic objects.
A utility type for determining whether an action should be executed based on the current time value....
A struct that contains all info about the time, expand as needed.