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 => &
94 procedure, pass(this) :: time_to_next => &
120 procedure, pass(this) :: move_from => &
123 procedure, pass(this) :: is_allocated => &
134 type(json_file),
intent(inout) :: json
135 class(
case_t),
intent(inout),
target :: case
153 module subroutine simulation_component_factory(object, json,
case)
154 class(simulation_component_t),
allocatable,
intent(inout) :: object
155 type(json_file),
intent(inout) :: json
156 class(
case_t),
intent(inout),
target :: case
157 end subroutine simulation_component_factory
164 module subroutine simulation_component_allocator(object, type_name)
165 class(simulation_component_t),
allocatable,
intent(inout) :: object
166 character(len=*),
intent(in):: type_name
167 end subroutine simulation_component_allocator
178 subroutine simulation_component_allocate(obj)
179 import simulation_component_t
180 class(simulation_component_t),
allocatable,
intent(inout) :: obj
181 end subroutine simulation_component_allocate
186 module subroutine register_simulation_component(type_name, allocator)
187 character(len=*),
intent(in) :: type_name
188 procedure(simulation_component_allocate),
pointer,
intent(in) :: &
190 end subroutine register_simulation_component
196 character(len=NEKO_TYPENAME_LEN) :: type_name
197 procedure(simulation_component_allocate),
pointer,
nopass :: allocator
198 end type allocator_entry
201 type(allocator_entry),
allocatable :: simcomp_registry(:)
204 integer :: simcomp_registry_size = 0
206 public :: simulation_component_factory, simulation_component_allocator, &
207 register_simulation_component, simulation_component_allocate
212 subroutine simulation_component_init_base(this, json, case)
213 class(simulation_component_t),
intent(inout) :: this
214 type(json_file),
intent(inout) :: json
215 class(
case_t),
intent(inout),
target :: case
216 character(len=:),
allocatable :: preprocess_control, compute_control, &
218 real(kind=
dp) :: preprocess_value, compute_value, output_value
221 call this%parse_json(json,
case%params, preprocess_control, &
222 preprocess_value, compute_control, compute_value, output_control, &
227 call this%init_base_from_components(
case, order, &
228 preprocess_control, preprocess_value, compute_control, compute_value, &
229 output_control, output_value)
231 end subroutine simulation_component_init_base
243 subroutine simulation_component_init_base_from_controllers_properties(this, &
244 case, order, preprocess_control, preprocess_value, compute_control, &
245 compute_value, output_control, output_value)
246 class(simulation_component_t),
intent(inout) :: this
247 class(
case_t),
intent(inout),
target :: case
249 character(len=*),
intent(in) :: preprocess_control
250 real(kind=
dp),
intent(in) :: preprocess_value
251 character(len=*),
intent(in) :: compute_control
252 real(kind=
dp),
intent(in) :: compute_value
253 character(len=*),
intent(in) :: output_control
254 real(kind=
dp),
intent(in) :: output_value
259 call this%preprocess_controller%init(
case%time%start_time, &
260 case%time%end_time, preprocess_control, preprocess_value)
261 call this%compute_controller%init(
case%time%start_time,
case%time%end_time,&
262 compute_control, compute_value)
263 call this%output_controller%init(
case%time%start_time,
case%time%end_time, &
264 output_control, output_value)
266 end subroutine simulation_component_init_base_from_controllers_properties
274 subroutine simulation_component_init_base_from_controllers(this, case, order,&
275 preprocess_controller, compute_controller, output_controller)
276 class(simulation_component_t),
intent(inout) :: this
277 class(
case_t),
intent(inout),
target :: case
285 this%preprocess_controller = preprocess_controller
286 this%compute_controller = compute_controller
288 end subroutine simulation_component_init_base_from_controllers
299 subroutine simulation_component_parse_json(this, json, case_params, &
300 preprocess_control, preprocess_value, compute_control, compute_value, &
301 output_control, output_value)
302 class(simulation_component_t),
intent(inout) :: this
303 type(json_file),
intent(inout) :: json
304 type(json_file),
intent(inout) :: case_params
305 character(len=:),
allocatable,
intent(inout) :: preprocess_control
306 real(kind=
dp),
intent(out) :: preprocess_value
307 character(len=:),
allocatable,
intent(inout) :: compute_control
308 real(kind=
dp),
intent(out) :: compute_value
309 character(len=:),
allocatable,
intent(inout) :: output_control
310 real(kind=
dp),
intent(out) :: output_value
311 integer :: preprocess_value_int, compute_value_int, output_value_int
312 character(len=:),
allocatable :: json_path
313 type(json_file) :: json_object
324 json_path =
"preprocess_value"
326 if (preprocess_control .eq.
"fluid_output")
then
327 call json_get(case_params,
'case.fluid.output_control', &
329 json_path =
"case.fluid.output_value"
330 json_object = case_params
334 if ((preprocess_control .eq.
"tsteps") .or. &
335 (preprocess_control .eq.
"nsamples"))
then
338 preprocess_value_int, 1)
339 preprocess_value =
real(preprocess_value_int, kind=
dp)
340 else if (preprocess_control .eq.
"simulationtime")
then
343 preprocess_value, 1.0_dp)
344 else if (preprocess_control .eq.
"never")
then
346 preprocess_value = 0.0_dp
358 json_path =
"compute_value"
360 if (compute_control .eq.
"fluid_output")
then
361 call json_get(case_params,
'case.fluid.output_control', &
363 json_path =
"case.fluid.output_value"
364 json_object = case_params
368 if ((compute_control .eq.
"tsteps") .or. &
369 (compute_control .eq.
"nsamples"))
then
372 compute_value_int, 1)
373 compute_value =
real(compute_value_int, kind=
dp)
374 else if (compute_control .eq.
"simulationtime")
then
377 compute_value, 1.0_dp)
378 compute_value_int = int(compute_value)
379 else if (compute_control .eq.
"never")
then
381 compute_value = 0.0_dp
382 compute_value_int = 0
393 json_path =
"output_value"
395 if (output_control .eq.
"global")
then
396 call json_get(case_params,
'case.fluid.output_control', &
398 json_path =
"case.fluid.output_value"
399 json_object = case_params
404 if ((output_control .eq.
"tsteps") .or. &
405 (output_control .eq.
"nsamples"))
then
408 output_value_int, compute_value_int)
409 output_value =
real(output_value_int, kind=
dp)
410 else if (output_control .eq.
"simulationtime")
then
413 output_value, compute_value)
414 else if (output_control .eq.
"never")
then
416 output_value = 0.0_dp
419 deallocate(json_path)
420 end subroutine simulation_component_parse_json
423 subroutine simulation_component_free_base(this)
424 class(simulation_component_t),
intent(inout) :: this
428 if (
allocated(this%name))
then
429 deallocate(this%name)
432 call this%preprocess_controller%free()
433 call this%compute_controller%free()
434 call this%output_controller%free()
435 end subroutine simulation_component_free_base
440 subroutine simulation_component_preprocess_wrapper(this, time)
441 class(simulation_component_t),
intent(inout) :: this
444 if (this%preprocess_controller%check(time))
then
445 call this%preprocess_(time)
446 call this%preprocess_controller%register_execution(time)
448 end subroutine simulation_component_preprocess_wrapper
453 subroutine simulation_component_compute_wrapper(this, time)
454 class(simulation_component_t),
intent(inout) :: this
457 if (this%compute_controller%check(time))
then
458 call this%compute_(time)
459 call this%compute_controller%register_execution(time)
461 end subroutine simulation_component_compute_wrapper
469 function simulation_component_time_to_next(this, time) &
471 class(simulation_component_t),
intent(in) :: this
475 t = min(this%preprocess_controller%time_to_next(time), &
476 this%compute_controller%time_to_next(time), &
477 this%output_controller%time_to_next(time))
479 end function simulation_component_time_to_next
483 subroutine simulation_component_restart_wrapper(this, time)
484 class(simulation_component_t),
intent(inout) :: this
487 call this%preprocess_controller%set_counter(time)
488 call this%compute_controller%set_counter(time)
489 call this%output_controller%set_counter(time)
490 call this%restart_(time)
492 end subroutine simulation_component_restart_wrapper
496 subroutine restart_(this, time)
497 class(simulation_component_t),
intent(inout) :: this
501 end subroutine restart_
505 subroutine preprocess_(this, time)
506 class(simulation_component_t),
intent(inout) :: this
510 end subroutine preprocess_
514 subroutine compute_(this, time)
515 class(simulation_component_t),
intent(inout) :: this
519 end subroutine compute_
525 subroutine simulation_component_wrapper_init(this, json, case)
526 class(simulation_component_wrapper_t),
intent(inout) :: this
527 type(json_file),
intent(inout) :: json
528 class(
case_t),
intent(inout),
target :: case
531 call simulation_component_factory(this%simcomp, json,
case)
533 end subroutine simulation_component_wrapper_init
536 subroutine simulation_component_wrapper_free(this)
537 class(simulation_component_wrapper_t),
intent(inout) :: this
539 if (
allocated(this%simcomp))
then
540 call this%simcomp%free()
541 deallocate(this%simcomp)
544 end subroutine simulation_component_wrapper_free
550 subroutine simulation_component_wrapper_move_from(this, other)
551 class(simulation_component_wrapper_t),
intent(inout) :: this
552 class(simulation_component_wrapper_t),
intent(inout) :: other
555 call move_alloc(other%simcomp, this%simcomp)
557 end subroutine simulation_component_wrapper_move_from
561 function simulation_component_wrapper_is_allocated(this)
result(is_alloc)
562 class(simulation_component_wrapper_t),
intent(in) :: this
564 is_alloc =
allocated(this%simcomp)
565 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.
real(kind=dp) function simulation_component_time_to_next(this, time)
The time until the next scheduled execution of preprocess, compute or the output, whichever comes fir...
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.