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.
256 call move_alloc(temp2, this%inuse)
266 type(
field_t),
pointer,
intent(inout) :: f
267 integer,
intent(inout) :: index
268 logical,
intent(in) :: clear
269 character(len=10) :: name
271 if (.not.
associated(this%dof))
then
272 call neko_error(
"scratch_registry::request_field: "&
273 //
"No dofmap assigned to scratch registry.")
276 associate(n_entries => this%n_entries, n_inuse => this%n_inuse)
278 do index = 1, this%get_size()
279 if (.not. this%inuse(index))
then
281 if (.not. this%entries(index)%is_allocated())
then
282 write(name,
"(A3,I0.3)")
"wrk", index
283 call this%entries(index)%init_field(this%dof, trim(name))
284 n_entries = n_entries + 1
285 else if (this%entries(index)%get_type() .ne.
'field')
then
289 f => this%entries(index)%get_field()
291 this%inuse(index) = .true.
292 this%n_inuse = this%n_inuse + 1
298 index = n_entries + 1
300 n_entries = n_entries + 1
301 n_inuse = n_inuse + 1
302 this%inuse(n_entries) = .true.
303 write (name,
"(A3,I0.3)")
"wrk", index
304 call this%entries(n_entries)%init_field(this%dof, trim(name))
305 f => this%entries(n_entries)%get_field()
317 type(vector_t),
pointer,
intent(inout) :: v
318 integer,
intent(inout) :: index
319 integer,
intent(in) :: n
320 logical,
intent(in) :: clear
322 associate(n_entries => this%n_entries, n_inuse => this%n_inuse)
324 do index = 1, this%get_size()
325 if (.not. this%inuse(index))
then
327 if (.not. this%entries(index)%is_allocated())
then
328 call this%entries(index)%init_vector(n)
329 n_entries = n_entries + 1
330 else if (trim(this%entries(index)%get_type()) .ne.
'vector')
then
334 v => this%entries(index)%get_vector()
335 if (v%size() .ne. n)
then
340 if (clear)
call vector_rzero(v)
341 this%inuse(index) = .true.
342 this%n_inuse = this%n_inuse + 1
348 index = n_entries + 1
350 n_entries = n_entries + 1
351 n_inuse = n_inuse + 1
352 this%inuse(n_entries) = .true.
353 call this%entries(n_entries)%init_vector(n)
354 v => this%entries(n_entries)%get_vector()
367 type(matrix_t),
pointer,
intent(inout) :: m
368 integer,
intent(inout) :: index
369 integer,
intent(in) :: nrows, ncols
370 logical,
intent(in) :: clear
372 associate(n_entries => this%n_entries, n_inuse => this%n_inuse)
374 do index = 1, this%get_size()
375 if (.not. this%inuse(index))
then
377 if (.not. this%entries(index)%is_allocated())
then
378 call this%entries(index)%init_matrix(nrows, ncols)
379 n_entries = n_entries + 1
380 else if (trim(this%entries(index)%get_type()) .ne.
'matrix')
then
384 m => this%entries(index)%get_matrix()
385 if (m%get_nrows() .ne. nrows .or. &
386 m%get_ncols() .ne. ncols)
then
391 if (clear)
call matrix_rzero(m)
392 this%inuse(index) = .true.
393 this%n_inuse = this%n_inuse + 1
399 index = n_entries + 1
401 n_entries = n_entries + 1
402 n_inuse = n_inuse + 1
403 this%inuse(n_entries) = .true.
404 call this%entries(n_entries)%init_matrix(nrows, ncols)
405 m => this%entries(n_entries)%get_matrix()
414 integer,
intent(inout) :: index
416 if (trim(this%entries(index)%get_type()) .ne.
'field')
then
417 call neko_error(
"scratch_registry::relinquish_field_single: " &
418 //
"Register entry is not a field.")
421 this%inuse(index) = .false.
422 this%n_inuse = this%n_inuse - 1
429 integer,
intent(inout) :: indices(:)
432 do i = 1,
size(indices)
433 if (trim(this%entries(indices(i))%get_type()) .ne.
'field')
then
434 call neko_error(
"scratch_registry::relinquish_field_single: " &
435 //
"Register entry is not a field.")
438 this%inuse(indices(i)) = .false.
440 this%n_inuse = this%n_inuse -
size(indices)
447 integer,
intent(inout) :: index
449 if (trim(this%entries(index)%get_type()) .ne.
'vector')
then
450 call neko_error(
"scratch_registry::relinquish_vector_single: " &
451 //
"Register entry is not a vector.")
454 this%inuse(index) = .false.
455 this%n_inuse = this%n_inuse - 1
462 integer,
intent(inout) :: indices(:)
465 do i = 1,
size(indices)
466 if (trim(this%entries(indices(i))%get_type()) .ne.
'vector')
then
467 call neko_error(
"scratch_registry::relinquish_vector_single: " &
468 //
"Register entry is not a vector.")
471 this%inuse(indices(i)) = .false.
473 this%n_inuse = this%n_inuse -
size(indices)
480 integer,
intent(inout) :: index
482 if (trim(this%entries(index)%get_type()) .ne.
'matrix')
then
483 call neko_error(
"scratch_registry::relinquish_matrix_single: " &
484 //
"Register entry is not a matrix.")
487 this%inuse(index) = .false.
488 this%n_inuse = this%n_inuse - 1
495 integer,
intent(inout) :: indices(:)
498 do i = 1,
size(indices)
499 if (trim(this%entries(indices(i))%get_type()) .ne.
'matrix')
then
500 call neko_error(
"scratch_registry::relinquish_matrix_single: " &
501 //
"Register entry is not a matrix.")
504 this%inuse(indices(i)) = .false.
506 this%n_inuse = this%n_inuse -
size(indices)
513 integer,
intent(inout) :: index
515 this%inuse(index) = .false.
516 this%n_inuse = this%n_inuse - 1
523 integer,
intent(inout) :: indices(:)
526 do i = 1,
size(indices)
527 this%inuse(indices(i)) = .false.
529 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.