Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
function_parser.h
1 // ---------------------------------------------------------------------
2 // @f$Id: function_parser.h 31887 2013-12-04 21:03:24Z heister @f$
3 //
4 // Copyright (C) 2005 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__function_parser_h
18 #define __deal2__function_parser_h
19 
20 
21 #include <deal.II/base/config.h>
23 #include <deal.II/base/function.h>
24 #include <deal.II/base/tensor.h>
25 #include <deal.II/base/point.h>
26 #include <vector>
27 #include <map>
28 
29 namespace fparser
30 {
31  class FunctionParser;
32 }
33 
35 
36 
37 template <typename> class Vector;
38 
39 
317 template <int dim>
318 class FunctionParser : public Function<dim>
319 {
320 public:
335  FunctionParser (const unsigned int n_components = 1,
336  const double initial_time = 0.0);
337 
344  ~FunctionParser();
345 
351  typedef std::map<std::string, double> ConstMap;
352 
358  typedef ConstMap::iterator ConstMapIterator;
359 
426  void initialize (const std::string &vars,
427  const std::vector<std::string> &expressions,
428  const ConstMap &constants,
429  const bool time_dependent = false,
430  const bool use_degrees = false);
431 
432 
445  void initialize (const std::string &vars,
446  const std::vector<std::string> &expressions,
447  const ConstMap &constants,
448  const ConstMap &units,
449  const bool time_dependent = false,
450  const bool use_degrees = false);
451 
464  void initialize (const std::string &vars,
465  const std::string &expression,
466  const ConstMap &constants,
467  const bool time_dependent = false,
468  const bool use_degrees = false);
469 
475  void initialize (const std::string &vars,
476  const std::string &expression,
477  const ConstMap &constants,
478  const ConstMap &units,
479  const bool time_dependent = false,
480  const bool use_degrees = false);
481 
491  static
492  std::string
494 
506  virtual double value (const Point<dim> &p,
507  const unsigned int component = 0) const;
508 
518  virtual void vector_value (const Point<dim> &p,
519  Vector<double> &values) const;
520 
523  DeclException2 (ExcParseError,
524  int, char *,
525  << "Parsing Error at Column " << arg1
526  << ". The parser said: " << arg2);
527 
528  DeclException2 (ExcInvalidExpressionSize,
529  int, int,
530  << "The number of components (" << arg1
531  << ") is not equal to the number of expressions ("
532  << arg2 << ").");
533 
535 private:
544  fparser::FunctionParser *fp;
545 
554 
569  unsigned int n_vars;
570 };
571 
572 
573 template <int dim>
574 std::string
576 {
577  switch (dim)
578  {
579  case 1:
580  return "x";
581  case 2:
582  return "x,y";
583  case 3:
584  return "x,y,z";
585  default:
586  Assert (false, ExcNotImplemented());
587  }
588  return "";
589 }
590 
591 
592 
593 DEAL_II_NAMESPACE_CLOSE
594 
595 #endif
596 
597 
virtual double value(const Point< dim > &p, const unsigned int component=0) const
ConstMap::iterator ConstMapIterator
unsigned int n_vars
static std::string default_variable_names()
virtual void vector_value(const Point< dim > &p, Vector< double > &values) const
void initialize(const std::string &vars, const std::vector< std::string > &expressions, const ConstMap &constants, const bool time_dependent=false, const bool use_degrees=false)
#define Assert(cond, exc)
Definition: exceptions.h:299
FunctionParser(const unsigned int n_components=1, const double initial_time=0.0)
const unsigned int n_components
Definition: function.h:130
fparser::FunctionParser * fp
std::map< std::string, double > ConstMap
::ExceptionBase & ExcNotImplemented()