QUGaR 0.0.4
Loading...
Searching...
No Matches
bezier_tp.hpp
Go to the documentation of this file.
1// --------------------------------------------------------------------------
2//
3// Copyright (C) 2025-present by Pablo Antolin
4//
5// This file is part of the QUGaR library.
6//
7// SPDX-License-Identifier: MIT
8//
9// --------------------------------------------------------------------------
10
11#ifndef QUGAR_IMPL_BEZIER_TP_HPP
12#define QUGAR_IMPL_BEZIER_TP_HPP
13
20
21#include <qugar/bbox.hpp>
26#include <qugar/types.hpp>
27
28#include <algoim/xarray.hpp>
29
30#include <memory>
31#include <vector>
32
33namespace qugar::impl {
34
35template<int dim, int range> class MonomialsTP;
36
41template<int dim, int range = 1> class BezierTP : public PolynomialTP<dim, range>
42{
43public:
46
48 using CoefsType = typename Parent::CoefsType;
49
51 template<typename T> using Value = typename Parent::template Value<T>;
52
54 template<typename T> using Gradient = typename Parent::template Gradient<T>;
55
57 template<typename T> using Hessian = typename Parent::template Hessian<T>;
58
60 template<int N> using Interval = ::algoim::Interval<N>;
61
67 explicit BezierTP(const TensorSizeTP<dim> &order);
68
73 BezierTP(const TensorSizeTP<dim> &order, const CoefsType &value);
74
81 BezierTP(const TensorSizeTP<dim> &order, const std::vector<CoefsType> &coefs);
82
87
93 explicit BezierTP(const MonomialsTP<dim, range> &monomials);
94
100 using DomainFunc<dim, range>::operator();
101
107 using DomainFunc<dim, range>::grad;
108
109
110private:
112 ::algoim::xarray<CoefsType, dim> coefs_xarray_;
113
114public:
119 [[nodiscard]] virtual Value<real> operator()(const Point<dim> &point) const final;
120
125 [[nodiscard]] virtual Value<Interval<dim>> operator()(const Point<dim, Interval<dim>> &point) const final;
126
131 [[nodiscard]] virtual Gradient<real> grad(const Point<dim> &point) const final;
132
137 [[nodiscard]] virtual Gradient<Interval<dim>> grad(const Point<dim, Interval<dim>> &point) const final;
138
143 [[nodiscard]] Hessian<real> virtual hessian(const Point<dim> &point) const final;
144
145private:
151 template<typename T> [[nodiscard]] Value<T> eval_(const Point<dim, T> &point) const;
152
158 template<typename T> [[nodiscard]] Gradient<T> grad_(const Point<dim, T> &point) const;
159
165 template<typename T> [[nodiscard]] Hessian<T> hessian_(const Point<dim, T> &point) const;
166
167public:
181 template<typename T>
182 static Value<T> casteljau(const Point<dim, T> &point,
183 typename std::vector<CoefsType>::const_iterator &coefs,
184 const Vector<int, dim> &order);
185
200 template<typename T>
201 static Vector<Value<T>, dim + 1> casteljau_der(const Point<dim, T> &point,
202 typename std::vector<CoefsType>::const_iterator &coefs,
203 const Vector<int, dim> &order);
204
207 [[nodiscard]] const ::algoim::xarray<CoefsType, dim> &get_xarray() const;
208
209 template<int dim_aux = dim>
210 requires(dim == dim_aux && dim > 1)
211
220 [[nodiscard]] std::shared_ptr<BezierTP<dim - 1, range>> extract_facet(const int local_facet_id) const;
221
231 [[nodiscard]] std::shared_ptr<BezierTP<dim, range>> raise_order(const TensorSizeTP<dim> &new_order) const;
232
239 [[nodiscard]] std::shared_ptr<BezierTP<dim, range>> negate() const;
240
245 template<int range_aux = range>
246 requires(range_aux == range && range == 1)
247 void rescale_domain(const BoundBox<dim> &new_domain);
248
253 template<int range_aux = range>
254 requires(range_aux == range && range == 1)
255 [[nodiscard]] FuncSign sign() const;
256
261 [[nodiscard]] std::shared_ptr<BezierTP<dim, range>> operator*(const BezierTP<dim, range> &rhs) const;
262
268 [[nodiscard]] std::shared_ptr<BezierTP<dim, range>> operator+(const BezierTP<dim, range> &rhs) const;
269
275 [[nodiscard]] std::shared_ptr<BezierTP<dim, range>> operator-(const BezierTP<dim, range> &rhs) const;
276
277
283 template<int sub_dim>
284 [[nodiscard]] std::shared_ptr<BezierTP<sub_dim, range>> compose(const BezierTP<sub_dim, dim> &rhs) const;
285};
286
298template<int dim, int range> static bool is_bezier(const DomainFunc<dim, range> &func)
299{
300 const auto *bzr = dynamic_cast<const BezierTP<dim, range> *>(&func);
301 return bzr != nullptr;
302}
303
304}// namespace qugar::impl
305
306#endif// QUGAR_IMPL_BEZIER_TP_HPP
Definition of Cartesian bounding box class.
Class representing a dim-dimensional Cartesian product bounding box.
Definition bbox.hpp:38
Class representing a dim-dimensional tensor-product sizes container.
Definition tensor_index_tp.hpp:38
dim-dimensional tensor-product Bezier polynomial function.
Definition monomials_tp.hpp:34
std::shared_ptr< BezierTP< dim - 1, range > > extract_facet(const int local_facet_id) const
BezierTP(const MonomialsTP< dim, range > &monomials)
Constructor.
FuncSign sign() const
Returns the sign of the function represented by the Bézier tensor-product using the properties of the...
virtual Value< Interval< dim > > operator()(const Point< dim, Interval< dim > > &point) const final
Evaluator operator.
virtual Hessian< real > hessian(const Point< dim > &point) const final
Hessian evaluator operator.
static Value< T > casteljau(const Point< dim, T > &point, typename std::vector< CoefsType >::const_iterator &coefs, const Vector< int, dim > &order)
Evaluates a Bezier polynomial using the Casteljau's algorithm.
BezierTP(const TensorSizeTP< dim > &order)
Constructor.
::algoim::xarray< CoefsType, dim > coefs_xarray_
dim-dimensional array view of the coefficients.
Definition bezier_tp.hpp:112
Gradient< T > grad_(const Point< dim, T > &point) const
Gradient evaluator operator.
std::shared_ptr< BezierTP< dim, range > > raise_order(const TensorSizeTP< dim > &new_order) const
Raises the order of the Bezier tensor product.
std::shared_ptr< BezierTP< dim, range > > operator*(const BezierTP< dim, range > &rhs) const
Product of two Beziers.
::algoim::Interval< N > Interval
Algoim's interval alias.
Definition bezier_tp.hpp:60
typename Parent::template Hessian< T > Hessian
Hessian type.
Definition bezier_tp.hpp:57
BezierTP(const TensorSizeTP< dim > &order, const CoefsType &value)
Constructs a constant value Bezier tensor product.
BezierTP(const TensorSizeTP< dim > &order, const std::vector< CoefsType > &coefs)
Constructor.
virtual Gradient< real > grad(const Point< dim > &point) const final
Gradient evaluator operator.
BezierTP(const BezierTP< dim, range > &bezier)
Copy constructor.
void rescale_domain(const BoundBox< dim > &new_domain)
Recomputes (in-place) the Bezier coefficients for a new domain (that may not be [0,...
virtual Gradient< Interval< dim > > grad(const Point< dim, Interval< dim > > &point) const final
Gradient evaluator operator.
static Vector< Value< T >, dim+1 > casteljau_der(const Point< dim, T > &point, typename std::vector< CoefsType >::const_iterator &coefs, const Vector< int, dim > &order)
Evaluates the gradient Bezier polynomial using the Casteljau's algorithm.
typename Parent::CoefsType CoefsType
Coefs type.
Definition bezier_tp.hpp:48
virtual Value< real > operator()(const Point< dim > &point) const final
Evaluator operator.
typename Parent::template Value< T > Value
Value type.
Definition bezier_tp.hpp:51
Value< T > eval_(const Point< dim, T > &point) const
Evaluator operator.
std::shared_ptr< BezierTP< dim, range > > operator+(const BezierTP< dim, range > &rhs) const
Addition of two Beziers.
std::shared_ptr< BezierTP< dim, range > > negate() const
Creates a new Bezier tensor product (TP) object that is the negation of the current object.
std::shared_ptr< BezierTP< sub_dim, range > > compose(const BezierTP< sub_dim, dim > &rhs) const
Composes the current Bezier with the given Bezier rhs.
const ::algoim::xarray< CoefsType, dim > & get_xarray() const
Gets a constant reference to the stored xarray view of the polynomial coefficients.
typename Parent::template Gradient< T > Gradient
Gradient type.
Definition bezier_tp.hpp:54
Hessian< T > hessian_(const Point< dim, T > &point) const
Hessian evaluator operator.
std::shared_ptr< BezierTP< dim, range > > operator-(const BezierTP< dim, range > &rhs) const
Subtraction of two Beziers.
Domain functions.
Definition domain_function.hpp:41
dim-dimensional tensor-product monomials function.
Definition monomials_tp.hpp:41
Base class for tensor-product polynomial functions.
Definition polynomial_tp.hpp:37
std::conditional_t< range==1, real, Point< range > > CoefsType
Coefs type.
Definition polynomial_tp.hpp:40
Declaration of a few implicit functions template class ready to be consumed by Algoim.
Declaration of tensor-product monomials class.
Definition affine_transf.hpp:28
FuncSign
Definition domain_function.hpp:33
static bool is_bezier(const DomainFunc< dim, range > &func)
Checks if a given DomainFunc object is of type BezierTP.
Definition bezier_tp.hpp:298
::algoim::uvector< T, dim > Vector
Class representing a vector.
Definition vector.hpp:31
Vector< T, dim > Point
Class representing a dim-dimensional Point.
Definition point.hpp:34
Declaration of tensor-product polynomial class.
Declaration of tensor-product index and size related classes.
Declaration of types.