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!
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=:), private, allocatable :: name
50 character(len=:), private, allocatable :: 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 end type registry_entry_t
81
82contains
83
85 subroutine init_register_field(this, dof, name)
86 class(registry_entry_t), intent(inout) :: this
87 type(dofmap_t), target, intent(in) :: dof
88 character(len=*), intent(in) :: name
89
90 if (this%allocated) then
91 call neko_error("init_register_field: " &
92 // "Register entry is already allocated.")
93 end if
94
95 call this%free()
96
97 allocate(this%field_ptr)
98 call this%field_ptr%init(dof, trim(name))
99
100 this%name = trim(name)
101 this%type = 'field'
102 this%allocated = .true.
103
104 end subroutine init_register_field
105
107 subroutine init_register_vector(this, n, name)
108 class(registry_entry_t), intent(inout) :: this
109 integer, intent(in) :: n
110 character(len=*), optional, intent(in) :: name
111
112 if (this%allocated) then
113 call neko_error("init_register_vector: " &
114 // "Register entry is already allocated.")
115 end if
116
117 call this%free()
118
119 allocate(this%vector_ptr)
120 call this%vector_ptr%init(n)
121
122 if (present(name)) this%name = trim(name)
123 this%type = 'vector'
124 this%allocated = .true.
125
126 end subroutine init_register_vector
127
129 subroutine init_register_matrix(this, nrows, ncols, name)
130 class(registry_entry_t), intent(inout) :: this
131 integer, intent(in) :: nrows, ncols
132 character(len=*), optional, intent(in) :: name
133
134 if (this%allocated) then
135 call neko_error("init_register_matrix: " &
136 // "Register entry is already allocated.")
137 end if
138
139 call this%free()
140
141 allocate(this%matrix_ptr)
142 call this%matrix_ptr%init(nrows, ncols)
143
144 if (present(name)) this%name = trim(name)
145 this%type = 'matrix'
146 this%allocated = .true.
147
148 end subroutine init_register_matrix
149
151 subroutine init_register_real_scalar(this, val, name)
152 class(registry_entry_t), intent(inout) :: this
153 real(kind=rp), intent(in) :: val
154 character(len=*), optional, intent(in) :: name
155
156 if (this%allocated) then
157 call neko_error("init_register_real_scalar: " &
158 // "Register entry is already allocated.")
159 end if
160
161 call this%free()
162
163 this%real_scalar = val
164
165 if (present(name)) this%name = trim(name)
166 this%type = 'real_scalar'
167 this%allocated = .true.
168
169 end subroutine init_register_real_scalar
170
172 subroutine init_register_integer_scalar(this, val, name)
173 class(registry_entry_t), intent(inout) :: this
174 integer, intent(in) :: val
175 character(len=*), optional, intent(in) :: name
176
177 if (this%allocated) then
178 call neko_error("init_register_integer_scalar: " &
179 // "Register entry is already allocated.")
180 end if
181
182 call this%free()
183
184 this%integer_scalar = val
185
186 if (present(name)) this%name = trim(name)
187 this%type = 'integer_scalar'
188 this%allocated = .true.
189
190 end subroutine init_register_integer_scalar
191
193 subroutine free_register(this)
194 class(registry_entry_t), intent(inout) :: this
195
196 if (associated(this%field_ptr)) then
197 call this%field_ptr%free()
198 deallocate(this%field_ptr)
199 end if
200
201 if (associated(this%vector_ptr)) then
202 call this%vector_ptr%free()
203 deallocate(this%vector_ptr)
204 end if
205
206 if (associated(this%matrix_ptr)) then
207 call this%matrix_ptr%free()
208 deallocate(this%matrix_ptr)
209 end if
210
211 this%real_scalar = 0.0_rp
212 this%integer_scalar = 0
213
214 if (allocated(this%name)) deallocate(this%name)
215 if (allocated(this%type)) deallocate(this%type)
216 this%allocated = .false.
217
218 end subroutine free_register
219
221 pure function get_name(this) result(name)
222 class(registry_entry_t), intent(in) :: this
223 character(len=:), allocatable :: name
224 name = trim(this%name)
225 end function get_name
226
228 pure function get_type(this) result(type)
229 class(registry_entry_t), intent(in) :: this
230 character(len=:), allocatable :: type
231 type = trim(this%type)
232 end function get_type
233
235 pure function is_allocated(this) result(allocated)
236 class(registry_entry_t), intent(in) :: this
237 logical :: allocated
238 allocated = this%allocated
239 end function is_allocated
240
242 function get_field(this) result(field_ptr)
243 class(registry_entry_t), target, intent(in) :: this
244 type(field_t), pointer :: field_ptr
245 if (this%get_type() .ne. 'field') then
246 call neko_error("registry_entry::get_field: " &
247 // "Registry entry is not of type 'field'.")
248 end if
249 field_ptr => this%field_ptr
250 end function get_field
251
253 function get_vector(this) result(vector_ptr)
254 class(registry_entry_t), target, intent(in) :: this
255 type(vector_t), pointer :: vector_ptr
256 if (this%get_type() .ne. 'vector') then
257 call neko_error("registry_entry::get_vector: " &
258 // "Registry entry is not of type 'vector'.")
259 end if
260 vector_ptr => this%vector_ptr
261 end function get_vector
262
264 function get_matrix(this) result(matrix_ptr)
265 class(registry_entry_t), target, intent(in) :: this
266 type(matrix_t), pointer :: matrix_ptr
267 if (this%get_type() .ne. 'matrix') then
268 call neko_error("registry_entry::get_field: " &
269 // "Registry entry is not of type 'matrix'.")
270 end if
271 matrix_ptr => this%matrix_ptr
272 end function get_matrix
273
275 function get_real_scalar(this) result(scalar_ptr)
276 class(registry_entry_t), target, intent(in) :: this
277 real(kind=rp), pointer :: scalar_ptr
278 if (this%get_type() .ne. 'real_scalar') then
279 call neko_error("registry_entry::get_real_scalar: " &
280 // "Registry entry is not of type 'real_scalar'.")
281 end if
282 scalar_ptr => this%real_scalar
283 end function get_real_scalar
284
286 function get_integer_scalar(this) result(scalar_ptr)
287 class(registry_entry_t), target, intent(in) :: this
288 integer, pointer :: scalar_ptr
289 if (this%get_type() .ne. 'integer_scalar') then
290 call neko_error("registry_entry::get_integer_scalar: " &
291 // "Registry entry is not of type 'integer_scalar'.")
292 end if
293 scalar_ptr => this%integer_scalar
294 end function get_integer_scalar
295
296end 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.
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