38 use json_module,
only : json_file
59 integer,
private :: n_simcomps
63 logical,
private :: finalized = .false.
94 type(
case_t),
target,
intent(inout) :: case
95 character(len=*),
optional,
intent(in) :: simcomp_root
96 integer :: n_simcomps, i
97 type(json_file) :: comp_subdict
100 logical,
allocatable :: mask(:)
102 integer,
allocatable :: read_order(:), order(:)
106 character(len=:),
allocatable :: root_name, comp_type
112 if (
present(simcomp_root))
then
113 root_name = simcomp_root
115 root_name =
'case.simulation_components'
119 if (.not. (root_name .in.
case%params))
return
120 call neko_log%section(
'Initialize simcomp')
123 call case%params%info(root_name, n_children = n_simcomps)
124 this%n_simcomps = n_simcomps
125 allocate(this%simcomps(n_simcomps))
126 allocate(order(n_simcomps))
127 allocate(read_order(n_simcomps))
128 allocate(
mask(n_simcomps), source = .true.)
138 if (read_order(i) .gt. max_order)
then
139 max_order = read_order(i)
146 if (read_order(i) == -1)
then
147 max_order = max_order + 1
148 read_order(i) = max_order
156 loc = minloc(read_order,
mask =
mask)
166 call json_get(comp_subdict,
"type", comp_type)
167 call neko_log%message(
'- ' // trim(comp_type))
169 call simulation_component_factory(this%simcomps(i)%simcomp, &
175 deallocate(read_order)
186 if (
allocated(this%simcomps))
then
187 do i = 1, this%n_simcomps
188 call this%simcomps(i)%simcomp%free
190 deallocate(this%simcomps)
200 type(json_file),
intent(inout),
optional :: settings
203 integer :: i, position
207 do i = 1, this%n_simcomps
208 if (.not.
allocated(this%simcomps(i)%simcomp))
then
215 if (position .eq. 0)
then
216 if (this%n_simcomps .gt. 0)
call move_alloc(this%simcomps, tmp_simcomps)
217 allocate(this%simcomps(this%n_simcomps + 1))
219 if (
allocated(tmp_simcomps))
then
220 do i = 1, this%n_simcomps
221 call move_alloc(tmp_simcomps(i)%simcomp, this%simcomps(i)%simcomp)
225 this%n_simcomps = this%n_simcomps + 1
226 position = this%n_simcomps
228 if (
allocated(tmp_simcomps))
deallocate(tmp_simcomps)
231 this%simcomps(position)%simcomp = object
232 if (
present(settings))
then
233 call this%simcomps(position)%simcomp%init(settings, this%case)
236 this%finalized = .false.
246 integer :: i, order, max_order
247 logical :: order_found, previous_found
250 integer,
allocatable :: order_list(:)
253 do i = 1, this%n_simcomps
254 if (.not.
allocated(this%simcomps(i)%simcomp))
then
255 call neko_error(
"Simulation component not initialized.")
260 previous_found = .true.
261 do order = 1, this%n_simcomps
262 order_found = .false.
263 do i = 1, this%n_simcomps
264 if (this%simcomps(i)%simcomp%order == order .and. order_found)
then
265 call neko_error(
"Simulation component order must be unique.")
266 else if (this%simcomps(i)%simcomp%order == order)
then
270 if (order_found .and. .not. previous_found)
then
271 call neko_error(
"Simulation component order must be contiguous " // &
274 previous_found = order_found
277 allocate(order_list(this%n_simcomps))
280 do i = 1, this%n_simcomps
281 order_list(i) = this%simcomps(i)%simcomp%order
282 if (order_list(i) .gt. max_order)
then
283 max_order = order_list(i)
287 do i = 1, this%n_simcomps
288 if (order_list(i) .eq. -1)
then
289 order_list(i) = max_order + 1
290 max_order = max_order + 1
295 do i = 1, this%n_simcomps
296 if (order_list(i) .gt. this%n_simcomps)
then
297 deallocate(order_list)
298 call neko_error(
"Simulation component order is out of bounds.")
303 call move_alloc(this%simcomps, tmp_simcomps)
304 allocate(this%simcomps(this%n_simcomps))
305 do i = 1, this%n_simcomps
306 order = order_list(i)
307 call move_alloc(tmp_simcomps(i)%simcomp, this%simcomps(order)%simcomp)
310 if (
allocated(tmp_simcomps))
then
311 deallocate(tmp_simcomps)
313 if (
allocated(order_list))
then
314 deallocate(order_list)
317 this%finalized = .true.
327 if (.not. this%finalized)
call this%finalize()
329 if (
allocated(this%simcomps))
then
330 do i = 1,
size(this%simcomps)
331 call this%simcomps(i)%simcomp%preprocess(time)
344 if (.not. this%finalized)
call this%finalize()
346 if (
allocated(this%simcomps))
then
347 do i = 1, this%n_simcomps
348 call this%simcomps(i)%simcomp%compute(time)
361 if (
allocated(this%simcomps))
then
362 do i = 1, this%n_simcomps
363 call this%simcomps(i)%simcomp%restart(time)
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.
Defines a simulation case.
Utilities for retrieving parameters from the case files.
subroutine, public json_extract_object(json, name, object)
Extract object as a separate JSON dictionary.
type(log_t), public neko_log
Global log stream.
Object for handling masks in Neko.
integer, parameter, public rp
Global precision used in computations.
Contains the simcomp_executor_t type.
subroutine simcomp_executor_restart(this, time)
Execute restart for all simcomps.
subroutine simcomp_executor_add(this, object, settings)
Appending a new simcomp to the executor.
subroutine simcomp_executor_compute(this, time)
Execute compute_ for all simcomps.
type(simcomp_executor_t), target, public neko_simcomps
Global variable for the simulation component driver.
subroutine simcomp_executor_finalize(this)
Finalize the initialization. Sorts the simcomps based on the order property. Additionally we check th...
subroutine simcomp_executor_init(this, case, simcomp_root)
Constructor.
pure integer function simcomp_executor_get_n(this)
Get the number of simcomps.
subroutine simcomp_executor_preprocess(this, time)
Execute preprocess_ for all simcomps.
subroutine simcomp_executor_free(this)
Destructor.
Simulation components are objects that encapsulate functionality that can be fit to a particular comp...
Module with things related to the simulation time.
Singleton type that serves as a driver for the simulation components. Stores all the components in th...
Base abstract class for simulation components.
A helper type that is needed to have an array of polymorphic objects.
A struct that contains all info about the time, expand as needed.