From 75989212813bacd1ab274dc7ef50fca44e36255a Mon Sep 17 00:00:00 2001 From: David Wells Date: Fri, 20 May 2022 23:23:13 -0400 Subject: [PATCH] Add a new muParser function base class. --- include/deal.II/base/function_parser.h | 57 +------------------ include/deal.II/base/mu_parser_internal.h | 50 ++++++++++++++++ include/deal.II/base/tensor_function_parser.h | 41 +------------ source/base/function_parser.cc | 8 +-- source/base/tensor_function_parser.cc | 6 +- 5 files changed, 63 insertions(+), 99 deletions(-) diff --git a/include/deal.II/base/function_parser.h b/include/deal.II/base/function_parser.h index 2e0934baf4..da8d955e58 100644 --- a/include/deal.II/base/function_parser.h +++ b/include/deal.II/base/function_parser.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -37,22 +38,6 @@ template class Vector; #endif -namespace internal -{ - /** - * deal.II uses muParser as a purely internal dependency. To this end, we do - * not include any muParser headers in this file (and the bundled version of - * the dependency does not install its headers or compile a separate muparser - * library). Hence, to interface with muParser, we use the PIMPL idiom here to - * wrap a pointer to mu::Parser objects. - */ - class muParserBase - { - public: - virtual ~muParserBase() = default; - }; -} // namespace internal - /** * This class implements a function object that gets its value by parsing a * string describing this function. It is a wrapper class for the muparser @@ -396,48 +381,12 @@ public: //@} private: - /** - * Class containing the mutable state required by muParser. - * - * @note For performance reasons it is best to put all mutable state in a - * single object so that, for each function call, we only need to get - * thread-local data exactly once. - */ - struct ParserData - { - /** - * Default constructor. Threads::ThreadLocalStorage requires that objects be - * either default- or copy-constructible: make sure we satisfy the first - * case by declaring it here. - */ - ParserData() = default; - - /** - * std::is_copy_constructible gives the wrong answer for containers with - * non-copy constructible types (e.g., std::vector>) - - * for more information, see the documentation of - * Threads::ThreadLocalStorage. Hence, to avoid compilation failures, just - * delete the copy constructor completely. - */ - ParserData(const ParserData &) = delete; - - /** - * Scratch array used to set independent variables (i.e., x, y, and t) - * before each muParser call. - */ - std::vector vars; - - /** - * The actual muParser parser objects (hidden with PIMPL). - */ - std::vector> parsers; - }; - /** * The muParser objects (hidden with the PIMPL idiom) for each thread (and one * for each component). */ - mutable Threads::ThreadLocalStorage parser_data; + mutable Threads::ThreadLocalStorage + parser_data; /** * An array to keep track of all the constants, required to initialize fp in diff --git a/include/deal.II/base/mu_parser_internal.h b/include/deal.II/base/mu_parser_internal.h index d068ccd895..46a7d6c77c 100644 --- a/include/deal.II/base/mu_parser_internal.h +++ b/include/deal.II/base/mu_parser_internal.h @@ -35,6 +35,56 @@ namespace internal { namespace FunctionParser { + /** + * deal.II uses muParser as a purely internal dependency. To this end, we do + * not include any muParser headers in our own headers (and the bundled + * version of the dependency does not install its headers or compile a + * separate muparser library). Hence, to interface with muParser, we use the + * PIMPL idiom here to wrap a pointer to mu::Parser objects. + */ + class muParserBase + { + public: + virtual ~muParserBase() = default; + }; + + /** + * Class containing the mutable state required by muParser. + * + * @note For performance reasons it is best to put all mutable state in a + * single object so that, for each function call, we only need to get + * thread-local data exactly once. + */ + struct ParserData + { + /** + * Default constructor. Threads::ThreadLocalStorage requires that objects + * be either default- or copy-constructible: make sure we satisfy the + * first case by declaring it here. + */ + ParserData() = default; + + /** + * std::is_copy_constructible gives the wrong answer for containers with + * non-copy constructible types (e.g., std::vector>) + * - for more information, see the documentation of + * Threads::ThreadLocalStorage. Hence, to avoid compilation failures, just + * delete the copy constructor completely. + */ + ParserData(const ParserData &) = delete; + + /** + * Scratch array used to set independent variables (i.e., x, y, and t) + * before each muParser call. + */ + std::vector vars; + + /** + * The actual muParser parser objects (hidden with PIMPL). + */ + std::vector> parsers; + }; + int mu_round(double val); diff --git a/include/deal.II/base/tensor_function_parser.h b/include/deal.II/base/tensor_function_parser.h index d86377ee44..eba3e486e5 100644 --- a/include/deal.II/base/tensor_function_parser.h +++ b/include/deal.II/base/tensor_function_parser.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -262,48 +263,12 @@ public: //@} private: - /** - * Class containing the mutable state required by muParser. - * - * @note For performance reasons it is best to put all mutable state in a - * single object so that, for each function call, we only need to get - * thread-local data exactly once. - */ - struct ParserData - { - /** - * Default constructor. Threads::ThreadLocalStorage requires that objects be - * either default- or copy-constructible: make sure we satisfy the first - * case by declaring it here. - */ - ParserData() = default; - - /** - * std::is_copy_constructible gives the wrong answer for containers with - * non-copy constructible types (e.g., std::vector>) - - * for more information, see the documentation of - * Threads::ThreadLocalStorage. Hence, to avoid compilation failures, just - * delete the copy constructor completely. - */ - ParserData(const ParserData &) = delete; - - /** - * Scratch array used to set independent variables (i.e., x, y, and t) - * before each muParser call. - */ - std::vector vars; - - /** - * The actual muParser parser objects (hidden with PIMPL). - */ - std::vector> parsers; - }; - /** * The muParser objects (hidden with the PIMPL idiom) for each thread (and one * for each component). */ - mutable Threads::ThreadLocalStorage parser_data; + mutable Threads::ThreadLocalStorage + parser_data; /** * An array to keep track of all the constants, required to initialize tfp in diff --git a/source/base/function_parser.cc b/source/base/function_parser.cc index 973bb569d3..c45d69f70f 100644 --- a/source/base/function_parser.cc +++ b/source/base/function_parser.cc @@ -130,7 +130,7 @@ namespace internal /** * PIMPL for mu::Parser. */ - class Parser : public internal::muParserBase + class Parser : public internal::FunctionParser::muParserBase { public: operator mu::Parser &() @@ -158,7 +158,7 @@ FunctionParser::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 - ParserData &data = parser_data.get(); + internal::FunctionParser::ParserData &data = 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::value(const Point & p, AssertIndexRange(component, this->n_components); // initialize the parser if that hasn't happened yet on the current thread - ParserData &data = parser_data.get(); + internal::FunctionParser::ParserData &data = parser_data.get(); if (data.vars.size() == 0) init_muparser(); @@ -327,7 +327,7 @@ FunctionParser::vector_value(const Point &p, // initialize the parser if that hasn't happened yet on the current thread - ParserData &data = parser_data.get(); + internal::FunctionParser::ParserData &data = parser_data.get(); if (data.vars.size() == 0) init_muparser(); diff --git a/source/base/tensor_function_parser.cc b/source/base/tensor_function_parser.cc index c6d6aa0fdd..2447d7b501 100644 --- a/source/base/tensor_function_parser.cc +++ b/source/base/tensor_function_parser.cc @@ -144,7 +144,7 @@ namespace internal /** * PIMPL for mu::Parser. */ - class Parser : public internal::muParserBase + class Parser : public internal::FunctionParser::muParserBase { public: operator mu::Parser &() @@ -173,7 +173,7 @@ TensorFunctionParser::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 - ParserData &data = parser_data.get(); + internal::FunctionParser::ParserData &data = 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::value(const Point &p) const Assert(initialized == true, ExcNotInitialized()); // initialize the parser if that hasn't happened yet on the current thread - ParserData &data = parser_data.get(); + internal::FunctionParser::ParserData &data = parser_data.get(); if (data.vars.size() == 0) init_muparser(); -- 2.39.5