GRALE
nfwlens.h
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 
26 #ifndef GRALE_NFWLENS_H
27 
28 #define GRALE_NFWLENS_H
29 
30 #include "graleconfig.h"
31 #include "symmetriclens.h"
32 #include "realtype.h"
33 
34 namespace grale
35 {
36 
37 class GRALE_IMPORTEXPORT NFWLensParams : public GravitationalLensParams
38 {
39 public:
40  NFWLensParams();
41  NFWLensParams(double rho_s, double theta_s);
42  ~NFWLensParams();
43 
44  bool write(serut::SerializationInterface &si) const;
45  bool read(serut::SerializationInterface &si);
46  GravitationalLensParams *createCopy() const;
47 
48  double get3DDensityScale() const { return m_densityScale3D; }
49  double getAngularRadiusScale() const { return m_angularRadiusScale; }
50 private:
51  double m_densityScale3D;
52  double m_angularRadiusScale;
53 };
54 
89 class GRALE_IMPORTEXPORT NFWLens : public SymmetricLens
90 {
91 public:
92  NFWLens();
93  ~NFWLens();
94 
95  bool getAlphaVectorDerivatives(Vector2D<double> theta, double &axx, double &ayy, double &axy) const;
96  bool getProjectedPotential(double D_s, double D_ds, Vector2D<double> theta, double *pPotentialValue) const;
97  double getMassInside(double thetaLength) const;
98  double getProfileSurfaceMassDensity(double thetaLength) const;
99 private:
100  bool processParameters(const GravitationalLensParams *params);
101  static double F(double x);
102  static double DF(double x);
103  static double P(double x);
104 
105  double m_deflectionScale;
106  double m_angularRadiusScale;
107  double m_potentialScale;
108  double m_massScale;
109  double m_densityScale;
110 };
111 
112 inline double NFWLens::F(double x)
113 {
114  if (x < 1.0)
115  {
116  double tmp = SQRT(1.0-x*x);
117  return ATANH(tmp)/tmp;
118  }
119  else if (x > 1.0)
120  {
121  double tmp = SQRT(x*x-1.0);
122  return ATAN(tmp)/tmp;
123  }
124  return 1.0;
125 }
126 
127 inline double NFWLens::DF(double x)
128 {
129  double x2 = x*x;
130 
131  return (1.0-x2*F(x))/(x*(x2-1.0));
132 }
133 
134 inline double NFWLens::P(double x)
135 {
136  if (x < 1.0)
137  {
138  double l = LN(x/2);
139  double at = ATANH(SQRT(1.0-x*x));
140  return l*l - at*at;
141  }
142  else if (x > 1.0)
143  {
144  double l = LN(x/2);
145  double at = ATAN(SQRT(x*x-1.0));
146  return l*l + at*at;
147  }
148  return 0.48045301391820142465;
149 }
150 
151 } // end namespace
152 
153 #endif // GRALE_NFWLENS_H
154