OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
RecursionRelation.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 <iostream>
30#include <vector>
31#include "RecursionRelation.h"
33
34namespace polynomial {
35
36RecursionRelation::RecursionRelation(): power_m(0), highestXorder_m(10) {
37 std::vector<int> poly(1, 1);
38 operator_m.setPolynomial(poly, 0, 0);
39}
40
41RecursionRelation::RecursionRelation(const std::size_t &power,
42 const std::size_t &highestXorder):
43 power_m(power), highestXorder_m(highestXorder) {
44 std::vector<int> poly(1, 1);
45 operator_m.setPolynomial(poly, 0, 0);
46 for (std::size_t i = 0; i < power_m; i++) {
48 }
49}
50
52 operator_m(DifferentialOperator(doperator.operator_m)),
53 power_m(doperator.power_m), highestXorder_m(doperator.highestXorder_m) {
54}
55
57}
58
60 const RecursionRelation &recursion) {
61 operator_m = recursion.operator_m;
62 power_m = recursion.power_m;
64 return *this;
65}
66
67void RecursionRelation::truncate(std::size_t highestXorder) {
68 highestXorder_m = highestXorder;
69 operator_m.truncate(highestXorder);
70}
71
72/* This function increases n by 1 in the differential operator used to find \n
73 * the magnetic scalar potential
74 */
76/* Differential operator has 3 terms, make three copies of current operator */
80/* Initialise polynomials
81 * p(x) = 1 - x + x^2 - ...
82 * q(x) = 1 - 2x + 3x^2 - ...
83 */
84 std::vector<int> p, q;
85 for (std::size_t i = 0; i <= highestXorder_m; i++) {
86 p.push_back(pow(-1, i));
87 q.push_back(pow(-1, i) * (i + 1));
88 }
89/* Differentiate first term by x, then multiply by p(x) */
90 firstTerm.differentiateX();
91 firstTerm.multiplyPolynomial(Polynomial(p));
92/* Differentiate second term twice by x */
93 secondTerm.differentiateX();
94 secondTerm.differentiateX();
95/* Differentiate third term by s twice, then multiply by q(x) */
96 thirdTerm.doubleDifferentiateS();
97 thirdTerm.multiplyPolynomial(Polynomial(q));
98/* Add operators to obtain final operator */
100 operator_m.addOperator(secondTerm);
101 operator_m.addOperator(thirdTerm);
102}
103
104}
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Definition: TpsMath.h:76
void truncate(const std::size_t &truncateOrder)
void multiplyPolynomial(const Polynomial &poly)
void setPolynomial(const std::vector< int > &poly, const std::size_t &x, const std::size_t &s)
void addOperator(const DifferentialOperator &doperator)
RecursionRelation & operator=(const RecursionRelation &recursion)
void truncate(std::size_t highestXorder)
DifferentialOperator operator_m