1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
|
/*******************************************************************************
*
* McXtrace, x-ray tracing package
* Copyright, All rights reserved
* DTU Physics, Kgs. Lyngby, Denmark
* Synchrotron SOLEIL, Saint-Aubin, France
*
* Component: Mirror_parabolic
*
* %Identification
* Written by: Erik Knudsen
* Date: Feb 11, 2010
* Origin: Risoe
*
* Idealized parabolic mirror (in XZ)
*
* %Description
* Takes a reflectivity as input and reflects rays in a ideal geometry
* parabolic mirror. The mirror is positioned in the zx-plane curving towards positive y.
* I.e. the focal point is (0,0,f(a,b))
* The geometry of the paraboloid is governed by the equation: y = x^2 / a^2 + z^2 / b^2
* Hence, the focal length for the 'x' curve is f=a^2 / 4, and analogous for z.
*
* Example: Mirror_parabolic(R0=1, a=1, b=0, xwidth=0.02, yheight=0, zdepth=0.05)
*
* %Parameters
* INPUT PARAMETERS
* R0: [1] Reflectivity of mirror.
* xwidth: [m] Width of mirror.
* zdepth: [m] Length of mirror.
* yheight:[m] Thickness of mirror. If 0 (the default) the mirror is mathemticlly thin. Only has an effect for hitting the mirror from the side.
* focusx: [m] Transverse focal length along X. Sets a.
* focusz: [m] Longitudinal focal length along Z. Sets b.
* radius: [m] Focal length. Sets focusx and focusz.
* a: [sqrt(m)] Transverse curvature scale, if zero - the mirror is flat along x.
* b: [sqrt(m)] Longitudinal curvature scale, if zero, flat along z.
*
* OUTPUT PARAMETERS
* xmax: [m] Mirrors' extent along x.
* zmax: [m] Mirrors' extent along z.
* a2inv: [m^-2] Inverse of a^2.
* b2inv: [m^-2] Inverse of b^2.
* %End
*******************************************************************************/
DEFINE COMPONENT Mirror_parabolic
SETTING PARAMETERS (R0=1, a=1, b=1, xwidth=0.1, zdepth=0.1, yheight=0,
focusx=0, focusz=0, radius=0)
/* X-ray parameters: (x,y,z,kx,ky,kz,phi,t,Ex,Ey,Ez,p) */
DECLARE
%{
double a2inv;
double b2inv;
%}
INITIALIZE
%{
if (radius>0) focusx=focusz=radius;
if (focusx>0) a=2*sqrt(focusx); else focusx=a*a/4.0;
if (focusz>0) b=2*sqrt(focusz); else focusz=b*b/4.0;
a2inv=(a!=0)?(1.0/(a*a)):0; /* if a==0, it is really infinity */
b2inv=(b!=0)?(1.0/(b*b)):0; /* if b==0, it is really infinity */
%}
TRACE
%{
int status,first;
double l0,l1,sx,sz;
double nx,ny,nz,zz,xx, Y0;
if (b==0 && kx==0 && ky==0){
/*k || z and mirror invariant in z*/
zz=x*x*a2inv;
if(fabs(z-zz)<=yheight){
ABSORB;
}
}
if (a==0 && ky==0 && kz==0){
/*k || x and mirror invariant in x*/
xx=z*z*b2inv;
if(fabs(x-xx)<=yheight){
ABSORB;
}
}
/*find plane of entry - i.e. y=sign*x*x*a2inv + sign*z*z*b2inv,
and propagate the ray there.*/
Y0=(xwidth*xwidth/4.0*a2inv) + (zdepth*zdepth/4.0*b2inv);
plane_intersect(&l0,x,y,z,kx,ky,kz, 0,1,0,0,Y0,0);
if(l0>0){
PROP_DL(l0);
}
/*need a check for mirror limits here*/
if(a!=0){
sx= (a*a)/2.0 * ( x*a2inv * sqrt( (2*x*a2inv)*(2*x*a2inv) + 1) + asinh(2*x*a2inv)/2.0 );
}else{
sx=fabs(x);
}
if(b!=0){
sz= (b*b)/2.0 * ( z*b2inv * sqrt( (2*z*b2inv)*(2*z*b2inv) + 1) + asinh(2*z*b2inv)/2.0 );
}else{
sz=fabs(z);
}
if( fabs(sx)>xwidth/2.0 || fabs(sz)>zdepth/2.0 ){
/*Path length to either x or z coordinate bigger than mirror limits
* => we have missed the mirror.*/
RESTORE_XRAY(INDEX_CURRENT_COMP,x,y,z,kx,ky,kz,phi,t,Ex,Ey,Ez,p);
}else{
/*The intersect routine assumes a parabola opening towards positive z
so swap y and z.*/
first=1;
status=paraboloid_intersect(&l0,&l1,x,z,y,kx,kz,ky, a,b,0);
/*if l0==0, assume that we should pick l1 instead (if it is positive).*/
double ll;
if (l0>0){
ll=l0;
} else if (l1>0) {
ll=l1;
} else {
/*both l0 and l1 <=0*/
status=0;
}
while(status) {
PROP_DL(ll);
/*reflect in normal - again swap y and z.*/
paraboloid_normal(&nx,&nz,&ny, x,z,y, a,b,1);
double s=scalar_prod(kx,ky,kz,nx,ny,nz);
if (s!=0){
kx -= s*2*nx;
ky -= s*2*ny;
kz -= s*2*nz;
}
SCATTER;
p*=R0;
/*update phase - as an approximation turn by 180 deg.*/
phi+=M_PI;
first=0;
status=paraboloid_intersect(&l0,&l1,x,z,y,kx,kz,ky, a,b,0);
/*need to check if the new reflection point is within mirror limits*/
if(status){
if(l0>0){
ll=l0;
}else if (l1>0){
ll=l1;
}else{
status=0;break;
}
double knx,kny,knz;
knx=kx;kny=ky;knz=kz;
NORM(knx,kny,knz);
double xx=x+knx*ll;
if(a!=0){
sx= (a*a)/2.0 * ( xx*a2inv * sqrt( (2*xx*a2inv)*(2*xx*a2inv) + 1) + asinh(2*xx*a2inv)/2.0 );
}else{
sx=fabs(xx);
}
double zz=z+knz*ll;
if(b!=0){
sz= (b*b)/2.0 * ( zz*b2inv * sqrt( (2*zz*b2inv)*(2*zz*b2inv) + 1) + asinh(2*zz*b2inv)/2.0 );
}else{
sz=fabs(zz);
}
if(fabs(sx)>xwidth/2.0 || fabs(sz)>zdepth/2.0 ){
status=0;break;
}
}
}
}
%}
MCDISPLAY
%{
const int Ni=25;
const int Nj=25;
double dx=xwidth/(Ni);
double dz=zdepth/(Nj);
double x0,x1,z0,z1,y[4],xmin,xmax,zmin,zmax;
int i,j;
magnify("");
line(-xwidth/2.0,0,-zdepth/2.0, xwidth/2.0,0,-zdepth/2.0);
line(-xwidth/2.0,0, zdepth/2.0, xwidth/2.0,0, zdepth/2.0);
line(-xwidth/2.0,0,-zdepth/2.0,-xwidth/2.0,0, zdepth/2.0);
line( xwidth/2.0,0,-zdepth/2.0, xwidth/2.0,0, zdepth/2.0);
/*find the limits in x and z*/
x0=0;x1=xwidth/2.0;
if(a!=0){
double xx=(x1+x0)/2.0;
double sx= (a*a)/2.0 * ( xx*a2inv * sqrt( (2*xx*a2inv)*(2*xx*a2inv) + 1) + asinh(2*xx*a2inv)/2.0 );
i=0;
while ( fabs(sx-xwidth/2.0)>1e-4 && i<100){
if ((sx-xwidth/2.0)>0){
x1=xx;
}else{
x0=xx;
}
xx=(x1+x0)/2.0;
sx= (a*a)/2.0 * ( xx*a2inv * sqrt( (2*xx*a2inv)*(2*xx*a2inv) + 1) + asinh(2*xx*a2inv)/2.0 );
i++;
}
xmax=xx;
}else{
xmax=xwidth/2.0;
}
z0=0;z1=zdepth/2.0;
if(b!=0){
double zz=(z1+z0)/2.0;
double sz= (b*b)/2.0 * ( zz*b2inv * sqrt( (2*zz*b2inv)*(2*zz*b2inv) + 1) + asinh(2*zz*b2inv)/2.0 );
j=0;
while ( fabs(sz-zdepth/2.0)>1e-4 && j<100){
if ((sz-zdepth/2.0)>0){
z1=zz;
}else{
z0=zz;
}
zz=(z1+z0)/2.0;
sz= (b*b)/2.0 * ( zz*b2inv * sqrt( (2*zz*b2inv)*(2*zz*b2inv) + 1) + asinh(2*zz*b2inv)/2.0 );
j++;
}
zmax=zz;
}else{
zmax=zdepth/2.0;
}
dx=2.0*xmax/(Ni);
dz=2.0*zmax/(Nj);
/*approximate the mirror bounds by width and depth to avoid inverting the sx and sz functions*/
/*mirror is symmetric around x,z=0,0. so we c an use xmax and zmax.*/
for (i=0;i<Ni;i++){
x0=i*dx - xmax;
x1=(i+1)*dx - xmax;
for (j=0;j<Nj;j++){
z0=j*dz - zmax;
z1=(j+1)*dz - zmax;
y[0]=x0*x0*a2inv + z0*z0*b2inv;
y[1]=x1*x1*a2inv + z0*z0*b2inv;
y[2]=x0*x0*a2inv + z1*z1*b2inv;
y[3]=x1*x1*a2inv + z1*z1*b2inv;
line(x0,y[0],z0, x1,y[1],z0);
line(x0,y[0],z0, x0,y[2],z1);
if(i==Ni-1) line(x1,y[1],z0, x1,y[3],z1);
if(j==Nj-1) line(x0,y[2],z1, x1,y[3],z1);
}
}
%}
END
|