MODFLOW 6  version 6.7.0.dev0
USGS Modular Hydrologic Model
petscvectormodule Module Reference

Data Types

type  petscvectortype
 

Functions/Subroutines

subroutine petsc_vec_create_mm (this, n, name, mem_path)
 Create a PETSc vector, with memory. More...
 
subroutine petsc_vec_create (this, n)
 Create a PETSc vector, with memory. More...
 
subroutine petsc_vec_destroy (this)
 Clean up. More...
 
real(dp) function, dimension(:), pointer, contiguous petsc_vec_get_array (this)
 Get a pointer to the underlying data array. More...
 
subroutine petsc_vec_get_ownership_range (this, start, end)
 
integer(i4b) function petsc_vec_get_size (this)
 
real(dp) function petsc_vec_get_value_local (this, idx)
 Gets a value from the vector at the local index. More...
 
subroutine petsc_vec_zero_entries (this)
 set all elements to zero More...
 
subroutine petsc_vec_set_value_local (this, idx, val)
 Set vector value at local index. More...
 
subroutine petsc_vec_axpy (this, alpha, vec_x)
 Calculate AXPY: y = a*x + y. More...
 
real(dp) function petsc_vec_norm2 (this)
 Calculate this vector's (global) 2-norm. More...
 
subroutine petsc_vec_print (this)
 

Function/Subroutine Documentation

◆ petsc_vec_axpy()

subroutine petscvectormodule::petsc_vec_axpy ( class(petscvectortype this,
real(dp)  alpha,
class(vectorbasetype), pointer  vec_x 
)
private
Parameters
thisthis vector
alphathe factor
vec_xthe vector to add

Definition at line 178 of file PetscVector.F90.

179  class(PetscVectorType) :: this !< this vector
180  real(DP) :: alpha !< the factor
181  class(VectorBaseType), pointer :: vec_x !< the vector to add
182  ! local
183  petscerrorcode :: ierr
184  class(PetscVectorType), pointer :: x
185 
186  x => null()
187  select type (vec_x)
188  class is (petscvectortype)
189  x => vec_x
190  end select
191  call vecaxpy(this%vec_impl, alpha, x%vec_impl, ierr)
192  chkerrq(ierr)
193 

◆ petsc_vec_create()

subroutine petscvectormodule::petsc_vec_create ( class(petscvectortype this,
integer(i4b)  n 
)
private
Parameters
thisthis vector
nthe nr. of elements in the vector

Definition at line 61 of file PetscVector.F90.

62  class(PetscVectorType) :: this !< this vector
63  integer(I4B) :: n !< the nr. of elements in the vector
64  ! local
65  petscerrorcode :: ierr
66 
67  this%is_mem_managed = .false.
68 
69  allocate (this%array(n))
70  if (simulation_mode == 'PARALLEL' .and. nr_procs > 1) then
71  call veccreatempiwitharray(petsc_comm_world, 1, n, petsc_decide, &
72  this%array, this%vec_impl, ierr)
73  else
74  call veccreateseqwitharray(petsc_comm_world, 1, n, this%array, &
75  this%vec_impl, ierr)
76  end if
77  chkerrq(ierr)
78 
79  call this%zero_entries()
80 

◆ petsc_vec_create_mm()

subroutine petscvectormodule::petsc_vec_create_mm ( class(petscvectortype this,
integer(i4b)  n,
character(len=*)  name,
character(len=*)  mem_path 
)
Parameters
thisthis vector
nthe nr. of elements in the vector
namethe variable name (for access through memory manager)
mem_pathmemory path for storing the underlying memory items

Definition at line 35 of file PetscVector.F90.

36  class(PetscVectorType) :: this !< this vector
37  integer(I4B) :: n !< the nr. of elements in the vector
38  character(len=*) :: name !< the variable name (for access through memory manager)
39  character(len=*) :: mem_path !< memory path for storing the underlying memory items
40  ! local
41  petscerrorcode :: ierr
42 
43  this%is_mem_managed = .true.
44 
45  call mem_allocate(this%array, n, name, mem_path)
46  if (simulation_mode == 'PARALLEL' .and. nr_procs > 1) then
47  call veccreatempiwitharray(petsc_comm_world, 1, n, petsc_decide, &
48  this%array, this%vec_impl, ierr)
49  else
50  call veccreateseqwitharray(petsc_comm_world, 1, n, this%array, &
51  this%vec_impl, ierr)
52  end if
53  chkerrq(ierr)
54 
55  call this%zero_entries()
56 

◆ petsc_vec_destroy()

subroutine petscvectormodule::petsc_vec_destroy ( class(petscvectortype this)
private
Parameters
thisthis vector

Definition at line 85 of file PetscVector.F90.

86  class(PetscVectorType) :: this !< this vector
87  ! local
88  petscerrorcode :: ierr
89 
90  call vecdestroy(this%vec_impl, ierr)
91  chkerrq(ierr)
92  if (this%is_mem_managed) then
93  call mem_deallocate(this%array)
94  else
95  deallocate (this%array)
96  end if
97 

◆ petsc_vec_get_array()

real(dp) function, dimension(:), pointer, contiguous petscvectormodule::petsc_vec_get_array ( class(petscvectortype this)
private
Parameters
thisthis vector
Returns
the underlying data array for this vector

Definition at line 102 of file PetscVector.F90.

103  class(PetscVectorType) :: this !< this vector
104  real(DP), dimension(:), pointer, contiguous :: array !< the underlying data array for this vector
105 
106  array => this%array
107 

◆ petsc_vec_get_ownership_range()

subroutine petscvectormodule::petsc_vec_get_ownership_range ( class(petscvectortype this,
integer(i4b)  start,
integer(i4b)  end 
)
private
Parameters
thisthis vector
startthe index of the first element (owned by this process) in the global vector
endthe index of the last element (owned by this process) in the global vector

Definition at line 110 of file PetscVector.F90.

111  class(PetscVectorType) :: this !< this vector
112  integer(I4B) :: start !< the index of the first element (owned by this process) in the global vector
113  integer(I4B) :: end !< the index of the last element (owned by this process) in the global vector
114  ! local
115  petscerrorcode :: ierr
116 
117  ! gets the range as [start, end) but 0-based
118  call vecgetownershiprange(this%vec_impl, start, end, ierr)
119 
120  ! now we make it [start, end] and 1-based
121  start = start + 1
122 
123  chkerrq(ierr)
124 

◆ petsc_vec_get_size()

integer(i4b) function petscvectormodule::petsc_vec_get_size ( class(petscvectortype this)
private
Parameters
thisthis vector
Returns
the (global) vector size

Definition at line 127 of file PetscVector.F90.

128  class(PetscVectorType) :: this !< this vector
129  integer(I4B) :: size !< the (global) vector size
130  ! local
131  petscerrorcode :: ierr
132 
133  call vecgetsize(this%vec_impl, size, ierr)
134  chkerrq(ierr)
135 

◆ petsc_vec_get_value_local()

real(dp) function petscvectormodule::petsc_vec_get_value_local ( class(petscvectortype this,
integer(i4b)  idx 
)
private
Parameters
thisthis vector
idxthe index in local numbering
Returns
the value

Definition at line 140 of file PetscVector.F90.

141  class(PetscVectorType) :: this !< this vector
142  integer(I4B) :: idx !< the index in local numbering
143  real(DP) :: val !< the value
144 
145  val = this%array(idx)
146 

◆ petsc_vec_norm2()

real(dp) function petscvectormodule::petsc_vec_norm2 ( class(petscvectortype this)
private
Parameters
thisthis vector
Returns
the calculated 2-norm

Definition at line 198 of file PetscVector.F90.

199  class(PetscVectorType) :: this !< this vector
200  real(DP) :: n2 !< the calculated 2-norm
201  ! local
202  petscerrorcode :: ierr
203 
204  call vecnorm(this%vec_impl, norm_2, n2, ierr)
205  chkerrq(ierr)
206 

◆ petsc_vec_print()

subroutine petscvectormodule::petsc_vec_print ( class(petscvectortype this)
private
Parameters
thisthis vector

Definition at line 209 of file PetscVector.F90.

210  class(PetscVectorType) :: this !< this vector
211  ! local
212  petscerrorcode :: ierr
213 
214  call vecview(this%vec_impl, petsc_viewer_stdout_world, ierr)
215  chkerrq(ierr)
216 

◆ petsc_vec_set_value_local()

subroutine petscvectormodule::petsc_vec_set_value_local ( class(petscvectortype this,
integer(i4b)  idx,
real(dp)  val 
)
private
Parameters
thisthis vector
idxthe index in local numbering
valthe value to set

Definition at line 167 of file PetscVector.F90.

168  class(PetscVectorType) :: this !< this vector
169  integer(I4B) :: idx !< the index in local numbering
170  real(DP) :: val !< the value to set
171 
172  this%array(idx) = val
173 

◆ petsc_vec_zero_entries()

subroutine petscvectormodule::petsc_vec_zero_entries ( class(petscvectortype this)
private
Parameters
thisthis vector

Definition at line 151 of file PetscVector.F90.

152  class(PetscVectorType) :: this !< this vector
153  ! local
154  petscerrorcode :: ierr
155 
156  call veczeroentries(this%vec_impl, ierr)
157  chkerrq(ierr)
158  call vecassemblybegin(this%vec_impl, ierr)
159  chkerrq(ierr)
160  call vecassemblyend(this%vec_impl, ierr)
161  chkerrq(ierr)
162