GLAMERDOC++
Gravitational Lensing Code Library
Loading...
Searching...
No Matches
disk.h
1#include "particle_halo.h"
2
3#ifndef GLAMER_disk_halo_h
4#define GLAMER_disk_halo_h
5
6using Utilities::Geometry::Quaternion;
7
15template <typename T=float>
16class LensHaloDisk:public LensHaloParticles<ParticleType<T> > {
17
18public:
20 double mass
21 ,double disk_scale
22 ,double Rperp
23 ,double mass_res
24 ,float my_PA
25 ,float my_inclination
27 ,float redshift
28 ,const COSMOLOGY &cosmo
29 ,int Nsmooth = 64
30 );
31
34 particles(LensHaloParticles<ParticleType<T> >::trash_collector)
35 {
36 qrot_invers = h.qrot_invers; // rotation that brings the disk back to face on
37 Rscale = h.Rscale;
38 Rhight = h.Rhight;
39 zpa = h.zpa;
40 inclination = h.inclination;
41 }
42
43 LensHaloDisk & operator=(LensHaloDisk &&h){
44 assert(&h != this);
45
46 LensHaloParticles<ParticleType<T> >::operator=(std::move(h));
47
48 particles = LensHaloParticles<ParticleType<T> >::trash_collector;
49 qrot_invers = h.qrot_invers; // rotation that brings the disk back to face on
50 Rscale = h.Rscale;
51 Rhight = h.Rhight;
52 zpa = h.zpa;
53 inclination = h.inclination;
54
55 return *this;
56 }
57
58
60 void reorient(float my_inclination,float my_PA){
61 inclination = my_inclination;
62 zpa = my_PA;
63
64 Quaternion<> R = Quaternion<>::q_z_rotation(zpa)*Quaternion<>::q_x_rotation(inclination)*qrot_invers;
65 rotate_all(R);
66 qrot_invers = Quaternion<>::q_x_rotation(-inclination)*Quaternion<>::q_z_rotation(-zpa);
67
68 // reconstruct LensHaloParticles base class
70 LensHaloParticles<ParticleType<T> >::qtree = new TreeQuadParticles<ParticleType<T> >(particles.data(),particles.size(),-1,-1,0,20);
71 }
73 float getInclination(){return inclination;}
75 float getPA(){return zpa;}
76
77private:
78
79 std::vector<ParticleType<T> > &particles;
80
81 void rotate_all(Quaternion<T> &R){
82 Quaternion<T> q(1,0,0,0);
83 for(auto &p : particles){
84 q[0] = 0; q[1] = p[0]; q[2] = p[1]; q[3] = p[2];
85 q.RotInplace(R);
86 p[0] = q[1]; p[1] = q[2]; p[2] = q[3];
87 }
88 }
89
90 Utilities::Geometry::Quaternion<T> qrot_invers; // rotation that brings the disk back to face on
91 double Rscale;
92 double Rhight;
93 double zpa;
94 double inclination;
95};
96
97template<typename T>
99 double mass
100 ,double disk_scale
101 ,double Rperp
102 ,double mass_res
103 ,float my_PA
104 ,float my_inclination
106 ,float redshift
107 ,const COSMOLOGY &cosmo
108 ,int Nsmooth
109 ):
110LensHaloParticles<ParticleType<T> >(redshift,cosmo),
111particles(LensHaloParticles<ParticleType<T> >::trash_collector),
112qrot_invers(1,0,0,0),Rscale(disk_scale),Rhight(Rperp),zpa(my_PA),
113inclination(my_inclination)
114{
115
117 size_t N = (size_t)(mass/mass_res + 1);
118 particles.resize(N);
119 LensHaloParticles<ParticleType<T> >::pp = particles.data();
120 LensHaloParticles<ParticleType<T> >::Npoints = particles.size();
121
122 double r,theta=0;
123 double dt = PI + PI*ran()/10.;
124
125 //std::cout << "dt = " << dt/PI << std::endl;
126 size_t i = 0;
127 double deltaF = 1.0/(N-1);
128 double x = 0;
129 for(auto &p : particles){
130 r = Rscale * x;
131
132 // quadratic recursive approximation
133 //x = x + 0.5*( sqrt(x + 4*(1-x)*exp(x)*deltaF ) - x)
135
136 if(x==0){
137 x = sqrt(deltaF);
138 }else{
139 x = x + deltaF*exp(x)/x;
140 }
141
142 assert(!isnan(x));
143 //r = -Rscale * log(1 - (float)(i) / N );
144 //theta = 2*PI*ran();
145 theta += dt;
146
147 p.x[0] = r*cos(theta);
148 p.x[1] = r*sin(theta);
149 if(Rhight > 0){
150 p.x[2] = -Rhight * log( 1 - ran() );
151 p.x[2] *= 2*(int)(2*ran()) - 1; // random sign
152 }else{
153 p.x[2] = 0;
154 }
155 p.Mass = mass_res;
156 ++i;
157 }
158
159
160 LensHaloParticles<ParticleType<T> >::calculate_smoothing(Nsmooth,particles.data(),particles.size());
161
162 // rotate particles to required inclination and position angle
163 Quaternion<T> R = Quaternion<T>::q_z_rotation(zpa) * Quaternion<T>::q_y_rotation(inclination);
164 rotate_all(R);
165 qrot_invers = R.conj();
166
167 LensHaloParticles<ParticleType<T> >::mcenter *= 0.0;
168 LensHalo::setMass(mass);
169
170 //LensHaloParticles<ParticleType<T> >::min_size;
171 LensHaloParticles<ParticleType<T> >::multimass=false;
172
173 Point_2d no_rotation;
174 LensHaloParticles<ParticleType<T> >::set_up(redshift,cosmo,no_rotation,-1,false,false);
175
176 LensHalo::Rmax = -8 * Rscale * log(1 - (float)(N-1) / N );
177 LensHalo::setRsize( LensHalo::Rmax );
178
179};
180
181#endif
The cosmology and all the functions required to calculated quantities based on the cosmology.
Definition cosmo.h:52
Creates a exponential disk out of particles.
Definition disk.h:16
LensHaloDisk(double mass, double disk_scale, double Rperp, double mass_res, float my_PA, float my_inclination, Utilities::RandomNumbers_NR &ran, float redshift, const COSMOLOGY &cosmo, int Nsmooth=64)
Definition disk.h:98
void reorient(float my_inclination, float my_PA)
Reorient the disk.
Definition disk.h:60
float getPA()
postion angle in radians,
Definition disk.h:75
float getInclination()
inclination in radians, 0 is face on
Definition disk.h:73
A class that represents the lensing by a collection of simulation particles.
Definition particle_halo.h:41
void set_up(float redshift, const COSMOLOGY &cosmo, Point_2d theta_rotate, double max_range, bool recenter, bool verbose)
Definition particle_halo.h:342
TreeQuadParticles is a class for calculating the deflection, kappa and gamma by tree method.
Definition quadTree.h:47
This is a class for generating random numbers. It simplifies and fool proofs initialization and allow...
Definition utilities_slsim.h:1059
Class for representing points or vectors in 2 dimensions. Not that the dereferencing operator is over...
Definition point.h:48