include/deal.II/base/function_parser.h

00001 //---------------------------------------------------------------------------
00002 //    @f$Id: function_parser.h 25345 2012-03-31 08:37:04Z bangerth @f$
00003 //
00004 //    Copyright (C) 2005, 2006, 2007, 2008, 2009, 2012 by the deal.II authors
00005 //
00006 //    This file is subject to QPL and may not be  distributed
00007 //    without copyright and license information. Please refer
00008 //    to the file deal.II/doc/license.html for the  text  and
00009 //    further information on this license.
00010 //
00011 //---------------------------------------------------------------------------
00012 
00013 
00014 #ifndef __deal2__function_parser_h
00015 #define __deal2__function_parser_h
00016 
00017 
00018 //TODO: Update to latest version of fparser library from http://warp.povusers.org/FunctionParser/
00019 
00020 #include <deal.II/base/config.h>
00021 #include <deal.II/base/exceptions.h>
00022 #include <deal.II/base/function.h>
00023 #include <deal.II/base/tensor.h>
00024 #include <deal.II/base/point.h>
00025 #include <vector>
00026 #include <map>
00027 
00028 namespace fparser
00029 {
00030   class FunctionParser;
00031 }
00032 
00033 DEAL_II_NAMESPACE_OPEN
00034 
00035 
00036 template <typename> class Vector;
00037 
00038 
00316 template <int dim>
00317 class FunctionParser : public Function<dim>
00318 {
00319   public:
00334     FunctionParser (const unsigned int n_components = 1,
00335                     const double       initial_time = 0.0);
00336 
00343     ~FunctionParser();
00344 
00350     typedef std::map<std::string, double> ConstMap;
00351 
00357     typedef ConstMap::iterator ConstMapIterator;
00358 
00425     void initialize (const std::string              &vars,
00426                      const std::vector<std::string> &expressions,
00427                      const ConstMap                 &constants,
00428                      const bool time_dependent = false,
00429                      const bool use_degrees = false);
00430 
00431 
00444      void initialize (const std::string              &vars,
00445                       const std::vector<std::string> &expressions,
00446                       const ConstMap                 &constants,
00447                       const ConstMap                 &units,
00448                       const bool time_dependent = false,
00449                       const bool use_degrees = false);
00450 
00463     void initialize (const std::string &vars,
00464                      const std::string &expression,
00465                      const ConstMap    &constants,
00466                      const bool time_dependent = false,
00467                      const bool use_degrees = false);
00468 
00474     void initialize (const std::string &vars,
00475                      const std::string &expression,
00476                      const ConstMap    &constants,
00477                      const ConstMap    &units,
00478                      const bool time_dependent = false,
00479                      const bool use_degrees = false);
00480 
00490     static
00491     std::string
00492     default_variable_names ();
00493 
00505     virtual double value (const Point<dim>   &p,
00506                           const unsigned int  component = 0) const;
00507 
00517     virtual void vector_value (const Point<dim>   &p,
00518                                Vector<double>     &values) const;
00519 
00522     DeclException2 (ExcParseError,
00523                     int, char*,
00524                     << "Parsing Error at Column " << arg1
00525                     << ". The parser said: " << arg2);
00526 
00527     DeclException2 (ExcInvalidExpressionSize,
00528                     int, int,
00529                     << "The number of components (" << arg1
00530                     << ") is not equal to the number of expressions ("
00531                     << arg2 << ").");
00532 
00534   private:
00539     fparser::FunctionParser * fp;
00540 
00548     bool initialized;
00549 
00564     unsigned int n_vars;
00565 };
00566 
00567 
00568 template <int dim>
00569 std::string
00570 FunctionParser<dim>::default_variable_names ()
00571 {
00572   switch (dim)
00573     {
00574       case 1:
00575             return "x";
00576       case 2:
00577             return "x,y";
00578       case 3:
00579             return "x,y,z";
00580       default:
00581             Assert (false, ExcNotImplemented());
00582     }
00583   return "";
00584 }
00585 
00586 
00587 
00588 DEAL_II_NAMESPACE_CLOSE
00589 
00590 #endif
00591 
00592 
00593 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

deal.II documentation generated on Tue May 22 2012 12:06:05 by doxygen 1.7.3