OPALX (Object Oriented Parallel Accelerator Library for Exascal)
MINIorX
OPALX
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
"
32
#include "
DifferentialOperator.h
"
33
34
namespace
polynomial
{
35
36
RecursionRelation::RecursionRelation
():
power_m
(0),
highestXorder_m
(10) {
37
std::vector<int> poly(1, 1);
38
operator_m
.setPolynomial(poly, 0, 0);
39
}
40
41
RecursionRelation::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++) {
47
applyOperator
();
48
}
49
}
50
51
RecursionRelation::RecursionRelation
(
const
RecursionRelation
&doperator):
52
operator_m
(
DifferentialOperator
(doperator.
operator_m
)),
53
power_m
(doperator.
power_m
),
highestXorder_m
(doperator.
highestXorder_m
) {
54
}
55
56
RecursionRelation::~RecursionRelation
() {
57
}
58
59
RecursionRelation
&
RecursionRelation::operator=
(
60
const
RecursionRelation
&recursion) {
61
operator_m
= recursion.
operator_m
;
62
power_m
= recursion.
power_m
;
63
highestXorder_m
= recursion.
highestXorder_m
;
64
return
*
this
;
65
}
66
67
void
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
*/
75
void
RecursionRelation::applyOperator
() {
76
/* Differential operator has 3 terms, make three copies of current operator */
77
DifferentialOperator
firstTerm(
operator_m
);
78
DifferentialOperator
secondTerm(
operator_m
);
79
DifferentialOperator
thirdTerm(
operator_m
);
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 */
99
operator_m
=
DifferentialOperator
(firstTerm);
100
operator_m
.addOperator(secondTerm);
101
operator_m
.addOperator(thirdTerm);
102
}
103
104
}
DifferentialOperator.h
RecursionRelation.h
polynomial
Definition
DifferentialOperator.cpp:32
polynomial::DifferentialOperator
Definition
DifferentialOperator.h:52
polynomial::DifferentialOperator::multiplyPolynomial
void multiplyPolynomial(const Polynomial &poly)
Definition
DifferentialOperator.cpp:111
polynomial::DifferentialOperator::differentiateX
void differentiateX()
Definition
DifferentialOperator.cpp:87
polynomial::DifferentialOperator::doubleDifferentiateS
void doubleDifferentiateS()
Definition
DifferentialOperator.cpp:99
polynomial::Polynomial
Definition
Polynomial.h:51
polynomial::RecursionRelation::highestXorder_m
std::size_t highestXorder_m
Definition
RecursionRelation.h:119
polynomial::RecursionRelation::~RecursionRelation
~RecursionRelation()
Definition
RecursionRelation.cpp:56
polynomial::RecursionRelation::operator=
RecursionRelation & operator=(const RecursionRelation &recursion)
Definition
RecursionRelation.cpp:59
polynomial::RecursionRelation::truncate
void truncate(std::size_t highestXorder)
Definition
RecursionRelation.cpp:67
polynomial::RecursionRelation::RecursionRelation
RecursionRelation()
Definition
RecursionRelation.cpp:36
polynomial::RecursionRelation::applyOperator
void applyOperator()
Definition
RecursionRelation.cpp:75
polynomial::RecursionRelation::operator_m
DifferentialOperator operator_m
Definition
RecursionRelation.h:117
polynomial::RecursionRelation::power_m
std::size_t power_m
Definition
RecursionRelation.h:118