Commit 450e3553 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

next step for boundary operators

parent ed9107af
...@@ -123,8 +123,8 @@ namespace AMDiS ...@@ -123,8 +123,8 @@ namespace AMDiS
/// Calculates the needed quadrature degree for the given term-order \p order. /// Calculates the needed quadrature degree for the given term-order \p order.
/// This takes into account the polynomial degree of trial and test functions /// This takes into account the polynomial degree of trial and test functions
/// and the polynomial degree of the coefficient functions /// and the polynomial degree of the coefficient functions
template <class Element> template <class Geometry>
int getQuadratureDegree(Element const& element, int order, FirstOrderType firstOrderType = GRD_PHI); int getQuadratureDegree(Dune::GeometryType t, Geometry const& geometry, int order, FirstOrderType firstOrderType = GRD_PHI);
template <class RowView, class ColView> template <class RowView, class ColView>
...@@ -133,12 +133,24 @@ namespace AMDiS ...@@ -133,12 +133,24 @@ namespace AMDiS
ElementMatrix& elementMatrix, ElementMatrix& elementMatrix,
double* factor = NULL); double* factor = NULL);
template <class Intersection, class RowView, class ColView>
bool getBoundaryElementMatrix(Intersection const& intersection,
RowView const& rowView,
ColView const& colView,
ElementMatrix& elementMatrix,
double* factor = NULL);
template <class RowView> template <class RowView>
bool getElementVector(RowView const& rowView, bool getElementVector(RowView const& rowView,
ElementVector& elementVector, ElementVector& elementVector,
double* factor = NULL); double* factor = NULL);
template <class Intersection, class RowView>
bool getBoundaryElementVector(Intersection const& intersection,
RowView const& rowView,
ElementVector& elementVector,
double* factor = NULL);
protected: protected:
template <class RowView, class ColView> template <class RowView, class ColView>
void assembleZeroOrderTerms(RowView const& rowView, void assembleZeroOrderTerms(RowView const& rowView,
......
...@@ -27,14 +27,11 @@ namespace AMDiS ...@@ -27,14 +27,11 @@ namespace AMDiS
template <class MeshView> template <class MeshView>
template <class Element> template <class Geometry>
int Operator<MeshView>::getQuadratureDegree(Element const& element, int order, FirstOrderType firstOrderType) int Operator<MeshView>::getQuadratureDegree(Dune::GeometryType t, Geometry const& geometry, int order, FirstOrderType firstOrderType)
{ {
std::list<OperatorTermType*>* terms = NULL; std::list<OperatorTermType*>* terms = NULL;
auto const& t = element.type();
auto geometry = element.geometry();
switch(order) switch(order)
{ {
case 0: case 0:
...@@ -86,8 +83,6 @@ namespace AMDiS ...@@ -86,8 +83,6 @@ namespace AMDiS
ElementMatrix& elementMatrix, ElementMatrix& elementMatrix,
double* factor) double* factor)
{ {
AMDIS_FUNCNAME("Operator::getElementMatrix()");
double fac = factor ? *factor : 1.0; double fac = factor ? *factor : 1.0;
if (fac == 0.0) if (fac == 0.0)
...@@ -128,6 +123,27 @@ namespace AMDiS ...@@ -128,6 +123,27 @@ namespace AMDiS
return true; return true;
} }
template <class MeshView>
template <class Intersection, class RowView, class ColView>
bool Operator<MeshView>::getBoundaryElementMatrix(Intersection const& intersection,
RowView const& rowView,
ColView const& colView,
ElementMatrix& elementMatrix,
double* factor)
{
const int dim = Intersection::mydimension;
auto const& element = intersection.inside();
auto geometryInInside = intersection.geometryInInside();
int order = getQuadratureDegree(intersection.type(), intersection.geometry(), 0);
auto const& quad = Dune::QuadratureRules<double, dim-1>::rule(intersection.type(), order);
int facet = intersection.indexInInside();
// TODO:
// - we need an abstraction for quadrature, quad-order, intersection-restriction
}
template <class MeshView> template <class MeshView>
template <class RowView> template <class RowView>
...@@ -172,6 +188,15 @@ namespace AMDiS ...@@ -172,6 +188,15 @@ namespace AMDiS
} }
template <class MeshView>
template <class Intersection, class RowView>
bool Operator<MeshView>::getBoundaryElementVector(Intersection const& intersection,
RowView const& rowView,
ElementVector& elementVector,
double* factor)
{
}
template <class MeshView> template <class MeshView>
template <class RowView, class ColView> template <class RowView, class ColView>
void Operator<MeshView>::assembleZeroOrderTerms(RowView const& rowView, void Operator<MeshView>::assembleZeroOrderTerms(RowView const& rowView,
...@@ -188,7 +213,7 @@ namespace AMDiS ...@@ -188,7 +213,7 @@ namespace AMDiS
auto const& rowLocalBasis = rowView.tree().finiteElement().localBasis(); auto const& rowLocalBasis = rowView.tree().finiteElement().localBasis();
auto const& colLocalBasis = colView.tree().finiteElement().localBasis(); auto const& colLocalBasis = colView.tree().finiteElement().localBasis();
int order = getQuadratureDegree(element, 0); int order = getQuadratureDegree(element.type(), geometry, 0);
auto const& quad = Dune::QuadratureRules<double, dim>::rule(element.type(), order); auto const& quad = Dune::QuadratureRules<double, dim>::rule(element.type(), order);
for (auto* operatorTerm : zeroOrder) for (auto* operatorTerm : zeroOrder)
...@@ -237,7 +262,7 @@ namespace AMDiS ...@@ -237,7 +262,7 @@ namespace AMDiS
auto const& rowLocalBasis = rowView.tree().finiteElement().localBasis(); auto const& rowLocalBasis = rowView.tree().finiteElement().localBasis();
int order = getQuadratureDegree(element, 0); int order = getQuadratureDegree(element.type(), geometry, 0);
auto const& quad = Dune::QuadratureRules<double, dim>::rule(element.type(), order); auto const& quad = Dune::QuadratureRules<double, dim>::rule(element.type(), order);
for (auto* operatorTerm : zeroOrder) for (auto* operatorTerm : zeroOrder)
...@@ -278,7 +303,7 @@ namespace AMDiS ...@@ -278,7 +303,7 @@ namespace AMDiS
auto const& rowLocalBasis = rowView.tree().finiteElement().localBasis(); auto const& rowLocalBasis = rowView.tree().finiteElement().localBasis();
auto const& colLocalBasis = colView.tree().finiteElement().localBasis(); auto const& colLocalBasis = colView.tree().finiteElement().localBasis();
int order = getQuadratureDegree(element, 1, GRD_PHI); int order = getQuadratureDegree(element.type(), geometry, 1, GRD_PHI);
auto const& quad = Dune::QuadratureRules<double, dim>::rule(element.type(), order); auto const& quad = Dune::QuadratureRules<double, dim>::rule(element.type(), order);
for (auto* operatorTerm : firstOrderGrdPhi) for (auto* operatorTerm : firstOrderGrdPhi)
...@@ -336,7 +361,7 @@ namespace AMDiS ...@@ -336,7 +361,7 @@ namespace AMDiS
auto const& rowLocalBasis = rowView.tree().finiteElement().localBasis(); auto const& rowLocalBasis = rowView.tree().finiteElement().localBasis();
auto const& colLocalBasis = colView.tree().finiteElement().localBasis(); auto const& colLocalBasis = colView.tree().finiteElement().localBasis();
int order = getQuadratureDegree(element, 1, GRD_PSI); int order = getQuadratureDegree(element.type(), geometry, 1, GRD_PSI);
auto const& quad = Dune::QuadratureRules<double, dim>::rule(element.type(), order); auto const& quad = Dune::QuadratureRules<double, dim>::rule(element.type(), order);
for (auto* operatorTerm : firstOrderGrdPsi) for (auto* operatorTerm : firstOrderGrdPsi)
...@@ -393,7 +418,7 @@ namespace AMDiS ...@@ -393,7 +418,7 @@ namespace AMDiS
auto const& rowLocalBasis = rowView.tree().finiteElement().localBasis(); auto const& rowLocalBasis = rowView.tree().finiteElement().localBasis();
int order = getQuadratureDegree(element, 1, GRD_PSI); int order = getQuadratureDegree(element.type(), geometry, 1, GRD_PSI);
auto const& quad = Dune::QuadratureRules<double, dim>::rule(element.type(), order); auto const& quad = Dune::QuadratureRules<double, dim>::rule(element.type(), order);
for (auto* operatorTerm : firstOrderGrdPsi) for (auto* operatorTerm : firstOrderGrdPsi)
...@@ -444,7 +469,7 @@ namespace AMDiS ...@@ -444,7 +469,7 @@ namespace AMDiS
auto const& rowLocalBasis = rowView.tree().finiteElement().localBasis(); auto const& rowLocalBasis = rowView.tree().finiteElement().localBasis();
// auto const& colLocalBasis = colView.tree().finiteElement().localBasis(); // auto const& colLocalBasis = colView.tree().finiteElement().localBasis();
int order = getQuadratureDegree(element, 2); int order = getQuadratureDegree(element.type(), geometry, 2);
auto const& quad = Dune::QuadratureRules<double, dim>::rule(element.type(), order); auto const& quad = Dune::QuadratureRules<double, dim>::rule(element.type(), order);
for (auto* operatorTerm : secondOrder) for (auto* operatorTerm : secondOrder)
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
namespace AMDiS namespace AMDiS
{ {
struct BoundaryType { int b; };
template <class Traits> template <class Traits>
class ProblemStatSeq class ProblemStatSeq
...@@ -76,6 +77,32 @@ namespace AMDiS ...@@ -76,6 +77,32 @@ namespace AMDiS
using LinearSolverType = LinearSolverInterface<typename SystemMatrixType::MultiMatrix, using LinearSolverType = LinearSolverInterface<typename SystemMatrixType::MultiMatrix,
typename SystemVectorType::MultiVector>; typename SystemVectorType::MultiVector>;
struct ScaledOperator
{
ScaledOperator(std::shared_ptr<OperatorType> const& op, double* factor = nullptr, double* estFactor = nullptr)
: op(op)
, factor(factor)
, estFactor(estFactor)
{}
std::shared_ptr<OperatorType> op;
double* factor;
double* estFactor;
};
struct ScaledBoundaryOperator
{
ScaledBoundaryOperator(std::shared_ptr<OperatorType> const& op, BoundaryType b, double* factor = nullptr, double* estFactor = nullptr)
: op(op)
, b(b)
, factor(factor)
, estFactor(estFactor)
{}
std::shared_ptr<OperatorType> op;
BoundaryType b;
double* factor;
double* estFactor;
};
public: public:
/** /**
* \brief Constructor. Takes the name of the problem that is used to * \brief Constructor. Takes the name of the problem that is used to
...@@ -106,21 +133,17 @@ namespace AMDiS ...@@ -106,21 +133,17 @@ namespace AMDiS
* MESH[0]->global refinements: nr of initial global refinements * MESH[0]->global refinements: nr of initial global refinements
**/ **/
void initialize(Flag initFlag, void initialize(Flag initFlag,
Self* adoptProblem = NULL, Self* adoptProblem = nullptr,
Flag adoptFlag = INIT_NOTHING); Flag adoptFlag = INIT_NOTHING);
/// Adds an operator to \ref A. /// Adds an operator to \ref A.
/** @{ */ /** @{ */
void addMatrixOperator(OperatorType& op, void addMatrixOperator(OperatorType const& op, int i, int j,
int i, int j, double* factor = nullptr, double* estFactor = nullptr);
double* factor = NULL,
double* estFactor = NULL);
void addMatrixOperator(std::shared_ptr<OperatorType> op, void addBoundaryMatrixOperator(BoundaryType b, OperatorType const& op, int i, int j,
int i, int j, double* factor = nullptr, double* estFactor = nullptr);
double* factor = NULL,
double* estFactor = NULL);
void addMatrixOperator(std::map< std::pair<int,int>, void addMatrixOperator(std::map< std::pair<int,int>,
std::shared_ptr<OperatorType> > ops); std::shared_ptr<OperatorType> > ops);
...@@ -131,15 +154,11 @@ namespace AMDiS ...@@ -131,15 +154,11 @@ namespace AMDiS
/// Adds an operator to \ref rhs. /// Adds an operator to \ref rhs.
/** @{ */ /** @{ */
void addVectorOperator(OperatorType& op, void addVectorOperator(OperatorType const& op, int i,
int i, double* factor = nullptr, double* estFactor = nullptr);
double* factor = NULL,
double* estFactor = NULL);
void addVectorOperator(std::shared_ptr<OperatorType> op, void addBoundaryVectorOperator(BoundaryType b, OperatorType const& op, int i,
int i, double* factor = nullptr, double* estFactor = nullptr);
double* factor = NULL,
double* estFactor = NULL);
void addVectorOperator(std::map< int, std::shared_ptr<OperatorType> > ops); void addVectorOperator(std::map< int, std::shared_ptr<OperatorType> > ops);
void addVectorOperator(std::map< int, std::pair<std::shared_ptr<OperatorType>, bool> > ops); void addVectorOperator(std::map< int, std::pair<std::shared_ptr<OperatorType>, bool> > ops);
...@@ -314,14 +333,14 @@ namespace AMDiS ...@@ -314,14 +333,14 @@ namespace AMDiS
bool getElementMatrix(RowView const& rowView, bool getElementMatrix(RowView const& rowView,
ColView const& colView, ColView const& colView,
ElementMatrix& elementMatrix, ElementMatrix& elementMatrix,
std::list<std::shared_ptr<OperatorType>>& operators, std::list<ScaledOperator>& operators,
std::list<double*> const& factors); std::list<ScaledBoundaryOperator>& boundary_operators);
template <class RowView> template <class RowView>
bool getElementVector(RowView const& rowView, bool getElementVector(RowView const& rowView,
ElementVector& elementVector, ElementVector& elementVector,
std::list<std::shared_ptr<OperatorType>>& operators, std::list<ScaledOperator>& operators,
std::list<double*> const& factors); std::list<ScaledBoundaryOperator>& boundary_operators);
template <class Matrix, class RowIndexSet, class ColIndexSet> template <class Matrix, class RowIndexSet, class ColIndexSet>
...@@ -374,29 +393,30 @@ namespace AMDiS ...@@ -374,29 +393,30 @@ namespace AMDiS
template <class T> template <class T>
using MatrixEntries = std::map< std::pair<int,int>, std::list<T> >; using MatrixEntries = Dune::FieldMatrix<T, nComponents, nComponents>;
template <class T> template <class T>
using VectorEntries = std::map< int, std::list<T> >; using VectorEntries = Dune::FieldVector<T, nComponents>;
using BoundaryCondition = std::list<std::shared_ptr<DirichletBC<WorldVector>>>;
/// A map (i,j) -> list<DirichleBC> string a boundary conditions for /// A map (i,j) -> list<DirichleBC> string a boundary conditions for
/// each matrix block /// each matrix block
MatrixEntries<std::shared_ptr<DirichletBC<WorldVector>>> dirichletBc; MatrixEntries<BoundaryCondition> dirichletBc;
/// A map (i,j) -> list<OperatorType> string the differential operators for /// A map (i,j) -> list<OperatorType> string the differential operators for
/// each matrix block /// each matrix block
MatrixEntries<std::shared_ptr<OperatorType>> matrixOperators; MatrixEntries<std::list<ScaledOperator>> matrixOperators;
MatrixEntries<double*> matrixFactors; MatrixEntries<std::list<ScaledBoundaryOperator>> matrixBoundaryOperators;
std::map< std::pair<int,int>, bool > matrixAssembled; // if false, do reassemble MatrixEntries<bool> matrixAssembled; // if false, do reassemble
std::map< std::pair<int,int>, bool > matrixChanging; // if true, or vectorAssembled false, do reassemble MatrixEntries<bool> matrixChanging; // if true, or vectorAssembled false, do reassemble
/// A map (i) -> list<OperatorType> string the differential operators for /// A map (i) -> list<OperatorType> string the differential operators for
/// each rhs block /// each rhs block
VectorEntries<std::shared_ptr<OperatorType>> vectorOperators; VectorEntries<std::list<ScaledOperator>> vectorOperators;
VectorEntries<double*> vectorFactors; VectorEntries<std::list<ScaledBoundaryOperator>> vectorBoundaryOperators;
std::map< int, bool > vectorAssembled; // if false, do reassemble VectorEntries<bool> vectorAssembled; // if false, do reassemble
std::map< int, bool > vectorChanging; // if true, or vectorAssembled false, do reassemble VectorEntries<bool> vectorChanging; // if true, or vectorAssembled false, do reassemble
template <int R, int C> template <int R, int C>
struct MatrixData struct MatrixData
...@@ -404,12 +424,13 @@ namespace AMDiS ...@@ -404,12 +424,13 @@ namespace AMDiS
using DOFMatrixType = using DOFMatrixType =
std::tuple_element_t<C, std::tuple_element_t<R, typename SystemMatrixType::DOFMatrices>>; std::tuple_element_t<C, std::tuple_element_t<R, typename SystemMatrixType::DOFMatrices>>;
DOFMatrixType& matrix; DOFMatrixType& matrix;
std::list<std::shared_ptr<OperatorType>>& operators; std::list<ScaledOperator>& operators;
std::list<double*> const& factors; std::list<ScaledBoundaryOperator>& boundary_operators;
bool assemble = true; bool assemble = true;
std::pair<int,int> row_col = {R, C}; int const row = R;
int const col = C;
}; };
template <int I> template <int I>
...@@ -417,12 +438,12 @@ namespace AMDiS ...@@ -417,12 +438,12 @@ namespace AMDiS
{ {
using DOFVectorType = std::tuple_element_t<I, typename SystemVectorType::DOFVectors>; using DOFVectorType = std::tuple_element_t<I, typename SystemVectorType::DOFVectors>;
DOFVectorType& vector; DOFVectorType& vector;
std::list<std::shared_ptr<OperatorType>>& operators; std::list<ScaledOperator>& operators;
std::list<double*> const& factors; std::list<ScaledBoundaryOperator>& boundary_operators;
bool assemble = true; bool assemble = true;
int row = I; int const index = I;
}; };
}; };
......
...@@ -107,83 +107,75 @@ namespace AMDiS ...@@ -107,83 +107,75 @@ namespace AMDiS
template <class Traits> template <class Traits>
void ProblemStatSeq<Traits>::addMatrixOperator(std::shared_ptr<OperatorType> op, void ProblemStatSeq<Traits>::
int i, int j, addMatrixOperator(OperatorType const& op, int i, int j, double* factor, double* estFactor)
double* factor,
double* estFactor)
{ {
// TODO: currently the factors are ignored matrixOperators[i][j].emplace_back(std::make_shared<OperatorType>(op), factor, estFactor);
assert( estFactor == NULL ); matrixChanging[i][j] = true;
matrixOperators[{i,j}].push_back(op);
matrixFactors[{i,j}].push_back(factor);
matrixChanging[{i,j}] = true;
} }
template <class Traits> template <class Traits>
void ProblemStatSeq<Traits>::addMatrixOperator(OperatorType& op, void ProblemStatSeq<Traits>::
int i, int j, addBoundaryMatrixOperator(BoundaryType b, OperatorType const& op, int i, int j, double* factor, double* estFactor)
double* factor,
double* estFactor)
{ {
addMatrixOperator(std::make_shared<OperatorType>(op), i, j, factor, estFactor); matrixBoundaryOperators[i][j].emplace_back(std::make_shared<OperatorType>(op), b, factor, estFactor);
matrixChanging[i][j] = true;
} }
template <class Traits> template <class Traits>
void ProblemStatSeq<Traits>::addMatrixOperator(std::map< std::pair<int,int>, std::shared_ptr<OperatorType> > ops) void ProblemStatSeq<Traits>::addMatrixOperator(std::map< std::pair<int,int>, std::shared_ptr<OperatorType> > ops)
{ {
for (auto op : ops) for (auto op : ops){
addMatrixOperator(op.second, op.first.first, op.first.second); int r = op.first.first;
int c = op.first.second;
matrixOperators[r][c].emplace_back(op.second);
matrixChanging[r][c] = true;
}
} }
template <class Traits> template <class Traits>
void ProblemStatSeq<Traits>::addMatrixOperator(std::map< std::pair<int,int>, std::pair<std::shared_ptr<OperatorType>,bool> > ops) void ProblemStatSeq<Traits>::addMatrixOperator(std::map< std::pair<int,int>, std::pair<std::shared_ptr<OperatorType>,bool> > ops)
{ {
for (auto op : ops) { for (auto op : ops) {
auto row_col = op.first; int r = op.first.first;
matrixOperators[row_col].push_back(op.second.first); int c = op.first.second;
matrixFactors[row_col].push_back(NULL); matrixOperators[r][c].emplace_back(op.second.first);
matrixChanging[row_col] = matrixChanging[row_col] || op.second.second; matrixChanging[r][c] = matrixChanging[r][c] || op.second.second;
} }
} }
template <class Traits> template <class Traits>
void ProblemStatSeq<Traits>::addVectorOperator(std::shared_ptr<OperatorType> op, void ProblemStatSeq<Traits>::
int i, addVectorOperator(OperatorType const& op, int i, double* factor, double* estFactor)
double* factor,
double* estFactor)
{ {
// TODO: currently the est-factors are ignored vectorOperators[i].emplace_back(std::make_shared<OperatorType>(op), factor, estFactor);
assert( estFactor == NULL );
vectorOperators[i].push_back(op);
vectorFactors[i].push_back(factor);
vectorChanging[i] = true; vectorChanging[i] = true;
} }
template <class Traits> template <class Traits>
void ProblemStatSeq<Traits>::addVectorOperator(OperatorType& op, void ProblemStatSeq<Traits>::
int i, addBoundaryVectorOperator(BoundaryType b, OperatorType const& op, int i, double* factor, double* estFactor)
double* factor,
double* estFactor)
{ {
addVectorOperator(std::make_shared<OperatorType>(op), i, factor, estFactor); vectorBoundaryOperators[i].emplace_back(std::make_shared<OperatorType>(op), b, factor, estFactor);
vectorChanging[i] = true;
} }
template <class Traits> template <class Traits>
void ProblemStatSeq<Traits>::addVectorOperator(std::map< int, std::shared_ptr<OperatorType> > ops) void ProblemStatSeq<Traits>::addVectorOperator(std::map< int, std::shared_ptr<OperatorType> > ops)
{ {
for (auto op : ops) for (auto op : ops) {
addVectorOperator(op.second, op.first); vectorOperators[op.first].emplace_back(op.second);
vectorChanging[op.first] = true;
}
} }
template <class Traits> template <class Traits>
void ProblemStatSeq<Traits>::addVectorOperator(std::map< int, std::pair<std::shared_ptr<OperatorType>, bool> > ops) void ProblemStatSeq<Traits>::addVectorOperator(std::map< int, std::pair<std::shared_ptr<OperatorType>, bool> > ops)
{ {
for (auto op : ops) { for (auto op : ops) {