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 => &
116 procedure, pass(this) :: move_from => &
119 procedure, pass(this) :: is_allocated => &
130 type(json_file),
intent(inout) :: json
131 class(
case_t),
intent(inout),
target :: case
149 module subroutine simulation_component_factory(object, json,
case)
150 class(simulation_component_t),
allocatable,
intent(inout) :: object
151 type(json_file),
intent(inout) :: json
152 class(
case_t),
intent(inout),
target :: case
153 end subroutine simulation_component_factory
160 module subroutine simulation_component_allocator(object, type_name)
161 class(simulation_component_t),
allocatable,
intent(inout) :: object
162 character(len=*),
intent(in):: type_name
163 end subroutine simulation_component_allocator
174 subroutine simulation_component_allocate(obj)
175 import simulation_component_t
176 class(simulation_component_t),
allocatable,
intent(inout) :: obj
177 end subroutine simulation_component_allocate
182 module subroutine register_simulation_component(type_name, allocator)
183 character(len=*),
intent(in) :: type_name
184 procedure(simulation_component_allocate),
pointer,
intent(in) :: &
186 end subroutine register_simulation_component
192 character(len=20) :: type_name
193 procedure(simulation_component_allocate),
pointer,
nopass :: allocator
194 end type allocator_entry
197 type(allocator_entry),
allocatable :: simcomp_registry(:)
200 integer :: simcomp_registry_size = 0
202 public :: simulation_component_factory, simulation_component_allocator, &
203 register_simulation_component, simulation_component_allocate
208 subroutine simulation_component_init_base(this, json, case)
209 class(simulation_component_t),
intent(inout) :: this
210 type(json_file),
intent(inout) :: json
211 class(
case_t),
intent(inout),
target :: case
212 character(len=:),
allocatable :: preprocess_control, compute_control, &
214 real(kind=
rp) :: preprocess_value, compute_value, output_value
217 call this%parse_json(json,
case%params, preprocess_control, &
218 preprocess_value, compute_control, compute_value, output_control, &
223 call this%init_base_from_components(
case, order, &
224 preprocess_control, preprocess_value, compute_control, compute_value, &
225 output_control, output_value)
227 end subroutine simulation_component_init_base
239 subroutine simulation_component_init_base_from_controllers_properties(this, &
240 case, order, preprocess_control, preprocess_value, compute_control, &
241 compute_value, output_control, output_value)
242 class(simulation_component_t),
intent(inout) :: this
243 class(
case_t),
intent(inout),
target :: case
245 character(len=*),
intent(in) :: preprocess_control
246 real(kind=
rp),
intent(in) :: preprocess_value
247 character(len=*),
intent(in) :: compute_control
248 real(kind=
rp),
intent(in) :: compute_value
249 character(len=*),
intent(in) :: output_control
250 real(kind=
rp),
intent(in) :: output_value
255 call this%preprocess_controller%init(
case%time%start_time, &
256 case%time%end_time, preprocess_control, preprocess_value)
257 call this%compute_controller%init(
case%time%start_time,
case%time%end_time,&
258 compute_control, compute_value)
259 call this%output_controller%init(
case%time%start_time,
case%time%end_time, &
260 output_control, output_value)
262 end subroutine simulation_component_init_base_from_controllers_properties
270 subroutine simulation_component_init_base_from_controllers(this, case, order,&
271 preprocess_controller, compute_controller, output_controller)
272 class(simulation_component_t),
intent(inout) :: this
273 class(
case_t),
intent(inout),
target :: case
281 this%preprocess_controller = preprocess_controller
282 this%compute_controller = compute_controller
284 end subroutine simulation_component_init_base_from_controllers
295 subroutine simulation_component_parse_json(this, json, case_params, &
296 preprocess_control, preprocess_value, compute_control, compute_value, &
297 output_control, output_value)
298 class(simulation_component_t),
intent(inout) :: this
299 type(json_file),
intent(inout) :: json
300 type(json_file),
intent(inout) :: case_params
301 character(len=:),
allocatable,
intent(inout) :: preprocess_control
302 real(kind=
rp),
intent(out) :: preprocess_value
303 character(len=:),
allocatable,
intent(inout) :: compute_control
304 real(kind=
rp),
intent(out) :: compute_value
305 character(len=:),
allocatable,
intent(inout) :: output_control
306 real(kind=
rp),
intent(out) :: output_value
307 integer :: preprocess_value_int, compute_value_int, output_value_int
308 character(len=:),
allocatable :: json_path
309 type(json_file) :: json_object
320 json_path =
"preprocess_value"
322 if (preprocess_control .eq.
"fluid_output")
then
323 call json_get(case_params,
'case.fluid.output_control', &
325 json_path =
"case.fluid.output_value"
326 json_object = case_params
330 if ((preprocess_control .eq.
"tsteps") .or. &
331 (preprocess_control .eq.
"nsamples"))
then
334 preprocess_value_int, 1)
335 preprocess_value =
real(preprocess_value_int, kind=
rp)
336 else if (preprocess_control .eq.
"simulationtime")
then
339 preprocess_value, 1.0_rp)
340 else if (preprocess_control .eq.
"never")
then
342 preprocess_value = 0.0_rp
354 json_path =
"compute_value"
356 if (compute_control .eq.
"fluid_output")
then
357 call json_get(case_params,
'case.fluid.output_control', &
359 json_path =
"case.fluid.output_value"
360 json_object = case_params
364 if ((compute_control .eq.
"tsteps") .or. &
365 (compute_control .eq.
"nsamples"))
then
368 compute_value_int, 1)
369 compute_value =
real(compute_value_int, kind=
rp)
370 else if (compute_control .eq.
"simulationtime")
then
373 compute_value, 1.0_rp)
374 compute_value_int = int(compute_value)
375 else if (compute_control .eq.
"never")
then
377 compute_value = 0.0_rp
378 compute_value_int = 0
389 json_path =
"output_value"
391 if (output_control .eq.
"global")
then
392 call json_get(case_params,
'case.fluid.output_control', &
394 json_path =
"case.fluid.output_value"
395 json_object = case_params
400 if ((output_control .eq.
"tsteps") .or. &
401 (output_control .eq.
"nsamples"))
then
404 output_value_int, compute_value_int)
405 output_value =
real(output_value_int, kind=
rp)
406 else if (output_control .eq.
"simulationtime")
then
409 output_value, compute_value)
410 else if (output_control .eq.
"never")
then
412 output_value = 0.0_rp
415 deallocate(json_path)
416 end subroutine simulation_component_parse_json
419 subroutine simulation_component_free_base(this)
420 class(simulation_component_t),
intent(inout) :: this
424 if (
allocated(this%name))
then
425 deallocate(this%name)
428 call this%preprocess_controller%free()
429 call this%compute_controller%free()
430 call this%output_controller%free()
431 end subroutine simulation_component_free_base
436 subroutine simulation_component_preprocess_wrapper(this, time)
437 class(simulation_component_t),
intent(inout) :: this
440 if (this%preprocess_controller%check(time))
then
441 call this%preprocess_(time)
442 call this%preprocess_controller%register_execution()
444 end subroutine simulation_component_preprocess_wrapper
449 subroutine simulation_component_compute_wrapper(this, time)
450 class(simulation_component_t),
intent(inout) :: this
453 if (this%compute_controller%check(time))
then
454 call this%compute_(time)
455 call this%compute_controller%register_execution()
457 end subroutine simulation_component_compute_wrapper
461 subroutine simulation_component_restart_wrapper(this, time)
462 class(simulation_component_t),
intent(inout) :: this
465 call this%compute_controller%set_counter(time)
466 call this%output_controller%set_counter(time)
467 call this%restart_(time)
469 end subroutine simulation_component_restart_wrapper
473 subroutine restart_(this, time)
474 class(simulation_component_t),
intent(inout) :: this
478 end subroutine restart_
482 subroutine preprocess_(this, time)
483 class(simulation_component_t),
intent(inout) :: this
487 end subroutine preprocess_
491 subroutine compute_(this, time)
492 class(simulation_component_t),
intent(inout) :: this
496 end subroutine compute_
502 subroutine simulation_component_wrapper_init(this, json, case)
503 class(simulation_component_wrapper_t),
intent(inout) :: this
504 type(json_file),
intent(inout) :: json
505 class(
case_t),
intent(inout),
target :: case
508 call simulation_component_factory(this%simcomp, json,
case)
510 end subroutine simulation_component_wrapper_init
513 subroutine simulation_component_wrapper_free(this)
514 class(simulation_component_wrapper_t),
intent(inout) :: this
516 if (
allocated(this%simcomp))
then
517 call this%simcomp%free()
518 deallocate(this%simcomp)
521 end subroutine simulation_component_wrapper_free
527 subroutine simulation_component_wrapper_move_from(this, other)
528 class(simulation_component_wrapper_t),
intent(inout) :: this
529 class(simulation_component_wrapper_t),
intent(inout) :: other
532 call move_alloc(other%simcomp, this%simcomp)
534 end subroutine simulation_component_wrapper_move_from
538 function simulation_component_wrapper_is_allocated(this)
result(is_alloc)
539 class(simulation_component_wrapper_t),
intent(in) :: this
541 is_alloc =
allocated(this%simcomp)
542 end function simulation_component_wrapper_is_allocated
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 simulation_component_wrapper_free(this)
Destructor. Just deallocates the pointer.
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_wrapper_init(this, json, case)
Constructor. Initializes the object.
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_wrapper_move_from(this, other)
Move assignment operator for the wrapper, needed for storing simcomps in lists and arrays.
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...
logical function simulation_component_wrapper_is_allocated(this)
Return allocation status.
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.