14#include "segment_o2.h"
20 : coords_(std::move(coords)),
21 alpha_(coords_.rows()),
22 beta_(coords_.rows(), 2),
23 gamma_(coords_.rows(), 2),
24 delta_(coords_.rows()),
25 epsilon_(coords_.rows(), 2),
26 gamma_x_2_(coords_.rows(), 2),
27 epsilon_x_2_(coords_.rows(), 2) {
35 const Eigen::VectorXd& A =
coords_.col(0);
36 const Eigen::VectorXd& B =
coords_.col(1);
37 const Eigen::VectorXd& C =
coords_.col(2);
38 const Eigen::VectorXd& D =
coords_.col(3);
39 const Eigen::VectorXd& E =
coords_.col(4);
40 const Eigen::VectorXd& F =
coords_.col(5);
41 const Eigen::VectorXd& G =
coords_.col(6);
42 const Eigen::VectorXd& H =
coords_.col(7);
45 beta_ << -3. * A - B + 4. * E, -3. * A - D + 4. * H;
46 gamma_ << 2. * (A + B) - 4. * E, 2. * (A + D) - 4. * H;
47 delta_ << 5. * A - B - 3. * C - D - 4. * (E - F - G + H);
48 epsilon_ << -2. * (A + B - C - D) + 4. * (E - G),
49 -2. * (A - B - C + D) - 4. * (F - H);
57 LF_VERIFY_MSG((0. <= local.array()).all() && (local.array() <= 1.).all(),
58 "local coordinates out of bounds for reference element");
60 auto local_squared = local.array().square();
61 return ((
beta_ * local) + (
gamma_ * local_squared.matrix()) +
62 (
delta_ * local.row(0).cwiseProduct(local.row(1))) +
64 (local_squared * local.colwise().reverse().array()).matrix()))
70 LF_VERIFY_MSG((0. <= local.array()).all() && (local.array() <= 1.).all(),
71 "local coordinates out of bounds for reference element");
73 auto local_squared_reversed = local.array().square().colwise().reverse();
74 auto local_colwise_product = local.row(0).cwiseProduct(local.row(1));
76 Eigen::MatrixXd tmp_epsilon(
gamma_.rows(), 2 * local.cols());
77 Eigen::MatrixXd tmp_epsilon_x_2 =
epsilon_x_2_.replicate(1, local.cols());
78 Eigen::MatrixXd tmp_gamma(
gamma_.rows(), 2 * local.cols());
80 for (
long i = 0; i < local.cols(); ++i) {
81 tmp_epsilon.block(0, 2 * i, tmp_epsilon.rows(), 2) =
82 epsilon_.rowwise().reverse().array().rowwise() *
83 local_squared_reversed.col(i).transpose().array();
84 tmp_epsilon_x_2.block(0, 2 * i, tmp_epsilon_x_2.rows(), 2) *=
85 local_colwise_product(i);
86 tmp_gamma.block(0, 2 * i, tmp_gamma.rows(), 2) =
87 gamma_x_2_.array().rowwise() * local.col(i).transpose().array();
90 Eigen::MatrixXd local_reversed = local.colwise().reverse();
91 local_reversed.resize(1, local.size());
93 return beta_.replicate(1, local.cols()) + tmp_gamma + tmp_epsilon +
95 (local_reversed.replicate(
delta_.rows(), 1).array().colwise() *
101 const Eigen::MatrixXd& local)
const {
102 LF_VERIFY_MSG((0. <= local.array()).all() && (local.array() <= 1.).all(),
103 "local coordinates out of bounds for reference element");
105 Eigen::MatrixXd jac =
Jacobian(local);
106 Eigen::MatrixXd jacInvGram(jac.rows(), jac.cols());
109 for (
long i = 0; i < local.cols(); ++i) {
110 auto jacobian = jac.block(0, 2 * i, 2, 2);
111 jacInvGram.block(0, 2 * i, 2, 2) << jacobian(1, 1), -jacobian(1, 0),
112 -jacobian(0, 1), jacobian(0, 0);
113 jacInvGram.block(0, 2 * i, 2, 2) /= jacobian.determinant();
116 for (
long i = 0; i < local.cols(); ++i) {
117 auto jacobian = jac.block(0, 2 * i, jac.rows(), 2);
119 auto A = jacobian.col(0);
120 auto B = jacobian.col(1);
123 Eigen::MatrixXd tmp(2, 2);
124 tmp << B.dot(B), -AB, -AB, A.dot(A);
126 jacInvGram.block(0, 2 * i, jac.rows(), 2) =
127 jacobian * tmp / tmp.determinant();
135 LF_VERIFY_MSG((0. <= local.array()).all() && (local.array() <= 1.).all(),
136 "local coordinates out of bounds for reference element");
138 Eigen::MatrixXd jac =
Jacobian(local);
139 Eigen::VectorXd intElem(local.cols());
142 for (
long i = 0; i < local.cols(); ++i) {
143 intElem(i) = std::abs(jac.block(0, 2 * i, 2, 2).determinant());
146 for (
long i = 0; i < local.cols(); ++i) {
147 auto jacobian = jac.block(0, 2 * i, jac.rows(), 2);
149 auto A = jacobian.col(0);
150 auto B = jacobian.col(1);
153 intElem(i) = std::sqrt(std::abs(A.dot(A) * B.dot(B) - AB * AB));
163 LF_ASSERT_MSG(i == 0,
"i is out of bounds");
164 return std::make_unique<QuadO2>(
coords_);
167 LF_ASSERT_MSG(0 <= i && i <= 3,
"i is out of bounds");
168 return std::make_unique<SegmentO2>(
169 (Eigen::Matrix<double, Eigen::Dynamic, 3>(
DimGlobal(), 3)
175 LF_ASSERT_MSG(0 <= i && i <= 8,
"i is out of bounds");
176 return std::make_unique<Point>(
coords_.col(i));
179 LF_VERIFY_MSG(
false,
"codim is out of bounds")
188 LF_VERIFY_MSG(codim < 3,
"Illegal codim " << codim);
190 const double hLattice = 1. /
static_cast<double>(ref_pat.
LatticeConst());
191 std::vector<std::unique_ptr<Geometry>> childGeoPtrs = {};
194 std::vector<Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic>> childPolygons(
200 "NumChildren " << noChildren <<
" <-> " << ref_pat.
NumChildren(codim));
203 for (
size_t child = 0; child < noChildren; ++child) {
209 childPolygons[child].rows() == 2,
210 "childPolygons[child].rows() = " << childPolygons[child].rows());
212 (childPolygons[child].cols() == (3 - codim)) ||
213 (childPolygons[child].cols() == 4),
214 "childPolygons[child].cols() = " << childPolygons[child].cols());
216 const Eigen::MatrixXd locChildPolygonCoords(
217 hLattice * childPolygons[child].cast<double>());
221 if (childPolygons[child].cols() == 3) {
222 Eigen::MatrixXd locChildCoords(locChildPolygonCoords.rows(), 6);
223 locChildCoords << locChildPolygonCoords,
224 (locChildPolygonCoords.col(0) + locChildPolygonCoords.col(1)) /
226 (locChildPolygonCoords.col(1) + locChildPolygonCoords.col(2)) /
228 (locChildPolygonCoords.col(2) + locChildPolygonCoords.col(0)) /
231 childGeoPtrs.push_back(
232 std::make_unique<TriaO2>(
Global(locChildCoords)));
234 }
else if (childPolygons[child].cols() == 4) {
235 Eigen::MatrixXd locChildCoords(locChildPolygonCoords.rows(), 8);
236 locChildCoords << locChildPolygonCoords,
237 (locChildPolygonCoords.col(0) + locChildPolygonCoords.col(1)) /
239 (locChildPolygonCoords.col(1) + locChildPolygonCoords.col(2)) /
241 (locChildPolygonCoords.col(2) + locChildPolygonCoords.col(3)) /
243 (locChildPolygonCoords.col(3) + locChildPolygonCoords.col(0)) /
246 childGeoPtrs.push_back(
247 std::make_unique<QuadO2>(
Global(locChildCoords)));
250 LF_VERIFY_MSG(
false,
"childPolygons[" << child <<
"].cols() = "
251 << childPolygons[child].cols());
257 Eigen::MatrixXd locChildCoords(locChildPolygonCoords.rows(), 3);
258 locChildCoords << locChildPolygonCoords,
259 (locChildPolygonCoords.col(0) + locChildPolygonCoords.col(1)) / 2.;
261 childGeoPtrs.push_back(
262 std::make_unique<SegmentO2>(
Global(locChildCoords)));
267 childGeoPtrs.push_back(
268 std::make_unique<Point>(
Global(locChildPolygonCoords)));
273 LF_VERIFY_MSG(
false,
"Illegal co-dimension");
static constexpr RefEl kQuad()
Returns the reference quadrilateral.
std::string ToString() const
Return a string representation of this Reference element.
Eigen::Matrix< double, Eigen::Dynamic, 2 > gamma_x_2_
Eigen::MatrixXd Jacobian(const Eigen::MatrixXd &local) const override
Evaluate the jacobian of the mapping simultaneously at numPoints points.
Eigen::Matrix< double, Eigen::Dynamic, 2 > epsilon_x_2_
Eigen::Matrix< double, Eigen::Dynamic, 2 > beta_
Eigen::VectorXd IntegrationElement(const Eigen::MatrixXd &local) const override
The integration element (factor appearing in integral transformation formula, see below) at number of...
Eigen::Matrix< double, Eigen::Dynamic, 2 > gamma_
Eigen::MatrixXd Global(const Eigen::MatrixXd &local) const override
Map a number of points in local coordinates into the global coordinate system.
Eigen::Matrix< double, Eigen::Dynamic, 8 > coords_
Coordinates of the 8 vertices/midpoints, stored in matrix columns.
Eigen::MatrixXd JacobianInverseGramian(const Eigen::MatrixXd &local) const override
Evaluate the Jacobian * Inverse Gramian ( ) simultaneously at numPoints.
std::vector< std::unique_ptr< Geometry > > ChildGeometry(const RefinementPattern &ref_pat, lf::base::dim_t codim) const override
Generate geometry objects for child entities created in the course of refinement.
Eigen::Matrix< double, Eigen::Dynamic, 1 > alpha_
Eigen::Matrix< double, Eigen::Dynamic, 1 > delta_
Eigen::Matrix< double, Eigen::Dynamic, 2 > epsilon_
QuadO2(Eigen::Matrix< double, Eigen::Dynamic, 8 > coords)
Constructor building quadrilateral from vertex/midpoint coordinates.
dim_t DimGlobal() const override
Dimension of the image of this mapping.
std::unique_ptr< Geometry > SubGeometry(dim_t codim, dim_t i) const override
Construct a new Geometry() object that describes the geometry of the i-th sub-entity with codimension...
Abstract interface class for encoding topological local refinement
lf::base::size_type LatticeConst() const
Provides information about lattice constant used.
virtual lf::base::size_type NumChildren(lf::base::dim_t codim) const =0
provide number of child entities of a given co-dimension to be created by refinement
virtual std::vector< Eigen::Matrix< int, Eigen::Dynamic, Eigen::Dynamic > > ChildPolygons(lf::base::dim_t codim) const =0
provide lattice reference coordinates of vertices of child polygons
lf::base::RefEl RefEl() const
Returns topological type of entity for which the current object is set up.
unsigned int size_type
general type for variables related to size of arrays
unsigned int dim_t
type for dimensions and co-dimensions and numbers derived from them
Defines the Geometry interface and provides a number of classes that implement this interface + addit...