OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
RecursionRelationTwo.cpp
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 #include <cmath>
29 #include <vector>
30 #include <iostream>
31 #include "RecursionRelationTwo.h"
33 #include "TwoPolynomial.h"
34 
35 namespace polynomial {
36 
37 RecursionRelationTwo::RecursionRelationTwo(): power_m(0), highestXorder_m(10) {
38  std::vector<int> poly2(1, 1);
39  std::vector<std::vector<int>> poly1;
40  poly1.push_back(poly2);
41  TwoPolynomial poly(poly1);
42  operator_m.setPolynomial(poly, 0, 0);
43 }
44 
46  const std::size_t &highestXorder):
47  power_m(power), highestXorder_m(highestXorder) {
48  std::vector<int> poly2(1, 1);
49  std::vector<std::vector<int>> poly1;
50  poly1.push_back(poly2);
51  TwoPolynomial poly(poly1);
52  operator_m.setPolynomial(poly, 0, 0);
53  for (std::size_t i = 0; i < power_m; i++) {
54  applyOperator();
55  truncate(highestXorder);
56  sortTerms();
57  }
58 }
59 
61  const RecursionRelationTwo &doperator):
62  operator_m(DifferentialOperatorTwo(doperator.operator_m)),
63  power_m(doperator.power_m), highestXorder_m(doperator.highestXorder_m) {
64 }
65 
67 }
68 
70  const RecursionRelationTwo &recursion) {
71  operator_m = recursion.operator_m;
72  power_m = recursion.power_m;
73  highestXorder_m = recursion.highestXorder_m;
74  return *this;
75 }
76 
77 /* This function increases n by 1 in the differential operator used to find \n
78  * the magnetic scalar potential
79  */
81 /* Differential operator has 3 terms, make three copies of current operator */
85 /* Initialise polynomials
86  * p(x) = s - xs^2 + x^2s^3 - ...
87  * q(x) = 1 - x + x^2 - ...
88  */
89  std::vector<std::vector<int>> p, q;
90  p.resize(highestXorder_m + 1);
91  q.resize(highestXorder_m + 1);
92  for (std::size_t i = 0; i <= highestXorder_m; i++) {
93  p[i].resize(highestXorder_m + 2, 0);
94  q[i].resize(highestXorder_m + 1, 0);
95  p[i][i + 1] = pow(-1, i);
96  q[i][i] = pow(-1, i);
97  }
98 /* Differentiate first term by x, then multiply by p(x) */
99  firstTerm.differentiateX();
100  firstTerm.multiplyPolynomial(TwoPolynomial(p));
101 /* Differentiate second term twice by x */
102  secondTerm.differentiateX();
103  secondTerm.differentiateX();
104 /* Differentiate third term by s, multiply by q(x)
105  * and then differentiate by s again
106  */
107  thirdTerm.differentiateS();
108  thirdTerm.multiplyPolynomial(TwoPolynomial(q));
109  thirdTerm.differentiateS();
110  thirdTerm.multiplyPolynomial(TwoPolynomial(q));
111 /* Add operators to obtain final operator */
112  operator_m = DifferentialOperatorTwo(firstTerm);
113  operator_m.addOperator(secondTerm);
114  operator_m.addOperator(thirdTerm);
115 }
116 
117 }
void setPolynomial(const TwoPolynomial &poly, const std::size_t &x, const std::size_t &s)
void truncate(std::size_t highestXorder)
RecursionRelationTwo & operator=(const RecursionRelationTwo &recursion)
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Definition: TpsMath.h:76
void multiplyPolynomial(const TwoPolynomial &poly)
void addOperator(const DifferentialOperatorTwo &doperator)