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
Aland, Sebastian
amdis
Commits
a1f6ce9c
Commit
a1f6ce9c
authored
Feb 13, 2012
by
Thomas Witkowski
Browse files
Added some nice to have features for using PETSc solver.
parent
aa1ec307
Changes
6
Hide whitespace changes
Inline
Side-by-side
AMDiS/src/parallel/DofComm.cc
View file @
a1f6ce9c
...
@@ -38,14 +38,18 @@ namespace AMDiS {
...
@@ -38,14 +38,18 @@ namespace AMDiS {
}
}
void
DofComm
::
Iterator
::
setNextFeMap
()
bool
DofComm
::
Iterator
::
setNextFeMap
()
{
{
FUNCNAME
(
"DofComm::Iterator::setNextFeMap()"
);
if
(
dataIter
!=
dofComm
.
data
.
end
())
{
if
(
dataIter
!=
dofComm
.
data
.
end
())
{
TEST_EXIT_DBG
(
dataIter
->
second
.
size
())(
"Should not happen!
\n
"
);
feMapIter
=
dataIter
->
second
.
begin
();
feMapIter
=
dataIter
->
second
.
begin
();
if
(
traverseFeSpace
!=
NULL
)
{
if
(
traverseFeSpace
!=
NULL
)
{
TEST_EXIT_DBG
(
dataIter
->
second
.
count
(
traverseFeSpace
))
if
(
(
dataIter
->
second
.
count
(
traverseFeSpace
)
==
0
)
)
(
"Should not happen!
\n
"
)
;
return
false
;
while
(
feMapIter
->
first
!=
traverseFeSpace
&&
while
(
feMapIter
->
first
!=
traverseFeSpace
&&
feMapIter
!=
dataIter
->
second
.
end
())
feMapIter
!=
dataIter
->
second
.
end
())
...
@@ -56,11 +60,11 @@ namespace AMDiS {
...
@@ -56,11 +60,11 @@ namespace AMDiS {
(
"Should not happen!
\n
"
);
(
"Should not happen!
\n
"
);
}
}
if
(
feMapIter
!=
dataIter
->
second
.
end
())
dofIter
=
feMapIter
->
second
.
begin
();
dofIter
=
feMapIter
->
second
.
begin
();
dofCounter
=
0
;
dofCounter
=
0
;
}
}
return
true
;
}
}
}
}
AMDiS/src/parallel/DofComm.h
View file @
a1f6ce9c
...
@@ -77,7 +77,8 @@ namespace AMDiS {
...
@@ -77,7 +77,8 @@ namespace AMDiS {
dataIter
=
dofComm
.
data
.
begin
();
dataIter
=
dofComm
.
data
.
begin
();
setNextFeMap
();
while
(
setNextFeMap
()
==
false
)
++
dataIter
;
}
}
inline
bool
end
()
inline
bool
end
()
...
@@ -87,9 +88,9 @@ namespace AMDiS {
...
@@ -87,9 +88,9 @@ namespace AMDiS {
inline
void
nextRank
()
inline
void
nextRank
()
{
{
++
dataIter
;
do
{
++
dataIter
;
setNextFeMap
();
}
while
(
setNextFeMap
()
==
false
)
;
}
}
inline
void
nextFeSpace
()
inline
void
nextFeSpace
()
...
@@ -101,9 +102,9 @@ namespace AMDiS {
...
@@ -101,9 +102,9 @@ namespace AMDiS {
{
{
++
feMapIter
;
++
feMapIter
;
if
(
feMapIter
==
dataIter
->
second
.
end
())
{
if
(
feMapIter
==
dataIter
->
second
.
end
())
{
++
dataIter
;
do
{
++
dataIter
;
setNextFeMap
();
}
while
(
setNextFeMap
()
==
false
)
;
}
else
{
}
else
{
dofIter
=
feMapIter
->
second
.
begin
();
dofIter
=
feMapIter
->
second
.
begin
();
dofCounter
=
0
;
dofCounter
=
0
;
...
@@ -122,15 +123,17 @@ namespace AMDiS {
...
@@ -122,15 +123,17 @@ namespace AMDiS {
++
feMapIter
;
++
feMapIter
;
}
}
TEST_EXIT_DBG
(
feMapIter
!=
dataIter
->
second
.
end
())
if
(
feMapIter
!=
dataIter
->
second
.
end
())
{
(
"Should not happen!
\n
"
);
dofIter
=
feMapIter
->
second
.
begin
();
dofCounter
=
0
;
dofIter
=
feMapIter
->
second
.
begin
();
}
dofCounter
=
0
;
}
}
inline
bool
endDofIter
()
inline
bool
endDofIter
()
{
{
if
(
feMapIter
==
dataIter
->
second
.
end
())
return
true
;
return
(
dofIter
==
feMapIter
->
second
.
end
());
return
(
dofIter
==
feMapIter
->
second
.
end
());
}
}
...
@@ -171,7 +174,7 @@ namespace AMDiS {
...
@@ -171,7 +174,7 @@ namespace AMDiS {
}
}
protected:
protected:
void
setNextFeMap
();
bool
setNextFeMap
();
protected:
protected:
DofComm
&
dofComm
;
DofComm
&
dofComm
;
...
...
AMDiS/src/parallel/PetscProblemStat.cc
View file @
a1f6ce9c
...
@@ -31,26 +31,30 @@ namespace AMDiS {
...
@@ -31,26 +31,30 @@ namespace AMDiS {
{
{
FUNCNAME
(
"PetscProblemStat::PetscProblemStat()"
);
FUNCNAME
(
"PetscProblemStat::PetscProblemStat()"
);
string
name
(
""
);
string
tmp
(
""
);
Parameters
::
get
(
"parallel->solver"
,
name
);
Parameters
::
get
(
"parallel->solver"
,
tmp
);
if
(
name
==
"petsc-schur"
)
{
if
(
tmp
==
"petsc-schur"
)
{
petscSolver
=
new
PetscSolverSchur
();
petscSolver
=
new
PetscSolverSchur
();
}
else
if
(
name
==
"petsc-feti"
)
{
}
else
if
(
tmp
==
"petsc-feti"
)
{
petscSolver
=
new
PetscSolverFeti
();
petscSolver
=
new
PetscSolverFeti
();
}
else
if
(
name
==
"petsc-block"
)
{
}
else
if
(
tmp
==
"petsc-block"
)
{
petscSolver
=
new
PetscSolverGlobalBlockMatrix
();
petscSolver
=
new
PetscSolverGlobalBlockMatrix
();
}
else
if
(
name
==
"petsc"
||
name
==
""
)
{
}
else
if
(
tmp
==
"petsc"
||
tmp
==
""
)
{
petscSolver
=
new
PetscSolverGlobalMatrix
();
petscSolver
=
new
PetscSolverGlobalMatrix
();
}
else
if
(
name
==
"bddcml"
)
{
}
else
if
(
tmp
==
"bddcml"
)
{
#ifdef HAVE_BDDC_ML
#ifdef HAVE_BDDC_ML
petscSolver
=
new
BddcMlSolver
();
petscSolver
=
new
BddcMlSolver
();
#else
#else
ERROR_EXIT
(
"AMDiS was compiled without BDDC-ML support!
\n
"
);
ERROR_EXIT
(
"AMDiS was compiled without BDDC-ML support!
\n
"
);
#endif
#endif
}
else
{
}
else
{
ERROR_EXIT
(
"No parallel solver %s available!
\n
"
,
name
.
c_str
());
ERROR_EXIT
(
"No parallel solver %s available!
\n
"
,
tmp
.
c_str
());
}
}
tmp
=
""
;
Parameters
::
get
(
nameStr
+
"->solver->petsc prefix"
,
tmp
);
petscSolver
->
setKspPrefix
(
tmp
);
}
}
...
...
AMDiS/src/parallel/PetscSolver.cc
View file @
a1f6ce9c
...
@@ -18,6 +18,18 @@ namespace AMDiS {
...
@@ -18,6 +18,18 @@ namespace AMDiS {
using
namespace
std
;
using
namespace
std
;
PetscSolver
::
PetscSolver
()
:
meshDistributor
(
NULL
),
mpiRank
(
-
1
),
kspPrefix
(
""
)
{
string
kspStr
=
""
;
Parameters
::
get
(
"parallel->solver->petsc->ksp"
,
kspStr
);
if
(
kspStr
!=
""
)
PetscOptionsInsertString
(
kspStr
.
c_str
());
}
void
PetscSolver
::
printSolutionInfo
(
AdaptInfo
*
adaptInfo
,
void
PetscSolver
::
printSolutionInfo
(
AdaptInfo
*
adaptInfo
,
bool
iterationCounter
,
bool
iterationCounter
,
bool
residual
)
bool
residual
)
...
...
AMDiS/src/parallel/PetscSolver.h
View file @
a1f6ce9c
...
@@ -46,10 +46,7 @@ namespace AMDiS {
...
@@ -46,10 +46,7 @@ namespace AMDiS {
class
PetscSolver
class
PetscSolver
{
{
public:
public:
PetscSolver
()
PetscSolver
();
:
meshDistributor
(
NULL
),
mpiRank
(
-
1
)
{}
virtual
~
PetscSolver
()
{}
virtual
~
PetscSolver
()
{}
...
@@ -96,6 +93,11 @@ namespace AMDiS {
...
@@ -96,6 +93,11 @@ namespace AMDiS {
return
pc
;
return
pc
;
}
}
void
setKspPrefix
(
std
::
string
s
)
{
kspPrefix
=
s
;
}
protected:
protected:
void
printSolutionInfo
(
AdaptInfo
*
adaptInfo
,
void
printSolutionInfo
(
AdaptInfo
*
adaptInfo
,
bool
iterationCounter
=
true
,
bool
iterationCounter
=
true
,
...
@@ -135,15 +137,18 @@ namespace AMDiS {
...
@@ -135,15 +137,18 @@ namespace AMDiS {
/// Petsc's matrix structure.
/// Petsc's matrix structure.
Mat
petscMatrix
;
Mat
petscMatrix
;
/** \brief
/// PETSc's vector structures for the rhs vector, the solution vector and a
* PETSc's vector structures for the rhs vector, the solution vector and a
/// temporary vector for calculating the final residuum.
* temporary vector for calculating the final residuum.
*/
Vec
petscRhsVec
,
petscSolVec
,
petscTmpVec
;
Vec
petscRhsVec
,
petscSolVec
,
petscTmpVec
;
/// PETSc solver object
KSP
solver
;
KSP
solver
;
/// PETSc preconditioner object
PC
pc
;
PC
pc
;
/// KSP database prefix
string
kspPrefix
;
};
};
...
...
AMDiS/src/parallel/PetscSolverGlobalMatrix.cc
View file @
a1f6ce9c
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
// See also license.opensource.txt in the distribution.
// See also license.opensource.txt in the distribution.
#include
"AMDiS.h"
#include
"parallel/PetscSolverGlobalMatrix.h"
#include
"parallel/PetscSolverGlobalMatrix.h"
#include
"parallel/StdMpi.h"
#include
"parallel/StdMpi.h"
#include
"parallel/MpiHelper.h"
#include
"parallel/MpiHelper.h"
...
@@ -113,6 +114,7 @@ namespace AMDiS {
...
@@ -113,6 +114,7 @@ namespace AMDiS {
KSPSetOperators
(
solver
,
petscMatrix
,
petscMatrix
,
SAME_NONZERO_PATTERN
);
KSPSetOperators
(
solver
,
petscMatrix
,
petscMatrix
,
SAME_NONZERO_PATTERN
);
KSPSetTolerances
(
solver
,
0.0
,
1e-8
,
PETSC_DEFAULT
,
PETSC_DEFAULT
);
KSPSetTolerances
(
solver
,
0.0
,
1e-8
,
PETSC_DEFAULT
,
PETSC_DEFAULT
);
KSPSetType
(
solver
,
KSPBCGS
);
KSPSetType
(
solver
,
KSPBCGS
);
KSPSetOptionsPrefix
(
solver
,
kspPrefix
.
c_str
());
KSPSetFromOptions
(
solver
);
KSPSetFromOptions
(
solver
);
PCSetFromOptions
(
pc
);
PCSetFromOptions
(
pc
);
...
@@ -171,7 +173,11 @@ namespace AMDiS {
...
@@ -171,7 +173,11 @@ namespace AMDiS {
}
}
// PETSc.
// PETSc.
KSPSolve
(
solver
,
petscRhsVec
,
petscSolVec
);
PetscErrorCode
solverError
=
KSPSolve
(
solver
,
petscRhsVec
,
petscSolVec
);
if
(
solverError
!=
0
)
{
AMDiS
::
finalize
();
exit
(
-
1
);
}
// === Transfere values from PETSc's solution vectors to the DOF vectors. ===
// === Transfere values from PETSc's solution vectors to the DOF vectors. ===
PetscScalar
*
vecPointer
;
PetscScalar
*
vecPointer
;
...
...
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