Neko 1.99.2
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
registry_entry.f90
Go to the documentation of this file.
1! Copyright (c) 2025, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
37 use field, only : field_t
38 use vector, only : vector_t
39 use matrix, only : matrix_t
40
41 use dofmap, only : dofmap_t
42 use utils, only : neko_error
43 implicit none
44 private
45
46 type, public :: registry_entry_t
47
48 character(len=:), private, allocatable :: name
49 character(len=:), private, allocatable :: type
50 logical, private :: allocated = .false.
51
52 type(field_t), private, pointer :: field_ptr => null()
53 type(vector_t), private, pointer :: vector_ptr => null()
54 type(matrix_t), private, pointer :: matrix_ptr => null()
55
56 contains
57 procedure, pass(this) :: init_field => init_register_field
58 procedure, pass(this) :: init_vector => init_register_vector
59 procedure, pass(this) :: init_matrix => init_register_matrix
60 procedure, pass(this) :: free => free_register
61
62 procedure, pass(this) :: get_name
63 procedure, pass(this) :: get_type
64 procedure, pass(this) :: get_field
65 procedure, pass(this) :: get_vector
66 procedure, pass(this) :: get_matrix
67 procedure, pass(this) :: is_allocated
68 end type registry_entry_t
69
70contains
71
73 subroutine init_register_field(this, dof, name)
74 class(registry_entry_t), intent(inout) :: this
75 type(dofmap_t), target, intent(in) :: dof
76 character(len=*), intent(in) :: name
77
78 if (this%allocated) then
79 call neko_error("scratch_registry::init_register_field: " &
80 // "Register entry is already allocated.")
81 end if
82
83 call this%free()
84
85 allocate(this%field_ptr)
86 call this%field_ptr%init(dof, trim(name))
87
88 this%name = trim(name)
89 this%type = 'field'
90 this%allocated = .true.
91
92 end subroutine init_register_field
93
95 subroutine init_register_vector(this, n, name)
96 class(registry_entry_t), intent(inout) :: this
97 integer, intent(in) :: n
98 character(len=*), optional, intent(in) :: name
99
100 if (this%allocated) then
101 call neko_error("scratch_registry::init_register_vector: " &
102 // "Register entry is already allocated.")
103 end if
104
105 call this%free()
106
107 allocate(this%vector_ptr)
108 call this%vector_ptr%init(n)
109
110 if (present(name)) this%name = trim(name)
111 this%type = 'vector'
112 this%allocated = .true.
113
114 end subroutine init_register_vector
115
117 subroutine init_register_matrix(this, nrows, ncols, name)
118 class(registry_entry_t), intent(inout) :: this
119 integer, intent(in) :: nrows, ncols
120 character(len=*), optional, intent(in) :: name
121
122 if (this%allocated) then
123 call neko_error("scratch_registry::init_register_matrix: " &
124 // "Register entry is already allocated.")
125 end if
126
127 call this%free()
128
129 allocate(this%matrix_ptr)
130 call this%matrix_ptr%init(nrows, ncols)
131
132 if (present(name)) this%name = trim(name)
133 this%type = 'matrix'
134 this%allocated = .true.
135
136 end subroutine init_register_matrix
137
139 subroutine free_register(this)
140 class(registry_entry_t), intent(inout) :: this
141
142 if (associated(this%field_ptr)) then
143 call this%field_ptr%free()
144 deallocate(this%field_ptr)
145 end if
146
147 if (associated(this%vector_ptr)) then
148 call this%vector_ptr%free()
149 deallocate(this%vector_ptr)
150 end if
151
152 if (associated(this%matrix_ptr)) then
153 call this%matrix_ptr%free()
154 deallocate(this%matrix_ptr)
155 end if
156
157 if (allocated(this%name)) deallocate(this%name)
158 if (allocated(this%type)) deallocate(this%type)
159 this%allocated = .false.
160
161 end subroutine free_register
162
164 pure function get_name(this) result(name)
165 class(registry_entry_t), intent(in) :: this
166 character(len=:), allocatable :: name
167 name = trim(this%name)
168 end function get_name
169
171 pure function get_type(this) result(type)
172 class(registry_entry_t), intent(in) :: this
173 character(len=:), allocatable :: type
174 type = trim(this%type)
175 end function get_type
176
178 pure function is_allocated(this) result(allocated)
179 class(registry_entry_t), intent(in) :: this
180 logical :: allocated
181 allocated = this%allocated
182 end function is_allocated
183
185 function get_field(this) result(field_ptr)
186 class(registry_entry_t), target, intent(in) :: this
187 type(field_t), pointer :: field_ptr
188 if (this%get_type() .ne. 'field') then
189 call neko_error("registry_entry::get_field: " &
190 // "Registry entry is not of type 'field'.")
191 end if
192 field_ptr => this%field_ptr
193 end function get_field
194
196 function get_vector(this) result(vector_ptr)
197 class(registry_entry_t), target, intent(in) :: this
198 type(vector_t), pointer :: vector_ptr
199 if (this%get_type() .ne. 'vector') then
200 call neko_error("registry_entry::get_vector: " &
201 // "Registry entry is not of type 'vector'.")
202 end if
203 vector_ptr => this%vector_ptr
204 end function get_vector
205
207 function get_matrix(this) result(matrix_ptr)
208 class(registry_entry_t), target, intent(in) :: this
209 type(matrix_t), pointer :: matrix_ptr
210 if (this%get_type() .ne. 'matrix') then
211 call neko_error("registry_entry::get_field: " &
212 // "Registry entry is not of type 'matrix'.")
213 end if
214 matrix_ptr => this%matrix_ptr
215 end function get_matrix
216
217end module registry_entry
Defines a mapping of the degrees of freedom.
Definition dofmap.f90:35
Defines a field.
Definition field.f90:34
Defines a matrix.
Definition matrix.f90:34
Defines a registry entry for storing and requesting temporary objects This is used in the scratch reg...
subroutine init_register_field(this, dof, name)
Initialize a register entry.
pure character(len=:) function, allocatable get_name(this)
Get the name of the registry entry.
subroutine init_register_matrix(this, nrows, ncols, name)
Initialize a register entry.
subroutine init_register_vector(this, n, name)
Initialize a register entry.
type(field_t) function, pointer get_field(this)
Get the field pointer of the registry entry.
subroutine free_register(this)
Free a register entry.
pure logical function is_allocated(this)
Check if the registry entry is allocated.
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.
pure character(len=:) function, allocatable get_type(this)
Get the type of the registry entry.
Utilities.
Definition utils.f90:35
Defines a vector.
Definition vector.f90:34