]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Move FunctionParser's thread-local data into a base class.
authorDavid Wells <drwells@email.unc.edu>
Sat, 21 May 2022 03:43:45 +0000 (23:43 -0400)
committerDavid Wells <drwells@email.unc.edu>
Sat, 21 May 2022 19:45:42 +0000 (15:45 -0400)
include/deal.II/base/function_parser.h
include/deal.II/base/mu_parser_internal.h
include/deal.II/base/tensor_function_parser.h
source/base/function_parser.cc
source/base/tensor_function_parser.cc

index da8d955e58d6ceedcfad323b5586877b94df37bb..05c81c7a235146251af50174abae43a47b9ff84b 100644 (file)
 
 #include <deal.II/base/auto_derivative_function.h>
 #include <deal.II/base/exceptions.h>
+#include <deal.II/base/mu_parser_internal.h>
 #include <deal.II/base/point.h>
 #include <deal.II/base/tensor.h>
-#include <deal.II/base/thread_local_storage.h>
-#include <deal.II/base/mu_parser_internal.h>
 
 #include <map>
-#include <memory>
 #include <vector>
 
 DEAL_II_NAMESPACE_OPEN
@@ -216,7 +214,9 @@ class Vector;
  * @ingroup functions
  */
 template <int dim>
-class FunctionParser : public AutoDerivativeFunction<dim>
+class FunctionParser
+  : public AutoDerivativeFunction<dim>,
+    protected internal::FunctionParser::ParserImplementation<dim, double>
 {
 public:
   /**
@@ -381,13 +381,6 @@ public:
   //@}
 
 private:
-  /**
-   * The muParser objects (hidden with the PIMPL idiom) for each thread (and one
-   * for each component).
-   */
-  mutable Threads::ThreadLocalStorage<internal::FunctionParser::ParserData>
-    parser_data;
-
   /**
    * An array to keep track of all the constants, required to initialize fp in
    * each thread.
index 76a567b897d6f9efc5899ab5121b4e21808f6d8f..39ffa8c098ecae3dce289e79522e5a1e7231c3ee 100644 (file)
@@ -21,6 +21,9 @@
 
 #include <deal.II/base/config.h>
 
+#include <deal.II/base/thread_local_storage.h>
+
+#include <memory>
 #include <string>
 #include <vector>
 
@@ -85,6 +88,18 @@ namespace internal
       std::vector<std::unique_ptr<muParserBase>> parsers;
     };
 
+    template <int dim, typename Number>
+    class ParserImplementation
+    {
+    public:
+      /**
+       * The muParser objects (hidden with the PIMPL idiom) for each thread (and
+       * one for each component).
+       */
+      mutable Threads::ThreadLocalStorage<internal::FunctionParser::ParserData>
+        parser_data;
+    };
+
     int
     mu_round(double val);
 
index eba3e486e56e04377754231d413d95a9c34cbbd1..568febb6b214d3ebb86b6e3d7ccc5ef7ca7135a4 100644 (file)
 
 #include <deal.II/base/exceptions.h>
 #include <deal.II/base/function_parser.h>
+#include <deal.II/base/mu_parser_internal.h>
 #include <deal.II/base/point.h>
 #include <deal.II/base/tensor.h>
 #include <deal.II/base/tensor_function.h>
-#include <deal.II/base/thread_local_storage.h>
-#include <deal.II/base/mu_parser_internal.h>
 
 #include <map>
-#include <memory>
 #include <vector>
 
 DEAL_II_NAMESPACE_OPEN
@@ -105,7 +103,9 @@ class Vector;
  * @ingroup functions
  */
 template <int rank, int dim, typename Number = double>
-class TensorFunctionParser : public TensorFunction<rank, dim, Number>
+class TensorFunctionParser
+  : public TensorFunction<rank, dim, Number>,
+    protected internal::FunctionParser::ParserImplementation<dim, Number>
 {
 public:
   /**
@@ -263,13 +263,6 @@ public:
   //@}
 
 private:
-  /**
-   * The muParser objects (hidden with the PIMPL idiom) for each thread (and one
-   * for each component).
-   */
-  mutable Threads::ThreadLocalStorage<internal::FunctionParser::ParserData>
-    parser_data;
-
   /**
    * An array to keep track of all the constants, required to initialize tfp in
    * each thread.
index ea1c952ad5cf77ab84df3e2f34527bd050304a54..09037c51eba9327060f3de81ff11b35940c235e2 100644 (file)
@@ -158,7 +158,7 @@ FunctionParser<dim>::init_muparser() const
   // check that we have not already initialized the parser on the
   // current thread, i.e., that the current function is only called
   // once per thread
-  internal::FunctionParser::ParserData &data = parser_data.get();
+  internal::FunctionParser::ParserData &data = this->parser_data.get();
   Assert(data.parsers.size() == 0 && data.vars.size() == 0, ExcInternalError());
 
   // initialize the objects for the current thread
@@ -280,7 +280,7 @@ FunctionParser<dim>::value(const Point<dim> & p,
   AssertIndexRange(component, this->n_components);
 
   // initialize the parser if that hasn't happened yet on the current thread
-  internal::FunctionParser::ParserData &data = parser_data.get();
+  internal::FunctionParser::ParserData &data = this->parser_data.get();
   if (data.vars.size() == 0)
     init_muparser();
 
@@ -327,7 +327,7 @@ FunctionParser<dim>::vector_value(const Point<dim> &p,
 
 
   // initialize the parser if that hasn't happened yet on the current thread
-  internal::FunctionParser::ParserData &data = parser_data.get();
+  internal::FunctionParser::ParserData &data = this->parser_data.get();
   if (data.vars.size() == 0)
     init_muparser();
 
index 1402675a9e11ce92968e259ad60ce79a71f30286..6396a0062e1be97fc6954a35c55ebd5d70d8074d 100644 (file)
@@ -173,7 +173,7 @@ TensorFunctionParser<rank, dim, Number>::init_muparser() const
   // check that we have not already initialized the parser on the
   // current thread, i.e., that the current function is only called
   // once per thread
-  internal::FunctionParser::ParserData &data = parser_data.get();
+  internal::FunctionParser::ParserData &data = this->parser_data.get();
   Assert(data.parsers.size() == 0 && data.vars.size() == 0, ExcInternalError());
 
   // initialize the objects for the current thread
@@ -294,7 +294,7 @@ TensorFunctionParser<rank, dim, Number>::value(const Point<dim> &p) const
   Assert(initialized == true, ExcNotInitialized());
 
   // initialize the parser if that hasn't happened yet on the current thread
-  internal::FunctionParser::ParserData &data = parser_data.get();
+  internal::FunctionParser::ParserData &data = this->parser_data.get();
   if (data.vars.size() == 0)
     init_muparser();
 

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.