1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
|
// This file is part of ff3d - http://www.freefem.org/ff3d
// Copyright (C) 2001, 2002, 2003 Stphane Del Pino
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// $Id: ScalarFunctionBase.hpp,v 1.9 2007/06/13 23:11:22 delpinux Exp $
#ifndef SCALAR_FUNCTION_BASE_HPP
#define SCALAR_FUNCTION_BASE_HPP
#include <Types.hpp>
#include <TinyVector.hpp>
#include <iostream>
#include <ErrorHandler.hpp>
/**
* @file ScalarFunctionBase.hpp
* @author Stephane Del Pino
* @date Thu Jul 20 00:29:36 2006
*
* @brief base class for scalar functions
*
*/
class ScalarFunctionBase
{
public:
enum Type {
cfunction,
constant,
convection,
femfunction,
linearBasis,
spectral,
unaryMinus,
modulo,
sum,
difference,
product,
division,
power,
min,
max,
gt,
ge,
lt,
le,
ne,
eq,
and_,
or_,
xor_,
not_,
derivate,
integrate,
normal,
domainCharacteristic,
meshCharacteristic,
objectCharacteristic,
composed,
references,
FEM0,
undefined
};
protected:
const Type __type; /**< type of the function */
std::string __name; /**< name of the function */
/**
* Writes the function to a stream
*
* @param os output stream
*
* @return the modified stream
*/
virtual std::ostream& __put(std::ostream& os) const = 0;
public:
/**
* Sets the name of the function
*
* @param name name to give to this function
*/
void setName(const std::string& name)
{
__name = name;
}
/**
* Gets the name of the function
*
* @return __name
*/
const std::string& name() const
{
return __name;
}
/**
* Read-only access to the type of the function
*
* @return __type
*/
inline const Type& type() const
{
return __type;
}
/**
* Writes the function @a scalarFunction to the stream @a os
*
* @param os the output stream
* @param scalarFunction the function to write
*
* @return os
*/
friend std::ostream& operator<<(std::ostream& os,
const ScalarFunctionBase& scalarFunction)
{
if (scalarFunction.__name.size()>0) {
os << scalarFunction.__name;
return os;
} else {
return scalarFunction.__put(os);
}
}
/**
* Evaluates the function at point @f$ (x,y,z) @f$
*
* @param x @f$ x @f$
* @param y @f$ y @f$
* @param z @f$ z @f$
*
* @return @f$ f(x,y,z) @f$
*/
inline real_t operator()(const real_t& x,
const real_t& y,
const real_t& z) const
{
return this->operator()(TinyVector<3, real_t>(x,y,z));
}
/**
* Evaluates the gunction at point @f$ X @f$
*
* @param X point of evaluation of the function
*
* @return @f$ f(X) @f$
*/
virtual real_t operator()(const TinyVector<3, real_t>& X) const = 0;
/**
* Evaluates first derivative of the function
*
* @param x position of evaluation
*
* @return @f$ \partial_x f @f$ at position @f$ x @f$
*/
virtual real_t dx(const TinyVector<3, real_t>& V) const
{
std::stringstream errorMsg;
errorMsg << "cannot compute derivative of non discrete functions :-(\n";
errorMsg << "the function " << (*this) << " is not of that kind"
<< std::ends;
throw ErrorHandler(__FILE__,__LINE__,
errorMsg.str(),
ErrorHandler::normal);
return 0;
}
/**
* Evaluates second derivative of the function
*
* @param x position of evaluation
*
* @return @f$ \partial_y f @f$ at position @f$ x @f$
*/
virtual real_t dy(const TinyVector<3, real_t>& V) const
{
std::stringstream errorMsg;
errorMsg << "cannot compute derivative of non discrete functions :-(\n";
errorMsg << "the function " << (*this) << " is not of that kind"
<< std::ends;
throw ErrorHandler(__FILE__,__LINE__,
errorMsg.str(),
ErrorHandler::normal);
return 0;
}
/**
* Evaluates third derivative of the function
*
* @param x position of evaluation
*
* @return @f$ \partial_z f @f$ at position @f$ x @f$
*/
virtual real_t dz(const TinyVector<3, real_t>& V) const
{
std::stringstream errorMsg;
errorMsg << "cannot compute derivative of non discrete functions :-(\n";
errorMsg << "the function " << (*this) << " is not of that kind"
<< std::ends;
throw ErrorHandler(__FILE__,__LINE__,
errorMsg.str(),
ErrorHandler::normal);
return 0;
}
/**
* Checks if the function can be simplified: it means that composed
* functions of using this function can be partialy
* pre-evaluated. For instance a fem-function multiplied by a
* constant can be evaluate when operation is declared.
*
* @return true if the function can be simplified
*/
virtual bool canBeSimplified() const = 0;
/**
* Copy constructor
*
* @param f given function
*/
ScalarFunctionBase(const ScalarFunctionBase& f)
: __type(f.__type),
__name(f.__name)
{
;
}
/**
* Constructor
*
* @param type the type of the function
*/
ScalarFunctionBase(const Type& type)
: __type(type),
__name("")
{
;
}
/**
* Destructor
*
*/
virtual ~ScalarFunctionBase()
{
;
}
};
#endif // SCALAR_FUNCTION_BASE_HPP
|