Neko 1.99.3
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!
36 use num_types, only : rp
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
48 character(len=80), private :: name = ""
50 character(len=80), private :: type = ""
52 logical, private :: allocated = .false.
53
54 ! Storage. Only one of these will be allocated at a time.
55 real(kind=rp), private :: real_scalar = 0.0_rp
56 integer, private :: integer_scalar = 0
57 type(vector_t), private, pointer :: vector_ptr => null()
58 type(matrix_t), private, pointer :: matrix_ptr => null()
59 type(field_t), private, pointer :: field_ptr => null()
60
61 contains
62 ! Constructors
63 procedure, pass(this) :: init_real_scalar => init_register_real_scalar
64 procedure, pass(this) :: init_integer_scalar => init_register_integer_scalar
65 procedure, pass(this) :: init_vector => init_register_vector
66 procedure, pass(this) :: init_matrix => init_register_matrix
67 procedure, pass(this) :: init_field => init_register_field
69 procedure, pass(this) :: free => free_register
70
72 procedure, pass(this) :: get_name
73 procedure, pass(this) :: get_type
74 procedure, pass(this) :: get_real_scalar
75 procedure, pass(this) :: get_integer_scalar
76 procedure, pass(this) :: get_vector
77 procedure, pass(this) :: get_matrix
78 procedure, pass(this) :: get_field
79 procedure, pass(this) :: is_allocated
80
81 procedure, pass(this) :: move_from => move_from_registry_entry
82 end type registry_entry_t
83
84contains
85
87 subroutine init_register_field(this, dof, name)
88 class(registry_entry_t), intent(inout) :: this
89 type(dofmap_t), target, intent(in) :: dof
90 character(len=*), intent(in) :: name
91
92 if (this%allocated) then
93 call neko_error("init_register_field: " &
94 // "Register entry is already allocated.")
95 end if
96
97 call this%free()
98
99 allocate(this%field_ptr)
100 call this%field_ptr%init(dof, trim(name))
101
102 this%name = trim(name)
103 this%type = 'field'
104 this%allocated = .true.
105
106 end subroutine init_register_field
107
109 subroutine init_register_vector(this, n, name)
110 class(registry_entry_t), intent(inout) :: this
111 integer, intent(in) :: n
112 character(len=*), optional, intent(in) :: name
113
114 if (this%allocated) then
115 call neko_error("init_register_vector: " &
116 // "Register entry is already allocated.")
117 end if
118
119 call this%free()
120
121 allocate(this%vector_ptr)
122 call this%vector_ptr%init(n)
123
124 if (present(name)) this%name = trim(name)
125 this%type = 'vector'
126 this%allocated = .true.
127
128 end subroutine init_register_vector
129
131 subroutine init_register_matrix(this, nrows, ncols, name)
132 class(registry_entry_t), intent(inout) :: this
133 integer, intent(in) :: nrows, ncols
134 character(len=*), optional, intent(in) :: name
135
136 if (this%allocated) then
137 call neko_error("init_register_matrix: " &
138 // "Register entry is already allocated.")
139 end if
140
141 call this%free()
142
143 allocate(this%matrix_ptr)
144 call this%matrix_ptr%init(nrows, ncols)
145
146 if (present(name)) this%name = trim(name)
147 this%type = 'matrix'
148 this%allocated = .true.
149
150 end subroutine init_register_matrix
151
153 subroutine init_register_real_scalar(this, val, name)
154 class(registry_entry_t), intent(inout) :: this
155 real(kind=rp), intent(in) :: val
156 character(len=*), optional, intent(in) :: name
157
158 if (this%allocated) then
159 call neko_error("init_register_real_scalar: " &
160 // "Register entry is already allocated.")
161 end if
162
163 call this%free()
164
165 this%real_scalar = val
166
167 if (present(name)) this%name = trim(name)
168 this%type = 'real_scalar'
169 this%allocated = .true.
170
171 end subroutine init_register_real_scalar
172
174 subroutine init_register_integer_scalar(this, val, name)
175 class(registry_entry_t), intent(inout) :: this
176 integer, intent(in) :: val
177 character(len=*), optional, intent(in) :: name
178
179 if (this%allocated) then
180 call neko_error("init_register_integer_scalar: " &
181 // "Register entry is already allocated.")
182 end if
183
184 call this%free()
185
186 this%integer_scalar = val
187
188 if (present(name)) this%name = trim(name)
189 this%type = 'integer_scalar'
190 this%allocated = .true.
191
192 end subroutine init_register_integer_scalar
193
195 subroutine free_register(this)
196 class(registry_entry_t), intent(inout) :: this
197
198 if (associated(this%field_ptr)) then
199 call this%field_ptr%free()
200 deallocate(this%field_ptr)
201 end if
202
203 if (associated(this%vector_ptr)) then
204 call this%vector_ptr%free()
205 deallocate(this%vector_ptr)
206 end if
207
208 if (associated(this%matrix_ptr)) then
209 call this%matrix_ptr%free()
210 deallocate(this%matrix_ptr)
211 end if
212
213 this%real_scalar = 0.0_rp
214 this%integer_scalar = 0
215
216 this%name = ""
217 this%type = ""
218 this%allocated = .false.
219
220 end subroutine free_register
221
223 pure function get_name(this) result(name)
224 class(registry_entry_t), intent(in) :: this
225 character(len=:), allocatable :: name
226 name = trim(this%name)
227 end function get_name
228
230 pure function get_type(this) result(type)
231 class(registry_entry_t), intent(in) :: this
232 character(len=:), allocatable :: type
233 type = trim(this%type)
234 end function get_type
235
237 pure function is_allocated(this) result(allocated)
238 class(registry_entry_t), intent(in) :: this
239 logical :: allocated
240 allocated = this%allocated
241 end function is_allocated
242
244 function get_field(this) result(field_ptr)
245 class(registry_entry_t), target, intent(in) :: this
246 type(field_t), pointer :: field_ptr
247 if (this%get_type() .ne. 'field') then
248 call neko_error("registry_entry::get_field: " &
249 // "Registry entry is not of type 'field'.")
250 end if
251 field_ptr => this%field_ptr
252 end function get_field
253
255 function get_vector(this) result(vector_ptr)
256 class(registry_entry_t), target, intent(in) :: this
257 type(vector_t), pointer :: vector_ptr
258 if (this%get_type() .ne. 'vector') then
259 call neko_error("registry_entry::get_vector: " &
260 // "Registry entry is not of type 'vector'.")
261 end if
262 vector_ptr => this%vector_ptr
263 end function get_vector
264
266 function get_matrix(this) result(matrix_ptr)
267 class(registry_entry_t), target, intent(in) :: this
268 type(matrix_t), pointer :: matrix_ptr
269 if (this%get_type() .ne. 'matrix') then
270 call neko_error("registry_entry::get_field: " &
271 // "Registry entry is not of type 'matrix'.")
272 end if
273 matrix_ptr => this%matrix_ptr
274 end function get_matrix
275
277 function get_real_scalar(this) result(scalar_ptr)
278 class(registry_entry_t), target, intent(in) :: this
279 real(kind=rp), pointer :: scalar_ptr
280 if (this%get_type() .ne. 'real_scalar') then
281 call neko_error("registry_entry::get_real_scalar: " &
282 // "Registry entry is not of type 'real_scalar'.")
283 end if
284 scalar_ptr => this%real_scalar
285 end function get_real_scalar
286
288 function get_integer_scalar(this) result(scalar_ptr)
289 class(registry_entry_t), target, intent(in) :: this
290 integer, pointer :: scalar_ptr
291 if (this%get_type() .ne. 'integer_scalar') then
292 call neko_error("registry_entry::get_integer_scalar: " &
293 // "Registry entry is not of type 'integer_scalar'.")
294 end if
295 scalar_ptr => this%integer_scalar
296 end function get_integer_scalar
297
299 subroutine move_from_registry_entry(this, source)
300 class(registry_entry_t), intent(inout) :: this
301 class(registry_entry_t), intent(inout) :: source
302
303 if (.not. source%is_allocated()) return
304 call this%free()
305
306 this%name = source%name
307 this%type = source%type
308 this%allocated = source%allocated
309
310 select case (trim(this%type))
311 case ('real_scalar')
312 this%real_scalar = source%real_scalar
313 case ('integer_scalar')
314 this%integer_scalar = source%integer_scalar
315 case ('vector')
316 this%vector_ptr => source%vector_ptr
317 nullify(source%vector_ptr)
318 case ('matrix')
319 this%matrix_ptr => source%matrix_ptr
320 nullify(source%matrix_ptr)
321 case ('field')
322 this%field_ptr => source%field_ptr
323 nullify(source%field_ptr)
324 case default
325 call neko_error("move_from_registry_entry: " // &
326 "Unsupported registry entry type: " // trim(this%type))
327 end select
328
329 ! Free the source entry after moving
330 call source%free()
331
332 end subroutine move_from_registry_entry
333end 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
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
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.
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_real_scalar(this, val, name)
Initialize a scalar register entry.
subroutine init_register_matrix(this, nrows, ncols, name)
Initialize a register entry.
subroutine init_register_vector(this, n, name)
Initialize a register entry.
subroutine init_register_integer_scalar(this, val, name)
Initialize an integer scalar register entry.
subroutine move_from_registry_entry(this, source)
Move a registry entry from another 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.
integer function, pointer get_integer_scalar(this)
Get the integer scalar pointer of the registry entry.
Utilities.
Definition utils.f90:35
Defines a vector.
Definition vector.f90:34