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

removed a lot obsolete code

parent 9e2dadcb
#define AMDIS_NO_EXTERN_SYSTEMMATRIX
#include <amdis/linear_algebra/mtl/SystemMatrix.hpp>
#undef AMDIS_NO_EXTERN_SYSTEMMATRIX
namespace AMDiS
{
// explicit template instatiation
// template class SystemMatrix<typename TestTraits<2,1,2>::FeSpaces>;
} // end namespace AMDiS
#pragma once
#include <vector>
#include <string>
#include <memory>
#include <tuple>
#include <boost/numeric/mtl/matrix/dense2D.hpp>
#include <boost/numeric/mtl/matrix/compressed2D.hpp>
#include <amdis/Output.hpp>
#include <amdis/common/TupleUtility.hpp>
#include <amdis/common/Utility.hpp>
#include <amdis/linear_algebra/mtl/BlockMTLMatrix.hpp>
#include <amdis/linear_algebra/mtl/DOFMatrix.hpp>
// for explicit instantiation
#include <amdis/ProblemStatTraits.hpp>
namespace AMDiS
{
/// \cond HIDDEN_SYMBOLS
namespace Impl
{
// DOFMatrices = std::tuple< std::tuple< DOFMatrix<RowFeSpace, ColFeSpace, ValueType>... >... >
template <class DOFMatrices>
struct BuildDOFMatrices
{
template <std::size_t R>
using DOFMatrixRow = std::tuple_element_t<R, DOFMatrices>;
template <std::size_t R, std::size_t C>
using DOFMatrixRowCol = std::tuple_element_t<C, DOFMatrixRow<R>>;
// add arg to repeated constructor argument list
template <std::size_t... R, class RowFeSpaces, class ColFeSpaces, class MultiMatrix>
static DOFMatrices make(Indices<R...>,
RowFeSpaces&& rowFeSpaces,
ColFeSpaces&& colFeSpace,
MultiMatrix&& multiMatrix)
{
return DOFMatrices{make_row(
index_<R>,
MakeSeq_t<std::tuple_size<std::decay_t<ColFeSpaces>>::value>(),
std::get<R>(std::forward<RowFeSpaces>(rowFeSpaces)),
std::forward<ColFeSpaces>(colFeSpace),
std::forward<MultiMatrix>(multiMatrix)
)...};
}
template <std::size_t R, std::size_t... C, class RowFeSpace, class ColFeSpaces, class MultiMatrix>
static DOFMatrixRow<R> make_row(index_t<R>,
Indices<C...>,
RowFeSpace&& rowFeSpace,
ColFeSpaces&& colFeSpace,
MultiMatrix&& multiMatrix)
{
return DOFMatrixRow<R>{DOFMatrixRowCol<R,C>(
std::forward<RowFeSpace>(rowFeSpace),
std::get<C>(std::forward<ColFeSpaces>(colFeSpace)),
"matrix[" + std::to_string(R) + "][" + std::to_string(C) + "]",
multiMatrix(index_<R>, index_<C>)
)...};
}
};
// construction method to construct a tuple of tuples of DOFMatrices
template <class DOFMatrices, class RowFeSpaces, class ColFeSpaces, class MultiMatrix>
DOFMatrices buildDOFMatrices(RowFeSpaces&& rowFeSpaces,
ColFeSpaces&& colFeSpace,
MultiMatrix&& multiMatrix)
{
return BuildDOFMatrices<DOFMatrices>::make(
MakeSeq_t<std::tuple_size<std::decay_t<RowFeSpaces>>::value>(), // traverse rows first
std::forward<RowFeSpaces>(rowFeSpaces),
std::forward<ColFeSpaces>(colFeSpace),
std::forward<MultiMatrix>(multiMatrix));
}
} // end namespace Impl
/// \endcond
/// \brief Container that repesents multiple data-matrices.
/**
* Represents a fixed-size matrix of \ref mtl::compressed2D + a tuple of corresponding
* feSpaces. This (R,C)'th matrix combined with the (R,C)'th FeSpace
* builds a \ref DOFMatrix and can be return by the \ref operator().
**/
template <class FeSpaces, class ValueType = double>
class SystemMatrix
{
template <class RowFeSpace>
struct MultiMatrixRowGenerator
{
template <class ColFeSpace>
using DOFMatrixGenerator = DOFMatrix<RowFeSpace, ColFeSpace, ValueType>;
using DOFMatrices = MakeTuple_t<DOFMatrixGenerator, FeSpaces>;
};
template <class RowFeSpace>
using DOFMatrixGenerator = typename MultiMatrixRowGenerator<RowFeSpace>::DOFMatrices;
public:
/// The number of blocks per row/column
static constexpr std::size_t nComponent = std::tuple_size<FeSpaces>::value;
AMDIS_STATIC_ASSERT( nComponent > 0 );
/// The type of the matrix in each block
using BaseMatrix = mtl::compressed2D<ValueType>;
/// The type of the matrix of DOFMatrices
using DOFMatrices = MakeTuple_t<DOFMatrixGenerator, FeSpaces>;
/// The type of the matrix of base-matrices
using MultiMatrix = BlockMTLMatrix<BaseMatrix, nComponent, nComponent>;
/// Constructor that constructs new base-matrices
explicit SystemMatrix(FeSpaces const& feSpaces)
: feSpaces(feSpaces)
, matrix()
, dofmatrices(Impl::buildDOFMatrices<DOFMatrices>(feSpaces, feSpaces, matrix))
{}
/// Return the number of blocks per row
static constexpr std::size_t N()
{
return std::tuple_size<FeSpaces>::value;
}
/// Return the number of blocks per column
static constexpr std::size_t M()
{
return std::tuple_size<FeSpaces>::value;
}
/// Return the (R,C)'th underlaying base matrix
template <std::size_t R, std::size_t C>
auto& getMatrix(const index_t<R> _r = {}, const index_t<C> _c = {})
{
static_assert(R < N() && C < M(), "Indices out of range [0,N)x[0,M)");
return matrix(_r, _c);
}
/// Return the (R,C)'th underlaying base matrix
template <std::size_t R, std::size_t C>
auto const& getMatrix(const index_t<R> _r = {}, const index_t<C> _c = {}) const
{
static_assert(R < N() && C < M(), "Indices out of range [0,N)x[0,M)");
return matrix(_r, _c);
}
/// Return the underlying multi matrix
MultiMatrix& getMatrix() { return matrix; }
MultiMatrix const& getMatrix() const { return matrix; }
/// Return the I'th row finite element space
template <std::size_t I = 0>
auto& getRowFeSpace(const index_t<I> = {}) const
{
static_assert(I < N(), "Index out of range [0,N)");
return std::get<I>(feSpaces);
}
/// Return the I'th column finite element space
template <std::size_t I = 0>
auto const& getColFeSpace(const index_t<I> = {}) const
{
static_assert(I < M(), "Index out of range [0,M)");
return std::get<I>(feSpaces);
}
/// Return the (R,C)'th DOFMatrix
template <std::size_t R = 0, std::size_t C = 0>
auto& operator()(const index_t<R> = {}, const index_t<C> = {})
{
static_assert(R < N() && C < M(), "Indices out of range [0,N)x[0,M)");
return std::get<C>(std::get<R>(dofmatrices));
}
/// Return the (R,C)'th DOFMatrix
template <std::size_t R = 0, std::size_t C = 0>
auto const& operator()(const index_t<R> = {}, const index_t<C> = {}) const
{
static_assert(R < N() && C < M(), "Indices out of range [0,N)x[0,M)");
return std::get<C>(std::get<R>(dofmatrices));
}
private:
/// a tuple of feSpaces for rows and columns of the matrix
FeSpaces const& feSpaces;
/// a tuple of data-matrices
MultiMatrix matrix;
/// a tuple of DOFMatrices
DOFMatrices dofmatrices;
};
// #ifndef AMDIS_NO_EXTERN_SYSTEMMATRIX
// // explicit instantiation in SystemMatrix.cpp
// extern template class SystemMatrix<typename TestTraits<2,1,2>::FeSpaces>;
// #endif
} // end namespace AMDiS
#define AMDIS_NO_EXTERN_SYSTEMVECTOR
#include <amdis/linear_algebra/mtl/SystemVector.hpp>
#undef AMDIS_NO_EXTERN_SYSTEMVECTOR
namespace AMDiS
{
// explicit template instatiation
// template class SystemVector<typename TestTraits<2,1,2>::FeSpaces>;
} // end namespace AMDiS
#pragma once
#include <algorithm>
#include <memory>
#include <string>
#include <tuple>
#include <vector>
#include <amdis/Output.hpp>
#include <amdis/common/Loops.hpp>
#include <amdis/common/ScalarTypes.hpp>
#include <amdis/common/TupleUtility.hpp>
#include <amdis/common/Utility.hpp>
#include <amdis/linear_algebra/mtl/BlockMTLVector.hpp>
#include <amdis/linear_algebra/mtl/DOFVector.hpp>
// for explicit instantiation
#include <amdis/ProblemStatTraits.hpp>
namespace AMDiS
{
namespace Impl
{
// DOFVectors = std::tuple< DOFVector<FeSpace, ValueType>... >
template <class DOFVectors>
struct BuildDOFVectors
{
template <std::size_t I>
using DOFVectorIdx = std::tuple_element_t<I, DOFVectors>;
template <std::size_t... I, class FeSpaces, class MultiVector>
static DOFVectors make(Indices<I...>,
FeSpaces&& feSpaces,
std::vector<std::string> const& names,
MultiVector&& multiVector)
{
return DOFVectors{DOFVectorIdx<I>(
std::get<I>(std::forward<FeSpaces>(feSpaces)),
names[I],
multiVector[I]
)...};
}
};
// construction method to construct a tuple of DOFVectors
template <class DOFVectors, class FeSpaces, class MultiVector>
DOFVectors buildDOFVectors(FeSpaces&& feSpaces,
std::vector<std::string> const& names,
MultiVector&& multiVector)
{
return BuildDOFVectors<DOFVectors>::make(
MakeSeq_t<std::tuple_size<std::decay_t<FeSpaces>>::value>(),
std::forward<FeSpaces>(feSpaces),
names,
std::forward<MultiVector>(multiVector));
}
} // end namespace Impl
/// \brief Container that repesents multiple data-Vectors of different value types.
/**
* Represents a std::array of \ref mtl::dense_vector + a tuple of corresponding
* feSpaces. This I'th matrix combined with the I'th FeSpace
* builds a \ref DOFVector and can be return by the \ref operator().
**/
template <class FeSpaces, class ValueType = double>
class SystemVector
{
using Self = SystemVector;
template <class FeSpace>
using DOFVectorGenerator = DOFVector<FeSpace, ValueType>;
public:
/// The number of blocks
static constexpr std::size_t nComponents = std::tuple_size<FeSpaces>::value;
AMDIS_STATIC_ASSERT( nComponents > 0 );
/// The type of the block-vector
using BaseVector = typename DOFVectorGenerator<std::tuple_element_t<0, FeSpaces>>::BaseVector;
using MultiVector = BlockMTLVector<BaseVector, nComponents>;
/// The type of the vector of DOFVectors
using DOFVectors = MakeTuple_t<DOFVectorGenerator, FeSpaces>;
/// Constructor that constructs new base-vectors
SystemVector(FeSpaces const& feSpaces, std::vector<std::string> const& names)
: feSpaces(feSpaces)
, names(names)
, vector_{}
, dofvectors(Impl::buildDOFVectors<DOFVectors>(feSpaces, names, vector_))
{
compress();
}
/// Return the number of blocks
static constexpr std::size_t size()
{
return std::tuple_size<FeSpaces>::value;
}
/// Return the number of blocks
int count() const
{
return int(size());
}
/// Return a shared pointer to the I'th underlaying base vector
template <std::size_t I>
auto& getVector(const index_t<I> = {})
{
static_assert(I < size(), "Index out of range [0,SIZE)" );
return vector_[I];
}
/// Return a shared pointer to the I'th underlaying base vector
template <std::size_t I>
auto const& getVector(const index_t<I> = {}) const
{
static_assert(I < size(), "Index out of range [0,SIZE)" );
return vector_[I];
}
/// Return the underlying multi vector
MultiVector& vector() { return vector_; }
MultiVector const& vector() const { return vector_; }
/// Return the I'th finite element space
template <std::size_t I = 0>
auto const& getFeSpace(const index_t<I> = {}) const
{
static_assert(I < size(), "Index out of range [0,SIZE)" );
return std::get<I>(feSpaces);
}
/// Return the name of the i'th DOFVector
std::string getName(std::size_t i) const
{
return names[i];
}
/// Return the I'th DOFVector
template <std::size_t I>
auto& operator[](const index_t<I>)
{
static_assert(I < size(), "Index out of range [0,SIZE)" );
return std::get<I>(dofvectors);
}
/// Return the I'th DOFVector
template <std::size_t I>
auto const& operator[](const index_t<I>) const
{
static_assert(I < size(), "Index out of range [0,SIZE)" );
return std::get<I>(dofvectors);
}
/// Return the I'th DOFVector
template <std::size_t I>
auto& getDOFVector(const index_t<I> = {})
{
static_assert(I < size(), "Index out of range [0,SIZE)" );
return std::get<I>(dofvectors);
}
/// Return the I'th DOFVector
template <std::size_t I>
auto const& getDOFVector(const index_t<I> = {}) const
{
static_assert(I < size(), "Index out of range [0,SIZE)" );
return std::get<I>(dofvectors);
}
/// Resize the I'th \ref vector to the sizes of the I'th \ref feSpaces.
template <std::size_t I = 0>
void compress(const index_t<I> = {})
{
std::get<I>(dofvectors).compress();
}
/// Resize the \ref vectors to the sizes of the \ref feSpaces.
void compress()
{
forEach(range_<0, size()>, [this](const auto I) {
std::get<I>(dofvectors).compress();
});
}
/// Copy the Systemvector \p that element-wise
void copy(Self const& that)
{
forEach(range_<0, size()>, [this, &that](const auto I) {
std::get<I>(dofvectors).copy(that[I]);
});
}
/// Scale each DOFVector by the factor \p s.
template <class Scalar>
std::enable_if_t< Concepts::Arithmetic<Scalar>, Self&>
operator*=(Scalar s)
{
forEach(range_<0, size()>, [this, s](const auto I) {
vector_[I] *= s;
});
return *this;
}
/// Sets each DOFVector to the scalar \p s.
template <class Scalar>
std::enable_if_t< Concepts::Arithmetic<Scalar>, Self&>
operator=(Scalar s)
{
forEach(range_<0, size()>, [this, s](const auto I) {
vector_[I] = s;
});
return *this;
}
private:
/// a tuple of feSpaces
FeSpaces const& feSpaces;
/// The names of the DOFVectors
std::vector<std::string> names;
/// a tuple of base vectors, i.e. mtl::dense_vectors
MultiVector vector_;
/// a tuple of dofvectors referencing \ref vector
DOFVectors dofvectors;
};
/// Construct a systemvector from given feSpace-tuple and names-vector
template <class FeSpacesType, class ValueType = double>
SystemVector<FeSpacesType, ValueType>
makeSystemVector(FeSpacesType const& feSpaces, std::vector<std::string> names)
{
return {feSpaces, names};
}
/// Construct a systemvector from given feSpace-tuple. Create vector of names
/// from base_name, i.e. {base_name_0, base_name_1, ...}
template <class FeSpaces, class ValueType = double>
SystemVector<FeSpaces, ValueType>
makeSystemVector(FeSpaces const& feSpaces, std::string base_name)
{
std::vector<std::string> names;
for (std::size_t i = 0; i < std::tuple_size<FeSpaces>::value; ++i)
names.push_back(base_name + "_" + std::to_string(i));
return {feSpaces, names};
}
// #ifndef AMDIS_NO_EXTERN_SYSTEMVECTOR
// // explicit instantiation in SystemVector.cpp
// extern template class SystemVector<typename TestTraits<2,1,2>::FeSpaces>;
// #endif
} // end namespace AMDiS
#pragma once
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_UMFPACK
#include <algorithm>
#include <iostream>
#include <string>
#include <boost/numeric/mtl/operation/two_norm.hpp>
#include <boost/numeric/mtl/interface/umfpack_solve.hpp>
#include <amdis/Output.hpp>
#include <amdis/linear_algebra/RunnerInterface.hpp>
#include <amdis/linear_algebra/SolverInfo.hpp>
#include <amdis/linear_algebra/mtl/Copy.hpp>
namespace AMDiS
{
/**
......@@ -40,16 +34,16 @@ namespace AMDiS
using Super = RunnerInterface<Matrix, Vector>;
using PreconBase = typename Super::PreconBase;
using FullMatrix = BaseMatrix_t<Matrix>;
using FullMatrix = Matrix;
using SolverType = mtl::mat::umfpack::solver<FullMatrix>;
public:
/// Constructor. Reads UMFPACK parameters from initfile
UmfpackRunnerBase(std::string prefix)
{
Parameters::get(prefix + "->store symbolic", store_symbolic); // ?
Parameters::get(prefix + "->symmetric strategy", symmetric_strategy);
Parameters::get(prefix + "->alloc init", alloc_init);
Parameters::get(prefix + "->store symbolic", storeSymbolic_); // ?
Parameters::get(prefix + "->symmetric strategy", symmetricStrategy_);
Parameters::get(prefix + "->alloc init", allocInit_);
}
/// Destructor
......@@ -60,11 +54,11 @@ namespace AMDiS
SolverInfo& solverInfo) override
{
AMDIS_FUNCNAME("Umfpack_Runner::solve()");
test_exit(bool(solver), "The umfpack solver was not initialized\n");
test_exit(bool(solver_), "The umfpack solver was not initialized\n");
int code = 0;
try {
code = (*solver)(x, b);
code = (*solver_)(x, b);
} catch (mtl::mat::umfpack::error& e) {
error_exit("UMFPACK_ERROR(solve, ", e.code, ") = ", e.what());
}
......@@ -79,47 +73,17 @@ namespace AMDiS
return code;
}
/// Implementation of \ref RunnerInterface::adjoint_solve()
/// Implementation of \ref RunnerInterface::exit()
virtual void exit() override {}
protected:
std::shared_ptr<SolverType> solver;
std::shared_ptr<SolverType> solver_;
int store_symbolic = 0;
int symmetric_strategy = 0;
double alloc_init = 0.7;
int storeSymbolic_ = 0;
int symmetricStrategy_ = 0;
double allocInit_ = 0.7;
};
// specialization for block-matrices
template <class SubMatrix, std::size_t _N, std::size_t _M, class Vector>
class UmfpackRunner<BlockMTLMatrix<SubMatrix, _N, _M>, Vector>
: public UmfpackRunnerBase<BlockMTLMatrix<SubMatrix, _N, _M>, Vector>
{
using Matrix = BlockMTLMatrix<SubMatrix, _N, _M>;
using Super = UmfpackRunnerBase<Matrix, Vector>;
using SolverType = typename Super::SolverType;
public:
UmfpackRunner(std::string prefix)
: Super(prefix)
{}
/// Implementation of \ref RunnerInterface::init()
virtual void init(Matrix const& A) override
{
copy(A, fullMatrix);
try {
Super::solver.reset(new SolverType(fullMatrix, Super::symmetric_strategy, Super::alloc_init));
} catch (mtl::mat::umfpack::error const& e) {
error_exit("UMFPACK_ERROR(factorize, ", e.code, ") = ", e.what());
}
}
private:
typename Super::FullMatrix fullMatrix;
};