00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SCALAR_FUNCTION_BASE_HPP
00021 #define SCALAR_FUNCTION_BASE_HPP
00022
00023 #include <Types.hpp>
00024 #include <TinyVector.hpp>
00025
00026 #include <iostream>
00027 #include <ErrorHandler.hpp>
00028
00037 class ScalarFunctionBase
00038 {
00039 public:
00040 enum Type {
00041 cfunction,
00042 constant,
00043 convection,
00044 dgfunction,
00045 femfunction,
00046 linearBasis,
00047 spectral,
00048 unaryMinus,
00049
00050 modulo,
00051 sum,
00052 difference,
00053 product,
00054 division,
00055 power,
00056
00057 min,
00058 max,
00059
00060 gt,
00061 ge,
00062 lt,
00063 le,
00064 ne,
00065 eq,
00066 and_,
00067 or_,
00068 xor_,
00069
00070 not_,
00071
00072 derivate,
00073 integrate,
00074
00075 normal,
00076
00077 domainCharacteristic,
00078 meshCharacteristic,
00079 objectCharacteristic,
00080
00081 composed,
00082 references,
00083
00084 FEM0,
00085
00086 undefined
00087 };
00088
00089 protected:
00090 const Type __type;
00092 std::string __name;
00101 virtual std::ostream& __put(std::ostream& os) const = 0;
00102
00103 public:
00109 void setName(const std::string& name)
00110 {
00111 __name = name;
00112 }
00113
00119 const std::string& name() const
00120 {
00121 return __name;
00122 }
00123
00129 inline const Type& type() const
00130 {
00131 return __type;
00132 }
00133
00142 friend std::ostream& operator<<(std::ostream& os,
00143 const ScalarFunctionBase& scalarFunction)
00144 {
00145 if (scalarFunction.__name.size()>0) {
00146 os << scalarFunction.__name;
00147 return os;
00148 } else {
00149 return scalarFunction.__put(os);
00150 }
00151 }
00152
00162 inline real_t operator()(const real_t& x,
00163 const real_t& y,
00164 const real_t& z) const
00165 {
00166 return this->operator()(TinyVector<3, real_t>(x,y,z));
00167 }
00168
00176 virtual real_t operator()(const TinyVector<3, real_t>& X) const = 0;
00177
00185 virtual real_t dx(const TinyVector<3, real_t>& x) const
00186 {
00187 std::stringstream errorMsg;
00188
00189 errorMsg << "cannot compute derivative of non discrete functions :-(\n";
00190 errorMsg << "the function " << (*this) << " is not of that kind"
00191 << std::ends;
00192
00193 throw ErrorHandler(__FILE__,__LINE__,
00194 errorMsg.str(),
00195 ErrorHandler::normal);
00196 return 0;
00197 }
00198
00206 virtual real_t dy(const TinyVector<3, real_t>& x) const
00207 {
00208 std::stringstream errorMsg;
00209
00210 errorMsg << "cannot compute derivative of non discrete functions :-(\n";
00211 errorMsg << "the function " << (*this) << " is not of that kind"
00212 << std::ends;
00213
00214 throw ErrorHandler(__FILE__,__LINE__,
00215 errorMsg.str(),
00216 ErrorHandler::normal);
00217 return 0;
00218 }
00219
00227 virtual real_t dz(const TinyVector<3, real_t>& x) const
00228 {
00229 std::stringstream errorMsg;
00230
00231 errorMsg << "cannot compute derivative of non discrete functions :-(\n";
00232 errorMsg << "the function " << (*this) << " is not of that kind"
00233 << std::ends;
00234
00235 throw ErrorHandler(__FILE__,__LINE__,
00236 errorMsg.str(),
00237 ErrorHandler::normal);
00238 return 0;
00239 }
00240
00249 virtual bool canBeSimplified() const = 0;
00250
00256 ScalarFunctionBase(const ScalarFunctionBase& f)
00257 : __type(f.__type),
00258 __name(f.__name)
00259 {
00260 ;
00261 }
00262
00268 ScalarFunctionBase(const Type& type)
00269 : __type(type),
00270 __name("")
00271 {
00272 ;
00273 }
00274
00279 virtual ~ScalarFunctionBase()
00280 {
00281 ;
00282 }
00283 };
00284
00285 #endif // SCALAR_FUNCTION_BASE_HPP