Commit 9e2dadcb authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

cleanup of DOFMatrix and removed name member

parent c4620783
...@@ -78,8 +78,8 @@ int main(int argc, char** argv) ...@@ -78,8 +78,8 @@ int main(int argc, char** argv)
// write matrix to file // write matrix to file
mtl::io::matrix_market_ostream out("matrix_stokes0.mtx"); mtl::io::matrix_market_ostream out("matrix_stokes0.mtx");
out << prob.getSystemMatrix().getMatrix(); out << prob.getSystemMatrix().matrix();
std::cout << prob.getSystemMatrix().getMatrix() << '\n'; std::cout << prob.getSystemMatrix().matrix() << '\n';
prob.solve(adaptInfo); prob.solve(adaptInfo);
......
...@@ -79,8 +79,8 @@ int main(int argc, char** argv) ...@@ -79,8 +79,8 @@ int main(int argc, char** argv)
// write matrix to file // write matrix to file
mtl::io::matrix_market_ostream out("matrix_stokes1.mtx"); mtl::io::matrix_market_ostream out("matrix_stokes1.mtx");
out << prob.getSystemMatrix().getMatrix(); out << prob.getSystemMatrix().matrix();
std::cout << prob.getSystemMatrix().getMatrix() << '\n'; std::cout << prob.getSystemMatrix().matrix() << '\n';
prob.solve(adaptInfo); prob.solve(adaptInfo);
......
...@@ -41,9 +41,9 @@ int main(int argc, char** argv) ...@@ -41,9 +41,9 @@ int main(int argc, char** argv)
// write matrix to file // write matrix to file
if (Parameters::get<int>("elliptMesh->global refinements").value_or(0) < 4) { if (Parameters::get<int>("elliptMesh->global refinements").value_or(0) < 4) {
mtl::io::matrix_market_ostream out("matrix.mtx"); mtl::io::matrix_market_ostream out("matrix.mtx");
out << prob.getSystemMatrix().getMatrix(); out << prob.getSystemMatrix().matrix();
std::cout << prob.getSystemMatrix().getMatrix() << '\n'; std::cout << prob.getSystemMatrix().matrix() << '\n';
} }
prob.solve(adaptInfo); prob.solve(adaptInfo);
......
...@@ -203,7 +203,7 @@ std::size_t Assembler<Traits>::finishMatrixVector( ...@@ -203,7 +203,7 @@ std::size_t Assembler<Traits>::finishMatrixVector(
}); });
}); });
return matrix.getNnz(); return matrix.nnz();
} }
} // end namespace AMDiS } // end namespace AMDiS
...@@ -45,7 +45,7 @@ void ProblemInstat<Traits>::createUhOld() ...@@ -45,7 +45,7 @@ void ProblemInstat<Traits>::createUhOld()
if (oldSolution) if (oldSolution)
warning("oldSolution already created\n"); warning("oldSolution already created\n");
else // create oldSolution else // create oldSolution
oldSolution.reset(new SystemVector(problemStat.globalBasis(), name + "_uOld")); oldSolution.reset(new SystemVector(problemStat.globalBasis()));
} }
......
...@@ -275,9 +275,9 @@ namespace AMDiS ...@@ -275,9 +275,9 @@ namespace AMDiS
void createMatricesAndVectors() void createMatricesAndVectors()
{ {
systemMatrix_ = std::make_shared<SystemMatrix>(*globalBasis_, *globalBasis_, "mat"); systemMatrix_ = std::make_shared<SystemMatrix>(*globalBasis_, *globalBasis_);
solution_ = std::make_shared<SystemVector>(*globalBasis_, "solution"); solution_ = std::make_shared<SystemVector>(*globalBasis_);
rhs_ = std::make_shared<SystemVector>(*globalBasis_, "rhs"); rhs_ = std::make_shared<SystemVector>(*globalBasis_);
AMDiS::forEachNode_(localView_->tree(), [&,this](auto const& node, auto treePath) AMDiS::forEachNode_(localView_->tree(), [&,this](auto const& node, auto treePath)
{ {
...@@ -286,8 +286,6 @@ namespace AMDiS ...@@ -286,8 +286,6 @@ namespace AMDiS
for (std::size_t j = 0; j < estimates_[i].size(); j++) for (std::size_t j = 0; j < estimates_[i].size(); j++)
estimates_[i][j] = 0.0; // TODO: Remove when estimate() is implemented estimates_[i][j] = 0.0; // TODO: Remove when estimate() is implemented
}); });
rhs_ = std::make_shared<SystemVector>(*globalBasis_, "rhs");
} }
void createSolver() void createSolver()
......
...@@ -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_->vector(), rhs_->vector(), linearSolver_->solve(systemMatrix_->matrix(), solution_->vector(), rhs_->vector(),
solverInfo); solverInfo);
if (solverInfo.getInfo() > 0) { if (solverInfo.getInfo() > 0) {
......
...@@ -2,29 +2,14 @@ ...@@ -2,29 +2,14 @@
namespace AMDiS namespace AMDiS
{ {
template <class GlobalBasisType>
class DOFVectorBase class DOFVectorBase
{ {
public: public:
using GlobalBasis = GlobalBasisType; /// Virtual destructor
using SizeType = std::size_t; ~DOFVectorBase() = default;
DOFVectorBase(GlobalBasisType const& basis) /// Change dimension of DOFVector to dimension of basis
: basis_(basis) virtual void compress() = 0;
{}
SizeType size() const
{
return basis_.dimension();
}
GlobalBasis const& basis() const
{
return GlobalBasis;
}
private:
GlobalBasis const& basis_;
}; };
} // end namespace AMDiS } // end namespace AMDiS
...@@ -136,7 +136,7 @@ namespace AMDiS ...@@ -136,7 +136,7 @@ namespace AMDiS
initialized = false; initialized = false;
} }
std::size_t getNnz() std::size_t nnz()
{ {
return matrix->nonzeroes(); return matrix->nonzeroes();
} }
......
...@@ -22,17 +22,17 @@ namespace AMDiS ...@@ -22,17 +22,17 @@ namespace AMDiS
{ {
/// \brief The basic container that stores a base matrix and a corresponding /// \brief The basic container that stores a base matrix and a corresponding
/// row/column feSpace. /// row/column feSpace.
template <class RowFeSpaceType, template <class RowBasisType,
class ColFeSpaceType, class ColBasisType,
class ValueType = double> class ValueType = double>
class DOFMatrix class DOFMatrix
{ {
public: public:
/// The type of the finite element space / basis of the row /// The type of the finite element space / basis of the row
using RowFeSpace = RowFeSpaceType; using RowBasis = RowBasisType;
/// The type of the finite element space / basis of the column /// The type of the finite element space / basis of the column
using ColFeSpace = ColFeSpaceType; using ColBasis = ColBasisType;
/// The matrix type of the underlying base matrix /// The matrix type of the underlying base matrix
using BaseMatrix = mtl::compressed2D<ValueType>; using BaseMatrix = mtl::compressed2D<ValueType>;
...@@ -51,68 +51,58 @@ namespace AMDiS ...@@ -51,68 +51,58 @@ namespace AMDiS
public: public:
/// Constructor. Constructs new BaseMatrix. /// Constructor. Constructs new BaseMatrix.
DOFMatrix(RowFeSpace const& rowFeSpace, DOFMatrix(RowBasis const& rowBasis,
ColFeSpace const& colFeSpace, ColBasis const& colBasis)
std::string name) : rowBasis_(&rowBasis)
: rowFeSpace(rowFeSpace) , colBasis_(&colBasis)
, colFeSpace(colFeSpace) , matrix_(ClonablePtr<BaseMatrix>::make())
, name(name)
, matrix(ClonablePtr<BaseMatrix>::make())
{} {}
/// Constructor. Takes pointer of data-matrix. /// Constructor. Takes pointer of data-matrix.
DOFMatrix(RowFeSpace const& rowFeSpace, DOFMatrix(RowBasis const& rowBasis,
ColFeSpace const& colFeSpace, ColBasis const& colBasis,
std::string name,
BaseMatrix& matrix_ref) BaseMatrix& matrix_ref)
: rowFeSpace(rowFeSpace) : rowBasis_(&rowBasis)
, colFeSpace(colFeSpace) , colBasis_(&colBasis)
, name(name) , matrix_(matrix_ref)
, matrix(matrix_ref)
{} {}
/// Return the row-basis \ref rowFeSpace of the matrix /// Return the row-basis \ref rowBasis_ of the matrix
RowFeSpace const& getRowFeSpace() const RowBasis const& rowBasis() const
{ {
return rowFeSpace; return *rowBasis_;
} }
/// Return the col-basis \ref colFeSpace of the matrix /// Return the col-basis \ref colBasis_ of the matrix
ColFeSpace const& getColFeSpace() const ColBasis const& colBasis() const
{ {
return colFeSpace; return *colBasis_;
} }
/// Return a reference to the data-matrix \ref matrix /// Return a reference to the data-matrix \ref matrix
BaseMatrix& getMatrix() BaseMatrix& matrix()
{ {
assert( !insertionMode ); assert( !insertionMode_ );
return *matrix; return *matrix_;
} }
/// Return a reference to the data-matrix \ref matrix /// Return a reference to the data-matrix \ref matrix
BaseMatrix const& getMatrix() const BaseMatrix const& matrix() const
{ {
assert( !insertionMode ); assert( !insertionMode_ );
return *matrix; return *matrix_;
} }
/// Return the size of the row \ref feSpace /// Return the size of the row \ref feSpace
size_type N() const size_type N() const
{ {
return rowFeSpace.size(); return rowBasis_->size();
} }
/// Return the size of the column \ref feSpace /// Return the size of the column \ref feSpace
size_type M() const size_type M() const
{ {
return colFeSpace.size(); return colBasis_->size();
}
/// Return the \ref name of this matrix
std::string getName() const
{
return name;
} }
...@@ -125,34 +115,34 @@ namespace AMDiS ...@@ -125,34 +115,34 @@ namespace AMDiS
auto operator()(FlatIndex row, FlatIndex col) auto operator()(FlatIndex row, FlatIndex col)
{ {
size_type r = row[0], c = col[0]; size_type r = row[0], c = col[0];
test_exit_dbg( insertionMode, "Inserter not initilized!"); test_exit_dbg( insertionMode_, "Inserter not initilized!");
test_exit_dbg( r < N() && c < M() , test_exit_dbg( r < N() && c < M() ,
"Indices out of range [0,", N(), ")x[0,", M(), ")" ); "Indices out of range [0,", N(), ")x[0,", M(), ")" );
return (*inserter)[r][c]; return (*inserter_)[r][c];
} }
auto operator()(BlockIndex row, BlockIndex col) auto operator()(BlockIndex row, BlockIndex col)
{ {
size_type r = row[0], c = col[0]; size_type r = row[0], c = col[0];
test_exit_dbg( insertionMode, "Inserter not initilized!"); test_exit_dbg( insertionMode_, "Inserter not initilized!");
test_exit_dbg( r < N() && c < M() , test_exit_dbg( r < N() && c < M() ,
"Indices out of range [0,", N(), ")x[0,", M(), ")" ); "Indices out of range [0,", N(), ")x[0,", M(), ")" );
return (*inserter)[r][c]; return (*inserter_)[r][c];
} }
/// Create inserter. Assumes that no inserter is currently active on this matrix. /// Create inserter. Assumes that no inserter is currently active on this matrix.
void init(bool prepareForInsertion) void init(bool prepareForInsertion)
{ {
test_exit(!insertionMode && !inserter, "Matrix already in insertion mode!"); test_exit(!insertionMode_ && !inserter_, "Matrix already in insertion mode!");
calculateSlotSize(); calculateSlotSize();
matrix->change_dim(rowFeSpace.dimension(), colFeSpace.dimension()); matrix_->change_dim(rowBasis_->dimension(), colBasis_->dimension());
test_exit(num_rows(*matrix) == rowFeSpace.dimension() && num_cols(*matrix) == colFeSpace.dimension(), test_exit(num_rows(*matrix_) == rowBasis_->dimension() && num_cols(*matrix_) == colBasis_->dimension(),
"Wrong dimensions in matrix"); "Wrong dimensions in matrix");
if (prepareForInsertion) { if (prepareForInsertion) {
set_to_zero(*matrix); set_to_zero(*matrix_);
inserter = new Inserter(*matrix, slot_size); inserter_ = new Inserter(*matrix_, slotSize_);
insertionMode = true; insertionMode_ = true;
} }
} }
...@@ -160,15 +150,15 @@ namespace AMDiS ...@@ -160,15 +150,15 @@ namespace AMDiS
/// final construction of the matrix. /// final construction of the matrix.
void finish() void finish()
{ {
delete inserter; delete inserter_;
inserter = NULL; inserter_ = NULL;
insertionMode = false; insertionMode_ = false;
} }
/// Return the number of nonzeros in the matrix /// Return the number of nonzeros in the matrix
std::size_t getNnz() const std::size_t nnz() const
{ {
return matrix->nnz(); return matrix_->nnz();
} }
/// \brief Deletes all rows with \p dirichletNodes != 0 and if \p apply is true, adds /// \brief Deletes all rows with \p dirichletNodes != 0 and if \p apply is true, adds
...@@ -178,9 +168,9 @@ namespace AMDiS ...@@ -178,9 +168,9 @@ namespace AMDiS
std::list<Triplet<value_type>> columns; std::list<Triplet<value_type>> columns;
// Define the property maps // Define the property maps
auto row = mtl::mat::row_map(*matrix); auto row = mtl::mat::row_map(*matrix_);
auto col = mtl::mat::col_map(*matrix); auto col = mtl::mat::col_map(*matrix_);
auto value = mtl::mat::value_map(*matrix); auto value = mtl::mat::value_map(*matrix_);
// iterate over the matrix // iterate over the matrix
#if 0 #if 0
...@@ -198,7 +188,7 @@ namespace AMDiS ...@@ -198,7 +188,7 @@ namespace AMDiS
} }
#endif #endif
for (auto r : mtl::rows_of(*matrix)) { // rows or columns for (auto r : mtl::rows_of(*matrix_)) { // rows or columns
if (dirichletNodes[r.value()]) { if (dirichletNodes[r.value()]) {
for (auto i : mtl::nz_of(r)) { // non-zeros within for (auto i : mtl::nz_of(r)) { // non-zeros within
// set identity row // set identity row
...@@ -273,12 +263,12 @@ namespace AMDiS ...@@ -273,12 +263,12 @@ namespace AMDiS
// Estimates the slot-size used in the inserter to reserve enough space per row. // Estimates the slot-size used in the inserter to reserve enough space per row.
void calculateSlotSize() void calculateSlotSize()
{ {
slot_size = 0; slotSize_ = 0;
if (num_rows(*matrix) != 0) if (num_rows(*matrix_) != 0)
slot_size = int(double(matrix->nnz()) / num_rows(*matrix) * 1.2); slotSize_ = int(double(matrix_->nnz()) / num_rows(*matrix_) * 1.2);
if (slot_size < MIN_NNZ_PER_ROW) if (slotSize_ < MIN_NNZ_PER_ROW)
slot_size = MIN_NNZ_PER_ROW; slotSize_ = MIN_NNZ_PER_ROW;
} }
private: private:
...@@ -286,28 +276,22 @@ namespace AMDiS ...@@ -286,28 +276,22 @@ namespace AMDiS
static constexpr int MIN_NNZ_PER_ROW = 50; static constexpr int MIN_NNZ_PER_ROW = 50;
/// The finite element space / basis of the row /// The finite element space / basis of the row
RowFeSpace const& rowFeSpace; RowBasis const* rowBasis_;
/// The finite element space / basis of the column /// The finite element space / basis of the column
ColFeSpace const& colFeSpace; ColBasis const* colBasis_;
/// The name of the DOFMatrix
std::string name;
/// The data-matrix (can hold a new BaseMatrix or a pointer to external data /// The data-matrix (can hold a new BaseMatrix or a pointer to external data
ClonablePtr<BaseMatrix> matrix; ClonablePtr<BaseMatrix> matrix_;
/// A pointer to the inserter. Created in \ref init and destroyed in \ref finish /// A pointer to the inserter. Created in \ref init and destroyed in \ref finish
Inserter* inserter = NULL; Inserter* inserter_ = nullptr;
/// A flag that indicates whether the matrix is in insertion mode /// A flag that indicates whether the matrix is in insertion mode
bool insertionMode = false; bool insertionMode_ = false;
/// The size of the slots used to insert values per row /// The size of the slots used to insert values per row
int slot_size = MIN_NNZ_PER_ROW; int slotSize_ = MIN_NNZ_PER_ROW;
// friend class declarations
template <class, class> friend class SystemMatrix;
}; };
} // end namespace AMDiS } // end namespace AMDiS
...@@ -11,14 +11,16 @@ ...@@ -11,14 +11,16 @@
#include <amdis/Output.hpp> #include <amdis/Output.hpp>
#include <amdis/common/ClonablePtr.hpp> #include <amdis/common/ClonablePtr.hpp>
#include <amdis/common/ScalarTypes.hpp> #include <amdis/common/ScalarTypes.hpp>
#include <amdis/linear_algebra/DOFVectorBase.hpp>
#include <amdis/linear_algebra/mtl/MTLDenseVector.hpp> #include <amdis/linear_algebra/mtl/MTLDenseVector.hpp>
#include <amdis/utility/MultiIndex.hpp> #include <amdis/utility/MultiIndex.hpp>
namespace AMDiS namespace AMDiS
{ {
/// The basic container that stores a base vector and a corresponding basis /// The basic container that stores a base vector and a corresponding basis
template <class GlobalBasis, class RangeType = double> template <class GlobalBasis, class ValueType = double>
class DOFVector class DOFVector
: public DOFVectorBase
{ {
using Self = DOFVector; using Self = DOFVector;
...@@ -27,28 +29,25 @@ namespace AMDiS ...@@ -27,28 +29,25 @@ namespace AMDiS
using Basis = GlobalBasis; using Basis = GlobalBasis;
/// The type of the base vector /// The type of the base vector
using BaseVector = MTLDenseVector<RangeType>; using BaseVector = MTLDenseVector<ValueType>;
/// 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 range_type = RangeType; using value_type = ValueType;
/// Constructor. Constructs new BaseVector. /// Constructor. Constructs new BaseVector.
DOFVector(GlobalBasis const& basis, std::string name) DOFVector(GlobalBasis const& basis)
: basis_(&basis) : basis_(&basis)
, 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& basis, std::string name, DOFVector(GlobalBasis const& basis, BaseVector& vector_ref)
BaseVector& vector_ref)
: basis_(&basis) : basis_(&basis)
, name_(name)
, vector_(vector_ref) , vector_(vector_ref)
{} {}
...@@ -76,18 +75,12 @@ namespace AMDiS ...@@ -76,18 +75,12 @@ namespace AMDiS
return basis_->dimension(); return basis_->dimension();
} }
/// Return the \ref name of this vector
std::string name() const
{
return name_;
}
/// Resize the \ref vector to the size of the \ref basis. /// Resize the \ref vector to the size of the \ref basis.