HermesCommon  3.0
hermes_function.cpp
1 // This file is part of Hermes2D.
2 //
3 // Hermes2D is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // Hermes2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Hermes2D. If not, see <http://www.gnu.org/licenses/>.
15 
16 #include "hermes_function.h"
17 
18 namespace Hermes
19 {
20  template<typename Scalar>
22  {
23  return is_const;
24  };
25 
26  template<typename Scalar>
28  {
29  return is_const;
30  };
31 
32  template<typename Scalar>
34  {
35  return is_const;
36  };
37 
38  template<typename Scalar>
40  {
41  this->is_const = false;
42  };
43 
44  template<typename Scalar>
46  {
47  this->is_const = true;
48  this->const_value = value;
49  };
50 
51  template<>
52  double Hermes1DFunction<double>::value(double x) const
53  {
54  if (this->is_const)
55  return const_value;
56  else
57  {
58  throw Hermes::Exceptions::MethodNotOverridenException("Hermes1DFunction<double>::value");
59  return 0.0;
60  }
61  };
62  template<>
63  std::complex<double> Hermes1DFunction<std::complex<double> >::value(std::complex<double> x) const
64  {
65  if (this->is_const)
66  return const_value;
67  else
68  {
69  throw Hermes::Exceptions::MethodNotOverridenException("Hermes1DFunction<std::complex<double> >::value");
70  return std::complex<double>(0.0, 0.0);
71  }
72  };
73 
74  template<typename Scalar>
76  {
77  if (this->is_const)
78  return Ord(0);
79  else
80  {
81  throw Hermes::Exceptions::MethodNotOverridenException("Hermes1DFunction<Scalar>::value");
82  return Ord(99);
83  }
84  };
85 
86  template<>
87  double Hermes1DFunction<double>::derivative(double x) const
88  {
89  if (this->is_const)
90  return 0.0;
91  else
92  {
93  throw Hermes::Exceptions::MethodNotOverridenException("Hermes1DFunction<double>::derivative");
94  return 0.0;
95  }
96  };
97  template<>
98  std::complex<double> Hermes1DFunction<std::complex<double> >::derivative(std::complex<double> x) const
99  {
100  if (this->is_const)
101  return std::complex<double>(0.0, 0.0);
102  else
103  {
104  throw Hermes::Exceptions::MethodNotOverridenException("Hermes1DFunction<std::complex<double> >::derivative");
105  return std::complex<double>(0.0, 0.0);
106  }
107  };
108 
109  template<typename Scalar>
111  {
112  if (this->is_const)
113  return Ord(0);
114  else
115  {
116  throw Hermes::Exceptions::MethodNotOverridenException("Hermes1DFunction<Scalar>::derivative");
117  return Ord(99);
118  }
119  };
120 
121  template<typename Scalar>
123  {
124  this->is_const = false;
125  };
126 
127  template<typename Scalar>
129  {
130  this->is_const = true;
131  this->const_value = value;
132  };
133 
134  template<>
135  double Hermes2DFunction<double>::value(double x, double y) const
136  {
137  if (this->is_const)
138  return const_value;
139  else
140  {
141  throw Hermes::Exceptions::MethodNotOverridenException("Hermes2DFunction<double>::value");
142  return 0.0;
143  }
144  };
145 
146  template<>
147  std::complex<double> Hermes2DFunction<std::complex<double> >::value(std::complex<double> x, std::complex<double> y) const
148  {
149  if (this->is_const)
150  return const_value;
151  else
152  {
153  throw Hermes::Exceptions::MethodNotOverridenException("Hermes2DFunction<std::complex<double> >::value");
154  return std::complex<double>(0.0, 0.0);
155  }
156  };
157 
158  template<typename Scalar>
160  {
161  if (this->is_const)
162  return Ord(0);
163  else
164  {
165  throw Hermes::Exceptions::MethodNotOverridenException("Hermes2DFunction<Scalar>::value");
166  return Ord(99);
167  }
168  };
169 
170  template<>
171  double Hermes2DFunction<double>::derivative_x(double x, double y) const
172  {
173  if (this->is_const)
174  return 0.0;
175  else
176  {
177  throw Hermes::Exceptions::MethodNotOverridenException("Hermes2DFunction<double>::derivative_x");
178  return 0.0;
179  }
180  };
181  template<>
182  std::complex<double> Hermes2DFunction<std::complex<double> >::derivative_x(std::complex<double> x, std::complex<double> y) const
183  {
184  if (this->is_const)
185  return std::complex<double>(0.0, 0.0);
186  else
187  {
188  throw Hermes::Exceptions::MethodNotOverridenException("Hermes2DFunction<std::complex<double> >::derivative_x");
189  return std::complex<double>(0.0, 0.0);
190  }
191  };
192 
193  template<typename Scalar>
195  {
196  if (this->is_const)
197  return Ord(0);
198  else
199  {
200  throw Hermes::Exceptions::MethodNotOverridenException("Hermes2DFunction<Scalar>::derivative_x");
201  return Ord(99);
202  }
203  };
204 
205  template<>
206  double Hermes2DFunction<double>::derivative_y(double x, double y) const
207  {
208  if (this->is_const)
209  return 0.0;
210  else
211  {
212  throw Hermes::Exceptions::MethodNotOverridenException("Hermes2DFunction<double>::derivative_y");
213  return 0.0;
214  }
215  };
216  template<>
217  std::complex<double> Hermes2DFunction<std::complex<double> >::derivative_y(std::complex<double> x, std::complex<double> y) const
218  {
219  if (this->is_const)
220  return std::complex<double>(0.0, 0.0);
221  else
222  {
223  throw Hermes::Exceptions::MethodNotOverridenException("Hermes2DFunction<std::complex<double> >::derivative_y");
224  return std::complex<double>(0.0, 0.0);
225  }
226  };
227 
228  template<typename Scalar>
229  Ord Hermes2DFunction<Scalar>::derivative_y(Ord x, Ord y) const
230  {
231  if (this->is_const)
232  return Ord(0);
233  else
234  {
235  throw Hermes::Exceptions::MethodNotOverridenException("Hermes2DFunction<Scalar>::derivative_y");
236  return Ord(99);
237  }
238  };
239 
240  template<typename Scalar>
242  {
243  this->is_const = false;
244  };
245 
246  template<typename Scalar>
248  {
249  this->is_const = true;
250  this->const_value = value;
251  };
252 
253  template<>
254  double Hermes3DFunction<double>::value(double x, double y, double z) const
255  {
256  if (this->is_const)
257  return 0.0;
258  else
259  {
260  throw Hermes::Exceptions::MethodNotOverridenException("Hermes3DFunction<double>::value");
261  return 0.0;
262  }
263  };
264  template<>
265  std::complex<double> Hermes3DFunction<std::complex<double> >::value(std::complex<double> x, std::complex<double> y, std::complex<double> z) const
266  {
267  if (this->is_const)
268  return std::complex<double>(0.0, 0.0);
269  else
270  {
271  throw Hermes::Exceptions::MethodNotOverridenException("Hermes3DFunction<std::complex<double> >::value");
272  return std::complex<double>(0.0, 0.0);
273  }
274  };
275 
276  template<typename Scalar>
278  {
279  if (this->is_const)
280  return Ord(0);
281  else
282  {
283  throw Hermes::Exceptions::MethodNotOverridenException("Hermes3DFunction<Scalar>::value");
284  return Ord(99);
285  }
286  };
287 
288  template<>
289  double Hermes3DFunction<double>::derivative_x(double x, double y, double z) const
290  {
291  if (this->is_const)
292  return 0.0;
293  else
294  {
295  throw Hermes::Exceptions::MethodNotOverridenException("Hermes3DFunction<double>::derivative_x");
296  return 0.0;
297  }
298  };
299  template<>
300  std::complex<double> Hermes3DFunction<std::complex<double> >::derivative_x(std::complex<double> x, std::complex<double> y, std::complex<double> z) const
301  {
302  if (this->is_const)
303  return std::complex<double>(0.0, 0.0);
304  else
305  {
306  throw Hermes::Exceptions::MethodNotOverridenException("Hermes3DFunction<std::complex<double> >::derivative_x");
307  return std::complex<double>(0.0, 0.0);
308  }
309  };
310 
311  template<typename Scalar>
313  {
314  if (this->is_const)
315  return Ord(0);
316  else
317  {
318  throw Hermes::Exceptions::MethodNotOverridenException("Hermes3DFunction<Scalar>::derivative_x");
319  return Ord(99);
320  }
321  };
322 
323  template<>
324  double Hermes3DFunction<double>::derivative_y(double x, double y, double z) const
325  {
326  if (this->is_const)
327  return 0.0;
328  else
329  {
330  throw Hermes::Exceptions::MethodNotOverridenException("Hermes3DFunction<double>::derivative_y");
331  return 0.0;
332  }
333  };
334  template<>
335  std::complex<double> Hermes3DFunction<std::complex<double> >::derivative_y(std::complex<double> x, std::complex<double> y, std::complex<double> z) const
336  {
337  if (this->is_const)
338  return std::complex<double>(0.0, 0.0);
339  else
340  {
341  throw Hermes::Exceptions::MethodNotOverridenException("Hermes3DFunction<std::complex<double> >::derivative_y");
342  return std::complex<double>(0.0, 0.0);
343  }
344  };
345 
346  template<typename Scalar>
347  Ord Hermes3DFunction<Scalar>::derivative_y(Ord x, Ord y, Ord z) const
348  {
349  if (this->is_const)
350  return Ord(0);
351  else
352  {
353  throw Hermes::Exceptions::MethodNotOverridenException("Hermes3DFunction<Scalar>::derivative_y");
354  return Ord(99);
355  }
356  };
357 
358  template<>
359  double Hermes3DFunction<double>::derivative_z(double x, double y, double z) const
360  {
361  if (this->is_const)
362  return 0.0;
363  else
364  {
365  throw Hermes::Exceptions::MethodNotOverridenException("Hermes3DFunction<double>::derivative_z");
366  return 0.0;
367  }
368  };
369  template<>
370  std::complex<double> Hermes3DFunction<std::complex<double> >::derivative_z(std::complex<double> x, std::complex<double> y, std::complex<double> z) const
371  {
372  if (this->is_const)
373  return std::complex<double>(0.0, 0.0);
374  else
375  {
376  throw Hermes::Exceptions::MethodNotOverridenException("Hermes3DFunction<std::complex<double> >::derivative_z");
377  return std::complex<double>(0.0, 0.0);
378  }
379  };
380 
381  template<typename Scalar>
382  Ord Hermes3DFunction<Scalar>::derivative_z(Ord x, Ord y, Ord z) const
383  {
384  if (this->is_const)
385  return Ord(0);
386  else
387  {
388  throw Hermes::Exceptions::MethodNotOverridenException("Hermes3DFunction<Scalar>::derivative_z");
389  return Ord(99);
390  }
391  };
392 
393  template class HERMES_API Hermes1DFunction < double > ;
394  template class HERMES_API Hermes1DFunction < std::complex<double> > ;
395  template class HERMES_API Hermes2DFunction < double > ;
396  template class HERMES_API Hermes2DFunction < std::complex<double> > ;
397  template class HERMES_API Hermes3DFunction < double > ;
398  template class HERMES_API Hermes3DFunction < std::complex<double> > ;
399 }
General namespace for the Hermes library.
virtual Scalar value(Scalar x, Scalar y, Scalar z) const
Two-dimensional function value.
Hermes1DFunction()
Constructor.
virtual Scalar derivative_x(Scalar x, Scalar y, Scalar z) const
Two-dimensional function derivative value.
virtual Scalar derivative_x(Scalar x, Scalar y) const
Two-dimensional function derivative value.
Method is not overriden and should be.
Definition: exceptions.h:201
virtual Scalar value(Scalar x) const
One-dimensional function value.
virtual Scalar derivative(Scalar x) const
One-dimensional function derivative value.
virtual Scalar value(Scalar x, Scalar y) const
Two-dimensional function value.