56 logical,
private,
allocatable :: inuse(:)
58 integer,
private :: n_entries = 0
60 integer,
private :: n_inuse = 0
62 integer,
private :: expansion_size = 10
66 procedure,
private, pass(this) ::
expand
131 integer,
optional,
intent(in) :: size
132 integer,
optional,
intent(in) :: expansion_size
133 type(
dofmap_t),
target,
intent(in),
optional :: dof
139 if (
present(size)) s =
size
140 if (
present(dof)) this%dof => dof
142 allocate(this%entries(s))
143 allocate(this%inuse(s))
144 this%inuse(:) = .false.
146 this%expansion_size = 10
147 if (
present(expansion_size)) this%expansion_size = expansion_size
156 if (
allocated(this%inuse))
then
157 if(any(this%inuse))
then
159 //
"Cannot free scratch registry with in-use entries.")
161 deallocate(this%inuse)
164 if (
allocated(this%entries))
then
165 do i = 1, this%n_entries
166 call this%entries(i)%free()
169 deallocate(this%entries)
172 if (
associated(this%dof))
nullify(this%dof)
177 this%expansion_size = 10
187 type(
dofmap_t),
target,
intent(in) :: dof
189 if (
associated(this%dof, dof))
then
191 else if (
associated(this%dof))
then
192 call neko_error(
"scratch_registry::set_dofmap: "&
193 //
"Dofmap is already assigned to scratch registry.")
212 n = count(this%inuse)
220 if (
allocated(this%entries))
then
221 n =
size(this%entries)
232 n = this%expansion_size
238 integer,
intent(in) :: index
246 logical,
allocatable :: temp2(:)
248 allocate(temp(this%get_size() + this%expansion_size))
249 temp(1:this%n_entries) = this%entries(1:this%n_entries)
251 call move_alloc(temp, this%entries)
253 allocate(temp2(this%get_size() + this%expansion_size))
254 temp2(1:this%n_entries) = this%inuse(1:this%n_entries)
255 temp2(this%n_entries+1:) = .false.
265 type(
field_t),
pointer,
intent(inout) :: f
266 integer,
intent(inout) :: index
267 logical,
intent(in) :: clear
268 character(len=10) :: name
270 if (.not.
associated(this%dof))
then
271 call neko_error(
"scratch_registry::request_field: "&
272 //
"No dofmap assigned to scratch registry.")
275 associate(n_entries => this%n_entries, n_inuse => this%n_inuse)
277 do index = 1, this%get_size()
278 if (.not. this%inuse(index))
then
280 if (.not. this%entries(index)%is_allocated())
then
281 write(name,
"(A3,I0.3)")
"wrk", index
282 call this%entries(index)%init_field(this%dof, trim(name))
283 n_entries = n_entries + 1
284 else if (this%entries(index)%get_type() .ne.
'field')
then
288 f => this%entries(index)%get_field()
290 this%inuse(index) = .true.
291 this%n_inuse = this%n_inuse + 1
297 index = n_entries + 1
299 n_entries = n_entries + 1
300 n_inuse = n_inuse + 1
301 this%inuse(n_entries) = .true.
302 write (name,
"(A3,I0.3)")
"wrk", index
303 call this%entries(n_entries)%init_field(this%dof, trim(name))
304 f => this%entries(n_entries)%get_field()
316 type(vector_t),
pointer,
intent(inout) :: v
317 integer,
intent(inout) :: index
318 integer,
intent(in) :: n
319 logical,
intent(in) :: clear
321 associate(n_entries => this%n_entries, n_inuse => this%n_inuse)
323 do index = 1, this%get_size()
324 if (.not. this%inuse(index))
then
326 if (.not. this%entries(index)%is_allocated())
then
327 call this%entries(index)%init_vector(n)
328 n_entries = n_entries + 1
329 else if (trim(this%entries(index)%get_type()) .ne.
'vector')
then
333 v => this%entries(index)%get_vector()
334 if (v%size() .ne. n)
then
339 if (clear)
call vector_rzero(v)
340 this%inuse(index) = .true.
341 this%n_inuse = this%n_inuse + 1
347 index = n_entries + 1
349 n_entries = n_entries + 1
350 n_inuse = n_inuse + 1
351 this%inuse(n_entries) = .true.
352 call this%entries(n_entries)%init_vector(n)
353 v => this%entries(n_entries)%get_vector()
366 type(matrix_t),
pointer,
intent(inout) :: m
367 integer,
intent(inout) :: index
368 integer,
intent(in) :: nrows, ncols
369 logical,
intent(in) :: clear
371 associate(n_entries => this%n_entries, n_inuse => this%n_inuse)
373 do index = 1, this%get_size()
374 if (.not. this%inuse(index))
then
376 if (.not. this%entries(index)%is_allocated())
then
377 call this%entries(index)%init_matrix(nrows, ncols)
378 n_entries = n_entries + 1
379 else if (trim(this%entries(index)%get_type()) .ne.
'matrix')
then
383 m => this%entries(index)%get_matrix()
384 if (m%get_nrows() .ne. nrows .or. &
385 m%get_ncols() .ne. ncols)
then
390 if (clear)
call matrix_rzero(m)
391 this%inuse(index) = .true.
392 this%n_inuse = this%n_inuse + 1
398 index = n_entries + 1
400 n_entries = n_entries + 1
401 n_inuse = n_inuse + 1
402 this%inuse(n_entries) = .true.
403 call this%entries(n_entries)%init_matrix(nrows, ncols)
404 m => this%entries(n_entries)%get_matrix()
413 integer,
intent(inout) :: index
415 if (trim(this%entries(index)%get_type()) .ne.
'field')
then
416 call neko_error(
"scratch_registry::relinquish_field_single: " &
417 //
"Register entry is not a field.")
420 this%inuse(index) = .false.
421 this%n_inuse = this%n_inuse - 1
428 integer,
intent(inout) :: indices(:)
431 do i = 1,
size(indices)
432 if (trim(this%entries(indices(i))%get_type()) .ne.
'field')
then
433 call neko_error(
"scratch_registry::relinquish_field_single: " &
434 //
"Register entry is not a field.")
437 this%inuse(indices(i)) = .false.
439 this%n_inuse = this%n_inuse -
size(indices)
446 integer,
intent(inout) :: index
448 if (trim(this%entries(index)%get_type()) .ne.
'vector')
then
449 call neko_error(
"scratch_registry::relinquish_vector_single: " &
450 //
"Register entry is not a vector.")
453 this%inuse(index) = .false.
454 this%n_inuse = this%n_inuse - 1
461 integer,
intent(inout) :: indices(:)
464 do i = 1,
size(indices)
465 if (trim(this%entries(indices(i))%get_type()) .ne.
'vector')
then
466 call neko_error(
"scratch_registry::relinquish_vector_single: " &
467 //
"Register entry is not a vector.")
470 this%inuse(indices(i)) = .false.
472 this%n_inuse = this%n_inuse -
size(indices)
479 integer,
intent(inout) :: index
481 if (trim(this%entries(index)%get_type()) .ne.
'matrix')
then
482 call neko_error(
"scratch_registry::relinquish_matrix_single: " &
483 //
"Register entry is not a matrix.")
486 this%inuse(index) = .false.
487 this%n_inuse = this%n_inuse - 1
494 integer,
intent(inout) :: indices(:)
497 do i = 1,
size(indices)
498 if (trim(this%entries(indices(i))%get_type()) .ne.
'matrix')
then
499 call neko_error(
"scratch_registry::relinquish_matrix_single: " &
500 //
"Register entry is not a matrix.")
503 this%inuse(indices(i)) = .false.
505 this%n_inuse = this%n_inuse -
size(indices)
512 integer,
intent(inout) :: index
514 this%inuse(index) = .false.
515 this%n_inuse = this%n_inuse - 1
522 integer,
intent(inout) :: indices(:)
525 do i = 1,
size(indices)
526 this%inuse(indices(i)) = .false.
528 this%n_inuse = this%n_inuse -
size(indices)
Defines a mapping of the degrees of freedom.
subroutine, public field_rzero(a, n)
Zero a real vector.
subroutine, public matrix_rzero(a, n)
Zero a real matrix .
Defines a registry entry for storing and requesting temporary objects This is used in the scratch reg...
Defines a registry for storing and requesting temporary objects This can be used when you have a func...
subroutine relinquish_matrix_single(this, index)
Relinquish the use of a matrix in the registry.
pure logical function get_inuse(this, index)
Get the inuse status for a given index.
pure integer function get_n_inuse(this)
Get the number of objects currently in use.
subroutine scratch_registry_free(this)
Destructor.
subroutine request_field(this, f, index, clear)
Get a field from the registry by assigning it to a pointer.
subroutine relinquish_matrix_multiple(this, indices)
Relinquish the use of multiple matrices in the registry.
pure integer function get_n_entries(this)
Get the number of objects stored in the registry.
subroutine relinquish_field_single(this, index)
Relinquish the use of a field in the registry.
pure integer function get_size(this)
Get the size of the objects array.
subroutine scratch_registry_set_dofmap(this, dof)
Assign a dofmap to the scratch registry.
subroutine relinquish_field_multiple(this, indices)
Relinquish the use of multiple fields in the registry.
type(scratch_registry_t), target, public neko_scratch_registry
Global scratch registry.
subroutine relinquish_vector_multiple(this, indices)
Relinquish the use of multiple vectors in the registry.
subroutine relinquish_vector_single(this, index)
Relinquish the use of a vector in the registry.
subroutine request_matrix(this, m, index, nrows, ncols, clear)
Get a matrix from the registry by assigning it to a pointer.
subroutine request_vector(this, v, index, n, clear)
Get a vector from the registry by assigning it to a pointer.
subroutine scratch_registry_init(this, size, expansion_size, dof)
Constructor, optionally taking initial registry and expansion size as argument.
subroutine relinquish_multiple(this, indices)
Relinquish the use of multiple objects in the registry.
subroutine relinquish_single(this, index)
Relinquish the use of an object in the registry.
pure integer function get_expansion_size(this)
Get the expansion size.
subroutine, public vector_rzero(a, n)
Zero a real vector.