Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
polynomial.hpp
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2//
3// Copyright (C) 2024 - 2025 by the Vulpes authors.
4// This file is part of Vulpes.
5//
6// Vulpes is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// Vulpes is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Vulpes. If not, see <http://www.gnu.org/licenses/>.
18//
19// ----------------------------------------------------------------------
20
21// Author: Matteo Caldana <matteo.caldana@polimi.it>
22
23#ifndef VULPES_POLYNOMIALS_POLYNOMIAL_HPP_
24#define VULPES_POLYNOMIALS_POLYNOMIAL_HPP_
25
26#include <cstddef>
27#include <ostream>
28#include <vector>
29
30#include <Eigen/Dense>
31
34
35namespace vulpes {
36namespace polynomial {
37
45template <typename T, std::size_t Dim, typename Polynomial>
47 public:
51 T evaluate(const T* x) const { return self()->evaluate(x); }
55 T evaluate(const Eigen::Vector<T, Dim>& x) const {
56 return self()->evaluate(x);
57 }
58
61 template <bool SimplexData>
64 monomial_integrals) const {
65 return self()->integrate(monomial_integrals);
66 }
67
70 Eigen::Vector<Polynomial, Dim> gradient() const { return self()->gradient(); }
74 Polynomial derivative(std::size_t component) const {
75 return self()->derivative(component);
76 }
77
80 Polynomial primitive(std::size_t component) const {
81 return self()->primitive(component);
82 }
83
84 Polynomial& operator+=(const Polynomial& other) { return (*self()) += other; }
85 Polynomial& operator-=(const Polynomial& other) { return (*self()) -= other; }
86 Polynomial& operator*=(const Polynomial& other) { return (*self()) *= other; }
87 Polynomial& operator*=(const T& scalar) { return (*self()) *= scalar; }
88 friend Polynomial operator+(Polynomial lhs, const Polynomial& rhs) {
89 return lhs += rhs;
90 }
91 friend Polynomial operator-(Polynomial lhs, const Polynomial& rhs) {
92 return lhs -= rhs;
93 }
94 friend Polynomial operator*(Polynomial lhs, const Polynomial& rhs) {
95 return lhs *= rhs;
96 }
97 friend Polynomial operator*(const T& lhs, Polynomial rhs) {
98 return rhs *= lhs;
99 }
100 friend Polynomial operator*(Polynomial lhs, const T& rhs) {
101 return lhs *= rhs;
102 }
103
104 protected:
105 Polynomial* self() { return static_cast<Polynomial*>(this); }
106 const Polynomial* self() const {
107 return static_cast<const Polynomial*>(this);
108 }
109};
110
111} // namespace polynomial
112} // namespace vulpes
113
114#endif // VULPES_POLYNOMIALS_POLYNOMIAL_HPP_
Base template class for a general polynomial.
Definition polynomial.hpp:46
Polynomial primitive(std::size_t component) const
Compute the primitive of the polynomial.
Definition polynomial.hpp:80
Polynomial & operator+=(const Polynomial &other)
Definition polynomial.hpp:84
friend Polynomial operator*(Polynomial lhs, const Polynomial &rhs)
Definition polynomial.hpp:94
Polynomial derivative(std::size_t component) const
Compute the derivative of the polynomial.
Definition polynomial.hpp:74
friend Polynomial operator+(Polynomial lhs, const Polynomial &rhs)
Definition polynomial.hpp:88
T evaluate(const T *x) const
Evaluate the polynomial in a given point passed as a row array.
Definition polynomial.hpp:51
Polynomial & operator-=(const Polynomial &other)
Definition polynomial.hpp:85
Polynomial & operator*=(const Polynomial &other)
Definition polynomial.hpp:86
const Polynomial * self() const
Definition polynomial.hpp:106
T integrate(const datastructure::SimplexDataView< Dim, SimplexData, T, std::size_t > &monomial_integrals) const
Integrate the polynomial given the monomials integrals.
Definition polynomial.hpp:62
Eigen::Vector< Polynomial, Dim > gradient() const
Compute the gradient of the polynomial.
Definition polynomial.hpp:70
friend Polynomial operator*(const T &lhs, Polynomial rhs)
Definition polynomial.hpp:97
friend Polynomial operator*(Polynomial lhs, const T &rhs)
Definition polynomial.hpp:100
friend Polynomial operator-(Polynomial lhs, const Polynomial &rhs)
Definition polynomial.hpp:91
Polynomial * self()
Definition polynomial.hpp:105
Polynomial & operator*=(const T &scalar)
Definition polynomial.hpp:87
T evaluate(const Eigen::Vector< T, Dim > &x) const
Evaluate the polynomial in a given point.
Definition polynomial.hpp:55
Template class to represent and operate on polynomials.
Definition polynomial1d.hpp:44
T evaluate(const T &x) const
Evaluates the polynomial at a given point using Horner's method.
Definition polynomial1d.hpp:222
Eigen::Vector< Polynomial< T >, 1 > gradient() const
Computes the derivative of the polynomial.
Definition polynomial1d.hpp:136
Polynomial< T > primitive(const T &c=T(0)) const
Computes the indefinite integral (primitive) of the polynomial.
Definition polynomial1d.hpp:175
Polynomial< T > derivative() const
Computes the derivative of the polynomial.
Definition polynomial1d.hpp:113
T integrate(const T &left, const T &right) const
Computes the definite integral of the polynomial between two bounds.
Definition polynomial1d.hpp:163
std::conditional_t< Dim==2, TriMatrix< Simplex, false, DataType, IndexType, const DataType * >, std::conditional_t< Dim==3, TetraTensor< Simplex, false, DataType, IndexType, const DataType * >, const DataType * > > SimplexDataView
Definition tensor.hpp:507
Definition monomial.hpp:39
Definition cell_manager.hpp:38