GRALE
deflectionmatrix.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_DEFLECTIONMATRIX_H
27 
28 #define GRALE_DEFLECTIONMATRIX_H
29 
30 #include "graleconfig.h"
31 #include "vector2d.h"
32 #include <errut/errorbase.h>
33 #include <vector>
34 #include <map>
35 
36 namespace grale
37 {
38 
39 class GravitationalLens;
40 
41 class GRALE_IMPORTEXPORT DeflectionMatrix : public errut::ErrorBase
42 {
43 public:
44  DeflectionMatrix();
45  ~DeflectionMatrix();
46 
47  bool startInit();
48  int addDeflectionPoint(Vector2D<double> point);
49  int addDerivativePoint(Vector2D<double> point);
50  int addPotentialPoint(Vector2D<double> point);
51  bool endInit(const std::vector<std::pair<GravitationalLens *, Vector2D<double> > > &basisLenses);
52 
53  bool calculateBasisMatrixProducts(const std::vector<float> &basisWeights, bool calcDeflection, bool calcDerivatives, bool calcPotential);
54 
55  double getAngularScale() const { return m_angularScale; }
56 
57  Vector2D<float> getDeflectionAngle(int index) const { return m_deflectionAngles[index]; }
58  void getDeflectionDerivatives(int index, float *pAxx, float *pAyy, float *pAxy) const { *pAxx = m_derivatives[0][index]; *pAyy = m_derivatives[1][index]; *pAxy = m_derivatives[2][index]; }
59  float getPotential(int index) const { return m_potentialValues[index]; }
60 private:
61  void calculateAngularScale();
62  void clear();
63 
64  bool m_initializing;
65  bool m_initialized;
66 
67  // Used during initialization, to determine for which points which values need to be
68  // calculated.
69 
70  std::map<Vector2D<double>, int> m_deflectionPointSet;
71  std::map<Vector2D<double>, int> m_derivativePointSet;
72  std::map<Vector2D<double>, int> m_potentialPointSet;
73 
74  // The actual points for which the deflections are being calculated, we'll keep these
75  // for debugging purposes
76 
77  std::vector<Vector2D<double> > m_deflectionPoints;
78  std::vector<Vector2D<double> > m_derivativePoints;
79  std::vector<Vector2D<double> > m_potentialPoints;
80 
81  double m_angularScale;
82  int m_numBasisFunctions;
83 
84  std::vector<std::vector<float > > m_deflectionMatrix[2]; // stores for each point in the lens plane the deflection angle by each basis function
85  std::vector<std::vector<float> > m_derivativeMatrices[3]; // same, but for the derivatives of the deflection angle
86  std::vector<std::vector<float> > m_potentialMatrix; // same, but for the lens potential
87 
88  std::vector<Vector2D<float> > m_deflectionAngles; // resulting deflection angles, for a specific set of weights
89  std::vector<float> m_derivatives[3]; // resulting derivatives
90  std::vector<float> m_potentialValues; // resulting values of the lens potential
91 };
92 
93 } // end namespace
94 
95 #endif // GRALE_DEFLECTIONMATRIX_H
96