From 63e78893944d883ff9db82c6a4366827815cb9bc Mon Sep 17 00:00:00 2001 From: wolf Date: Thu, 30 Jun 2005 16:23:04 +0000 Subject: [PATCH] Rework: bring up to our coding standards. git-svn-id: https://svn.dealii.org/trunk@11002 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/source/function_parser.cc | 194 +++++++++++++++---------- 1 file changed, 116 insertions(+), 78 deletions(-) diff --git a/deal.II/base/source/function_parser.cc b/deal.II/base/source/function_parser.cc index 7d7497c583..5e851707e2 100644 --- a/deal.II/base/source/function_parser.cc +++ b/deal.II/base/source/function_parser.cc @@ -53,6 +53,7 @@ unsigned int SplitString(const std::string& input, } + template FunctionParser::FunctionParser(const unsigned int n_components, const double initial_time) @@ -63,138 +64,175 @@ FunctionParser::FunctionParser(const unsigned int n_components, fp = new fparser::FunctionParser[n_components]; } + + template FunctionParser::~FunctionParser() { delete[] fp; } + #ifndef DEAL_II_DISABLE_PARSER template -void FunctionParser::initialize(const std::string variables, - const std::vector expressions, - std::map constants, - bool time_dependent, - bool use_degrees) +void FunctionParser::initialize (const std::string variables, + const std::vector expressions, + const std::map constants, + const bool time_dependent, + const bool use_degrees) { - // We check that the number of components of this function matches - // the number of components passed in as a vector of strings. + // 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()) ); - for (unsigned int i=0; in_components; ++i) { - // Add the variuous constants to the parser. - std::map< std::string, double >::const_iterator - constant = constants.begin(), - endc = constants.end(); - for(;constant != endc; ++constant) { - AssertThrow( fp[i].AddConstant(constant->first, constant->second), - ExcMessage("Invalid Constant Name")); - } + for (unsigned int i=0; in_components; ++i) + { + // Add the various constants to + // the parser. + std::map< std::string, double >::const_iterator + constant = constants.begin(), + endc = constants.end(); + for(; constant != endc; ++constant) + { + const bool success = fp[i].AddConstant(constant->first, constant->second); + AssertThrow (success, ExcMessage("Invalid Constant Name")); + } + const int ret_value = fp[i].Parse(expressions[i], + variables, + use_degrees); + AssertThrow (ret_value == -1, + ExcParseError(ret_value, fp[i].ErrorMsg())); - int ret_value = fp[i].Parse(expressions[i], - variables, - use_degrees); - AssertThrow(ret_value == -1, - ExcParseError(ret_value, fp[i].ErrorMsg())); - - // The fact that the parser did not throw an error does not mean - // that everything went ok... we can still have problems with the - // number of variables... - } + // The fact that the parser did + // not throw an error does not + // mean that everything went + // ok... we can still have + // problems with the 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. + // 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) n_vars = dim+1; else n_vars = dim; - // Let's check if the number of variables is correct... - AssertThrow(n_vars == fp[0].NVars(), - ExcDimensionMismatch(n_vars,fp[0].NVars())); + // Let's check if the number of + // variables is correct... + AssertThrow (n_vars == fp[0].NVars(), + ExcDimensionMismatch(n_vars,fp[0].NVars())); - // Now set the initialization bit. + // Now set the initialization bit. initialized = true; } + template -void FunctionParser::initialize(const std::string variables, - const std::string expression, - std::map constants, - bool time_dependent, - bool use_degrees) +void FunctionParser::initialize (const std::string variables, + const std::string expression, + const std::map constants, + const bool time_dependent, + const bool use_degrees) { - // Start up with an empty vector of expressions. + // Start up with an empty vector of + // expressions. std::vector expressions; - // In this case a vector function is built with the number of - // components found between the separators ';' - SplitString(expression, ";", expressions); - // Now initialize with the things we got. - initialize - (variables, expressions, constants, time_dependent, use_degrees); + // In this case a vector function + // is built with the number of + // components found between the + // separators ';' + SplitString (expression, ";", expressions); + // Now initialize with the things + // we got. + initialize (variables, expressions, constants, + time_dependent, use_degrees); } + + template -double FunctionParser::value (const Point &p, - unsigned int component) const +double FunctionParser::value (const Point &p, + const unsigned int component) const { - AssertThrow(initialized==true, ExcNotInitialized()); - AssertThrow(component < this->n_components, - ExcIndexRange(component, 0, this->n_components)); - // Statically allocates dim+1 double variables. + Assert (initialized==true, ExcNotInitialized()); + Assert (component < this->n_components, + ExcIndexRange(component, 0, this->n_components)); + + // Statically allocate dim+1 + // double variables. double vars[dim+1]; - for(unsigned int i=0; iget_time(); double my_value = fp[component].Eval(vars); - AssertThrow(fp[component].EvalError() == 0, - ExcMessage(fp[component].ErrorMsg())); + AssertThrow (fp[component].EvalError() == 0, + ExcMessage(fp[component].ErrorMsg())); return my_value; } + template void FunctionParser::vector_value (const Point &p, Vector &values) const { - AssertThrow(initialized==true, ExcNotInitialized()); - AssertThrow(values.size() == this->n_components, - ExcDimensionMismatch (values.size(), this->n_components)); - // Statically allocates dim+1 double variables. - double vars[dim+1]; + Assert (initialized==true, ExcNotInitialized()); + Assert (values.size() == this->n_components, + ExcDimensionMismatch (values.size(), this->n_components)); + + // Statically allocates dim+1 + // double variables. + double vars[dim+1]; - for(unsigned int i=0; iget_time(); + // We need the time variable only + // if the number of variables is + // different from the dimension. In + // this case it can only be dim+1, + // otherwise an exception would + // have already been thrown + if(dim != n_vars) + vars[dim] = this->get_time(); - for(unsigned int component = 0; component < this->n_components; - ++component) { + for(unsigned int component = 0; component < this->n_components; + ++component) + { values(component) = fp[component].Eval(vars); - Assert(fp[component].EvalError() == 0, - ExcMessage(fp[component].ErrorMsg())); + AssertThrow(fp[component].EvalError() == 0, + ExcMessage(fp[component].ErrorMsg())); } } -- 2.39.5