00001 #ifndef _MY_SFunctions_
00002 #define _MY_SFunctions_
00003 #include "base/function.h"
00004 #include "globals.h"
00005 #include <iostream>
00006 #include "exception.h"
00007 #include <vector>
00008 #include "generalfunctioninterface.h"
00009 #include "arrayofvecdouble.h"
00010
00011
00012
00013
00014
00015
00016 class VectorFunction : public GeneralFunctionInterface
00017 {
00018 std::vector<GeneralFunctionInterface *> vFunctions;
00019 int m_nComponents;
00020 bool m_delete;
00021 public:
00022
00023 VectorFunction(GeneralFunctionInterface *f1,GeneralFunctionInterface *f2,bool del=false)
00024 :GeneralFunctionInterface(f1->getDomainDim(),2)
00025 {
00026 assert(f1->getDomainDim() == f2->getDomainDim());
00027 assert(f1->getImageDim() ==1);
00028 assert(f2->getImageDim() ==1);
00029 vFunctions.push_back(f1);
00030 vFunctions.push_back(f2);
00031 m_nComponents=2;
00032 m_delete=del;
00033 }
00034
00035
00036 virtual bool isInDomain(const VecDouble &p,unsigned component=0)
00037 {
00038 assert(component < getImageDim());
00039 return vFunctions[component]->isInDomain(p);
00040 }
00041 virtual double operator() (const VecDouble &p, unsigned int component=0) const
00042 {
00043 assert(component < getImageDim());
00044 return (*(vFunctions[component]))(p);
00045 }
00046 virtual ~VectorFunction()
00047 {
00048 for (unsigned i=0;i<vFunctions.size();i++)
00049 {
00050 delete vFunctions[i];
00051 }
00052 }
00053 };
00054
00055
00056
00057
00058 class Function1D: public GeneralFunctionInterface
00059 {
00060 public:
00061 Function1D(unsigned n_components=1):GeneralFunctionInterface(1,n_components)
00062 {}
00063 virtual double operator()(double dd,unsigned cmp =0) const=0;
00064 virtual bool isInDomain(double dd,unsigned component=0) const{return true;}
00065
00066
00067 virtual double getMaxNorm(double a,double b) const
00068 {
00069 double min,max;
00070 getMinMaxValues(a,b,min,max);
00071 return std::max(fabs(min),fabs(max));
00072 }
00073
00074 virtual double operator() (const VecDouble &p, unsigned int component=0) const
00075 {
00076 return (*this)(p(0),component);
00077 }
00078
00079 virtual bool isInDomain(const VecDouble &p,unsigned component=0) const
00080 {
00081 return this->isInDomain(p(0),component);
00082 }
00083
00084
00085
00086 virtual void getMinMaxValues(double a, double b,double &min,double &max) const
00087 {
00088 min=max=NAN;
00089 throw new Exception("Function1D::getMinMaxValues(%g,%g) = Warning: Invalid Base Method called\n",a,b);
00090 return;
00091 }
00092
00093 virtual ~Function1D()
00094 {
00095
00096 }
00097
00098 void plot(std::ostream &out,double a,double b,unsigned nPoints,unsigned cmp=0)
00099 {
00100 assert(a<b);
00101 double dx = (b-a)/nPoints;
00102 double x=a;
00103 for (unsigned i=0;i<nPoints;i++,x+=dx)
00104 {
00105 out << x << " " << (*this)(x,cmp) << std::endl;
00106 }
00107 }
00108 void evaluate(VecDouble &v)
00109 {
00110 for (unsigned i=0;i<v.size();i++)
00111 {
00112 v(i)=this->operator()(v(i));
00113 }
00114
00115 }
00116 };
00117
00118
00119 class Function3D: public GeneralFunctionInterface
00120 {
00121 public:
00122 Function3D(unsigned n_components=1)
00123 :GeneralFunctionInterface(3,n_components)
00124 {}
00125 virtual ~Function3D(){}
00126 };
00127
00128 class Function2D: public GeneralFunctionInterface
00129 {
00130 public:
00131 Function2D(unsigned n_components=1)
00132 :GeneralFunctionInterface(2,n_components)
00133 {}
00134
00135 };
00136
00137
00138
00139
00140
00141
00142
00143
00144 template<int dim>
00145 class TensorFunction
00146 {
00147 public:
00148 virtual ~TensorFunction(){}
00149 double operator() (Point<dim> &p,unsigned i,unsigned j){return value(p,i,j);}
00150 virtual double value(const Point<dim> &p,const unsigned i,const unsigned j) const = 0;
00151 };
00152
00153
00154
00155 #endif
00156