Commit 633b910f authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

some cleanup

parent 5a874ddf
Pipeline #903 failed with stage
in 2 minutes and 2 seconds
......@@ -8,8 +8,9 @@ DEPENDENCIES=@REQUIRES@
Name: @PACKAGE_NAME@
Version: @VERSION@
Description: amdis module
URL: http://www.github.com/spraetor
Description: AMDiS dune-module
URL: https://gitlab.math.tu-dresden.de/spraetor/dune-amdis
Requires: dune-common dune-geometry dune-localfunctions dune-istl dune-typetree dune-grid dune-functions
Suggests: dune-uggrid dune-alugrid
Libs: -L${libdir}
Cflags: -I${includedir}
......@@ -8,3 +8,4 @@ Version: 0.1
Maintainer: simon.praetorius@tu-dresden.de
#depending on
Depends: dune-common dune-geometry dune-localfunctions dune-istl dune-typetree dune-grid dune-functions
Suggests: dune-uggrid dune-alugrid
......@@ -82,8 +82,8 @@ namespace AMDiS
template <class MeshView>
template <class RowView, class ColView>
bool Operator<MeshView>::getElementMatrix(RowView const& rowView,
ColView const& colView,
ElementMatrix& elementMatrix,
ColView const& colView,
ElementMatrix& elementMatrix,
double* factor)
{
AMDIS_FUNCNAME("Operator::getElementMatrix()");
......@@ -132,7 +132,7 @@ namespace AMDiS
template <class MeshView>
template <class RowView>
bool Operator<MeshView>::getElementVector(RowView const& rowView,
ElementVector& elementVector,
ElementVector& elementVector,
double* factor)
{
AMDIS_FUNCNAME("Operator::getElementVector()");
......@@ -175,8 +175,8 @@ namespace AMDiS
template <class MeshView>
template <class RowView, class ColView>
void Operator<MeshView>::assembleZeroOrderTerms(RowView const& rowView,
ColView const& colView,
ElementMatrix& elementMatrix)
ColView const& colView,
ElementMatrix& elementMatrix)
{
AMDIS_FUNCNAME("Operator::assembleZeroOrderTerms(elementMatrix)");
......@@ -196,7 +196,7 @@ namespace AMDiS
for (size_t iq = 0; iq < quad.size(); ++iq) {
// Position of the current quadrature point in the reference element
const Dune::FieldVector<double,dim>& quadPos = quad[iq].position();
Dune::FieldVector<double,dim> const& quadPos = quad[iq].position();
// The multiplicative factor in the integral transformation formula
const double factor = geometry.integrationElement(quadPos) * quad[iq].weight();
......@@ -226,7 +226,7 @@ namespace AMDiS
template <class MeshView>
template <class RowView>
void Operator<MeshView>::assembleZeroOrderTerms(RowView const& rowView,
ElementVector& elementvector)
ElementVector& elementvector)
{
AMDIS_FUNCNAME("Operator::assembleZeroOrderTerms(elementvector)");
......@@ -241,9 +241,7 @@ namespace AMDiS
auto const& quad = Dune::QuadratureRules<double, dim>::rule(element.type(), order);
for (auto* operatorTerm : zeroOrder)
operatorTerm->init(element, quad);
operatorTerm->init(element, quad);
for (size_t iq = 0; iq < quad.size(); ++iq) {
// Position of the current quadrature point in the reference element
......@@ -267,8 +265,8 @@ namespace AMDiS
template <class MeshView>
template <class RowView, class ColView>
void Operator<MeshView>::assembleFirstOrderTermsGrdPhi(RowView const& rowView,
ColView const& colView,
ElementMatrix& elementMatrix)
ColView const& colView,
ElementMatrix& elementMatrix)
{
AMDIS_FUNCNAME("Operator::assembleFirstOrderTermsGrdPhi(elementMatrix)");
......@@ -286,8 +284,6 @@ namespace AMDiS
for (auto* operatorTerm : firstOrderGrdPhi)
operatorTerm->init(element, quad);
for (size_t iq = 0; iq < quad.size(); ++iq) {
// Position of the current quadrature point in the reference element
const Dune::FieldVector<double,dim>& quadPos = quad[iq].position();
......@@ -327,8 +323,8 @@ namespace AMDiS
template <class MeshView>
template <class RowView, class ColView>
void Operator<MeshView>::assembleFirstOrderTermsGrdPsi(RowView const& rowView,
ColView const& colView,
ElementMatrix& elementMatrix)
ColView const& colView,
ElementMatrix& elementMatrix)
{
AMDIS_FUNCNAME("Operator::assembleFirstOrderTermsGrdPsi(elementMatrix)");
......@@ -435,8 +431,8 @@ namespace AMDiS
template <class MeshView>
template <class RowView, class ColView>
void Operator<MeshView>::assembleSecondOrderTerms(RowView const& rowView,
ColView const& colView,
ElementMatrix& elementMatrix)
ColView const& colView,
ElementMatrix& elementMatrix)
{
AMDIS_FUNCNAME("Operator::assembleSecondOrderTerms(elementMatrix)");
......@@ -517,7 +513,7 @@ namespace AMDiS
template <class MeshView>
template <class Term>
Operator<MeshView>& Operator<MeshView>::addFOTImpl(Term const& term,
std::size_t i,
size_t i,
FirstOrderType firstOrderType)
{
using OpTerm = GenericOperatorTerm<MeshView, Term, VectorComponent>;
......@@ -542,7 +538,7 @@ namespace AMDiS
template <class MeshView>
template <class Term>
Operator<MeshView>& Operator<MeshView>::addSOTImpl(Term const& term,
std::size_t i, std::size_t j)
size_t i, size_t j)
{
using OpTerm = GenericOperatorTerm<MeshView, Term, MatrixComponent>;
secondOrder.push_back(new OpTerm(term, {i,j}));
......
......@@ -30,8 +30,7 @@ namespace AMDiS
using PointList = std::vector<Dune::QuadraturePoint<double, dim>>;
public:
virtual void init(Element const& element,
PointList const& points) = 0;
virtual void init(Element const& element, PointList const& points) = 0;
virtual double evalZot(size_t iq,
Dune::FieldVector<double,1> const& test,
......@@ -58,7 +57,7 @@ namespace AMDiS
template <class MeshView, class Term, class Traits = tag::none>
class GenericOperatorTerm
: public OperatorTerm<MeshView>
, public OperatorEvaluation
, public OperatorEvaluation // NOTE: better: use static functions
{
using Super = OperatorTerm<MeshView>;
using Element = typename Super::Element;
......@@ -73,8 +72,7 @@ namespace AMDiS
, traits(traits)
{}
virtual void init(Element const& element,
PointList const& points) override
virtual void init(Element const& element, PointList const& points) override
{
term.init(element, points);
......@@ -122,9 +120,9 @@ namespace AMDiS
Traits traits;
using value_type = std::decay_t< decltype( std::declval<Term>()[std::declval<size_t>()] ) >;
using _cat = ValueCategory_t<value_type>;
using _cat = ValueCategory_t<value_type>;
std::vector<value_type> values;
std::vector<value_type> values; // NOTE: maybe caching is not necessary here, since cached already in the term
};
} // end namespace AMDiS
......@@ -8,7 +8,7 @@ namespace AMDiS
{
// forward declarations
class AdaptInfo;
/**
* \ingroup Problem
*
......@@ -21,22 +21,19 @@ namespace AMDiS
{
using Self = ProblemInstat;
using ProblemType = ProblemStat<Traits>;
using SystemVectorType = typename ProblemType::SystemVectorType;
public:
/// Constructs a ProblemInstat with prob as its stationary problem.
ProblemInstat(std::string name,
ProblemType& prob)
: ProblemInstatBase(name, NULL),
problemStat(prob)
ProblemInstat(std::string name, ProblemType& prob)
: ProblemInstatBase(name, nullptr)
, problemStat(prob)
{}
ProblemInstat(std::string name,
ProblemType& prob,
ProblemStatBase& initialProb)
: ProblemInstatBase(name, &initialProb),
problemStat(prob)
ProblemInstat(std::string name, ProblemType& prob, ProblemStatBase& initialProb)
: ProblemInstatBase(name, &initialProb)
, problemStat(prob)
{}
/// Initialisation of the problem.
......@@ -60,10 +57,10 @@ namespace AMDiS
/// Returns \ref oldSolution.
decltype(auto) getOldSolution() { return *oldSolution; }
decltype(auto) getOldSolution() const { return *oldSolution; }
/// Returns the I'th component of \ref oldSolution.
template <size_t I = 0>
decltype(auto) getOldSolution(const index_<I> _i = index_<I>())
decltype(auto) getOldSolution(const index_<I> _i = {})
{
return (*oldSolution)[_i];
}
......@@ -76,14 +73,14 @@ namespace AMDiS
ProblemType& problemStat;
/// Solution of the last timestep.
shared_ptr<SystemVectorType> oldSolution;
std::shared_ptr<SystemVectorType> oldSolution;
};
#ifndef AMDIS_NO_EXTERN_PROBLEMINSTAT
extern template class ProblemInstat<ProblemStatTraits<2>>;
#endif
} // end namespace AMDiS
#include "ProblemInstat.inc.hpp"
......@@ -7,6 +7,8 @@ namespace AMDiS
template <class Traits>
void ProblemInstat<Traits>::transferInitialSolution(AdaptInfo& adaptInfo)
{
AMDIS_FUNCNAME("ProblemInstat::transferInitialSolution()");
test_exit(adaptInfo.getTime() == adaptInfo.getStartTime(),
"after initial solution: time != start time");
problemStat.writeFiles(adaptInfo, true);
......@@ -24,8 +26,6 @@ namespace AMDiS
template <class Traits>
void ProblemInstat<Traits>::initialize(Flag initFlag)
{
AMDIS_FUNCNAME("ProblemInstat::initialize()");
// === create vector for old solution ===
if (initFlag.isSet(INIT_UH_OLD))
createUhOld();
......@@ -35,6 +35,8 @@ namespace AMDiS
template <class Traits>
void ProblemInstat<Traits>::createUhOld()
{
AMDIS_FUNCNAME("ProblemInstat::createUhOld()");
if (oldSolution) {
warning("oldSolution already created\n");
}
......@@ -43,7 +45,7 @@ namespace AMDiS
// create oldSolution
std::vector<std::string> componentNames(size, name + "_uOld");
oldSolution = make_shared<SystemVectorType>(*problemStat.getFeSpaces(), componentNames);
oldSolution = std::make_shared<SystemVectorType>(*problemStat.getFeSpaces(), componentNames);
}
}
......
......@@ -7,15 +7,16 @@ namespace AMDiS
{
// forward declarations
class AdaptInfo;
/**
* \ingroup Problem
*
* \brief
* Base class for \ref ProblemInstat.
*/
class ProblemInstatBase : public ProblemTimeInterface,
public ProblemStatBase // NOTE: Why is this derived from ProblemStatBase
class ProblemInstatBase
: public ProblemTimeInterface
, public ProblemStatBase // NOTE: Why is this derived from ProblemStatBase
{
public:
/// Constructor.
......
......@@ -35,7 +35,8 @@ namespace AMDiS
{
template <class Traits>
class ProblemStatSeq : public ProblemStatBase
class ProblemStatSeq
: public ProblemStatBase
{
using Self = ProblemStatSeq;
......@@ -98,26 +99,26 @@ namespace AMDiS
* MESH[0]->global refinements: nr of initial global refinements
**/
void initialize(Flag initFlag,
Self* adoptProblem = NULL,
Flag adoptFlag = INIT_NOTHING);
Self* adoptProblem = NULL,
Flag adoptFlag = INIT_NOTHING);
/// Adds an operator to \ref A.
/** @{ */
void addMatrixOperator(OperatorType& op,
int i, int j,
int i, int j,
double* factor = NULL,
double* estFactor = NULL);
void addMatrixOperator(shared_ptr<OperatorType> op,
void addMatrixOperator(std::shared_ptr<OperatorType> op,
int i, int j,
double* factor = NULL,
double* estFactor = NULL);
void addMatrixOperator(std::map< std::pair<int,int>,
shared_ptr<OperatorType> > ops);
std::shared_ptr<OperatorType> > ops);
void addMatrixOperator(std::map< std::pair<int,int>,
std::pair<shared_ptr<OperatorType>, bool> > ops);
std::pair<std::shared_ptr<OperatorType>, bool> > ops);
/** @} */
......@@ -128,40 +129,39 @@ namespace AMDiS
double* factor = NULL,
double* estFactor = NULL);
void addVectorOperator(shared_ptr<OperatorType> op,
void addVectorOperator(std::shared_ptr<OperatorType> op,
int i,
double* factor = NULL,
double* estFactor = NULL);
void addVectorOperator(std::map< int,
shared_ptr<OperatorType> > ops);
void addVectorOperator(std::map< int,
std::pair<shared_ptr<OperatorType>, bool> > ops);
void addVectorOperator(std::map< int, std::shared_ptr<OperatorType> > ops);
void addVectorOperator(std::map< int, std::pair<std::shared_ptr<OperatorType>, bool> > ops);
/** @} */
/// Adds a Dirichlet boundary condition
template <class Predicate, class Values>
void addDirichletBC(Predicate const& predicate,
int row, int col,
Values const& values);
int row, int col,
Values const& values);
/// Implementation of \ref ProblemStatBase::solve
virtual void solve(AdaptInfo& adaptInfo,
bool createMatrixData = true,
bool storeMatrixData = false) override;
bool createMatrixData = true,
bool storeMatrixData = false) override;
/// Implementation of \ref ProblemStatBase::buildAfterCoarse
virtual void buildAfterCoarsen(AdaptInfo& adaptInfo,
Flag flag,
bool asmMatrix = true,
bool asmVector = true) override;
Flag flag,
bool asmMatrix = true,
bool asmVector = true) override;
/// Writes output files.
void writeFiles(AdaptInfo& adaptInfo, bool force = false);
public: // get-methods
/// Returns nr of components \ref nComponents
......@@ -196,9 +196,9 @@ namespace AMDiS
/// Return the \ref linearSolver
auto getSolver() { return linearSolver; }
void setSolver(std::shared_ptr<LinearSolverType> const& solver_)
void setSolver(std::shared_ptr<LinearSolverType> const& solver)
{
linearSolver = solver_;
linearSolver = solver;
}
/// Return the \ref mesh
......@@ -207,7 +207,7 @@ namespace AMDiS
void setMesh(std::shared_ptr<Mesh> const& mesh_)
{
mesh = mesh_;
meshView = make_shared<MeshView>(mesh->leafGridView());
meshView = std::make_shared<MeshView>(mesh->leafGridView());
createFeSpaces();
createMatricesAndVectors();
......@@ -251,7 +251,7 @@ namespace AMDiS
"No mesh name specified for '", name, "->mesh'!");
mesh = MeshCreator<Mesh>::create(meshName);
meshView = make_shared<MeshView>(mesh->leafGridView());
meshView = std::make_shared<MeshView>(mesh->leafGridView());
msg("Create mesh:");
msg("#elements = " , mesh->size(0));
......@@ -262,16 +262,16 @@ namespace AMDiS
void createFeSpaces()
{
feSpaces = make_shared<FeSpaces>(constructTuple<FeSpaces>(*meshView));
feSpaces = std::make_shared<FeSpaces>(constructTuple<FeSpaces>(*meshView));
}
void createMatricesAndVectors()
{
systemMatrix = make_shared<SystemMatrixType>(*feSpaces);
solution = make_shared<SystemVectorType>(*feSpaces, componentNames);
systemMatrix = std::make_shared<SystemMatrixType>(*feSpaces);
solution = std::make_shared<SystemVectorType>(*feSpaces, componentNames);
auto rhsNames = std::vector<std::string>(nComponents, "rhs");
rhs = make_shared<SystemVectorType>(*feSpaces, rhsNames);
rhs = std::make_shared<SystemVectorType>(*feSpaces, rhsNames);
}
void createSolver()
......@@ -287,11 +287,10 @@ namespace AMDiS
void createFileWriter()
{
filewriter = make_shared<FileWriter<Traits>>(name + "->output",
*meshView,
componentNames);
filewriter = std::make_shared<FileWriter<Traits>>(name + "->output", *meshView, componentNames);
}
protected: // sub-methods to assemble DOFMatrix
template <class LhsData, class RhsData, class Elements>
......@@ -299,37 +298,28 @@ namespace AMDiS
template <class RowView, class ColView>
bool getElementMatrix(RowView const& rowView,
ColView const& colView,
ElementMatrix& elementMatrix,
std::list<shared_ptr<OperatorType>>& operators,
ColView const& colView,
ElementMatrix& elementMatrix,
std::list<std::shared_ptr<OperatorType>>& operators,
std::list<double*> const& factors);
template <class RowView>
bool getElementVector(RowView const& rowView,
ElementVector& elementVector,
std::list<shared_ptr<OperatorType>>& operators,
ElementVector& elementVector,
std::list<std::shared_ptr<OperatorType>>& operators,
std::list<double*> const& factors);
template <class Matrix, class RowIndexSet, class ColIndexSet>
void addElementMatrix(Matrix& matrix,
RowIndexSet const& rowIndexSet,
ColIndexSet const& colIndexSet,
ElementMatrix const& elementMatrix);
RowIndexSet const& rowIndexSet,
ColIndexSet const& colIndexSet,
ElementMatrix const& elementMatrix);
template <class Vector, class IndexSet>
void addElementVector(Vector& vector,
IndexSet const& indexSet,
ElementVector const& elementvector);
private: // some internal methods
template <size_t I = 0>
typename FeSpace<I>::NodeFactory&
getNodeFactory(const index_<I> = index_<I>())
{
return const_cast<typename FeSpace<I>::NodeFactory&>(std::get<I>(*feSpaces).nodeFactory());
}
IndexSet const& indexSet,
ElementVector const& elementvector);
private:
......@@ -341,35 +331,35 @@ namespace AMDiS
std::vector<std::string> componentNames;
/// Mesh of this problem.
shared_ptr<Mesh> mesh; // TODO: generalize to multi-mesh problems
std::shared_ptr<Mesh> mesh; // TODO: generalize to multi-mesh problems
/// Name of the mesh
std::string meshName;
/// A gridView object
shared_ptr<MeshView> meshView;
std::shared_ptr<MeshView> meshView;
/// Pointer to the meshes for the different problem components
std::vector<Mesh*> componentMeshes;
/// FE spaces of this problem.
shared_ptr<FeSpaces> feSpaces; // eventuell const
std::shared_ptr<FeSpaces> feSpaces; // eventuell const
/// A FileWriter object
shared_ptr<FileWriter<Traits>> filewriter;
std::shared_ptr<FileWriter<Traits>> filewriter;
/// An object of the linearSolver Interface
shared_ptr<LinearSolverType> linearSolver;
std::shared_ptr<LinearSolverType> linearSolver;
/// A block-matrix that is filled during assembling
shared_ptr<SystemMatrixType> systemMatrix;
std::shared_ptr<SystemMatrixType> systemMatrix;
/// A block-vector with the solution components
shared_ptr<SystemVectorType> solution;
std::shared_ptr<SystemVectorType> solution;
/// A block-vector (load-vector) corresponding to the right.hand side
/// of the equation, filled during assembling
shared_ptr<SystemVectorType> rhs;
std::shared_ptr<SystemVectorType> rhs;
template <class T>
......@@ -381,48 +371,47 @@ namespace AMDiS
/// A map (i,j) -> list<DirichleBC> string a boundary conditions for
/// each matrix block
MatrixEntries<shared_ptr<DirichletBC<WorldVector>>> dirichletBc;
MatrixEntries<std::shared_ptr<DirichletBC<WorldVector>>> dirichletBc;
/// A map (i,j) -> list<OperatorType> string the differential operators for
/// each matrix block
MatrixEntries<shared_ptr<OperatorType>> matrixOperators;
MatrixEntries<std::shared_ptr<OperatorType>> matrixOperators;
MatrixEntries<double*> matrixFactors;
std::map< std::pair<int,int>, bool > matrixAssembled; // if false, do reassemble
std::map< std::pair<int,int>, bool > matrixChanging; // if true, or vectorAssembled false, do reassemble
/// A map (i) -> list<OperatorType> string the differential operators for
/// each rhs block
VectorEntries<shared_ptr<OperatorType>> vectorOperators;
VectorEntries<std::shared_ptr<OperatorType>> vectorOperators;
VectorEntries<double*> vectorFactors;
std::map< int, bool > vectorAssembled; // if false, do reassemble
std::map< int, bool > vectorChanging; // if true, or vectorAssembled false, do reassemble
template <int r, int c>
template <int R, int C>
struct MatrixData
{
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;
std::list<shared_ptr<OperatorType>>& operators;
std::list<std::shared_ptr<OperatorType>>& operators;
std::list<double*> const& factors;
bool assemble;
std::pair<int,int> row_col = {r, c};
std::pair<int,int> row_col = {R, C};
};
template <int r>
template <int I>
struct VectorData
{
using DOFVectorType =
std::tuple_element_t<r, typename SystemVectorType::DOFVectors>;
using DOFVectorType = std::tuple_element_t<I, typename SystemVectorType::DOFVectors>;
DOFVectorType& vector;
std::list<shared_ptr<OperatorType>>& operators;
std::list<std::shared_ptr<OperatorType>>& operators;
std::list<double*> const& factors;
bool assemble;
int row = r;
int row = I;
};
};
......@@ -437,8 +426,9 @@ namespace AMDiS
namespace Impl
{
template <class ProblemStatType>
struct ProblemStat : public ProblemStatType,