GRALE
monopolegrid2.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_MONOPOLEGRID2_H
27 
28 #define GRALE_MONOPOLEGRID2_H
29 
30 #include "graleconfig.h"
31 #include "monopolebasisfunction.h"
32 #include <errut/errorbase.h>
33 #include <serut/serializationinterface.h>
34 #include <vector>
35 #include <list>
36 
37 namespace grale
38 {
39 
40 class ImagesData;
41 class GravitationalLens;
42 
43 class GRALE_IMPORTEXPORT MonopoleGrid2 : public errut::ErrorBase
44 {
45 public:
46  MonopoleGrid2();
47  ~MonopoleGrid2();
48 
49  bool init(const ImagesData &avoidImages, const ImagesData &deflectionPoints,
50  const Real2DFunction &target, const GravitationalLens &differenceDeflection,
51  Vector2D<double> center, double areaSize, int subDiv = 32, double zeroPointFactor = 2.0);
52 
53  int getNumberOfBasisFunctions() const { return m_monoPoleFunctions.size(); }
54  void setBasisWeights(const std::vector<double> &w) { if (w.size() == m_monoPoleWeights.size()) m_monoPoleWeights = w; }
55 
56  double getZeroPoint(int i) const { return m_monoPoleFunctions[i].getZeroPoint(); }
57  double getLengthScale(int i) const { return m_monoPoleFunctions[i].getLengthScale(); }
58  Vector2D<double> getPosition(int i) const { return m_monoPoleCenters[i]; }
59 
60  void prepareFitnessCalculation();
61  void calculateFitness(double *pTotalDeflection, double *pNegative, double scale);
62 
63  bool write(serut::SerializationInterface &si) const;
64  bool read(serut::SerializationInterface &si);
65 private:
66  void clear();
67 
68  std::vector<MonopoleBasisFunction> m_monoPoleFunctions;
69  std::vector<Vector2D<double> > m_monoPoleCenters;
70  std::vector<double> m_monoPoleWeights;
71  std::vector<std::vector<int> > m_pixelDependencies;
72  std::vector<std::vector<int> > m_pointDependencies; // on which monopoles each deflection point depends
73  std::vector<std::vector<Vector2D<double> > > m_pointMonoPoleDeflections; // deflections caused by each monopole at a specific point
74 
75  std::vector<double> m_targetMap;
76  std::vector<double> m_monoPoleMap;
77 
78  std::vector<Vector2D<double> > m_differenceDeflections; // at the points
79  std::vector<Vector2D<double> > m_monoPoleTotalDelections; // at the points
80 
81  Vector2D<double> m_bottomLeft;
82  double m_stepSize;
83  int m_subDiv;
84 };
85 
86 } // end namespace
87 
88 #endif // GRALE_MONOPOLEGRID2_H