]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add initialization of MappingQCache by a lambda
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Thu, 14 Nov 2019 09:22:06 +0000 (10:22 +0100)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Thu, 14 Nov 2019 09:33:11 +0000 (10:33 +0100)
include/deal.II/fe/mapping_q_cache.h
source/fe/mapping_q_cache.cc

index 6f1a4225e9a8237d19c652e8d6fac3f2ea15bec1..4d9bf652d50eca00607fbedb2a91f770b45b615d 100644 (file)
@@ -86,6 +86,33 @@ public:
   initialize(const Triangulation<dim, spacedim> &  triangulation,
              const MappingQGeneric<dim, spacedim> &mapping);
 
+  /**
+   * Initialize the data cache by letting the function given as an argument
+   * provide the mapping support points for all cells (on all levels) of the
+   * given triangulation. The function must return a vector of
+   * `Point<spacedim>` whose length is the same as the size of the polynomial
+   * space, $(p+1)^\text{dim}$, where $p$ is the polynomial degree of the
+   * mapping, and it must be in the order the mapping or FE_Q sort their
+   * points, i.e., all $2^\text{dim}$ vertex points first, then the points on
+   * the lines, quads, and hexes according to the usual hierarchical
+   * numbering. No attempt is made to validate these points internally, except
+   * for the number of given points.
+   *
+   * @note If multiple threads are enabled, this function will run in
+   * parallel, invoking the function passed in several times. Thus, in case
+   * MultithreadInfo::n_threads()>1, the user code must make sure that the
+   * function, typically a lambda, does not write into data shared with other
+   * threads.
+   *
+   * @note The cache is invalidated upon the signal
+   * Triangulation::Signals::any_change of the underlying triangulation.
+   */
+  void
+  initialize(const Triangulation<dim, spacedim> &triangulation,
+             const std::function<std::vector<Point<spacedim>>(
+               const typename Triangulation<dim, spacedim>::cell_iterator &)>
+               &compute_points_on_cell);
+
   /**
    * Return the memory consumption (in bytes) of the cache.
    */
index 9c7cae10e6e75de61d9dd18f9fe41b1494b576ef..9f95efb1c6defe361682b2543692d7abbbf45d92 100644 (file)
@@ -77,7 +77,23 @@ MappingQCache<dim, spacedim>::initialize(
   const MappingQGeneric<dim, spacedim> &mapping)
 {
   AssertDimension(this->get_degree(), mapping.get_degree());
+  initialize(triangulation,
+             [&mapping](const typename Triangulation<dim>::cell_iterator &cell)
+               -> std::vector<Point<spacedim>> {
+               return mapping.compute_mapping_support_points(cell);
+             });
+}
+
 
+
+template <int dim, int spacedim>
+void
+MappingQCache<dim, spacedim>::initialize(
+  const Triangulation<dim, spacedim> &triangulation,
+  const std::function<std::vector<Point<spacedim>>(
+    const typename Triangulation<dim, spacedim>::cell_iterator &)>
+    &compute_points_on_cell)
+{
   clear_signal = triangulation.signals.any_change.connect(
     [&]() -> void { this->support_point_cache.reset(); });
 
@@ -94,7 +110,10 @@ MappingQCache<dim, spacedim>::initialize(
         void *,
         void *) {
       (*support_point_cache)[cell->level()][cell->index()] =
-        mapping.compute_mapping_support_points(cell);
+        compute_points_on_cell(cell);
+      AssertDimension(
+        (*support_point_cache)[cell->level()][cell->index()].size(),
+        Utilities::pow(this->get_degree() + 1, dim));
     },
     /* copier */ std::function<void(void *)>(),
     /* scratch_data */ nullptr,

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.