TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Polynome.h
1/****************************************************************************
2* Copyright (c) 2022, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef Polynome_included
17#define Polynome_included
18
19#include <TRUSTTab.h>
20
21
22/*! @brief Polynomial in n variables, n <= 4. Coefficients are stored using a DoubleTab.
23 *
24 */
25class Polynome : public Objet_U
26{
27 Declare_instanciable(Polynome);
28
29public :
30 inline Polynome(int n1);
31 inline Polynome(int n1, int n2);
32 inline Polynome(int n1, int n2, int n3);
33 inline Polynome(int n1, int n2, int n3, int n4);
34 inline Polynome(const DoubleTab& );
35 inline int degre(int ) const;
36 inline double& coeff(int n1);
37 inline double& coeff(int n1, int n2);
38 inline double& coeff(int n1, int n2, int n3);
39 inline double& coeff(int n1, int n2, int n3, int n4);
40 inline double coeff(int n1) const;
41 inline double coeff(int n1, int n2) const;
42 inline double coeff(int n1, int n2, int n3) const;
43 inline double coeff(int n1, int n2, int n3, int n4) const;
44 double operator()(double x1) const;
45 double operator()(double x1, double x2) const;
46 double operator()(double x1, double x2, double x3) const;
47 double operator()(double x1, double x2, double x3, double x4) const;
48
49 void derive(int =0);
50 void integre(int =0);
51
52 double derive(double x1) const;
53 double derive(double x1, double x2) const;
54 double derive(double x1, double x2, double x3) const;
55 double derive(double x1, double x2, double x3, double x4) const;
56
57 double integre(double x1) const;
58 double integre(double x1, double x2) const;
59 double integre(double x1, double x2, double x3) const;
60 double integre(double x1, double x2, double x3, double x4) const;
61
65 Polynome& operator *=(double);
66 Polynome& operator /=(double);
67
68private :
69 DoubleTab coeff_;
70};
71
72
73
74/*! @brief Constructs a polynomial in one variable of degree n1.
75 *
76 * @param (int n1) degree of the polynomial
77 */
78inline Polynome::Polynome(int n1) : coeff_(++n1) {}
79
80/*! @brief Constructs a polynomial in 2 variables of degrees n1 and n2.
81 *
82 * @param (int n1) degree of the first variable
83 * @param (int n2) degree of the second variable
84 */
85inline Polynome::Polynome(int n1, int n2) : coeff_(++n1, ++n2) {}
86
87/*! @brief Constructs a polynomial in 3 variables of degrees n1, n2 and n3.
88 *
89 * @param (int n1) degree of the first variable
90 * @param (int n2) degree of the second variable
91 * @param (int n3) degree of the third variable
92 */
93inline Polynome::Polynome(int n1, int n2, int n3) : coeff_(++n1, ++n2, ++n3) {}
94
95/*! @brief Constructs a polynomial in 4 variables of degrees n1, n2, n3 and n4.
96 *
97 * @param (int n1) degree of the first variable
98 * @param (int n2) degree of the second variable
99 * @param (int n3) degree of the third variable
100 * @param (int n4) degree of the fourth variable
101 */
102inline Polynome::Polynome(int n1, int n2, int n3, int n4) : coeff_(++n1, ++n2, ++n3, ++n4) {}
103
104/*! @brief Constructs a polynomial from its coefficient array.
105 *
106 * @param (const DoubleTab& t) the coefficient array of the polynomial (1 to 4 dimensions)
107 */
108inline Polynome::Polynome(const DoubleTab& t) : coeff_(t) {}
109
110/*! @brief Returns the degree of the polynomial with respect to the i-th variable.
111 *
112 * @param (int i) index of the variable
113 * @return (int) degree of the polynomial
114 */
115inline int Polynome::degre(int i) const
116{
117 return coeff_.dimension(i)-1;
118}
119
120/*! @brief Returns the coefficient of the term of degree n1.
121 *
122 * @param (int n1) degree
123 * @return (double&) coefficient
124 */
125inline double& Polynome::coeff(int n1)
126{
127 return coeff_(n1);
128}
129
130/*! @brief Returns the coefficient of the term of degree (n1, n2).
131 *
132 * @param (int n1) degree in first variable
133 * @param (int n2) degree in second variable
134 * @return (double&) coefficient
135 */
136inline double& Polynome::coeff(int n1, int n2)
137{
138 return coeff_(n1, n2);
139}
140
141/*! @brief Returns the coefficient of the term of degree (n1, n2, n3).
142 *
143 * @param (int n1) degree in first variable
144 * @param (int n2) degree in second variable
145 * @param (int n3) degree in third variable
146 * @return (double&) coefficient
147 */
148inline double& Polynome::coeff(int n1, int n2, int n3)
149{
150 return coeff_(n1, n2, n3);
151}
152
153/*! @brief Returns the coefficient of the term of degree (n1, n2, n3, n4).
154 *
155 * @param (int n1) degree in first variable
156 * @param (int n2) degree in second variable
157 * @param (int n3) degree in third variable
158 * @param (int n4) degree in fourth variable
159 * @return (double&) coefficient
160 */
161inline double& Polynome::coeff(int n1, int n2, int n3, int n4)
162{
163 return coeff_(n1, n2, n3, n4);
164}
165
166/*! @brief Returns the coefficient of the term of degree n1 (const).
167 *
168 * @param (int n1) degree
169 * @return (double) coefficient
170 */
171inline double Polynome::coeff(int n1) const
172{
173 return coeff_(n1);
174}
175
176/*! @brief Returns the coefficient of the term of degree (n1, n2) (const).
177 *
178 * @param (int n1) degree in first variable
179 * @param (int n2) degree in second variable
180 * @return (double) coefficient
181 */
182inline double Polynome::coeff(int n1, int n2) const
183{
184 return coeff_(n1, n2);
185}
186
187/*! @brief Returns the coefficient of the term of degree (n1, n2, n3) (const).
188 *
189 * @param (int n1) degree in first variable
190 * @param (int n2) degree in second variable
191 * @param (int n3) degree in third variable
192 * @return (double) coefficient
193 */
194inline double Polynome::coeff(int n1, int n2, int n3) const
195{
196 return coeff_(n1, n2, n3);
197}
198
199/*! @brief Returns the coefficient of the term of degree (n1, n2, n3, n4) (const).
200 *
201 * @param (int n1) degree in first variable
202 * @param (int n2) degree in second variable
203 * @param (int n3) degree in third variable
204 * @param (int n4) degree in fourth variable
205 * @return (double) coefficient
206 */
207inline double Polynome::coeff(int n1, int n2, int n3, int n4) const
208{
209 return coeff_(n1, n2, n3, n4);
210}
211#endif //Polynome_H
212
Objet_U()
Default constructor: assigns a unique identifier to the object (object_id_) and registers the object ...
Definition Objet_U.cpp:54
void derive(int=0)
Not implemented. Does nothing.
Definition Polynome.cpp:198
Polynome(int n1)
Constructs a polynomial in one variable of degree n1.
Definition Polynome.h:78
double & coeff(int n1)
Returns the coefficient of the term of degree n1.
Definition Polynome.h:125
Polynome & operator/=(double)
Not implemented. Does nothing. Returns *this.
Definition Polynome.cpp:311
Polynome & operator+=(const Polynome &)
Not implemented. Does nothing. Returns *this.
Definition Polynome.cpp:279
Polynome & operator*=(const Polynome &)
Not implemented. Does nothing. Returns *this.
Definition Polynome.cpp:295
double operator()(double x1) const
Evaluates the polynomial at point x1.
Definition Polynome.cpp:51
void integre(int=0)
Not implemented. Does nothing.
Definition Polynome.cpp:205
int degre(int) const
Returns the degree of the polynomial with respect to the i-th variable.
Definition Polynome.h:115
Polynome & operator-=(const Polynome &)
Not implemented. Does nothing. Returns *this.
Definition Polynome.cpp:287