OGS
EigenVector.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "EigenVector.h"
5
6#include <range/v3/algorithm/copy.hpp>
7
8#include "BaseLib/Error.h"
9#include "EigenMapTools.h"
10
11#ifndef NDEBUG
12#include <fstream>
13#endif
14
15namespace MathLib
16{
17void EigenVector::copyValues(std::vector<double>& u) const
18{
19 u.resize(size());
20 toVector(u) = vec_;
21}
22
23void EigenVector::copyValues(std::span<double> u) const
24{
25 if (u.size() != static_cast<std::size_t>(vec_.size()))
26 {
28 "EigenVector copy values; size mismatch. Trying to copy a vector "
29 "of size {:d} to a span of size {:d}.",
30 size(), u.size());
31 }
32 ranges::copy(vec_, u.begin());
33}
34
35#ifndef NDEBUG
36void EigenVector::write(const std::string& filename) const
37{
38 std::ofstream os(filename);
39 os << vec_;
40}
41#endif
42
43} // namespace MathLib
#define OGS_FATAL(...)
Definition Error.h:19
void copyValues(std::vector< double > &u) const
RawVectorType vec_
IndexType size() const
return a vector length
Definition EigenVector.h:36
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