OGS
EigenVector.cpp
Go to the documentation of this file.
1
11#include "EigenVector.h"
12
13#include <range/v3/algorithm/copy.hpp>
14
15#include "BaseLib/Error.h"
16#include "EigenMapTools.h"
17
18#ifndef NDEBUG
19#include <fstream>
20#endif
21
22namespace MathLib
23{
24void EigenVector::copyValues(std::vector<double>& u) const
25{
26 u.resize(size());
27 toVector(u) = vec_;
28}
29
30void EigenVector::copyValues(std::span<double> u) const
31{
32 if (u.size() != static_cast<std::size_t>(vec_.size()))
33 {
35 "EigenVector copy values; size mismatch. Trying to copy a vector "
36 "of size {:d} to a span of size {:d}.",
37 size(), u.size());
38 }
39 ranges::copy(vec_, u.begin());
40}
41
42#ifndef NDEBUG
43void EigenVector::write(const std::string& filename) const
44{
45 std::ofstream os(filename);
46 os << vec_;
47}
48#endif
49
50} // namespace MathLib
#define OGS_FATAL(...)
Definition Error.h:26
void copyValues(std::vector< double > &u) const
RawVectorType vec_
IndexType size() const
return a vector length
Definition EigenVector.h:43
void write(const std::string &filename) const
write this vector to a file for debugging
Eigen::Map< const Vector > toVector(std::vector< double > const &data, Eigen::VectorXd::Index size)
Creates an Eigen mapped vector from the given data vector.
static const double u