OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
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 
36 namespace 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  private:
140  Enge(const Enge& enge);
141  Enge& operator=(const Enge& enge);
142  std::vector<double> _a;
143  double _lambda, _x0;
144 
146  static std::vector< std::vector< std::vector<int> > > _q;
148  static std::vector< std::vector< std::vector<int> > > _h;
149 };
150 
153 }
154 
155 double Enge::function(double x, int n) const {
156  return getDoubleEnge(x, n);
157 }
158 
159 std::vector< std::vector<int> > Enge::getQIndex(int n) {
160  return _q[n];
161 }
162 
163 std::vector< std::vector<int> > Enge::getHIndex(int n) {
164  return _h[n];
165 }
166 
167 double Enge::getDoubleEnge(double x, int n) const {
168  if (n == 0) {
169  return (getEnge(x-_x0, n)+getEnge(-x-_x0, n))-1.;
170  } else {
171  if (n%2 != 0) return getEnge(x-_x0, n)-getEnge(-x-_x0, n);
172  else return getEnge(x-_x0, n)+getEnge(-x-_x0, n);
173  }
174 }
175 
176 double Enge::getCentreLength() const {
177  return _x0/2.0;
178 }
179 
180 double Enge::getEndLength() const {
181  return _lambda;
182 }
183 }
184 
185 #endif
double function(double x, int n) const
Definition: Enge.h:155
double getX0() const
Definition: Enge.h:96
static std::vector< std::vector< int > > getHIndex(int n)
Definition: Enge.h:163
std::vector< double > getCoefficients() const
Definition: Enge.h:84
double getEnge(double x, int n) const
Definition: Enge.cpp:40
void setLambda(double lambda)
Definition: Enge.h:93
double getEndLength() const
Definition: Enge.h:180
void setMaximumDerivative(size_t n)
Definition: Enge.h:151
static std::vector< std::vector< int > > getQIndex(int n)
Definition: Enge.h:159
double getCentreLength() const
Definition: Enge.h:176
static std::vector< std::vector< std::vector< int > > > _h
Definition: Enge.h:148
void setX0(double x0)
Definition: Enge.h:99
void setCoefficients(std::vector< double > a)
Definition: Enge.h:87
std::ostream & print(std::ostream &out) const
Definition: Enge.cpp:167
static std::vector< std::vector< std::vector< int > > > _q
Definition: Enge.h:146
static void setEngeDiffIndices(size_t n)
Definition: Enge.cpp:91
Enge & operator=(const Enge &enge)
std::vector< double > _a
Definition: Enge.h:142
double getDoubleEnge(double x, int n) const
Definition: Enge.h:167
double hN(double x, int n) const
Definition: Enge.cpp:58
double _lambda
Definition: Enge.h:143
Enge * clone() const
Definition: Enge.cpp:157
double getLambda() const
Definition: Enge.h:90
double gN(double x, int n) const
Definition: Enge.cpp:69
void rescale(double scaleFactor)
Definition: Enge.cpp:162