35 use,
intrinsic :: iso_fortran_env, only: error_unit
46 use json_module,
only : json_file
56 type(json_file),
private :: aliases
58 integer,
private :: n_entries_ = 0
60 integer,
private :: n_aliases_ = 0
62 integer,
private :: expansion_size_ = 5
91 procedure, pass(this) :: get_real_scalar_by_name => &
94 procedure, pass(this) :: get_integer_scalar_by_name => &
119 procedure, pass(this) :: integer_scalar_exists => &
168 integer,
optional,
intent(in) :: size
169 integer,
optional,
intent(in) :: expansion_size
173 if (
present(size))
then
174 allocate(this%entries(size))
176 allocate(this%entries(25))
179 call this%aliases%initialize()
181 if (
present(expansion_size))
then
182 this%expansion_size_ = expansion_size
192 if (
allocated(this%entries))
then
193 do i = 1, this%n_entries()
194 call this%entries(i)%free()
196 deallocate(this%entries)
199 call this%aliases%destroy()
203 this%expansion_size_ = 5
211 allocate(temp(this%n_entries_ + this%expansion_size_))
212 temp(1:this%n_entries_) = this%entries(1:this%n_entries_)
213 call move_alloc(temp, this%entries)
226 type(
dofmap_t),
target,
intent(in) :: dof
227 character(len=*),
target,
intent(in) :: name
228 logical,
optional,
intent(in) :: ignore_existing
229 logical :: ignore_existing_
231 ignore_existing_ = .false.
232 if (
present(ignore_existing))
then
233 ignore_existing_ = ignore_existing
236 if (this%field_exists(name))
then
237 if (ignore_existing_)
then
240 call neko_error(
"Field with name " // name // &
241 " is already registered")
245 if (this%n_entries() .eq. this%get_size())
then
249 this%n_entries_ = this%n_entries_ + 1
252 call this%entries(this%n_entries_)%init_field(dof, name)
254 call neko_log%message(
"Field " // trim(name) //
" added to the registry", &
266 integer,
intent(in) :: n
267 character(len=*),
target,
intent(in) :: name
268 logical,
optional,
intent(in) :: ignore_existing
269 logical :: ignore_existing_
271 ignore_existing_ = .false.
272 if (
present(ignore_existing))
then
273 ignore_existing_ = ignore_existing
276 if (this%vector_exists(name))
then
277 if (ignore_existing_)
then
280 call neko_error(
"Vector with name " // name // &
281 " is already registered")
285 if (this%n_entries() .eq. this%get_size())
then
289 this%n_entries_ = this%n_entries_ + 1
292 call this%entries(this%n_entries_)%init_vector(n, name)
294 call neko_log%message(
"Vector " // trim(name) //
" added to the registry", &
306 integer,
intent(in) :: nrows, ncols
307 character(len=*),
target,
intent(in) :: name
308 logical,
optional,
intent(in) :: ignore_existing
309 logical :: ignore_existing_
311 ignore_existing_ = .false.
312 if (
present(ignore_existing))
then
313 ignore_existing_ = ignore_existing
316 if (this%matrix_exists(name))
then
317 if (ignore_existing_)
then
320 call neko_error(
"Vector with name " // name // &
321 " is already registered")
325 if (this%n_entries() .eq. this%get_size())
then
329 this%n_entries_ = this%n_entries_ + 1
332 call this%entries(this%n_entries_)%init_matrix(nrows, ncols, name)
334 call neko_log%message(
"Matrix " // trim(name) //
" added to the registry", &
345 real(kind=
rp),
intent(in) ::
value
346 character(len=*),
target,
intent(in) :: name
347 logical,
optional,
intent(in) :: ignore_existing
348 logical :: ignore_existing_
350 ignore_existing_ = .false.
351 if (
present(ignore_existing))
then
352 ignore_existing_ = ignore_existing
355 if (this%real_scalar_exists(name))
then
356 if (ignore_existing_)
then
359 call neko_error(
"Scalar with name " // name // &
360 " is already registered")
364 if (this%n_entries() .eq. this%get_size())
then
368 this%n_entries_ = this%n_entries_ + 1
371 call this%entries(this%n_entries_)%init_real_scalar(
value, name)
381 integer,
intent(in) :: value
382 character(len=*),
target,
intent(in) :: name
383 logical,
optional,
intent(in) :: ignore_existing
384 logical :: ignore_existing_
386 ignore_existing_ = .false.
387 if (
present(ignore_existing))
then
388 ignore_existing_ = ignore_existing
391 if (this%integer_scalar_exists(name))
then
392 if (ignore_existing_)
then
395 call neko_error(
"Scalar with name " // name // &
396 " is already registered")
400 if (this%n_entries() .eq. this%get_size())
then
404 this%n_entries_ = this%n_entries_ + 1
407 call this%entries(this%n_entries_)%init_integer_scalar(
value, name)
416 character(len=*),
intent(in) :: alias
417 character(len=*),
intent(in) :: name
419 if (this%entry_exists(alias))
then
420 call neko_error(
"Cannot create alias. Entry " // alias // &
421 " already exists in the registry")
424 if (this%entry_exists(name))
then
425 this%n_aliases_ = this%n_aliases_ + 1
426 call this%aliases%add(trim(alias), trim(name))
428 call neko_error(
"Cannot create alias. Entry " // name // &
429 " could not be found in the registry")
438 class(
registry_t),
target,
intent(inout) :: this
439 character(len=*),
intent(in) :: name
440 character(len=:),
allocatable :: alias_target
445 do i = 1, this%n_entries()
446 if (this%entries(i)%get_type() .eq.
'field' .and. &
447 this%entries(i)%get_name() .eq. trim(name))
then
448 f => this%entries(i)%get_field()
453 call this%aliases%get(name, alias_target, found)
455 f => this%get_field_by_name(alias_target)
459 call this%print_contents()
460 call neko_error(
"Field " // name //
" could not be found in the registry")
467 class(
registry_t),
target,
intent(inout) :: this
468 character(len=*),
intent(in) :: name
469 character(len=:),
allocatable :: alias_target
476 do i = 1, this%n_entries()
477 if (this%entries(i)%get_type() .eq.
'vector' .and. &
478 this%entries(i)%get_name() .eq. trim(name))
then
479 f => this%entries(i)%get_vector()
484 call this%aliases%get(name, alias_target, found)
486 f => this%get_vector_by_name(alias_target)
490 call this%print_contents()
491 call neko_error(
"Vector " // name //
" could not be found in the registry")
497 class(
registry_t),
target,
intent(inout) :: this
498 character(len=*),
intent(in) :: name
499 character(len=:),
allocatable :: alias_target
506 do i = 1, this%n_entries()
507 if (this%entries(i)%get_type() .eq.
'matrix' .and. &
508 this%entries(i)%get_name() .eq. trim(name))
then
509 f => this%entries(i)%get_matrix()
514 call this%aliases%get(name, alias_target, found)
516 f => this%get_matrix_by_name(alias_target)
520 call this%print_contents()
521 call neko_error(
"Matrix " // name //
" could not be found in the registry")
527 class(
registry_t),
target,
intent(inout) :: this
528 character(len=*),
intent(in) :: name
529 character(len=:),
allocatable :: alias_target
530 real(kind=
rp),
pointer :: s
536 do i = 1, this%n_entries()
537 if (this%entries(i)%get_type() .eq.
'real_scalar' .and. &
538 this%entries(i)%get_name() .eq. trim(name))
then
539 s => this%entries(i)%get_real_scalar()
544 call this%aliases%get(name, alias_target, found)
546 s => this%get_real_scalar_by_name(alias_target)
550 call this%print_contents()
551 call neko_error(
"Scalar " // name //
" could not be found in the registry")
557 class(
registry_t),
target,
intent(inout) :: this
558 character(len=*),
intent(in) :: name
559 character(len=:),
allocatable :: alias_target
560 integer,
pointer :: s
566 do i = 1, this%n_entries()
567 if (this%entries(i)%get_type() .eq.
'integer_scalar' .and. &
568 this%entries(i)%get_name() .eq. trim(name))
then
569 s => this%entries(i)%get_integer_scalar()
574 call this%aliases%get(name, alias_target, found)
576 s => this%get_integer_scalar_by_name(alias_target)
580 call this%print_contents()
581 call neko_error(
"Integer scalar " // name // &
582 " could not be found in the registry")
591 class(
registry_t),
target,
intent(inout) :: this
592 character(len=*),
intent(in) :: name
597 do i = 1, this%n_entries()
598 if (trim(this%entries(i)%get_name()) .eq. trim(name))
then
604 found = this%aliases%valid_path(name)
609 class(
registry_t),
target,
intent(inout) :: this
610 character(len=*),
intent(in) :: name
615 do i = 1, this%n_entries()
616 if (this%entries(i)%get_type() .eq.
'field' .and. &
617 this%entries(i)%get_name() .eq. trim(name))
then
623 found = this%aliases%valid_path(name)
628 class(
registry_t),
target,
intent(inout) :: this
629 character(len=*),
intent(in) :: name
634 do i = 1, this%n_entries()
635 if (this%entries(i)%get_type() .eq.
'vector' .and. &
636 this%entries(i)%get_name() .eq. trim(name))
then
642 found = this%aliases%valid_path(name)
647 class(
registry_t),
target,
intent(inout) :: this
648 character(len=*),
intent(in) :: name
653 do i = 1, this%n_entries()
654 if (this%entries(i)%get_type() .eq.
'matrix' .and. &
655 this%entries(i)%get_name() .eq. trim(name))
then
661 found = this%aliases%valid_path(name)
666 class(
registry_t),
target,
intent(inout) :: this
667 character(len=*),
intent(in) :: name
672 do i = 1, this%n_entries()
673 if (this%entries(i)%get_type() .eq.
'real_scalar' .and. &
674 this%entries(i)%get_name() .eq. trim(name))
then
680 found = this%aliases%valid_path(name)
685 class(
registry_t),
target,
intent(inout) :: this
686 character(len=*),
intent(in) :: name
691 do i = 1, this%n_entries()
692 if (this%entries(i)%get_type() .eq.
'integer_scalar' .and. &
693 this%entries(i)%get_name() .eq. trim(name))
then
699 found = this%aliases%valid_path(name)
719 do i = 1, this%n_entries()
720 if (this%entries(i)%get_type() .eq.
'field')
then
732 do i = 1, this%n_entries()
733 if (this%entries(i)%get_type() .eq.
'vector')
then
745 do i = 1, this%n_entries()
746 if (this%entries(i)%get_type() .eq.
'matrix')
then
758 do i = 1, this%n_entries()
759 if (this%entries(i)%get_type() .eq.
'real_scalar')
then
771 do i = 1, this%n_entries()
772 if (this%entries(i)%get_type() .eq.
'integer_scalar')
then
791 if (
allocated(this%entries))
then
792 n =
size(this%entries)
803 n = this%expansion_size_
809 character(len=LOG_SIZE),
allocatable :: buffer
812 call neko_log%section(
"Field Registry Contents")
813 do i = 1, this%n_entries()
814 write(
buffer,
'(A,I4,A,A)')
"- [", i,
"] ", &
815 this%entries(i)%get_type(),
": ", this%entries(i)%get_name()
825 character(len=*),
optional,
intent(in) :: type
826 character(len=:),
allocatable :: filter_type
827 character(len=14),
parameter :: types(5) = (/ &
833 logical :: filter_active
835 logical :: known_type
837 filter_active = .false.
838 if (
present(type))
then
839 filter_type = trim(type)
840 filter_active = .true.
842 do i = 1,
size(types)
843 if (filter_type == types(i))
then
848 if (.not. known_type)
then
849 call neko_error(
"registry::print_contents: Unsupported type " &
850 // trim(filter_type))
854 call neko_log%section(
"Registry Contents")
855 do i = 1,
size(types)
856 if (filter_active .and. (filter_type .ne. types(i))) cycle
865 character(len=*),
intent(in) :: entity_type
868 character(len=LOG_SIZE) :: buffer
870 call neko_log%message(
" "//trim(entity_type)//
" entries:")
872 do i = 1, this%n_entries()
873 if (this%entries(i)%get_type() .eq. entity_type)
then
875 write(
buffer,
'(A,I4,A,A)')
" [", i,
"] ", &
876 trim(this%entries(i)%get_name())
880 if (.not. found)
then
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.
integer, parameter, public neko_log_debug
Debug log level.
type(log_t), public neko_log
Global log stream.
integer, parameter, public log_size
integer, parameter, public rp
Global precision used in computations.
Defines a registry entry for storing and requesting temporary objects This is used in the registries ...
real(kind=rp) function, pointer get_real_scalar(this)
Get the real scalar pointer of the registry entry.
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.
integer function, pointer get_integer_scalar(this)
Get the integer scalar pointer of the registry entry.
Defines a registry for storing solution fields.
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.
subroutine registry_add_integer_scalar(this, value, name, ignore_existing)
Add an integer scalar to the registry.
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_print_contents(this, type)
Print the registry contents grouped by entity type.
subroutine registry_init(this, size, expansion_size)
Constructor.
subroutine registry_add_real_scalar(this, value, name, ignore_existing)
Add a real scalar to the registry.
pure integer function registry_get_expansion_size(this)
Get the expansion size.
type(registry_t), target, public neko_const_registry
This registry is used to store user-defined scalars and vectors, provided under the constants section...
pure integer function registry_n_real_scalars(this)
Get the number of real scalars stored in the registry.
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.
subroutine registry_print_section(this, entity_type)
Print a single section of the registry for the given type.
pure integer function registry_n_integer_scalars(this)
Get the number of integer scalars stored in the registry.
logical function registry_entry_exists(this, name)
Check if a field with a given name is already in the registry.
logical function registry_integer_scalar_exists(this, name)
Check if an integer scalar 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 integer function, pointer registry_get_integer_scalar_by_name(this, name)
Get pointer to a stored integer scalar by name.
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.
logical function registry_real_scalar_exists(this, name)
Check if a real scalar with a given name is already in the registry.
recursive real(kind=rp) function, pointer registry_get_real_scalar_by_name(this, name)
Get pointer to a stored real scalar by name.
logical function registry_field_exists(this, name)
Check if a field with a given name is already in the registry.