38 use json_module,
only : json_file
58 integer,
private :: n_simcomps
62 logical,
private :: finalized = .false.
93 type(
case_t),
target,
intent(inout) :: case
94 character(len=*),
optional,
intent(in) :: simcomp_root
95 integer :: n_simcomps, i
96 type(json_file) :: comp_subdict
99 logical,
allocatable :: mask(:)
101 integer,
allocatable :: read_order(:), order(:)
105 character(len=:),
allocatable :: root_name, comp_type
111 if (
present(simcomp_root))
then
112 root_name = simcomp_root
114 root_name =
'case.simulation_components'
118 if (.not. (root_name .in.
case%params))
return
119 call neko_log%section(
'Initialize simcomp')
122 call case%params%info(root_name, n_children = n_simcomps)
123 this%n_simcomps = n_simcomps
124 allocate(this%simcomps(n_simcomps))
125 allocate(order(n_simcomps))
126 allocate(read_order(n_simcomps))
127 allocate(
mask(n_simcomps), source = .true.)
137 if (read_order(i) .gt. max_order)
then
138 max_order = read_order(i)
145 if (read_order(i) == -1)
then
146 max_order = max_order + 1
147 read_order(i) = max_order
155 loc = minloc(read_order,
mask =
mask)
165 call json_get(comp_subdict,
"type", comp_type)
166 call neko_log%message(
'- ' // trim(comp_type))
168 call simulation_component_factory(this%simcomps(i)%simcomp, &
174 deallocate(read_order)
185 if (
allocated(this%simcomps))
then
186 do i = 1, this%n_simcomps
187 call this%simcomps(i)%simcomp%free
189 deallocate(this%simcomps)
193 this%finalized = .false.
202 type(json_file),
intent(inout),
optional :: settings
205 integer :: i, position
209 do i = 1, this%n_simcomps
210 if (.not.
allocated(this%simcomps(i)%simcomp))
then
217 if (position .eq. 0)
then
218 if (this%n_simcomps .gt. 0)
call move_alloc(this%simcomps, tmp_simcomps)
219 allocate(this%simcomps(this%n_simcomps + 1))
221 if (
allocated(tmp_simcomps))
then
222 do i = 1, this%n_simcomps
223 call move_alloc(tmp_simcomps(i)%simcomp, this%simcomps(i)%simcomp)
227 this%n_simcomps = this%n_simcomps + 1
228 position = this%n_simcomps
230 if (
allocated(tmp_simcomps))
deallocate(tmp_simcomps)
233 this%simcomps(position)%simcomp = object
234 if (
present(settings))
then
235 call this%simcomps(position)%simcomp%init(settings, this%case)
238 this%finalized = .false.
248 integer :: i, order, max_order
249 logical :: order_found, previous_found
252 integer,
allocatable :: order_list(:)
255 do i = 1, this%n_simcomps
256 if (.not.
allocated(this%simcomps(i)%simcomp))
then
257 call neko_error(
"Simulation component not initialized.")
262 previous_found = .true.
263 do order = 1, this%n_simcomps
264 order_found = .false.
265 do i = 1, this%n_simcomps
266 if (this%simcomps(i)%simcomp%order == order .and. order_found)
then
267 call neko_error(
"Simulation component order must be unique.")
268 else if (this%simcomps(i)%simcomp%order == order)
then
272 if (order_found .and. .not. previous_found)
then
273 call neko_error(
"Simulation component order must be contiguous " // &
276 previous_found = order_found
279 allocate(order_list(this%n_simcomps))
282 do i = 1, this%n_simcomps
283 order_list(i) = this%simcomps(i)%simcomp%order
284 if (order_list(i) .gt. max_order)
then
285 max_order = order_list(i)
289 do i = 1, this%n_simcomps
290 if (order_list(i) .eq. -1)
then
291 order_list(i) = max_order + 1
292 max_order = max_order + 1
297 do i = 1, this%n_simcomps
298 if (order_list(i) .gt. this%n_simcomps)
then
299 deallocate(order_list)
300 call neko_error(
"Simulation component order is out of bounds.")
305 call move_alloc(this%simcomps, tmp_simcomps)
306 allocate(this%simcomps(this%n_simcomps))
307 do i = 1, this%n_simcomps
308 order = order_list(i)
309 call move_alloc(tmp_simcomps(i)%simcomp, this%simcomps(order)%simcomp)
312 if (
allocated(tmp_simcomps))
then
313 deallocate(tmp_simcomps)
315 if (
allocated(order_list))
then
316 deallocate(order_list)
319 this%finalized = .true.
329 if (.not. this%finalized)
call this%finalize()
331 if (
allocated(this%simcomps))
then
332 do i = 1,
size(this%simcomps)
333 call this%simcomps(i)%simcomp%preprocess(time)
346 if (.not. this%finalized)
call this%finalize()
348 if (
allocated(this%simcomps))
then
349 do i = 1, this%n_simcomps
350 call this%simcomps(i)%simcomp%compute(time)
363 if (
allocated(this%simcomps))
then
364 do i = 1, this%n_simcomps
365 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_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.