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

Copy constructor for DOFVector that does proper resizing of the data-vectors before

parent d7c6313f
Pipeline #1258 failed with stage
in 3 minutes and 1 second
#pragma once
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <fmt/core.h>
/**
* \def AMDIS_NO_THROW
* \brief The preprocessor constant sets whether to use c-asserts (if defined) or
......@@ -18,10 +14,14 @@
#include <stdexcept>
#endif
#ifdef AMDIS_HAS_MPI
#ifdef HAVE_MPI
#include <mpi.h>
#endif
/// Use the formatting librart fmtlib::fmt
#include <fmt/core.h>
#include <fmt/ostream.h>
/**
* \def AMDIS_ENABLE_MSG_DBG
* \brief The preprocessor constant enables the functions \ref AMDiS::MSG_DBG
......@@ -65,12 +65,13 @@ namespace AMDiS
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &num_ranks);
if (num_ranks > 1 && rank == 0) {
out << "[0] " << fmt::format(std::forward<Args>(args)...);
out << "[0] ";
fmt::print(out, std::forward<Args>(args)...);
} else if (num_ranks == 1) {
out << fmt::format(std::forward<Args>(args)...);
fmt::print(out, std::forward<Args>(args)...);
}
#else
out << fmt::format(std::forward<Args>(args)...);
fmt::print(out, std::forward<Args>(args)...);
#endif
return out;
}
......
......@@ -52,13 +52,19 @@ namespace AMDiS
virtual void closeTimestep(AdaptInfo& adaptInfo) override;
/// Returns \ref problemStat.
ProblemType& getStatProblem()
ProblemType const& getProblemStat() const
{
return problemStat_;
}
/// Returns \ref problemStat.
ProblemType& getProblemStat()
{
return problemStat_;
}
/// Returns \ref oldSolution.
std::unique_ptr<SystemVector> getOldSolutionVector() const
std::unique_ptr<SystemVector> const& getOldSolutionVector() const
{
test_exit_dbg(oldSolution_,
"OldSolution need to be created. Call initialize with INIT_UH_OLD.");
......@@ -70,7 +76,7 @@ namespace AMDiS
auto getOldSolution(TreePath const& path = {})
{
auto&& tp = makeTreePath(path);
return makeDOFVectorView(*oldSolution_, tp);
return makeDOFVectorView(*getOldSolutionVector(), tp);
}
/// Return a const view to a oldSolution component
......@@ -78,7 +84,7 @@ namespace AMDiS
auto getOldSolution(TreePath const& path = {}) const
{
auto&& tp = makeTreePath(path);
return makeDOFVectorView(*oldSolution_, tp);
return makeDOFVectorView(*getOldSolutionVector(), tp);
}
/// Implementation of \ref ProblemTimeInterface::transferInitialSolution().
......
......@@ -33,7 +33,7 @@ void ProblemInstat<Traits>::initialize(Flag initFlag)
{
// create vector for old solution
if (initFlag.isSet(INIT_UH_OLD))
createUhOld();
createUhOld();
}
......
......@@ -19,7 +19,7 @@ namespace AMDiS
using Self = DOFVectorBase;
public:
/// The type of the \ref basis
/// The type of the functionspace basis associated to this vector
using Basis = BasisType;
/// The index/size - type
......@@ -28,6 +28,7 @@ namespace AMDiS
/// The type of the elements of the DOFVector
using value_type = typename Backend::value_type;
/// The type of the data vector used in the backend
using BaseVector = typename Backend::BaseVector;
public:
......@@ -38,6 +39,30 @@ namespace AMDiS
compress();
}
DOFVectorBase(Self const&) = default;
DOFVectorBase(Self&&) = default;
/// Copy assignment operator
Self& operator=(Self const& that)
{
assert(basis_ == that.basis_);
backend_.resize(that.size());
backend_ = that.backend_;
return *this;
}
/// Move assignment
Self& operator=(Self&& that) = default;
/// Sets each DOFVector to the scalar \p value.
template <class Scalar,
std::enable_if_t<Concepts::Arithmetic<Scalar>, int> = 0>
Self& operator=(Scalar value)
{
vector() = value;
return *this;
}
/// Return the basis \ref basis_ associated to the vector
Basis const& basis() const
{
......@@ -67,7 +92,7 @@ namespace AMDiS
backend_.resize(size_type(s));
}
/// Resize the \ref vector to the size of the \ref basis.
/// Resize the \ref vector to the size of the \ref basis and set to zero
virtual void compress() override
{
if (backend_.size() != size()) {
......@@ -105,15 +130,6 @@ namespace AMDiS
}
}
/// Sets each DOFVector to the scalar \p value.
template <class Scalar,
std::enable_if_t<Concepts::Arithmetic<Scalar>, int> = 0>
Self& operator=(Scalar value)
{
vector() = value;
return *this;
}
private:
/// The finite element space / basis associated with the data vector
Basis const* basis_;
......
......@@ -24,10 +24,16 @@ namespace AMDiS
{
public:
/// The type of the elements of the DOFVector
using value_type = typename BlockVectorType<ValueType>::type;
using block_type = typename BlockVectorType<ValueType>::type;
/// The type of the elements of the DOFVector
using value_type = block_type;
/// The underlying field type
using field_type = typename block_type::field_type;
/// The vector type of the underlying base vector
using BaseVector = Dune::BlockVector<value_type>;
using BaseVector = Dune::BlockVector<block_type>;
/// The index/size - type
using size_type = typename BaseVector::size_type;
......@@ -63,7 +69,7 @@ namespace AMDiS
/// Access the entry \p i of the \ref vector with read-access.
value_type const& operator[](size_type i) const
block_type const& operator[](size_type i) const
{
test_exit_dbg(i < vector_.size(),
"Index {} out of range [0,{})", i, vector_.size());
......@@ -71,7 +77,7 @@ namespace AMDiS
}
/// Access the entry \p i of the \ref vector with write-access.
value_type& operator[](size_type i)
block_type& operator[](size_type i)
{
test_exit_dbg(i < vector_.size(),
"Index {} out of range [0,{})", i, vector_.size());
......
......@@ -2,6 +2,8 @@
#include <boost/numeric/mtl/vector/dense_vector.hpp>
#include <dune/common/ftraits.hh>
#include <amdis/Output.hpp>
#include <amdis/linear_algebra/DOFVectorBase.hpp>
......@@ -12,15 +14,21 @@ namespace AMDiS
class MtlVector
{
public:
/// The type of the elements of the DOFVector
using value_type = ValueType;
/// The type of the elements of the DOFVector
using block_type = ValueType;
/// The underlying field type
using field_type = typename Dune::FieldTraits<ValueType>::field_type;
/// The type of the base vector
using BaseVector = mtl::vec::dense_vector<ValueType>;
/// The index/size - type
using size_type = typename BaseVector::size_type;
/// The type of the elements of the DOFVector
using value_type = ValueType;
public:
/// Constructor. Constructs new BaseVector.
MtlVector() = default;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment