Medusa  1.1
Coordinate Free Mehless Method implementation
test/operators/computeShapes_test.cpp
#include "gtest/gtest.h"
namespace mm {
TEST(Operators, computeShapes) {
BoxShape<Vec2d> box(0.0, 1.0);
DomainDiscretization<Vec2d> d = box.discretizeWithStep(0.1);
d.findSupport(FindClosest(9));
WLS<Monomials<Vec2d>> approx(2);
auto shapes = d.computeShapes<sh::lap|sh::d1>(approx); // implicit call via domain hook
// direct call which overwrites shapes for Laplacian for internal nodes in given storage
computeShapes(d, approx, d.interior(), operators, &shapes);
int node = 12;
approx.compute(d.pos(node), d.supportNodes(node));
Eigen::VectorXd sh = approx.getShape(Der1<2>(0)); // d/dx shape
Eigen::VectorXd sh2 = shapes.d1(0, node);
EXPECT_EQ(sh, sh2);
node = 5;
approx.compute(d.pos(node), d.supportNodes(node));
sh = approx.getShape(Der1<2>(1)); // d/dy shape
sh2 = shapes.d1(1, node);
EXPECT_EQ(sh, sh2);
node = 34;
approx.compute(d.pos(node), d.supportNodes(node));
sh = approx.getShape(Lap<2>()); // lap shape
sh2 = shapes.laplace(node);
EXPECT_EQ(sh, sh2);
}
TEST(Operators, computeShapesD2) {
BoxShape<Vec2d> box(0.0, 1.0);
DomainDiscretization<Vec2d> d = box.discretizeWithStep(0.1);
d.findSupport(FindClosest(9));
WLS<Monomials<Vec2d>> approx(2);
auto shapes = d.computeShapes<sh::lap|sh::d2>(approx);
int node = 22;
approx.compute(d.pos(node), d.supportNodes(node));
Eigen::VectorXd sh = approx.getShape(Der2<2>(0)); // d/dx^2 shape
Eigen::VectorXd sh2 = shapes.d2(0, 0, node);
EXPECT_EQ(sh, sh2);
node = 0;
approx.compute(d.pos(node), d.supportNodes(node));
sh = approx.getShape(Der2<2>(1)); // d/dy^2 shape
sh2 = shapes.d2(1, 1, node);
EXPECT_EQ(sh, sh2);
node = 46;
approx.compute(d.pos(node), d.supportNodes(node));
sh = approx.getShape(Der2<2>(0, 1)); // d/dy^2 shape
sh2 = shapes.d2(0, 1, node);
EXPECT_EQ(sh, sh2);
node = 78;
approx.compute(d.pos(node), d.supportNodes(node));
sh = approx.getShape(Lap<2>()); // lap shape
sh2 = shapes.laplace(node);
EXPECT_EQ(sh, sh2);
}
// Dummy zero operator
struct Zero : Operator<Zero> {
template <typename basis_t> typename basis_t::scalar_t applyAt0(
const basis_t&, int, const std::vector<typename basis_t::vector_t>&,
typename basis_t::scalar_t) const { return 0.0; }
};
TEST(Operators, ComputeShapesCustom) {
BoxShape<Vec2d> box(0.0, 1.0);
DomainDiscretization<Vec2d> d = box.discretizeWithStep(0.1);
int n = 9;
d.findSupport(FindClosest(n));
WLS<Monomials<Vec2d>> approx(2);
std::tuple<Lap<2>, Der1s<2>, Zero> ops;
auto shapes = d.computeShapes<decltype(ops)>(ops, approx);
shapes.get<Zero>(3, 2); // coefficient 4 of shape for zero in 3rd node.
shapes.get<Der1s<2>>(0, 3, 4); // coefficient 4 of shape for dx in 3rd node.
int N = d.size();
for (int i = 0; i < N; ++i) {
for (int j = 0; j < n; ++j) {
EXPECT_EQ(0, shapes.get<Zero>(i, j));
}
}
}
TEST(Operators, computeShapesEmptySupport) {
BoxShape<Vec2d> box(0.0, 1.0);
DomainDiscretization<Vec2d> d = box.discretizeWithStep(0.1);
WLS<Monomials<Vec2d>> approx(2);
UniformShapeStorage<Vec2d, std::tuple<Lap<2>>> storage;
EXPECT_DEATH(computeShapes(d, approx, d.interior(), operators, &storage),
"Did you forget to find support before computing shapes?");
}
} // namespace mm
mm::sh::d1
static const shape_flags d1
Indicates to calculate d1 shapes.
Definition: shape_flags.hpp:23
Monomials.hpp
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
scalar_t
Scalar scalar_t
Type of the elements, alias of Scalar.
Definition: MatrixBaseAddons.hpp:16
DomainDiscretization.hpp
stdtypesutils.hpp
mm::sh::lap
static const shape_flags lap
Indicates to calculate laplace shapes.
Definition: shape_flags.hpp:24
mm::computeShapes
void computeShapes(const DomainDiscretization< typename approx_t::vector_t > &domain, approx_t approx, const indexes_t &indexes, const std::tuple< OpFamilies... > &operators, shape_storage_t *storage)
Computes shape functions (stencil weights) for given nodes using support domains from domain and appr...
JacobiSVDWrapper_fwd.hpp
RaggedShapeStorage.hpp
ScaleFunction.hpp
ShapeStorage.hpp
mm::sh::d2
static const shape_flags d2
Indicates to calculate d2 shapes.
Definition: shape_flags.hpp:25
FindClosest.hpp
mm::sh::operator_tuple::type
void type
The type of the operator tuple.
Definition: shape_flags.hpp:43
Operators_fwd.hpp
computeShapes.hpp
WeightFunction.hpp
Timer.hpp
BoxShape.hpp
UniformShapeStorage.hpp
WLS.hpp