38 use json_module,
only : json_file
58 integer,
private :: n_simcomps
62 logical,
private :: finalized = .false.
91 type(
case_t),
target,
intent(inout) :: case
92 character(len=*),
optional,
intent(in) :: simcomp_root
93 integer :: n_simcomps, i
94 type(json_file) :: comp_subdict
97 logical,
allocatable :: mask(:)
99 integer,
allocatable :: read_order(:), order(:)
103 character(len=:),
allocatable :: root_name, comp_type
109 if (
present(simcomp_root))
then
110 root_name = simcomp_root
112 root_name =
'case.simulation_components'
116 if (.not. (root_name .in.
case%params))
return
117 call neko_log%section(
'Initialize simcomp')
120 call case%params%info(root_name, n_children = n_simcomps)
121 this%n_simcomps = n_simcomps
122 allocate(this%simcomps(n_simcomps))
123 allocate(order(n_simcomps))
124 allocate(read_order(n_simcomps))
125 allocate(
mask(n_simcomps), source = .true.)
135 if (read_order(i) .gt. max_order)
then
136 max_order = read_order(i)
143 if (read_order(i) == -1)
then
144 max_order = max_order + 1
145 read_order(i) = max_order
153 loc = minloc(read_order,
mask =
mask)
163 call json_get(comp_subdict,
"type", comp_type)
164 call neko_log%message(
'- ' // trim(comp_type))
166 call this%simcomps(i)%init(comp_subdict,
case)
171 deallocate(read_order)
182 if (
allocated(this%simcomps))
then
183 do i = 1, this%n_simcomps
184 call this%simcomps(i)%free()
186 deallocate(this%simcomps)
190 this%finalized = .false.
199 integer :: i, j, order, max_order
200 logical :: order_found, previous_found
203 integer,
allocatable :: order_list(:)
206 do i = 1, this%n_simcomps
207 if (.not. this%simcomps(i)%is_allocated())
then
208 call neko_error(
"Simulation component not initialized.")
213 previous_found = .true.
214 do order = 1, this%n_simcomps
215 order_found = .false.
216 do i = 1, this%n_simcomps
217 if (this%simcomps(i)%simcomp%order == order .and. order_found)
then
218 call neko_error(
"Simulation component order must be unique.")
219 else if (this%simcomps(i)%simcomp%order == order)
then
223 if (order_found .and. .not. previous_found)
then
224 call neko_error(
"Simulation component order must be contiguous " // &
227 previous_found = order_found
230 allocate(order_list(this%n_simcomps))
233 do i = 1, this%n_simcomps
234 order_list(i) = this%simcomps(i)%simcomp%order
235 if (order_list(i) .gt. max_order)
then
236 max_order = order_list(i)
240 do i = 1, this%n_simcomps
241 if (order_list(i) .eq. -1)
then
242 order_list(i) = max_order + 1
243 max_order = max_order + 1
248 do i = 1, this%n_simcomps
249 if (order_list(i) .gt. this%n_simcomps)
then
250 deallocate(order_list)
251 call neko_error(
"Simulation component order is out of bounds.")
256 call move_alloc(this%simcomps, tmp_simcomps)
257 allocate(this%simcomps(this%n_simcomps))
258 do i = 1, this%n_simcomps
259 order = order_list(i)
260 call this%simcomps(order)%move_from(tmp_simcomps(i))
261 call tmp_simcomps(i)%free()
264 if (
allocated(tmp_simcomps))
then
265 deallocate(tmp_simcomps)
267 if (
allocated(order_list))
then
268 deallocate(order_list)
272 do i = 1, this%n_simcomps - 1
273 do j = i + 1, this%n_simcomps
274 associate(simcomp_i => this%simcomps(i)%simcomp, &
275 simcomp_j => this%simcomps(j)%simcomp)
276 if (simcomp_i%name .eq. simcomp_j%name)
then
277 call neko_error(
"Simulation component names must be unique. " &
278 //
"Duplicate name: " // trim(simcomp_i%name))
284 this%finalized = .true.
291 type(time_state_t),
intent(in) :: time
294 if (.not. this%finalized)
call this%finalize()
296 if (
allocated(this%simcomps))
then
297 do i = 1,
size(this%simcomps)
298 call this%simcomps(i)%simcomp%preprocess(time)
308 type(time_state_t),
intent(in) :: time
311 if (.not. this%finalized)
call this%finalize()
313 if (
allocated(this%simcomps))
then
314 do i = 1, this%n_simcomps
315 call this%simcomps(i)%simcomp%compute(time)
325 type(time_state_t),
intent(in) :: time
328 if (
allocated(this%simcomps))
then
329 do i = 1, this%n_simcomps
330 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.
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_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.