GRALE
gravitationallens.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of GRALE, a library to facilitate the simulation
4  and inversion of gravitational lenses.
5 
6  Copyright (C) 2008-2012 Jori Liesenborgs
7 
8  Contact: jori.liesenborgs@gmail.com
9 
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 
24 */
25 
30 #ifndef GRALE_GRAVITATIONALLENS_H
31 
32 #define GRALE_GRAVITATIONALLENS_H
33 
34 #include "graleconfig.h"
35 #include "vector2d.h"
36 #include <serut/serializationinterface.h>
37 #include <string>
38 
39 namespace grale
40 {
41 
43 class GRALE_IMPORTEXPORT GravitationalLensParams : public errut::ErrorBase
44 {
45 public:
47  virtual ~GravitationalLensParams() { }
48 
50  virtual bool write(serut::SerializationInterface &si) const { setErrorString("Not implemented"); return false; }
51 
53  virtual bool read(serut::SerializationInterface &si) { setErrorString("Not implemented"); return false; }
54 
56  virtual GravitationalLensParams *createCopy() const = 0;
57 };
58 
60 class GRALE_IMPORTEXPORT GravitationalLens : public errut::ErrorBase
61 {
62 public:
64  enum LensType
65  {
70  SIS,
71  NSIE,
72  NSIS,
73  SIE,
84  NFW,
88  TestLensType,
89  MaxLensType
90  };
91 protected:
93  GravitationalLens(LensType t);
94 public:
96 
98  LensType getLensType() const { return m_lensType; }
99 
103  virtual bool init(double D_d, const GravitationalLensParams *pLensParams = 0);
104 
112  bool traceTheta(double D_s, double D_ds, Vector2D<double> theta, Vector2D<double> *pBeta) const;
113 
117  virtual bool getAlphaVector(Vector2D<double> theta, Vector2D<double> *pAlpha) const = 0;
118 
120  virtual bool getAlphaVectorDerivatives(Vector2D<double> theta, double &axx,
121  double &ayy, double &axy) const;
122 
124  static double getInverseMagnification(double D_s, double D_ds, double axx,
125  double ayy, double axy) { double f = D_ds/D_s; return (1.0-f*axx)*(1.0-f*ayy)-f*f*axy*axy; }
126 
128  static void getShearInfo(double D_s, double D_ds, double axx, double ayy,
129  double axy, double *pShearAngle, double *pShearSize) { double f = D_ds/D_s; double g1 = 0.5*(axx-ayy); double g2 = axy; Vector2D<double> gVector(g1, g2); double g = gVector.getLength(); if (g2 >= 0) *pShearAngle = 0.5*ACOS(g1/g); else *pShearAngle = -0.5*ACOS(g1/g); *pShearSize = g*f; }
130 
132  static void getShearInfo(double gamma1, double gamma2,
133  double *pShearAngle, double *pShearSize) { Vector2D<double> gVector(gamma1, gamma2); double g = gVector.getLength(); if (gamma2 >= 0) *pShearAngle = 0.5*ACOS(gamma1/g); else *pShearAngle = -0.5*ACOS(gamma1/g); *pShearSize = g; }
134 
135 
142  virtual double getInverseMagnification(double D_s, double D_ds, Vector2D<double> theta) const;
143 
145  virtual double getSurfaceMassDensity(Vector2D<double> theta) const = 0;
146 
148  double getLensDistance() const { return m_Dd; }
149 
151  void setLensDistance(double D_d) { m_Dd = D_d; }
152 
153  bool getTimeDelay(double z_d, double D_s, double D_ds, Vector2D<double> theta,
154  Vector2D<double> beta, double *pTimeDelay) const;
155  virtual bool getProjectedPotential(double D_s, double D_ds, Vector2D<double> theta,
156  double *pPotentialValue) const;
157 
159  const GravitationalLensParams *getLensParameters() const { return m_pParameters; }
160 
164  virtual void setDerivativeAngularDistanceScale(double distanceScale) { m_derivDistScale = ABS(distanceScale); }
165 
167  bool write(serut::SerializationInterface &si) const;
168 
173  static bool read(serut::SerializationInterface &si, GravitationalLens **pLens, std::string &errorString);
174 
176  bool save(const std::string &fileName) const;
177 
181  static bool load(const std::string &fileName, GravitationalLens **pLens, std::string &errorString);
182 
184  GravitationalLens *createCopy() const;
185 
186  // TODO: experimental
187  // OpenCL stuff
188 
189  virtual bool getSuggestedScales(double *pDeflectionScale, double *pPotentialScale) const;
190  virtual bool getCLParameterCounts(int *pNumIntParams, int *pNumFloatParams) const;
191  virtual bool getCLParameters(double deflectionScale, double potentialScale, int *pIntParams, float *pFloatParams) const;
192 
193  std::string getCLLensProgram(std::string &subRoutineName) const;
194 
195  // like this:
196  // LensQuantities subRoutineName(float2 coord, __global const int *pIntParams, __global const float *pFloatParams)
197  //
198  // typedef struct
199  // {
200  // float alphaX;
201  // float alphaY;
202  // float potential;
203  // float axx;
204  // float ayy;
205  // float axy;
206  // } LensQuantities;
207  virtual std::string getCLProgram(std::string &subRoutineName) const;
208 
209  virtual int getCLSubLenses() const { return -1; }
210 protected:
214  virtual bool processParameters(const GravitationalLensParams *params) = 0;
215 
216  std::string getCLLensQuantitiesStructure() const;
217 private:
218  bool m_init;
219  double m_Dd;
220  LensType m_lensType;
221  GravitationalLensParams *m_pParameters;
222  double m_derivDistScale;
223 };
224 
225 } // end namespace
226 
227 #endif // GRALE_GRAVITATIONALLENS_H
228