9#include <kernel/analytic/function.hpp>
25 template<
typename Function_>
31 static_assert(Function_::ImageType::is_scalar,
"only scalar functions are supported");
39 static constexpr bool can_value = Function_::can_grad;
40 static constexpr bool can_grad = Function_::can_hess;
41 static constexpr bool can_hess =
false;
43 template<
typename Traits_>
48 typedef typename Traits_::DataType DataType;
49 typedef typename Traits_::PointType PointType;
50 typedef typename Traits_::ValueType ValueType;
51 typedef typename Traits_::GradientType GradientType;
52 typedef typename Traits_::HessianType HessianType;
64 ValueType
value(
const PointType& point)
69 GradientType gradient(
const PointType& point)
76 const Function_& _function;
101 template<
typename Function_>
107 static_assert(Function_::ImageType::is_vector,
"only vector fields are supported");
115 static constexpr bool can_value = Function_::can_grad;
116 static constexpr bool can_grad =
false;
117 static constexpr bool can_hess =
false;
119 template<
typename Traits_>
124 typedef typename Traits_::DataType DataType;
125 typedef typename Traits_::PointType PointType;
126 typedef typename Traits_::ValueType ValueType;
127 typedef typename Traits_::GradientType GradientType;
128 typedef typename Traits_::HessianType HessianType;
141 ValueType
value(
const PointType& point)
160 const Function_& _function;
185 template<
typename Function_>
191 static_assert(Function_::ImageType::is_vector,
"only vector fields are supported; use ScalarCurl for scalar functions");
199 static constexpr bool can_value = Function_::can_grad;
200 static constexpr bool can_grad = Function_::can_hess;
201 static constexpr bool can_hess =
false;
203 template<
typename Traits_>
208 typedef typename Traits_::DataType DataType;
209 typedef typename Traits_::PointType PointType;
210 typedef typename Traits_::ValueType ValueType;
211 typedef typename Traits_::GradientType GradientType;
212 typedef typename Traits_::HessianType HessianType;
220 template<
typename T_,
int s_,
int sm_,
int sn_>
224 curl[0] = -
grad[1][0];
225 curl[1] = +
grad[0][1];
229 template<
typename T_,
int n_,
int sm1_,
int sn1_,
int sl_,
int sm_,
int sn_>
230 static Tiny::Matrix<T_, 2, n_, sm1_, sn1_> compute(
const Tiny::Tensor3<T_, 2, 2, n_, sl_, sm_, sn_>&
grad)
233 curl[0] = -
grad[1][0];
234 curl[1] = +
grad[0][1];
239 template<
typename T_,
int s_,
int sm_,
int sn_>
249 template<
typename T_,
int n_,
int sm1_,
int sn1_,
int sl_,
int sm_,
int sn_>
250 static Tiny::Matrix<T_, 3, n_, sm1_, sn1_> compute(
const Tiny::Tensor3<T_, 3, 3, n_, sl_, sm_, sn_>&
grad)
260 explicit Evaluator(
const Curl& function) :
265 ValueType
value(
const PointType& point)
270 GradientType gradient(
const PointType& point)
277 const Function_& _function;
286 explicit Curl(
const Function_& function) :
302 template<
typename Function_>
308 static_assert(Function_::ImageType::is_scalar,
"only scalar functions are supported; use Curl for vector fields");
316 static constexpr bool can_value = Function_::can_grad;
317 static constexpr bool can_grad = Function_::can_hess;
318 static constexpr bool can_hess =
false;
320 template<
typename Traits_>
325 typedef typename Traits_::DataType DataType;
326 typedef typename Traits_::PointType PointType;
327 typedef typename Traits_::ValueType ValueType;
328 typedef typename Traits_::GradientType GradientType;
329 typedef typename Traits_::HessianType HessianType;
337 template<
typename T_,
int s_,
int sn_>
346 template<
typename T_,
int sa_,
int sb_,
int sm_,
int sn_>
356 template<
typename T_,
int s_,
int sn_>
366 template<
typename T_,
int sa_,
int sb_,
int sm_,
int sn_>
377 explicit Evaluator(
const ScalarCurl& function) :
382 ValueType
value(
const PointType& point)
387 GradientType gradient(
const PointType& point)
394 const Function_& _function;
431 template<
typename Function_,
bool pos_range_ = true>
437 static_assert(Function_::ImageType::is_scalar,
"For now, we only allow scalar functions... although this should be doable without any major problems.");
441 static constexpr bool pos_range = pos_range_;
443 static_assert(
domain_dim == 2,
"PolarCoordinates are only available for 2 dimenions!");
447 typedef typename Function_::DataType DataType;
449 static constexpr bool can_value = Function_::can_value;
450 static constexpr bool can_grad = Function_::can_grad;
451 static constexpr bool can_hess = Function_::can_hess;
459 _shift(Tiny::Vector<DataType, 2>::null()),
470 _shift(Tiny::Vector<DataType, 2>::null()),
479 _shift(std::move(shift)),
488 _shift(std::move(shift)),
497 template<
typename Traits_>
502 typedef typename Traits_::DataType DataType;
503 typedef typename Traits_::PointType PointType;
504 typedef typename Traits_::ValueType ValueType;
505 typedef typename Traits_::GradientType GradientType;
506 typedef typename Traits_::HessianType HessianType;
517 PointType transform(
const PointType& point)
521 auto p_n = _rotation * (point - _shift);
523 pcoords[0] = p_n.norm_euclid();
524 pcoords[1] = (pcoords[0] < DataType(5)*Math::eps<DataType>()) ? DataType(0) :
Math::acos(p_n[0]/pcoords[0]);
526 if constexpr(pos_range_)
527 pcoords[1] = ((p_n[1] >= DataType(0)) || (pcoords[1] < DataType(3)*Math::eps<DataType>())) ? pcoords[1] : DataType(2)*Math::pi<DataType>()-pcoords[1];
529 pcoords[1] = (p_n[1] < DataType(0)) ? -pcoords[1] : pcoords[1];
533 GradientType compute(
const GradientType& grad_p,
const PointType& pcoords)
538 if(pcoords[0] > DataType(5) * Math::eps<DataType>())
543 return _rotation_t *
grad;
546 HessianType compute(
const HessianType& hess_p,
const GradientType& grad_p,
const PointType& pcoords)
549 const DataType valsin =
Math::sin(pcoords[1]);
550 const DataType valcos =
Math::cos(pcoords[1]);
553 hess[0][1] = hess_p[0][0] * valsin * valcos;
554 if(pcoords[0] > DataType(5) *
Math::sqrt(Math::eps<DataType>()))
556 const DataType r_re = DataType(1) / pcoords[0];
557 hess[0][0] += grad_p[0] *
Math::sqr(valsin) * r_re + DataType(2) * grad_p[1] * valsin * valcos *
Math::sqr(r_re)
558 - DataType(2) * hess_p[0][1] * valsin * valcos * r_re + hess_p[1][1] *
Math::sqr(valsin * r_re);
559 hess[1][1] += grad_p[0] *
Math::sqr(valcos) * r_re - DataType(2) * grad_p[1] * valsin * valcos *
Math::sqr(r_re)
560 + DataType(2) * hess_p[0][1] * valsin * valcos * r_re + hess_p[1][1] *
Math::sqr(valcos * r_re);
566 return _rotation_t *
hess * _rotation;
571 explicit Evaluator(
const PolarCoordinate& function) :
573 _rotation(function._rotation),
574 _shift(function._shift)
579 ValueType
value(
const PointType& point)
581 return _func_eval.value(this->transform(point));
584 GradientType gradient(
const PointType& point)
586 auto p = this->transform(point);
590 HessianType hessian(
const PointType& point)
592 auto p = this->transform(point);
598 const Function_& _function;
static Tiny::Vector< T_, 3, s_ > compute(const Tiny::Matrix< T_, 3, 3, sm_, sn_ > &grad)
3D vector curl operator
Function_::template Evaluator< FuncEvalTraits > _func_eval
our original function evaluator
static Tiny::Vector< T_, 2, s_ > compute(const Tiny::Matrix< T_, 2, 2, sm_, sn_ > &grad)
2D vector curl operator
Analytic Function Curl wrapper.
Curl(const Function_ &function)
Constructor.
Image::Vector< domain_dim > ImageType
this is a vector-valued function
static constexpr int domain_dim
our domain dimension is the same as the input function's
Function_::template Evaluator< FuncEvalTraits > _func_eval
our original function evaluator
Analytic Function Divergence wrapper.
Divergence(const Function_ &function)
Constructor.
Image::Scalar ImageType
this is a vector-valued function
static constexpr int domain_dim
our domain dimension is the same as the input function's
Analytic Function Evaluator base-class template.
Analytic Function interface.
Function_::template Evaluator< EvalTraits< DataType, Function_ > > _func_eval
our original function evaluator
Analytic Function Gradient wrapper.
Image::Vector< domain_dim > ImageType
this is a vector-valued function
Gradient(const Function_ &function)
Constructor.
static constexpr int domain_dim
our domain dimension is the same as the input function's
Function_::template Evaluator< FuncEvalTraits > _func_eval
our original function evaluator
This class is a wrapper transforming a polar-basis function to a euclidean base one.
PolarCoordinate(const Function_ &func, Tiny::Vector< DataType, 2 > shift, Tiny::Vector< DataType, 2 > x_base)
provide shift vector and the first x' basis vector
Function_::ImageType ImageType
this is a vector-valued function
PolarCoordinate(const Function_ &func, DataType theta)
PolarCoordinate(const Function_ &func, Tiny::Vector< DataType, 2 > shift, DataType theta=DataType(0))
theta rot angle, so that x' = rot(theta) * x
static constexpr int domain_dim
our domain dimension is the same as the input function's
static Tiny::Vector< T_, 2, s_ > compute(const Tiny::Vector< T_, 2, sn_ > &grad)
2D scalar curl operator
Function_::template Evaluator< FuncEvalTraits > _func_eval
our original function evaluator
static Tiny::Vector< T_, 3, s_ > compute(const Tiny::Vector< T_, 3, sn_ > &grad)
3D scalar curl operator
Analytic Scalar Function Curl wrapper.
ScalarCurl(const Function_ &function)
Constructor.
static constexpr int domain_dim
our domain dimension is the same as the input function's
Image::Vector< domain_dim > ImageType
this is a vector-valued function
Tiny Matrix class template.
CUDA_HOST_DEVICE Matrix & set_transpose(const Matrix< T_, n_, m_, sma_, sna_ > &a)
Sets this matrix to the transpose of another matrix.
CUDA_HOST_DEVICE Matrix & set_rotation_2d(T_ angle)
Sets this matrix to a 2D rotation matrix.
CUDA_HOST_DEVICE Matrix & set_identity()
Sets this matrix to the identity matrix.
Tiny Tensor3 class template.
Tiny Vector class template.
T_ sqrt(T_ x)
Returns the square-root of a value.
T_ acos(T_ x)
Returns the arccosine of a value.
DT_ calc_opening_angle(DT_ x1, DT_ x2, DT_ y1, DT_ y2)
Calculates the opening angle of two 2D vectors.
T_ sin(T_ x)
Returns the sine of a value.
T_ sqr(T_ x)
Returns the square of a value.
T_ cos(T_ x)
Returns the cosine of a value.
@ 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.
Vector Field Image tag class.