9#ifndef __b9b63bcccec548419a52fe0b06ffb3fc
10#define __b9b63bcccec548419a52fe0b06ffb3fc
12#include <lf/mesh/mesh.h>
38template <
class OP,
class MF>
44 return op_(
mf_(e, local), 0);
55 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
56 auto operator()(
const std::vector<U>& u,
int )
const {
57 Eigen::Map<const Eigen::Matrix<U, 1, Eigen::Dynamic>> um(&u[0], 1,
59 std::vector<U> result(u.size());
60 Eigen::Map<Eigen::Matrix<U, 1, Eigen::Dynamic>> rm(&result[0], 1, u.size());
66 template <
class S,
int R,
int C,
int O,
int MR,
int MC>
67 auto operator()(
const std::vector<Eigen::Matrix<S, R, C, O, MR, MC>>& u,
69 if constexpr (R == 0 || C == 0) {
73 if constexpr (R != Eigen::Dynamic && C != Eigen::Dynamic) {
75 Eigen::Map<const Eigen::Matrix<S, 1, Eigen::Dynamic>> um(
76 &u[0](0, 0), 1, u.size() * R * C);
77 std::vector<Eigen::Matrix<S, R, C, O, MR, MC>> result(u.size());
78 Eigen::Map<Eigen::Matrix<S, 1, Eigen::Dynamic>> rm(&result[0](0, 0), 1,
84 std::vector<Eigen::Matrix<S, R, C, O, MR, MC>> result(u.size());
85 for (
int i = 0; i < u.size(); ++i) {
93 template <
class S,
int R,
int C,
int O,
int MR,
int MC>
94 auto operator()(
const std::vector<Eigen::Array<S, R, C, O, MR, MC>>& u,
96 if constexpr (R == 0 || C == 0) {
100 if constexpr (R != Eigen::Dynamic && C != Eigen::Dynamic) {
102 Eigen::Map<const Eigen::Array<S, 1, Eigen::Dynamic>> um(&u[0](0, 0), 1,
104 std::vector<Eigen::Array<S, R, C, O, MR, MC>> result(u.size());
105 Eigen::Map<Eigen::Array<S, 1, Eigen::Dynamic>> rm(&result[0](0, 0), 1,
111 std::vector<Eigen::Array<S, R, C, O, MR, MC>> result(u.size());
112 for (
int i = 0; i < u.size(); ++i) {
121 auto operator()(
const std::vector<T>& u,
long )
const {
122 std::vector<T> result(u.size());
123 for (
int i = 0; i < u.size(); ++i) {
130struct UnaryOpSquaredNorm {
132 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
133 auto operator()(
const std::vector<U>& u,
int )
const {
134 Eigen::Map<const Eigen::Matrix<U, 1, Eigen::Dynamic>> um(&u[0], 1,
136 std::vector<U> result(u.size());
137 Eigen::Map<Eigen::Matrix<U, 1, Eigen::Dynamic>> rm(&result[0], 1, u.size());
143 template <
class S,
int R,
int C,
int O,
int MR,
int MC>
144 auto operator()(
const std::vector<Eigen::Matrix<S, R, C, O, MR, MC>>& u,
146 std::vector<double> result(u.size());
147 if constexpr (R != Eigen::Dynamic && C != Eigen::Dynamic) {
150 "squaredNorm only supported for matrices with at least 1 row "
152 if constexpr (C == 1) {
153 Eigen::Map<const Eigen::Matrix<S, R, Eigen::Dynamic>> um(&u[0](0, 0), R,
155 Eigen::Map<Eigen::Matrix<S, 1, Eigen::Dynamic>> rm(&result[0], 1,
157 rm = um.cwiseAbs2().colwise().sum();
158 }
else if constexpr (R == 1) {
159 Eigen::Map<const Eigen::Matrix<S, Eigen::Dynamic, C, Eigen::RowMajor>>
160 um(&u[0](0, 0), u.size(), C);
161 Eigen::Map<Eigen::Matrix<S, Eigen::Dynamic, 1>> rm(&result[0], u.size(),
163 rm = um.cwiseAbs2().rowwise().sum();
166 for (std::size_t i = 0; i < u.size(); ++i) {
167 result[i] = u[i].squaredNorm();
174struct UnaryOpTranspose {
176 template <
class S,
int R,
int C,
int O,
int MR,
int MC>
177 auto operator()(
const std::vector<Eigen::Matrix<S, R, C, O, MR, MC>>& u,
179 std::vector<Eigen::Matrix<S, C, R>> result(u.size());
180 for (std::size_t i = 0; i < u.size(); ++i) {
181 result[i] = u[i].transpose();
187 template <
class S,
int R,
int C,
int O,
int MR,
int MC>
188 auto operator()(
const std::vector<Eigen::Array<S, R, C, O, MR, MC>>& u,
190 std::vector<Eigen::Array<S, C, R>> result(u.size());
191 for (std::size_t i = 0; i < u.size(); ++i) {
192 result[i] = u[i].transpose();
198struct UnaryOpAdjoint {
200 template <
class S,
int R,
int C,
int O,
int MR,
int MC>
201 auto operator()(
const std::vector<Eigen::Matrix<S, R, C, O, MR, MC>>& u,
203 std::vector<Eigen::Matrix<S, C, R>> result(u.size());
204 for (std::size_t i = 0; i < u.size(); ++i) {
205 result[i] = u[i].adjoint();
211struct UnaryOpConjugate {
213 template <
class U,
class = std::enable_if_t<base::is_scalar<U>>>
214 auto operator()(
const std::vector<U>& u,
int )
const {
215 Eigen::Map<const Eigen::Matrix<U, 1, Eigen::Dynamic>> um(&u[0], 1,
217 std::vector<U> result(u.size());
218 Eigen::Map<Eigen::Matrix<U, 1, Eigen::Dynamic>> rm(&result[0], 1, u.size());
224 template <
class S,
int R,
int C,
int O,
int MR,
int MC>
225 auto operator()(
const std::vector<Eigen::Matrix<S, R, C, O, MR, MC>>& u,
227 std::vector<Eigen::Matrix<S, R, C>> result(u.size());
228 for (std::size_t i = 0; i < u.size(); ++i) {
229 result[i] = u[i].conjugate();
235 template <
class S,
int R,
int C,
int O,
int MR,
int MC>
236 auto operator()(
const std::vector<Eigen::Array<S, R, C, O, MR, MC>>& u,
238 std::vector<Eigen::Array<S, R, C>> result(u.size());
239 for (std::size_t i = 0; i < u.size(); ++i) {
240 result[i] = u[i].conjugate();
259template <
class A,
class = std::enable_if_t<isMeshFunction<A>>>
274template <
class A,
class = std::enable_if_t<isMeshFunction<A>>>
286template <
class A,
class = std::enable_if_t<isMeshFunction<A>>>
288 static_assert(base::is_eigen_matrix<MeshFunctionReturnType<A>> ||
289 base::is_eigen_array<MeshFunctionReturnType<A>>,
290 "transpose() only supported for Eigen::Matrix and Eigen::Array "
291 "valued mesh functions");
303template <
class A,
class = std::enable_if_t<isMeshFunction<A>>>
306 static_assert(base::is_eigen_matrix<returnType_t>,
307 "adjoint only supported for Eigen::Matrix valued mesh "
320template <
class A,
class = std::enable_if_t<isMeshFunction<A>>>
324 base::is_eigen_matrix<returnType_t> ||
325 base::is_eigen_array<returnType_t> || base::is_scalar<returnType_t>,
326 "conjugate() supports only Eigen::Matrix, Eigen::Array or Scalar valued "
Interface class representing a topological entity in a cellular complex
A mesh function representing another mesh function under a pointwise, unary operation.
auto operator()(const mesh::Entity &e, const Eigen::MatrixXd &local) const
auto adjoint(const A &a)
Pointwise adjoint of an Eigen::Matrix, i.e. the conjugate transposed of the matrix.
auto squaredNorm(const A &a)
Pointwise squared norm of another mesh function.
MeshFunctionUnary(OP op, MF mf)
auto transpose(const A &a)
Pointwise transpose of an Eigen::Matrix or Eigen::Array
auto conjugate(const A &a)
Pointwise conjuagte of an Eigen::Matrix, Eigen::Array or scalar valued mesh function.
auto operator-(const A &a)
Applies the unary minus operator to a mesh function.
Contains helper functions and classes that all operate on the interface classes defined in lf::mesh.
internal::VectorElement_t< internal::MeshFunctionReturnType_t< R > > MeshFunctionReturnType
Determine the type of objects returned by a MeshFunction.