OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
SectorField.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, 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 _CLASSIC_FIELDS_SECTORFIELD_HH_
29 #define _CLASSIC_FIELDS_SECTORFIELD_HH_
30 
31 #include <vector>
32 
33 #include "Fields/Fieldmap.h"
34 
55 class SectorField {
56  public:
59  SectorField(const std::string& file_name);
60 
63  virtual ~SectorField();
64 
82  virtual bool getFieldstrengthPolar
83  (const Vector_t &R_p, Vector_t &E_p, Vector_t &B_p) const = 0;
84 
102  virtual bool getFieldstrength
103  (const Vector_t &R_c, Vector_t &E_c, Vector_t &B_c) const = 0;
104 
112  static void convertToPolar(double* position);
113 
123  static void convertToPolar(const double* position_polar, double* value);
124 
132  static void convertToCartesian(double* position);
133 
143  static void convertToCartesian(const double* position_polar, double* value);
144 
149  virtual std::vector<double> getPolarBoundingBoxMin() const;
150 
155  virtual std::vector<double> getPolarBoundingBoxMax() const;
156 
166  void getFieldDimensions(double &zBegin, double &zEnd,
167  double &rBegin, double &rEnd) const;
168 
178  void getFieldDimensions(double &xIni, double &xFinal,
179  double &yIni, double &yFinal,
180  double &zIni, double &zFinal) const;
181 
186  inline bool isInBoundingBox(const double R_p[]) const;
187 
188  protected:
204  void setPolarBoundingBox(double bbMinR, double bbMinY, double bbMinPhi,
205  double bbMaxR, double bbMaxY, double bbMaxPhi,
206  double bbTolR, double bbTolY, double bbTolPhi);
207 
209  std::vector<double> bbMin_m;
211  std::vector<double> bbMax_m;
213  std::vector<double> polarBBMin_m;
215  std::vector<double> polarBBMax_m;
217  std::string Filename_m;
218 
219  private:
220  std::vector< std::vector<double> > getCorners
221  (double bbMinR, double bbMinPhi, double bbMaxR, double bbMaxPhi);
222 };
223 
224 bool SectorField::isInBoundingBox(const double R_p[]) const {
225  bool inside = R_p[0] >= polarBBMin_m[0] &&
226  R_p[0] <= polarBBMax_m[0] &&
227  R_p[1] >= polarBBMin_m[1] &&
228  R_p[1] <= polarBBMax_m[1] &&
229  R_p[2] >= polarBBMin_m[2] &&
230  R_p[2] <= polarBBMax_m[2];
231  // std::cerr << "BB " << inside << "\n" << R_p[0] << " " << R_p[1] << " " << R_p[2] << "\n"
232  // << polarBBMin_m[0] << " " << polarBBMin_m[1] << " " << polarBBMin_m[2] << "\n"
233  // << polarBBMax_m[0] << " " << polarBBMax_m[1] << " " << polarBBMax_m[2] << std::endl;
234  return inside;
235 }
236 
237 #endif
238 
std::vector< double > bbMin_m
Definition: SectorField.h:209
void setPolarBoundingBox(double bbMinR, double bbMinY, double bbMinPhi, double bbMaxR, double bbMaxY, double bbMaxPhi, double bbTolR, double bbTolY, double bbTolPhi)
Definition: SectorField.cpp:87
virtual ~SectorField()
Definition: SectorField.cpp:52
std::vector< double > bbMax_m
Definition: SectorField.h:211
std::string Filename_m
Definition: SectorField.h:217
bool isInBoundingBox(const double R_p[]) const
Definition: SectorField.h:224
static void convertToCartesian(double *position)
Definition: SectorField.cpp:70
virtual bool getFieldstrengthPolar(const Vector_t &R_p, Vector_t &E_p, Vector_t &B_p) const =0
SectorField(const std::string &file_name)
Definition: SectorField.cpp:41
virtual std::vector< double > getPolarBoundingBoxMax() const
std::vector< std::vector< double > > getCorners(double bbMinR, double bbMinPhi, double bbMaxR, double bbMaxPhi)
void getFieldDimensions(double &zBegin, double &zEnd, double &rBegin, double &rEnd) const
static void convertToPolar(double *position)
Definition: SectorField.cpp:54
virtual std::vector< double > getPolarBoundingBoxMin() const
virtual bool getFieldstrength(const Vector_t &R_c, Vector_t &E_c, Vector_t &B_c) const =0
std::vector< double > polarBBMax_m
Definition: SectorField.h:215
std::vector< double > polarBBMin_m
Definition: SectorField.h:213