Commit 7bd6ff1c authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Merge branch 'issue/cleanup_dofvector' into 'develop'

Issue/cleanup dofvector

See merge request !29
parents 9d6a1e4c 55a910fd
Pipeline #1231 failed with stage
in 4 seconds
......@@ -45,7 +45,7 @@ void ProblemInstat<Traits>::createUhOld()
if (oldSolution)
warning("oldSolution already created\n");
else // create oldSolution
oldSolution.reset(new SystemVector(problemStat.globalBasis(), name + "_uOld"));
oldSolution.reset(new SystemVector(problemStat.globalBasis()));
}
......@@ -53,7 +53,7 @@ template <class Traits>
void ProblemInstat<Traits>::initTimestep(AdaptInfo&)
{
if (oldSolution)
oldSolution->copy(problemStat.getSolutionVector());
*oldSolution = problemStat.getSolutionVector();
}
} // end namespace AMDiS
......@@ -27,7 +27,6 @@
#include <amdis/StandardProblemIteration.hpp>
#include <amdis/common/TupleUtility.hpp>
#include <amdis/common/TypeDefs.hpp>
#include <amdis/common/Utility.hpp>
#include <amdis/GridFunctions.hpp>
......@@ -68,7 +67,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>;
......@@ -275,9 +274,9 @@ namespace AMDiS
void createMatricesAndVectors()
{
systemMatrix_ = std::make_shared<SystemMatrix>(*globalBasis_, *globalBasis_, "mat");
solution_ = std::make_shared<SystemVector>(*globalBasis_, "solution");
rhs_ = std::make_shared<SystemVector>(*globalBasis_, "rhs");
systemMatrix_ = std::make_shared<SystemMatrix>(*globalBasis_, *globalBasis_);
solution_ = std::make_shared<SystemVector>(*globalBasis_);
rhs_ = std::make_shared<SystemVector>(*globalBasis_);
AMDiS::forEachNode_(localView_->tree(), [&,this](auto const& node, auto treePath)
{
......@@ -286,8 +285,6 @@ namespace AMDiS
for (std::size_t j = 0; j < estimates_[i].size(); j++)
estimates_[i][j] = 0.0; // TODO: Remove when estimate() is implemented
});
rhs_ = std::make_shared<SystemVector>(*globalBasis_, "rhs");
}
void createSolver()
......
......@@ -281,7 +281,7 @@ solve(AdaptInfo& adaptInfo, bool createMatrixData, bool storeMatrixData)
solution_->compress();
linearSolver_->solve(systemMatrix_->getMatrix(), solution_->getVector(), rhs_->getVector(),
linearSolver_->solve(systemMatrix_->matrix(), solution_->vector(), rhs_->vector(),
solverInfo);
if (solverInfo.getInfo() > 0) {
......
......@@ -18,8 +18,8 @@ install(FILES
ScalarTypes.hpp
Size.hpp
Tags.hpp
Transposed.hpp
TupleUtility.hpp
TypeDefs.hpp
Utility.hpp
ValueCategory.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/amdis/common)
......@@ -118,7 +118,7 @@ namespace AMDiS
}
template <class T>
constexpr T threshold = T(1.e-18L); //Math::sqr(std::numeric_limits<T>::epsilon());
constexpr T threshold = std::numeric_limits<T>::epsilon();
/// Calculates factorial of i
......
#pragma once
#include <type_traits>
namespace AMDiS
{
/// \brief The transposed view onto a matrix
template <class Matrix>
class TransposedMatrix
{
using RawMatrix = std::decay_t<Matrix>;
public:
using size_type = typename RawMatrix::size_type;
using value_type = typename RawMatrix::value_type;
private:
struct ConstRowProxy
{
RawMatrix const* mat;
size_type row;
value_type const& operator[](size_type col) const
{
return (*mat)[col][row];
}
};
struct MutableRowProxy
{
RawMatrix* mat;
size_type row;
value_type& operator[](size_type col)
{
return (*mat)[col][row];
}
};
public:
template <class M>
TransposedMatrix(M&& matrix)
: matrix_(std::forward<M>(matrix))
{}
ConstRowProxy operator[](size_type row) const
{
return ConstRowProxy{&matrix_, row};
}
template <class M = Matrix,
std::enable_if_t<not std::is_const<M>::value, int> = 0>
MutableRowProxy operator[](size_type row)
{
return MutableRowProxy{&matrix_, row};
}
size_type N() const
{
return matrix_.M();
}
size_type M() const
{
return matrix_.N();
}
private:
Matrix& matrix_;
};
template <class Matrix>
auto transposed(Matrix&& matrix)
{
using M = std::remove_reference_t<Matrix>;
return TransposedMatrix<M>{std::forward<Matrix>(matrix)};
}
} // end namespace AMDiS
#pragma once
#include <type_traits>
#include <amdis/linear_algebra/Mtl.hpp>
namespace AMDiS
{
namespace Impl
{
using ElementVector = mtl::dense_vector<double>;
using ElementMatrix = mtl::dense2D<double>;
using SystemVector = mtl::dense_vector<double>;
using SystemMatrix = mtl::compressed2D<double>;
} // end namespace Impl
struct BoundaryType { int b; };
} // end namespace AMDiS
......@@ -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_ );
......
#install headers
install(FILES
Common.hpp
DOFMatrixBase.hpp
DOFVectorBase.hpp
DOFVectorInterface.hpp
HierarchicWrapper.hpp
LinearAlgebraBase.hpp
LinearSolverInterface.hpp
Mtl.hpp
PreconditionerInterface.hpp
RunnerInterface.hpp
SolverInfo.hpp
......
#pragma once
#include <cstddef>
namespace AMDiS
{
template <class T>
struct Triplet
{
std::size_t row, cols;
T value;
};
} // end namespace AMDiS
#pragma once
#include <cmath>
#include <amdis/common/Math.hpp>
namespace AMDiS
{
template <class RowBasisType, class ColBasisType, class Backend>
class DOFMatrixBase
{
public:
/// The type of the finite element space / basis of the row
using RowBasis = RowBasisType;
/// The type of the finite element space / basis of the column
using ColBasis = ColBasisType;
/// The index/size - type
using size_type = typename RowBasis::size_type;
using BaseMatrix = typename Backend::BaseMatrix;
public:
/// Constructor. Constructs new BaseVector.
DOFMatrixBase(RowBasis const& rowBasis, ColBasis const& colBasis)
: rowBasis_(&rowBasis)
, colBasis_(&colBasis)
{}
/// Return the row-basis \ref rowBasis of the matrix
RowBasis const& rowBasis() const
{
return *rowBasis_;
}
/// Return the col-basis \ref colBasis of the matrix
ColBasis const& colBasis() const
{
return *colBasis_;
}
/// Return the data-matrix
BaseMatrix const& matrix() const
{
return backend_.matrix();
}
/// Return the data-matrix
BaseMatrix& matrix()
{
return backend_.matrix();
}
/// Return the size of the \ref rowBasis_
size_type rows() const
{
return rowBasis_->dimension();
}
/// Return the size of the \ref colBasis_
size_type cols() const
{
return colBasis_->dimension();
}
/// Initialize the matrix for insertion, e.g. allocate the non-zero pattern
/// If \p setToZero is true, the matrix is set to 0
void init(bool setToZero)
{
backend_.init(*rowBasis_, *colBasis_, setToZero);
}
/// Finish the matrix insertion, e.g. cleanup or final insertion
void finish()
{
backend_.finish();
}
/// Insert a block of values into the matrix (add to existing values)
template <class ElementMatrix>
void insert(typename RowBasis::LocalView const& rowLocalView,
typename ColBasis::LocalView const& colLocalView,
ElementMatrix const& elementMatrix)
{
for (size_type i = 0; i < rowLocalView.size(); ++i) {
size_type const row = flatMultiIndex(rowLocalView.index(i));
for (size_type j = 0; j < colLocalView.size(); ++j) {
if (std::abs(elementMatrix[i][j]) > threshold<double>) {
size_type const col = flatMultiIndex(colLocalView.index(j));
backend_.insert(row, col, elementMatrix[i][j]);
}
}
}
}
/// Insert a single value into the matrix (add to existing value)
template <class RowIndex, class ColIndex>
void insert(RowIndex row, ColIndex col, typename Backend::value_type const& value)
{
backend_.insert(flatMultiIndex(row), flatMultiIndex(col), value);
}
/// \brief Deletes all rows with \p dirichletNodes != 0 and if \p apply is true, adds
/// a one on the diagonal of the matrix.
auto applyDirichletBC(std::vector<char> const& dirichletNodes)
{
return backend_.applyDirichletBC(dirichletNodes);
}
size_type nnz() const
{
return backend_.nnz();
}
protected:
RowBasis const* rowBasis_;
ColBasis const* colBasis_;
Backend backend_;
};
} // end namespace AMDiS
#pragma once
#include <cmath>
#include <dune/functions/functionspacebases/sizeinfo.hh>
#include <amdis/common/Math.hpp>
#include <amdis/common/ScalarTypes.hpp>
#include <amdis/linear_algebra/DOFVectorInterface.hpp>
#include <amdis/utility/MultiIndex.hpp>
namespace AMDiS
{
template <class GlobalBasisType>
/// The basic container that stores a base vector and a corresponding basis
template <class BasisType, class Backend>
class DOFVectorBase
: public DOFVectorInterface
{
using Self = DOFVectorBase;
public:
/// The type of the \ref basis
using Basis = BasisType;
/// The index/size - type
using size_type = typename BasisType::size_type;
/// The type of the elements of the DOFVector
using value_type = typename Backend::value_type;
using BaseVector = typename Backend::BaseVector;
public:
using GlobalBasis = GlobalBasisType;
using SizeType = std::size_t;
/// Constructor. Constructs new BaseVector.
DOFVectorBase(BasisType const& basis)
: basis_(&basis)
{
compress();
}
DOFVectorBase(GlobalBasisType const& basis)
: basis_(basis)
{}
/// Return the basis \ref basis_ associated to the vector
Basis const& basis() const
{
return *basis_;
}
SizeType size() const
/// Return the data-vector
BaseVector const& vector() const
{
return basis_.dimension();
return backend_.vector();
}
GlobalBasis const& basis() const
/// Return the data-vector
BaseVector& vector()
{
return GlobalBasis;
return backend_.vector();
}