OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
TwoPolynomial.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018, Martin Duy Tat
3 * All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * 1. Redistributions of source code must retain the above copyright notice,
7 * this list of conditions and the following disclaimer.
8 * 2. Redistributions in binary form must reproduce the above copyright notice,
9 * this list of conditions and the following disclaimer in the documentation
10 * and/or other materials provided with the distribution.
11 * 3. Neither the name of STFC nor the names of its contributors may be used to
12 * endorse or promote products derived from this software without specific
13 * prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef TWO_POLYNOMIAL_H
29#define TWO_POLYNOMIAL_H
30
56#include <vector>
57
58namespace polynomial {
59
68struct vectorLengths {
69 std::size_t nx;
70 std::size_t ny;
71 std::size_t nx1;
72 std::size_t ny1;
73 std::size_t nx2;
74 std::size_t ny2;
75};
76
77class TwoPolynomial {
78public:
80 TwoPolynomial();
87 explicit TwoPolynomial(const std::vector<std::vector<int>> &coefficients);
89 TwoPolynomial(const TwoPolynomial &poly);
91 TwoPolynomial& operator= (const TwoPolynomial &poly);
93 ~TwoPolynomial();
95 void differentiateX();
97 void differentiateS();
101 void multiplyConstant (const int &constant);
105 void multiplydSfactors(const TwoPolynomial &poly);
112 void convert2Dto1Darray(double *vec1, double *vec2,
113 const vectorLengths &nn,
114 const TwoPolynomial &poly) const;
124 void convolution(double *vec1, double *vec2,
125 const std::size_t &nx, const std::size_t &ny) const;
130 void convert1Dto2Darray(double *vec1, const vectorLengths &nn);
134 void multiplyPolynomial(const TwoPolynomial &poly);
136 void printPolynomial() const;
141 int getCoefficient(const std::size_t &Xorder,
142 const std::size_t &Sorder) const;
148 void setCoefficient(const int &coefficient,
149 const std::size_t &Xorder,
150 const std::size_t &Sorder);
152 std::size_t getMaxXorder() const;
154 std::size_t getMaxSorder() const;
158 void setMaxXorder(const std::size_t &maxXorder);
162 void setMaxSorder(const std::size_t &maxSorder);
164 std::size_t getNdSfactors() const;
166 std::vector<std::size_t> getdSfactors() const;
170 void setdSfactors(const std::vector<std::size_t> &dSfactors);
172 void setZero();
174 bool isZero() const;
179 double evaluatePolynomial(const double &x, const double &s) const;
183 void truncate(const std::size_t &truncateOrder);
189 void addPolynomial(const TwoPolynomial &poly);
196 friend bool operator < (const TwoPolynomial &left,
197 const TwoPolynomial &right);
203 friend bool operator == (const TwoPolynomial &left,
204 const TwoPolynomial &right);
206 friend class PolynomialSum;
207private:
208 std::size_t maxXorder_m;
209 std::size_t maxSorder_m;
210 std::vector<std::vector<int>> coefficients_m;
211 std::vector<std::size_t> dSfactors_m;
212};
213
214inline
215 std::size_t TwoPolynomial::getMaxXorder() const {
216 return maxXorder_m;
217}
218inline
219 std::size_t TwoPolynomial::getMaxSorder() const {
220 return maxSorder_m;
221}
222inline
223 std::size_t TwoPolynomial::getNdSfactors() const {
224 return dSfactors_m.size();
225}
226inline
227 std::vector<std::size_t> TwoPolynomial::getdSfactors() const {
228 return dSfactors_m;
229}
230inline
231 void TwoPolynomial::setdSfactors(
232 const std::vector<std::size_t> &dSfactors) {
233 dSfactors_m = dSfactors;
234}
235inline
236 bool TwoPolynomial::isZero() const {
237 return (maxXorder_m == 0 && maxSorder_m == 0 &&
238 coefficients_m[0][0] == 0);
239}
240inline
241 void TwoPolynomial::truncate(const std::size_t &truncateOrder) {
242 if (truncateOrder < maxXorder_m) {
243 coefficients_m.resize(truncateOrder + 1);
244 maxXorder_m = truncateOrder;
245 }
246}
247
248}
249
250#endif
bool operator<(const TwoPolynomial &left, const TwoPolynomial &right)
bool operator==(const TwoPolynomial &left, const TwoPolynomial &right)