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(:)
252 call move_alloc(this%entries, temp)
253 call move_alloc(this%inuse, temp2)
256 allocate(this%entries(n + this%expansion_size))
257 allocate(this%inuse(n + this%expansion_size), source = .false.)
261 call this%entries(i)%move_from(temp(i))
262 this%inuse(i) = temp2(i)
267 if (
allocated(temp))
deallocate(temp)
268 if (
allocated(temp2))
deallocate(temp2)
278 type(
field_t),
pointer,
intent(inout) :: f
279 integer,
intent(inout) :: index
280 logical,
intent(in) :: clear
281 character(len=10) :: name
283 if (.not.
associated(this%dof))
then
284 call neko_error(
"scratch_registry::request_field: "&
285 //
"No dofmap assigned to scratch registry.")
288 associate(n_entries => this%n_entries, n_inuse => this%n_inuse)
290 do index = 1, this%get_size()
291 if (.not. this%inuse(index))
then
293 if (.not. this%entries(index)%is_allocated())
then
294 write(name,
"(A3,I0.3)")
"wrk", index
295 call this%entries(index)%init_field(this%dof, trim(name))
296 n_entries = n_entries + 1
297 else if (this%entries(index)%get_type() .ne.
'field')
then
301 f => this%entries(index)%get_field()
303 this%inuse(index) = .true.
304 this%n_inuse = this%n_inuse + 1
310 index = n_entries + 1
312 n_entries = n_entries + 1
313 n_inuse = n_inuse + 1
314 this%inuse(n_entries) = .true.
315 write (name,
"(A3,I0.3)")
"wrk", index
316 call this%entries(n_entries)%init_field(this%dof, trim(name))
317 f => this%entries(n_entries)%get_field()
329 type(vector_t),
pointer,
intent(inout) :: v
330 integer,
intent(inout) :: index
331 integer,
intent(in) :: n
332 logical,
intent(in) :: clear
334 associate(n_entries => this%n_entries, n_inuse => this%n_inuse)
336 do index = 1, this%get_size()
337 if (.not. this%inuse(index))
then
339 if (.not. this%entries(index)%is_allocated())
then
340 call this%entries(index)%init_vector(n)
341 n_entries = n_entries + 1
342 else if (trim(this%entries(index)%get_type()) .ne.
'vector')
then
346 v => this%entries(index)%get_vector()
347 if (v%size() .ne. n)
then
352 if (clear)
call vector_rzero(v)
353 this%inuse(index) = .true.
354 this%n_inuse = this%n_inuse + 1
360 index = n_entries + 1
362 n_entries = n_entries + 1
363 n_inuse = n_inuse + 1
364 this%inuse(n_entries) = .true.
365 call this%entries(n_entries)%init_vector(n)
366 v => this%entries(n_entries)%get_vector()
379 type(matrix_t),
pointer,
intent(inout) :: m
380 integer,
intent(inout) :: index
381 integer,
intent(in) :: nrows, ncols
382 logical,
intent(in) :: clear
384 associate(n_entries => this%n_entries, n_inuse => this%n_inuse)
386 do index = 1, this%get_size()
387 if (.not. this%inuse(index))
then
389 if (.not. this%entries(index)%is_allocated())
then
390 call this%entries(index)%init_matrix(nrows, ncols)
391 n_entries = n_entries + 1
392 else if (trim(this%entries(index)%get_type()) .ne.
'matrix')
then
396 m => this%entries(index)%get_matrix()
397 if (m%get_nrows() .ne. nrows .or. &
398 m%get_ncols() .ne. ncols)
then
403 if (clear)
call matrix_rzero(m)
404 this%inuse(index) = .true.
405 this%n_inuse = this%n_inuse + 1
411 index = n_entries + 1
413 n_entries = n_entries + 1
414 n_inuse = n_inuse + 1
415 this%inuse(n_entries) = .true.
416 call this%entries(n_entries)%init_matrix(nrows, ncols)
417 m => this%entries(n_entries)%get_matrix()
426 integer,
intent(inout) :: index
428 if (trim(this%entries(index)%get_type()) .ne.
'field')
then
429 call neko_error(
"scratch_registry::relinquish_field_single: " &
430 //
"Register entry is not a field.")
433 this%inuse(index) = .false.
434 this%n_inuse = this%n_inuse - 1
441 integer,
intent(inout) :: indices(:)
444 do i = 1,
size(indices)
445 if (trim(this%entries(indices(i))%get_type()) .ne.
'field')
then
446 call neko_error(
"scratch_registry::relinquish_field_single: " &
447 //
"Register entry is not a field.")
450 this%inuse(indices(i)) = .false.
452 this%n_inuse = this%n_inuse -
size(indices)
459 integer,
intent(inout) :: index
461 if (trim(this%entries(index)%get_type()) .ne.
'vector')
then
462 call neko_error(
"scratch_registry::relinquish_vector_single: " &
463 //
"Register entry is not a vector.")
466 this%inuse(index) = .false.
467 this%n_inuse = this%n_inuse - 1
474 integer,
intent(inout) :: indices(:)
477 do i = 1,
size(indices)
478 if (trim(this%entries(indices(i))%get_type()) .ne.
'vector')
then
479 call neko_error(
"scratch_registry::relinquish_vector_single: " &
480 //
"Register entry is not a vector.")
483 this%inuse(indices(i)) = .false.
485 this%n_inuse = this%n_inuse -
size(indices)
492 integer,
intent(inout) :: index
494 if (trim(this%entries(index)%get_type()) .ne.
'matrix')
then
495 call neko_error(
"scratch_registry::relinquish_matrix_single: " &
496 //
"Register entry is not a matrix.")
499 this%inuse(index) = .false.
500 this%n_inuse = this%n_inuse - 1
507 integer,
intent(inout) :: indices(:)
510 do i = 1,
size(indices)
511 if (trim(this%entries(indices(i))%get_type()) .ne.
'matrix')
then
512 call neko_error(
"scratch_registry::relinquish_matrix_single: " &
513 //
"Register entry is not a matrix.")
516 this%inuse(indices(i)) = .false.
518 this%n_inuse = this%n_inuse -
size(indices)
525 integer,
intent(inout) :: index
527 this%inuse(index) = .false.
528 this%n_inuse = this%n_inuse - 1
535 integer,
intent(inout) :: indices(:)
538 do i = 1,
size(indices)
539 this%inuse(indices(i)) = .false.
541 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 registries ...
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.