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
|
/*******************************************************************************
*
* McXtrace, x-ray tracing package
* Copyright, All rights reserved
* DTU Physics, Kgs. Lyngby, Denmark
* Synchrotron SOLEIL, Saint-Aubin, France
*
* Component: Mirror
*
* %Identification
*
* Written by: Erik B Knudsen
* Date: July 2016
* Version: 1.3
* Origin: DTU Physics
*
* Perfectly flat mirror (in XZ or YZ), or polygonal
*
* %Description
* This is a simple implementation of a perfectly flat mirror. The mirror plane is in the XZ-plane.
* It can be oriented in the YZ plane by setting 'yheight'.
* It may also be a complex polygonal geometry (OFF/PLY) by setting 'geometry'.
*
* Reflectivity may be specified either as a number (R0) or by means of a material datafile.
* The material datafile may be specified as a coating or as relfectivity - either parameterized by q or E,theta.
* If the datafile is identified as a coating recipe, an ab-initio reflectivity calculation is triggered.
*
* Example: Mirror(xwidth=5e-2, zdepth=2e-1, R0=1, coating="B4C.dat")
*
* %Parameters
* Input parameters:
* xwidth: [m] The width of the mirror
* zdepth: [m] The length of the mirror
* yheight: [m] The height of the mirror. This overrides xwidth and puts the mirror in the yz-plane.
* R0: [0-1] Constant reflectivity
* coating: [str] Filename containing reflectivities (or coating).
* geometry:[str] Filename of an OFF/PLY geometry providing a polygonal surface. When xwidth/yheight/zdepth are also given, the object is rescaled accordingly.
*
* %End
*******************************************************************************/
DEFINE COMPONENT Mirror
SETTING PARAMETERS (zdepth=0.1, xwidth=0.01, yheight=0,
string coating="", R0=0, string geometry="")
/* X-ray parameters: (x,y,z,kx,ky,kz,phi,t,Ex,Ey,Ez,p) */
SHARE
%{
%include "read_table-lib"
%include "reflectivity-lib"
%include "interoff-lib"
#ifndef SHAPES_T
#define SHAPES_T
enum shapes_t {NONE=-1,SPHERE, CYLINDER, CUBE, ELLIPSOID, ANY};
#endif
%}
DECLARE
%{
t_Reflec re;
off_struct offdata;
int shape;
%}
INITIALIZE
%{
int status=0;
if (coating && strlen(coating) && strcmp(coating,"NULL") ) {
status=reflec_Init(&re,COATING_UNDEFINED,coating,NULL);
}else{
/*assume a constant reflectivity*/
status=reflec_Init_const(&re,R0);
}
if(status!=0){
fprintf(stderr,"ERROR (%s): Could not interpret reflectivity. Aborting.\n", NAME_CURRENT_COMP);
exit(-1);
}
if (geometry && strlen(geometry) && strcmp(geometry, "NULL") && strcmp(geometry, "0")) {
if (off_init(geometry, xwidth, yheight, zdepth, 0, &(offdata)))
shape=ANY;
else
exit(fprintf(stderr,"ERROR (%s): Could not import geometry file %s\n",
NAME_CURRENT_COMP, geometry));
} else if (yheight || xwidth)
shape=CUBE;
else
exit(fprintf(stderr,"ERROR (%s): invalid Mirror dimensions. Aborting.\n",
NAME_CURRENT_COMP));
%}
TRACE
%{
int intersect=1;
double nx,ny,nz;
if (shape == ANY) { // off/ply
double l0,l1;
Coords n0, n1;
intersect = off_x_intersect(&l0, &l1, &n0, &n1, x, y, z, kx, ky, kz, offdata );
if (intersect) {
if (l0>0) {
PROP_DL(l0);
coords_get(n0, &nx, &ny, &nz);
} else if (l1 > 0) {
PROP_DL(l1);
coords_get(n1, &nx, &ny, &nz);
}
}
} else if(yheight){ // YZ plane
PROP_X0;
if(y<-yheight/2.0|| y>yheight/2.0 || z<-zdepth/2.0 || z>zdepth/2.0){
intersect=0;
}else{
nx=1; ny=nz=0;
}
} else { // XZ plane
PROP_Y0;
if(x<-xwidth/2.0|| x>xwidth/2.0 || z<-zdepth/2.0 || z>zdepth/2.0){
intersect=0;
}else{
nx=0; ny=1; nz=0;
}
}
if(intersect){
double s,k,q,R;
s=scalar_prod(kx,ky,kz,nx,ny,nz);
k=sqrt(scalar_prod(kx,ky,kz,kx,ky,kz));
kx=kx-2*s*nx;
ky=ky-2*s*ny;
kz=kz-2*s*nz;
SCATTER;
q=2.0*s;
R=reflecq(re,q,0.0,k,fabs(90-acos(s/k)*RAD2DEG));
p*=R;
/*update phase - as an approximation turn by 180 deg.*/;
phi+=M_PI;
}else{
/*missed mirror - restore xray*/
RESTORE_XRAY(INDEX_CURRENT_COMP, x,y,z, kx,ky,kz, phi,t, Ex,Ey,Ez, p);
}
%}
MCDISPLAY
%{
/* A bit ugly; hard-coded dimensions. */
magnify("");
if (shape == ANY) { /* OFF file */
off_display(offdata);
} else if(yheight){
line(0,-yheight/2.0,-zdepth/2.0, 0, yheight/2.0,-zdepth/2.0);
line(0,-yheight/2.0, zdepth/2.0, 0, yheight/2.0, zdepth/2.0);
line(0,-yheight/2.0,-zdepth/2.0, 0,-yheight/2.0, zdepth/2.0);
line(0, yheight/2.0,-zdepth/2.0, 0, yheight/2.0, zdepth/2.0);
}else{
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);
}
%}
END
|