FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
static_wrapper.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
9#include <kernel/analytic/function.hpp>
10
11namespace FEAT
12{
13 namespace Analytic
14 {
23 template<typename DataType_>
25 {
26 public:
27#ifdef DOXYGEN
37 static DataType_ eval(DataType_ x);
38
48 static DataType_ eval(DataType_ x, DataType_ y);
49
59 static DataType_ eval(DataType_ x, DataType_ y, DataType_ z);
60
70 static DataType_ der_x(DataType_ x);
71
81 static DataType_ der_x(DataType_ x, DataType_ y);
82
92 static DataType_ der_x(DataType_ x, DataType_ y, DataType_ z);
93
103 static DataType_ der_y(DataType_ x);
104
114 static DataType_ der_y(DataType_ x, DataType_ y);
115
125 static DataType_ der_y(DataType_ x, DataType_ y, DataType_ z);
126
136 static DataType_ der_z(DataType_ x);
137
147 static DataType_ der_z(DataType_ x, DataType_ y);
148
158 static DataType_ der_z(DataType_ x, DataType_ y, DataType_ z);
159
169 static DataType_ der_xx(DataType_ x);
170
180 static DataType_ der_xx(DataType_ x, DataType_ y);
181
191 static DataType_ der_xx(DataType_ x, DataType_ y, DataType_ z);
192
202 static DataType_ der_yy(DataType_ x);
203
213 static DataType_ der_yy(DataType_ x, DataType_ y);
214
224 static DataType_ der_yy(DataType_ x, DataType_ y, DataType_ z);
225
235 static DataType_ der_zz(DataType_ x);
236
246 static DataType_ der_zz(DataType_ x, DataType_ y);
247
257 static DataType_ der_zz(DataType_ x, DataType_ y, DataType_ z);
258
268 static DataType_ der_xy(DataType_ x, DataType_ y);
269
279 static DataType_ der_xy(DataType_ x, DataType_ y, DataType_ z);
280
290 static DataType_ der_yx(DataType_ x, DataType_ y);
291
301 static DataType_ der_yx(DataType_ x, DataType_ y, DataType_ z);
302
312 static DataType_ der_xz(DataType_ x, DataType_ y, DataType_ z);
313
323 static DataType_ der_zx(DataType_ x, DataType_ y, DataType_ z);
324
334 static DataType_ der_yz(DataType_ x, DataType_ y, DataType_ z);
335
345 static DataType_ der_zy(DataType_ x, DataType_ y, DataType_ z);
346#endif // DOXYGEN
347 }; // class StaticFunction
348
350 namespace Intern
351 {
352 template<
353 template<typename> class Function_,
354 typename DataType_,
355 int dim_,
356 bool enable_>
357 struct StaticFunctionWrapper;
358
359 // specialization for 1D functions
360 template<template<typename> class Function_, typename DataType_>
361 struct StaticFunctionWrapper<Function_, DataType_, 1, true>
362 {
363 template<typename Value_, typename Point_>
364 static void eval(Value_& v, const Point_& x)
365 {
366 v = Function_<DataType_>::eval(x[0]);
367 }
368
369 template<typename Value_, typename Point_>
370 static void grad(Value_& v, const Point_& x)
371 {
372 v[0] = Function_<DataType_>::der_x(x[0]);
373 }
374
375 template<typename Value_, typename Point_>
376 static void hess(Value_& v, const Point_& x)
377 {
378 v[0][0] = Function_<DataType_>::der_xx(x[0]);
379 }
380 };
381
382 // specialization for 2D functions
383 template<template<typename> class Function_, typename DataType_>
384 struct StaticFunctionWrapper<Function_, DataType_, 2, true>
385 {
386 template<typename Value_, typename Point_>
387 static void eval(Value_& v, const Point_& x)
388 {
389 v = Function_<DataType_>::eval(x[0], x[1]);
390 }
391
392 template<typename Value_, typename Point_>
393 static void grad(Value_& v, const Point_& x)
394 {
395 v[0] = Function_<DataType_>::der_x(x[0], x[1]);
396 v[1] = Function_<DataType_>::der_y(x[0], x[1]);
397 }
398
399 template<typename Value_, typename Point_>
400 static void hess(Value_& v, const Point_& x)
401 {
402 v[0][0] = Function_<DataType_>::der_xx(x[0], x[1]);
403 v[0][1] = Function_<DataType_>::der_xy(x[0], x[1]);
404 v[1][0] = Function_<DataType_>::der_yx(x[0], x[1]);
405 v[1][1] = Function_<DataType_>::der_yy(x[0], x[1]);
406 }
407 };
408
409 // specialization for 3D functions
410 template<template<typename> class Function_, typename DataType_>
411 struct StaticFunctionWrapper<Function_, DataType_, 3, true>
412 {
413 template<typename Value_, typename Point_>
414 static void eval(Value_& v, const Point_& x)
415 {
416 v = Function_<DataType_>::eval(x[0], x[1],x[2]);
417 }
418
419 template<typename Value_, typename Point_>
420 static void grad(Value_& v, const Point_& x)
421 {
422 v[0] = Function_<DataType_>::der_x(x[0], x[1], x[2]);
423 v[1] = Function_<DataType_>::der_y(x[0], x[1], x[2]);
424 v[2] = Function_<DataType_>::der_z(x[0], x[1], x[2]);
425 }
426
427 template<typename Value_, typename Point_>
428 static void hess(Value_& v, const Point_& x)
429 {
430 v[0][0] = Function_<DataType_>::der_xx(x[0], x[1], x[2]);
431 v[0][1] = Function_<DataType_>::der_xy(x[0], x[1], x[2]);
432 v[0][2] = Function_<DataType_>::der_xz(x[0], x[1], x[2]);
433 v[1][0] = Function_<DataType_>::der_yx(x[0], x[1], x[2]);
434 v[1][1] = Function_<DataType_>::der_yy(x[0], x[1], x[2]);
435 v[1][2] = Function_<DataType_>::der_yz(x[0], x[1], x[2]);
436 v[2][0] = Function_<DataType_>::der_zx(x[0], x[1], x[2]);
437 v[2][1] = Function_<DataType_>::der_zy(x[0], x[1], x[2]);
438 v[2][2] = Function_<DataType_>::der_zz(x[0], x[1], x[2]);
439 }
440 };
441 } // namespace Intern
443
467 template<
468 int domain_dim_,
469 template<typename> class Function_,
470 bool can_value_ = true,
471 bool can_grad_ = false,
472 bool can_hess_ = false>
474 public Analytic::Function
475 {
476 public:
477 static_assert((1 <= domain_dim_) && (domain_dim_ <= 3), "invalid domain dimension");
478
480 static constexpr int domain_dim = domain_dim_;
481
484
485 static constexpr bool can_value = can_value_;
486 static constexpr bool can_grad = can_grad_;
487 static constexpr bool can_hess = can_hess_;
488
491 StaticWrapperFunction(StaticWrapperFunction&&) {}
492
494 template<typename Traits_>
495 class Evaluator :
496 public Analytic::Function::Evaluator<Traits_>
497 {
498 public:
500 typedef typename Traits_::DataType DataType;
502 typedef typename Traits_::PointType PointType;
504 typedef typename Traits_::ValueType ValueType;
506 typedef typename Traits_::GradientType GradientType;
508 typedef typename Traits_::HessianType HessianType;
509
510 public:
513 {
514 }
515
516 ValueType value(const PointType& point) const
517 {
518 ValueType val;
519 Intern::StaticFunctionWrapper<Function_, DataType, domain_dim, can_value_>::eval(val, point);
520 return val;
521 }
522
523 GradientType gradient(const PointType& point) const
524 {
526 Intern::StaticFunctionWrapper<Function_, DataType, domain_dim, can_grad_>::grad(grad, point);
527 return grad;
528 }
529
530 HessianType hessian(const PointType& point) const
531 {
533 Intern::StaticFunctionWrapper<Function_, DataType, domain_dim, can_hess_>::hess(hess, point);
534 return hess;
535 }
536 }; // class StaticWrapperFunction::Evaluator<...>
537 }; // class StaticWrapperFunction
538 } // namespace Analytic
539} // namespace FEAT
Analytic Function Evaluator base-class template.
Definition: function.hpp:157
Analytic Function interface.
Definition: function.hpp:112
Analytic static function interface class template.
static DataType_ der_xy(DataType_ x, DataType_ y)
Evaluates the second order xy-derivative.
static DataType_ der_y(DataType_ x)
Evaluates the first order y-derivative.
static DataType_ der_zz(DataType_ x, DataType_ y)
Evaluates the second order zz-derivative.
static DataType_ der_zy(DataType_ x, DataType_ y, DataType_ z)
Evaluates the second order zy-derivative.
static DataType_ eval(DataType_ x, DataType_ y)
Evaluates the function value.
static DataType_ der_x(DataType_ x, DataType_ y)
Evaluates the first order x-derivative.
static DataType_ der_z(DataType_ x, DataType_ y, DataType_ z)
Evaluates the first order z-derivative.
static DataType_ der_yx(DataType_ x, DataType_ y)
Evaluates the second order yx-derivative.
static DataType_ der_y(DataType_ x, DataType_ y)
Evaluates the first order y-derivative.
static DataType_ der_xx(DataType_ x, DataType_ y, DataType_ z)
Evaluates the second order xx-derivative.
static DataType_ eval(DataType_ x, DataType_ y, DataType_ z)
Evaluates the function value.
static DataType_ der_yy(DataType_ x, DataType_ y, DataType_ z)
Evaluates the second order yy-derivative.
static DataType_ der_x(DataType_ x, DataType_ y, DataType_ z)
Evaluates the first order x-derivative.
static DataType_ der_z(DataType_ x, DataType_ y)
Evaluates the first order z-derivative.
static DataType_ der_xx(DataType_ x, DataType_ y)
Evaluates the second order xx-derivative.
static DataType_ der_y(DataType_ x, DataType_ y, DataType_ z)
Evaluates the first order y-derivative.
static DataType_ der_zz(DataType_ x)
Evaluates the second order zz-derivative.
static DataType_ der_z(DataType_ x)
Evaluates the first order z-derivative.
static DataType_ der_xz(DataType_ x, DataType_ y, DataType_ z)
Evaluates the second order xz-derivative.
static DataType_ der_yx(DataType_ x, DataType_ y, DataType_ z)
Evaluates the second order yx-derivative.
static DataType_ der_xy(DataType_ x, DataType_ y, DataType_ z)
Evaluates the second order xy-derivative.
static DataType_ eval(DataType_ x)
Evaluates the function value.
static DataType_ der_yy(DataType_ x)
Evaluates the second order yy-derivative.
static DataType_ der_zz(DataType_ x, DataType_ y, DataType_ z)
Evaluates the second order zz-derivative.
static DataType_ der_yz(DataType_ x, DataType_ y, DataType_ z)
Evaluates the second order yz-derivative.
static DataType_ der_xx(DataType_ x)
Evaluates the second order xx-derivative.
static DataType_ der_yy(DataType_ x, DataType_ y)
Evaluates the second order yy-derivative.
static DataType_ der_zx(DataType_ x, DataType_ y, DataType_ z)
Evaluates the second order zx-derivative.
static DataType_ der_x(DataType_ x)
Evaluates the first order x-derivative.
Analytic Function Evaluator base-class template.
Traits_::PointType PointType
domain point type
Evaluator(const StaticWrapperFunction &)
Constructor.
Traits_::HessianType HessianType
hessian type
Traits_::DataType DataType
coefficient data type
Traits_::GradientType GradientType
gradient type
StaticFunction wrapper class template for Analytic::Function interface.
static constexpr int domain_dim
our domain dimension
Analytic::Image::Scalar ImageType
this is always a scalar function
FEAT namespace.
Definition: adjactor.hpp:12
@ value
specifies whether the space should supply basis function values
@ hess
specifies whether the space should supply basis function hessians
@ grad
specifies whether the space should supply basis function gradients
Scalar Function Image tag class.
Definition: function.hpp:28