Commit c4620783 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Changed template parameter of DOFVector to GlobalBasis + Range

parent 9d6a1e4c
...@@ -82,13 +82,13 @@ namespace AMDiS ...@@ -82,13 +82,13 @@ namespace AMDiS
using Dune::Functions::interpolate; using Dune::Functions::interpolate;
Dune::Hybrid::ifElse(std::is_same<RangeType_t<typename RowBasis::LocalView::Tree>, Range>{}, Dune::Hybrid::ifElse(std::is_same<RangeType_t<typename RowBasis::LocalView::Tree>, Range>{},
[&](auto id) { [&](auto id) {
auto rhsWrapper = wrapper(rhs.getVector()); auto rhsWrapper = wrapper(rhs.vector());
interpolate(id(rowBasis), rhsWrapper, values_, dirichletNodes_); interpolate(id(rowBasis), rhsWrapper, values_, dirichletNodes_);
}); });
Dune::Hybrid::ifElse(std::is_same<RangeType_t<typename ColBasis::LocalView::Tree>, Range>{}, Dune::Hybrid::ifElse(std::is_same<RangeType_t<typename ColBasis::LocalView::Tree>, Range>{},
[&](auto id) { [&](auto id) {
auto solutionWrapper = wrapper(solution.getVector()); auto solutionWrapper = wrapper(solution.vector());
interpolate(id(colBasis), solutionWrapper, values_, dirichletNodes_); interpolate(id(colBasis), solutionWrapper, values_, dirichletNodes_);
}); });
......
...@@ -43,14 +43,13 @@ namespace AMDiS ...@@ -43,14 +43,13 @@ namespace AMDiS
constexpr std::size_t VTKFieldSize = Size<Range>; constexpr std::size_t VTKFieldSize = Size<Range>;
template <class Traits, class TreePath> template <class GlobalBasis, class RangeType, class TreePath>
class FileWriter class FileWriter
: public FileWriterInterface : public FileWriterInterface
{ {
private: // typedefs and static constants private: // typedefs and static constants
using GlobalBasis = typename Traits::GlobalBasis;
using GridView = typename GlobalBasis::GridView; using GridView = typename GlobalBasis::GridView;
using Vector = DOFVectorConstView<Traits,TreePath>; using Vector = DOFVectorConstView<GlobalBasis,RangeType,TreePath>;
using Range = typename Vector::Range; using Range = typename Vector::Range;
/// Dimension of the mesh /// Dimension of the mesh
...@@ -123,12 +122,12 @@ namespace AMDiS ...@@ -123,12 +122,12 @@ namespace AMDiS
}; };
template <class Traits, class TreePath> template <class GlobalBasis, class Range, class TreePath>
std::shared_ptr<FileWriter<Traits,TreePath>> makeFileWriterPtr( std::shared_ptr<FileWriter<GlobalBasis,Range,TreePath>>
std::string baseName, makeFileWriterPtr(std::string baseName,
DOFVectorConstView<Traits,TreePath> const& dofvector) DOFVectorConstView<GlobalBasis,Range,TreePath> const& dofvector)
{ {
return std::make_shared<FileWriter<Traits,TreePath>>(baseName, dofvector); return std::make_shared<FileWriter<GlobalBasis,Range,TreePath>>(baseName, dofvector);
} }
} // end namespace AMDiS } // end namespace AMDiS
...@@ -68,7 +68,7 @@ namespace AMDiS ...@@ -68,7 +68,7 @@ namespace AMDiS
static constexpr int dow = Grid::dimensionworld; static constexpr int dow = Grid::dimensionworld;
using SystemMatrix = DOFMatrix<GlobalBasis, GlobalBasis, double>; using SystemMatrix = DOFMatrix<GlobalBasis, GlobalBasis, double>;
using SystemVector = DOFVector<Traits, double>; using SystemVector = DOFVector<GlobalBasis, double>;
using LinearSolverType = LinearSolverInterface<typename SystemMatrix::BaseMatrix, typename SystemVector::BaseVector>; using LinearSolverType = LinearSolverInterface<typename SystemMatrix::BaseMatrix, typename SystemVector::BaseVector>;
......
...@@ -281,7 +281,7 @@ solve(AdaptInfo& adaptInfo, bool createMatrixData, bool storeMatrixData) ...@@ -281,7 +281,7 @@ solve(AdaptInfo& adaptInfo, bool createMatrixData, bool storeMatrixData)
solution_->compress(); solution_->compress();
linearSolver_->solve(systemMatrix_->getMatrix(), solution_->getVector(), rhs_->getVector(), linearSolver_->solve(systemMatrix_->getMatrix(), solution_->vector(), rhs_->vector(),
solverInfo); solverInfo);
if (solverInfo.getInfo() > 0) { if (solverInfo.getInfo() > 0) {
......
...@@ -20,13 +20,12 @@ namespace AMDiS ...@@ -20,13 +20,12 @@ namespace AMDiS
* @{ * @{
**/ **/
template <class Traits, class TreePathType> template <class GlobalBasisType, class RangeType, class TreePathType>
class DOFVectorConstView class DOFVectorConstView
{ {
public: public:
using GlobalBasis = typename Traits::GlobalBasis; using GlobalBasis = GlobalBasisType;
using TreePath = TreePathType; using TreePath = TreePathType;
using Vector = DOFVector<Traits>;
using Tree = typename GlobalBasis::LocalView::Tree; using Tree = typename GlobalBasis::LocalView::Tree;
using SubTree = typename Dune::TypeTree::ChildForTreePath<Tree, TreePath>; using SubTree = typename Dune::TypeTree::ChildForTreePath<Tree, TreePath>;
...@@ -37,6 +36,8 @@ namespace AMDiS ...@@ -37,6 +36,8 @@ namespace AMDiS
using Domain = typename EntitySet::GlobalCoordinate; using Domain = typename EntitySet::GlobalCoordinate;
using Range = RangeType_t<SubTree>; using Range = RangeType_t<SubTree>;
static_assert(std::is_arithmetic<RangeType>::value, "");
// Don't know how to determine Range with non-trivial RangeType
using RawSignature = typename Dune::Functions::SignatureTraits<Range(Domain)>::RawSignature; using RawSignature = typename Dune::Functions::SignatureTraits<Range(Domain)>::RawSignature;
using DerivativeTraits = Dune::Functions::DefaultDerivativeTraits<RawSignature>; using DerivativeTraits = Dune::Functions::DefaultDerivativeTraits<RawSignature>;
...@@ -201,11 +202,11 @@ namespace AMDiS ...@@ -201,11 +202,11 @@ namespace AMDiS
public: public:
/// Constructor. Stores a pointer to the dofVector and a copy of the treePath. /// Constructor. Stores a pointer to the dofVector and a copy of the treePath.
DOFVectorConstView(DOFVector<Traits> const& dofVector, TreePath const& treePath) DOFVectorConstView(DOFVector<GlobalBasis,RangeType> const& dofVector, TreePath const& treePath)
: dofVector_(&dofVector) : dofVector_(&dofVector)
, treePath_(treePath) , treePath_(treePath)
, entitySet_(dofVector.getFeSpace().gridView()) , entitySet_(dofVector.basis().gridView())
, nodeToRangeEntry_(Dune::Functions::makeDefaultNodeToRangeMap(dofVector.getFeSpace(), treePath)) , nodeToRangeEntry_(Dune::Functions::makeDefaultNodeToRangeMap(dofVector.basis(), treePath))
{} {}
/// Evaluate the view on this DOFVector in global coordinates /// Evaluate the view on this DOFVector in global coordinates
...@@ -230,7 +231,7 @@ namespace AMDiS ...@@ -230,7 +231,7 @@ namespace AMDiS
/// Return global basis /// Return global basis
GlobalBasis const& basis() const GlobalBasis const& basis() const
{ {
return dofVector_->getFeSpace(); return dofVector_->basis();
} }
/// Return treePath associated with this view /// Return treePath associated with this view
...@@ -240,13 +241,13 @@ namespace AMDiS ...@@ -240,13 +241,13 @@ namespace AMDiS
} }
/// Return const coefficient vector /// Return const coefficient vector
DOFVector<Traits> const& coefficients() const DOFVector<GlobalBasis,RangeType> const& coefficients() const
{ {
return *dofVector_; return *dofVector_;
} }
protected: protected:
DOFVector<Traits> const* dofVector_; DOFVector<GlobalBasis,RangeType> const* dofVector_;
TreePath const treePath_; TreePath const treePath_;
EntitySet entitySet_; EntitySet entitySet_;
...@@ -255,18 +256,18 @@ namespace AMDiS ...@@ -255,18 +256,18 @@ namespace AMDiS
// A mutable version of DOFVectorView // A mutable version of DOFVectorView
template <class Traits, class TreePathType> template <class GlobalBasisType, class RangeType, class TreePathType>
class DOFVectorMutableView class DOFVectorMutableView
: public DOFVectorConstView<Traits, TreePathType> : public DOFVectorConstView<GlobalBasisType, RangeType, TreePathType>
{ {
using Super = DOFVectorConstView<Traits, TreePathType>; using Super = DOFVectorConstView<GlobalBasisType, RangeType, TreePathType>;
using GlobalBasis = typename Traits::GlobalBasis; using GlobalBasis = GlobalBasisType;
using TreePath = TreePathType; using TreePath = TreePathType;
public: public:
/// Constructor. Stores a pointer to the mutable `dofvector`. /// Constructor. Stores a pointer to the mutable `dofvector`.
DOFVectorMutableView(DOFVector<Traits>& dofVector, TreePath const& treePath) DOFVectorMutableView(DOFVector<GlobalBasis,RangeType>& dofVector, TreePath const& treePath)
: Super(dofVector, treePath) : Super(dofVector, treePath)
, mutableDofVector_(&dofVector) , mutableDofVector_(&dofVector)
{} {}
...@@ -281,11 +282,11 @@ namespace AMDiS ...@@ -281,11 +282,11 @@ namespace AMDiS
auto&& gridFct = makeGridFunction(std::forward<Expr>(expr), basis.gridView()); auto&& gridFct = makeGridFunction(std::forward<Expr>(expr), basis.gridView());
DOFVector<Traits> tmp(basis, "tmp"); DOFVector<GlobalBasis,RangeType> tmp(*mutableDofVector_);
Dune::Functions::interpolate(basis, treePath, tmp, std::forward<decltype(gridFct)>(gridFct)); Dune::Functions::interpolate(basis, treePath, tmp, std::forward<decltype(gridFct)>(gridFct));
// move data from temporary vector into stored DOFVector // move data from temporary vector into stored DOFVector
mutableDofVector_->getVector() = std::move(tmp.getVector()); mutableDofVector_->vector() = std::move(tmp.vector());
return *this; return *this;
} }
...@@ -297,13 +298,13 @@ namespace AMDiS ...@@ -297,13 +298,13 @@ namespace AMDiS
/// Return the mutable DOFVector /// Return the mutable DOFVector
DOFVector<Traits>& coefficients() { return *mutableDofVector_; } DOFVector<GlobalBasis,RangeType>& coefficients() { return *mutableDofVector_; }
/// Return the const DOFVector /// Return the const DOFVector
using Super::coefficients; using Super::coefficients;
protected: protected:
DOFVector<Traits>* mutableDofVector_; DOFVector<GlobalBasis,RangeType>* mutableDofVector_;
}; };
/** @} **/ /** @} **/
...@@ -311,34 +312,34 @@ namespace AMDiS ...@@ -311,34 +312,34 @@ namespace AMDiS
#ifndef DOXYGEN #ifndef DOXYGEN
// A Generator for a const \ref DOFVectorView. // A Generator for a const \ref DOFVectorView.
template <class Traits, class TreePath> template <class GlobalBasis, class RangeType, class TreePath>
auto makeDOFVectorView(DOFVector<Traits> const& dofVector, TreePath const& treePath) auto makeDOFVectorView(DOFVector<GlobalBasis, RangeType> const& dofVector, TreePath const& treePath)
{ {
return DOFVectorConstView<Traits, TreePath>{dofVector, treePath}; return DOFVectorConstView<GlobalBasis, RangeType, TreePath>{dofVector, treePath};
} }
// A Generator for a mutable \ref DOFVectorView. // A Generator for a mutable \ref DOFVectorView.
template <class Traits, class TreePath> template <class GlobalBasis, class RangeType, class TreePath>
auto makeDOFVectorView(DOFVector<Traits>& dofVector, TreePath const& treePath) auto makeDOFVectorView(DOFVector<GlobalBasis, RangeType>& dofVector, TreePath const& treePath)
{ {
return DOFVectorMutableView<Traits, TreePath>{dofVector, treePath}; return DOFVectorMutableView<GlobalBasis, RangeType, TreePath>{dofVector, treePath};
} }
// A Generator for a const \ref DOFVectorView. // A Generator for a const \ref DOFVectorView.
template <class Traits> template <class GlobalBasis, class RangeType>
auto makeDOFVectorView(DOFVector<Traits> const& dofVector) auto makeDOFVectorView(DOFVector<GlobalBasis, RangeType> const& dofVector)
{ {
auto treePath = Dune::TypeTree::hybridTreePath(); auto treePath = Dune::TypeTree::hybridTreePath();
return DOFVectorConstView<Traits, decltype(treePath)>{dofVector, treePath}; return DOFVectorConstView<GlobalBasis, RangeType, decltype(treePath)>{dofVector, treePath};
} }
// A Generator for a mutable \ref DOFVectorView. // A Generator for a mutable \ref DOFVectorView.
template <class Traits> template <class GlobalBasis, class RangeType>
auto makeDOFVectorView(DOFVector<Traits>& dofVector) auto makeDOFVectorView(DOFVector<GlobalBasis, RangeType>& dofVector)
{ {
auto treePath = Dune::TypeTree::hybridTreePath(); auto treePath = Dune::TypeTree::hybridTreePath();
return DOFVectorMutableView<Traits, decltype(treePath)>{dofVector, treePath}; return DOFVectorMutableView<GlobalBasis, RangeType, decltype(treePath)>{dofVector, treePath};
} }
#endif #endif
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
namespace AMDiS { namespace AMDiS {
template <class Traits, class TreePath> template <class GB, class RT, class TP>
typename DOFVectorConstView<Traits, TreePath>::Range DOFVectorConstView<Traits, TreePath>:: typename DOFVectorConstView<GB,RT,TP>::Range DOFVectorConstView<GB,RT,TP>::
LocalFunction::operator()(LocalDomain const& x) const LocalFunction::operator()(LocalDomain const& x) const
{ {
assert( bound_ ); assert( bound_ );
...@@ -48,8 +48,8 @@ LocalFunction::operator()(LocalDomain const& x) const ...@@ -48,8 +48,8 @@ LocalFunction::operator()(LocalDomain const& x) const
} }
template <class Traits, class TreePath> template <class GB, class RT, class TP>
typename DOFVectorConstView<Traits, TreePath>::DerivativeRange DOFVectorConstView<Traits, TreePath>:: typename DOFVectorConstView<GB,RT,TP>::DerivativeRange DOFVectorConstView<GB,RT,TP>::
GradientLocalFunction::operator()(LocalDomain const& x) const GradientLocalFunction::operator()(LocalDomain const& x) const
{ {
assert( bound_ ); assert( bound_ );
......
...@@ -50,13 +50,13 @@ namespace AMDiS ...@@ -50,13 +50,13 @@ namespace AMDiS
} }
/// Return the data-vector \ref vector /// Return the data-vector \ref vector
BaseVector const& getVector() const BaseVector const& vector() const
{ {
return *vector; return *vector;
} }
/// Return the data-vector \ref vector /// Return the data-vector \ref vector
BaseVector& getVector() BaseVector& vector()
{ {
return *vector; return *vector;
} }
...@@ -107,7 +107,7 @@ namespace AMDiS ...@@ -107,7 +107,7 @@ namespace AMDiS
/// Calls the copy assignment operator of the BaseVector \ref vector /// Calls the copy assignment operator of the BaseVector \ref vector
void copy(Self const& that) void copy(Self const& that)
{ {
*vector = that.getVector(); *vector = that.vector();
} }
private: private:
......
...@@ -91,7 +91,7 @@ namespace AMDiS ...@@ -91,7 +91,7 @@ namespace AMDiS
explicit BlockVectorWrapper(BlockVector& blockVector, explicit BlockVectorWrapper(BlockVector& blockVector,
bool copyBack = !std::is_const<BlockVector>::value) bool copyBack = !std::is_const<BlockVector>::value)
: blockVector(blockVector) : blockVector(blockVector)
, vector(num_rows(blockVector)) , vector_(num_rows(blockVector))
, copyBack(copyBack) , copyBack(copyBack)
{ {
assignTo(); assignTo();
...@@ -107,8 +107,8 @@ namespace AMDiS ...@@ -107,8 +107,8 @@ namespace AMDiS
BlockVector const& getBlockVector() const { return blockVector; } BlockVector const& getBlockVector() const { return blockVector; }
/// Return a reference to the contiguose-vector /// Return a reference to the contiguose-vector
Vector& getVector() { return vector; } Vector& vector() { return vector_; }
Vector const& getVector() const { return vector; } Vector const& vector() const { return vector_; }
private: private:
/// copy from block-vector to vector /// copy from block-vector to vector
...@@ -119,7 +119,7 @@ namespace AMDiS ...@@ -119,7 +119,7 @@ namespace AMDiS
std::size_t finish = start + num_rows(blockVector[r]); std::size_t finish = start + num_rows(blockVector[r]);
mtl::irange range(start, finish); mtl::irange range(start, finish);
vector[range] = blockVector[r]; vector_[range] = blockVector[r];
start = finish; start = finish;
} }
} }
...@@ -137,14 +137,14 @@ namespace AMDiS ...@@ -137,14 +137,14 @@ namespace AMDiS
std::size_t finish = start + num_rows(blockVector[r]); std::size_t finish = start + num_rows(blockVector[r]);
mtl::irange range(start, finish); mtl::irange range(start, finish);
blockVector[r] = vector[range]; blockVector[r] = vector_[range];
start = finish; start = finish;
} }
} }
private: private:
BlockVector& blockVector; BlockVector& blockVector;
Vector vector; Vector vector_;
/// Copy data back to block-vector on destruction /// Copy data back to block-vector on destruction
bool copyBack; bool copyBack;
...@@ -159,16 +159,16 @@ namespace AMDiS ...@@ -159,16 +159,16 @@ namespace AMDiS
"This specialization is for contiguose vectors only."); "This specialization is for contiguose vectors only.");
public: public:
explicit BlockVectorWrapper(BlockVector& vector, bool = false) explicit BlockVectorWrapper(BlockVector& vector, bool = false)
: vector(vector) : vector_(vector)
{} {}
/// Return a reference to the vector /// Return a reference to the vector
BlockVector const& getBlockVector() const { return vector; } BlockVector const& getBlockVector() const { return vector_; }
BlockVector& getVector() { return vector; } BlockVector& vector() { return vector_; }
BlockVector const& getVector() const { return vector; } BlockVector const& vector() const { return vector_; }
private: private:
BlockVector& vector; BlockVector& vector_;
}; };
template <class BlockVector, class Vector> template <class BlockVector, class Vector>
......
...@@ -16,117 +16,114 @@ ...@@ -16,117 +16,114 @@
namespace AMDiS namespace AMDiS
{ {
/// The basic container that stores a base vector and a corresponding feSpace /// The basic container that stores a base vector and a corresponding basis
template <class Traits, class ValueType = double> template <class GlobalBasis, class RangeType = double>
class DOFVector class DOFVector
{ {
using Self = DOFVector; using Self = DOFVector;
public: public:
/// The type of the \ref feSpace /// The type of the \ref basis
using GlobalBasis = typename Traits::GlobalBasis; using Basis = GlobalBasis;
/// The type of the base vector /// The type of the base vector
using BaseVector = MTLDenseVector<ValueType>; using BaseVector = MTLDenseVector<RangeType>;
/// The index/size - type /// The index/size - type
using size_type = typename GlobalBasis::size_type; using size_type = typename GlobalBasis::size_type;
/// The type of the elements of the DOFVector /// The type of the elements of the DOFVector
using value_type = ValueType; using range_type = RangeType;
/// The underlying field-type (typically the same as \ref value_type)
using field_type = typename BaseVector::value_type;
/// Constructor. Constructs new BaseVector. /// Constructor. Constructs new BaseVector.
DOFVector(GlobalBasis const& feSpace, std::string name) DOFVector(GlobalBasis const& basis, std::string name)
: feSpace(feSpace) : basis_(&basis)
, name(name) , name_(name)
, vector(ClonablePtr<BaseVector>::make()) , vector_(ClonablePtr<BaseVector>::make())
{ {
compress(); compress();
} }
/// Constructor. Takes reference to existing BaseVector /// Constructor. Takes reference to existing BaseVector
DOFVector(GlobalBasis const& feSpace, std::string name, DOFVector(GlobalBasis const& basis, std::string name,
BaseVector& vector_ref) BaseVector& vector_ref)
: feSpace(feSpace) : basis_(&basis)
, name(name) , name_(name)
, vector(vector_ref) , vector_(vector_ref)
{} {}
/// Return the basis \ref feSpace of the vector /// Return the basis \ref basis of the vector
GlobalBasis const& getFeSpace() const Basis const& basis() const
{ {
return feSpace; return *basis_;
} }