GLAMERDOC++
Gravitational Lensing Code Library
Loading...
Searching...
No Matches
lens.h
1/*
2 * multiplane.h
3 *
4 */
5
6#ifndef MULTIPLANE_H_
7#define MULTIPLANE_H_
8
9#include "quadTree.h"
10#include "utilities_slsim.h"
11#include "planes.h"
12#include "geometry.h"
13
14#include <map>
15
16GLAMER_TEST_USES(LensTest)
17
18
71class Lens{
72public:
73 Lens(long* seed, PosType z_source,CosmoParamSet cosmoset, bool verbose = false);
74 //Lens(InputParams& params, long* my_seed, CosmoParamSet cosmoset, bool verbose = false);
75 Lens(long* seed, PosType z_source,const COSMOLOGY &cosmo, bool verbose = false);
76 //Lens(InputParams& params, long* my_seed, const COSMOLOGY &cosmo, bool verbose = false);
77
78 ~Lens();
79
81 bool set;
82
84 int getNplanes() const {return lensing_planes.size();}
85
87 PosType getfov() const {return fieldofview;};
88 void setfov(PosType fov){fieldofview=fov;};
89
91 void resetFieldNplanes(std::size_t field_Nplanes, bool verbose = false);
92
95 void resetFieldHalos(bool verbose = false);
96
98 void printMultiLens();
99
100
102 PosType getZlens() const{
103 if(flag_switch_main_halo_on)
104 return main_halos[0]->getZlens();
105 else{
106 ERROR_MESSAGE();
107 std::cerr << "error, no main lens present" << std::endl;
108 exit(1);
109 }
110 }
112 PosType getAngDistLens() const{
113 if(flag_switch_main_halo_on)
114 return cosmo.angDist( main_halos[0]->getZlens());
115 else{
116 ERROR_MESSAGE();
117 std::cerr << "error, no main lens present" << std::endl;
118 exit(1);
119 }
120 }
121
122 Utilities::Geometry::SphericalPoint<> getCenter() const {return central_point_sphere;}
123
125 void clearMainHalos(bool verbose=false);
127 template<typename HaloType>
128 void clearMainHalo(bool verbose=false);
129
130
132 //void insertMainHalo(LensHalo* halo,PosType zlens, bool addplanes,bool verbose = false);
133
134/* void insertMainHalo(LensHalo *halo, bool addplanes,bool verbose)
135 {
136// LensHaloNFW * halo = new LensHaloNFW(halo_in);
137 halo->setCosmology(cosmo);
138 main_halos.push_back(halo);
139
140 flag_switch_main_halo_on = true;
141
142 if(addplanes) addMainHaloToPlane(halo);
143 else addMainHaloToNearestPlane(halo);
144
145 combinePlanes(verbose);
146 }
147*/
148
149 template <typename T>
150 void insertMainHalo(const T &halo_in, bool addplanes,bool verbose=false)
151 {
152
153 T * halo = new T(halo_in);
154 halo->setCosmology(cosmo);
155 main_halos.push_back(halo);
156
157 flag_switch_main_halo_on = true;
158
159 if(addplanes) addMainHaloToPlane(halo);
160 else addMainHaloToNearestPlane(halo);
161
162 combinePlanes(verbose);
163 }
164
172 template <typename T>
173 void moveinMainHalo(T &halo_in, bool addplanes,bool verbose=false)
174 {
175 T * halo = new T(std::move(halo_in));
176 halo->setCosmology(cosmo);
177 main_halos.push_back(halo);
178
179 flag_switch_main_halo_on = true;
180
181 if(addplanes) addMainHaloToPlane(halo);
182 else addMainHaloToNearestPlane(halo);
183
184 combinePlanes(verbose);
185 }
186
193 template <typename T>
194 void replaceMainHalo(const T &halo_in,bool addplanes,bool verbose=false)
195 {
196 main_halos.clear();
197
198 T * halo = new T(halo_in);
199 halo->setCosmology(cosmo);
200 main_halos.push_back(halo);
201
202 flag_switch_main_halo_on = true;
203
204 Utilities::delete_container(main_planes);
205 createMainPlanes();
206 combinePlanes(verbose);
207 }
208
219 template <typename T>
220 void insertMainHalos(std::vector<T> &my_halos,bool addplanes, bool verbose=false)
221 {
222 T* ptr;
223 //for(std::size_t i = 0; i < my_halos.size() ; ++i)
224 for(T &h : my_halos){
225 ptr = new T(h);
226 ptr->setCosmology(cosmo);
227 ptr->setDist(cosmo);
228 main_halos.push_back( ptr );
229 if(addplanes) addMainHaloToPlane( ptr );
230 else addMainHaloToNearestPlane( ptr );
231 }
232
233 flag_switch_main_halo_on = true;
234
235 combinePlanes(verbose);
236 }
243 template <typename T>
244 void replaceMainHalos(std::vector<T> &my_halos,bool verbose)
245 {
246
247 main_halos.clear();
248
249 T* ptr;
250 //for(std::size_t i = 0; i < my_halos.size() ; ++i)
251 for(T &h : my_halos){
252 ptr = new T(h);
253 ptr->setCosmology(cosmo);
254 ptr->setDist(cosmo);
255 main_halos.push_back( ptr );
256 }
257
258 flag_switch_main_halo_on = true;
259
260 Utilities::delete_container(main_planes);
261 createMainPlanes();
262 combinePlanes(verbose);
263 }
264
266 //void insertMainHalos(LensHalo** halos, std::size_t Nhalos,bool addplanes,bool verbose = false);
267
269 //void replaceMainHalo(LensHalo* halo,PosType zlens, bool addplanes,bool verbose = false);
270
272 // replaceMainHalos(LensHalo** halos, std::size_t Nhalos,bool verbose = false);
273
274
275// /* \brief Add substructures to the lens.
276//
277// This method is meant for inserting substructure to a main lens. All the substructure will be at
278// one redshift. The mass function follows a power law. The density of substructures is constant within
279// a circular region. The tidal truncation is controlled through the parameter density_contrast which is
280// the average density within the substructures orbit in units of the average density to the universe at
281// the redshift where they are places. For example density_contrast=200 would give them the truncation radius appropriate at R_200.
282// */
283// void insertSubstructures(
284// PosType Rregion /// radius of region in which substructures are inserted (radians)
285// ,PosType center[] /// center of region in which the substructures are inserted (radians)
286// ,PosType NumberDensity /// number density per radian^2 of all substructures
287// ,PosType Mass_min /// minimum mass of substructures
288// ,PosType Mass_max /// maximum mass of substructures
289// ,PosType redshift /// redshift of substructures
290// ,PosType alpha /// index of mass function (dN/dm \propto m^alpha)
291// ,PosType density_contrast ///
292// ,bool verbose
293// );
294//
295// /** \brief This function will randomize the substructure without changing the region, mass function, etc.
296//
297// The Lens::insertSubstructures() function must have been called on this instance of the Lens before.
298// */
299// void resetSubstructure(bool verbose = false);
300//
301
303 std::size_t getNMainHalos() const;
305 template<typename HaloType>
306 std::size_t getNMainHalos() const;
307
309 LensHalo* getMainHalo(std::size_t i);
310
312 template<typename HaloType>
313 HaloType* getMainHalo(std::size_t i);
314
322 void rayshooter(RAY &ray);
323
330 void rayshooterInternal(unsigned long Npoints
331 ,Point *i_points
332 ,bool RSIverbose = false
333 );
334
340 void rayshooterInternal(unsigned long Npoints
341 ,LinkedPoint *i_points
342 ,std::vector<double> &source_zs
343 ,bool RSIverbose = false
344 );
345
346 void rayshooterInternal(unsigned long Npoints
347 ,RAY *rays
348 );
349 void rayshooterInternal(RAY &ray);
350
351 void info_rayshooter(RAY &i_point
352 ,std::vector<Point_2d> & ang_positions
353 ,std::vector<KappaType> & kappa_on_planes
354 ,std::vector<std::vector<LensHalo*>> & halo_neighbors
355 ,LensHalo &halo_max
356 ,KappaType &kappa_max
357 ,KappaType gamma_max[]
358 ,PosType rmax
359 ,int tag = 0
360 ,short mode = 0
361 ,bool verbose = false
362 );
363
365 void mass_on_planes(const std::vector<RAY> &rays
366 ,std::vector<double> &masses
367 ,bool verbose = false
368 );
369
374 /*RAY find_image_min(
375 Point_2d y_source /// input position of source (radians)
376 ,Point_2d &x_image /// initial guess for image postion (radians)
377 ,PosType z_source /// redshift of source
378 ,PosType ytol2 /// target tolerance in source position squared
379 ,PosType &fret ///
380 ,int sign=0 /// sign of magnification, it is found automatically if left out
381 );*/
382
393 RAY find_image_min(
394 Point &p
395 ,double zs
396 ,PosType ytol2
397 ,PosType &dy2
398 ,bool use_image_guess
399 );
404 RAY find_image_min(const RAY &in_ray
405 ,PosType ytol2
406 );
407
409// RAY find_image_min(
410// RAY &p /// p[] is
411// ,PosType ytol2 /// target tolerance in source position squared
412// ,PosType &dy2 /// final value of Delta y ^2
413// ,std::vector<Point_2d> &boundary /// image will be limited to within this boundary
414// );
415 RAY find_image_min(
416 Point &p
417 ,double zs
418 ,PosType ytol2
419 ,PosType &dy2
420 ,std::vector<Point_2d> &boundary
421 );
422
424 std::vector<RAY> find_images(Point_2d y_source
425 ,double z_source
426 ,Point_2d center
427 ,double range
428 ,double stop_res
429 );
431 std::vector<RAY> find_images(GridMap &init_grid
432 ,Point_2d y_source
433 ,double z_source
434 ,double stop_res
435 );
436
437 void find_images_min_parallel(std::vector<RAY> &rays
438 ,double ytol2
439 ,std::vector<bool> &success
440 );
441// void find_point_source_images(
442// Grid &grid
443// ,Point_2d y_source
444// ,PosType r_source
445// ,PosType z_source
446// ,std::vector<RAY> &images
447// ,double dytol2
448// ,double dxtol
449// ,bool verbose = false
450// );
451
452
453 // methods used for use with implanted sources
454
456 short ResetSourcePlane(PosType z,bool nearest=false,bool verbose = false);
457
459 void FindSourcePlane(
460 PosType zs
461 ,long &jmax
462 ,double &Dls
463 ,double &Ds
464 );
465
467 void RevertSourcePlane(){ toggle_source_plane = false;}
468 //void ImplantSource(unsigned long index,CosmoHndl cosmo);
469 PosType getSourceZ(){
470 if(toggle_source_plane){
471 return zs_implant;
472 }else{
473 return plane_redshifts.back();
474 }
475 }
476
477 PosType getZmax() const{return plane_redshifts.back();}
478
480 void PrintCosmology() { cosmo.PrintCosmology(); }
481
483 PosType getSigmaCrit(PosType zsource) const{ return cosmo.SigmaCrit(getZlens(), zsource); }
484
485
487 const COSMOLOGY & getCosmo(){return cosmo;}
488
490 void TurnFieldOff() { flag_switch_field_off = true ; }
491 void TurnFieldOn() { flag_switch_field_off = false ; }
492
494 PosType getFieldMinMass() const { return field_min_mass ; }
495
496 // get the field_Off value :
497 bool getfieldOff() const {return flag_switch_field_off ;}
498
499
500 Lens & operator=(Lens &&lens){
501
502 fieldofview = lens.fieldofview;
503 seed = lens.seed;
504 init_seed = lens.init_seed;
505 cosmo = lens.cosmo;
506 toggle_source_plane = lens.toggle_source_plane;
507
508 zs_implant = lens.zs_implant;
509 zsource = lens.zsource;
510
511 NZSamples = lens.NZSamples;
512 zbins = lens.zbins;
513 NhalosbinZ = lens.NhalosbinZ;
514 Nhaloestot_Tab = lens.Nhaloestot_Tab;
515 aveNhalosField = lens.aveNhalosField;
516 Logm = lens.Logm;
517 NhalosbinMass = lens.NhalosbinMass;
518 sigma_back_Tab = lens.sigma_back_Tab;
519
520 flag_switch_deflection_off = lens.flag_switch_deflection_off;
521 flag_switch_lensing_off = lens.flag_switch_lensing_off;
522
523 Dl = lens.Dl;
524 dDl = lens.dDl;
525 dTl = lens.dTl;
526 plane_redshifts = lens.plane_redshifts;
527 charge = lens.charge;
528 flag_switch_field_off = lens.flag_switch_field_off;
529
530 field_halos = lens.field_halos;
531
532 field_Nplanes_original = lens.field_Nplanes_original;
533 field_Nplanes_current = lens.field_Nplanes_current;
534
535 field_plane_redshifts = lens.field_plane_redshifts;
536 field_plane_redshifts_original = lens.field_plane_redshifts_original;
537 field_Dl = lens.field_Dl;
538 field_Dl_original = lens.field_Dl_original;
539
540 //substructure = lens.substructure;
541
542 //WasInsertSubStructuresCalled = lens.WasInsertSubStructuresCalled;
543 field_mass_func_type = lens.field_mass_func_type;
544 mass_func_PL_slope = lens.mass_func_PL_slope;
545 field_min_mass = lens.field_min_mass;
546 field_int_prof_type = lens.field_int_prof_type;
547 field_prof_internal_slope = lens.field_prof_internal_slope;
548
549 flag_field_gal_on = lens.flag_field_gal_on;
550 field_int_prof_gal_type = lens.field_int_prof_gal_type;
551 field_int_prof_gal_slope = lens.field_int_prof_gal_slope;
552
553 redshift_planes_file = lens.redshift_planes_file;
554 read_redshift_planes = lens.read_redshift_planes;
555
556 field_input_sim_file = lens.field_input_sim_file;
557 field_input_sim_format = lens.field_input_sim_format;
558
559 sim_input_flag = lens.sim_input_flag;
560 read_sim_file = lens.read_sim_file;
561 field_buffer = lens.field_buffer;
562
563 flag_switch_main_halo_on = lens.flag_switch_main_halo_on;
564
565 main_plane_redshifts = lens.main_plane_redshifts;
566 main_Dl = lens.main_Dl;
567
568 main_halo_type = lens.main_halo_type;
569 main_galaxy_halo_type = lens.main_galaxy_halo_type;
570
571 pixel_map_input_file = lens.pixel_map_input_file;
572 pixel_map_on = lens.pixel_map_on;
573 pixel_map_zeropad = lens.pixel_map_zeropad;
574 pixel_map_zeromean = lens.pixel_map_zeromean;
575
576 central_point_sphere = lens.central_point_sphere;
577 sim_angular_radius = lens.sim_angular_radius;
578 inv_ang_screening_scale = lens.inv_ang_screening_scale;
579
580 std::swap(lensing_planes,lens.lensing_planes);
581 std::swap(field_planes,lens.field_planes);
582 swap(main_halos,lens.main_halos);
583 std::swap(main_planes,lens.main_planes);
584
585 return *this;
586 }
587 Lens(Lens &&lens){
588 *this = std::move(lens);
589 }
590
591 // get the adress of field_plane_redshifts
592 std::vector<PosType> get_plane_redshifts () { return plane_redshifts; }
593
594private:
595 Lens & operator=(const Lens &lens); // block copy
596 Lens(const Lens &lens);
597
598protected:
600 PosType fieldofview;
601
602private:
603 GLAMER_TEST_FRIEND(LensTest)
604
605
606 void _find_images_(std::vector<RAY> &images
607 ,RAY &center
608 ,double range
609 ,double stop_res
610 );
611
612 void _find_images_min_parallel_(RAY *rays
613 ,size_t begin
614 ,size_t end
615 ,double ytol2
616 ,std::vector<bool> &success
617 );
618
619 // seed for random field generation
620 long *seed;
621
622 long init_seed;
623 //InputParams init_params;
624
625 // the cosmology
626 COSMOLOGY cosmo;
627
628 template<typename P>
629 void compute_points_parallel(int start
630 ,int chunk_size
631 ,P *i_point
632 ,double *source_zs
633 ,bool multiZs
634 ,bool verbose = false);
635
636 // this is a version that uses RAYs instead of Points or LinkedPoints and must be kept sinked with the above
637 void compute_rays_parallel(int start
638 ,int chunk_size
639 ,RAY *rays
640 ,bool verbose = false);
641
642 //void readCosmology(InputParams& params);
643 //void assignParams(InputParams& params,bool verbose = false);
644 void defaultParams(PosType zsource,bool verbose = true);
645
647 bool toggle_source_plane;
648
649 // redhsift of true source plane if rest from original
650 PosType zs_implant;
651
653 PosType zsource;
654
655 void quicksort(LensHaloHndl *halo,PosType **pos,unsigned long N);
656
657 // create the lens planes
658 //void buildPlanes(InputParams& params, bool verbose);
659
661 void setFieldDist();
663 void setFieldDistFromFile();
665 void setupFieldPlanes();
668 void ComputeHalosDistributionVariables ();
669
670 enum DM_Light_Division {All_DM,Moster};
671
672 void createFieldHalos(bool verbose,DM_Light_Division division = Moster);
673
675 void readInputSimFileMillennium(bool verbose,DM_Light_Division division = Moster);
676
678 void readInputSimFileMultiDarkHalos(bool verbose,DM_Light_Division division = Moster);
679
681 void readInputSimFileObservedGalaxies(bool verbose);
682
684 void createFieldPlanes(bool verbose);
685
686 // generate main halo from the parameter file
687 //void createMainHalos(InputParams& params);
689 void createMainPlanes();
691 void addMainHaloToPlane(LensHalo* halo);
692 void addMainHaloToNearestPlane(LensHalo* halo);
693
695 void combinePlanes(bool verbose);
696
697 /* Variables used by buildPlanes, createFieldHalos, and createFieldPlanes */
699
701 const int Nzbins = 64 ;
703 const int Nmassbin=64;
705 int NZSamples = 50;
706 // table for redshift bins for mass function
707 std::vector<PosType> zbins ;
708 // table of number of halos per redshift bins for mass function
709 std::vector<PosType> NhalosbinZ ;
711 std::vector<PosType> Nhaloestot_Tab ;
713 PosType aveNhalosField ;
715 std::vector<PosType> Logm;
717 std::vector<std::vector<PosType>> NhalosbinMass;
719 std::vector<PosType> sigma_back_Tab;
720
721 /* ----- */
722
724 size_t getNFieldHalos() const {return field_halos.size();}
726 //size_t getNSubHalos() const {return substructure.halos.size();}
727
728private: /* force calculation */
730 bool flag_switch_deflection_off;
731 bool flag_switch_lensing_off;
732
734 std::vector<LensPlane *> lensing_planes;
736 std::vector<PosType> Dl;
738 std::vector<PosType> dDl;
740 std::vector<PosType> dTl;
742 std::vector<PosType> plane_redshifts;
744 PosType charge;
745
746private: /* field */
748 bool flag_switch_field_off;
749
751 std::vector<LensHalo *> field_halos;
753 std::size_t field_Nplanes_original;
754 std::size_t field_Nplanes_current;
755
757 std::vector<LensPlane*> field_planes;
759 std::vector<PosType> field_plane_redshifts;
761 std::vector<PosType> field_plane_redshifts_original;
763 std::vector<PosType> field_Dl;
765 std::vector<PosType> field_Dl_original;
766
767// struct SubStructureInfo{
768// // things for substructures
769// /// vector of all substructure halos
770// std::vector<LensHaloNFW *> halos;
771// LensPlane *plane;
772// PosType Rregion = 0;
773// PosType Mmax = 0;
774// PosType Mmin = 0;
775// PosType alpha = 0;
776// PosType Ndensity = 0;
777// Point_2d center;
778// PosType rho_tidal = 0;
779// // Added quantities for the resetting of the substructure
780// // (when WasInsertSubStructuresCalled = MAYBE) :
781// PosType redshift = 0;
782// bool verbose = false;
783// };
784//
785// SubStructureInfo substructure;
786
788 // Boo WasInsertSubStructuresCalled = NO ;
789
791 //PosType **halo_pos;
792
794 MassFuncType field_mass_func_type;
796 PosType mass_func_PL_slope;
798 PosType field_min_mass;
800 LensHaloType field_int_prof_type;
802 PosType field_prof_internal_slope;
803
805 bool flag_field_gal_on;
807 GalaxyLensHaloType field_int_prof_gal_type;
809 PosType field_int_prof_gal_slope;
810
811 // mass fraction in the host galaxy
812 //PosType field_galaxy_mass_fraction;
813
814 std::string redshift_planes_file;
815 bool read_redshift_planes;
816
817 std::string field_input_sim_file;
818 HaloCatFormats field_input_sim_format;
819
820 bool sim_input_flag;
821 //std::string input_gal_file;
822 //bool gal_input_flag;
823 bool read_sim_file;
824
826 PosType field_buffer;
827
828private: /* main */
830 bool flag_switch_main_halo_on;
831
836 std::vector<LensPlane*> main_planes;
838 std::vector<PosType> main_plane_redshifts;
840 std::vector<PosType> main_Dl;
841
843 LensHaloType main_halo_type;
845 GalaxyLensHaloType main_galaxy_halo_type;
846
847private: /* input */
849 std::string pixel_map_input_file;
850
852 short pixel_map_on;
854 int pixel_map_zeropad;
855 bool pixel_map_zeromean;
856 void readPixelizedDensity();
857
861 PosType sim_angular_radius;
863 PosType inv_ang_screening_scale;
864
865 /* TO BE DEPRICATED
866 Add random halos to the light cone according to standard structure formation theory. A new realization of the light-cone can be made with Lens::resetFieldHalos() after this function is called once.
867
868 The cone is filled up until the redshift of the current zsource that is stored in the Lens class. The field is a circular on the sky. There is no clustering of the halos.
869 */
870 void GenerateFieldHalos(double min_mass
871 ,MassFuncType mass_function
872 ,double field_of_view
873 ,int Nplanes
874 ,LensHaloType halo_type = LensHaloType::nfw_lens
875 ,GalaxyLensHaloType galaxy_type = GalaxyLensHaloType::null_gal
876 ,double buffer = 1.0
877 ,bool verbose = false
878 );
879
880
881};
882
883inline std::size_t Lens::getNMainHalos() const
884{
885 return main_halos.size();
886}
887
888template<typename HaloType>
889inline std::size_t Lens::getNMainHalos() const
890{
891 return main_halos.size<HaloType>();
892}
893
894inline LensHalo* Lens::getMainHalo(std::size_t i)
895{
896 return main_halos.at(i);
897}
898
899template<typename HaloType>
900inline HaloType* Lens::getMainHalo(std::size_t i)
901{
902 if(main_halos.size<HaloType>() == 0 ) return nullptr;
903 return main_halos.at<HaloType>(i);
904}
905
906typedef Lens* LensHndl;
907
908// P should be Point or LinkedPoint
909template <typename P>
910void Lens::compute_points_parallel(int start
911 ,int chunk_size
912 ,P *i_points
913 ,double *source_zs
914 ,bool multiZs
915 ,bool verbose)
916{
917 int end = start + chunk_size;
918
919 int i, j;
920
921 PosType xx[2];
922 PosType aa,bb;
923 PosType alpha[2];
924
925 KappaType kappa,gamma[3];
926 KappaType phi;
927
928 Matrix2x2<PosType> G;
929
930 PosType SumPrevAlphas[2];
931 Matrix2x2<PosType> SumPrevAG;
932
933 PosType *theta;
934
935 long jmax = lensing_planes.size();
936 double Dls_Ds; // this is the ratio between of the distance between the last lens plane and the source to the distance to the source
937 double D_Ds; // this is the ratio between of the distance to the last lens plane and the source to the distance to the source
938
939 if(!multiZs){
940 if(source_zs[0] == plane_redshifts.back() ){
941 Dls_Ds = dDl.back() / Dl.back();
942 D_Ds = Dl[Dl.size() - 2] / Dl.back();
943 }else{
944 PosType Dls,Ds;
945 FindSourcePlane(source_zs[0],jmax,Dls,Ds);
946 Dls_Ds = Dls / Ds;
947 if(jmax > 0) D_Ds = Dl[jmax-1] / Ds;
948 }
949 }
950
951 // Main loop : loop over the points of the image
952 for(i = start; i < end; i++)
953 {
954 // In case e.g. a temporary point is outside of the grid.
955 if(i_points[i].in_image == MAYBE) continue;
956
957 //theta = i_points[i].image->x;
958 theta = i_points[i].ptr_y();
959
960 theta[0] = i_points[i].x[0];
961 theta[1] = i_points[i].x[1];
962
963 // Initializing SumPrevAlphas :
964 SumPrevAlphas[0] = theta[0];
965 SumPrevAlphas[1] = theta[1];
966
967 // Initializing SumPrevAG :
968 SumPrevAG.setToI();
969
970 // Setting phi on the first plane.
971 phi = 0.0;
972
973 // Default values :
974 i_points[i].A.setToI();
975 i_points[i].dt = 0;
976
977 // In case we don't want to compute the values :
978 if(flag_switch_lensing_off)
979 {
980 i_points[i].image->A.setToI();
981 continue;
982 }
983
984 // Time delay at first plane : position on the observer plane is (0,0) => no need to take difference of positions.
985 i_points[i].dt = 0;
986
987 //0.5*( p->i_points[i].image->x[0]*p->i_points[i].image->x[0] + p->i_points[i].image->x[1]*p->i_points[i].image->x[1] )/ p->dDl[0] ;
988
989 if(multiZs){
990 PosType Dls,Ds;
991 FindSourcePlane(source_zs[i],jmax,Dls,Ds);
992 Dls_Ds = Dls / Ds;
993 if(jmax > 0) D_Ds = Dl[jmax-1]/Ds;
994 }
995
996 // Begining of the loop through the planes :
997 // Each iteration leaves i_point[i].image on plane (j+1)
998
999 for(j = 0; j < jmax ; ++j)
1000 {
1001
1002 double Dphysical = Dl[j]/(1 + plane_redshifts[j]);
1003 // convert to physical coordinates on the plane j, just for force calculation
1004 xx[0] = theta[0] * Dphysical;
1005 xx[1] = theta[1] * Dphysical;
1006 // PhysMpc = ComMpc / (1+z)
1007
1008 assert(xx[0] == xx[0] && xx[1] == xx[1]);
1009
1011
1012 lensing_planes[j]->force(alpha,&kappa,gamma,&phi,xx);
1013 // Computed in physical coordinates, xx is in PhysMpc.
1014
1016
1017 assert(alpha[0] == alpha[0] && alpha[1] == alpha[1]);
1018 assert(gamma[0] == gamma[0] && gamma[1] == gamma[1]);
1019 assert(kappa == kappa);
1020 if(std::isinf(kappa)) { std::cout << "xx = " << xx[0] << " " << xx[1] << std::endl ;}
1021 assert(!std::isinf(kappa));
1022
1023 G[0] = kappa + gamma[0]; G[1] = gamma[1];
1024 G[2] = gamma[1]; G[3] = kappa - gamma[0];
1025
1026 /* multiply by fac to obtain 1/comoving_distance/physical_distance
1027 * such that a multiplication with the charge (in units of physical distance)
1028 * will result in a 1/comoving_distance quantity */
1029
1030 G *= charge * Dl[j] / (1 + plane_redshifts[j]);
1031
1032 assert(gamma[0] == gamma[0] && gamma[1] == gamma[1]);
1033 assert(kappa == kappa);
1034 //assert(phi == phi);
1035
1036 // This computes \vec{x}^{j+1} in terms of \vec{x}^{j}
1037 // according to the corrected Eq. (18) of paper GLAMER II ---------------------------------
1038
1039 // Adding the j-plane alpha contribution to the sum \Sum_{k=1}^{j} \vec{alpha_j} :
1040 SumPrevAlphas[0] -= charge * alpha[0] ;
1041 SumPrevAlphas[1] -= charge * alpha[1] ;
1042
1043 if(j < jmax-1 ){
1044 aa = dDl[j+1] / Dl[j+1];
1045 bb = Dl[j] / Dl[j+1];
1046 }else{
1047 aa = Dls_Ds;
1048 bb = D_Ds;
1049 }
1050
1051 if(!flag_switch_deflection_off){
1052 theta[0] = bb * theta[0] + aa * SumPrevAlphas[0];
1053 theta[1] = bb * theta[1] + aa * SumPrevAlphas[1];
1054 }
1055
1056 // ----------------------------------------------------------------------------------------
1057
1058 // Sum_{k=1}^{j} Dl[k] A^k.G^k
1059 SumPrevAG -= (G * (i_points[i].A)) ;
1060
1061 // Computation of the "plus quantities", i.e. the next plane quantities :
1062 i_points[i].A = i_points[i].A * bb + SumPrevAG * aa;
1063
1064 // ----------------------------------------------
1065
1066 // Geometric time delay with added potential
1067 //p->i_points[i].dt += 0.5*( (xplus[0] - xminus[0])*(xplus[0] - xminus[0]) + (xplus[1] - xminus[1])*(xplus[1] - xminus[1]) ) * p->dTl[j+1] /p->dDl[j+1] /p->dDl[j+1] - phi * p->charge ; /// in Mpc ???
1068
1069 // Check that the 1+z factor must indeed be there (because the x positions have been rescaled, so it may be different compared to the draft).
1070 // Remark : Here the true lensing potential is not "phi" but "phi * p->charge = phi * 4 pi G".
1071
1072
1073 } // End of the loop going through the planes
1074
1075 if(flag_switch_deflection_off){
1076 i_points[i].A = Matrix2x2<KappaType>::I() - SumPrevAG;
1077 }
1078
1079 // Subtracting off a term that makes the unperturbed ray to have zero time delay
1080 //p->i_points[i].dt -= 0.5*( p->i_points[i].image->x[0]*p->i_points[i].image->x[0] + p->i_points[i].image->x[1]*p->i_points[i].image->x[1] ) / p->Dl[NLastPlane];
1081
1082 // Conversion of dt from Mpc (physical Mpc) to Years -----------------
1083 i_points[i].dt *= MpcToSeconds * SecondToYears ;
1084
1085 // ---------------------------------------------------------------------------------------------
1086
1087 // Putting the final values of the quantities in the image point -----
1088 i_points[i].image->A = i_points[i].A;
1089 i_points[i].image->dt = i_points[i].dt;
1090 // ------------------------------------------------------------------------
1091
1092
1093 // TEST : showing final quantities
1094 // ------------------------------=
1095 if(verbose) std::cout << "RSI final : X X | " << i << " " << source_zs[i] << " | " << i_points[i].kappa() << " " << i_points[i].gamma1() << " " << i_points[i].gamma2() << " " << i_points[i].gamma3() << " " << i_points[i].invmag() << " | " << i_points[i].dt << std::endl ;
1096
1097 } // End of the main loop.
1098
1099}
1100
1101#endif /* MULTIPLANE_H_ */
1102
MassFuncType
Type of mass function.
Definition InputParams.h:36
GalaxyLensHaloType
Definition InputParams.h:66
LensHaloType
Type of halo profile.
Definition InputParams.h:44
The cosmology and all the functions required to calculated quantities based on the cosmology.
Definition cosmo.h:52
void PrintCosmology(short physical=0) const
Print cosmological parameters.
Definition cosmo.cpp:359
double SigmaCrit(double zlens, double zsource) const
The lensing critical density in Msun / Mpc^2.
Definition cosmo.cpp:1540
double angDist(double zo, double z) const
The angular size distance in units Mpc.
Definition cosmo.cpp:704
A base class for all types of lensing "halos" which are any mass distribution that cause lensing.
Definition lens_halos.h:56
A class to represents a lens with multiple planes.
Definition lens.h:71
bool set
marks if the lens has been setup.
Definition lens.h:81
int getNplanes() const
the total number of lens planes
Definition lens.h:84
void replaceMainHalos(std::vector< T > &my_halos, bool verbose)
Inserts a sequense of main lens halos and remove all previous ones.
Definition lens.h:244
void insertMainHalo(const T &halo_in, bool addplanes, bool verbose=false)
inserts a single main lens halo and adds it to the existing ones
Definition lens.h:150
PosType getFieldMinMass() const
get the field min mass :
Definition lens.h:494
Lens & operator=(Lens &&lens)
Definition lens.h:500
void TurnFieldOff()
set flag_switch_field_off, turn the field On/Off :
Definition lens.h:490
PosType getfov() const
field of view in square degrees
Definition lens.h:87
PosType getSigmaCrit(PosType zsource) const
returns the critical density at the main lens in Msun/ Mpc^2 for a source at zsource
Definition lens.h:483
const COSMOLOGY & getCosmo()
returns a const reference to the cosmology so that constant functions can be used,...
Definition lens.h:487
void PrintCosmology()
print the cosmological parameters
Definition lens.h:480
void FindSourcePlane(PosType zs, long &jmax, double &Dls, double &Ds)
find information on the position of the source plane with respect to the lens planes
Definition lens.cpp:2659
PosType getAngDistLens() const
Angular size distance (Mpc) to first main lens plane.
Definition lens.h:112
void moveinMainHalo(T &halo_in, bool addplanes, bool verbose=false)
This has the same effect as insertMainHalo(), but the halo is not copied, it is moved.
Definition lens.h:173
void replaceMainHalo(const T &halo_in, bool addplanes, bool verbose=false)
Inserts a single main lens halo and deletes all previous ones. Then all lensing planes are updated ac...
Definition lens.h:194
PosType getZlens() const
Redshift of first main lens plane.
Definition lens.h:102
void clearMainHalo(bool verbose=false)
remaove all main halo of given type
std::size_t getNMainHalos() const
inserts a sequence of main lens halos and adds them to the existing ones
Definition lens.h:883
LensHalo * getMainHalo(std::size_t i)
get single main halo
Definition lens.h:894
PosType fieldofview
field of view in square degrees
Definition lens.h:600
void RevertSourcePlane()
Revert the source redshift to the value it was when the Lens was created.
Definition lens.h:467
void insertMainHalos(std::vector< T > &my_halos, bool addplanes, bool verbose=false)
Inserts a sequense of main lens halos and adds them to the existing ones. Then all lensing planes are...
Definition lens.h:220
represents a point in spherical coordinates, theta = 0 is equator
Definition geometry.h:30
A container that can hold mixed objects all derived from a base class and retains the ability to acce...
Definition utilities_slsim.h:272
std::size_t size() const
number of all elements
Definition utilities_slsim.h:549
BaseT & at(std::size_t i)
indexed access with bounds checking
Definition utilities_slsim.h:514
void delete_container(Container &c)
delete the objects that are pointed to in a container of pointers
Definition utilities_slsim.h:993
A simplified version of the Grid structure for making non-adaptive maps of the lensing quantities (ka...
Definition gridmap.h:31
A point that automatically has an image point.
Definition point.h:496
Class for representing points or vectors in 2 dimensions. Not that the dereferencing operator is over...
Definition point.h:48
A point on the source or image plane that contains a position and the lensing quantities.
Definition point.h:414
Simple representaion of a light path giving position on the image and source planes and lensing quant...
Definition point.h:510