#include "gtest/gtest.h"
BoxShape<Vec2d> box(0.0, 1.0);
DomainDiscretization<Vec2d> d = box.discretizeWithStep(0.1);
d.findSupport(FindClosest(9));
WLS<Monomials<Vec2d>> approx(2);
int node = 12;
approx.compute(d.pos(node), d.supportNodes(node));
Eigen::VectorXd sh = approx.getShape(Der1<2>(0));
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));
sh2 = shapes.d1(1, node);
EXPECT_EQ(sh, sh2);
node = 34;
approx.compute(d.pos(node), d.supportNodes(node));
sh = approx.getShape(Lap<2>());
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);
int node = 22;
approx.compute(d.pos(node), d.supportNodes(node));
Eigen::VectorXd sh = approx.getShape(Der2<2>(0));
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));
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));
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>());
sh2 = shapes.laplace(node);
EXPECT_EQ(sh, sh2);
}
struct Zero : Operator<Zero> {
const basis_t&, int, const std::vector<typename basis_t::vector_t>&,
};
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);
shapes.get<Der1s<2>>(0, 3, 4);
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?");
}
}