35 use,
intrinsic :: iso_fortran_env, only: error_unit
45 use json_module,
only : json_file
55 type(json_file),
private :: aliases
57 integer,
private :: n_entries_ = 0
59 integer,
private :: n_aliases_ = 0
61 integer,
private :: expansion_size_ = 5
82 procedure, pass(this) :: get_vector_by_index => &
85 procedure, pass(this) :: get_matrix_by_index => &
96 generic ::
get_field => get_field_by_index, get_field_by_name
98 generic ::
get_vector => get_vector_by_index, get_vector_by_name
100 generic ::
get_matrix => get_matrix_by_index, get_matrix_by_name
139 integer,
optional,
intent(in) :: size
140 integer,
optional,
intent(in) :: expansion_size
144 if (
present(size))
then
145 allocate(this%entries(size))
147 allocate(this%entries(25))
150 call this%aliases%initialize()
152 if (
present(expansion_size))
then
153 this%expansion_size_ = expansion_size
163 if (
allocated(this%entries))
then
164 do i = 1, this%n_entries()
165 call this%entries(i)%free()
167 deallocate(this%entries)
170 call this%aliases%destroy()
174 this%expansion_size_ = 5
182 allocate(temp(this%n_entries_ + this%expansion_size_))
183 temp(1:this%n_entries_) = this%entries(1:this%n_entries_)
184 call move_alloc(temp, this%entries)
197 type(
dofmap_t),
target,
intent(in) :: dof
198 character(len=*),
target,
intent(in) :: name
199 logical,
optional,
intent(in) :: ignore_existing
200 logical :: ignore_existing_
202 ignore_existing_ = .false.
203 if (
present(ignore_existing))
then
204 ignore_existing_ = ignore_existing
207 if (this%field_exists(name))
then
208 if (ignore_existing_)
then
211 call neko_error(
"Field with name " // name // &
212 " is already registered")
216 if (this%n_entries() .eq. this%get_size())
then
220 this%n_entries_ = this%n_entries_ + 1
223 call this%entries(this%n_entries_)%init_field(dof, name)
234 integer,
intent(in) :: n
235 character(len=*),
target,
intent(in) :: name
236 logical,
optional,
intent(in) :: ignore_existing
237 logical :: ignore_existing_
239 ignore_existing_ = .false.
240 if (
present(ignore_existing))
then
241 ignore_existing_ = ignore_existing
244 if (this%vector_exists(name))
then
245 if (ignore_existing_)
then
248 call neko_error(
"Vector with name " // name // &
249 " is already registered")
253 if (this%n_entries() .eq. this%get_size())
then
257 this%n_entries_ = this%n_entries_ + 1
260 call this%entries(this%n_entries_)%init_vector(n, name)
271 integer,
intent(in) :: nrows, ncols
272 character(len=*),
target,
intent(in) :: name
273 logical,
optional,
intent(in) :: ignore_existing
274 logical :: ignore_existing_
276 ignore_existing_ = .false.
277 if (
present(ignore_existing))
then
278 ignore_existing_ = ignore_existing
281 if (this%matrix_exists(name))
then
282 if (ignore_existing_)
then
285 call neko_error(
"Vector with name " // name // &
286 " is already registered")
290 if (this%n_entries() .eq. this%get_size())
then
294 this%n_entries_ = this%n_entries_ + 1
297 call this%entries(this%n_entries_)%init_matrix(nrows, ncols, name)
306 character(len=*),
intent(in) :: alias
307 character(len=*),
intent(in) :: name
309 if (this%entry_exists(alias))
then
310 call neko_error(
"Cannot create alias. Entry " // alias // &
311 " already exists in the registry")
314 if (this%entry_exists(name))
then
315 this%n_aliases_ = this%n_aliases_ + 1
316 call this%aliases%add(trim(alias), trim(name))
318 call neko_error(
"Cannot create alias. Entry " // name // &
319 " could not be found in the registry")
329 integer,
intent(in) :: i
331 character(len=:),
allocatable ::
buffer
335 else if (i > this%n_entries())
then
336 call neko_error(
"Field index exceeds number of stored fields")
339 if (this%entries(i)%get_type() .ne.
'field')
then
340 write(
buffer, *)
"Requested index ", i,
" is not a field, but a ", &
341 this%entries(i)%get_type()
345 f => this%entries(i)%get_field()
351 integer,
intent(in) :: i
353 character(len=:),
allocatable ::
buffer
357 else if (i > this%n_entries())
then
358 call neko_error(
"Vector index exceeds number of stored vectors")
361 if (this%entries(i)%get_type() .ne.
'vector')
then
362 write(
buffer, *)
"Requested index ", i,
" is not a vector, but a ", &
363 this%entries(i)%get_type()
367 f => this%entries(i)%get_vector()
373 integer,
intent(in) :: i
375 character(len=:),
allocatable ::
buffer
379 else if (i > this%n_entries())
then
380 call neko_error(
"Matrix index exceeds number of stored matrices")
383 if (this%entries(i)%get_type() .ne.
'matrix')
then
384 write(
buffer, *)
"Requested index ", i,
" is not a matrix, but a ", &
385 this%entries(i)%get_type()
389 f => this%entries(i)%get_matrix()
397 class(
registry_t),
target,
intent(inout) :: this
398 character(len=*),
intent(in) :: name
399 character(len=:),
allocatable :: alias_target
404 do i = 1, this%n_entries()
405 if (this%entries(i)%get_type() .eq.
'field' .and. &
406 this%entries(i)%get_name() .eq. trim(name))
then
407 f => this%entries(i)%get_field()
412 call this%aliases%get(name, alias_target, found)
414 f => this%get_field_by_name(alias_target)
419 write(error_unit, *)
"Current registry contents:"
421 do i = 1, this%n_entries()
422 write(error_unit, *)
"- ", this%entries(i)%get_name()
425 call neko_error(
"Field " // name //
" could not be found in the registry")
432 class(
registry_t),
target,
intent(inout) :: this
433 character(len=*),
intent(in) :: name
434 character(len=:),
allocatable :: alias_target
441 do i = 1, this%n_entries()
442 if (this%entries(i)%get_type() .eq.
'vector' .and. &
443 this%entries(i)%get_name() .eq. trim(name))
then
444 f => this%entries(i)%get_vector()
449 call this%aliases%get(name, alias_target, found)
451 f => this%get_vector_by_name(alias_target)
456 write(error_unit, *)
"Current registry contents:"
458 do i = 1, this%n_entries()
459 write(error_unit, *)
"- ", this%entries(i)%get_name()
462 call neko_error(
"Vector " // name //
" could not be found in the registry")
468 class(
registry_t),
target,
intent(inout) :: this
469 character(len=*),
intent(in) :: name
470 character(len=:),
allocatable :: alias_target
477 do i = 1, this%n_entries()
478 if (this%entries(i)%get_type() .eq.
'matrix' .and. &
479 this%entries(i)%get_name() .eq. trim(name))
then
480 f => this%entries(i)%get_matrix()
485 call this%aliases%get(name, alias_target, found)
487 f => this%get_matrix_by_name(alias_target)
492 write(error_unit, *)
"Current registry contents:"
494 do i = 1, this%n_entries()
495 write(error_unit, *)
"- ", this%entries(i)%get_name()
498 call neko_error(
"Matrix " // name //
" could not be found in the registry")
507 class(
registry_t),
target,
intent(inout) :: this
508 character(len=*),
intent(in) :: name
513 do i = 1, this%n_entries()
514 if (trim(this%entries(i)%get_name()) .eq. trim(name))
then
520 found = this%aliases%valid_path(name)
525 class(
registry_t),
target,
intent(inout) :: this
526 character(len=*),
intent(in) :: name
531 do i = 1, this%n_entries()
532 if (this%entries(i)%get_type() .eq.
'field' .and. &
533 this%entries(i)%get_name() .eq. trim(name))
then
539 found = this%aliases%valid_path(name)
544 class(
registry_t),
target,
intent(inout) :: this
545 character(len=*),
intent(in) :: name
550 do i = 1, this%n_entries()
551 if (this%entries(i)%get_type() .eq.
'vector' .and. &
552 this%entries(i)%get_name() .eq. trim(name))
then
558 found = this%aliases%valid_path(name)
563 class(
registry_t),
target,
intent(inout) :: this
564 character(len=*),
intent(in) :: name
569 do i = 1, this%n_entries()
570 if (this%entries(i)%get_type() .eq.
'matrix' .and. &
571 this%entries(i)%get_name() .eq. trim(name))
then
577 found = this%aliases%valid_path(name)
597 do i = 1, this%n_entries()
598 if (this%entries(i)%get_type() .eq.
'field')
then
610 do i = 1, this%n_entries()
611 if (this%entries(i)%get_type() .eq.
'vector')
then
623 do i = 1, this%n_entries()
624 if (this%entries(i)%get_type() .eq.
'matrix')
then
643 if (
allocated(this%entries))
then
644 n =
size(this%entries)
655 n = this%expansion_size_
661 character(len=LOG_SIZE),
allocatable :: buffer
664 call neko_log%section(
"Field Registry Contents")
665 do i = 1, this%n_entries()
666 write(
buffer,
'(A,I4,A,A)')
"- [", i,
"] ", &
667 this%entries(i)%get_type(),
": ", this%entries(i)%get_name()
Retrieves a parameter by name or throws an error.
Generic buffer that is extended with buffers of varying rank.
integer, public pe_rank
MPI rank.
Defines a mapping of the degrees of freedom.
Implements a hash table ADT.
Utilities for retrieving parameters from the case files.
type(log_t), public neko_log
Global log stream.
integer, parameter, public log_size
Defines a registry entry for storing and requesting temporary objects This is used in the scratch reg...
type(field_t) function, pointer get_field(this)
Get the field pointer of the registry entry.
type(vector_t) function, pointer get_vector(this)
Get the vector pointer of the registry entry.
type(matrix_t) function, pointer get_matrix(this)
Get the matrix pointer of the registry entry.
Defines a registry for storing solution fields.
type(matrix_t) function, pointer registry_get_matrix_by_index(this, i)
Get pointer to a stored matrix by index.
type(registry_t), target, public neko_registry
Global field registry.
subroutine registry_free(this)
Destructor.
recursive type(vector_t) function, pointer registry_get_vector_by_name(this, name)
Get pointer to a stored vector by name.
type(vector_t) function, pointer registry_get_vector_by_index(this, i)
Get pointer to a stored vector by index.
pure integer function registry_get_size(this)
Get the size of the fields array.
subroutine registry_print(this)
Print the contents of the registry to standard output.
subroutine registry_add_matrix(this, nrows, ncols, name, ignore_existing)
Add a matrix to the registry.
subroutine registry_init(this, size, expansion_size)
Constructor.
pure integer function registry_get_expansion_size(this)
Get the expansion size.
pure integer function registry_n_vectors(this)
Get the number of vector stored in the registry.
pure integer function registry_n_aliases(this)
Get the number of aliases stored in the registry.
logical function registry_matrix_exists(this, name)
Check if a matrix with a given name is already in the registry.
pure integer function registry_n_fields(this)
Get the number of fields stored in the registry.
subroutine registry_add_alias(this, alias, name)
Add an alias for an existing entry in the registry.
subroutine registry_add_field(this, dof, name, ignore_existing)
Add a field to the registry.
recursive type(matrix_t) function, pointer registry_get_matrix_by_name(this, name)
Get pointer to a stored matrix by name.
logical function registry_entry_exists(this, name)
Check if a field with a given name is already in the registry.
pure integer function registry_n_entries(this)
Get number of registered entries.
subroutine registry_expand(this)
Expand the fields array so as to accommodate more fields.
pure integer function registry_n_matrices(this)
Get the number of matrix stored in the registry.
logical function registry_vector_exists(this, name)
Check if a vector with a given name is already in the registry.
recursive type(field_t) function, pointer registry_get_field_by_name(this, name)
Get pointer to a stored field by field name.
subroutine registry_add_vector(this, n, name, ignore_existing)
Add a vector to the registry.
type(field_t) function, pointer registry_get_field_by_index(this, i)
Get pointer to a stored field by index.
logical function registry_field_exists(this, name)
Check if a field with a given name is already in the registry.