18 #ifndef DCELL_HPP_INCLUDED
19 #define DCELL_HPP_INCLUDED
40 template<
size_t dimension>
44 typedef std::array<std::vector<dCell_graph>,dimension+1>
Collection;
48 std::vector<size_t>
const & map_ids );
54 std::vector<size_t>
const & map_ids ,
55 std::vector<size_t>
const & bd );
58 size_t get_id()
const {
return _bd_ids[_d][0];}
60 std::vector<size_t>
const &
get_map_ids()
const {
return _map_ids;}
62 std::vector<size_t>
const &
get_boundary(
size_t dim )
const {
return _bd_ids[dim];}
64 std::vector<size_t>
const &
get_relative_map(
size_t dim )
const {
return _bd_rel_maps[dim];}
69 std::vector<size_t> _map_ids;
70 std::array<std::vector<size_t>,dimension+1> _bd_ids;
71 std::array<std::vector<size_t>,dimension> _bd_rel_maps;
72 size_t _find_map(
size_t id)
const;
82 template<
size_t dimension,
size_t d>
93 dCell_map(Eigen::Vector<double,dimension>
const ¢er_mass ,
94 Eigen::Matrix<double,dimension,d>
const &flat_map ,
96 std::vector<
Simplex<d>>
const &triangulation );
100 std::vector<
Simplex<d>>
const &triangulation );
111 Eigen::Vector<double,dimension>
evaluate_I(
size_t rel_map_id ,
112 Eigen::Vector<double,d>
const &x )
const;
116 Eigen::Vector<double,dimension>
const &x )
const;
125 Eigen::Vector<double,dimension>
const &x ,
131 Eigen::Vector<double,d>
const &x )
const;
135 Eigen::Vector<double,dimension>
const &x )
const;
141 Eigen::Vector<double,d>
const &x )
const;
147 Eigen::Vector<double,dimension>
const &x )
const;
157 Eigen::Vector<double,dimension>
const &x ,
158 Eigen::Matrix<double,dimension,d-1>
const &pM
162 Eigen::Vector<double,dimension> _center_mass;
163 Eigen::Matrix<double,dimension,d> _flat_map;
165 std::vector<std::unique_ptr<ParametrizedMap<dimension,d>>> _maps;
166 std::vector<std::unique_ptr<ParametrizedDerivedMap<dimension,d>>> _pullback_maps;
169 std::vector<Simplex<d>> _triangulation;
174 template<
size_t dimension>
177 dCell_map(std::vector<Eigen::Vector<double,dimension>>
const &coords ) : _locs(coords) {};
180 Eigen::Vector<double,dimension>
const &
coord(
size_t map_rel_id )
const {
return _locs[map_rel_id];}
183 std::vector<Eigen::Vector<double,dimension>> _locs;
193 template<
size_t dimension>
195 : _d(0), _map_ids(map_ids) {
196 _bd_ids[_d] = std::vector<size_t>{
id};
199 template<
size_t dimension>
201 : _d(d), _map_ids(map_ids) {
204 _bd_ids[d] = std::vector<size_t>{
id};
206 for (
size_t i = 0; i < bd.size(); ++i) {
207 _bd_rel_maps[d-1].push_back(coll[d-1][bd[i]]._find_map(_map_ids[0]));
210 for (
size_t dim = d-1; dim > 0; --dim) {
211 std::set<size_t> clist;
212 for (
size_t i = 0; i < _bd_ids[dim].size(); ++i) {
213 std::vector<size_t>
const & cb = coll[dim][_bd_ids[dim][i]].get_boundary(dim-1);
214 for (
size_t j = 0; j < cb.size(); ++j) {
218 for (
auto const &p : clist) {
219 _bd_ids[dim-1].push_back(p);
220 _bd_rel_maps[dim-1].push_back(coll[dim-1][p]._find_map(_map_ids[0]));
226 template<
size_t dimension>
228 for (
size_t i = 0; i < _map_ids.size(); ++i) {
229 if (_map_ids[i] ==
id)
return i;
231 return _map_ids.size();
234 template<
size_t dimension>
237 for (
size_t i = 0; i < _bd_ids[d_boundary].size(); ++ i) {
238 if (_bd_ids[d_boundary][i] == i_b)
return i;
241 return _bd_ids[d_boundary].size();
247 template<
size_t dimension,
size_t d>
249 Eigen::Matrix<double,dimension,d>
const &flat_map,
250 double diam, std::vector<
Simplex<d>>
const &triangulation)
251 : _center_mass(center_mass), _flat_map(flat_map), _diam(diam), _is_flat(true), _triangulation(triangulation)
254 template<
size_t dimension,
size_t d>
258 : _maps(std::move(maps)), _pullback_maps(std::move(pullback_maps)), _is_flat(false), _triangulation(triangulation)
261 template<
size_t dimension,
size_t d>
265 if constexpr(dimension == d) {
266 return x*_diam + _center_mass;
268 return _flat_map*x*_diam + _center_mass;
271 assert(rel_map_id < _maps.size());
272 return _maps[rel_map_id]->I(x);
276 template<
size_t dimension,
size_t d>
280 if constexpr(dimension == d) {
281 return (x - _center_mass)/_diam;
283 return _flat_map.transpose()*(x - _center_mass)/_diam;
286 assert(rel_map_id < _maps.size());
287 return _maps[rel_map_id]->J(x);
293 template<
size_t dimension,
size_t d>
298 double rv = std::pow(x(0),power[0]);
299 for (
size_t i = 1; i < d; ++i) {
300 rv *= std::pow(x(i),power[i]);
305 template<
size_t dimension,
size_t d>
308 return evaluate_poly_on_ref(evaluate_J(rel_map_id,x),i_pbasis,r);
311 template<
size_t dimension,
size_t d>
315 if constexpr(dimension == d) {
316 return Eigen::Matrix<double,d,d>::Identity()*_diam;
318 return _flat_map*_diam;
321 return _pullback_maps[rel_map_id]->DI(x);
325 template<
size_t dimension,
size_t d>
329 if constexpr(dimension == d) {
330 return Eigen::Matrix<double,d,d>::Identity()/_diam;
332 return _flat_map/_diam;
335 return _pullback_maps[rel_map_id]->DJ(x);
339 template<
size_t dimension,
size_t d>
344 if constexpr(dimension == d) {
354 template<
size_t dimension,
size_t d>
359 if constexpr(dimension == d) {
369 template<
size_t dimension,
size_t d>
371 Eigen::Vector<double,dimension>
const &x,
372 Eigen::Matrix<double,dimension,d-1>
const &pM)
const requires(d>1)
374 auto const Jx = evaluate_J(rel_map_id,x);
375 for (
auto const &S : _triangulation) {
376 if (Geometry::inside<d>(Jx,S)) {
377 auto mid = Geometry::middleSimplex<d>(S);
378 auto DI = evaluate_DI(rel_map_id,Jx);
379 Eigen::Matrix<double,dimension,d> cmpM;
380 cmpM.rightCols(d-1) = pM;
381 cmpM.leftCols(1) = DI*(Jx - mid).normalized();
382 double tmp = (evaluate_DJ(rel_map_id,x)*cmpM).determinant();
383 assert(std::abs(tmp) > 1e-10 &&
"Volume form is 0");
384 return (tmp > 0.)? 1 : -1;
387 assert(
false &&
"Point outside of element");
Manage topological relations between cells.
Definition: dcell.hpp:41
size_t get_id() const
Return the global index of the cell.
Definition: dcell.hpp:58
dCell_graph(size_t id, std::vector< size_t > const &map_ids)
Constructor for vertex (0-cell)
Definition: dcell.hpp:194
std::array< std::vector< dCell_graph >, dimension+1 > Collection
Type to store the topological data of every cell.
Definition: dcell.hpp:44
std::vector< size_t > const & get_relative_map(size_t dim) const
Return the index of the parametrization of the cell of dimension dim on the boundary,...
Definition: dcell.hpp:64
std::vector< size_t > const & get_map_ids() const
Return the id of the charts corresponding to its parametrizations.
Definition: dcell.hpp:60
size_t global_to_local(size_t d_boundary, size_t i_b) const
Return the index of the i_b d_boundary-cell relative to this cell.
Definition: dcell.hpp:235
std::vector< size_t > const & get_boundary(size_t dim) const
Return the global index of the cell of dimension dim on its boundary.
Definition: dcell.hpp:62
dCell_map(std::vector< Eigen::Vector< double, dimension >> const &coords)
Definition: dcell.hpp:177
Eigen::Vector< double, dimension > const & coord(size_t map_rel_id) const
Return the location of the vertex in a given chart.
Definition: dcell.hpp:180
Manage the geometry of a cell.
Definition: dcell.hpp:83
Eigen::Matrix< double, Dimension::ExtDim(l, d), Dimension::ExtDim(l, dimension)> evaluate_DI_p(size_t rel_map_id, Eigen::Vector< double, d > const &x) const
Compute the action of the pullback of l-forms by the parametrization.
Definition: dcell.hpp:341
int get_orientation(size_t rel_map_id, Eigen::Vector< double, dimension > const &x, Eigen::Matrix< double, dimension, d-1 > const &pM) const requires(d >1)
Return the relative orientation.
Definition: dcell.hpp:370
static constexpr size_t cell_dim
Dimension of the cell
Definition: dcell.hpp:86
double evaluate_poly_on_ref(Eigen::Vector< double, d > const &x, size_t i_pbasis, int r) const
Evaluate a scalar polynomial on the reference element.
Definition: dcell.hpp:294
Eigen::Matrix< double, d, dimension > evaluate_DJ(size_t rel_map_id, Eigen::Vector< double, dimension > const &x) const
Evaluate the differential of the inverse mapping.
Definition: dcell.hpp:326
Eigen::Vector< double, d > evaluate_J(size_t rel_map_id, Eigen::Vector< double, dimension > const &x) const
Evaluate the inverse mapping from the chart to the reference element.
Definition: dcell.hpp:277
dCell_map(Eigen::Vector< double, dimension > const ¢er_mass, Eigen::Matrix< double, dimension, d > const &flat_map, double diam, std::vector< Simplex< d >> const &triangulation)
Flat constructor.
Definition: dcell.hpp:248
Eigen::Matrix< double, Dimension::ExtDim(l, dimension), Dimension::ExtDim(l, d)> evaluate_DJ_p(size_t rel_map_id, Eigen::Vector< double, dimension > const &x) const
Compute the action of the pullback of l-forms by the inverse mapping.
Definition: dcell.hpp:356
std::vector< Simplex< d > > const & get_reference_elem() const
Return the reference element as a collection of simplexes.
Definition: dcell.hpp:108
Eigen::Vector< double, dimension > evaluate_I(size_t rel_map_id, Eigen::Vector< double, d > const &x) const
Evaluate the parametrization from the reference element to a chart.
Definition: dcell.hpp:262
double evaluate_poly_pullback(size_t rel_map_id, Eigen::Vector< double, dimension > const &x, size_t i_pbasis, int r) const
Evaluate the pullback of a scalar polynomial on the chart.
Definition: dcell.hpp:306
bool is_flat() const
Is the cell flat.
Definition: dcell.hpp:105
Eigen::Matrix< double, dimension, d > evaluate_DI(size_t rel_map_id, Eigen::Vector< double, d > const &x) const
Evaluate the differential of the parametrization.
Definition: dcell.hpp:312
dCell_map(std::vector< std::unique_ptr< ParametrizedMap< dimension, d >>> &maps, std::vector< std::unique_ptr< ParametrizedDerivedMap< dimension, d >>> &pullback_maps, std::vector< Simplex< d >> const &triangulation)
General constructor.
Definition: dcell.hpp:255
The methods in this file are meant to compute the action of everything that is independent of the atl...
Helpers to compute geometric quantities.
constexpr size_t ExtDim(size_t l, size_t d)
Dimension of the exterior algebra .
Definition: exterior_dimension.hpp:37
constexpr size_t PolyDim(int r, size_t d)
Dimension of .
Definition: exterior_dimension.hpp:43
requires(d > 0 &&d<=dimension) struct dCell_mass
Compute the mass matrices of a d-cell.
Definition: dcell_integral.hpp:17
Definition: maxwell.hpp:23
std::array< Eigen::Vector< double, d >, d+1 > Simplex
Array of d+1 points of .
Definition: definitions.hpp:16
static Eigen::Matrix< double, Dimension::ExtDim(l, d1), Dimension::ExtDim(l, d2)> compute(Eigen::MatrixBase< Derived > const &A)
Definition: exterior_algebra.hpp:211
static std::vector< std::array< size_t, d > > const & complete(const int r)
Basis of polynomial of at most degree r.
Definition: exterior_algebra.hpp:312
First order differentials of the parametrizations.
Definition: definitions.hpp:38
Used for the parametrization of the mesh elements.
Definition: definitions.hpp:23