42 use json_module,
only : json_file
51 type(json_file),
private :: aliases
53 integer,
private :: n_entries_ = 0
55 integer,
private :: n_aliases_ = 0
57 integer,
private :: expansion_size_ = 5
86 procedure, pass(this) :: get_real_scalar_by_name => &
89 procedure, pass(this) :: get_integer_scalar_by_name => &
114 procedure, pass(this) :: integer_scalar_exists => &
163 integer,
optional,
intent(in) :: size
164 integer,
optional,
intent(in) :: expansion_size
168 if (
present(size))
then
169 allocate(this%entries(size))
171 allocate(this%entries(25))
174 call this%aliases%initialize()
176 if (
present(expansion_size))
then
177 this%expansion_size_ = expansion_size
187 if (
allocated(this%entries))
then
188 do i = 1, this%n_entries()
189 call this%entries(i)%free()
191 deallocate(this%entries)
194 call this%aliases%destroy()
198 this%expansion_size_ = 5
210 call move_alloc(this%entries, temp)
213 allocate(this%entries(n + this%expansion_size_))
217 call this%entries(i)%move_from(temp(i))
222 if (
allocated(temp))
deallocate(temp)
235 type(
dofmap_t),
target,
intent(in) :: dof
236 character(len=*),
target,
intent(in) :: name
237 logical,
optional,
intent(in) :: ignore_existing
238 logical :: ignore_existing_
240 ignore_existing_ = .false.
241 if (
present(ignore_existing))
then
242 ignore_existing_ = ignore_existing
245 if (this%field_exists(name))
then
246 if (ignore_existing_)
then
249 call neko_error(
"Field with name " // name // &
250 " is already registered")
254 if (this%n_entries() .eq. this%get_size())
then
258 this%n_entries_ = this%n_entries_ + 1
261 call this%entries(this%n_entries_)%init_field(dof, name)
263 call neko_log%message(
"Field " // trim(name) //
" added to the registry", &
275 integer,
intent(in) :: n
276 character(len=*),
target,
intent(in) :: name
277 logical,
optional,
intent(in) :: ignore_existing
278 logical :: ignore_existing_
280 ignore_existing_ = .false.
281 if (
present(ignore_existing))
then
282 ignore_existing_ = ignore_existing
285 if (this%vector_exists(name))
then
286 if (ignore_existing_)
then
289 call neko_error(
"Vector with name " // name // &
290 " is already registered")
294 if (this%n_entries() .eq. this%get_size())
then
298 this%n_entries_ = this%n_entries_ + 1
301 call this%entries(this%n_entries_)%init_vector(n, name)
303 call neko_log%message(
"Vector " // trim(name) //
" added to the registry", &
315 integer,
intent(in) :: nrows, ncols
316 character(len=*),
target,
intent(in) :: name
317 logical,
optional,
intent(in) :: ignore_existing
318 logical :: ignore_existing_
320 ignore_existing_ = .false.
321 if (
present(ignore_existing))
then
322 ignore_existing_ = ignore_existing
325 if (this%matrix_exists(name))
then
326 if (ignore_existing_)
then
329 call neko_error(
"Vector with name " // name // &
330 " is already registered")
334 if (this%n_entries() .eq. this%get_size())
then
338 this%n_entries_ = this%n_entries_ + 1
341 call this%entries(this%n_entries_)%init_matrix(nrows, ncols, name)
343 call neko_log%message(
"Matrix " // trim(name) //
" added to the registry", &
354 real(kind=
rp),
intent(in) ::
value
355 character(len=*),
target,
intent(in) :: name
356 logical,
optional,
intent(in) :: ignore_existing
357 logical :: ignore_existing_
359 ignore_existing_ = .false.
360 if (
present(ignore_existing))
then
361 ignore_existing_ = ignore_existing
364 if (this%real_scalar_exists(name))
then
365 if (ignore_existing_)
then
368 call neko_error(
"Scalar with name " // name // &
369 " is already registered")
373 if (this%n_entries() .eq. this%get_size())
then
377 this%n_entries_ = this%n_entries_ + 1
380 call this%entries(this%n_entries_)%init_real_scalar(
value, name)
390 integer,
intent(in) :: value
391 character(len=*),
target,
intent(in) :: name
392 logical,
optional,
intent(in) :: ignore_existing
393 logical :: ignore_existing_
395 ignore_existing_ = .false.
396 if (
present(ignore_existing))
then
397 ignore_existing_ = ignore_existing
400 if (this%integer_scalar_exists(name))
then
401 if (ignore_existing_)
then
404 call neko_error(
"Scalar with name " // name // &
405 " is already registered")
409 if (this%n_entries() .eq. this%get_size())
then
413 this%n_entries_ = this%n_entries_ + 1
416 call this%entries(this%n_entries_)%init_integer_scalar(
value, name)
425 character(len=*),
intent(in) :: alias
426 character(len=*),
intent(in) :: name
428 if (this%entry_exists(alias))
then
429 call neko_error(
"Cannot create alias. Entry " // alias // &
430 " already exists in the registry")
433 if (this%entry_exists(name))
then
434 this%n_aliases_ = this%n_aliases_ + 1
435 call this%aliases%add(trim(alias), trim(name))
437 call neko_error(
"Cannot create alias. Entry " // name // &
438 " could not be found in the registry")
447 class(
registry_t),
target,
intent(inout) :: this
448 character(len=*),
intent(in) :: name
449 character(len=:),
allocatable :: alias_target
454 do i = 1, this%n_entries()
455 if (this%entries(i)%get_type() .eq.
'field' .and. &
456 this%entries(i)%get_name() .eq. trim(name))
then
457 f => this%entries(i)%get_field()
462 call this%aliases%get(name, alias_target, found)
464 f => this%get_field_by_name(alias_target)
468 call this%print_contents()
469 call neko_error(
"Field " // name //
" could not be found in the registry")
476 class(
registry_t),
target,
intent(inout) :: this
477 character(len=*),
intent(in) :: name
478 character(len=:),
allocatable :: alias_target
485 do i = 1, this%n_entries()
486 if (this%entries(i)%get_type() .eq.
'vector' .and. &
487 this%entries(i)%get_name() .eq. trim(name))
then
488 f => this%entries(i)%get_vector()
493 call this%aliases%get(name, alias_target, found)
495 f => this%get_vector_by_name(alias_target)
499 call this%print_contents()
500 call neko_error(
"Vector " // name //
" could not be found in the registry")
506 class(
registry_t),
target,
intent(inout) :: this
507 character(len=*),
intent(in) :: name
508 character(len=:),
allocatable :: alias_target
515 do i = 1, this%n_entries()
516 if (this%entries(i)%get_type() .eq.
'matrix' .and. &
517 this%entries(i)%get_name() .eq. trim(name))
then
518 f => this%entries(i)%get_matrix()
523 call this%aliases%get(name, alias_target, found)
525 f => this%get_matrix_by_name(alias_target)
529 call this%print_contents()
530 call neko_error(
"Matrix " // name //
" could not be found in the registry")
536 class(
registry_t),
target,
intent(inout) :: this
537 character(len=*),
intent(in) :: name
538 character(len=:),
allocatable :: alias_target
539 real(kind=
rp),
pointer :: s
545 do i = 1, this%n_entries()
546 if (this%entries(i)%get_type() .eq.
'real_scalar' .and. &
547 this%entries(i)%get_name() .eq. trim(name))
then
548 s => this%entries(i)%get_real_scalar()
553 call this%aliases%get(name, alias_target, found)
555 s => this%get_real_scalar_by_name(alias_target)
559 call this%print_contents()
560 call neko_error(
"Scalar " // name //
" could not be found in the registry")
566 class(
registry_t),
target,
intent(inout) :: this
567 character(len=*),
intent(in) :: name
568 character(len=:),
allocatable :: alias_target
569 integer,
pointer :: s
575 do i = 1, this%n_entries()
576 if (this%entries(i)%get_type() .eq.
'integer_scalar' .and. &
577 this%entries(i)%get_name() .eq. trim(name))
then
578 s => this%entries(i)%get_integer_scalar()
583 call this%aliases%get(name, alias_target, found)
585 s => this%get_integer_scalar_by_name(alias_target)
589 call this%print_contents()
590 call neko_error(
"Integer scalar " // name // &
591 " could not be found in the registry")
600 class(
registry_t),
target,
intent(inout) :: this
601 character(len=*),
intent(in) :: name
606 do i = 1, this%n_entries()
607 if (trim(this%entries(i)%get_name()) .eq. trim(name))
then
613 found = this%aliases%valid_path(name)
618 class(
registry_t),
target,
intent(inout) :: this
619 character(len=*),
intent(in) :: name
624 do i = 1, this%n_entries()
625 if (this%entries(i)%get_type() .eq.
'field' .and. &
626 this%entries(i)%get_name() .eq. trim(name))
then
632 found = this%aliases%valid_path(name)
637 class(
registry_t),
target,
intent(inout) :: this
638 character(len=*),
intent(in) :: name
643 do i = 1, this%n_entries()
644 if (this%entries(i)%get_type() .eq.
'vector' .and. &
645 this%entries(i)%get_name() .eq. trim(name))
then
651 found = this%aliases%valid_path(name)
656 class(
registry_t),
target,
intent(inout) :: this
657 character(len=*),
intent(in) :: name
662 do i = 1, this%n_entries()
663 if (this%entries(i)%get_type() .eq.
'matrix' .and. &
664 this%entries(i)%get_name() .eq. trim(name))
then
670 found = this%aliases%valid_path(name)
675 class(
registry_t),
target,
intent(inout) :: this
676 character(len=*),
intent(in) :: name
681 do i = 1, this%n_entries()
682 if (this%entries(i)%get_type() .eq.
'real_scalar' .and. &
683 this%entries(i)%get_name() .eq. trim(name))
then
689 found = this%aliases%valid_path(name)
694 class(
registry_t),
target,
intent(inout) :: this
695 character(len=*),
intent(in) :: name
700 do i = 1, this%n_entries()
701 if (this%entries(i)%get_type() .eq.
'integer_scalar' .and. &
702 this%entries(i)%get_name() .eq. trim(name))
then
708 found = this%aliases%valid_path(name)
728 do i = 1, this%n_entries()
729 if (this%entries(i)%get_type() .eq.
'field')
then
741 do i = 1, this%n_entries()
742 if (this%entries(i)%get_type() .eq.
'vector')
then
754 do i = 1, this%n_entries()
755 if (this%entries(i)%get_type() .eq.
'matrix')
then
767 do i = 1, this%n_entries()
768 if (this%entries(i)%get_type() .eq.
'real_scalar')
then
780 do i = 1, this%n_entries()
781 if (this%entries(i)%get_type() .eq.
'integer_scalar')
then
800 if (
allocated(this%entries))
then
801 n =
size(this%entries)
812 n = this%expansion_size_
818 character(len=LOG_SIZE),
allocatable :: buffer
821 call neko_log%section(
"Field Registry Contents")
822 do i = 1, this%n_entries()
823 write(
buffer,
'(A,I4,A,A)')
"- [", i,
"] ", &
824 this%entries(i)%get_type(),
": ", this%entries(i)%get_name()
834 character(len=*),
optional,
intent(in) :: type
835 character(len=:),
allocatable :: filter_type
836 character(len=14),
parameter :: types(5) = (/ &
842 logical :: filter_active
844 logical :: known_type
846 filter_active = .false.
847 if (
present(type))
then
848 filter_type = trim(type)
849 filter_active = .true.
851 do i = 1,
size(types)
852 if (filter_type == types(i))
then
857 if (.not. known_type)
then
858 call neko_error(
"registry::print_contents: Unsupported type " &
859 // trim(filter_type))
863 call neko_log%section(
"Registry Contents")
864 do i = 1,
size(types)
865 if (filter_active .and. (filter_type .ne. types(i))) cycle
874 character(len=*),
intent(in) :: entity_type
877 character(len=LOG_SIZE) :: buffer
879 call neko_log%message(
" "//trim(entity_type)//
" entries:")
881 do i = 1, this%n_entries()
882 if (this%entries(i)%get_type() .eq. entity_type)
then
884 write(
buffer,
'(A,I4,A,A)')
" [", i,
"] ", &
885 trim(this%entries(i)%get_name())
889 if (.not. found)
then
Generic buffer that is extended with buffers of varying rank.
Defines a mapping of the degrees of freedom.
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.