OGS
anonymous_namespace{CompareJacobiansJacobianAssembler.cpp} Namespace Reference

Functions

template<typename T>
requires std::integral<T> || std::floating_point<T>
void dump_py (std::ostream &fh, std::string const &var, T const val)
 Dumps a numeric value as a Python script snippet.
template<typename Vec>
void dump_py_vec (std::ostream &fh, std::string const &var, Vec const &val)
 Dumps an arbitrary vector as a Python script snippet.
void dump_py (std::ostream &fh, std::string const &var, std::vector< double > const &val)
 Dumps a std::vector<double> as a Python script snippet.
template<typename Derived>
void dump_py (std::ostream &fh, std::string const &var, Eigen::ArrayBase< Derived > const &val, std::integral_constant< int, 1 >)
 Dumps an Eigen vector (array with 1 column) as a Python script snippet.
template<typename Derived, int ColsAtCompileTime>
void dump_py (std::ostream &fh, std::string const &var, Eigen::ArrayBase< Derived > const &val, std::integral_constant< int, ColsAtCompileTime >)
 Dumps an Eigen array as a Python script snippet.
template<typename Derived>
void dump_py (std::ostream &fh, std::string const &var, Eigen::ArrayBase< Derived > const &val)
 Dumps an Eigen array as a Python script snippet.
template<typename Derived>
void dump_py (std::ostream &fh, std::string const &var, Eigen::MatrixBase< Derived > const &val)
 Dumps an Eigen matrix as a Python script snippet.
auto signedAbsDiffRelDiff (auto const &mat_or_vec1, auto const &mat_or_vec2)
 (Signed) absolute and (symmetric) relative difference as Eigen::Array
template<typename MatOrVec>
auto oneIfAboveThresholdElseZero (MatOrVec &&mat_or_vec, double const threshold)
bool isSimilar (auto const &mat_or_vec1, auto const &mat_or_vec2, double const abs_tol, double const rel_tol)

Variables

const std::string msg_fatal
 Will be printed if some consistency error is detected.

Function Documentation

◆ dump_py() [1/6]

template<typename Derived>
void anonymous_namespace{CompareJacobiansJacobianAssembler.cpp}::dump_py ( std::ostream & fh,
std::string const & var,
Eigen::ArrayBase< Derived > const & val )

Dumps an Eigen array as a Python script snippet.

Definition at line 98 of file CompareJacobiansJacobianAssembler.cpp.

100{
101 dump_py(fh, var, val,
102 std::integral_constant<int, Derived::ColsAtCompileTime>{});
103}
void dump_py(std::ostream &fh, std::string const &var, T const val)
Dumps a numeric value as a Python script snippet.

References dump_py().

◆ dump_py() [2/6]

template<typename Derived>
void anonymous_namespace{CompareJacobiansJacobianAssembler.cpp}::dump_py ( std::ostream & fh,
std::string const & var,
Eigen::ArrayBase< Derived > const & val,
std::integral_constant< int, 1 >  )

Dumps an Eigen vector (array with 1 column) as a Python script snippet.

Definition at line 62 of file CompareJacobiansJacobianAssembler.cpp.

65{
66 dump_py_vec(fh, var, val);
67}
void dump_py_vec(std::ostream &fh, std::string const &var, Vec const &val)
Dumps an arbitrary vector as a Python script snippet.

References dump_py_vec().

◆ dump_py() [3/6]

template<typename Derived, int ColsAtCompileTime>
void anonymous_namespace{CompareJacobiansJacobianAssembler.cpp}::dump_py ( std::ostream & fh,
std::string const & var,
Eigen::ArrayBase< Derived > const & val,
std::integral_constant< int, ColsAtCompileTime >  )

Dumps an Eigen array as a Python script snippet.

Definition at line 71 of file CompareJacobiansJacobianAssembler.cpp.

74{
75 fh << var << " = np.array([\n";
76 for (std::ptrdiff_t r = 0; r < val.rows(); ++r)
77 {
78 if (r != 0)
79 {
80 fh << ",\n";
81 }
82 fh << " [";
83 for (std::ptrdiff_t c = 0; c < val.cols(); ++c)
84 {
85 if (c != 0)
86 {
87 fh << ", ";
88 }
89 fh << val(r, c);
90 }
91 fh << "]";
92 }
93 fh << "])\n";
94}

◆ dump_py() [4/6]

template<typename Derived>
void anonymous_namespace{CompareJacobiansJacobianAssembler.cpp}::dump_py ( std::ostream & fh,
std::string const & var,
Eigen::MatrixBase< Derived > const & val )

Dumps an Eigen matrix as a Python script snippet.

Definition at line 107 of file CompareJacobiansJacobianAssembler.cpp.

109{
110 dump_py(fh, var, val.array());
111}

References dump_py().

◆ dump_py() [5/6]

void anonymous_namespace{CompareJacobiansJacobianAssembler.cpp}::dump_py ( std::ostream & fh,
std::string const & var,
std::vector< double > const & val )

Dumps a std::vector<double> as a Python script snippet.

Definition at line 54 of file CompareJacobiansJacobianAssembler.cpp.

56{
57 dump_py_vec(fh, var, val);
58}

References dump_py_vec().

◆ dump_py() [6/6]

template<typename T>
requires std::integral<T> || std::floating_point<T>
void anonymous_namespace{CompareJacobiansJacobianAssembler.cpp}::dump_py ( std::ostream & fh,
std::string const & var,
T const val )

Dumps a numeric value as a Python script snippet.

Definition at line 23 of file CompareJacobiansJacobianAssembler.cpp.

24{
25 fh << var << " = " << val << '\n';
26}

Referenced by dump_py(), and dump_py().

◆ dump_py_vec()

template<typename Vec>
void anonymous_namespace{CompareJacobiansJacobianAssembler.cpp}::dump_py_vec ( std::ostream & fh,
std::string const & var,
Vec const & val )

Dumps an arbitrary vector as a Python script snippet.

Definition at line 30 of file CompareJacobiansJacobianAssembler.cpp.

31{
32 fh << var << " = np.array([";
33 for (decltype(val.size()) i = 0; i < val.size(); ++i)
34 {
35 if (i != 0)
36 {
37 if (i % 8 == 0)
38 {
39 // Print at most eight entries on one line,
40 // indent with four spaces.
41 fh << ",\n ";
42 }
43 else
44 {
45 fh << ", ";
46 }
47 }
48 fh << val[i];
49 }
50 fh << "])\n";
51}

Referenced by dump_py(), and dump_py().

◆ isSimilar()

bool anonymous_namespace{CompareJacobiansJacobianAssembler.cpp}::isSimilar ( auto const & mat_or_vec1,
auto const & mat_or_vec2,
double const abs_tol,
double const rel_tol )

Definition at line 142 of file CompareJacobiansJacobianAssembler.cpp.

144{
145 if (mat_or_vec1.size() == 0 || mat_or_vec2.size() == 0)
146 {
147 // either size is 0, ignore
148 return true;
149 }
150 if (mat_or_vec1.rows() != mat_or_vec2.rows() ||
151 mat_or_vec1.cols() != mat_or_vec2.cols())
152 {
153 return false;
154 }
155
156 auto const [abs_diff, rel_diff] =
157 signedAbsDiffRelDiff(mat_or_vec1, mat_or_vec2);
158 auto const abs_tol_exceeded = abs_diff.abs() > abs_tol;
159 auto const rel_tol_exceeded = rel_diff.abs() > rel_tol;
160
161 // similar if for no entry abs and rel tols are exceeded at the same time
162 return !(abs_tol_exceeded && rel_tol_exceeded).any();
163}
auto signedAbsDiffRelDiff(auto const &mat_or_vec1, auto const &mat_or_vec2)
(Signed) absolute and (symmetric) relative difference as Eigen::Array

References signedAbsDiffRelDiff().

◆ oneIfAboveThresholdElseZero()

template<typename MatOrVec>
auto anonymous_namespace{CompareJacobiansJacobianAssembler.cpp}::oneIfAboveThresholdElseZero ( MatOrVec && mat_or_vec,
double const threshold )

Definition at line 133 of file CompareJacobiansJacobianAssembler.cpp.

134{
135 return (mat_or_vec <= threshold)
136 .select(MatOrVec::Zero(mat_or_vec.rows(), mat_or_vec.cols()),
137 MatOrVec::Ones(mat_or_vec.rows(), mat_or_vec.cols()))
138 .eval();
139}

◆ signedAbsDiffRelDiff()

auto anonymous_namespace{CompareJacobiansJacobianAssembler.cpp}::signedAbsDiffRelDiff ( auto const & mat_or_vec1,
auto const & mat_or_vec2 )

(Signed) absolute and (symmetric) relative difference as Eigen::Array

Definition at line 119 of file CompareJacobiansJacobianAssembler.cpp.

120{
121 auto abs_diff = (mat_or_vec2 - mat_or_vec1).array().eval();
122 auto const rel_diff =
123 (abs_diff == 0.0)
124 .select(
125 abs_diff,
126 2. * abs_diff /
127 (mat_or_vec1.cwiseAbs() + mat_or_vec2.cwiseAbs()).array())
128 .eval();
129 return std::pair{std::move(abs_diff), std::move(rel_diff)};
130}

Referenced by isSimilar().

Variable Documentation

◆ msg_fatal

const std::string anonymous_namespace{CompareJacobiansJacobianAssembler.cpp}::msg_fatal
Initial value:
=
"The local matrices M or K or the local vectors b assembled with the two "
"different Jacobian assemblers differ."

Will be printed if some consistency error is detected.

Definition at line 114 of file CompareJacobiansJacobianAssembler.cpp.