Commit 2ab573aa authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

cleanup of source-tree, new directory common for commonly used functionality,...

cleanup of source-tree, new directory common for commonly used functionality, advanced addMatrixOperator syntax, OperatorTerm creation from Operators.
parent 24a3d588
...@@ -62,37 +62,73 @@ install(FILES ...@@ -62,37 +62,73 @@ install(FILES
AdaptInstationary.hpp AdaptInstationary.hpp
AdaptStationary.hpp AdaptStationary.hpp
AMDiS.hpp AMDiS.hpp
Basic.hpp CreatorInterface.hpp
CreatorMap.hpp
DirichletBC.hpp DirichletBC.hpp
DirichletBC.inc.hpp DirichletBC.inc.hpp
FileWriter.hpp
Flag.hpp Flag.hpp
IndexSeq.hpp
Initfile.hpp Initfile.hpp
LinearAlgebra.hpp
Log.hpp Log.hpp
Loop.hpp
Math.hpp Math.hpp
Mesh.hpp
OperatorEvaluation.hpp
Operator.hpp Operator.hpp
Operator.inc.hpp Operator.inc.hpp
OperatorTermBase.hpp
OperatorTerm.hpp OperatorTerm.hpp
ProblemInstatBase.hpp ProblemInstatBase.hpp
ProblemInstat.hpp ProblemInstat.hpp
ProblemInstat.inc.hpp ProblemInstat.inc.hpp
ProblemInterationInterface.hpp ProblemInterationInterface.hpp
ProblemStatBase.hpp
ProblemStat.hpp ProblemStat.hpp
ProblemStat.inc.hpp ProblemStat.inc.hpp
ProblemStatBase.hpp
ProblemTimeInterface.hpp ProblemTimeInterface.hpp
StandardProblemIteration.hpp StandardProblemIteration.hpp
Timer.hpp TermGenerator.hpp
common/ConceptsBase.hpp
common/ClonablePtr.hpp
common/IndexSeq.hpp
common/Literals.hpp
common/Loops.hpp
common/Mpl.hpp
common/ScalarTypes.hpp
common/Timer.hpp
common/Traits.hpp
common/TupleUtility.hpp
common/Utility.hpp
common/ValueCategory.hpp
linear_algebra/LinearAlgebraBse.hpp
linear_algebra/LinearSolverInterface.hpp
linear_algebra/PreconditionerInterface.hpp
linear_algebra/RunnerInterface.hpp
linear_algebra/SolverInfo.hpp
linear_algebra/istl/DOFMatrix.hpp linear_algebra/istl/DOFMatrix.hpp
linear_algebra/istl/DOFVector.hpp linear_algebra/istl/DOFVector.hpp
linear_algebra/istl/ISTL_Preconditioner.hpp
linear_algebra/istl/ISTLRunner.hpp
linear_algebra/istl/ISTL_Solver.hpp
linear_algebra/istl/LinearSolver.hpp linear_algebra/istl/LinearSolver.hpp
linear_algebra/istl/Preconditioner.hpp linear_algebra/istl/Preconditioner.hpp
linear_algebra/istl/SystemMatrix.hpp linear_algebra/istl/SystemMatrix.hpp
linear_algebra/istl/SystemVector.hpp linear_algebra/istl/SystemVector.hpp
linear_algebra/mtl/BITL_Preconditioner.hpp
linear_algebra/mtl/BITL_Solver.hpp
linear_algebra/mtl/BlockMTLMatrix.hpp
linear_algebra/mtl/BlockMTLVector.hpp
linear_algebra/mtl/Copy.hpp
linear_algebra/mtl/DOFMatrix.hpp linear_algebra/mtl/DOFMatrix.hpp
linear_algebra/mtl/DOFVector.hpp linear_algebra/mtl/DOFVector.hpp
linear_algebra/mtl/ITL_Preconditioner.hpp
linear_algebra/mtl/ITL_Solver.hpp
linear_algebra/mtl/KrylovRunner.hpp
linear_algebra/mtl/LinearSolver.hpp linear_algebra/mtl/LinearSolver.hpp
linear_algebra/mtl/Mapper.hpp
linear_algebra/mtl/MTLDenseVector.hpp
linear_algebra/mtl/Preconditioner.hpp
linear_algebra/mtl/SystemMatrix.hpp linear_algebra/mtl/SystemMatrix.hpp
linear_algebra/mtl/SystemVector.hpp linear_algebra/mtl/SystemVector.hpp
linear_algebra/mtl/UmfpackRunner.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/amdis) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/amdis)
#pragma once #pragma once
#include <memory>
#include <string> #include <string>
#include <dune/amdis/Basic.hpp> #include <dune/amdis/Log.hpp>
namespace AMDiS namespace AMDiS
{ {
...@@ -57,7 +58,14 @@ namespace AMDiS ...@@ -57,7 +58,14 @@ namespace AMDiS
virtual std::shared_ptr<BaseClass> create(std::string) = 0; virtual std::shared_ptr<BaseClass> create(std::string) = 0;
}; };
template <class T>
void addDefaultCreators(Type<T>); /// cast a ptr of CreatorInterface to CreatorInterfaceName
template <class BaseClass>
inline CreatorInterfaceName<BaseClass>* named(CreatorInterface<BaseClass>* ptr)
{
auto result = dynamic_cast<CreatorInterfaceName<BaseClass>*>(ptr);
AMDIS_TEST_EXIT_DBG(result, "Can not cast CreatorInterface to CreatorInterfaceName!");
return result;
}
} // end namespace AMDiS } // end namespace AMDiS
...@@ -8,6 +8,13 @@ ...@@ -8,6 +8,13 @@
namespace AMDiS namespace AMDiS
{ {
// forward declaration.
// All classes that need creators must specialize this class and implement
// a static void init() method.
template <class BaseClass>
struct DefaultCreators;
/** \ingroup Common /** \ingroup Common
* \brief * \brief
* A CreatorMap is used to construct objects, which types depends on key words * A CreatorMap is used to construct objects, which types depends on key words
...@@ -54,7 +61,7 @@ namespace AMDiS ...@@ -54,7 +61,7 @@ namespace AMDiS
{ {
if (!initialized) { if (!initialized) {
initialized = true; initialized = true;
addDefaultCreators(Type<BaseClass>{}); DefaultCreators<BaseClass>::init();
} }
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <type_traits> #include <type_traits>
#include <vector> #include <vector>
#include <dune/functions/common/functionconcepts.hh> #include <dune/amdis/common/ConceptsBase.hpp>
#include "Log.hpp" #include "Log.hpp"
...@@ -15,8 +15,8 @@ namespace AMDiS ...@@ -15,8 +15,8 @@ namespace AMDiS
{ {
public: public:
template <class Predicate, class Values, template <class Predicate, class Values,
class = std::enable_if_t< Dune::Functions::Concept::isFunction<Predicate, bool(WorldVector)>() && class = std::enable_if_t< concepts::Functor<Predicate, bool(WorldVector)> &&
Dune::Functions::Concept::isFunction<Values, double(WorldVector)>() > > concepts::Functor<Values, double(WorldVector)> > >
DirichletBC(Predicate&& predicate, Values&& values) DirichletBC(Predicate&& predicate, Values&& values)
: predicate(std::forward<Predicate>(predicate)) : predicate(std::forward<Predicate>(predicate))
, values(std::forward<Values>(values)) , values(std::forward<Values>(values))
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
#include <dune/grid/io/file/vtk/vtksequencewriter.hh> #include <dune/grid/io/file/vtk/vtksequencewriter.hh>
#include <dune/geometry/genericgeometry/referenceelements.hh> #include <dune/geometry/genericgeometry/referenceelements.hh>
#include "Loops.hpp" #include <dune/amdis/Initfile.hpp>
#include "Initfile.hpp" #include <dune/amdis/common/Loops.hpp>
namespace AMDiS namespace AMDiS
{ {
...@@ -52,7 +52,7 @@ namespace AMDiS ...@@ -52,7 +52,7 @@ namespace AMDiS
/// default write method for time-depended data /// default write method for time-depended data
template <class SystemVectorType> template <class SystemVectorType>
void write(double time, SystemVectorType&& solutions) void write(double time, SystemVectorType const& solutions)
{ {
vtkWriter->clear(); vtkWriter->clear();
// copy dofvector to vertex data // copy dofvector to vertex data
...@@ -67,7 +67,7 @@ namespace AMDiS ...@@ -67,7 +67,7 @@ namespace AMDiS
/// default write method for stationary data /// default write method for stationary data
template <class SystemVectorType> template <class SystemVectorType>
void write(SystemVectorType&& solutions) void write(SystemVectorType const& solutions)
{ {
vtkWriter->clear(); vtkWriter->clear();
// copy dofvector to vertex data // copy dofvector to vertex data
......
#pragma once #pragma once
#include "linear_algebra/LinearSolverInterface.hpp" #include <dune/amdis/linear_algebra/LinearSolverInterface.hpp>
#include "linear_algebra/SolverInfo.hpp" #include <dune/amdis/linear_algebra/SolverInfo.hpp>
#if defined(AMDIS_BACKEND_ISTL) #if defined(AMDIS_BACKEND_ISTL)
#include "linear_algebra/istl/SystemVector.hpp" #include <dune/amdis/linear_algebra/istl/SystemVector.hpp>
#include "linear_algebra/istl/SystemMatrix.hpp" #include <dune/amdis/linear_algebra/istl/SystemMatrix.hpp>
#include "linear_algebra/istl/LinearSolver.hpp" #include <dune/amdis/linear_algebra/istl/LinearSolver.hpp>
#elif defined(AMDIS_BACKEND_MTL) #elif defined(AMDIS_BACKEND_MTL)
#include "linear_algebra/mtl/SystemVector.hpp" #include <dune/amdis/linear_algebra/mtl/SystemVector.hpp>
#include "linear_algebra/mtl/SystemMatrix.hpp" #include <dune/amdis/linear_algebra/mtl/SystemMatrix.hpp>
#include "linear_algebra/mtl/LinearSolver.hpp" #include <dune/amdis/linear_algebra/mtl/LinearSolver.hpp>
#include "linear_algebra/mtl/ITL_Solver.hpp" #include <dune/amdis/linear_algebra/mtl/ITL_Solver.hpp>
#include "linear_algebra/mtl/BITL_Solver.hpp" #include <dune/amdis/linear_algebra/mtl/BITL_Solver.hpp>
#elif defined(AMDIS_BACKEND_PETSC) #elif defined(AMDIS_BACKEND_PETSC)
#include "linear_algebra/petsc/SystemVector.hpp" #include <dune/amdis/linear_algebra/petsc/SystemVector.hpp>
#include "linear_algebra/petsc/SystemMatrix.hpp" #include <dune/amdis/linear_algebra/petsc/SystemMatrix.hpp>
#include "linear_algebra/petsc/LinearSolver.hpp" #include <dune/amdis/linear_algebra/petsc/LinearSolver.hpp>
#else #else
......
...@@ -29,6 +29,14 @@ namespace AMDiS ...@@ -29,6 +29,14 @@ namespace AMDiS
return addZOTImpl(toTerm(c)); return addZOTImpl(toTerm(c));
} }
template <class... Args>
static std::shared_ptr<Self> zot(Args&&... args)
{
auto op = std::make_shared<Self>();
op->addZOT(std::forward<Args>(args)...);
return op;
}
/// Add coefficients for first-order operator < psi, term * grad(phi) > or /// Add coefficients for first-order operator < psi, term * grad(phi) > or
/// < grad(psi), term * phi >, where the first corresponds to /// < grad(psi), term * phi >, where the first corresponds to
...@@ -50,6 +58,14 @@ namespace AMDiS ...@@ -50,6 +58,14 @@ namespace AMDiS
return addFOTImpl(toTerm(b), _i, firstOrderType); return addFOTImpl(toTerm(b), _i, firstOrderType);
} }
template <class... Args>
static std::shared_ptr<Self> fot(Args&&... args)
{
auto op = std::make_shared<Self>();
op->addFOT(std::forward<Args>(args)...);
return op;
}
/// Add coefficients for second-order operator < grad(psi), A * grad(phi) >, /// Add coefficients for second-order operator < grad(psi), A * grad(phi) >,
/// where \p A can be a matrix or a scalar expression. /// where \p A can be a matrix or a scalar expression.
...@@ -69,10 +85,21 @@ namespace AMDiS ...@@ -69,10 +85,21 @@ namespace AMDiS
return addSOTImpl(toTerm(A), _i, _j); return addSOTImpl(toTerm(A), _i, _j);
} }
template <class... Args>
static std::shared_ptr<Self> sot(Args&&... args)
{
auto op = std::make_shared<Self>();
op->addSOT(std::forward<Args>(args)...);
return op;
}
static std::shared_ptr<Self> create()
/// Calls \ref zot(), \ref for() or \ref sot(), depending on template
/// parameter \p Order.
template <size_t Order, class... Args>
static std::shared_ptr<Self> create(Args&&... args)
{ {
return std::make_shared<Self>(); return create(index_<Order>{}, std::forward<Args>(args)...);
} }
...@@ -152,6 +179,25 @@ namespace AMDiS ...@@ -152,6 +179,25 @@ namespace AMDiS
template <class Term, size_t I, size_t J> template <class Term, size_t I, size_t J>
Self& addSOTImpl(Term const& term, const index_<I>, const index_<J>); Self& addSOTImpl(Term const& term, const index_<I>, const index_<J>);
template <class... Args>
static std::shared_ptr<Self> create(index_<0>, Args&&... args)
{
return zot(std::forward<Args>(args)...);
}
template <class... Args>
static std::shared_ptr<Self> create(index_<1>, Args&&... args)
{
return fot(std::forward<Args>(args)...);
}
template <class... Args>
static std::shared_ptr<Self> create(index_<2>, Args&&... args)
{
return sot(std::forward<Args>(args)...);
}
private: private:
/// List of all second order terms /// List of all second order terms
std::list<OperatorTermType*> secondOrder; std::list<OperatorTermType*> secondOrder;
......
#pragma once
#include <cassert>
#include <dune/amdis/common/ValueCategory.hpp>
namespace AMDiS {
template <class K, int SIZE>
K sum(Dune::FieldVector<K, SIZE> const& vector)
{
K result = 0;
for (int i = 0; i < SIZE; ++i)
result += vector[i];
return result;
}
class OperatorEvaluation
{
using Scalar = Dune::FieldVector<double, 1>;
protected:
template <class... Args>
auto evalZotImpl(Args...) const { assert( false ); return 0; }
template <class ValueType>
auto evalZotImpl(tag::scalar, tag::none, ValueType const& v,
Scalar const& test, Scalar const& trial) const
{
return v * test * trial;
}
template <class... Args>
auto evalFotImpl(Args...) const { assert( false ); return 0; }
template <size_t I, class ValueType, class Gradient>
auto evalFotImpl(tag::scalar, VectorComponent<I>, ValueType const& v,
Gradient const& grad_test, Scalar const& trial) const
{
return v * grad_test[I] * trial;
}
template <class ValueType, class Gradient>
auto evalFotImpl(tag::vector, tag::none, ValueType const& v,
Gradient const& grad_test, Scalar const& trial) const
{
return (v * grad_test) * trial;
}
template <class ValueType, class Gradient>
auto evalFotImpl(tag::scalar, tag::none, ValueType const& v,
Gradient const& grad_test, Scalar const& trial) const
{
return v * sum(grad_test) * trial;
}
template <class... Args>
auto evalSotImpl(Args...) const { assert( false ); return 0; }
template <size_t R, size_t C, class ValueType, class Gradient>
auto evalSotImpl(tag::scalar, MatrixComponent<R, C>, ValueType const& v,
Gradient const& grad_test, Gradient const& grad_trial) const
{
return v * (grad_test[R] * grad_trial[C]);
}
template <class ValueType, class Gradient>
auto evalSotImpl(tag::matrix, tag::none, ValueType const& M,
Gradient const& grad_test, Gradient const& grad_trial) const
{
return grad_test * (M * grad_trial);
}
template <class ValueType, class Gradient>
auto evalSotImpl(tag::scalar, tag::none, ValueType const& v,
Gradient const& grad_test, Gradient const& grad_trial) const
{
return v * (grad_test * grad_trial);
}
};
} // end namespace AMDiS
\ No newline at end of file
...@@ -4,125 +4,15 @@ ...@@ -4,125 +4,15 @@
#include <vector> #include <vector>
#include <type_traits> #include <type_traits>
#include <dune/geometry/quadraturerules.hh>
#include <dune/istl/bvector.hh> #include <dune/istl/bvector.hh>
#include <dune/functions/common/functionconcepts.hh> #include <dune/functions/common/functionconcepts.hh>
#include <dune/functions/functionspacebases/pqknodalbasis.hh> #include <dune/functions/functionspacebases/pqknodalbasis.hh>
#include "OperatorTermBase.hpp" #include <dune/amdis/OperatorTermBase.hpp>
#include <dune/amdis/common/Traits.hpp>
namespace AMDiS namespace AMDiS
{ {
template <class MeshView>
class OperatorTerm
{
protected:
using Codim0 = typename MeshView::template Codim<0>;
using Element = typename Codim0::Entity;
static constexpr int dim = Element::dimension;
using QuadratureRule = Dune::QuadratureRule<double, dim>;
using PointList = std::vector<Dune::QuadraturePoint<double, dim>>;
public:
virtual void init(Element const& element,
PointList const& points) = 0;
virtual double evalZot(size_t iq,
Dune::FieldVector<double,1> const& test,
Dune::FieldVector<double,1> const trial = 1.0) const = 0;
virtual double evalFot1(size_t iq,
Dune::FieldVector<double,1> const& test,
Dune::FieldVector<double,dim> const& grad_trial) const = 0;
virtual double evalFot2(size_t iq,
Dune::FieldVector<double,dim> const& grad_test,
Dune::FieldVector<double,1> const trial = 1.0) const = 0;
virtual double evalSot(size_t iq,
Dune::FieldVector<double,dim> const& grad_test,
Dune::FieldVector<double,dim> const& grad_trial) const = 0;
virtual int getDegree() const = 0;
};
/// Base class for all operators based on expressions
template <class MeshView, class Term, class Traits = _none>
class GenericOperatorTerm
: public OperatorTerm<MeshView>
, public OperatorEvaluation
{
using Super = OperatorTerm<MeshView>;
using Element = typename Super::Element;
using PointList = typename Super::PointList;
static constexpr int dim = Element::dimension;
public:
GenericOperatorTerm(Term const& term)
: term(term)
{}
virtual void init(Element const& element,
PointList const& points) override
{
term.init(element, points);
// cache term evaluation
values.resize(points.size());
for (size_t iq = 0; iq < points.size(); ++iq)
values[iq] = term[iq];
}
virtual double evalZot(size_t iq,
Dune::FieldVector<double,1> const& test,
Dune::FieldVector<double,1> const trial = 1.0) const override
{
return this->evalZotImpl(_cat{}, _traits{}, values[iq], test, trial);
}
virtual double evalFot1(size_t iq,
Dune::FieldVector<double,1> const& test,
Dune::FieldVector<double,dim> const& grad_trial) const override
{
return this->evalFotImpl(_cat{}, _traits{}, values[iq], grad_trial, test);
}
virtual double evalFot2(size_t iq,
Dune::FieldVector<double,dim> const& grad_test,
Dune::FieldVector<double,1> const trial = 1.0) const override
{
return this->evalFotImpl(_cat{}, _traits{}, values[iq], grad_test, trial);
}
virtual double evalSot(size_t iq,
Dune::FieldVector<double,dim> const& grad_test,
Dune::FieldVector<double,dim> const& grad_trial) const override
{
return this->evalSotImpl(_cat{}, _traits{}, values[iq], grad_test, grad_trial);
}
virtual int getDegree() const override
{
return term.getDegree();
}
private:
Term term;
using value_type = std::decay_t< decltype( std::declval<Term>()[std::declval<size_t>()] ) >;
using _cat = ValueCategory_t<value_type>;
using _traits = Traits;
std::vector<value_type> values;
};
// some example terms // some example terms
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -158,7 +48,7 @@ namespace AMDiS ...@@ -158,7 +48,7 @@ namespace AMDiS