17 #ifndef dealii_mesh_worker_mesh_loop_h 18 #define dealii_mesh_worker_mesh_loop_h 20 #include <deal.II/base/config.h> 22 #include <deal.II/base/template_constraints.h> 23 #include <deal.II/base/work_stream.h> 25 #include <deal.II/grid/filtered_iterator.h> 26 #include <deal.II/grid/tria.h> 28 #include <deal.II/meshworker/assemble_flags.h> 29 #include <deal.II/meshworker/dof_info.h> 30 #include <deal.II/meshworker/integration_info.h> 31 #include <deal.II/meshworker/local_integrator.h> 32 #include <deal.II/meshworker/loop.h> 36 DEAL_II_NAMESPACE_OPEN
118 template <
class CellIteratorType,
class ScratchData,
class CopyData>
121 const typename identity<CellIteratorType>::type &end,
123 const typename identity<std::function<
124 void(
const CellIteratorType &, ScratchData &, CopyData &)>>::type
126 const typename identity<std::function<
void(
const CopyData &)>>::type
129 const ScratchData &sample_scratch_data,
130 const CopyData & sample_copy_data,
134 const typename identity<std::function<
void(
const CellIteratorType &,
135 const unsigned int &,
138 &boundary_worker = std::function<
void(
const CellIteratorType &,
139 const unsigned int &,
143 const typename identity<std::function<
void(
const CellIteratorType &,
144 const unsigned int &,
145 const unsigned int &,
146 const CellIteratorType &,
147 const unsigned int &,
148 const unsigned int &,
151 &face_worker = std::function<
void(
const CellIteratorType &,
152 const unsigned int &,
153 const unsigned int &,
154 const CellIteratorType &,
155 const unsigned int &,
156 const unsigned int &,
161 const unsigned int chunk_size = 8)
166 "If you specify a cell_worker, you need to set assemble_own_cells or assemble_ghost_cells."));
173 "You can only specify assemble_own_interior_faces_once OR assemble_own_interior_faces_both."));
179 "You can only specify assemble_ghost_faces_once OR assemble_ghost_faces_both."));
185 "The option cells_after_faces only makes sense if you assemble on cells."));
189 "If you specify a face_worker, assemble_face_* needs to be set."));
194 "If you specify a boundary_worker, assemble_boundary_faces needs to be set."));
196 auto cell_action = [&](
const CellIteratorType &cell,
197 ScratchData & scratch,
201 copy = sample_copy_data;
203 const bool ignore_subdomain =
204 (cell->get_triangulation().locally_owned_subdomain() ==
208 (cell->is_level_cell() ? cell->level_subdomain_id() :
209 cell->subdomain_id());
211 const bool own_cell =
213 (current_subdomain_id ==
214 cell->get_triangulation().locally_owned_subdomain());
216 if ((!ignore_subdomain) &&
220 if (!(flags & (cells_after_faces)) &&
223 cell_worker(cell, scratch, copy);
226 for (
unsigned int face_no = 0;
227 face_no <
GeometryInfo<CellIteratorType::AccessorType::Container::
228 dimension>::faces_per_cell;
231 typename CellIteratorType::AccessorType::Container::face_iterator
232 face = cell->face(face_no);
233 if (cell->at_boundary(face_no) &&
234 !cell->has_periodic_neighbor(face_no))
237 if ((flags & assemble_boundary_faces) && own_cell)
238 boundary_worker(cell, face_no, scratch, copy);
244 cell->neighbor_or_periodic_neighbor(face_no);
248 if (neighbor->is_level_cell())
249 neighbor_subdomain_id = neighbor->level_subdomain_id();
251 else if (neighbor->active())
252 neighbor_subdomain_id = neighbor->subdomain_id();
254 const bool own_neighbor =
256 (neighbor_subdomain_id ==
257 cell->get_triangulation().locally_owned_subdomain());
260 if (!own_cell && !own_neighbor)
264 if (own_cell && own_neighbor &&
270 if (own_cell != own_neighbor &&
278 const bool periodic_neighbor =
279 cell->has_periodic_neighbor(face_no);
281 if ((!periodic_neighbor &&
282 cell->neighbor_is_coarser(face_no)) ||
283 (periodic_neighbor &&
284 cell->periodic_neighbor_is_coarser(face_no)))
294 const std::pair<unsigned int, unsigned int>
297 cell->periodic_neighbor_of_coarser_periodic_neighbor(
299 cell->neighbor_of_coarser_neighbor(face_no);
305 neighbor_face_no.first,
306 neighbor_face_no.second,
316 face_worker(neighbor,
317 neighbor_face_no.first,
318 neighbor_face_no.second,
331 neighbor->has_children())
335 Assert(cell->level() == neighbor->level(),
341 if (own_cell && own_neighbor &&
354 if (own_cell && !own_neighbor &&
356 (neighbor_subdomain_id < current_subdomain_id))
359 const unsigned int neighbor_face_no =
361 cell->periodic_neighbor_face_no(face_no) :
362 cell->neighbor_face_no(face_no);
363 Assert(periodic_neighbor ||
364 neighbor->face(neighbor_face_no) == face,
380 if ((flags & cells_after_faces) &&
383 cell_worker(cell, scratch, copy);
398 DEAL_II_NAMESPACE_CLOSE
static const unsigned int invalid_unsigned_int
void mesh_loop(const CellIteratorType &begin, const typename identity< CellIteratorType >::type &end, const typename identity< std::function< void(const CellIteratorType &, ScratchData &, CopyData &)>>::type &cell_worker, const typename identity< std::function< void(const CopyData &)>>::type &copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const AssembleFlags flags=assemble_own_cells, const typename identity< std::function< void(const CellIteratorType &, const unsigned int &, ScratchData &, CopyData &)>>::type &boundary_worker=std::function< void(const CellIteratorType &, const unsigned int &, ScratchData &, CopyData &)>(), const typename identity< std::function< void(const CellIteratorType &, const unsigned int &, const unsigned int &, const CellIteratorType &, const unsigned int &, const unsigned int &, ScratchData &, CopyData &)>>::type &face_worker=std::function< void(const CellIteratorType &, const unsigned int &, const unsigned int &, const CellIteratorType &, const unsigned int &, const unsigned int &, ScratchData &, CopyData &)>(), const unsigned int queue_length=2 *MultithreadInfo::n_threads(), const unsigned int chunk_size=8)
const types::subdomain_id invalid_subdomain_id
static::ExceptionBase & ExcMessage(std::string arg1)
unsigned int subdomain_id
#define Assert(cond, exc)
bool is_active_iterator(const DI &)
const types::subdomain_id artificial_subdomain_id
void run(const std::vector< std::vector< Iterator >> &colored_iterators, Worker worker, Copier copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const unsigned int queue_length=2 *MultithreadInfo::n_threads(), const unsigned int chunk_size=8)
static unsigned int n_threads()
void cell_action(ITERATOR cell, DoFInfoBox< dim, DOFINFO > &dof_info, INFOBOX &info, const std::function< void(DOFINFO &, typename INFOBOX::CellInfo &)> &cell_worker, const std::function< void(DOFINFO &, typename INFOBOX::CellInfo &)> &boundary_worker, const std::function< void(DOFINFO &, DOFINFO &, typename INFOBOX::CellInfo &, typename INFOBOX::CellInfo &)> &face_worker, const LoopControl &loop_control)
static::ExceptionBase & ExcInternalError()