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
70
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 }
111
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 }
237
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
339
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
394 RAY find_image_min(
395 Point &p
396 ,double zs
397 ,PosType ytol2
398 ,PosType &dy2
399 ,bool use_image_guess
400 );
403 RAY find_image_min(const RAY &in_ray
404 ,PosType ytol2
405 );
406
408 RAY find_image_min(
409 Point &p
410 ,double zs
411 ,PosType ytol2
412 ,PosType &dy2
413 ,std::vector<Point_2d> &boundary
414 );
416 void find_images_min_parallel(std::vector<RAY> &rays
417 ,double ytol2
418 ,std::vector<bool> &success
419 );
420
425 std::vector<RAY> find_images(Point_2d y_source
426 ,double z_source
427 ,Point_2d center
428 ,double range
429 ,double stop_res
430 );
436 std::vector<RAY> find_images(GridMap &init_grid
437 ,Point_2d y_source
438 ,double z_source
439 ,double stop_res
440 );
441
442
443// void find_point_source_images(
444// Grid &grid
445// ,Point_2d y_source
446// ,PosType r_source
447// ,PosType z_source
448// ,std::vector<RAY> &images
449// ,double dytol2
450// ,double dxtol
451// ,bool verbose = false
452// );
453
454
455 // methods used for use with implanted sources
456
458 short ResetSourcePlane(PosType z,bool nearest=false,bool verbose = false);
459
461 void FindSourcePlane(
462 PosType zs
463 ,long &jmax
464 ,double &Dls
465 ,double &Ds
466 );
467
469 void RevertSourcePlane(){ toggle_source_plane = false;}
470 //void ImplantSource(unsigned long index,CosmoHndl cosmo);
471 PosType getSourceZ(){
472 if(toggle_source_plane){
473 return zs_implant;
474 }else{
475 return plane_redshifts.back();
476 }
477 }
478
479 PosType getZmax() const{return plane_redshifts.back();}
480
482 void PrintCosmology() { cosmo.PrintCosmology(); }
483
485 PosType getSigmaCrit(PosType zsource) const{ return cosmo.SigmaCrit(getZlens(), zsource); }
486
487
489 const COSMOLOGY & getCosmo(){return cosmo;}
490
492 void TurnFieldOff() { flag_switch_field_off = true ; }
493 void TurnFieldOn() { flag_switch_field_off = false ; }
494
496 PosType getFieldMinMass() const { return field_min_mass ; }
497
498 // get the field_Off value :
499 bool getfieldOff() const {return flag_switch_field_off ;}
500
505 void GenerateFieldHalos(double min_mass
506 ,MassFuncType mass_function
507 ,double field_of_view
508 ,int Nplanes
509 ,LensHaloType halo_type = LensHaloType::nfw_lens
510 ,GalaxyLensHaloType galaxy_type = GalaxyLensHaloType::null_gal
511 ,double buffer = 1.0
512 ,bool verbose = false
513 );
514
515 Lens & operator=(Lens &&lens){
516
517 fieldofview = lens.fieldofview;
518 seed = lens.seed;
519 init_seed = lens.init_seed;
520 cosmo = lens.cosmo;
521 toggle_source_plane = lens.toggle_source_plane;
522
523 zs_implant = lens.zs_implant;
524 zsource = lens.zsource;
525
526 NZSamples = lens.NZSamples;
527 zbins = lens.zbins;
528 NhalosbinZ = lens.NhalosbinZ;
529 Nhaloestot_Tab = lens.Nhaloestot_Tab;
530 aveNhalosField = lens.aveNhalosField;
531 Logm = lens.Logm;
532 NhalosbinMass = lens.NhalosbinMass;
533 sigma_back_Tab = lens.sigma_back_Tab;
534
535 flag_switch_deflection_off = lens.flag_switch_deflection_off;
536 flag_switch_lensing_off = lens.flag_switch_lensing_off;
537
538 Dl = lens.Dl;
539 dDl = lens.dDl;
540 dTl = lens.dTl;
541 plane_redshifts = lens.plane_redshifts;
542 charge = lens.charge;
543 flag_switch_field_off = lens.flag_switch_field_off;
544
545 field_halos = lens.field_halos;
546
547 field_Nplanes_original = lens.field_Nplanes_original;
548 field_Nplanes_current = lens.field_Nplanes_current;
549
550 field_plane_redshifts = lens.field_plane_redshifts;
551 field_plane_redshifts_original = lens.field_plane_redshifts_original;
552 field_Dl = lens.field_Dl;
553 field_Dl_original = lens.field_Dl_original;
554
555 //substructure = lens.substructure;
556
557 //WasInsertSubStructuresCalled = lens.WasInsertSubStructuresCalled;
558 field_mass_func_type = lens.field_mass_func_type;
559 mass_func_PL_slope = lens.mass_func_PL_slope;
560 field_min_mass = lens.field_min_mass;
561 field_int_prof_type = lens.field_int_prof_type;
562 field_prof_internal_slope = lens.field_prof_internal_slope;
563
564 flag_field_gal_on = lens.flag_field_gal_on;
565 field_int_prof_gal_type = lens.field_int_prof_gal_type;
566 field_int_prof_gal_slope = lens.field_int_prof_gal_slope;
567
568 redshift_planes_file = lens.redshift_planes_file;
569 read_redshift_planes = lens.read_redshift_planes;
570
571 field_input_sim_file = lens.field_input_sim_file;
572 field_input_sim_format = lens.field_input_sim_format;
573
574 sim_input_flag = lens.sim_input_flag;
575 read_sim_file = lens.read_sim_file;
576 field_buffer = lens.field_buffer;
577
578 flag_switch_main_halo_on = lens.flag_switch_main_halo_on;
579
580 main_plane_redshifts = lens.main_plane_redshifts;
581 main_Dl = lens.main_Dl;
582
583 main_halo_type = lens.main_halo_type;
584 main_galaxy_halo_type = lens.main_galaxy_halo_type;
585
586 pixel_map_input_file = lens.pixel_map_input_file;
587 pixel_map_on = lens.pixel_map_on;
588 pixel_map_zeropad = lens.pixel_map_zeropad;
589 pixel_map_zeromean = lens.pixel_map_zeromean;
590
591 central_point_sphere = lens.central_point_sphere;
592 sim_angular_radius = lens.sim_angular_radius;
593 inv_ang_screening_scale = lens.inv_ang_screening_scale;
594
595 std::swap(lensing_planes,lens.lensing_planes);
596 std::swap(field_planes,lens.field_planes);
597 swap(main_halos,lens.main_halos);
598 std::swap(main_planes,lens.main_planes);
599
600 return *this;
601 }
602 Lens(Lens &&lens){
603 *this = std::move(lens);
604 }
605
606 // get the adress of field_plane_redshifts
607 std::vector<PosType> get_plane_redshifts () { return plane_redshifts; }
608
609private:
610 Lens & operator=(const Lens &lens); // block copy
611 Lens(const Lens &lens);
612
613protected:
615 PosType fieldofview;
616
617private:
618 GLAMER_TEST_FRIEND(LensTest)
619
620
621 void _find_images_(std::vector<RAY> &images
622 ,Point_2d &y
623 ,Point_2d ll
624 ,Point_2d ur
625 ,double resolution
626 ,double stop_res
627 );
628
629 void _find_images_min_parallel_(RAY *rays
630 ,size_t begin
631 ,size_t end
632 ,double ytol2
633 ,std::vector<bool> &success
634 );
635
636 // seed for random field generation
637 long *seed;
638
639 long init_seed;
640 //InputParams init_params;
641
642 // the cosmology
643 COSMOLOGY cosmo;
644
645 template<typename P>
646 void compute_points_parallel(int start
647 ,int chunk_size
648 ,P *i_point
649 ,double *source_zs
650 ,bool multiZs
651 ,bool verbose = false);
652
653 // this is a version that uses RAYs instead of Points or LinkedPoints and must be kept sinked with the above
654 void compute_rays_parallel(int start
655 ,int chunk_size
656 ,RAY *rays
657 ,bool verbose = false);
658
659 //void readCosmology(InputParams& params);
660 //void assignParams(InputParams& params,bool verbose = false);
661 void defaultParams(PosType zsource,bool verbose = true);
662
664 bool toggle_source_plane;
665
666 // redhsift of true source plane if rest from original
667 PosType zs_implant;
668
670 PosType zsource;
671
672 void quicksort(LensHaloHndl *halo,PosType **pos,unsigned long N);
673
674 // create the lens planes
675 //void buildPlanes(InputParams& params, bool verbose);
676
678 void setFieldDist();
680 void setFieldDistFromFile();
682 void setupFieldPlanes();
685 void ComputeHalosDistributionVariables ();
686
687 enum DM_Light_Division {All_DM,Moster};
688
689 void createFieldHalos(bool verbose,DM_Light_Division division = Moster);
690
692 void readInputSimFileMillennium(bool verbose,DM_Light_Division division = Moster);
693
695 void readInputSimFileMultiDarkHalos(bool verbose,DM_Light_Division division = Moster);
696
698 void readInputSimFileObservedGalaxies(bool verbose);
699
701 void createFieldPlanes(bool verbose);
702
703 // generate main halo from the parameter file
704 //void createMainHalos(InputParams& params);
706 void createMainPlanes();
708 void addMainHaloToPlane(LensHalo* halo);
709 void addMainHaloToNearestPlane(LensHalo* halo);
710
712 void combinePlanes(bool verbose);
713
714 /* Variables used by buildPlanes, createFieldHalos, and createFieldPlanes */
716
718 const int Nzbins = 64 ;
720 const int Nmassbin=64;
722 int NZSamples = 50;
723 // table for redshift bins for mass function
724 std::vector<PosType> zbins ;
725 // table of number of halos per redshift bins for mass function
726 std::vector<PosType> NhalosbinZ ;
728 std::vector<PosType> Nhaloestot_Tab ;
730 PosType aveNhalosField ;
732 std::vector<PosType> Logm;
734 std::vector<std::vector<PosType>> NhalosbinMass;
736 std::vector<PosType> sigma_back_Tab;
737
738 /* ----- */
739
741 size_t getNFieldHalos() const {return field_halos.size();}
743 //size_t getNSubHalos() const {return substructure.halos.size();}
744
745private: /* force calculation */
747 bool flag_switch_deflection_off;
748 bool flag_switch_lensing_off;
749
751 std::vector<LensPlane *> lensing_planes;
753 std::vector<PosType> Dl;
755 std::vector<PosType> dDl;
757 std::vector<PosType> dTl;
759 std::vector<PosType> plane_redshifts;
761 PosType charge;
762
763private: /* field */
765 bool flag_switch_field_off;
766
768 std::vector<LensHalo *> field_halos;
770 std::size_t field_Nplanes_original;
771 std::size_t field_Nplanes_current;
772
774 std::vector<LensPlane*> field_planes;
776 std::vector<PosType> field_plane_redshifts;
778 std::vector<PosType> field_plane_redshifts_original;
780 std::vector<PosType> field_Dl;
782 std::vector<PosType> field_Dl_original;
783
784// struct SubStructureInfo{
785// // things for substructures
786// /// vector of all substructure halos
787// std::vector<LensHaloNFW *> halos;
788// LensPlane *plane;
789// PosType Rregion = 0;
790// PosType Mmax = 0;
791// PosType Mmin = 0;
792// PosType alpha = 0;
793// PosType Ndensity = 0;
794// Point_2d center;
795// PosType rho_tidal = 0;
796// // Added quantities for the resetting of the substructure
797// // (when WasInsertSubStructuresCalled = MAYBE) :
798// PosType redshift = 0;
799// bool verbose = false;
800// };
801//
802// SubStructureInfo substructure;
803
805 // Boo WasInsertSubStructuresCalled = NO ;
806
808 //PosType **halo_pos;
809
811 MassFuncType field_mass_func_type;
813 PosType mass_func_PL_slope;
815 PosType field_min_mass;
817 LensHaloType field_int_prof_type;
819 PosType field_prof_internal_slope;
820
822 bool flag_field_gal_on;
824 GalaxyLensHaloType field_int_prof_gal_type;
826 PosType field_int_prof_gal_slope;
827
828 // mass fraction in the host galaxy
829 //PosType field_galaxy_mass_fraction;
830
831 std::string redshift_planes_file;
832 bool read_redshift_planes;
833
834 std::string field_input_sim_file;
835 HaloCatFormats field_input_sim_format;
836
837 bool sim_input_flag;
838 //std::string input_gal_file;
839 //bool gal_input_flag;
840 bool read_sim_file;
841
843 PosType field_buffer;
844
845private: /* main */
847 bool flag_switch_main_halo_on;
848
853 std::vector<LensPlane*> main_planes;
855 std::vector<PosType> main_plane_redshifts;
857 std::vector<PosType> main_Dl;
858
860 LensHaloType main_halo_type;
862 GalaxyLensHaloType main_galaxy_halo_type;
863
864private: /* input */
866 std::string pixel_map_input_file;
867
869 short pixel_map_on;
871 int pixel_map_zeropad;
872 bool pixel_map_zeromean;
873 void readPixelizedDensity();
874
878 PosType sim_angular_radius;
880 PosType inv_ang_screening_scale;
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 // if(alpha[0] != alpha[0] || alpha[1] != alpha[1]){
1018 // std::cout << "xx[0] = " << xx[0] << " xx[1] = " << xx[1] << std::endl ;
1019 // std::cout << "alpha = " << alpha[0] << " " << alpha[1] << std::endl ;
1020 // throw std::runtime_error("alpha is NaN");
1021 // }
1022 assert(alpha[0] == alpha[0] && alpha[1] == alpha[1]);
1023 assert(gamma[0] == gamma[0] && gamma[1] == gamma[1]);
1024 assert(kappa == kappa);
1025 if(std::isinf(kappa)) { std::cout << "xx = " << xx[0] << " " << xx[1] << std::endl ;}
1026 assert(!std::isinf(kappa));
1027
1028 G[0] = kappa + gamma[0]; G[1] = gamma[1];
1029 G[2] = gamma[1]; G[3] = kappa - gamma[0];
1030
1031 /* multiply by fac to obtain 1/comoving_distance/physical_distance
1032 * such that a multiplication with the charge (in units of physical distance)
1033 * will result in a 1/comoving_distance quantity */
1034
1035 G *= charge * Dl[j] / (1 + plane_redshifts[j]);
1036
1037 assert(gamma[0] == gamma[0] && gamma[1] == gamma[1]);
1038 assert(kappa == kappa);
1039 //assert(phi == phi);
1040
1041 // This computes \vec{x}^{j+1} in terms of \vec{x}^{j}
1042 // according to the corrected Eq. (18) of paper GLAMER II ---------------------------------
1043
1044 // Adding the j-plane alpha contribution to the sum \Sum_{k=1}^{j} \vec{alpha_j} :
1045 SumPrevAlphas[0] -= charge * alpha[0] ;
1046 SumPrevAlphas[1] -= charge * alpha[1] ;
1047
1048 if(j < jmax-1 ){
1049 aa = dDl[j+1] / Dl[j+1];
1050 bb = Dl[j] / Dl[j+1];
1051 }else{
1052 aa = Dls_Ds;
1053 bb = D_Ds;
1054 }
1055
1056 if(!flag_switch_deflection_off){
1057 theta[0] = bb * theta[0] + aa * SumPrevAlphas[0];
1058 theta[1] = bb * theta[1] + aa * SumPrevAlphas[1];
1059 }
1060
1061 // ----------------------------------------------------------------------------------------
1062
1063 // Sum_{k=1}^{j} Dl[k] A^k.G^k
1064 SumPrevAG -= (G * (i_points[i].A)) ;
1065
1066 // Computation of the "plus quantities", i.e. the next plane quantities :
1067 i_points[i].A = i_points[i].A * bb + SumPrevAG * aa;
1068
1069 // ----------------------------------------------
1070
1071 // Geometric time delay with added potential
1072 //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 ???
1073
1074 // 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).
1075 // Remark : Here the true lensing potential is not "phi" but "phi * p->charge = phi * 4 pi G".
1076
1077
1078 } // End of the loop going through the planes
1079
1080 if(flag_switch_deflection_off){
1081 i_points[i].A = Matrix2x2<KappaType>::I() - SumPrevAG;
1082 }
1083
1084 // Subtracting off a term that makes the unperturbed ray to have zero time delay
1085 //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];
1086
1087 // Conversion of dt from Mpc (physical Mpc) to Years -----------------
1088 i_points[i].dt *= MpcToSeconds * SecondToYears ;
1089
1090 // ---------------------------------------------------------------------------------------------
1091
1092 // Putting the final values of the quantities in the image point -----
1093 i_points[i].image->A = i_points[i].A;
1094 i_points[i].image->dt = i_points[i].dt;
1095 // ------------------------------------------------------------------------
1096
1097
1098 // TEST : showing final quantities
1099 // ------------------------------=
1100 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 ;
1101
1102 } // End of the main loop.
1103
1104}
1105
1106#endif /* MULTIPLANE_H_ */
1107
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
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:496
Lens & operator=(Lens &&lens)
Definition lens.h:515
void TurnFieldOff()
set flag_switch_field_off, turn the field On/Off :
Definition lens.h:492
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:485
const COSMOLOGY & getCosmo()
returns a const reference to the cosmology so that constant functions can be used,...
Definition lens.h:489
void PrintCosmology()
print the cosmological parameters
Definition lens.h:482
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
Lens(long *seed, PosType z_source, CosmoParamSet cosmoset, bool verbose=false)
Creates an empty lens. Main halos and field halos need to be inserted by hand from the user.
Definition lens.cpp:38
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:615
void RevertSourcePlane()
Revert the source redshift to the value it was when the Lens was created.
Definition lens.h:469
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
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:503
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:421
Simple representaion of a light path giving position on the image and source planes and lensing quant...
Definition point.h:517