gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
simpleFunction.h
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #ifndef SIMPLE_FUNCTION_H
7 #define SIMPLE_FUNCTION_H
8 
9 #include <map>
10 
11 // FIXME: src/numeric/ should not depend on src/geo/
12 class MElement;
13 
14 template <class scalar> class simpleFunction {
15 protected:
16  scalar _val;
18 
19 public:
20  simpleFunction(scalar val = 0.0) : _val(val), _hasDerivatives(false) {}
21  virtual ~simpleFunction() {}
22  virtual bool hasDerivatives() { return _hasDerivatives; };
23  virtual scalar operator()(double x, double y, double z) const { return _val; }
24  virtual void setElement(MElement *e) const {}
25  virtual void gradient(double x, double y, double z, scalar &dfdx,
26  scalar &dfdy, scalar &dfdz) const
27  {
28  dfdx = dfdy = dfdz = 0.0;
29  }
30  virtual void hessian(double x, double y, double z, scalar &dfdxx,
31  scalar &dfdxy, scalar &dfdxz, scalar &dfdyx,
32  scalar &dfdyy, scalar &dfdyz, scalar &dfdzx,
33  scalar &dfdzy, scalar &dfdzz) const
34  {
35  dfdxx = dfdxy = dfdxz = 0.0;
36  dfdyx = dfdyy = dfdyz = 0.0;
37  dfdzx = dfdzy = dfdzz = 0.0;
38  }
39 };
40 
41 template <class scalar>
42 class constantPerElement : public simpleFunction<scalar> {
43  std::map<MElement *, scalar> _data;
44  mutable MElement *_e;
45 
46 public:
47  constantPerElement() : _e(nullptr) {}
48  void set(MElement *e, scalar v) { _data[e] = v; }
49  void setElement(MElement *e) const { _e = e; }
50  virtual scalar operator()(double x, double y, double z) const
51  {
52  if(!_e) return 0.0;
53  typename std::map<MElement *, scalar>::const_iterator it = _data.find(_e);
54  if(it == _data.end()) return 0.0;
55  return it->second;
56  }
57 };
58 
59 template <class scalar>
60 class simpleFunctionOnElement : public simpleFunction<scalar> {
61  mutable MElement *_e;
62 
63 public:
64  simpleFunctionOnElement(scalar val = 0) : simpleFunction<scalar>(val), _e(nullptr)
65  {
66  }
68  void setElement(MElement *e) const { _e = e; }
69  MElement *getElement(void) const { return _e; }
70  MElement *getElement(double x, double y, double z) const
71  {
72  if(_e)
73  return _e;
74  else { // search
75  }
76  }
77 };
78 
79 #endif
simpleFunctionOnElement
Definition: simpleFunction.h:60
simpleFunction::operator()
virtual scalar operator()(double x, double y, double z) const
Definition: simpleFunction.h:23
constantPerElement
Definition: simpleFunction.h:42
simpleFunction::hessian
virtual void hessian(double x, double y, double z, scalar &dfdxx, scalar &dfdxy, scalar &dfdxz, scalar &dfdyx, scalar &dfdyy, scalar &dfdyz, scalar &dfdzx, scalar &dfdzy, scalar &dfdzz) const
Definition: simpleFunction.h:30
simpleFunctionOnElement::~simpleFunctionOnElement
virtual ~simpleFunctionOnElement()
Definition: simpleFunction.h:67
simpleFunction::gradient
virtual void gradient(double x, double y, double z, scalar &dfdx, scalar &dfdy, scalar &dfdz) const
Definition: simpleFunction.h:25
constantPerElement::_e
MElement * _e
Definition: simpleFunction.h:44
simpleFunction::_hasDerivatives
bool _hasDerivatives
Definition: simpleFunction.h:17
simpleFunction::_val
scalar _val
Definition: simpleFunction.h:16
simpleFunction::setElement
virtual void setElement(MElement *e) const
Definition: simpleFunction.h:24
simpleFunction
Definition: GModel.h:30
constantPerElement::_data
std::map< MElement *, scalar > _data
Definition: simpleFunction.h:43
constantPerElement::operator()
virtual scalar operator()(double x, double y, double z) const
Definition: simpleFunction.h:50
simpleFunctionOnElement::setElement
void setElement(MElement *e) const
Definition: simpleFunction.h:68
MElement
Definition: MElement.h:30
simpleFunctionOnElement::simpleFunctionOnElement
simpleFunctionOnElement(scalar val=0)
Definition: simpleFunction.h:64
simpleFunctionOnElement::getElement
MElement * getElement(void) const
Definition: simpleFunction.h:69
constantPerElement::setElement
void setElement(MElement *e) const
Definition: simpleFunction.h:49
simpleFunctionOnElement::_e
MElement * _e
Definition: simpleFunction.h:61
simpleFunction::simpleFunction
simpleFunction(scalar val=0.0)
Definition: simpleFunction.h:20
z
const double z
Definition: GaussQuadratureQuad.cpp:56
constantPerElement::constantPerElement
constantPerElement()
Definition: simpleFunction.h:47
constantPerElement::set
void set(MElement *e, scalar v)
Definition: simpleFunction.h:48
simpleFunctionOnElement::getElement
MElement * getElement(double x, double y, double z) const
Definition: simpleFunction.h:70
simpleFunction::hasDerivatives
virtual bool hasDerivatives()
Definition: simpleFunction.h:22
simpleFunction::~simpleFunction
virtual ~simpleFunction()
Definition: simpleFunction.h:21