Commit ace7781a authored by Thomas Witkowski's avatar Thomas Witkowski

Navier stokes solver ready to be used.

parent a41536c3
......@@ -145,6 +145,8 @@
#include "parallel/Mtl4Solver.h"
#else
#include "parallel/PetscProblemStat.h"
#include "parallel/PetscSolver.h"
#include "parallel/PetscSolverNavierStokes.h"
#endif
#endif
......
......@@ -103,6 +103,7 @@ namespace AMDiS {
class FeSpaceDofMap;
class MatrixNnzStructure;
class MeshLevelData;
class PetscSolver;
class PetscSolverFeti;
class PetscSolverFetiDebug;
#endif
......
......@@ -10,8 +10,8 @@
// See also license.opensource.txt in the distribution.
#include "AMDiS.h"
#include "parallel/ParallelCoarseSpaceMatVec.h"
#include "parallel/ParallelDofMapping.h"
#include "parallel/MatrixNnzStructure.h"
namespace AMDiS {
......
......@@ -23,10 +23,13 @@
#ifndef AMDIS_PARALLEL_COARSE_SPACE_MAT_VEC_H
#define AMDIS_PARALLEL_COARSE_SPACE_MAT_VEC_H
#include <mpi.h>
#include <vector>
#include <map>
#include <petsc.h>
#include "AMDiS_fwd.h"
#include "parallel/ParallelDofMapping.h"
#include "parallel/MeshDistributor.h"
#include "parallel/MatrixNnzStructure.h"
namespace AMDiS {
......
......@@ -11,6 +11,7 @@
#include "parallel/PetscHelper.h"
#include "parallel/PetscSolver.h"
#include "Global.h"
namespace AMDiS {
......@@ -247,6 +248,25 @@ namespace AMDiS {
MatAssemblyEnd(mat, MAT_FINAL_ASSEMBLY);
}
void setSolver(KSP ksp,
string kspPrefix,
KSPType kspType,
PCType pcType,
PetscReal rtol,
PetscReal atol,
PetscInt maxIt)
{
KSPSetType(ksp, kspType);
KSPSetTolerances(ksp, rtol, atol, PETSC_DEFAULT, maxIt);
if (kspPrefix != "")
KSPSetOptionsPrefix(ksp, kspPrefix.c_str());
KSPSetFromOptions(ksp);
PC pc;
KSPGetPC(ksp, &pc);
PCSetType(pc, pcType);
}
}
}
......@@ -27,6 +27,7 @@
#include <map>
#include <vector>
#include <petsc.h>
#include "AMDiS_fwd.h"
namespace AMDiS {
......@@ -89,6 +90,14 @@ namespace AMDiS {
* \param[out] mat matrix of type MATAIJ, created inside this function.
*/
void matNestConvert(Mat matNest, Mat &mat);
void setSolver(KSP ksp,
string kspPrefix,
KSPType kspType,
PCType pcType,
PetscReal rtol = PETSC_DEFAULT,
PetscReal atol = PETSC_DEFAULT,
PetscInt maxIt = PETSC_DEFAULT);
}
}
......
......@@ -150,6 +150,11 @@ namespace AMDiS {
return dofMap;
}
vector<const FiniteElemSpace*>& getComponentSpaces()
{
return componentSpaces;
}
protected:
/** \brief
* Copies between to PETSc vectors by using different index sets for the
......
......@@ -10,7 +10,6 @@
// See also license.opensource.txt in the distribution.
#include "AMDiS.h"
#include "MatrixVector.h"
#include "parallel/PetscHelper.h"
#include "parallel/PetscSolverFeti.h"
......
......@@ -9,8 +9,8 @@
//
// See also license.opensource.txt in the distribution.
#include "AMDiS.h"
#include <mpi.h>
#include "DirichletBC.h"
#include "parallel/PetscSolverGlobalMatrix.h"
#include "parallel/StdMpi.h"
#include "parallel/MpiHelper.h"
......@@ -904,4 +904,39 @@ namespace AMDiS {
return subSolver;
}
void PetscSolverGlobalMatrix::setConstantNullSpace(KSP ksp,
int constFeSpace,
bool test)
{
Vec nullSpaceBasis;
VecDuplicate(getVecSolInterior(), &nullSpaceBasis);
SystemVector basisVec("tmp", componentSpaces, componentSpaces.size(), true);
basisVec.set(0.0);
basisVec.getDOFVector(constFeSpace)->set(1.0);
setDofVector(nullSpaceBasis, basisVec, true);
VecAssemblyBegin(nullSpaceBasis);
VecAssemblyEnd(nullSpaceBasis);
VecNormalize(nullSpaceBasis, PETSC_NULL);
if (test) {
Vec tmp;
MatGetVecs(getMatInterior(), &tmp, PETSC_NULL);
MatMult(getMatInterior(), nullSpaceBasis, tmp);
PetscReal n;
VecNorm(tmp, NORM_2, &n);
MSG("NORM IS: %e\n", n);
VecDestroy(&tmp);
}
MatNullSpace matNullSpace;
MatNullSpaceCreate(mpiCommGlobal, PETSC_FALSE, 1, &nullSpaceBasis, &matNullSpace);
KSPSetNullSpace(ksp, matNullSpace);
MatNullSpaceDestroy(&matNullSpace);
}
}
......@@ -130,6 +130,8 @@ namespace AMDiS {
PetscSolver* createSubSolver(int component, string kspPrefix);
void setConstantNullSpace(KSP ksp, int constFeSpace, bool test = false);
protected:
bool zeroStartVector;
......
......@@ -29,32 +29,38 @@ namespace AMDiS {
using namespace std;
struct MatShellNavierStokesSchur {
int solverMode;
// === Data for mode 0 (solve the schur complement directly) ===
Mat A00, A01, A10, A11;
KSP kspVelocity;
// === Data for mode 1 ===
struct NavierStokesSchurData {
KSP kspMass, kspLaplace;
Mat matConDif;
IS isVelocity, isPressure;
};
class PetscSolverNavierStokes : public PetscSolverGlobalMatrix
{
private:
class IdFct : public AbstractFunction<double, double>
{
public:
IdFct()
: AbstractFunction<double, double>(0)
{}
double operator()(const double& x) const
{
return x;
}
};
public:
PetscSolverNavierStokes(string name);
void setStokesData(double *nuPtr, double *invTauPtr, SystemVector *vec)
{
nu = nuPtr;
invTau = invTauPtr;
solution = vec;
}
protected:
void initSolver(KSP &ksp);
......@@ -65,7 +71,13 @@ namespace AMDiS {
PetscSolver *massMatrixSolver, *laplaceMatrixSolver, *conDifMatrixSolver;
MatShellNavierStokesSchur matShellContext;
NavierStokesSchurData matShellContext;
double *nu, *invTau;
SystemVector* solution;
IdFct idFct;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment