Commit 289b2b9a authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

working version of dune-functions assembling

parent 7668c6b7
#pragma once
#include <memory>
#include <utility>
#include <dune/amdis/common/Utility.hpp>
......@@ -28,18 +29,18 @@ namespace AMDiS
{}
/// Constructor from reference
ClonablePtr(T& ref) noexcept
explicit ClonablePtr(T& ref) noexcept
: p(&ref)
, is_owner(false)
{}
/// Constructor from std::unique_ptr
ClonablePtr(std::unique_ptr<T>& ptr)
explicit ClonablePtr(std::unique_ptr<T>& ptr)
: p(ptr.release())
, is_owner(true)
{}
ClonablePtr(std::unique_ptr<T>&& ptr)
explicit ClonablePtr(std::unique_ptr<T>&& ptr)
: p(ptr.release())
, is_owner(true)
{}
......
#pragma once
#include <algorithm>
#include <dune/common/fmatrix.hh>
#include <dune/common/fvector.hh>
......
#pragma once
#include <algorithm>
#include <dune/amdis/Math.hpp>
#include <dune/amdis/common/Concepts.hpp>
#include <dune/amdis/common/ScalarTypes.hpp>
......
......@@ -14,7 +14,7 @@ namespace AMDiS
class FileWriterInterface
{
public:
FileWriterInterface(std::string base)
explicit FileWriterInterface(std::string base)
{
filename_ = "solution";
Parameters::get(base + "->filename", filename_);
......
#pragma once
namespace AMDiS
{
namespace Impl
{
using BaseElementMatrix = mtl::dense2D<double>;
using PowerIndex = std::array<std::size_t, 2>;
template <class RowNode, class ColNode, class RowTag, class ColTag>
class ElementMatrix;
template <class RowNode, class ColNode>
class ElementMatrix<RowNode, ColNode, Dune::TypeTree::LeafNodeTag, Dune::TypeTree::LeafNodeTag>
{
public:
ElementMatrix() = default;
ElementMatrix(RowNode const& rowNode, ColNode const& colNode)
{
resize(rowNode, colNode);
}
void resize(RowNode const& rowNode, ColNode const& colNode)
{
matrix_.change_dim(rowNode.finiteElement().size(),
colNode.finiteElement().size());
}
double const& operator()(std::size_t i, std::size_t j) const
{
return matrix_[i][j];
}
double& operator()(std::size_t i, std::size_t j)
{
return matrix_[i][j];
}
template <class RowIndexSet, class ColIndexSet, class Matrix>
void apply(RowIndexSet const& rowIndexSet, ColIndexSet const& colIndexSet, Matrix& mat) const
{
for (std::size_t i = 0; i < num_rows(matrix_); ++i) {
// The global index of the i−th vertex of the element
auto const row = rowIndexSet.index(i);
for (std::size_t j = 0; j < num_cols(matrix_); ++j) {
// The global index of the j−th vertex of the element
auto const col = colIndexSet.index(j);
mat(row,col) += matrix_(i,j);
}
}
}
private:
BaseElementMatrix matrix_;
};
template <class RowNode, class ColNode>
class ElementMatrix<RowNode, ColNode, Dune::TypeTree::PowerNodeTag, Dune::TypeTree::LeafNodeTag>
{
static_assert( RowNode::Child<0>::type::isLeaf,
"Requires near-leaf power nodes." );
public:
ElementMatrix() = default;
ElementMatrix(RowNode const& rowNode, ColNode const& colNode)
{
resize(rowNode, colNode);
}
void resize(RowNode const& rowNode, ColNode const& colNode)
{
for (std::size_t i = 0; i < RowNode::CHILDREN; ++i)
matrix_[i].change_dim(rowNode.child(0).finiteElement().size(),
colNode.finiteElement().size());
}
double const& operator()(PowerIndex ii, std::size_t j) const
{
return matrix_[ii[0]][ii[1]][j];
}
double& operator()(PowerIndex ii, std::size_t j)
{
return matrix_[ii[0]][ii[1]][j];
}
private:
std::array<BaseElementMatrix, RowNode::CHILDREN> matrix_;
};
template <class RowNode, class ColNode>
class ElementMatrix<RowNode, ColNode, Dune::TypeTree::LeafNodeTag, Dune::TypeTree::PowerNodeTag>
{
static_assert( ColNode::Child<0>::type::isLeaf,
"Requires near-leaf power nodes." );
public:
ElementMatrix() = default;
ElementMatrix(RowNode const& rowNode, ColNode const& colNode)
{
resize(rowNode, colNode);
}
void resize(RowNode const& rowNode, ColNode const& colNode)
{
for (std::size_t i = 0; i < ColNode::CHILDREN; ++i)
matrix_[i].change_dim(rowNode.finiteElement().size(),
colNode.child(0).finiteElement().size());
}
double const& operator()(std::size_t i, PowerIndex jj) const
{
return matrix_[jj[0]][i][jj[1]];
}
double& operator()(std::size_t i, PowerIndex jj)
{
return matrix_[jj[0]][i][jj[1]];
}
private:
std::array<BaseElementMatrix, ColNode::CHILDREN> matrix_;
};
template <class RowNode, class ColNode>
class ElementMatrix<RowNode, ColNode, Dune::TypeTree::PowerNodeTag, Dune::TypeTree::PowerNodeTag>
{
static_assert( RowNode::Child<0>::type::isLeaf &&
ColNode::Child<0>::type::isLeaf,
"Requires near-leaf power nodes." );
public:
ElementMatrix() = default;
ElementMatrix(RowNode const& rowNode, ColNode const& colNode)
{
resize(rowNode, colNode);
}
void resize(RowNode const& rowNode, ColNode const& colNode)
{
for (std::size_t i = 0; i < RowNode::CHILDREN; ++i)
for (std::size_t j = 0; j < ColNode::CHILDREN; ++j)
matrix_[i][j].change_dim(rowNode.child(0).finiteElement().size(),
colNode.child(0).finiteElement().size());
}
double const& operator()(PowerIndex ii, PowerIndex jj) const
{
return matrix_[ii[0]][jj[0]][ii[1]][jj[1]];
}
double& operator()(PowerIndex ii, PowerIndex jj)
{
return matrix_[ii[0]][jj[0]][ii[1]][jj[1]];
}
private:
std::array<std::array<BaseElementMatrix, ColNode::CHILDREN>, RowNode::CHILDREN> matrix_;
};
} // end namespace Impl
template <class RowNode, class ColNode>
using ElementMatrix
= Impl::ElementMatrix<RowNode, ColNode, typename RowNode::NodeTag, typename ColNode::NodeTag>;
template <class RowNode, class ColNode>
ElementMatrix<RowNode, ColNode> makeElementMatrix(RowNode const& rowNode, ColNode const& colNode)
{
return {rowNode, colNode};
}
} // end namespace AMDiS
#pragma once
namespace AMDiS
{
namespace Impl
{
using BaseElementVector = mtl::dense_vector<double>;
using PowerIndex = std::array<std::size_t, 2>;
template <class Node, class NodeTag>
class ElementVector;
template <class Node>
class ElementVector<Node, Dune::TypeTree::LeafNodeTag>
{
public:
ElementVector() = default;
ElementVector(Node const& node)
{
resize(node);
}
void resize(Node const& node)
{
vector_.change_dim(node.finiteElement().size());
}
double const& operator[](std::size_t i) const { return vector_[i]; }
double& operator[](std::size_t i) { return vector_[i]; }
template <class LocalIndexSet, class Vector>
void apply(LocalIndexSet const& localIndexSet, Vector& vec) const
{
for (std::size_t i = 0; i < num_rows(vector_); ++i) {
// The global index of the i−th vertex of the element
auto const idx = localIndexSet.index(i);
vec[idx] += vector_[i];
}
}
private:
BaseElementVector vector_;
};
template <class Node>
class ElementVector<Node, Dune::TypeTree::PowerNodeTag>
{
static_assert( Node::Child<0>::type::isLeaf,
"Requires near-leaf power nodes." );
public:
ElementVector() = default;
ElementVector(Node const& node)
{
resize(node);
}
void resize(Node const& node)
{
for (std::size_t i = 0; i < Node::CHILDREN; ++i)
vector_[i].change_dim(node.child(0).finiteElement().size());
}
double const& operator()(PowerIndex ii) const
{
return vector_[ii[0]][ii[1]];
}
double& operator()(PowerIndex ii)
{
return vector_[ii[0]][ii[1]];
}
private:
std::array<BaseElementVector, Node::CHILDREN> vector_;
};
} // end namespace Impl
template <class Node>
using ElementVector = Impl::ElementVector<Node, typename Node::NodeTag>;
template <class Node>
ElementVector<Node> makeElementVector(Node const& node)
{
return {node};
}
} // end namespace AMDiS
......@@ -10,7 +10,7 @@ namespace AMDiS
class HierarchicMatrixWrapper
{
public:
HierarchicMatrixWrapper(Matrix& matrix)
explicit HierarchicMatrixWrapper(Matrix& matrix)
: matrix_(matrix)
{}
......@@ -42,7 +42,7 @@ namespace AMDiS
class HierarchicVectorWrapper
{
public:
HierarchicVectorWrapper(Vector& vector)
explicit HierarchicVectorWrapper(Vector& vector)
: vector_(vector)
{}
......@@ -85,9 +85,9 @@ namespace AMDiS
};
template <class Vector>
HierarchicVectorWrapper<Vector> hierarchicVectorWrapper(Vector& vector)
auto hierarchicVectorWrapper(Vector& vector)
{
return {vector};
return HierarchicVectorWrapper<Vector>{vector};
}
} // end namespace AMDiS
......@@ -35,7 +35,7 @@ namespace AMDiS
using value_type = typename Vector::value_type;
using size_type = typename Vector::size_type;
BaseWrapper(Vector& vec) : vec(vec) {}
explicit BaseWrapper(Vector& vec) : vec(vec) {}
void resize(size_type s)
{
......
#pragma once
namespace Dune {
namespace Functions {
template <class NodeFactory>
struct VectorBuilder
{
using type = mtl::dense_vector<double>;
};
template <class MultiIndex, class IndexTag, class... SubFactories>
struct VectorBuilder<CompositeNodeFactory<MultiIndex, IndexTag, SubFactories...>>
{
static const bool isBlocked = std::is_same<IndexTag, BlockedLexicographic>::value ||
std::is_same<IndexTag, LeafBlockedInterleaved>::value;
using type = Dune::TupleVector<typename VectorBuilder<SubFactories>::type...>;
};
template <class MultiIndex, class IndexTag, class SubFactory, int k>
struct VectorBuilder<PowerNodeFactory<MultiIndex, IndexTag, SubFactory, k>>
{
static const bool isBlocked = std::is_same<IndexTag, BlockedLexicographic>::value ||
std::is_same<IndexTag, LeafBlockedInterleaved>::value;
using type = Dune::FieldVector<typename VectorBuilder<SubFactory>::type, std::size_t(k)>;
};
}} // end namespace Dune::Functions
......@@ -88,8 +88,8 @@ namespace AMDiS
"This specialization is for BlockMTLVectors only.");
public:
BlockVectorWrapper(BlockVector& blockVector,
bool copyBack = !std::is_const<BlockVector>::value)
explicit BlockVectorWrapper(BlockVector& blockVector,
bool copyBack = !std::is_const<BlockVector>::value)
: blockVector(blockVector)
, vector(num_rows(blockVector))
, copyBack(copyBack)
......@@ -158,7 +158,7 @@ namespace AMDiS
static_assert( std::is_same< std::remove_const_t<BlockVector>, Vector >::value,
"This specialization is for contiguose vectors only.");
public:
BlockVectorWrapper(BlockVector& vector, bool = false)
explicit BlockVectorWrapper(BlockVector& vector, bool = false)
: vector(vector)
{}
......@@ -177,10 +177,9 @@ namespace AMDiS
template <class BlockVector, class Vector = MTLDenseVector<typename BlockVector::value_type>>
BlockVectorWrapper_t<BlockVector, Vector>
blockWrapper(BlockVector& bvec)
auto blockWrapper(BlockVector& bvec)
{
return {bvec};
return BlockVectorWrapper_t<BlockVector, Vector>{bvec};
}
......
#pragma once
#include <algorithm>
#include <dune/amdis/linear_algebra/mtl/BlockMTLVector.hpp>
#include <dune/amdis/linear_algebra/mtl/BlockMTLMatrix.hpp>
......
#pragma once
#include <string>
#include <list>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <boost/numeric/mtl/matrix/compressed2D.hpp>
#include <boost/numeric/mtl/matrix/inserter.hpp>
......
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string>
#include <algorithm>
#include <memory>
#include <string>
#include <dune/common/reservedvector.hh>
#include <dune/functions/functionspacebases/flatmultiindex.hh>
......@@ -48,6 +45,7 @@ namespace AMDiS
, vector(ClonablePtr<BaseVector>::make())
{
compress();
*vector = ValueType(0);
}
/// Constructor. Takes reference to existing BaseVector
......
......@@ -2,6 +2,8 @@
#pragma once
#include <string>
// MTL4 includes
#include <boost/numeric/itl/itl.hpp>
// #include <boost/numeric/itl/krylov/bicg.hpp>
......@@ -44,7 +46,7 @@ namespace AMDiS
class cg_solver_type
{
public:
cg_solver_type(std::string /*name*/) {}
explicit cg_solver_type(std::string /*name*/) {}
template <class LinOp, class X, class B, class L, class R, class I>
int operator()(LinOp const& A, X& x, B const& b, L const& l, R const& r, I& iter)
{
......@@ -64,7 +66,7 @@ namespace AMDiS
class cgs_solver_type
{
public:
cgs_solver_type(std::string /*name*/) {}
explicit cgs_solver_type(std::string /*name*/) {}
template <class LinOp, class X, class B, class L, class R, class I>
int operator()(LinOp const& A, X& x, B const& b, L const& l, R const&, I& iter)
{
......@@ -84,7 +86,7 @@ namespace AMDiS
class bicg_solver_type
{
public:
bicg_solver_type(std::string /*name*/) {}
explicit bicg_solver_type(std::string /*name*/) {}
template <class LinOp, class X, class B, class L, class R, class I>
int operator()(LinOp const& A, X& x, B const& b, L const& l, R const&, I& iter)
{
......@@ -104,7 +106,7 @@ namespace AMDiS
class bicgstab_type
{
public:
bicgstab_type(std::string /*name*/) {}
explicit bicgstab_type(std::string /*name*/) {}
template <class LinOp, class X, class B, class L, class R, class I>
int operator()(LinOp const& A, X& x, B const& b, L const& l, R const&, I& iter)
{
......@@ -124,7 +126,7 @@ namespace AMDiS
class bicgstab2_type
{
public:
bicgstab2_type(std::string /*name*/) {}
explicit bicgstab2_type(std::string /*name*/) {}
template <class LinOp, class X, class B, class L, class R, class I>
int operator()(LinOp const& A, X& x, B const& b, L const& l, R const&, I& iter)
{
......@@ -143,7 +145,7 @@ namespace AMDiS
class qmr_solver_type
{
public:
qmr_solver_type(std::string /*name*/) {}
explicit qmr_solver_type(std::string /*name*/) {}
template <class LinOp, class X, class B, class L, class R, class I>
int operator()(LinOp const& A, X& x, B const& b, L const& l, R const& r, I& iter)
{
......@@ -163,7 +165,7 @@ namespace AMDiS
class tfqmr_solver_type
{
public:
tfqmr_solver_type(std::string /*name*/) {}
explicit tfqmr_solver_type(std::string /*name*/) {}
template <class LinOp, class X, class B, class L, class R, class I>
int operator()(LinOp const& A, X& x, B const& b, L const& l, R const& r, I& iter)
{
......@@ -184,7 +186,7 @@ namespace AMDiS
{
int ell;
public:
bicgstab_ell_type(std::string name) : ell(3)
explicit bicgstab_ell_type(std::string name) : ell(3)
{
Parameters::get(name + "->ell", ell);
}
......@@ -209,7 +211,7 @@ namespace AMDiS
{
public:
gmres_type(std::string name) : restart(30), ortho(GRAM_SCHMIDT)
explicit gmres_type(std::string name) : restart(30), ortho(GRAM_SCHMIDT)
{
Parameters::get(name + "->restart", restart);
Parameters::get(name + "->orthogonalization", ortho);
......@@ -228,11 +230,11 @@ namespace AMDiS
break;
}
}
private:
static constexpr int GRAM_SCHMIDT = 1;
static constexpr int HOUSEHOLDER = 2;
int restart;
int ortho;
};
......@@ -254,7 +256,7 @@ namespace AMDiS
{
int s;
public:
idr_s_type(std::string name) : s(30)
explicit idr_s_type(std::string name) : s(30)
{
Parameters::get(name + "->s", s);
}
......@@ -277,7 +279,7 @@ namespace AMDiS
class minres_solver_type
{
public:
minres_solver_type(std::string /*name*/) {}
explicit minres_solver_type(std::string /*name*/) {}
template <class LinOp, class X, class B, class L, class R, class I>
int operator()(LinOp const& A, X& x, B const& b, L const& l, R const& r, I& iter)
{
......@@ -300,7 +302,7 @@ namespace AMDiS