LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
Loading...
Searching...
No Matches
check_jacobian.cc
1
9#include "check_jacobian.h"
10
11#include <gtest/gtest.h>
12
14
16 const Eigen::MatrixXd &eval_points,
17 const double &tolerance) {
18 const double h = 1e-6;
19
20 const size_t num_points = eval_points.cols();
21 const size_t dim_local = geom.DimLocal();
22 const size_t dim_global = geom.DimGlobal();
23
24 Eigen::MatrixXd jacobians = geom.Jacobian(eval_points);
25
26 EXPECT_EQ(jacobians.rows(), dim_global) << "Jacobian has " << jacobians.rows()
27 << " rows instead of " << dim_global;
28 EXPECT_EQ(jacobians.cols(), num_points * dim_local)
29 << "Jacobian has " << jacobians.cols() << " cols instead of "
30 << num_points * dim_local;
31
32 for (size_t j = 0; j < num_points; ++j) {
33 auto point = eval_points.col(j);
34
35 Eigen::MatrixXd jacobian =
36 jacobians.block(0, j * dim_local, dim_global, dim_local);
37 Eigen::MatrixXd approx_jacobian =
38 Eigen::MatrixXd::Zero(dim_global, dim_local);
39
40 for (size_t i = 0; i < dim_local; ++i) {
41 Eigen::VectorXd h_vec = Eigen::VectorXd::Zero(dim_local);
42 h_vec(i) = h;
43
44 // approximate gradient with symmetric difference quotient
45 approx_jacobian.col(i) =
46 (geom.Global(point + h_vec) - geom.Global(point - h_vec)) / (2. * h);
47 }
48
49 EXPECT_TRUE(jacobian.isApprox(approx_jacobian, tolerance))
50 << "Jacobian incorrect at point " << point;
51 }
52}
53
54} // namespace lf::geometry::test_utils
Interface class for shape information on a mesh cell in the spirit of parametric finite element metho...
virtual Eigen::MatrixXd Global(const Eigen::MatrixXd &local) const =0
Map a number of points in local coordinates into the global coordinate system.
virtual dim_t DimLocal() const =0
Dimension of the domain of this mapping.
virtual dim_t DimGlobal() const =0
Dimension of the image of this mapping.
virtual Eigen::MatrixXd Jacobian(const Eigen::MatrixXd &local) const =0
Evaluate the jacobian of the mapping simultaneously at numPoints points.
Defines the Geometry::test_utils module and provides a number of test functions to check geometry obj...
void checkJacobian(const lf::geometry::Geometry &geom, const Eigen::MatrixXd &eval_points, const double &tolerance)
Checks if Jacobian() is implemented correctly by comparing it to the symmetric difference quotient ap...