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
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 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.)
139 has_user = has_user .or. is_user
142 if (read_order(i) .gt. max_order)
then
143 max_order = read_order(i)
150 if (read_order(i) == -1)
then
151 max_order = max_order + 1
152 read_order(i) = max_order
160 loc = minloc(read_order, mask = mask)
170 call json_get(comp_subdict,
"type", comp_type)
172 if (.not. is_user)
call neko_log%message(
'- ' // trim(comp_type))
174 call simulation_component_factory(this%simcomps(i)%simcomp, &
179 call neko_log%message(
'Initialize user simcomp')
182 call case%usr%init_user_simcomp(comp_subdict)
187 deallocate(read_order)
198 if (
allocated(this%simcomps))
then
199 do i = 1, this%n_simcomps
200 call this%simcomps(i)%simcomp%free
202 deallocate(this%simcomps)
212 type(json_file),
intent(inout),
optional :: settings
215 integer :: i, position
219 do i = 1, this%n_simcomps
220 if (.not.
allocated(this%simcomps(i)%simcomp))
then
227 if (position .eq. 0)
then
228 if (this%n_simcomps .gt. 0)
call move_alloc(this%simcomps, tmp_simcomps)
229 allocate(this%simcomps(this%n_simcomps + 1))
231 if (
allocated(tmp_simcomps))
then
232 do i = 1, this%n_simcomps
233 call move_alloc(tmp_simcomps(i)%simcomp, this%simcomps(i)%simcomp)
237 this%n_simcomps = this%n_simcomps + 1
238 position = this%n_simcomps
240 if (
allocated(tmp_simcomps))
deallocate(tmp_simcomps)
243 this%simcomps(position)%simcomp = object
244 if (
present(settings))
then
245 call this%simcomps(position)%simcomp%init(settings, this%case)
248 this%finalized = .false.
258 integer :: i, order, max_order
259 logical :: order_found, previous_found
262 integer,
allocatable :: order_list(:)
265 do i = 1, this%n_simcomps
266 if (.not.
allocated(this%simcomps(i)%simcomp))
then
267 call neko_error(
"Simulation component not initialized.")
272 previous_found = .true.
273 do order = 1, this%n_simcomps
274 order_found = .false.
275 do i = 1, this%n_simcomps
276 if (this%simcomps(i)%simcomp%order == order .and. order_found)
then
277 call neko_error(
"Simulation component order must be unique.")
278 else if (this%simcomps(i)%simcomp%order == order)
then
282 if (order_found .and. .not. previous_found)
then
283 call neko_error(
"Simulation component order must be contiguous " // &
286 previous_found = order_found
289 allocate(order_list(this%n_simcomps))
292 do i = 1, this%n_simcomps
293 order_list(i) = this%simcomps(i)%simcomp%order
294 if (order_list(i) .gt. max_order)
then
295 max_order = order_list(i)
299 do i = 1, this%n_simcomps
300 if (order_list(i) .eq. -1)
then
301 order_list(i) = max_order + 1
302 max_order = max_order + 1
307 do i = 1, this%n_simcomps
308 if (order_list(i) .gt. this%n_simcomps)
then
309 deallocate(order_list)
310 call neko_error(
"Simulation component order is out of bounds.")
315 call move_alloc(this%simcomps, tmp_simcomps)
316 allocate(this%simcomps(this%n_simcomps))
317 do i = 1, this%n_simcomps
318 order = order_list(i)
319 call move_alloc(tmp_simcomps(i)%simcomp, this%simcomps(order)%simcomp)
322 if (
allocated(tmp_simcomps))
then
323 deallocate(tmp_simcomps)
325 if (
allocated(order_list))
then
326 deallocate(order_list)
329 this%finalized = .true.
339 if (.not. this%finalized)
call this%finalize()
341 if (
allocated(this%simcomps))
then
342 do i = 1,
size(this%simcomps)
343 call this%simcomps(i)%simcomp%preprocess(time)
356 if (.not. this%finalized)
call this%finalize()
358 if (
allocated(this%simcomps))
then
359 do i = 1, this%n_simcomps
360 call this%simcomps(i)%simcomp%compute(time)
373 if (
allocated(this%simcomps))
then
374 do i = 1, this%n_simcomps
375 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.
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.