OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
Enge.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017, Chris Rogers
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 ENDFIELDMODEL_ENGE_H_
29#define ENDFIELDMODEL_ENGE_H_
30
31#include <iostream>
32#include <vector>
33
35
36namespace endfieldmodel {
37
47 class Enge : public EndFieldModel {
48 public:
50 Enge() : _a(), _lambda(0.) { setEngeDiffIndices(10); }
57 Enge(const std::vector<double> a, double x0, double lambda);
58
60 ~Enge() {}
61
63 Enge* clone() const;
64
69 void rescale(double scaleFactor);
70
72 inline double function(double x, int n) const;
73
75 inline double getEndLength() const;
76
78 inline double getCentreLength() const;
79
81 std::ostream& print(std::ostream& out) const;
82
84 std::vector<double> getCoefficients() const { return _a; }
85
87 void setCoefficients(std::vector<double> a) { _a = a; }
88
90 inline double getLambda() const { return _lambda; }
91
93 inline void setLambda(double lambda) { _lambda = lambda; }
94
96 inline double getX0() const { return _x0; }
97
99 inline void setX0(double x0) { _x0 = x0; }
100
102 inline void setMaximumDerivative(size_t n);
103
108 double getEnge(double x, int n) const;
109
111 inline double getDoubleEnge(double x, int n) const;
112
118 double hN(double x, int n) const;
119
125 double gN(double x, int n) const;
126
132 static void setEngeDiffIndices(size_t n);
133
135 inline static std::vector<std::vector<int> > getQIndex(int n);
136
138 inline static std::vector<std::vector<int> > getHIndex(int n);
139
140 private:
141 Enge(const Enge& enge);
142 Enge& operator=(const Enge& enge);
143 std::vector<double> _a;
144 double _lambda, _x0;
145
147 static std::vector<std::vector<std::vector<int> > > _q;
149 static std::vector<std::vector<std::vector<int> > > _h;
150 };
151
153
154 double Enge::function(double x, int n) const { return getDoubleEnge(x, n); }
155
156 std::vector<std::vector<int> > Enge::getQIndex(int n) { return _q[n]; }
157
158 std::vector<std::vector<int> > Enge::getHIndex(int n) { return _h[n]; }
159
160 double Enge::getDoubleEnge(double x, int n) const {
161 if (n == 0) {
162 return (getEnge(x - _x0, n) + getEnge(-x - _x0, n)) - 1.;
163 } else {
164 if (n % 2 != 0)
165 return getEnge(x - _x0, n) - getEnge(-x - _x0, n);
166 else
167 return getEnge(x - _x0, n) + getEnge(-x - _x0, n);
168 }
169 }
170
171 double Enge::getCentreLength() const { return _x0 / 2.0; }
172
173 double Enge::getEndLength() const { return _lambda; }
174} // namespace endfieldmodel
175
176#endif
std::vector< double > getCoefficients() const
Definition Enge.h:84
Enge & operator=(const Enge &enge)
void rescale(double scaleFactor)
Definition Enge.cpp:161
void setMaximumDerivative(size_t n)
Definition Enge.h:152
Enge * clone() const
Definition Enge.cpp:156
double getEndLength() const
Definition Enge.h:173
std::vector< double > _a
Definition Enge.h:143
double getDoubleEnge(double x, int n) const
Definition Enge.h:160
void setLambda(double lambda)
Definition Enge.h:93
double getX0() const
Definition Enge.h:96
static std::vector< std::vector< std::vector< int > > > _h
Definition Enge.h:149
static std::vector< std::vector< std::vector< int > > > _q
Definition Enge.h:147
double gN(double x, int n) const
Definition Enge.cpp:68
static void setEngeDiffIndices(size_t n)
Definition Enge.cpp:91
void setCoefficients(std::vector< double > a)
Definition Enge.h:87
void setX0(double x0)
Definition Enge.h:99
static std::vector< std::vector< int > > getQIndex(int n)
Definition Enge.h:156
static std::vector< std::vector< int > > getHIndex(int n)
Definition Enge.h:158
double hN(double x, int n) const
Definition Enge.cpp:57
double getLambda() const
Definition Enge.h:90
double function(double x, int n) const
Definition Enge.h:154
double getEnge(double x, int n) const
Definition Enge.cpp:39
std::ostream & print(std::ostream &out) const
Definition Enge.cpp:166
Enge(const Enge &enge)
double getCentreLength() const
Definition Enge.h:171