TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Polynome.cpp
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#include <Polynome.h>
17
18Implemente_instanciable(Polynome,"Polynome",Objet_U);
19
20
21
22/*! @brief Writes the coefficient array to an output stream.
23 *
24 * @param (Sortie& os) the output stream to use
25 * @return (Sortie&) the modified output stream
26 */
28{
29 os << coeff_;
30 return os;
31}
32
33
34/*! @brief Reads the coefficient array from an input stream.
35 *
36 * @param (Entree& is) the input stream to use
37 * @return (Entree&) the modified input stream
38 */
40{
41 is >> coeff_;
42 return is;
43}
44
45
46/*! @brief Evaluates the polynomial at point x1.
47 *
48 * @param (double x1) evaluation point
49 * @return (double) value of the polynomial
50 */
51double Polynome::operator()(double x1) const
52{
53 int n=coeff_.dimension(0);
54 int i=0;
55 double xi=1;
56 double sum=0;
57 while(n--)
58 {
59 sum+=coeff_(i++)*xi;
60 xi*=x1;
61 }
62 return sum;
63}
64
65/*! @brief Evaluates the polynomial at point (x1, x2).
66 *
67 * @param (double x1) first variable evaluation point
68 * @param (double x2) second variable evaluation point
69 * @return (double) value of the polynomial
70 */
71double Polynome::operator()(double x1, double x2) const
72{
73 int n1=coeff_.dimension(0);
74 int n2=coeff_.dimension(1);
75 int i=0;
76 int j=0;
77 double xi=1;
78 double xj=1;
79 double sum=0;
80 while(n1--)
81 {
82 xj=1.;
83 n2=coeff_.dimension(1);
84 j=0;
85 while(n2--)
86 {
87 sum+=coeff_(i,j++)*xj*xi;
88 xj*=x2;
89 }
90 xi*=x1;
91 i++;
92 }
93 return sum;
94}
95
96/*! @brief Evaluates the polynomial at point (x1, x2, x3).
97 *
98 * @param (double x1) first variable evaluation point
99 * @param (double x2) second variable evaluation point
100 * @param (double x3) third variable evaluation point
101 * @return (double) value of the polynomial
102 */
103double Polynome::operator()(double x1, double x2, double x3) const
104{
105 int n1=coeff_.dimension(0);
106 int n2=coeff_.dimension(1);
107 int n3=coeff_.dimension(2);
108 int i=0;
109 int j=0;
110 int k=0;
111 double xi=1;
112 double xj=1;
113 double xk=1;
114 double sum=0;
115 while(n1--)
116 {
117 xj=1.;
118 n2=coeff_.dimension(1);
119 j=0;
120 while(n2--)
121 {
122 xk=1.;
123 n3=coeff_.dimension(2);
124 k=0;
125 while(n3--)
126 {
127 sum+=coeff_(i,j,k++)*xk*xj*xi;
128 xk*=x3;
129 }
130 xj*=x2;
131 j++;
132 }
133 xi*=x1;
134 i++;
135 }
136 return sum;
137}
138
139/*! @brief Evaluates the polynomial at point (x1, x2, x3, x4).
140 *
141 * @param (double x1) first variable evaluation point
142 * @param (double x2) second variable evaluation point
143 * @param (double x3) third variable evaluation point
144 * @param (double x4) fourth variable evaluation point
145 * @return (double) value of the polynomial
146 */
147double Polynome::operator()(double x1, double x2, double x3, double x4) const
148{
149 int n1=coeff_.dimension(0);
150 int n2=coeff_.dimension(1);
151 int n3=coeff_.dimension(2);
152 int n4=coeff_.dimension(3);
153 int i=0;
154 int j=0;
155 int k=0;
156 int l=0;
157 double xi=1;
158 double xj=1;
159 double xk=1;
160 double xl=1;
161 double sum=0;
162 while(n1--)
163 {
164 xj=1.;
165 n2=coeff_.dimension(1);
166 j=0;
167 while(n2--)
168 {
169 xk=1.;
170 n3=coeff_.dimension(2);
171 k=0;
172 while(n3--)
173 {
174 xl=1.;
175 n4=coeff_.dimension(3);
176 l=0;
177 while(n4--)
178 {
179 sum+=coeff_(i,j,k,l++)*xl*xk*xj*xi;
180 xl*=x4;
181 }
182 xk*=x3;
183 k++;
184 }
185 xj*=x2;
186 j++;
187 }
188 xi*=x1;
189 i++;
190 }
191 return sum;
192}
193
194
195/*! @brief Not implemented. Does nothing.
196 *
197 */
199{
200}
201
202/*! @brief Not implemented. Does nothing.
203 *
204 */
206{
207}
208
209
210/*! @brief Not implemented. Returns 0.
211 *
212 */
213double Polynome::derive(double ) const
214{
215 return 0;
216}
217
218/*! @brief Not implemented. Returns 0.
219 *
220 */
221double Polynome::derive(double , double ) const
222{
223 return 0;
224}
225
226/*! @brief Not implemented. Returns 0.
227 *
228 */
229double Polynome::derive(double , double , double ) const
230{
231 return 0;
232}
233
234/*! @brief Not implemented. Returns 0.
235 *
236 */
237double Polynome::derive(double , double , double , double ) const
238{
239 return 0;
240}
241
242
243/*! @brief Not implemented. Returns 0.
244 *
245 */
246double Polynome::integre(double ) const
247{
248 return 0;
249}
250
251/*! @brief Not implemented. Returns 0.
252 *
253 */
254double Polynome::integre(double , double ) const
255{
256 return 0;
257}
258
259/*! @brief Not implemented. Returns 0.
260 *
261 */
262double Polynome::integre(double , double , double ) const
263{
264 return 0;
265}
266
267/*! @brief Not implemented. Returns 0.
268 *
269 */
270double Polynome::integre(double , double , double , double ) const
271{
272 return 0;
273}
274
275
276/*! @brief Not implemented. Does nothing. Returns *this.
277 *
278 */
280{
281 return *this;
282}
283
284/*! @brief Not implemented. Does nothing. Returns *this.
285 *
286 */
288{
289 return *this;
290}
291
292/*! @brief Not implemented. Does nothing. Returns *this.
293 *
294 */
296{
297 return *this;
298}
299
300/*! @brief Not implemented. Does nothing. Returns *this.
301 *
302 */
304{
305 return *this;
306}
307
308/*! @brief Not implemented. Does nothing. Returns *this.
309 *
310 */
312{
313 return *this;
314}
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
Polynomial in n variables, n <= 4. Coefficients are stored using a DoubleTab.
Definition Polynome.h:26
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
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
Polynome & operator-=(const Polynome &)
Not implemented. Does nothing. Returns *this.
Definition Polynome.cpp:287
Base class for output streams.
Definition Sortie.h:52