GLAMERDOC++
Gravitational Lensing Code Library
Public Member Functions | Public Attributes | Protected Attributes | List of all members
Lens Class Reference

A class to represents a lens with multiple planes. More...

#include <lens.h>

Public Member Functions

 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.
 
 Lens (long *seed, PosType z_source, const COSMOLOGY &cosmo, bool verbose=false)
 
int getNplanes () const
 the total number of lens planes
 
PosType getfov () const
 field of view in square degrees
 
void setfov (PosType fov)
 
void resetFieldNplanes (std::size_t field_Nplanes, bool verbose=false)
 reset the number of planes, but keep the field halos and main lens
 
void resetFieldHalos (bool verbose=false)
 
void printMultiLens ()
 print the main parameters of the lens
 
PosType getZlens () const
 Redshift of first main lens plane.
 
PosType getAngDistLens () const
 Angular size distance (Mpc) to first main lens plane.
 
Utilities::Geometry::SphericalPoint getCenter () const
 
void clearMainHalos (bool verbose=false)
 remove all main halos
 
template<typename HaloType >
void clearMainHalo (bool verbose=false)
 remaove all main halo of given type
 
template<typename T >
void insertMainHalo (const T &halo_in, bool addplanes, bool verbose=false)
 inserts a single main lens halo and adds it to the existing ones
 
template<typename T >
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. More...
 
template<typename T >
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 accordingly. More...
 
template<typename T >
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 updated accordingly. If addplanes is true new planes will be added otherwise the halo is added to the nearest plane and a plane is added only if none exited on entry. More...
 
template<typename T >
void replaceMainHalos (std::vector< T > &my_halos, bool verbose)
 Inserts a sequense of main lens halos and remove all previous ones. More...
 
std::size_t getNMainHalos () const
 inserts a sequence of main lens halos and adds them to the existing ones More...
 
template<typename HaloType >
std::size_t getNMainHalos () const
 get number of main halos of given type
 
LensHalogetMainHalo (std::size_t i)
 get single main halo
 
template<typename HaloType >
HaloType * getMainHalo (std::size_t i)
 get single main halo of given type
 
void rayshooter (RAY &ray)
 Using to shoot a single ray. More...
 
void rayshooterInternal (unsigned long Npoints, Point *i_points, bool RSIverbose=false)
 Main routine for shooting rays in parrallel. More...
 
void rayshooterInternal (unsigned long Npoints, LinkedPoint *i_points, std::vector< double > &source_zs, bool RSIverbose=false)
 Routine for shooting rays with differnt source redshifts in parrallel. More...
 
void rayshooterInternal (unsigned long Npoints, RAY *rays)
 
void rayshooterInternal (RAY &ray)
 
void info_rayshooter (RAY &i_point, std::vector< Point_2d > &ang_positions, std::vector< KappaType > &kappa_on_planes, std::vector< std::vector< LensHalo * >> &halo_neighbors, LensHalo &halo_max, KappaType &kappa_max, KappaType gamma_max[], PosType rmax, int tag=0, short mode=0, bool verbose=false)
 single ray More...
 
void mass_on_planes (const std::vector< RAY > &rays, std::vector< double > &masses, bool verbose=false)
 finds the mass within a curve of rays one every lens plane im Msun More...
 
RAY find_image_min (Point &p, double zs, PosType ytol2, PosType &dy2, bool use_image_guess)
 Find the image position of a source without grid refinement. More...
 
RAY find_image_min (const RAY &in_ray, PosType ytol2)
 
RAY find_image_min (Point &p, double zs, PosType ytol2, PosType &dy2, std::vector< Point_2d > &boundary)
 This is the same, but the image is forced to stay within boundary. More...
 
std::vector< RAYfind_images (Point_2d y_source, double z_source, Point_2d center, double range, double stop_res)
 finds images by telescoping triangle method More...
 
std::vector< RAYfind_images (GridMap &init_grid, Point_2d y_source, double z_source, double stop_res)
 finds images by telescoping triangle method More...
 
void find_images_min_parallel (std::vector< RAY > &rays, double ytol2, std::vector< bool > &success)
 
short ResetSourcePlane (PosType z, bool nearest=false, bool verbose=false)
 reset the redshift of the source plane More...
 
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 More...
 
void RevertSourcePlane ()
 Revert the source redshift to the value it was when the Lens was created.
 
PosType getSourceZ ()
 
PosType getZmax () const
 
void PrintCosmology ()
 print the cosmological parameters
 
PosType getSigmaCrit (PosType zsource) const
 returns the critical density at the main lens in Msun/ Mpc^2 for a source at zsource
 
const COSMOLOGY & getCosmo ()
 returns a const reference to the cosmology so that constant functions can be used, but the cosmological parameters cannot be changed.
 
void TurnFieldOff ()
 set flag_switch_field_off, turn the field On/Off :
 
void TurnFieldOn ()
 
PosType getFieldMinMass () const
 get the field min mass :
 
bool getfieldOff () const
 
void GenerateFieldHalos (double min_mass, MassFuncType mass_function, double field_of_view, int Nplanes, LensHaloType halo_type=LensHaloType::nfw_lens, GalaxyLensHaloType galaxy_type=GalaxyLensHaloType::null_gal, double buffer=1.0, bool verbose=false)
 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. More...
 
Lensoperator= (Lens &&lens)
 
 Lens (Lens &&lens)
 
std::vector< PosType > get_plane_redshifts ()
 

Public Attributes

bool set
 marks if the lens has been setup.
 

Protected Attributes

PosType fieldofview
 field of view in square degrees
 

Detailed Description

A class to represents a lens with multiple planes.

 The rays are traced through multiple deflections.  On each plane there is a deflection
 solver.  An LensHaloAnaNSIE or LensHaloMassMap can be put on one of the planes.  The other planes can be
 populated with random field_halos drawn from a mass function or they can be retrieved from an
 external catalog.
   Input Parameters (variable names):
   main_halo_on -- 0: no major lens present; 1: there is a major lens present
   main_halo_type -- profile type for the main DM lens halo
    0 or nolens, 1 or NFW, 2 or PseudoNFW, 3 or PowerLaw, 4 or NSIE, 5 or AnaLens, 6 or UniLens, 7 or MOKALens, 8 or DummyLens
   main_galaxy_halo_type -- profile typ for the main galaxy lens halo 0 or none, 1 or NSIE
   redshift_planes_file -- asci file with the redshifts of the lensing planes, if not set then created internaly
   flag_switch_field_off -- false: field halos are created, true: no field halos are created; default is false
   if field_off == false, i.e. there are field halos then also the following are used:
   field_Nplanes -- number of field planes
   field_fov -- field of view of the light cone, filled with field halos
   field_internal_profile -- profile type of the DM field lens halos
    0 or nolens, 1 or NFW, 2 or PseudoNFW, 3 or PowerLaw, 4 or NSIE, 5 or AnaLens, 6 or UniLens, 7 or MOKALens, 8 or DummyLens, 9 or Hernquist, 10 or Jaffe
   field_prof_internal_slope_pl -- slope of the surface density for power law
   field_prof_internal_slope_pnfw -- slope of the surface density for pseudo nfw profiles
   field_internal_profile_galaxy -- profile type of the galaxy field halos; if not set, no galaxies are used
    0 or none, 1 or NSIE
   field_input_sim_file -- filename of the Millennium simulation data to be read in and used to populate the light cone with field halos
   if field_input_sim_file is  _not_ set, then the field halos are generated from a mass function and the following are used:
   field_mass_func_type -- type of the halo mass function
    PS (0), ST (1), and power law (2)
   mass_func_PL_slope -- slope of the mass function in the power law case; default is -1/6
   field_min_mass -- minimum mass for the generated field halos
   field_buffer -- a constant physical size buffer, padding every lens plane to increase its surface
   zsource -- source redshift
   flag_switch_deflection_off -- false: deflection is on, but kappa and gamma may be calculated, true: deflection is off; default is false
   flag_switch_lensing_off -- false: lensing is on, true: lensing is off (no alpha, kappa or gamma); default is false
   # Cosmology - Any cosmological parameters that are not set will have default values
  Omega_matter -- Total mass (baryons + dark matter) in the units of the critical density, optional
  Omega_lambda -- Density in a cosmological constant, if not set it will be = 1 - Omega_matter
  Omega_baryon -- Density in baryons
  Omega_neutrino -- Density in neutrinos
  hubble -- Hubble parameter in units of 100 km/s/Mpc
  sigm_8 -- normalization of power spectrum
 

Member Function Documentation

◆ find_image_min() [1/3]

RAY Lens::find_image_min ( const RAY in_ray,
PosType  ytol2 
)

this version uses the redshift stored in the ray,

Tthe ray is replaced with the best guess so the source position is replaced.

Parameters
in_rayp.y[] should be set to source position
ytol2target tolerance in source position squared

◆ find_image_min() [2/3]

RAY Lens::find_image_min ( Point p,
double  zs,
PosType  ytol2,
PosType &  dy2,
bool  use_image_guess 
)

Find the image position of a source without grid refinement.

Find an image position for a source position.

This uses Powell's algorithm to minimise the distance between the source point of an image and the desired source point. No grid is necessary. This should be fast, but will miss multiple images. This is useful for finding the position of weakly lensed images or the rough region where a grid should be put down for a strong lens.

Find the image position of a source without grid refinement.

This finds an image position given a source postion. No grid is necessary.

If use_image_guess=true the input image position will be used as a first guess and the output image will be guarenteed to have the same pairity.

This is useful for finding the position of weakly lensed images or for refining the image positions that are found on a finite grid.

This routine finds the image position by minimizing the seporation on the source plane with Powell's method of minimization. This will not find all images. For that you must use another routine. In the weak lensing regiam this should be sufficient.

Parameters
pp.image->x should be set to source position
zsredhsift of source
ytol2target tolerance in source position squared
dy2final value of Delta y ^2
use_image_guessif true p.x[] will be used as a guess for the image position

◆ find_image_min() [3/3]

RAY Lens::find_image_min ( Point p,
double  zs,
PosType  ytol2,
PosType &  dy2,
std::vector< Point_2d > &  boundary 
)

This is the same, but the image is forced to stay within boundary.

Parameters
pp[] is
zssource redshift
ytol2target tolerance in source position squared
dy2final value of Delta y ^2
boundaryimage will be limited to within this boundary

◆ find_images() [1/2]

std::vector< RAY > Lens::find_images ( GridMap init_grid,
Point_2d  y_source,
double  z_source,
double  stop_res 
)

finds images by telescoping triangle method

find rays using telescoping triangle method starting with a GridMap init_grid

Meant for refining the image positions to higher resolution than the initial grid

◆ find_images() [2/2]

std::vector< RAY > Lens::find_images ( Point_2d  y_source,
double  z_source,
Point_2d  center,
double  range,
double  stop_res 
)

finds images by telescoping triangle method

find rays using telescoping triangle method

◆ FindSourcePlane()

void Lens::FindSourcePlane ( PosType  zs,
long &  jmax,
double &  Dls,
double &  Ds 
)

find information on the position of the source plane with respect to the lens planes

Parameters
zsredshift of implanted source
jmaxindex of last plane at lower redshift
Dlscoordinate distance between last plane and source plane
Dstotal coordinate distance to source plane

◆ GenerateFieldHalos()

void Lens::GenerateFieldHalos ( double  min_mass,
MassFuncType  mass_function,
double  field_of_view,
int  Nplanes,
LensHaloType  halo_type = LensHaloType::nfw_lens,
GalaxyLensHaloType  galaxy_type = GalaxyLensHaloType::null_gal,
double  buffer = 1.0,
bool  verbose = false 
)

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.

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.

Parameters
min_massminimum mass of halos
mass_functiontype of mass function
field_of_viewin square degrees
Nplanesnumber of lens planes
halo_typetype of halo
galaxy_typetype of galaxy, if null_gal no galaxy
bufferbuffer in Mpc for cone

◆ getNMainHalos()

std::size_t Lens::getNMainHalos ( ) const
inline

inserts a sequence of main lens halos and adds them to the existing ones

replaces existing main halos with a single main halo replaces existing main halos with a sequence of main halos get number of main halos

◆ info_rayshooter()

void Lens::info_rayshooter ( RAY ray,
std::vector< Point_2d > &  ang_positions,
std::vector< KappaType > &  kappa_on_planes,
std::vector< std::vector< LensHalo * >> &  halo_neighbors,
LensHalo halo_max,
KappaType &  kappa_max,
KappaType  gamma_max[],
PosType  rmax,
int  tag = 0,
short  mode = 0,
bool  verbose = false 
)

single ray

Collects information about the halos and kappa contributions along the light path.

Information on the nearest halos is collected where nearest is defined by rmax and mode. When mode == 2 the unlensed angular coordinates are used to evaluate proximity not the lensed ones.

Parameters
rayray, ray.x needs to be set, all other quantities will be calculated
ang_positionsangular positions on each plane
kappa_on_planesconvergence on each plane
halo_neighborsneighboring halos within rmax of ray on each plane
halo_maxhalo with the larges kappa
kappa_maxthe kappa from that halo
gamma_maxshear from that halo
rmaxdistance from ray on each plane, units depend on mode parameter
tagi f not 0, information on halos with this tag are gathered
mode0:physical distance, 1: comoving distance, 2: angular distance

◆ insertMainHalos()

template<typename T >
void Lens::insertMainHalos ( std::vector< T > &  my_halos,
bool  addplanes,
bool  verbose = false 
)
inline

Inserts a sequense of main lens halos and adds them to the existing ones. Then all lensing planes are updated accordingly. If addplanes is true new planes will be added otherwise the halo is added to the nearest plane and a plane is added only if none exited on entry.

The angular position of the halo should be preserved, but the x coordinates may change The halos are copied so the input halos can be destoyed without affecting the Lens.

◆ mass_on_planes()

void Lens::mass_on_planes ( const std::vector< RAY > &  rays,
std::vector< double > &  masses,
bool  verbose = false 
)

finds the mass within a curve of rays one every lens plane im Msun

Parameters
raysray, ray.x needs to be set
massesmass within curve on each lens plane

◆ moveinMainHalo()

template<typename T >
void Lens::moveinMainHalo ( T &  halo_in,
bool  addplanes,
bool  verbose = false 
)
inline

This has the same effect as insertMainHalo(), but the halo is not copied, it is moved.

The Lens will take possession of the halo and will destroy it when it is destroyed. This is to avoid copying halos that take up a lot of memory and require a lot of time to copy like LensHaloParticles().

◆ operator=()

Lens& Lens::operator= ( Lens &&  lens)
inline

MixedVector cannot be copyed

◆ rayshooter()

void Lens::rayshooter ( RAY ray)

Using to shoot a single ray.

This function calculates the deflection, shear, convergence, rotation and time-delay of rays in parallel. The source redshift must be set for the ray.

ray.x should be set to the image position. The kappa,gamma,deflection, time-delay and source position will be calculated at that image point.

◆ rayshooterInternal() [1/3]

void Lens::rayshooterInternal ( unsigned long  Npoints,
LinkedPoint i_points,
std::vector< double > &  source_zs,
bool  RSIverbose = false 
)

Routine for shooting rays with differnt source redshifts in parrallel.

i_points[].x must be set to the image postion in angular radians.

Parameters
Npointsnumber of points to be shot
i_pointspoinst on the image plane
source_zssource redshifts
RSIverboseverbose option

◆ rayshooterInternal() [2/3]

void Lens::rayshooterInternal ( unsigned long  Npoints,
Point i_points,
bool  RSIverbose = false 
)

Main routine for shooting rays in parrallel.

i_points[].x must be set to the image postion in angular radians.

i_points must have linked image points. LinkedPoints could be used, but for its internal use this is not done.

Parameters
Npointsnumber of points to be shot
i_pointspoints on the image plane
RSIverboseverbose option

◆ rayshooterInternal() [3/3]

void Lens::rayshooterInternal ( unsigned long  Npoints,
RAY rays 
)
Parameters
Npointsnumber of points to be shot
rayspoints on the image plane

◆ replaceMainHalo()

template<typename T >
void Lens::replaceMainHalo ( const T &  halo_in,
bool  addplanes,
bool  verbose = false 
)
inline

Inserts a single main lens halo and deletes all previous ones. Then all lensing planes are updated accordingly.

Note that this does delete all the halos that were there.

◆ replaceMainHalos()

template<typename T >
void Lens::replaceMainHalos ( std::vector< T > &  my_halos,
bool  verbose 
)
inline

Inserts a sequense of main lens halos and remove all previous ones.

Note that this does delete the halos that were there. Then all lensing planes are updated accordingly.

◆ resetFieldHalos()

void Lens::resetFieldHalos ( bool  verbose = false)

keep the main lens and the number of planes constant, but generate new field halos.

◆ ResetSourcePlane()

short Lens::ResetSourcePlane ( PosType  z,
bool  nearest = false,
bool  verbose = false 
)

reset the redshift of the source plane

Changes the maximum redshift that the rays are shot to. Warning: Grids that have already been made with this Lens will not have this new source redshift.

The multilens must have been initially constructed with a source redshift that is higher than this redshift. This is used to rayshoot to a source whose line of sight passes through the simulation volume. The source can be at higher redshift than the simulation volume.

To revert the source redshift to its original value use Lens::RevertSourcePlane().

Parameters
zredshift of implanted source
nearestIf true, set the source plane to the nearest (in coordinate distance) lensing plane that was created already. This can be used to avoid self-lensing by the halo of the source. If the source is at higher redshift than the simulation volume the source will be at its real redshift.

The documentation for this class was generated from the following files: