QUGaR 0.0.4
Loading...
Searching...
No Matches
polynomial_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_POLYNOMIAL_TP_HPP
12#define QUGAR_IMPL_POLYNOMIAL_TP_HPP
13
20
21#include <qugar/bbox.hpp>
23#include <qugar/point.hpp>
25#include <qugar/types.hpp>
26
27#include <cassert>
28#include <vector>
29
30namespace qugar::impl {
31
36template<int dim, int range> class PolynomialTP : public DomainFunc<dim, range>
37{
38public:
40 using CoefsType = std::conditional_t<range == 1, real, Point<range>>;
41
47 explicit PolynomialTP(const TensorSizeTP<dim> &order);
48
53 PolynomialTP(const TensorSizeTP<dim> &order, const CoefsType &value);
54
61 PolynomialTP(const TensorSizeTP<dim> &order, const std::vector<CoefsType> &coefs);
62
63protected:
66
70 std::vector<CoefsType> coefs_;
71
72public:
76 [[nodiscard]] std::size_t get_num_coefs() const;
77
81 [[nodiscard]] const std::vector<CoefsType> &get_coefs() const;
82
86 [[nodiscard]] const TensorSizeTP<dim> &get_order() const;
87
92 [[nodiscard]] int get_order(int dir) const;
93
101 [[nodiscard]] const CoefsType &get_coef(int index) const;
102
110 [[nodiscard]] CoefsType &get_coef(int index);
111
120 [[nodiscard]] const CoefsType &get_coef(const TensorIndexTP<dim> &index) const;
121
131
136 [[nodiscard]] int get_degree(int dir) const;
137
143 void transform_image(const BoundBox<range> &old_domain, const BoundBox<range> &new_domain);
144
150 void coefs_linear_transform(const real scale, const CoefsType &shift);
151};
152
153// /**
154// * @brief Iterator for edges of tensor product elements.
155// *
156// * @tparam N Dimension of the parametric domain.
157// */
158// template<int N> struct PolynomialTPEdgeIt
159// {
160// /**
161// * @brief Constructor.
162// *
163// * @param _order Order of the element along all the parametric directions.
164// * @param _edge_id Id of the element's edge (following lexicographical convention).
165// */
166// PolynomialTPEdgeIt(const Vector<int, N> &_order, const int _edge_id)
167// : act_dir(getActiveDir(_edge_id)), order(_order), i(), min(), max(), valid(true)
168// {
169// this->setMinMax(_order, _edge_id);
170// }
171
172// /**
173// * @brief Increments the iterator position.
174// */
175// PolynomialTPEdgeIt &operator++()
176// {
177// if (++i(act_dir) < max(act_dir))
178// return *this;
179// valid = false;
180// return *this;
181// }
182
183// /**
184// * @brief Returns a reference to the current tensor index.
185// *
186// * @return Current tensor index.
187// */
188// const Vector<int, N> &operator()() const { return i; }
189
190// /**
191// * @brief Gets the flat index of the current iterator's position.
192// * @return Flat index of the position.
193// */
194// int getFlatIndex() const
195// {
196// assert(valid && "Iterator is not in a valid state");
197// return util::toFlatIndex(this->order, i);
198// }
199
200// /**
201// * @brief Checks whether or not the iteration is valid
202// * of not (reached the end).
203// *
204// * @return True if the iterator is in a valid state, false otherwise.
205// */
206// bool operator~() const { return valid; }
207
208// /**
209// * @brief Resets the iterator to a valid state setting its tensor
210// * index to the beginning of the edge.
211// */
212// void reset()
213// {
214// this->i(act_dir) = 0;
215// this->valid = true;
216// }
217
218// /// Active parametric direction of the edge.
219// const int act_dir;
220
221// private:
222// /// Order of the element along all the parametric directions.
223// const Vector<int, N> order;
224// /// Tensor index of the iterator.
225// Vector<int, N> i;
226// /// Minimum and maximum tensor dimensions of the edge.
227// Vector<int, N> min, max;
228// /// Flag indicating if the iterator is in a valid state.
229// bool valid;
230
231
232// /**
233// * @brief Sets the minimum and maximum tensor dimensions of the edge.
234// *
235// * @param _order Polynomial order of the element along the parametric directions.
236// * @param _edge_id If of the edge.
237// */
238// void setMinMax(const Vector<int, N> &_order, const int _edge_id)
239// {
240// if constexpr (N == 2) {
241// if (_edge_id < 2) {
242// min(0) = _edge_id == 0 ? 0 : (_order(0) - 1);
243// } else {
244// min(1) = _edge_id == 2 ? 0 : (_order(1) - 1);
245// }
246// } else// if constexpr (N == 3)
247// {
248// if (_edge_id < 4) {
249// min(0) = (_edge_id % 2) == 0 ? 0 : (_order(0) - 1);
250// min(1) = (_edge_id / 2) == 0 ? 0 : (_order(1) - 1);
251// } else if (_edge_id < 8) {
252// min(0) = ((_edge_id - 4) % 2) == 0 ? 0 : (_order(0) - 1);
253// min(2) = ((_edge_id - 4) / 2) == 0 ? 0 : (_order(2) - 1);
254// } else {
255// min(1) = ((_edge_id - 8) % 2) == 0 ? 0 : (_order(1) - 1);
256// min(2) = ((_edge_id - 8) / 2) == 0 ? 0 : (_order(2) - 1);
257// }
258// }
259// this->max = this->min;
260
261// this->min(act_dir) = 0;
262// this->max(act_dir) = _order(act_dir);
263
264// this->i = this->min;
265// }
266
267// /**
268// * @brief Gets the number of edge in an element of dimension N.
269// * @return Number of edge.
270// */
271// static int getNumEdges()
272// {
273// static_assert(N == 2 || N == 3, "Not implemented.");
274// return N == 2 ? 4 : 12;
275// }
276
277// /**
278// * @brief Gets the active parametric direction of an edge.
279// *
280// * @param _edge_id If of the edge.
281// * @return Active parametric direction index.
282// */
283// static int getActiveDir(const int _edge_id)
284// {
285// static_assert(N == 2 || N == 3, "Not implemented.");
286// assert(0 <= _edge_id && _edge_id < getNumEdges());
287
288// int act_dir{ -1 };
289// if constexpr (N == 2) {
290// if (_edge_id < 2)
291// return 1;
292// else
293// return 0;
294// } else// if constexpr (N == 3)
295// {
296// if (_edge_id < 4)
297// return 2;
298// else if (_edge_id < 8)
299// return 1;
300// else
301// return 0;
302// }
303// }
304// };
305
306
307}// namespace qugar::impl
308
309#endif// QUGAR_IMPL_POLYNOMIAL_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 indices.
Definition tensor_index_tp.hpp:95
Class representing a dim-dimensional tensor-product sizes container.
Definition tensor_index_tp.hpp:38
Domain functions.
Definition domain_function.hpp:41
Base class for tensor-product polynomial functions.
Definition polynomial_tp.hpp:37
PolynomialTP(const TensorSizeTP< dim > &order, const std::vector< CoefsType > &coefs)
Constructor.
const CoefsType & get_coef(int index) const
Retrieves the coefficients at the specified index.
PolynomialTP(const TensorSizeTP< dim > &order, const CoefsType &value)
Constructs a constant value PolynomialTP object with the specified order.
int get_degree(int dir) const
Gets the polynomial degree (order - 1) along the direction dir.
std::conditional_t< range==1, real, Point< range > > CoefsType
Coefs type.
Definition polynomial_tp.hpp:40
std::vector< CoefsType > coefs_
Definition polynomial_tp.hpp:70
CoefsType & get_coef(const TensorIndexTP< dim > &index)
Retrieves the coefficient associated with the given tensor index.
const std::vector< CoefsType > & get_coefs() const
Gets the polynomial coefficients.
PolynomialTP(const TensorSizeTP< dim > &order)
Constructor.
void coefs_linear_transform(const real scale, const CoefsType &shift)
Applies a linear transformation to every coefficient.
CoefsType & get_coef(int index)
Retrieves the coefficients at the specified index.
const TensorSizeTP< dim > & get_order() const
Gets the polynomial order along the parametric directions.
const CoefsType & get_coef(const TensorIndexTP< dim > &index) const
Retrieves the coefficient associated with the given tensor index.
TensorSizeTP< dim > order_
Order of the polynomial along each parametric direction.
Definition polynomial_tp.hpp:65
int get_order(int dir) const
Gets the polynomial order (degree + 1) along the direction dir.
std::size_t get_num_coefs() const
Get the number of coeficients.
void transform_image(const BoundBox< range > &old_domain, const BoundBox< range > &new_domain)
Transforms (in place) the coefficients of the polynomial from old_domain to new_domain.
Declaration of a few implicit functions template class ready to be consumed by Algoim.
Definition affine_transf.hpp:28
double real
Definition types.hpp:18
std::ptrdiff_t index
Definition types.hpp:19
Definition and implementation of Point class.
Declaration of tensor-product index and size related classes.
Declaration of types.