38 use json_module,
only : json_file, json_core, json_value
57 integer,
private :: n_simcomps
61 logical,
private :: finalized = .false.
92 type(
case_t),
target,
intent(inout) :: case
93 character(len=*),
optional,
intent(in) :: simcomp_root
94 integer :: n_simcomps, i
95 type(json_core) :: core
96 type(json_value),
pointer :: simcomp_object
97 type(json_file) :: comp_subdict
98 logical :: found, is_user, has_user
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 call case%params%get_core(core)
120 call case%params%get(root_name, simcomp_object, found)
121 if (.not. found)
return
122 call neko_log%section(
'Initialize simcomp')
125 call case%params%info(root_name, n_children = n_simcomps)
126 this%n_simcomps = n_simcomps
127 allocate(this%simcomps(n_simcomps))
128 allocate(order(n_simcomps))
129 allocate(read_order(n_simcomps))
130 allocate(mask(n_simcomps), source = .true.)
141 has_user = has_user .or. is_user
144 if (read_order(i) .gt. max_order)
then
145 max_order = read_order(i)
152 if (read_order(i) == -1)
then
153 max_order = max_order + 1
154 read_order(i) = max_order
162 loc = minloc(read_order, mask = mask)
172 call json_get(comp_subdict,
"type", comp_type)
174 if (.not. is_user)
call neko_log%message(
'- ' // trim(comp_type))
176 call simulation_component_factory(this%simcomps(i)%simcomp, &
181 call neko_log%message(
'Initialize user simcomp')
183 comp_subdict = json_file(simcomp_object)
184 call case%usr%init_user_simcomp(comp_subdict)
189 deallocate(read_order)
200 if (
allocated(this%simcomps))
then
201 do i = 1, this%n_simcomps
202 call this%simcomps(i)%simcomp%free
204 deallocate(this%simcomps)
214 type(json_file),
intent(inout),
optional :: settings
217 integer :: i, position
221 do i = 1, this%n_simcomps
222 if (.not.
allocated(this%simcomps(i)%simcomp))
then
229 if (position .eq. 0)
then
230 if (this%n_simcomps .gt. 0)
call move_alloc(this%simcomps, tmp_simcomps)
231 allocate(this%simcomps(this%n_simcomps + 1))
233 if (
allocated(tmp_simcomps))
then
234 do i = 1, this%n_simcomps
235 call move_alloc(tmp_simcomps(i)%simcomp, this%simcomps(i)%simcomp)
239 this%n_simcomps = this%n_simcomps + 1
240 position = this%n_simcomps
242 if (
allocated(tmp_simcomps))
deallocate(tmp_simcomps)
245 this%simcomps(position)%simcomp = object
246 if (
present(settings))
then
247 call this%simcomps(position)%simcomp%init(settings, this%case)
250 this%finalized = .false.
260 integer :: i, order, max_order
261 logical :: order_found, previous_found
264 integer,
allocatable :: order_list(:)
267 do i = 1, this%n_simcomps
268 if (.not.
allocated(this%simcomps(i)%simcomp))
then
269 call neko_error(
"Simulation component not initialized.")
274 previous_found = .true.
275 do order = 1, this%n_simcomps
276 order_found = .false.
277 do i = 1, this%n_simcomps
278 if (this%simcomps(i)%simcomp%order == order .and. order_found)
then
279 call neko_error(
"Simulation component order must be unique.")
280 else if (this%simcomps(i)%simcomp%order == order)
then
284 if (order_found .and. .not. previous_found)
then
285 call neko_error(
"Simulation component order must be contiguous &
288 previous_found = order_found
291 allocate(order_list(this%n_simcomps))
294 do i = 1, this%n_simcomps
295 order_list(i) = this%simcomps(i)%simcomp%order
296 if (order_list(i) .gt. max_order)
then
297 max_order = order_list(i)
301 do i = 1, this%n_simcomps
302 if (order_list(i) .eq. -1)
then
303 order_list(i) = max_order + 1
304 max_order = max_order + 1
309 do i = 1, this%n_simcomps
310 if (order_list(i) .gt. this%n_simcomps)
then
311 deallocate(order_list)
312 call neko_error(
"Simulation component order is out of bounds.")
317 call move_alloc(this%simcomps, tmp_simcomps)
318 allocate(this%simcomps(this%n_simcomps))
319 do i = 1, this%n_simcomps
320 order = order_list(i)
321 call move_alloc(tmp_simcomps(i)%simcomp, this%simcomps(order)%simcomp)
324 if (
allocated(tmp_simcomps))
then
325 deallocate(tmp_simcomps)
327 if (
allocated(order_list))
then
328 deallocate(order_list)
331 this%finalized = .true.
339 real(kind=
rp),
intent(in) :: t
340 integer,
intent(in) :: tstep
343 if (.not. this%finalized)
call this%finalize()
345 if (
allocated(this%simcomps))
then
346 do i = 1,
size(this%simcomps)
347 call this%simcomps(i)%simcomp%preprocess(t, tstep)
358 real(kind=
rp),
intent(in) :: t
359 integer,
intent(in) :: tstep
362 if (.not. this%finalized)
call this%finalize()
364 if (
allocated(this%simcomps))
then
365 do i = 1, this%n_simcomps
366 call this%simcomps(i)%simcomp%compute(t, tstep)
376 real(kind=
rp),
intent(in) :: t
379 if (
allocated(this%simcomps))
then
380 do i = 1, this%n_simcomps
381 call this%simcomps(i)%simcomp%restart(t)
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.
type(log_t), public neko_log
Global log stream.
integer, parameter, public rp
Global precision used in computations.
Contains the simcomp_executor_t type.
subroutine simcomp_executor_add(this, object, settings)
Appending a new simcomp to the executor.
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_restart(this, t)
Execute restart for all simcomps.
subroutine simcomp_executor_init(this, case, simcomp_root)
Constructor.
subroutine simcomp_executor_compute(this, t, tstep)
Execute compute_ for all simcomps.
pure integer function simcomp_executor_get_n(this)
Get the number of simcomps.
subroutine simcomp_executor_free(this)
Destructor.
subroutine simcomp_executor_preprocess(this, t, tstep)
Execute preprocess_ for all simcomps.
Simulation components are objects that encapsulate functionality that can be fit to a particular comp...
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.