41 use json_module,
only : json_file
63 character(:),
allocatable :: name
68 generic :: init_base_from_components => &
69 init_base_from_controllers_properties, &
70 init_base_from_controllers
74 procedure, pass(this) :: init_base_from_controllers => &
79 procedure, pass(this) :: init_base_from_controllers_properties => &
88 procedure, pass(this) :: preprocess => &
117 procedure, pass(this) :: move_from => &
120 procedure, pass(this) :: is_allocated => &
131 type(json_file),
intent(inout) :: json
132 class(
case_t),
intent(inout),
target :: case
150 module subroutine simulation_component_factory(object, json,
case)
151 class(simulation_component_t),
allocatable,
intent(inout) :: object
152 type(json_file),
intent(inout) :: json
153 class(
case_t),
intent(inout),
target :: case
154 end subroutine simulation_component_factory
161 module subroutine simulation_component_allocator(object, type_name)
162 class(simulation_component_t),
allocatable,
intent(inout) :: object
163 character(len=*),
intent(in):: type_name
164 end subroutine simulation_component_allocator
175 subroutine simulation_component_allocate(obj)
176 import simulation_component_t
177 class(simulation_component_t),
allocatable,
intent(inout) :: obj
178 end subroutine simulation_component_allocate
183 module subroutine register_simulation_component(type_name, allocator)
184 character(len=*),
intent(in) :: type_name
185 procedure(simulation_component_allocate),
pointer,
intent(in) :: &
187 end subroutine register_simulation_component
193 character(len=NEKO_TYPENAME_LEN) :: type_name
194 procedure(simulation_component_allocate),
pointer,
nopass :: allocator
195 end type allocator_entry
198 type(allocator_entry),
allocatable :: simcomp_registry(:)
201 integer :: simcomp_registry_size = 0
203 public :: simulation_component_factory, simulation_component_allocator, &
204 register_simulation_component, simulation_component_allocate
209 subroutine simulation_component_init_base(this, json, case)
210 class(simulation_component_t),
intent(inout) :: this
211 type(json_file),
intent(inout) :: json
212 class(
case_t),
intent(inout),
target :: case
213 character(len=:),
allocatable :: preprocess_control, compute_control, &
215 real(kind=
dp) :: preprocess_value, compute_value, output_value
218 call this%parse_json(json,
case%params, preprocess_control, &
219 preprocess_value, compute_control, compute_value, output_control, &
224 call this%init_base_from_components(
case, order, &
225 preprocess_control, preprocess_value, compute_control, compute_value, &
226 output_control, output_value)
228 end subroutine simulation_component_init_base
240 subroutine simulation_component_init_base_from_controllers_properties(this, &
241 case, order, preprocess_control, preprocess_value, compute_control, &
242 compute_value, output_control, output_value)
243 class(simulation_component_t),
intent(inout) :: this
244 class(
case_t),
intent(inout),
target :: case
246 character(len=*),
intent(in) :: preprocess_control
247 real(kind=
dp),
intent(in) :: preprocess_value
248 character(len=*),
intent(in) :: compute_control
249 real(kind=
dp),
intent(in) :: compute_value
250 character(len=*),
intent(in) :: output_control
251 real(kind=
dp),
intent(in) :: output_value
256 call this%preprocess_controller%init(
case%time%start_time, &
257 case%time%end_time, preprocess_control, preprocess_value)
258 call this%compute_controller%init(
case%time%start_time,
case%time%end_time,&
259 compute_control, compute_value)
260 call this%output_controller%init(
case%time%start_time,
case%time%end_time, &
261 output_control, output_value)
263 end subroutine simulation_component_init_base_from_controllers_properties
271 subroutine simulation_component_init_base_from_controllers(this, case, order,&
272 preprocess_controller, compute_controller, output_controller)
273 class(simulation_component_t),
intent(inout) :: this
274 class(
case_t),
intent(inout),
target :: case
282 this%preprocess_controller = preprocess_controller
283 this%compute_controller = compute_controller
285 end subroutine simulation_component_init_base_from_controllers
296 subroutine simulation_component_parse_json(this, json, case_params, &
297 preprocess_control, preprocess_value, compute_control, compute_value, &
298 output_control, output_value)
299 class(simulation_component_t),
intent(inout) :: this
300 type(json_file),
intent(inout) :: json
301 type(json_file),
intent(inout) :: case_params
302 character(len=:),
allocatable,
intent(inout) :: preprocess_control
303 real(kind=
dp),
intent(out) :: preprocess_value
304 character(len=:),
allocatable,
intent(inout) :: compute_control
305 real(kind=
dp),
intent(out) :: compute_value
306 character(len=:),
allocatable,
intent(inout) :: output_control
307 real(kind=
dp),
intent(out) :: output_value
308 integer :: preprocess_value_int, compute_value_int, output_value_int
309 character(len=:),
allocatable :: json_path
310 type(json_file) :: json_object
321 json_path =
"preprocess_value"
323 if (preprocess_control .eq.
"fluid_output")
then
324 call json_get(case_params,
'case.fluid.output_control', &
326 json_path =
"case.fluid.output_value"
327 json_object = case_params
331 if ((preprocess_control .eq.
"tsteps") .or. &
332 (preprocess_control .eq.
"nsamples"))
then
335 preprocess_value_int, 1)
336 preprocess_value =
real(preprocess_value_int, kind=
dp)
337 else if (preprocess_control .eq.
"simulationtime")
then
340 preprocess_value, 1.0_dp)
341 else if (preprocess_control .eq.
"never")
then
343 preprocess_value = 0.0_dp
355 json_path =
"compute_value"
357 if (compute_control .eq.
"fluid_output")
then
358 call json_get(case_params,
'case.fluid.output_control', &
360 json_path =
"case.fluid.output_value"
361 json_object = case_params
365 if ((compute_control .eq.
"tsteps") .or. &
366 (compute_control .eq.
"nsamples"))
then
369 compute_value_int, 1)
370 compute_value =
real(compute_value_int, kind=
dp)
371 else if (compute_control .eq.
"simulationtime")
then
374 compute_value, 1.0_dp)
375 compute_value_int = int(compute_value)
376 else if (compute_control .eq.
"never")
then
378 compute_value = 0.0_dp
379 compute_value_int = 0
390 json_path =
"output_value"
392 if (output_control .eq.
"global")
then
393 call json_get(case_params,
'case.fluid.output_control', &
395 json_path =
"case.fluid.output_value"
396 json_object = case_params
401 if ((output_control .eq.
"tsteps") .or. &
402 (output_control .eq.
"nsamples"))
then
405 output_value_int, compute_value_int)
406 output_value =
real(output_value_int, kind=
dp)
407 else if (output_control .eq.
"simulationtime")
then
410 output_value, compute_value)
411 else if (output_control .eq.
"never")
then
413 output_value = 0.0_dp
416 deallocate(json_path)
417 end subroutine simulation_component_parse_json
420 subroutine simulation_component_free_base(this)
421 class(simulation_component_t),
intent(inout) :: this
425 if (
allocated(this%name))
then
426 deallocate(this%name)
429 call this%preprocess_controller%free()
430 call this%compute_controller%free()
431 call this%output_controller%free()
432 end subroutine simulation_component_free_base
437 subroutine simulation_component_preprocess_wrapper(this, time)
438 class(simulation_component_t),
intent(inout) :: this
441 if (this%preprocess_controller%check(time))
then
442 call this%preprocess_(time)
443 call this%preprocess_controller%register_execution(time)
445 end subroutine simulation_component_preprocess_wrapper
450 subroutine simulation_component_compute_wrapper(this, time)
451 class(simulation_component_t),
intent(inout) :: this
454 if (this%compute_controller%check(time))
then
455 call this%compute_(time)
456 call this%compute_controller%register_execution(time)
458 end subroutine simulation_component_compute_wrapper
462 subroutine simulation_component_restart_wrapper(this, time)
463 class(simulation_component_t),
intent(inout) :: this
466 call this%preprocess_controller%set_counter(time)
467 call this%compute_controller%set_counter(time)
468 call this%output_controller%set_counter(time)
469 call this%restart_(time)
471 end subroutine simulation_component_restart_wrapper
475 subroutine restart_(this, time)
476 class(simulation_component_t),
intent(inout) :: this
480 end subroutine restart_
484 subroutine preprocess_(this, time)
485 class(simulation_component_t),
intent(inout) :: this
489 end subroutine preprocess_
493 subroutine compute_(this, time)
494 class(simulation_component_t),
intent(inout) :: this
498 end subroutine compute_
504 subroutine simulation_component_wrapper_init(this, json, case)
505 class(simulation_component_wrapper_t),
intent(inout) :: this
506 type(json_file),
intent(inout) :: json
507 class(
case_t),
intent(inout),
target :: case
510 call simulation_component_factory(this%simcomp, json,
case)
512 end subroutine simulation_component_wrapper_init
515 subroutine simulation_component_wrapper_free(this)
516 class(simulation_component_wrapper_t),
intent(inout) :: this
518 if (
allocated(this%simcomp))
then
519 call this%simcomp%free()
520 deallocate(this%simcomp)
523 end subroutine simulation_component_wrapper_free
529 subroutine simulation_component_wrapper_move_from(this, other)
530 class(simulation_component_wrapper_t),
intent(inout) :: this
531 class(simulation_component_wrapper_t),
intent(inout) :: other
534 call move_alloc(other%simcomp, this%simcomp)
536 end subroutine simulation_component_wrapper_move_from
540 function simulation_component_wrapper_is_allocated(this)
result(is_alloc)
541 class(simulation_component_wrapper_t),
intent(in) :: this
543 is_alloc =
allocated(this%simcomp)
544 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 dp
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.
integer, parameter, public neko_typename_len
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.