Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hyteg
hyteg
Commits
32be99c0
Commit
32be99c0
authored
Sep 28, 2021
by
Dominik Thoennes
Browse files
copy index vector only if types don't match
parent
e3c45624
Pipeline
#34454
failed with stages
in 22 minutes and 3 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/hyteg/petsc/PETScSparseMatrix.hpp
View file @
32be99c0
...
...
@@ -116,16 +116,24 @@ class PETScSparseMatrix
void
applyDirichletBC
(
const
FunctionType
<
idx_t
>&
numerator
,
uint_t
level
)
{
std
::
vector
<
idx_t
>
bcIndices
;
hyteg
::
petsc
::
applyDirichletBC
(
numerator
,
bcIndices
,
level
);
std
::
vector
<
PetscInt
>
PetscIntBcIndices
(
bcIndices
.
begin
(),
bcIndices
.
end
()
);
std
::
unique_ptr
<
std
::
vector
<
idx_t
>
>
bcIndices
;
hyteg
::
petsc
::
applyDirichletBC
(
numerator
,
*
bcIndices
,
level
);
std
::
unique_ptr
<
std
::
vector
<
PetscInt
>
>
PetscIntBcIndices
;
if
constexpr
(
std
::
is_same_v
<
idx_t
,
PetscInt
>
)
{
PetscIntBcIndices
=
std
::
move
(
bcIndices
);
}
else
{
PetscIntBcIndices
=
std
::
make_unique
<
std
::
vector
<
PetscInt
>
>
(
bcIndices
->
begin
(),
bcIndices
->
end
()
);
}
// This is required as the implementation of MatZeroRows() checks (for performance reasons?!)
// if there are zero diagonals in the matrix. If there are, the function halts.
// To disable that check, we need to allow setting MAT_NEW_NONZERO_LOCATIONS to true.
MatSetOption
(
mat
,
MAT_NEW_NONZERO_LOCATIONS
,
PETSC_TRUE
);
MatZeroRows
(
mat
,
static_cast
<
PetscInt
>
(
PetscIntBcIndices
.
size
()
),
PetscIntBcIndices
.
data
(),
1.0
,
nullptr
,
nullptr
);
MatZeroRows
(
mat
,
static_cast
<
PetscInt
>
(
PetscIntBcIndices
->
size
()
),
PetscIntBcIndices
->
data
(),
1.0
,
nullptr
,
nullptr
);
MatAssemblyBegin
(
mat
,
MAT_FINAL_ASSEMBLY
);
MatAssemblyEnd
(
mat
,
MAT_FINAL_ASSEMBLY
);
...
...
@@ -153,9 +161,17 @@ class PETScSparseMatrix
PETScVector
<
real_t
,
FunctionType
>&
rhsVec
,
const
uint_t
&
level
)
{
std
::
vector
<
idx_t
>
bcIndices
;
hyteg
::
petsc
::
applyDirichletBC
(
numerator
,
bcIndices
,
level
);
std
::
vector
<
PetscInt
>
PetscIntBcIndices
(
bcIndices
.
begin
(),
bcIndices
.
end
()
);
std
::
unique_ptr
<
std
::
vector
<
idx_t
>
>
bcIndices
;
hyteg
::
petsc
::
applyDirichletBC
(
numerator
,
*
bcIndices
,
level
);
std
::
unique_ptr
<
std
::
vector
<
PetscInt
>
>
PetscIntBcIndices
;
if
constexpr
(
std
::
is_same_v
<
idx_t
,
PetscInt
>
)
{
PetscIntBcIndices
=
std
::
move
(
bcIndices
);
}
else
{
PetscIntBcIndices
=
std
::
make_unique
<
std
::
vector
<
PetscInt
>
>
(
bcIndices
->
begin
(),
bcIndices
->
end
()
);
}
PETScVector
<
real_t
,
FunctionType
>
dirichletSolutionVec
(
dirichletSolution
,
numerator
,
level
,
All
,
"dirichletSolutionVec"
,
rhsVec
.
getCommunicator
()
);
...
...
@@ -166,7 +182,7 @@ class PETScSparseMatrix
MatSetOption
(
mat
,
MAT_NEW_NONZERO_LOCATIONS
,
PETSC_TRUE
);
MatZeroRowsColumns
(
mat
,
PetscIntBcIndices
.
size
(),
PetscIntBcIndices
.
data
(),
1.0
,
dirichletSolutionVec
.
get
(),
rhsVec
.
get
()
);
mat
,
PetscIntBcIndices
->
size
(),
PetscIntBcIndices
->
data
(),
1.0
,
dirichletSolutionVec
.
get
(),
rhsVec
.
get
()
);
}
/// \brief Variant of applyDirichletBCSymmetrically() that only modifies the matrix itself
...
...
@@ -174,9 +190,17 @@ class PETScSparseMatrix
/// \return Vector with global indices of the Dirichlet DoFs
std
::
vector
<
idx_t
>
applyDirichletBCSymmetrically
(
const
FunctionType
<
idx_t
>&
numerator
,
const
uint_t
&
level
)
{
std
::
vector
<
idx_t
>
bcIndices
;
hyteg
::
petsc
::
applyDirichletBC
(
numerator
,
bcIndices
,
level
);
std
::
vector
<
PetscInt
>
PetscIntBcIndices
(
bcIndices
.
begin
(),
bcIndices
.
end
()
);
std
::
shared_ptr
<
std
::
vector
<
idx_t
>
>
bcIndices
;
hyteg
::
petsc
::
applyDirichletBC
(
numerator
,
*
bcIndices
,
level
);
std
::
shared_ptr
<
std
::
vector
<
PetscInt
>
>
PetscIntBcIndices
;
if
constexpr
(
std
::
is_same_v
<
idx_t
,
PetscInt
>
)
{
PetscIntBcIndices
=
bcIndices
;
}
else
{
PetscIntBcIndices
=
std
::
make_shared
<
std
::
vector
<
PetscInt
>
>
(
bcIndices
->
begin
(),
bcIndices
->
end
()
);
}
// This is required as the implementation of MatZeroRowsColumns() checks (for performance reasons?!)
// if there are zero diagonals in the matrix. If there are, the function halts.
...
...
@@ -184,9 +208,9 @@ class PETScSparseMatrix
MatSetOption
(
mat
,
MAT_NEW_NONZERO_LOCATIONS
,
PETSC_TRUE
);
MatZeroRowsColumns
(
mat
,
static_cast
<
PetscInt
>
(
PetscIntBcIndices
.
size
()
),
PetscIntBcIndices
.
data
(),
1.0
,
nullptr
,
nullptr
);
mat
,
static_cast
<
PetscInt
>
(
PetscIntBcIndices
->
size
()
),
PetscIntBcIndices
->
data
(),
1.0
,
nullptr
,
nullptr
);
return
bcIndices
;
return
*
bcIndices
;
}
inline
void
reset
()
{
assembled_
=
false
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment