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
using Dune::Functions::interpolate;
Dune::Hybrid::ifElse(std::is_same<RangeType_t<typename RowBasis::LocalView::Tree>, Range>{},
[&](auto id) {
auto rhsWrapper = wrapper(rhs.getVector());
auto rhsWrapper = wrapper(rhs.vector());
interpolate(id(rowBasis), rhsWrapper, values_, dirichletNodes_);
});
Dune::Hybrid::ifElse(std::is_same<RangeType_t<typename ColBasis::LocalView::Tree>, Range>{},
[&](auto id) {
auto solutionWrapper = wrapper(solution.getVector());
auto solutionWrapper = wrapper(solution.vector());
interpolate(id(colBasis), solutionWrapper, values_, dirichletNodes_);
});
......
......@@ -43,14 +43,13 @@ namespace AMDiS
constexpr std::size_t VTKFieldSize = Size<Range>;
template <class Traits, class TreePath>
template <class GlobalBasis, class RangeType, class TreePath>
class FileWriter
: public FileWriterInterface
{
private: // typedefs and static constants
using GlobalBasis = typename Traits::GlobalBasis;
using GridView = typename GlobalBasis::GridView;
using Vector = DOFVectorConstView<Traits,TreePath>;
using Vector = DOFVectorConstView<GlobalBasis,RangeType,TreePath>;
using Range = typename Vector::Range;
/// Dimension of the mesh
......@@ -123,12 +122,12 @@ namespace AMDiS
};
template <class Traits, class TreePath>
std::shared_ptr<FileWriter<Traits,TreePath>> makeFileWriterPtr(
std::string baseName,
DOFVectorConstView<Traits,TreePath> const& dofvector)
template <class GlobalBasis, class Range, class TreePath>
std::shared_ptr<FileWriter<GlobalBasis,Range,TreePath>>
makeFileWriterPtr(std::string baseName,
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
......@@ -68,7 +68,7 @@ namespace AMDiS
static constexpr int dow = Grid::dimensionworld;
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>;
......
......@@ -281,7 +281,7 @@ solve(AdaptInfo& adaptInfo, bool createMatrixData, bool storeMatrixData)
solution_->compress();
linearSolver_->solve(systemMatrix_->getMatrix(), solution_->getVector(), rhs_->getVector(),
linearSolver_->solve(systemMatrix_->getMatrix(), solution_->vector(), rhs_->vector(),
solverInfo);
if (solverInfo.getInfo() > 0) {
......
......@@ -20,13 +20,12 @@ namespace AMDiS
* @{
**/
template <class Traits, class TreePathType>
template <class GlobalBasisType, class RangeType, class TreePathType>
class DOFVectorConstView
{
public:
using GlobalBasis = typename Traits::GlobalBasis;
using GlobalBasis = GlobalBasisType;
using TreePath = TreePathType;
using Vector = DOFVector<Traits>;
using Tree = typename GlobalBasis::LocalView::Tree;
using SubTree = typename Dune::TypeTree::ChildForTreePath<Tree, TreePath>;
......@@ -37,6 +36,8 @@ namespace AMDiS
using Domain = typename EntitySet::GlobalCoordinate;
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 DerivativeTraits = Dune::Functions::DefaultDerivativeTraits<RawSignature>;
......@@ -201,11 +202,11 @@ namespace AMDiS
public:
/// 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)
, treePath_(treePath)
, entitySet_(dofVector.getFeSpace().gridView())
, nodeToRangeEntry_(Dune::Functions::makeDefaultNodeToRangeMap(dofVector.getFeSpace(), treePath))
, entitySet_(dofVector.basis().gridView())
, nodeToRangeEntry_(Dune::Functions::makeDefaultNodeToRangeMap(dofVector.basis(), treePath))
{}
/// Evaluate the view on this DOFVector in global coordinates
......@@ -230,7 +231,7 @@ namespace AMDiS
/// Return global basis
GlobalBasis const& basis() const
{
return dofVector_->getFeSpace();
return dofVector_->basis();
}
/// Return treePath associated with this view
......@@ -240,13 +241,13 @@ namespace AMDiS
}
/// Return const coefficient vector
DOFVector<Traits> const& coefficients() const
DOFVector<GlobalBasis,RangeType> const& coefficients() const
{
return *dofVector_;
}
protected:
DOFVector<Traits> const* dofVector_;
DOFVector<GlobalBasis,RangeType> const* dofVector_;
TreePath const treePath_;
EntitySet entitySet_;
......@@ -255,18 +256,18 @@ namespace AMDiS
// A mutable version of DOFVectorView
template <class Traits, class TreePathType>
template <class GlobalBasisType, class RangeType, class TreePathType>
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;
public:
/// 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)
, mutableDofVector_(&dofVector)
{}
......@@ -281,11 +282,11 @@ namespace AMDiS
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));
// move data from temporary vector into stored DOFVector
mutableDofVector_->getVector() = std::move(tmp.getVector());
mutableDofVector_->vector() = std::move(tmp.vector());
return *this;
}
......@@ -297,13 +298,13 @@ namespace AMDiS
/// Return the mutable DOFVector
DOFVector<Traits>& coefficients() { return *mutableDofVector_; }
DOFVector<GlobalBasis,RangeType>& coefficients() { return *mutableDofVector_; }
/// Return the const DOFVector
using Super::coefficients;
protected:
DOFVector<Traits>* mutableDofVector_;
DOFVector<GlobalBasis,RangeType>* mutableDofVector_;
};
/** @} **/
......@@ -311,34 +312,34 @@ namespace AMDiS
#ifndef DOXYGEN
// A Generator for a const \ref DOFVectorView.
template <class Traits, class TreePath>
auto makeDOFVectorView(DOFVector<Traits> const& dofVector, TreePath const& treePath)
template <class GlobalBasis, class RangeType, class 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.
template <class Traits, class TreePath>
auto makeDOFVectorView(DOFVector<Traits>& dofVector, TreePath const& treePath)
template <class GlobalBasis, class RangeType, class 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.
template <class Traits>
auto makeDOFVectorView(DOFVector<Traits> const& dofVector)
template <class GlobalBasis, class RangeType>
auto makeDOFVectorView(DOFVector<GlobalBasis, RangeType> const& dofVector)
{
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.
template <class Traits>
auto makeDOFVectorView(DOFVector<Traits>& dofVector)
template <class GlobalBasis, class RangeType>
auto makeDOFVectorView(DOFVector<GlobalBasis, RangeType>& dofVector)
{
auto treePath = Dune::TypeTree::hybridTreePath();
return DOFVectorMutableView<Traits, decltype(treePath)>{dofVector, treePath};
return DOFVectorMutableView<GlobalBasis, RangeType, decltype(treePath)>{dofVector, treePath};
}
#endif
......
......@@ -4,8 +4,8 @@
namespace AMDiS {
template <class Traits, class TreePath>
typename DOFVectorConstView<Traits, TreePath>::Range DOFVectorConstView<Traits, TreePath>::
template <class GB, class RT, class TP>
typename DOFVectorConstView<GB,RT,TP>::Range DOFVectorConstView<GB,RT,TP>::
LocalFunction::operator()(LocalDomain const& x) const
{
assert( bound_ );
......@@ -48,8 +48,8 @@ LocalFunction::operator()(LocalDomain const& x) const
}
template <class Traits, class TreePath>
typename DOFVectorConstView<Traits, TreePath>::DerivativeRange DOFVectorConstView<Traits, TreePath>::
template <class GB, class RT, class TP>
typename DOFVectorConstView<GB,RT,TP>::DerivativeRange DOFVectorConstView<GB,RT,TP>::
GradientLocalFunction::operator()(LocalDomain const& x) const
{
assert( bound_ );
......
......@@ -50,13 +50,13 @@ namespace AMDiS
}
/// Return the data-vector \ref vector
BaseVector const& getVector() const
BaseVector const& vector() const
{
return *vector;
}
/// Return the data-vector \ref vector
BaseVector& getVector()
BaseVector& vector()
{
return *vector;
}
......@@ -107,7 +107,7 @@ namespace AMDiS
/// Calls the copy assignment operator of the BaseVector \ref vector
void copy(Self const& that)
{
*vector = that.getVector();
*vector = that.vector();
}
private:
......
......@@ -91,7 +91,7 @@ namespace AMDiS
explicit BlockVectorWrapper(BlockVector& blockVector,
bool copyBack = !std::is_const<BlockVector>::value)
: blockVector(blockVector)
, vector(num_rows(blockVector))
, vector_(num_rows(blockVector))
, copyBack(copyBack)
{
assignTo();
......@@ -107,8 +107,8 @@ namespace AMDiS
BlockVector const& getBlockVector() const { return blockVector; }
/// Return a reference to the contiguose-vector
Vector& getVector() { return vector; }
Vector const& getVector() const { return vector; }
Vector& vector() { return vector_; }
Vector const& vector() const { return vector_; }
private:
/// copy from block-vector to vector
......@@ -119,7 +119,7 @@ namespace AMDiS
std::size_t finish = start + num_rows(blockVector[r]);
mtl::irange range(start, finish);
vector[range] = blockVector[r];
vector_[range] = blockVector[r];
start = finish;
}
}
......@@ -137,14 +137,14 @@ namespace AMDiS
std::size_t finish = start + num_rows(blockVector[r]);
mtl::irange range(start, finish);
blockVector[r] = vector[range];
blockVector[r] = vector_[range];
start = finish;
}
}
private:
BlockVector& blockVector;
Vector vector;
Vector vector_;
/// Copy data back to block-vector on destruction
bool copyBack;
......@@ -159,16 +159,16 @@ namespace AMDiS
"This specialization is for contiguose vectors only.");
public:
explicit BlockVectorWrapper(BlockVector& vector, bool = false)
: vector(vector)
: vector_(vector)
{}
/// Return a reference to the vector
BlockVector const& getBlockVector() const { return vector; }
BlockVector& getVector() { return vector; }
BlockVector const& getVector() const { return vector; }
BlockVector const& getBlockVector() const { return vector_; }
BlockVector& vector() { return vector_; }
BlockVector const& vector() const { return vector_; }
private:
BlockVector& vector;
BlockVector& vector_;
};
template <class BlockVector, class Vector>
......
......@@ -16,117 +16,114 @@
namespace AMDiS
{
/// The basic container that stores a base vector and a corresponding feSpace
template <class Traits, class ValueType = double>
/// The basic container that stores a base vector and a corresponding basis
template <class GlobalBasis, class RangeType = double>
class DOFVector
{
using Self = DOFVector;
public:
/// The type of the \ref feSpace
using GlobalBasis = typename Traits::GlobalBasis;
/// The type of the \ref basis
using Basis = GlobalBasis;
/// The type of the base vector
using BaseVector = MTLDenseVector<ValueType>;
using BaseVector = MTLDenseVector<RangeType>;
/// The index/size - type
using size_type = typename GlobalBasis::size_type;
/// The type of the elements of the DOFVector
using value_type = ValueType;
/// The underlying field-type (typically the same as \ref value_type)
using field_type = typename BaseVector::value_type;
using range_type = RangeType;
/// Constructor. Constructs new BaseVector.
DOFVector(GlobalBasis const& feSpace, std::string name)
: feSpace(feSpace)
, name(name)
, vector(ClonablePtr<BaseVector>::make())
DOFVector(GlobalBasis const& basis, std::string name)
: basis_(&basis)
, name_(name)
, vector_(ClonablePtr<BaseVector>::make())
{
compress();
}
/// Constructor. Takes reference to existing BaseVector
DOFVector(GlobalBasis const& feSpace, std::string name,
DOFVector(GlobalBasis const& basis, std::string name,
BaseVector& vector_ref)
: feSpace(feSpace)
, name(name)
, vector(vector_ref)
: basis_(&basis)
, name_(name)
, vector_(vector_ref)
{}
/// Return the basis \ref feSpace of the vector
GlobalBasis const& getFeSpace() const
/// Return the basis \ref basis of the vector
Basis const& basis() const
{
return feSpace;
return *basis_;
}
/// Return the data-vector \ref vector
BaseVector const& getVector() const
BaseVector const& vector() const
{
return *vector;
return *vector_;
}
/// Return the data-vector \ref vector
BaseVector& getVector()
BaseVector& vector()
{
return *vector;
return *vector_;
}
/// Return the size of the \ref feSpace
size_type getSize() const
/// Return the size of the \ref basis
size_type size() const
{
return feSpace.dimension();
return basis_->dimension();
}
/// Return the \ref name of this vector
std::string getName() const
std::string name() const
{
return name;
return name_;
}
/// Resize the \ref vector to the size of the \ref feSpace.
/// Resize the \ref vector to the size of the \ref basis.
void compress()
{
if (num_rows(*vector) != getSize()) {
resize(getSize());
*vector = ValueType(0);
if (num_rows(*vector_) != size()) {
resize(size());
*vector_ = range_type(0);
}
}
template <class SizeInfo>
void resize(SizeInfo s)
{
vector->change_dim(size_type(s));
vector_->change_dim(size_type(s));
}
/// Access the entry \p i of the \ref vector with read-access.
template <class Index>
value_type const& operator[](Index idx) const
range_type const& operator[](Index idx) const
{
auto const i = flatMultiIndex(idx);
test_exit_dbg( i < num_rows(*vector) ,
"Index ", i, " out of range [0,", num_rows(*vector), ")" );
return (*vector)[i];
test_exit_dbg( i < num_rows(*vector_) ,
"Index ", i, " out of range [0,", num_rows(*vector_), ")" );
return (*vector_)[i];
}
/// Access the entry \p i of the \ref vector with write-access.
template <class Index>
value_type& operator[](Index idx)
range_type& operator[](Index idx)
{
auto const i = flatMultiIndex(idx);
test_exit_dbg( i < num_rows(*vector) ,
"Index ", i, " out of range [0,", num_rows(*vector), ")" );
return (*vector)[i];
test_exit_dbg( i < num_rows(*vector_) ,
"Index ", i, " out of range [0,", num_rows(*vector_), ")" );
return (*vector_)[i];
}
/// \brief interpolate a function \p f to the basis \ref feSpace and store the
/// \brief interpolate a function \p f to the basis \ref basis and store the
/// coefficients in \ref vector.
template <class F>
void interpol(F&& f)
{
Dune::Functions::interpolate(feSpace, *this, std::forward<F>(f));
Dune::Functions::interpolate(*basis_, *this, std::forward<F>(f));
}
/// Scale each DOFVector by the factor \p s.
......@@ -134,7 +131,7 @@ namespace AMDiS
std::enable_if_t< Concepts::Arithmetic<Scalar>, Self&>
operator*=(Scalar s)
{
(*vector) *= s;
(*vector_) *= s;
return *this;
}
......@@ -143,37 +140,55 @@ namespace AMDiS
std::enable_if_t< Concepts::Arithmetic<Scalar>, Self&>
operator=(Scalar s)
{
(*vector) = s;
(*vector_) = s;
return *this;
}
/// Calls the copy assignment operator of the BaseVector \ref vector
void copy(Self const& that)
{
*vector = that.getVector();
*vector_ = *that.vector_;
}
private:
/// The finite element space / basis associated with the data vector
GlobalBasis const& feSpace;
Basis const* basis_;
/// The name of the DOFVector (used in file-writing)
std::string name;
std::string name_;
/// The data-vector (can hold a new BaseVector or a pointer to external data
ClonablePtr<BaseVector> vector;
ClonablePtr<BaseVector> vector_;
// friend class declarations
template <class, class> friend class SystemVector;
};
#if DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
// Deduction rules
template <class GlobalBasis>
DOFVector(GlobalBasis const& basis, std::string name)
-> DOFVector<GlobalBasis, double>;
template <class GlobalBasis, class RangeType>
DOFVector(GlobalBasis const& basis, std::string name, MTLDenseVector<RangeType>& coefficients)
-> DOFVector<GlobalBasis, RangeType>;
#endif
/// Constructor a dofvector from given feSpace and name
template <class Traits, class ValueType = double>
DOFVector<Traits, ValueType>
makeDOFVector(typename Traits::GlobalBasis const& basis, std::string name)
/// Constructor a dofvector from given basis and name
template <class GlobalBasis, class RangeType = double>
DOFVector<GlobalBasis, RangeType>
makeDOFVector(GlobalBasis const& basis, std::string name)
{
return {basis, name};
}
/// Constructor a dofvector from given basis, name, and coefficient vector
template <class GlobalBasis, class RangeType>
DOFVector<GlobalBasis, RangeType>
makeDOFVector(GlobalBasis const& basis, std::string name, MTLDenseVector<RangeType>& coefficients)
{
return {basis, name, coefficients};
}
} // end namespace AMDiS
......@@ -70,7 +70,7 @@ namespace AMDiS
msg("fill MTL4 matrix needed ", t.elapsed(), " seconds");
}
int error = runner->solve(A, X.getVector(), B.getVector(), solverInfo);
int error = runner->solve(A, X.vector(), B.vector(), solverInfo);
solverInfo.setError(error);
if (!solverInfo.doStoreMatrixData())
......