From d5352c0eece6ed55b84ae3c50823b9d2b8f5dfd7 Mon Sep 17 00:00:00 2001 From: David Wells Date: Sat, 21 May 2022 15:29:18 -0400 Subject: [PATCH] Move the initialize function to the base class. --- include/deal.II/base/function_parser.h | 4 +- include/deal.II/base/mu_parser_internal.h | 12 +++-- include/deal.II/base/tensor_function_parser.h | 4 +- source/base/function_parser.cc | 34 +------------- source/base/mu_parser_internal.cc | 39 ++++++++++++++++ source/base/tensor_function_parser.cc | 45 +------------------ 6 files changed, 55 insertions(+), 83 deletions(-) diff --git a/include/deal.II/base/function_parser.h b/include/deal.II/base/function_parser.h index 4564072f3e..cf77606c79 100644 --- a/include/deal.II/base/function_parser.h +++ b/include/deal.II/base/function_parser.h @@ -308,11 +308,11 @@ public: * this case is dim+1. The value of this parameter defaults to false, i.e., * do not consider time. */ - void + virtual void initialize(const std::string & vars, const std::vector &expressions, const ConstMap & constants, - const bool time_dependent = false); + const bool time_dependent = false) override; /** * Initialize the function. Same as above, but accepts a string rather than diff --git a/include/deal.II/base/mu_parser_internal.h b/include/deal.II/base/mu_parser_internal.h index 562cc6025e..040a494152 100644 --- a/include/deal.II/base/mu_parser_internal.h +++ b/include/deal.II/base/mu_parser_internal.h @@ -164,11 +164,15 @@ namespace internal {} /** - * The muParser objects (hidden with the PIMPL idiom) for each thread (and - * one for each component). + * Initialize the internal state of the object. This is the same as the + * inheriting class method - see FunctionParser::initialize() for more + * information. */ - mutable Threads::ThreadLocalStorage - parser_data; + virtual void + initialize(const std::string & vars, + const std::vector & expressions, + const std::map &constants, + const bool time_dependent = false); void init_muparser() const; diff --git a/include/deal.II/base/tensor_function_parser.h b/include/deal.II/base/tensor_function_parser.h index 1045c106ff..93d9c84e85 100644 --- a/include/deal.II/base/tensor_function_parser.h +++ b/include/deal.II/base/tensor_function_parser.h @@ -196,11 +196,11 @@ public: * method in this case is dim+1. The value of this parameter defaults to * false, i.e. do not consider time. */ - void + virtual void initialize(const std::string & vars, const std::vector &expressions, const ConstMap & constants, - const bool time_dependent = false); + const bool time_dependent = false) override; /** * Initialize the function. Same as above, but accepts a string rather than diff --git a/source/base/function_parser.cc b/source/base/function_parser.cc index 13c0812bb0..bec8278c52 100644 --- a/source/base/function_parser.cc +++ b/source/base/function_parser.cc @@ -17,12 +17,10 @@ #include #include #include -#include #include #include -#include #include DEAL_II_NAMESPACE_OPEN @@ -78,38 +76,10 @@ FunctionParser::initialize(const std::string & variables, const std::map &constants, const bool time_dependent) { - this->parser_data.clear(); // this will reset all thread-local objects - - this->constants = constants; - this->var_names = Utilities::split_string_list(variables, ','); - this->expressions = expressions; - AssertThrow(((time_dependent) ? dim + 1 : dim) == this->var_names.size(), - ExcMessage("Wrong number of variables")); - - // We check that the number of components of this function matches the - // number of components passed in as a vector of strings. AssertThrow(this->n_components == expressions.size(), ExcInvalidExpressionSize(this->n_components, expressions.size())); - - // Now we define how many variables we expect to read in. We distinguish - // between two cases: Time dependent problems, and not time dependent - // problems. In the first case the number of variables is given by the - // dimension plus one. In the other case, the number of variables is equal - // to the dimension. Once we parsed the variables string, if none of this is - // the case, then an exception is thrown. - if (time_dependent) - this->n_vars = dim + 1; - else - this->n_vars = dim; - - // create a parser object for the current thread we can then query in - // value() and vector_value(). this is not strictly necessary because a user - // may never call these functions on the current thread, but it gets us - // error messages about wrong formulas right away - this->init_muparser(); - - // finally set the initialization bit - this->initialized = true; + internal::FunctionParser::ParserImplementation::initialize( + variables, expressions, constants, time_dependent); } diff --git a/source/base/mu_parser_internal.cc b/source/base/mu_parser_internal.cc index 93c6470bec..07bf42886c 100644 --- a/source/base/mu_parser_internal.cc +++ b/source/base/mu_parser_internal.cc @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -223,6 +224,44 @@ namespace internal + + template + void + ParserImplementation::initialize( + const std::string & variables, + const std::vector & expressions, + const std::map &constants, + const bool time_dependent) + { + this->parser_data.clear(); // this will reset all thread-local objects + + this->constants = constants; + this->var_names = Utilities::split_string_list(variables, ','); + this->expressions = expressions; + AssertThrow(((time_dependent) ? dim + 1 : dim) == this->var_names.size(), + ExcMessage("Wrong number of variables")); + + // Now we define how many variables we expect to read in. We distinguish + // between two cases: Time dependent problems, and not time dependent + // problems. In the first case the number of variables is given by the + // dimension plus one. In the other case, the number of variables is equal + // to the dimension. Once we parsed the variables string, if none of this + // is the case, then an exception is thrown. + if (time_dependent) + this->n_vars = dim + 1; + else + this->n_vars = dim; + + // create a parser object for the current thread we can then query in + // value() and vector_value(). this is not strictly necessary because a + // user may never call these functions on the current thread, but it gets + // us error messages about wrong formulas right away + this->init_muparser(); + this->initialized = true; + } + + + template void ParserImplementation::init_muparser() const diff --git a/source/base/tensor_function_parser.cc b/source/base/tensor_function_parser.cc index 1584d369ff..08230dca19 100644 --- a/source/base/tensor_function_parser.cc +++ b/source/base/tensor_function_parser.cc @@ -20,10 +20,8 @@ #include #include #include -#include #include -#include #include DEAL_II_NAMESPACE_OPEN @@ -79,49 +77,10 @@ TensorFunctionParser::initialize( const std::map &constants, const bool time_dependent) { - this->parser_data.clear(); // this will reset all thread-local objects - - this->constants = constants; - this->var_names = Utilities::split_string_list(variables, ','); - this->expressions = expressions; - AssertThrow(((time_dependent) ? dim + 1 : dim) == this->var_names.size(), - ExcMessage("Wrong number of variables")); - - // We check that the number of - // components of this function - // matches the number of components - // passed in as a vector of - // strings. AssertThrow(this->n_components == expressions.size(), ExcInvalidExpressionSize(this->n_components, expressions.size())); - - // Now we define how many variables - // we expect to read in. We - // distinguish between two cases: - // Time dependent problems, and not - // time dependent problems. In the - // first case the number of - // variables is given by the - // dimension plus one. In the other - // case, the number of variables is - // equal to the dimension. Once we - // parsed the variables string, if - // none of this is the case, then - // an exception is thrown. - if (time_dependent) - this->n_vars = dim + 1; - else - this->n_vars = dim; - - // create a parser object for the current thread we can then query - // in value() and vector_value(). this is not strictly necessary - // because a user may never call these functions on the current - // thread, but it gets us error messages about wrong formulas right - // away - this->init_muparser(); - - // finally set the initialization bit - this->initialized = true; + internal::FunctionParser::ParserImplementation::initialize( + variables, expressions, constants, time_dependent); } -- 2.39.5