NeoPZ
pzfunction.h
Go to the documentation of this file.
1 
3 #ifndef PZFUNCTION_H
4 #define PZFUNCTION_H
5 
6 #include "TPZSavable.h"
7 #include "pzvec.h"
8 #include "pzfmatrix.h"
9 
18 template<class TVar>
19 class TPZFunction : public virtual TPZSavable {
20 public:
21 
24 
25  }
26 
29 
30  }
31 
38  virtual void Execute(const TPZVec<REAL> &x, TPZVec<TVar> &f, TPZFMatrix<TVar> &df)
39  {
40  DebugStop();
41  }
42 
50  virtual void Execute(const TPZVec<REAL> &x, REAL time, TPZVec<TVar> &f, TPZFMatrix<TVar> &gradf){
51  DebugStop();
52  }
53 
55  virtual void Execute(const TPZVec<REAL> &x, const TPZFMatrix<REAL> &axes, TPZVec<TVar> &f, TPZFMatrix<TVar> &df){
56  DebugStop();
57  }
58 
60  virtual void Execute(const TPZVec<REAL> &x, TPZVec<TVar> &f){
61  DebugStop();
62  }
63 
66  virtual int PolynomialOrder() const {
67  return 1;
68  }
69 
71  virtual int NFunctions() const
72  {
73  return 1;
74  }
75 
77  virtual void Print(std::ostream &out)
78  {
79  out << __PRETTY_FUNCTION__ << std::endl;
80  out << "Polynomial Order = " << PolynomialOrder() << std::endl;
81  }
82 
83 public:
84  int ClassId() const override;
85 
86  void Write(TPZStream &buf, int withclassid) const override{ //ok
87  }
88 
89  void Read(TPZStream &buf, void *context) override{ //ok
90  }
91 
92 };
93 
94 template<class TVar>
96  return Hash("TPZFunction") ^ ClassIdOrHash<TVar>()<<1;
97 }
98 
99 template<class TVar>
100 class TPZDummyFunction : public TPZFunction<TVar>
101 {
102 
103  void (*fFunc)(const TPZVec<REAL> &x, TPZVec<TVar> &f);
104  void (*fFunc2)(const TPZVec<REAL> &x, TPZVec<TVar> &f, TPZFMatrix<TVar> &gradf);
105  void (*fFunc3)(const TPZVec<REAL> &x, REAL ftime, TPZVec<TVar> &f, TPZFMatrix<TVar> &gradf);
106 
107  int fPorder;
108 public:
109 
112  {
113  fFunc = 0;
114  fFunc2 = 0;
115  fFunc3 = 0;
116  }
117 
120  {
121 
122  }
123 
124  TPZDummyFunction(void (*FuncPtr)(const TPZVec<REAL> &x, TPZVec<TVar> &val), int polynomialorder )
126  {
127  fFunc = FuncPtr;
128  fFunc2 = 0;
129  fFunc3 = 0;
130  fPorder = polynomialorder;
131  }
132 
133  TPZDummyFunction(void (*FuncPtr)(const TPZVec<REAL> &x, TPZVec<TVar> &val, TPZFMatrix<TVar> &gradf), int polynomialorder )
135  {
136  fFunc = 0;
137  fFunc2 = FuncPtr;
138  fFunc3 = 0;
139  fPorder = polynomialorder;
140  }
141 
142  TPZDummyFunction(void (*FuncPtr)(const TPZVec<REAL> &x, REAL ftime, TPZVec<TVar> &val, TPZFMatrix<TVar> &gradf), int polynomialorder ) : TPZRegisterClassId(&TPZDummyFunction::ClassId)
143  {
144  fFunc = 0;
145  fFunc2 = 0;
146  fFunc3 = FuncPtr;
147  fPorder = polynomialorder;
148  }
149 
151  fFunc(cp.fFunc), fFunc2(cp.fFunc2), fFunc3(cp.fFunc3), fPorder(cp.fPorder)
152  {
153 
154  }
155 
156 
158  {
159  fFunc = cp.fFunc;
160  fFunc2 = cp.fFunc2;
161  fFunc3 = cp.fFunc3;
162  fPorder = cp.fPorder;
163  return *this;
164  }
171  virtual void Execute(const TPZVec<REAL> &x, TPZVec<TVar> &f, TPZFMatrix<TVar> &df) override
172  {
173  if (!fFunc2) {
174  if (!fFunc)
175  DebugStop();
176  else {
177  df.Zero();
178  fFunc(x, f);
179  }
180  }
181  else
182  fFunc2(x, f, df);
183  }
184 
192  virtual void Execute(const TPZVec<REAL> &x, REAL ftime, TPZVec<TVar> &f, TPZFMatrix<TVar> &gradf) override
193  {
194  if (!fFunc3) {
195  DebugStop();
196  }
197  fFunc3(x, ftime, f, gradf);
198  }
199 
204  virtual void Execute(const TPZVec<REAL> &x, const TPZFMatrix<REAL> &axes, TPZVec<TVar> &f, TPZFMatrix<TVar> &df) override {
205  DebugStop();
206  }
207 
213  virtual void Execute(const TPZVec<REAL> &x, TPZVec<TVar> &f) override {
214  if (!fFunc) {
215  DebugStop();
216  }
217  fFunc(x,f);
218  }
219 
221  virtual int NFunctions() const override
222  {
223  return 1;
224  }
225 
227  {
228  fPorder = porder;
229  }
230 
233  virtual int PolynomialOrder() const override
234  {
235 #ifdef PZDEBUG
236  if (fPorder == -1) {
237  DebugStop();
238  }
239 #endif
240  return fPorder;
241  }
242 
244  public:
245  int ClassId() const override;
246 
247 
249  void Write(TPZStream &buf, int withclassid) const override
250  {
251  DebugStop();
252  }
253 
255  void Read(TPZStream &buf, void *context) override
256  {
257  DebugStop();
258  }
259 };
260 
261 template<class TVar>
263  return TPZFunction<TVar>::ClassId() ^ Hash("TPZDummyFunction");
264 }
265 
266 #endif
virtual void Execute(const TPZVec< REAL > &x, TPZVec< TVar > &f, TPZFMatrix< TVar > &df)
Performs function computation.
Definition: pzfunction.h:38
void(* fFunc)(const TPZVec< REAL > &x, TPZVec< TVar > &f)
Definition: pzfunction.h:103
Contains declaration of the TPZSavable class which defines the interface to save and restore objects ...
void(* fFunc2)(const TPZVec< REAL > &x, TPZVec< TVar > &f, TPZFMatrix< TVar > &gradf)
Definition: pzfunction.h:104
virtual void Print(std::ostream &out)
Print a brief statement.
Definition: pzfunction.h:77
virtual void Execute(const TPZVec< REAL > &x, const TPZFMatrix< REAL > &axes, TPZVec< TVar > &f, TPZFMatrix< TVar > &df) override
Execute method receiving axes. It is used in shape functions.
Definition: pzfunction.h:204
TPZFunction()
Class constructor.
Definition: pzfunction.h:23
int ClassId() const override
Unique identifier for serialization purposes.
Definition: pzfunction.h:262
Templated vector implementation.
TPZDummyFunction & operator=(const TPZDummyFunction &cp)
Definition: pzfunction.h:157
TPZDummyFunction(void(*FuncPtr)(const TPZVec< REAL > &x, REAL ftime, TPZVec< TVar > &val, TPZFMatrix< TVar > &gradf), int polynomialorder)
Definition: pzfunction.h:142
virtual void Execute(const TPZVec< REAL > &x, const TPZFMatrix< REAL > &axes, TPZVec< TVar > &f, TPZFMatrix< TVar > &df)
Execute method receiving axes. It is used in shape functions.
Definition: pzfunction.h:55
REAL val(STATE &number)
Returns value of the variable.
Definition: pzartdiff.h:23
virtual int PolynomialOrder() const override
Polynomial order of this function.
Definition: pzfunction.h:233
Implements a function. Utility.
Definition: pzfunction.h:19
int Zero() override
Makes Zero all the elements.
Definition: pzfmatrix.h:651
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
Definition: pzfunction.h:86
TPZDummyFunction(void(*FuncPtr)(const TPZVec< REAL > &x, TPZVec< TVar > &val, TPZFMatrix< TVar > &gradf), int polynomialorder)
Definition: pzfunction.h:133
TPZDummyFunction(void(*FuncPtr)(const TPZVec< REAL > &x, TPZVec< TVar > &val), int polynomialorder)
Definition: pzfunction.h:124
void Read(TPZStream &buf, void *context) override
read objects from the stream
Definition: pzfunction.h:89
f
Definition: test.py:287
Contains TPZMatrixclass which implements full matrix (using column major representation).
virtual ~TPZDummyFunction()
Class destructor.
Definition: pzfunction.h:119
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
virtual void Execute(const TPZVec< REAL > &x, REAL time, TPZVec< TVar > &f, TPZFMatrix< TVar > &gradf)
Performs time dependent function computation.
Definition: pzfunction.h:50
TPZDummyFunction()
Class constructor.
Definition: pzfunction.h:111
~TPZFunction()
Class destructor.
Definition: pzfunction.h:28
virtual int NFunctions() const
number of values returned by this function
Definition: pzfunction.h:71
virtual void Execute(const TPZVec< REAL > &x, TPZVec< TVar > &f)
Simpler version of Execute method which does not compute function derivatives.
Definition: pzfunction.h:60
Full matrix class. Matrix.
Definition: pzfmatrix.h:32
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
void Read(TPZStream &buf, void *context) override
Reads the element data from a stream.
Definition: pzfunction.h:255
virtual void Execute(const TPZVec< REAL > &x, REAL ftime, TPZVec< TVar > &f, TPZFMatrix< TVar > &gradf) override
Performs time dependent function computation.
Definition: pzfunction.h:192
void SetPolynomialOrder(int porder)
Definition: pzfunction.h:226
void(* fFunc3)(const TPZVec< REAL > &x, REAL ftime, TPZVec< TVar > &f, TPZFMatrix< TVar > &gradf)
Definition: pzfunction.h:105
void Write(TPZStream &buf, int withclassid) const override
Saves the element data to a stream.
Definition: pzfunction.h:249
int ClassId() const override
Define the class id associated with the class.
Definition: pzfunction.h:95
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
clarg::argInt porder("-porder", "polinomial order", 1)
virtual void Execute(const TPZVec< REAL > &x, TPZVec< TVar > &f) override
Simpler version of Execute method which does not compute function derivatives.
Definition: pzfunction.h:213
TPZDummyFunction(const TPZDummyFunction &cp)
Definition: pzfunction.h:150
This class defines the interface to save and restore objects from TPZStream objects. Persistency.
Definition: TPZSavable.h:67
virtual int PolynomialOrder() const
Polynomial order of this function. In case of non-polynomial function it can be a reasonable approxim...
Definition: pzfunction.h:66
virtual void Execute(const TPZVec< REAL > &x, TPZVec< TVar > &f, TPZFMatrix< TVar > &df) override
Performs function computation.
Definition: pzfunction.h:171
virtual int NFunctions() const override
Returns number of functions.
Definition: pzfunction.h:221