24#ifndef VULPES_ASSEMBLE_CELL_MANAGER_HPP_
25#define VULPES_ASSEMBLE_CELL_MANAGER_HPP_
61template <
typename MeshType,
typename FeSpaceType>
64 using index_t =
typename MeshType::index_t;
66 static inline constexpr std::size_t
dim = MeshType::self_dim;
95 CellManager(
const MeshType& mesh,
const FeSpaceType& fe_space)
97 m_cells.resize(mesh.numCells());
103 m_mesh.getCellToFacetMap().data().size());
120 constexpr auto cell_options = FeType::cellInitOptions();
124 m_cells[cell_id] = std::make_unique<geometry::Cell<dim, double, index_t>>(
125 m_mesh, cell_id, cell_options);
129 auto& cell = *
m_cells[cell_id];
130 std::unique_ptr<MappingType> mapping;
132 mapping = std::make_unique<MappingType>(
134 mapping->transformInv_(cell.vtxs());
140 m_mappings[cell_id] = std::make_unique<MappingType>(
172 if (neigh_info.built) {
176 const auto glob_face_id =
m_mesh.getCellToFacetMap()[cell_id][loc_face_id];
178 const auto cell_ids =
m_mesh.getFacetToCellMap()[glob_face_id];
180 neigh_info.neigh_cell_id = cell_ids[(cell_ids[0] == cell_id)];
181 neigh_info.have_neigh =
182 (neigh_info.neigh_cell_id !=
static_cast<index_t>(-1));
183 if (neigh_info.have_neigh) {
185 const auto& dual_map =
m_mesh.getDualMap();
186 const auto neighs_begin = dual_map[cell_id].begin();
187 const auto neighs_end = dual_map[cell_id].end();
188 neigh_info.loc_neigh_cell_id = std::distance(
190 std::find(neighs_begin, neighs_end, neigh_info.neigh_cell_id));
191 assert(neigh_info.loc_neigh_cell_id < dual_map[cell_id].size());
192 const auto neigh_cell_to_facet =
193 m_mesh.getCellToFacetMap()[neigh_info.neigh_cell_id];
194 const auto loc_neigh_face_it = std::find(
195 neigh_cell_to_facet.begin(), neigh_cell_to_facet.end(), glob_face_id);
196 neigh_info.loc_neigh_face_id =
197 std::distance(neigh_cell_to_facet.begin(), loc_neigh_face_it);
198 assert(neigh_info.loc_neigh_face_id < neigh_cell_to_facet.size());
200 neigh_info.built =
true;
218 const auto& curr_cell =
m_cells[current_cell_id];
221 if (!curr_cell || !neigh_cell) {
222 return Eigen::Array<double, dim, 1>::Zero();
226 const auto& md =
m_mesh.getMetadata();
227 Eigen::Array<double, dim, 1> period = Eigen::Array<double, dim, 1>::Zero();
229 if (md.doubles.find(
"XPeriod") != md.doubles.end()) {
230 period[0] = md.doubles.at(
"XPeriod")[0];
232 if constexpr (
dim > 1) {
233 if (md.doubles.find(
"YPeriod") != md.doubles.end()) {
234 period[1] = md.doubles.at(
"YPeriod")[0];
237 if constexpr (
dim > 2) {
238 if (md.doubles.find(
"ZPeriod") != md.doubles.end()) {
239 throw std::logic_error(
"3D periodic conditions not yet implemented.");
245 curr_cell->bbox(), neigh_cell->bbox(), period);
253 std::vector<std::unique_ptr<CellType>>
m_cells;
static void stop(const char *label)
stop(label) when recording is on.
Definition profiler.hpp:90
static void start(const char *label)
start(label) when recording is on.
Definition profiler.hpp:84
std::decay_t< decltype(FeType::getMapping(CellType{}))> MappingType
Definition cell_manager.hpp:68
const auto & getCells() const
Access the underlying memory buffer for cells (some might be empty).
Definition cell_manager.hpp:158
std::vector< std::unique_ptr< MappingType > > m_mappings
Definition cell_manager.hpp:257
const auto & getFeSpace() const
Get the finite element space associated to this cell manager.
Definition cell_manager.hpp:107
geometry::Cell< dim, double, index_t > CellType
Definition cell_manager.hpp:67
const CellType & getCell(index_t cell_id)
Get and build lazily the cells of the mesh.
Definition cell_manager.hpp:118
datastructure::CrsMap< NeighInfo, index_t > m_cell_to_facet_neigh
Definition cell_manager.hpp:261
const FeType & m_fe_space
Definition cell_manager.hpp:250
std::vector< std::unique_ptr< CellType > > m_cells
Definition cell_manager.hpp:253
static constexpr std::size_t dim
Definition cell_manager.hpp:66
typename MeshType::index_t index_t
Definition cell_manager.hpp:64
Eigen::Array< double, MeshType::self_dim, 1 > getPeriodicShift(index_t neigh_cell_id, index_t current_cell_id) const
Get the periodic shift needed for neighbor cell coordinate transformation.
Definition cell_manager.hpp:216
const MeshType & m_mesh
Definition cell_manager.hpp:249
FeSpaceType FeType
Definition cell_manager.hpp:65
CellManager(const MeshType &mesh, const FeSpaceType &fe_space)
Construct a new Cell Manager object.
Definition cell_manager.hpp:95
std::vector< bool > m_cell_is_normalized
Definition cell_manager.hpp:255
const auto & getMapping(index_t cell_id) const
Get the geometrical mapping of the reference element to physical element.
Definition cell_manager.hpp:152
NeighInfo findCellNeigh(index_t cell_id, index_t loc_face_id)
Find the cell id of the neighbour of a cell given the face id in local cell enumeration.
Definition cell_manager.hpp:170
const auto & getMesh() const
Get the underlying mesh.
Definition cell_manager.hpp:110
Definition crs_map.hpp:72
Definition cell_manager.hpp:39
Eigen::Array< double, Dim, 1 > computePeriodicShift(const Eigen::Matrix< double, Dim, 2 > &curr_bbox, const Eigen::Matrix< double, Dim, 2 > &neigh_bbox, const Eigen::Array< double, Dim, 1 > &period)
Compute periodic shift between two cells based on bboxes.
Definition mapping.hpp:228
std::conditional_t< Dim==2, Cell2D< FloatType, IndexType >, Cell3D< FloatType, IndexType > > Cell
Definition cell.hpp:267
Definition cell_manager.hpp:38
Information about the neighbouring cell for a certain face.
Definition cell_manager.hpp:73
index_t neigh_cell_id
cell id of the neighbor in global cell enumeration, local MPI enumeration
Definition cell_manager.hpp:76
bool have_neigh
the currently considered face of the cell has a neigh (i.e. not boundary)
Definition cell_manager.hpp:85
bool built
this class instance has been built
Definition cell_manager.hpp:87
index_t loc_neigh_cell_id
cell id of the neighbor in local cell enumeration, ranges [0, num of cell neighs)
Definition cell_manager.hpp:79
index_t loc_neigh_face_id
face id of the cell currently considered in local cell enumeration
Definition cell_manager.hpp:82