/* Automatically generated file. Do not edit. * Format: ANSI C source code * Creator: McStas * Instrument: PANDA_Michal_DV_draft.instr (PANDA) * Date: Sat Feb 6 23:38:01 2021 * File: ./PANDA_Michal_DV_draft.c * CFLAGS= -Wl,-rpath,@MCCODE_LIB@/libs -L@MCCODE_LIB@/libs -lNCrystal -I@MCCODE_LIB@/include -DFUNNEL */ #define MCCODE_STRING "McStas 3.0 - Dec. 15, 2020" #define FLAVOR "mcstas" #define FLAVOR_UPPER "MCSTAS" #define MC_USE_DEFAULT_MAIN #define MC_TRACE_ENABLED #include #define PI 3.14159265358979323846 #ifndef M_PI #define M_PI PI #endif #ifndef M_2_PI #define M_2_PI 0.63661977236758134308 #endif #ifndef M_PI_2 #define M_PI_2 1.57079632679489661923 /* pi/2 */ #endif #ifndef M_SQRT2 #define M_SQRT2 1.4142135623730951 /* sqrt(2) */ #endif #ifdef DISABLE_TRACE #undef MC_TRACE_ENABLED #endif typedef double MCNUM; typedef struct {MCNUM x, y, z;} Coords; typedef MCNUM Rotation[3][3]; #define MCCODE_BASE_TYPES #ifdef OPENACC #undef MC_TRACE_ENABLED #endif #ifndef MC_NUSERVAR #define MC_NUSERVAR 10 #endif struct _struct_particle { double x,y,z; /* position [m] */ double vx,vy,vz; /* velocity [m/s] */ double sx,sy,sz; /* spin [0-1] */ int mcgravitation; /* gravity-state */ void *mcMagnet; /* precession-state */ int allow_backprop; /* allow backprop */ unsigned long randstate[7]; double t, p; /* time, event weight */ long long _uid; /* event ID */ long _index; /* component index where to send this event */ long _absorbed; /* flag set to TRUE when this event is to be removed/ignored */ long _scattered; /* flag set to TRUE when this event has interacted with the last component instance */ long _restore; /* set to true if neutron event must be restored */ }; typedef struct _struct_particle _class_particle; _class_particle _particle_global_randnbuse_var; _class_particle* _particle = &_particle_global_randnbuse_var; _class_particle mcgenstate(void); _class_particle mcsetstate(double x, double y, double z, double vx, double vy, double vz, double t, double sx, double sy, double sz, double p, int mcgravitation, int mcMagnet, int mcallowbackprop); extern int mcgravitation; /* flag to enable gravitation */ #pragma acc declare create ( mcgravitation ) int mcMagnet; /* precession-state */ #pragma acc declare create ( mcMagnet ) int mcallowbackprop; #pragma acc declare create ( mcallowbackprop ) #pragma acc routine _class_particle mcgenstate(void) { _class_particle particle = mcsetstate(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, mcgravitation, mcMagnet, mcallowbackprop); return(particle); } /*Generated user variable handlers:*/ #pragma acc routine double particle_getvar(_class_particle *p, char *name, int *suc){ #ifndef OPENACC #define str_comp strcmp #endif int s=1; double rval=0; if(!str_comp("x",name)){rval=p->x;s=0;} if(!str_comp("y",name)){rval=p->y;s=0;} if(!str_comp("z",name)){rval=p->z;s=0;} if(!str_comp("vx",name)){rval=p->vx;s=0;} if(!str_comp("vy",name)){rval=p->vy;s=0;} if(!str_comp("vz",name)){rval=p->vz;s=0;} if(!str_comp("sx",name)){rval=p->sx;s=0;} if(!str_comp("sy",name)){rval=p->sy;s=0;} if(!str_comp("sz",name)){rval=p->sz;s=0;} if(!str_comp("t",name)){rval=p->t;s=0;} if(!str_comp("p",name)){rval=p->p;s=0;} if (suc!=0x0) {*suc=s;} return rval; } #pragma acc routine double particle_getuservar_byid(_class_particle *p, int id, int *suc){ int s=1; double rval=0; switch(id){ } if (suc!=0x0) {*suc=s;} return rval; } #pragma acc routine void particle_uservar_init(_class_particle *p){ } #define MC_EMBEDDED_RUNTIME /* embedding file "mccode-r.h" */ /******************************************************************************* * * McCode, neutron/xray ray-tracing package * Copyright (C) 1997-2009, All rights reserved * Risoe National Laboratory, Roskilde, Denmark * Institut Laue Langevin, Grenoble, France * * Runtime: share/mccode-r.h * * %Identification * Written by: KN * Date: Aug 29, 1997 * Release: McStas 3.0 * Version: $Revision$ * * Runtime system header for McStas/McXtrace. * * In order to use this library as an external library, the following variables * and macros must be declared (see details in the code) * * struct mcinputtable_struct mcinputtable[]; * int numipar; * char instrument_name[], instrument_source[]; * int traceenabled, defaultmain; * extern MCNUM mccomp_storein[]; * extern MCNUM mcAbsorbProp[]; * extern MCNUM mcScattered; * #define MCCODE_STRING "the McStas/McXtrace version" * * Usage: Automatically embbeded in the c code. * * $Id$ * *******************************************************************************/ #ifndef MCCODE_R_H #define MCCODE_R_H "$Revision$" #include #include #include #include #include #include #include #include #include #include #include #ifdef OPENACC #include int noprintf(); int str_comp(char *str1, char *str2); size_t str_len(const char *s); #else #include #endif /* If the runtime is embedded in the simulation program, some definitions can be made static. */ #ifdef MC_EMBEDDED_RUNTIME # define mcstatic #else # define mcstatic #endif #ifdef __dest_os # if (__dest_os == __mac_os) # define MAC # endif #endif #ifdef __FreeBSD__ # define NEED_STAT_H #endif #if defined(__APPLE__) && defined(__GNUC__) # define NEED_STAT_H #endif #ifdef NEED_STAT_H # include #endif #ifndef MC_PATHSEP_C # ifdef WIN32 # define MC_PATHSEP_C '\\' # define MC_PATHSEP_S "\\" # else /* !WIN32 */ # define MC_PATHSEP_C '/' # define MC_PATHSEP_S "/" # endif /* !WIN32 */ #endif /* MC_PATHSEP_C */ /* the version string is replaced when building distribution with mkdist */ #ifndef MCCODE_STRING # define MCCODE_STRING "McStas 3.0 - Dec. 15, 2020" #endif #ifndef MCCODE_DATE # define MCCODE_DATE "Dec. 15, 2020" #endif #ifndef MCCODE_VERSION # define MCCODE_VERSION "3.0" #endif #ifndef MCCODE_NAME # define MCCODE_NAME "McStas" #endif #ifndef MCCODE_PARTICLE # define MCCODE_PARTICLE "neutron" #endif #ifndef MCCODE_PARTICLE_CODE # define MCCODE_PARTICLE_CODE 2112 #endif #ifndef MCCODE_LIBENV # define MCCODE_LIBENV "MCSTAS" #endif #ifndef FLAVOR_UPPER # define FLAVOR_UPPER MCCODE_NAME #endif #ifdef MC_PORTABLE # ifndef NOSIGNALS # define NOSIGNALS 1 # endif #endif #ifdef MAC # ifndef NOSIGNALS # define NOSIGNALS 1 # endif #endif #if (USE_MPI == 0) # undef USE_MPI #endif #ifdef USE_MPI /* default is to disable signals with MPI, as MPICH uses them to communicate */ # ifndef NOSIGNALS # define NOSIGNALS 1 # endif #endif #ifdef OPENACC /* default is to disable signals with PGI/OpenACC */ # ifndef NOSIGNALS # define NOSIGNALS 1 # endif #endif #ifndef OPENACC # ifndef USE_OFF /* default is to enable OFF when not using PGI/OpenACC */ # define USE_OFF # endif # ifdef FUNNEL /* disable FUNNEL-mode when not using PGI/OpenACC */ # undef FUNNEL # endif #endif #if (NOSIGNALS == 0) # undef NOSIGNALS #endif /* Note: the enum instr_formal_types definition MUST be kept synchronized with the one in mccode.h and with the instr_formal_type_names array in cogen.c. */ enum instr_formal_types { instr_type_int, instr_type_string, instr_type_char, instr_type_vector, instr_type_double }; struct mcinputtable_struct { /* defines instrument parameters */ char *name; /* name of parameter */ void *par; /* pointer to instrument parameter (variable) */ enum instr_formal_types type; char *val; /* default value */ }; #ifndef MCCODE_BASE_TYPES typedef double MCNUM; typedef struct {MCNUM x, y, z;} Coords; typedef MCNUM Rotation[3][3]; #endif /* the following variables are defined in the McStas generated C code but should be defined externally in case of independent library usage */ #ifndef DANSE extern struct mcinputtable_struct mcinputtable[]; /* list of instrument parameters */ extern int numipar; /* number of instrument parameters */ extern char instrument_name[], instrument_source[]; /* instrument name and filename */ extern char *instrument_exe; /* executable path = argv[0] or NULL */ extern char instrument_code[]; /* contains the initial 'instr' file */ #ifndef MC_ANCIENT_COMPATIBILITY extern int traceenabled, defaultmain; #endif #endif /* Useful macros ============================================================ */ /* SECTION: Dynamic Arrays */ typedef double* DArray1d; DArray1d create_darr1d(int n); void destroy_darr1d(DArray1d a); typedef double** DArray2d; DArray2d create_darr2d(int nx, int ny); void destroy_darr2d(DArray2d a); typedef double*** DArray3d; DArray3d create_darr3d(int nx, int ny, int nz); void destroy_darr3d(DArray3d a); /* MPI stuff */ #ifdef USE_MPI #include "mpi.h" #ifdef OMPI_MPI_H /* openmpi does not use signals: we may install our sighandler */ #ifndef OPENACC /* ... but only if we are not also running on GPU */ #undef NOSIGNALS #endif #endif /* * MPI_MASTER(i): * execution of i only on master node */ #define MPI_MASTER(statement) { \ if(mpi_node_rank == mpi_node_root)\ { statement; } \ } #ifndef MPI_REDUCE_BLOCKSIZE #define MPI_REDUCE_BLOCKSIZE 1000 #endif int mc_MPI_Sum(double* buf, long count); int mc_MPI_Send(void *sbuf, long count, MPI_Datatype dtype, int dest); int mc_MPI_Recv(void *rbuf, long count, MPI_Datatype dtype, int source); /* MPI_Finalize exits gracefully and should be preferred to MPI_Abort */ #define exit(code) do { \ MPI_Finalize(); \ exit(code); \ } while(0) #else /* !USE_MPI */ #define MPI_MASTER(instr) instr #endif /* USE_MPI */ #ifdef USE_MPI static int mpi_node_count; #endif #ifdef USE_THREADS /* user want threads */ #error Threading (USE_THREADS) support has been removed for very poor efficiency. Use MPI/SSH grid instead. #endif void mcset_ncount(unsigned long long count); /* wrapper to get mcncount */ unsigned long long int mcget_ncount(void); /* wrapper to set mcncount */ unsigned long long mcget_run_num(void); /* wrapper to get mcrun_num=0:mcncount */ /* Following part is only embedded when not redundant with mccode.h ========= */ #ifndef MCCODE_H #ifndef NOSIGNALS #include char *mcsig_message; #define SIG_MESSAGE(msg) mcsig_message=(char *)(msg); #else #define SIG_MESSAGE(...) #endif /* !NOSIGNALS */ /* Useful macros and constants ============================================== */ #ifndef FLT_MAX #define FLT_MAX 3.40282347E+38F /* max decimal value of a "float" */ #endif #ifndef MIN #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX #define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif #ifndef SQR #define SQR(x) ( (x) * (x) ) #endif #ifndef SIGN #define SIGN(x) (((x)>0.0)?(1):(-1)) #endif #ifndef PI # ifdef M_PI # define PI M_PI # else /* When using c99 in the CFLAGS, some of these consts are lost... Perhaps we should in fact include everything from https://www.gnu.org/software/libc/manual/html_node/Mathematical-Constants.html */ # define PI 3.14159265358979323846 # define M_PI PI # define M_PI_2 M_PI/2.0 # define M_PI_4 M_PI/4.0 # define M_1_PI 1.0/M_PI # define M_2_PI 2*M_1_PI # endif #endif #define RAD2MIN ((180*60)/PI) #define MIN2RAD (PI/(180*60)) #define DEG2RAD (PI/180) #define RAD2DEG (180/PI) #define FWHM2RMS 0.424660900144 /* Convert between full-width-half-max and */ #define RMS2FWHM 2.35482004503 /* root-mean-square (standard deviation) */ #define HBAR 1.05457168e-34 /* [Js] h bar Planck constant CODATA 2002 */ #define MNEUTRON 1.67492728e-27 /* [kg] mass of neutron CODATA 2002 */ #define GRAVITY 9.81 /* [m/s^2] gravitational acceleration */ #define NA 6.02214179e23 /* [#atoms/g .mole] Avogadro's number*/ /* wrapper to get absolute and relative position of comp */ /* mccomp_posa and mccomp_posr are defined in McStas generated C code */ #define POS_A_COMP_INDEX(index) (instrument->_position_absolute[index]) #define POS_R_COMP_INDEX(index) (instrument->_position_relative[index]) /* setting parameters based COMP_GETPAR (returned as pointer) */ /* compname must be given as a string, type and par are symbols. */ #define COMP_GETPAR3(type, compname, par) \ &( ((_class_ ## type ##_parameters *) _getvar_parameters(compname))->par ) /* the body of this function depends on component instances, and is cogen'd */ void* _getvar_parameters(char* compname); /* Note: The two-stage approach to COMP_GETPAR is NOT redundant; without it, * after #define C sample, COMP_GETPAR(C,x) would refer to component C, not to * component sample. Such are the joys of ANSI C. * Anyway the usage of COMP_GETPAR requires that we use sometimes bare names... * NOTE: This can ONLY be used in instrument descriptions, not components. */ #define COMP_GETPAR2(comp, par) (_ ## comp ## _var._parameters.par) #define COMP_GETPAR(comp, par) COMP_GETPAR2(comp,par) #define INSTRUMENT_GETPAR(par) (_instrument_var._parameters.par) /* Current component name, index, position and orientation */ /* These macros work because, using class-based functions, "comp" is usually * the local variable of the active/current component. */ #define INDEX_CURRENT_COMP (_comp->_index) #define NAME_CURRENT_COMP (_comp->_name) #define TYPE_CURRENT_COMP (_comp->_type) #define POS_A_CURRENT_COMP (_comp->_position_absolute) #define POS_R_CURRENT_COMP (_comp->_position_relative) #define ROT_A_CURRENT_COMP (_comp->_rotation_absolute) #define ROT_R_CURRENT_COMP (_comp->_rotation_relative) #define NAME_INSTRUMENT (instrument->_name) /* MCDISPLAY/trace and debugging message sent to stdout */ #ifdef MC_TRACE_ENABLED #define DEBUG #endif #ifdef DEBUG #define DEBUG_INSTR() if(!mcdotrace); else { printf("INSTRUMENT:\n"); printf("Instrument '%s' (%s)\n", instrument_name, instrument_source); } #define DEBUG_COMPONENT(name,c,t) if(!mcdotrace); else {\ printf("COMPONENT: \"%s\"\n" \ "POS: %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g\n", \ name, c.x, c.y, c.z, t[0][0], t[0][1], t[0][2], \ t[1][0], t[1][1], t[1][2], t[2][0], t[2][1], t[2][2]); \ printf("Component %30s AT (%g,%g,%g)\n", name, c.x, c.y, c.z); \ } #define DEBUG_INSTR_END() if(!mcdotrace); else printf("INSTRUMENT END:\n"); #define DEBUG_ENTER() if(!mcdotrace); else printf("ENTER:\n"); #define DEBUG_COMP(c) if(!mcdotrace); else printf("COMP: \"%s\"\n", c); #define DEBUG_LEAVE() if(!mcdotrace); else printf("LEAVE:\n"); #define DEBUG_ABSORB() if(!mcdotrace); else printf("ABSORB:\n"); #else #define DEBUG_INSTR() #define DEBUG_COMPONENT(name,c,t) #define DEBUG_INSTR_END() #define DEBUG_ENTER() #define DEBUG_COMP(c) #define DEBUG_LEAVE() #define DEBUG_ABSORB() #endif // mcDEBUG_STATE and mcDEBUG_SCATTER are defined by mcstas-r.h and mcxtrace-r.h #ifdef TEST #define test_printf printf #else #define test_printf while(0) printf #endif /* send MCDISPLAY message to stdout to show gemoetry */ void mcdis_magnify(char *what); void mcdis_line(double x1, double y1, double z1, double x2, double y2, double z2); void mcdis_dashed_line(double x1, double y1, double z1, double x2, double y2, double z2, int n); void mcdis_multiline(int count, ...); void mcdis_rectangle(char* plane, double x, double y, double z, double width, double height); void mcdis_box(double x, double y, double z, double width, double height, double length); void mcdis_circle(char *plane, double x, double y, double z, double r); void mcdis_Circle(double x, double y, double z, double r, double nx, double ny, double nz); void mcdis_cylinder( double x, double y, double z, double r, double height, int N, double nx, double ny, double nz); void mcdis_sphere(double x, double y, double z, double r, int N); # define MC_RAND_MAX ((unsigned long)0xffffffff) /* random number generation. ================================================ */ /* available random number generators */ #define _RNG_ALG_MT 1 #define _RNG_ALG_KISS 2 #define _RNG_ALG_FAST_KISS 3 #define _RNG_ALG_CUDA 4 /* selection of random number generator */ #ifndef RNG_ALG # define RNG_ALG _RNG_ALG_KISS #endif #if RNG_ALG == _RNG_ALG_MT // MT (currently not functional for gpu) # define MC_RAND_MAX ((unsigned long)0xffffffff) # define randstate_t unsigned long // this could be anything # define RANDSTATE_LEN 1 # define srandom(seed) mt_srandom_empty() # define random() mt_random() # define _random() mt_random() #elif RNG_ALG == _RNG_ALG_KISS // KISS # ifndef ULONG_MAX # define ULONG_MAX ((unsigned long)0xffffffffffffffffUL) # endif # define MC_RAND_MAX ULONG_MAX # define randstate_t unsigned long # define RANDSTATE_LEN 7 # define srandom(seed) kiss_srandom(_particle->randstate, seed) # define random() kiss_random(_particle->randstate) # define _random() kiss_random(state) #elif RNG_ALG == _RNG_ALG_FAST_KISS // FAST KISS Hundt impl. (not yet functional) # define randstate_t uint32_t # define RANDSTATE_LEN 5 # define srandom(seed) fast_kiss_srandom(_particle->randstate, seed) # define random() fast_kiss_random(_particle->randstate) # define _random() kiss_random(state) # define _rand01 #elif RNG_ALG == _RNG_ALG_CUDA # include # define randstate_t curandState_t /* CUDA RNG state */ # define srandom(seed) curand_init(_particle->_uid, seed, 0ULL, _particle->randstate); # define random() curand_uniform(_particle->randstate) # define _random() curand_uniform(state); #endif // component writers interface #define randnorm() _randnorm2(_particle->randstate) // NOTE: can not use _randnorm on gpu #define rand01() _rand01(_particle->randstate) #define randpm1() _randpm1(_particle->randstate) #define rand0max(p1) _rand0max(p1, _particle->randstate) #define randminmax(p1, p2) _randminmax(p1, p2, _particle->randstate) #define randtriangle() _randtriangle(_particle->randstate) // Mersenne Twister rng unsigned long mt_random(void); void mt_srandom (unsigned long x); void mt_srandom_empty(); // KISS rng unsigned long *kiss_srandom(unsigned long state[7], unsigned long seed); unsigned long kiss_random(unsigned long state[7]); // FAST KISS rng randstate_t _hash(randstate_t x); randstate_t fast_kiss(randstate_t * state); randstate_t * fast_kiss_seed(randstate_t * state, randstate_t seed); // internal RNG (transforms) interface double _rand01(randstate_t* state); double _randpm1(randstate_t* state); double _rand0max(double max, randstate_t* state); double _randminmax(double min, double max, randstate_t* state); double _randtriangle(randstate_t* state); // some rngs use this package instead double _uniform_double(randstate_t * state); double _gaussian_double(randstate_t * state); #ifdef USE_OPENCL #include "opencl-lib.h" #include "opencl-lib.c" #endif #ifndef DANSE int init(void); int raytrace(_class_particle*); int save(FILE *); int finally(void); int display(void); #endif /* GPU related algorithms =================================================== */ /* * Divide-and-conquer strategy for parallel sort absorbed last. */ #ifdef FUNNEL long sort_absorb_last(_class_particle* particles, _class_particle* pbuffer, long len, long buffer_len, long flag_split, long* multiplier); #endif long sort_absorb_last_serial(_class_particle* particles, long len); /* simple vector algebra ==================================================== */ #define vec_prod(x, y, z, x1, y1, z1, x2, y2, z2) \ vec_prod_func(&x, &y, &z, x1, y1, z1, x2, y2, z2) mcstatic void vec_prod_func(double *x, double *y, double *z, double x1, double y1, double z1, double x2, double y2, double z2); mcstatic double scalar_prod( double x1, double y1, double z1, double x2, double y2, double z2); mcstatic void norm_func(double *x, double *y, double *z); #define NORM(x,y,z) norm_func(&x, &y, &z) void normal_vec(double *nx, double *ny, double *nz, double x, double y, double z); /** * Rotate the vector vx,vy,vz psi radians around the vector ax,ay,az * and put the result in x,y,z. */ #define rotate(x, y, z, vx, vy, vz, phi, ax, ay, az) \ do { \ double mcrt_tmpx = (ax), mcrt_tmpy = (ay), mcrt_tmpz = (az); \ double mcrt_vp, mcrt_vpx, mcrt_vpy, mcrt_vpz; \ double mcrt_vnx, mcrt_vny, mcrt_vnz, mcrt_vn1x, mcrt_vn1y, mcrt_vn1z; \ double mcrt_bx, mcrt_by, mcrt_bz; \ double mcrt_cos, mcrt_sin; \ NORM(mcrt_tmpx, mcrt_tmpy, mcrt_tmpz); \ mcrt_vp = scalar_prod((vx), (vy), (vz), mcrt_tmpx, mcrt_tmpy, mcrt_tmpz); \ mcrt_vpx = mcrt_vp*mcrt_tmpx; \ mcrt_vpy = mcrt_vp*mcrt_tmpy; \ mcrt_vpz = mcrt_vp*mcrt_tmpz; \ mcrt_vnx = (vx) - mcrt_vpx; \ mcrt_vny = (vy) - mcrt_vpy; \ mcrt_vnz = (vz) - mcrt_vpz; \ vec_prod(mcrt_bx, mcrt_by, mcrt_bz, \ mcrt_tmpx, mcrt_tmpy, mcrt_tmpz, mcrt_vnx, mcrt_vny, mcrt_vnz); \ mcrt_cos = cos((phi)); mcrt_sin = sin((phi)); \ mcrt_vn1x = mcrt_vnx*mcrt_cos + mcrt_bx*mcrt_sin; \ mcrt_vn1y = mcrt_vny*mcrt_cos + mcrt_by*mcrt_sin; \ mcrt_vn1z = mcrt_vnz*mcrt_cos + mcrt_bz*mcrt_sin; \ (x) = mcrt_vpx + mcrt_vn1x; \ (y) = mcrt_vpy + mcrt_vn1y; \ (z) = mcrt_vpz + mcrt_vn1z; \ } while(0) /** * Mirror (xyz) in the plane given by the point (rx,ry,rz) and normal (nx,ny,nz) * * TODO: This define is seemingly never used... */ #define mirror(x,y,z,rx,ry,rz,nx,ny,nz) \ do { \ double mcrt_tmpx= (nx), mcrt_tmpy = (ny), mcrt_tmpz = (nz); \ double mcrt_tmpt; \ NORM(mcrt_tmpx, mcrt_tmpy, mcrt_tmpz); \ mcrt_tmpt=scalar_prod((rx),(ry),(rz),mcrt_tmpx,mcrt_tmpy,mcrt_tmpz); \ (x) = rx -2 * mcrt_tmpt*mcrt_rmpx; \ (y) = ry -2 * mcrt_tmpt*mcrt_rmpy; \ (z) = rz -2 * mcrt_tmpt*mcrt_rmpz; \ } while (0) Coords coords_set(MCNUM x, MCNUM y, MCNUM z); Coords coords_get(Coords a, MCNUM *x, MCNUM *y, MCNUM *z); Coords coords_add(Coords a, Coords b); Coords coords_sub(Coords a, Coords b); Coords coords_neg(Coords a); Coords coords_scale(Coords b, double scale); double coords_sp(Coords a, Coords b); Coords coords_xp(Coords b, Coords c); double coords_len(Coords a); void coords_print(Coords a); mcstatic void coords_norm(Coords* c); void rot_set_rotation(Rotation t, double phx, double phy, double phz); int rot_test_identity(Rotation t); void rot_mul(Rotation t1, Rotation t2, Rotation t3); void rot_copy(Rotation dest, Rotation src); void rot_transpose(Rotation src, Rotation dst); Coords rot_apply(Rotation t, Coords a); void mccoordschange(Coords a, Rotation t, _class_particle *particle); void mccoordschange_polarisation(Rotation t, double *sx, double *sy, double *sz); double mcestimate_error(double N, double p1, double p2); void mcreadparams(void); /* this is now in mcstas-r.h and mcxtrace-r.h as the number of state parameters is no longer equal */ _class_particle mcgenstate(void); // trajectory/shape intersection routines int inside_rectangle(double, double, double, double); int box_intersect(double *dt_in, double *dt_out, double x, double y, double z, double vx, double vy, double vz, double dx, double dy, double dz); int cylinder_intersect(double *t0, double *t1, double x, double y, double z, double vx, double vy, double vz, double r, double h); int sphere_intersect(double *t0, double *t1, double x, double y, double z, double vx, double vy, double vz, double r); // second order equation roots int solve_2nd_order(double *t1, double *t2, double A, double B, double C); // random vector generation to shape // defines silently introducing _particle as the last argument #define randvec_target_circle(xo, yo, zo, solid_angle, xi, yi, zi, radius) \ _randvec_target_circle(xo, yo, zo, solid_angle, xi, yi, zi, radius, _particle) #define randvec_target_rect_angular(xo, yo, zo, solid_angle, xi, yi, zi, height, width, A) \ _randvec_target_rect_angular(xo, yo, zo, solid_angle, xi, yi, zi, height, width, A, _particle) #define randvec_target_rect_real(xo, yo, zo, solid_angle, xi, yi, zi, height, width, A, lx, ly, lz, order) \ _randvec_target_rect_real(xo, yo, zo, solid_angle, xi, yi, zi, height, width, A, lx, ly, lz, order, _particle) // defines forwarding to "inner" functions #define randvec_target_sphere randvec_target_circle #define randvec_target_rect(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9) \ randvec_target_rect_real(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,0,0,0,1) // headers for randvec void _randvec_target_circle(double *xo, double *yo, double *zo, double *solid_angle, double xi, double yi, double zi, double radius, _class_particle* _particle); void _randvec_target_rect_angular(double *xo, double *yo, double *zo, double *solid_angle, double xi, double yi, double zi, double height, double width, Rotation A, _class_particle* _particle); void _randvec_target_rect_real(double *xo, double *yo, double *zo, double *solid_angle, double xi, double yi, double zi, double height, double width, Rotation A, double lx, double ly, double lz, int order, _class_particle* _particle); // this is the main() int mccode_main(int argc, char *argv[]); #endif /* !MCCODE_H */ #ifndef MCCODE_R_IO_H #define MCCODE_R_IO_H "$Revision$" #if (USE_NEXUS == 0) #undef USE_NEXUS #endif #ifndef CHAR_BUF_LENGTH #define CHAR_BUF_LENGTH 1024 #endif /* I/O section part ========================================================= */ /* ========================================================================== */ /* MCCODE_R_IO_C */ /* ========================================================================== */ /* main DETECTOR structure which stores most information to write to data files */ struct mcdetector_struct { char filename[CHAR_BUF_LENGTH]; /* file name of monitor */ char position[CHAR_BUF_LENGTH]; /* position of detector component */ char component[CHAR_BUF_LENGTH]; /* component instance name */ char instrument[CHAR_BUF_LENGTH]; /* instrument name */ char type[CHAR_BUF_LENGTH]; /* data type, e.g. 0d, 1d, 2d, 3d */ char user[CHAR_BUF_LENGTH]; /* user name, e.g. HOME */ char date[CHAR_BUF_LENGTH]; /* date of simulation end/write time */ char title[CHAR_BUF_LENGTH]; /* title of detector */ char xlabel[CHAR_BUF_LENGTH]; /* X axis label */ char ylabel[CHAR_BUF_LENGTH]; /* Y axis label */ char zlabel[CHAR_BUF_LENGTH]; /* Z axis label */ char xvar[CHAR_BUF_LENGTH]; /* X variable name */ char yvar[CHAR_BUF_LENGTH]; /* Y variable name */ char zvar[CHAR_BUF_LENGTH]; /* Z variable name */ char ncount[CHAR_BUF_LENGTH]; /* number of events initially generated */ char limits[CHAR_BUF_LENGTH]; /* X Y Z limits, e.g. [xmin xmax ymin ymax zmin zmax] */ char variables[CHAR_BUF_LENGTH]; /* variables written into data block */ char statistics[CHAR_BUF_LENGTH]; /* center, mean and half width along axis */ char signal[CHAR_BUF_LENGTH]; /* min max and mean of signal (data block) */ char values[CHAR_BUF_LENGTH]; /* integrated values e.g. [I I_err N] */ double xmin,xmax; /* min max of axes */ double ymin,ymax; double zmin,zmax; double intensity; /* integrated values for data block */ double error; double events; double min; /* statistics for data block */ double max; double mean; double centerX; /* statistics for axes */ double halfwidthX; double centerY; double halfwidthY; int rank; /* dimensionaly of monitor, e.g. 0 1 2 3 */ char istransposed; /* flag to transpose matrix for some formats */ long m,n,p; /* dimensions of data block and along axes */ long date_l; /* same as date, but in sec since 1970 */ double *p0, *p1, *p2; /* pointers to saved data, NULL when freed */ char format[CHAR_BUF_LENGTH]; /* format for file generation */ }; typedef struct mcdetector_struct MCDETECTOR; static char *dirname = NULL; /* name of output directory */ static char *siminfo_name = "mccode"; /* default output sim file name */ char *mcformat = NULL; /* NULL (default) or a specific format */ /* file I/O definitions and function prototypes */ #ifndef MC_EMBEDDED_RUNTIME /* the mcstatic variables (from mccode-r.c) */ extern FILE * siminfo_file; /* handle to the output siminfo file */ extern int mcgravitation; /* flag to enable gravitation */ #pragma acc declare create ( mcgravitation ) extern int mcdotrace; /* flag to print MCDISPLAY messages */ #else mcstatic FILE *siminfo_file = NULL; #endif /* I/O function prototypes ================================================== */ // from msysgit: https://code.google.com/p/msysgit/source/browse/compat/strcasestr.c char *strcasestr(const char *haystack, const char *needle); /* output functions */ MCDETECTOR mcdetector_out_0D(char *t, double p0, double p1, double p2, char *c, Coords pos); MCDETECTOR mcdetector_out_1D(char *t, char *xl, char *yl, char *xvar, double x1, double x2, long n, double *p0, double *p1, double *p2, char *f, char *c, Coords pos); MCDETECTOR mcdetector_out_2D(char *t, char *xl, char *yl, double x1, double x2, double y1, double y2, long m, long n, double *p0, double *p1, double *p2, char *f, char *c, Coords pos); MCDETECTOR mcdetector_out_list(char *t, char *xl, char *yl, long m, long n, double *p1, char *f, char *c, Coords posa); /* wrappers to output functions, that automatically set NAME and POSITION */ #define DETECTOR_OUT(p0,p1,p2) mcdetector_out_0D(NAME_CURRENT_COMP,p0,p1,p2,NAME_CURRENT_COMP,POS_A_CURRENT_COMP) #define DETECTOR_OUT_0D(t,p0,p1,p2) mcdetector_out_0D(t,p0,p1,p2,NAME_CURRENT_COMP,POS_A_CURRENT_COMP) #define DETECTOR_OUT_1D(t,xl,yl,xvar,x1,x2,n,p0,p1,p2,f) \ mcdetector_out_1D(t,xl,yl,xvar,x1,x2,n,p0,p1,p2,f,NAME_CURRENT_COMP,POS_A_CURRENT_COMP) #define DETECTOR_OUT_2D(t,xl,yl,x1,x2,y1,y2,m,n,p0,p1,p2,f) \ mcdetector_out_2D(t,xl,yl,x1,x2,y1,y2,m,n,p0,p1,p2,f,NAME_CURRENT_COMP,POS_A_CURRENT_COMP) #ifdef USE_NEXUS #include "napi.h" NXhandle nxhandle; #endif #endif /* ndef MCCODE_R_IO_H */ #endif /* MCCODE_R_H */ /* End of file "mccode-r.h". */ /* embedding file "mcstas-r.h" */ /******************************************************************************* * * McStas, neutron ray-tracing package * Copyright (C) 1997-2009, All rights reserved * Risoe National Laboratory, Roskilde, Denmark * Institut Laue Langevin, Grenoble, France * * Runtime: share/mcstas-r.h * * %Identification * Written by: KN * Date: Aug 29, 1997 * Release: McStas X.Y * Version: $Revision$ * * Runtime system header for McStas. * * In order to use this library as an external library, the following variables * and macros must be declared (see details in the code) * * struct mcinputtable_struct mcinputtable[]; * int mcnumipar; * char instrument_name[], instrument_source[]; * int traceenabled, defaultmain; * extern MCNUM mccomp_storein[]; * extern MCNUM instrument.counter_AbsorbProp[]; * extern MCNUM mcScattered; * #define MCCODE_STRING "the McStas version" * * Usage: Automatically embbeded in the c code. * * $Id$ * *******************************************************************************/ #ifndef MCSTAS_R_H #define MCSTAS_R_H "$Revision$" /* Following part is only embedded when not redundent with mcstas.h ========= */ #ifndef MCCODE_H #define AA2MS 629.622368 /* Convert k[1/AA] to v[m/s] */ #define MS2AA 1.58825361e-3 /* Convert v[m/s] to k[1/AA] */ #define K2V AA2MS #define V2K MS2AA #define Q2V AA2MS #define V2Q MS2AA #define SE2V 437.393377 /* Convert sqrt(E)[meV] to v[m/s] */ #define VS2E 5.22703725e-6 /* Convert (v[m/s])**2 to E[meV] */ #define SCATTER0 do {DEBUG_SCATTER(); SCATTERED++;} while(0) #define SCATTER SCATTER0 #define JUMPTOCOMP(comp) mcneutron->_index = INDEX_COMP(comp); #define MAGNET_ON \ do { \ mcMagnet = 1; \ } while(0) #define MAGNET_OFF \ do { \ mcMagnet = 0; \ } while(0) #define ALLOW_BACKPROP \ do { \ mcallowbackprop = 1; \ } while(0) #define DISALLOW_BACKPROP \ do { \ mcallowbackprop = 0; \ } while(0) #define PROP_MAGNET(dt) \ do { \ } while (0) /* change coordinates from local system to magnet system */ /* Rotation rotLM, rotTemp; \ Coords posLM = coords_sub(POS_A_CURRENT_COMP, mcMagnetPos); \ rot_transpose(ROT_A_CURRENT_COMP, rotTemp); \ rot_mul(rotTemp, mcMagnetRot, rotLM); \ mcMagnetPrecession(x, y, z, t, vx, vy, vz, \ &sx, &sy, &sz, dt, posLM, rotLM); \ } while(0) */ #define mcPROP_DT(dt) \ do { \ if (mcMagnet && dt > 0) PROP_MAGNET(dt);\ x += vx*(dt); \ y += vy*(dt); \ z += vz*(dt); \ t += (dt); \ if (isnan(p) || isinf(p)) { ABSORB; }\ } while(0) /* ADD: E. Farhi, Aug 6th, 2001 PROP_GRAV_DT propagation with acceleration */ #define PROP_GRAV_DT(dt, Ax, Ay, Az) \ do { \ if(dt < 0 && mcallowbackprop == 0) { ABSORB; }\ if (mcMagnet) /*printf("Spin precession gravity\n")*/; \ x += vx*(dt) + (Ax)*(dt)*(dt)/2; \ y += vy*(dt) + (Ay)*(dt)*(dt)/2; \ z += vz*(dt) + (Az)*(dt)*(dt)/2; \ vx += (Ax)*(dt); \ vy += (Ay)*(dt); \ vz += (Az)*(dt); \ t += (dt); \ DISALLOW_BACKPROP;\ } while(0) #define PROP_DT(dt) \ do { \ if(dt < 0) { RESTORE=1; ABSORB; }; \ if (mcgravitation) { Coords mcLocG; double mc_gx, mc_gy, mc_gz; \ mcLocG = rot_apply(ROT_A_CURRENT_COMP, coords_set(0,-GRAVITY,0)); \ coords_get(mcLocG, &mc_gx, &mc_gy, &mc_gz); \ PROP_GRAV_DT(dt, mc_gx, mc_gy, mc_gz); } \ else mcPROP_DT(dt); \ DISALLOW_BACKPROP;\ } while(0) #define PROP_Z0 \ do { \ if (mcgravitation) { Coords mcLocG; int mc_ret; \ double mc_dt, mc_gx, mc_gy, mc_gz; \ mcLocG = rot_apply(ROT_A_CURRENT_COMP, coords_set(0,-GRAVITY,0)); \ coords_get(mcLocG, &mc_gx, &mc_gy, &mc_gz); \ mc_ret = solve_2nd_order(&mc_dt, NULL, -mc_gz/2, -vz, -z); \ if (mc_ret && mc_dt>=0) PROP_GRAV_DT(mc_dt, mc_gx, mc_gy, mc_gz); \ else { if (mcallowbackprop ==0) { ABSORB; }}; } \ else mcPROP_Z0; \ DISALLOW_BACKPROP;\ } while(0) #define mcPROP_Z0 \ do { \ double mc_dt; \ if(vz == 0) { ABSORB; }; \ mc_dt = -z/vz; \ if(mc_dt < 0 && mcallowbackprop == 0) { ABSORB; }; \ mcPROP_DT(mc_dt); \ z = 0; \ DISALLOW_BACKPROP;\ } while(0) #define PROP_X0 \ do { \ if (mcgravitation) { Coords mcLocG; int mc_ret; \ double mc_dt, mc_gx, mc_gy, mc_gz; \ mcLocG = rot_apply(ROT_A_CURRENT_COMP, coords_set(0,-GRAVITY,0)); \ coords_get(mcLocG, &mc_gx, &mc_gy, &mc_gz); \ mc_ret = solve_2nd_order(&mc_dt, NULL, -mc_gx/2, -vx, -x); \ if (mc_ret && mc_dt>=0) PROP_GRAV_DT(mc_dt, mc_gx, mc_gy, mc_gz); \ else { if (mcallowbackprop ==0) { ABSORB; }}; }\ else mcPROP_X0; \ DISALLOW_BACKPROP;\ } while(0) #define mcPROP_X0 \ do { \ double mc_dt; \ if(vx == 0) { ABSORB; }; \ mc_dt = -x/vx; \ if(mc_dt < 0 && mcallowbackprop == 0) { ABSORB; }; \ mcPROP_DT(mc_dt); \ x = 0; \ DISALLOW_BACKPROP;\ } while(0) #define PROP_Y0 \ do { \ if (mcgravitation) { Coords mcLocG; int mc_ret; \ double mc_dt, mc_gx, mc_gy, mc_gz; \ mcLocG = rot_apply(ROT_A_CURRENT_COMP, coords_set(0,-GRAVITY,0)); \ coords_get(mcLocG, &mc_gx, &mc_gy, &mc_gz); \ mc_ret = solve_2nd_order(&mc_dt, NULL, -mc_gy/2, -vy, -y); \ if (mc_ret && mc_dt>=0) PROP_GRAV_DT(mc_dt, mc_gx, mc_gy, mc_gz); \ else { if (mcallowbackprop ==0) { ABSORB; }}; }\ else mcPROP_Y0; \ DISALLOW_BACKPROP;\ } while(0) #define mcPROP_Y0 \ do { \ double mc_dt; \ if(vy == 0) { ABSORB; }; \ mc_dt = -y/vy; \ if(mc_dt < 0 && mcallowbackprop == 0) { ABSORB; }; \ mcPROP_DT(mc_dt); \ y = 0; \ DISALLOW_BACKPROP; \ } while(0) #pragma acc routine seq _class_particle mcsetstate(double x, double y, double z, double vx, double vy, double vz, double t, double sx, double sy, double sz, double p, int mcgravitation, int mcMagnet, int mcallowbackprop); #ifdef DEBUG #define DEBUG_STATE() if(!mcdotrace); else \ printf("STATE: %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g\n", \ x,y,z,vx,vy,vz,t,sx,sy,sz,p); #define DEBUG_SCATTER() if(!mcdotrace); else \ printf("SCATTER: %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g\n", \ x,y,z,vx,vy,vz,t,sx,sy,sz,p); #else #define DEBUG_STATE() #define DEBUG_SCATTER() #endif #endif /* !MCCODE_H */ #endif /* MCSTAS_R_H */ /* End of file "mcstas-r.h". */ /* embedding file "mccode-r.c" */ /******************************************************************************* * * McCode, neutron/xray ray-tracing package * Copyright (C) 1997-2009, All rights reserved * Risoe National Laboratory, Roskilde, Denmark * Institut Laue Langevin, Grenoble, France * * Runtime: share/mccode-r.c * * %Identification * Written by: KN * Date: Aug 29, 1997 * Release: McStas X.Y/McXtrace X.Y * Version: $Revision$ * * Runtime system for McStas and McXtrace. * Embedded within instrument in runtime mode. * Contains SECTIONS: * MPI handling (sum, send, recv) * format definitions * I/O * mcdisplay support * random numbers * coordinates handling * vectors math (solve 2nd order, normals, randvec...) * parameter handling * signal and main handlers * * Usage: Automatically embbeded in the c code whenever required. * * $Id$ * *******************************************************************************/ /******************************************************************************* * The I/O format definitions and functions *******************************************************************************/ /** Include header files to avoid implicit declarations (not allowed on LLVM) */ #include #include // UNIX specific headers (non-Windows) #if defined(__unix__) || defined(__APPLE__) #include #include #endif #ifndef DANSE #ifdef MC_ANCIENT_COMPATIBILITY int traceenabled = 0; int defaultmain = 0; #endif /* else defined directly in the McCode generated C code */ static long mcseed = 0; /* seed for random generator */ #pragma acc declare create ( mcseed ) static long mcstartdate = 0; /* start simulation time */ static int mcdisable_output_files = 0; /* --no-output-files */ mcstatic int mcgravitation = 0; /* use gravitation flag, for PROP macros */ #pragma acc declare create ( mcgravitation ) int mcMagnet = 0; /* magnet stack flag */ #pragma acc declare create ( mcMagnet ) mcstatic int mcdotrace = 0; /* flag for --trace and messages for DISPLAY */ int mcallowbackprop = 0; /* flag to enable negative/backprop */ #pragma acc declare create ( mcallowbackprop ) /* Number of particle histories to simulate. */ #ifdef NEUTRONICS mcstatic unsigned long long int mcncount = 1; mcstatic unsigned long long int mcrun_num = 0; #else #ifdef MCDEFAULT_NCOUNT mcstatic unsigned long long int mcncount = MCDEFAULT_NCOUNT; #else mcstatic unsigned long long int mcncount = 1000000; #endif #pragma acc declare create ( mcncount ) mcstatic unsigned long long int mcrun_num = 0; #pragma acc declare create ( mcrun_num ) #endif /* NEUTRONICS */ #else #include "mcstas-globals.h" #endif /* !DANSE */ /* String nullification on GPU and other replacements */ #ifdef OPENACC #pragma acc routine seq int noprintf() { return 0; } #pragma acc routine seq int str_comp(char *str1, char *str2) { while (*str1 && *str1 == *str2) { str1++; str2++; } return (*str1 - *str2); } #pragma acc routine seq size_t str_len(const char *s) { size_t len = 0; if(s != NULL) { while(*s != '\0') { ++len; ++s; } } return len; } #endif /* SECTION: Dynamic Arrays ================================================== */ DArray1d create_darr1d(int n){ DArray1d arr2d; arr2d = calloc(n, sizeof(double)); return arr2d; } void destroy_darr1d(DArray1d a){ free(a); } DArray2d create_darr2d(int nx, int ny){ DArray2d arr2d; arr2d = calloc(nx, sizeof(double *)); double *p1; p1 = calloc(nx*ny, sizeof(double)); int i; for (i=0; i count-1) length=count-offset; else length=MPI_REDUCE_BLOCKSIZE; if (MPI_Allreduce((double*)(sbuf+offset), (double*)(rbuf+offset), length, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD) != MPI_SUCCESS) return MPI_ERR_COUNT; offset += length; } for (i=0; i count-1) length=count-offset; else length=MPI_REDUCE_BLOCKSIZE; if (MPI_Send((void*)(sbuf+offset*dsize), length, dtype, dest, tag++, MPI_COMM_WORLD) != MPI_SUCCESS) return MPI_ERR_COUNT; offset += length; } return MPI_SUCCESS; } /* mc_MPI_Send */ /******************************************************************************* * mc_MPI_Recv: Receives arrays from MPI nodes by blocks to avoid buffer limit * the buffer must have been allocated previously. *******************************************************************************/ int mc_MPI_Recv(void *sbuf, long count, MPI_Datatype dtype, int source) { int dsize; long offset=0; int tag=1; int length=MPI_REDUCE_BLOCKSIZE; /* defined in mccode-r.h */ if (!sbuf || count <= 0) return(MPI_SUCCESS); /* nothing to recv */ MPI_Type_size(dtype, &dsize); while (offset < count) { if (offset+length > count-1) length=count-offset; else length=MPI_REDUCE_BLOCKSIZE; if (MPI_Recv((void*)(sbuf+offset*dsize), length, dtype, source, tag++, MPI_COMM_WORLD, MPI_STATUS_IGNORE) != MPI_SUCCESS) return MPI_ERR_COUNT; offset += length; } return MPI_SUCCESS; } /* mc_MPI_Recv */ #endif /* USE_MPI */ /* SECTION: parameters handling ============================================= */ /* Instrument input parameter type handling. */ /******************************************************************************* * mcparm_double: extract double value from 's' into 'vptr' *******************************************************************************/ static int mcparm_double(char *s, void *vptr) { char *p; double *v = (double *)vptr; if (!s) { *v = 0; return(1); } *v = strtod(s, &p); if(*s == '\0' || (p != NULL && *p != '\0') || errno == ERANGE) return 0; /* Failed */ else return 1; /* Success */ } /******************************************************************************* * mcparminfo_double: display parameter type double *******************************************************************************/ static char * mcparminfo_double(char *parmname) { return "double"; } /******************************************************************************* * mcparmerror_double: display error message when failed extract double *******************************************************************************/ static void mcparmerror_double(char *parm, char *val) { fprintf(stderr, "Error: Invalid value '%s' for floating point parameter %s (mcparmerror_double)\n", val, parm); } /******************************************************************************* * mcparmprinter_double: convert double to string *******************************************************************************/ static void mcparmprinter_double(char *f, void *vptr) { double *v = (double *)vptr; sprintf(f, "%g", *v); } /******************************************************************************* * mcparm_int: extract int value from 's' into 'vptr' *******************************************************************************/ static int mcparm_int(char *s, void *vptr) { char *p; int *v = (int *)vptr; long x; if (!s) { *v = 0; return(1); } *v = 0; x = strtol(s, &p, 10); if(x < INT_MIN || x > INT_MAX) return 0; /* Under/overflow */ *v = x; if(*s == '\0' || (p != NULL && *p != '\0') || errno == ERANGE) return 0; /* Failed */ else return 1; /* Success */ } /******************************************************************************* * mcparminfo_int: display parameter type int *******************************************************************************/ static char * mcparminfo_int(char *parmname) { return "int"; } /******************************************************************************* * mcparmerror_int: display error message when failed extract int *******************************************************************************/ static void mcparmerror_int(char *parm, char *val) { fprintf(stderr, "Error: Invalid value '%s' for integer parameter %s (mcparmerror_int)\n", val, parm); } /******************************************************************************* * mcparmprinter_int: convert int to string *******************************************************************************/ static void mcparmprinter_int(char *f, void *vptr) { int *v = (int *)vptr; sprintf(f, "%d", *v); } /******************************************************************************* * mcparm_string: extract char* value from 's' into 'vptr' (copy) *******************************************************************************/ static int mcparm_string(char *s, void *vptr) { char **v = (char **)vptr; if (!s) { *v = NULL; return(1); } *v = (char *)malloc(strlen(s) + 1); if(*v == NULL) { exit(-fprintf(stderr, "Error: Out of memory %li (mcparm_string).\n", (long)strlen(s) + 1)); } strcpy(*v, s); return 1; /* Success */ } /******************************************************************************* * mcparminfo_string: display parameter type string *******************************************************************************/ static char * mcparminfo_string(char *parmname) { return "string"; } /******************************************************************************* * mcparmerror_string: display error message when failed extract string *******************************************************************************/ static void mcparmerror_string(char *parm, char *val) { fprintf(stderr, "Error: Invalid value '%s' for string parameter %s (mcparmerror_string)\n", val, parm); } /******************************************************************************* * mcparmprinter_string: convert string to string (including esc chars) *******************************************************************************/ static void mcparmprinter_string(char *f, void *vptr) { char **v = (char **)vptr; char *p; if (!*v) { *f='\0'; return; } strcpy(f, ""); for(p = *v; *p != '\0'; p++) { switch(*p) { case '\n': strcat(f, "\\n"); break; case '\r': strcat(f, "\\r"); break; case '"': strcat(f, "\\\""); break; case '\\': strcat(f, "\\\\"); break; default: strncat(f, p, 1); } } /* strcat(f, "\""); */ } /* mcparmprinter_string */ /* now we may define the parameter structure, using previous functions */ static struct { int (*getparm)(char *, void *); char * (*parminfo)(char *); void (*error)(char *, char *); void (*printer)(char *, void *); } mcinputtypes[] = { { mcparm_int, mcparminfo_int, mcparmerror_int, mcparmprinter_int }, { mcparm_string, mcparminfo_string, mcparmerror_string, mcparmprinter_string }, { mcparm_string, mcparminfo_string, mcparmerror_string, mcparmprinter_string }, { mcparm_double, mcparminfo_double, mcparmerror_double, mcparmprinter_double }, { mcparm_double, mcparminfo_double, mcparmerror_double, mcparmprinter_double } }; /******************************************************************************* * mcestimate_error: compute sigma from N,p,p2 in Gaussian large numbers approx *******************************************************************************/ double mcestimate_error(double N, double p1, double p2) { double pmean, n1; if(N <= 1) return p1; pmean = p1 / N; n1 = N - 1; /* Note: underflow may cause p2 to become zero; the fabs() below guards against this. */ return sqrt((N/n1)*fabs(p2 - pmean*pmean)); } double (*mcestimate_error_p) (double V2, double psum, double p2sum)=mcestimate_error; /* ========================================================================== */ /* MCCODE_R_IO_C */ /* ========================================================================== */ #ifndef MCCODE_R_IO_C #define MCCODE_R_IO_C "$Revision$" /* SECTION: file i/o handling ================================================ */ #ifndef HAVE_STRCASESTR // from msysgit: https://code.google.com/p/msysgit/source/browse/compat/strcasestr.c char *strcasestr(const char *haystack, const char *needle) { int nlen = strlen(needle); int hlen = strlen(haystack) - nlen + 1; int i; for (i = 0; i < hlen; i++) { int j; for (j = 0; j < nlen; j++) { unsigned char c1 = haystack[i+j]; unsigned char c2 = needle[j]; if (toupper(c1) != toupper(c2)) goto next; } return (char *) haystack + i; next: ; } return NULL; } #endif #ifndef HAVE_STRCASECMP int strcasecmp( const char *s1, const char *s2 ) { int c1, c2; do { c1 = tolower( (unsigned char) *s1++ ); c2 = tolower( (unsigned char) *s2++ ); } while (c1 == c2 && c1 != 0); return c2 > c1 ? -1 : c1 > c2; } #endif #ifndef STRACPY /* this is a replacement to strncpy, but ensures that the copy ends with NULL */ /* http://stracpy.blogspot.fr/2011/04/stracpy-strncpy-replacement.html */ #define STRACPY char *stracpy(char *destination, const char *source, size_t amount) { if (!destination || !source || !amount) return(NULL); while(amount--) if((*destination++ = *source++) == '\0') break; *destination = '\0'; return destination; } #endif /******************************************************************************* * mcfull_file: allocates a full file name=dirname+file. Catenate extension if missing. *******************************************************************************/ char *mcfull_file(char *name, char *ext) { int dirlen=0; char *mem =NULL; dirlen = dirname ? strlen(dirname) : 0; mem = (char*)malloc(dirlen + strlen(name) + CHAR_BUF_LENGTH); if(!mem) { exit(-fprintf(stderr, "Error: Out of memory %li (mcfull_file)\n", (long)(dirlen + strlen(name) + 256))); } strcpy(mem, ""); /* prepend directory name to path if name does not contain a path */ if (dirlen > 0 && !strchr(name, MC_PATHSEP_C)) { strcat(mem, dirname); strcat(mem, MC_PATHSEP_S); } /* dirlen */ strcat(mem, name); if (!strchr(name, '.') && ext && strlen(ext)) { /* add extension if not in file name already */ strcat(mem, "."); strcat(mem, ext); } return(mem); } /* mcfull_file */ /******************************************************************************* * mcnew_file: opens a new file within dirname if non NULL * the file is opened in "a" (append, create if does not exist) * the extension 'ext' is added if the file name does not include one. * the last argument is set to 0 if file did not exist, else to 1. *******************************************************************************/ FILE *mcnew_file(char *name, char *ext, int *exists) { char *mem; FILE *file=NULL; if (!name || strlen(name) == 0 || mcdisable_output_files) return(NULL); mem = mcfull_file(name, ext); /* create dirname/name.ext */ /* check for existence */ file = fopen(mem, "r"); /* for reading -> fails if does not exist */ if (file) { fclose(file); *exists=1; } else *exists=0; /* open the file for writing/appending */ #ifdef USE_NEXUS if (mcformat && strcasestr(mcformat, "NeXus")) { /* NXhandle nxhandle is defined in the .h with USE_NEXUS */ NXaccess mode = (*exists ? NXACC_CREATE5 | NXACC_RDWR : NXACC_CREATE5); if (NXopen(mem, mode, &nxhandle) != NX_OK) file = NULL; else file = (FILE*)&nxhandle; /* to make it non NULL */ } else #endif file = fopen(mem, "a+"); if(!file) fprintf(stderr, "Warning: could not open output file '%s' for %s (mcnew_file)\n", mem, *exists ? "append" : "create"); free(mem); return file; } /* mcnew_file */ /******************************************************************************* * mcdetector_statistics: compute detector statistics, error bars, [x I I_err N] 1D * RETURN: updated detector structure * Used by: detector_import *******************************************************************************/ MCDETECTOR mcdetector_statistics( MCDETECTOR detector) { if (!detector.p1 || !detector.m || !detector.filename) return(detector); /* compute statistics and update MCDETECTOR structure ===================== */ double sum_z = 0, min_z = 0, max_z = 0; double fmon_x =0, smon_x = 0, fmon_y =0, smon_y=0, mean_z=0; double Nsum=0, P2sum=0; double sum_xz = 0, sum_yz = 0, sum_x = 0, sum_y = 0, sum_x2z = 0, sum_y2z = 0; int i,j; char hasnan=0, hasinf=0; char israw = ((char*)strcasestr(detector.format,"raw") != NULL); double *this_p1=NULL; /* new 1D McCode array [x I E N]. Freed after writing data */ /* if McCode/PGPLOT and rank==1 we create a new m*4 data block=[x I E N] */ if (detector.rank == 1 && strcasestr(detector.format,"McCode")) { this_p1 = (double *)calloc(detector.m*detector.n*detector.p*4, sizeof(double)); if (!this_p1) exit(-fprintf(stderr, "Error: Out of memory creating %li 1D " MCCODE_STRING " data set for file '%s' (detector_import)\n", detector.m*detector.n*detector.p*4*sizeof(double*), detector.filename)); } max_z = min_z = detector.p1[0]; /* compute sum and moments (not for lists) */ if (!strcasestr(detector.format,"list") && detector.m) for(j = 0; j < detector.n*detector.p; j++) { for(i = 0; i < detector.m; i++) { double x,y,z; double N, E; long index= !detector.istransposed ? i*detector.n*detector.p + j : i+j*detector.m; char hasnaninf=0; if (detector.m) x = detector.xmin + (i + 0.5)/detector.m*(detector.xmax - detector.xmin); else x = 0; if (detector.n && detector.p) y = detector.ymin + (j + 0.5)/detector.n/detector.p*(detector.ymax - detector.ymin); else y = 0; z = detector.p1[index]; N = detector.p0 ? detector.p0[index] : 1; E = detector.p2 ? detector.p2[index] : 0; if (detector.p2 && !israw) detector.p2[index] = (*mcestimate_error_p)(detector.p0[index],detector.p1[index],detector.p2[index]); /* set sigma */ if (detector.rank == 1 && this_p1 && strcasestr(detector.format,"McCode")) { /* fill-in 1D McCode array [x I E N] */ this_p1[index*4] = x; this_p1[index*4+1] = z; this_p1[index*4+2] = detector.p2 ? detector.p2[index] : 0; this_p1[index*4+3] = N; } if (isnan(z) || isnan(E) || isnan(N)) hasnaninf=hasnan=1; if (isinf(z) || isinf(E) || isinf(N)) hasnaninf=hasinf=1; /* compute stats integrals */ if (!hasnaninf) { sum_xz += x*z; sum_yz += y*z; sum_x += x; sum_y += y; sum_z += z; sum_x2z += x*x*z; sum_y2z += y*y*z; if (z > max_z) max_z = z; if (z < min_z) min_z = z; Nsum += N; P2sum += E; } } } /* for j */ /* compute 1st and 2nd moments. For lists, sum_z=0 so this is skipped. */ if (sum_z && detector.n*detector.m*detector.p) { fmon_x = sum_xz/sum_z; fmon_y = sum_yz/sum_z; smon_x = sum_x2z/sum_z-fmon_x*fmon_x; smon_x = smon_x > 0 ? sqrt(smon_x) : 0; smon_y = sum_y2z/sum_z-fmon_y*fmon_y; smon_y = smon_y > 0 ? sqrt(smon_y) : 0; mean_z = sum_z/detector.n/detector.m/detector.p; } /* store statistics into detector */ detector.intensity = sum_z; detector.error = Nsum ? (*mcestimate_error_p)(Nsum, sum_z, P2sum) : 0; detector.events = Nsum; detector.min = min_z; detector.max = max_z; detector.mean = mean_z; detector.centerX = fmon_x; detector.halfwidthX= smon_x; detector.centerY = fmon_y; detector.halfwidthY= smon_y; /* if McCode/PGPLOT and rank==1 replace p1 with new m*4 1D McCode and clear others */ if (detector.rank == 1 && this_p1 && strcasestr(detector.format,"McCode")) { detector.p1 = this_p1; detector.n = detector.m; detector.m = 4; detector.p0 = detector.p2 = NULL; detector.istransposed = 1; } if (detector.n*detector.m*detector.p > 1) snprintf(detector.signal, CHAR_BUF_LENGTH, "Min=%g; Max=%g; Mean=%g;", detector.min, detector.max, detector.mean); else strcpy(detector.signal, "None"); snprintf(detector.values, CHAR_BUF_LENGTH, "%g %g %g", detector.intensity, detector.error, detector.events); switch (detector.rank) { case 1: snprintf(detector.statistics, CHAR_BUF_LENGTH, "X0=%g; dX=%g;", detector.centerX, detector.halfwidthX); break; case 2: case 3: snprintf(detector.statistics, CHAR_BUF_LENGTH, "X0=%g; dX=%g; Y0=%g; dY=%g;", detector.centerX, detector.halfwidthX, detector.centerY, detector.halfwidthY); break; default: strcpy(detector.statistics, "None"); } if (hasnan) printf("WARNING: Nan detected in component/file %s %s\n", detector.component, strlen(detector.filename) ? detector.filename : ""); if (hasinf) printf("WARNING: Inf detected in component/file %s %s\n", detector.component, strlen(detector.filename) ? detector.filename : ""); return(detector); } /* mcdetector_statistics */ /******************************************************************************* * detector_import: build detector structure, merge non-lists from MPI * compute basic stat, write "Detector:" line * RETURN: detector structure. Invalid data if detector.p1 == NULL * Invalid detector sets m=0 and filename="" * Simulation data sets m=0 and filename=siminfo_name * This function is equivalent to the old 'mcdetector_out', returning a structure *******************************************************************************/ MCDETECTOR detector_import( char *format, char *component, char *title, long m, long n, long p, char *xlabel, char *ylabel, char *zlabel, char *xvar, char *yvar, char *zvar, double x1, double x2, double y1, double y2, double z1, double z2, char *filename, double *p0, double *p1, double *p2, Coords position) { time_t t; /* for detector.date */ long date_l; /* date as a long number */ char istransposed=0; char c[CHAR_BUF_LENGTH]; /* temp var for signal label */ MCDETECTOR detector; /* build MCDETECTOR structure ============================================= */ /* make sure we do not have NULL for char fields */ /* these also apply to simfile */ strncpy (detector.filename, filename ? filename : "", CHAR_BUF_LENGTH); strncpy (detector.format, format ? format : "McCode" , CHAR_BUF_LENGTH); /* add extension if missing */ if (strlen(detector.filename) && !strchr(detector.filename, '.')) { /* add extension if not in file name already */ strcat(detector.filename, ".dat"); } strncpy (detector.component, component ? component : MCCODE_STRING " component", CHAR_BUF_LENGTH); snprintf(detector.instrument, CHAR_BUF_LENGTH, "%s (%s)", instrument_name, instrument_source); snprintf(detector.user, CHAR_BUF_LENGTH, "%s on %s", getenv("USER") ? getenv("USER") : MCCODE_NAME, getenv("HOST") ? getenv("HOST") : "localhost"); time(&t); /* get current write time */ date_l = (long)t; /* same but as a long */ snprintf(detector.date, CHAR_BUF_LENGTH, "%s", ctime(&t)); if (strlen(detector.date)) detector.date[strlen(detector.date)-1] = '\0'; /* remove last \n in date */ detector.date_l = date_l; if (!mcget_run_num() || mcget_run_num() >= mcget_ncount()) snprintf(detector.ncount, CHAR_BUF_LENGTH, "%llu", mcget_ncount() #ifdef USE_MPI *mpi_node_count #endif ); else snprintf(detector.ncount, CHAR_BUF_LENGTH, "%g/%g", (double)mcget_run_num(), (double)mcget_ncount()); detector.p0 = p0; detector.p1 = p1; detector.p2 = p2; /* handle transposition (not for NeXus) */ if (!strcasestr(detector.format, "NeXus")) { if (m<0 || n<0 || p<0) istransposed = !istransposed; if (strcasestr(detector.format, "transpose")) istransposed = !istransposed; if (istransposed) { /* do the swap once for all */ long i=m; m=n; n=i; } } m=abs(m); n=abs(n); p=abs(p); /* make sure dimensions are positive */ detector.istransposed = istransposed; /* determine detector rank (dimensionality) */ if (!m || !n || !p || !p1) detector.rank = 4; /* invalid: exit with m=0 filename="" */ else if (m*n*p == 1) detector.rank = 0; /* 0D */ else if (n == 1 || m == 1) detector.rank = 1; /* 1D */ else if (p == 1) detector.rank = 2; /* 2D */ else detector.rank = 3; /* 3D */ /* from rank, set type */ switch (detector.rank) { case 0: strcpy(detector.type, "array_0d"); m=n=p=1; break; case 1: snprintf(detector.type, CHAR_BUF_LENGTH, "array_1d(%ld)", m*n*p); m *= n*p; n=p=1; break; case 2: snprintf(detector.type, CHAR_BUF_LENGTH, "array_2d(%ld, %ld)", m, n*p); n *= p; p=1; break; case 3: snprintf(detector.type, CHAR_BUF_LENGTH, "array_3d(%ld, %ld, %ld)", m, n, p); break; default: m=0; strcpy(detector.type, ""); strcpy(detector.filename, "");/* invalid */ } detector.m = m; detector.n = n; detector.p = p; /* these only apply to detector files ===================================== */ snprintf(detector.position, CHAR_BUF_LENGTH, "%g %g %g", position.x, position.y, position.z); /* may also store actual detector orientation in the future */ strncpy(detector.title, title && strlen(title) ? title : component, CHAR_BUF_LENGTH); strncpy(detector.xlabel, xlabel && strlen(xlabel) ? xlabel : "X", CHAR_BUF_LENGTH); /* axis labels */ strncpy(detector.ylabel, ylabel && strlen(ylabel) ? ylabel : "Y", CHAR_BUF_LENGTH); strncpy(detector.zlabel, zlabel && strlen(zlabel) ? zlabel : "Z", CHAR_BUF_LENGTH); strncpy(detector.xvar, xvar && strlen(xvar) ? xvar : "x", CHAR_BUF_LENGTH); /* axis variables */ strncpy(detector.yvar, yvar && strlen(yvar) ? yvar : detector.xvar, CHAR_BUF_LENGTH); strncpy(detector.zvar, zvar && strlen(zvar) ? zvar : detector.yvar, CHAR_BUF_LENGTH); /* set "variables" as e.g. "I I_err N" */ strcpy(c, "I "); if (strlen(detector.zvar)) strncpy(c, detector.zvar,32); else if (strlen(detector.yvar)) strncpy(c, detector.yvar,32); else if (strlen(detector.xvar)) strncpy(c, detector.xvar,32); if (detector.rank == 1) snprintf(detector.variables, CHAR_BUF_LENGTH, "%s %s %s_err N", detector.xvar, c, c); else snprintf(detector.variables, CHAR_BUF_LENGTH, "%s %s_err N", c, c); /* limits */ detector.xmin = x1; detector.xmax = x2; detector.ymin = y1; detector.ymax = y2; detector.zmin = z1; detector.zmax = z2; if (abs(detector.rank) == 1) snprintf(detector.limits, CHAR_BUF_LENGTH, "%g %g", x1, x2); else if (detector.rank == 2) snprintf(detector.limits, CHAR_BUF_LENGTH, "%g %g %g %g", x1, x2, y1, y2); else snprintf(detector.limits, CHAR_BUF_LENGTH, "%g %g %g %g %g %g", x1, x2, y1, y2, z1, z2); /* if MPI and nodes_nb > 1: reduce data sets when using MPI =============== */ #ifdef USE_MPI if (!strcasestr(detector.format,"list") && mpi_node_count > 1 && m) { /* we save additive data: reduce everything into mpi_node_root */ if (p0) mc_MPI_Sum(p0, m*n*p); if (p1) mc_MPI_Sum(p1, m*n*p); if (p2) mc_MPI_Sum(p2, m*n*p); if (!p0) { /* additive signal must be then divided by the number of nodes */ int i; for (i=0; i CHAR_BUF_LENGTH) break; snprintf(ThisParam, CHAR_BUF_LENGTH, " %s(%s)", mcinputtable[i].name, (*mcinputtypes[mcinputtable[i].type].parminfo) (mcinputtable[i].name)); strcat(Parameters, ThisParam); if (strlen(Parameters) >= CHAR_BUF_LENGTH-64) break; } /* output data ============================================================ */ if (f != stdout) fprintf(f, "%sFile: %s%c%s\n", pre, dirname, MC_PATHSEP_C, siminfo_name); else fprintf(f, "%sCreator: %s\n", pre, MCCODE_STRING); fprintf(f, "%sSource: %s\n", pre, instrument_source); fprintf(f, "%sParameters: %s\n", pre, Parameters); fprintf(f, "%sTrace_enabled: %s\n", pre, traceenabled ? "yes" : "no"); fprintf(f, "%sDefault_main: %s\n", pre, defaultmain ? "yes" : "no"); fprintf(f, "%sEmbedded_runtime: %s\n", pre, #ifdef MC_EMBEDDED_RUNTIME "yes" #else "no" #endif ); fflush(f); } /* mcinfo_out */ /******************************************************************************* * mcruninfo_out: output simulation tags/info (both in SIM and data files) * Used in: siminfo_init (ascii case), mcdetector_out_xD_ascii *******************************************************************************/ static void mcruninfo_out(char *pre, FILE *f) { int i; char Parameters[CHAR_BUF_LENGTH]; if (!f || mcdisable_output_files) return; fprintf(f, "%sFormat: %s%s\n", pre, mcformat && strlen(mcformat) ? mcformat : MCCODE_NAME, mcformat && strcasestr(mcformat,"McCode") ? " with text headers" : ""); fprintf(f, "%sURL: %s\n", pre, "http://www.mccode.org"); fprintf(f, "%sCreator: %s\n", pre, MCCODE_STRING); fprintf(f, "%sInstrument: %s\n", pre, instrument_source); fprintf(f, "%sNcount: %llu\n", pre, mcget_ncount()); fprintf(f, "%sTrace: %s\n", pre, mcdotrace ? "yes" : "no"); fprintf(f, "%sGravitation: %s\n", pre, mcgravitation ? "yes" : "no"); snprintf(Parameters, CHAR_BUF_LENGTH, "%ld", mcseed); fprintf(f, "%sSeed: %s\n", pre, Parameters); fprintf(f, "%sDirectory: %s\n", pre, dirname ? dirname : "."); #ifdef USE_MPI if (mpi_node_count > 1) fprintf(f, "%sNodes: %i\n", pre, mpi_node_count); #endif /* output parameter string ================================================ */ for(i = 0; i < numipar; i++) { if (mcinputtable[i].par){ /* Parameters with a default value */ if(mcinputtable[i].val && strlen(mcinputtable[i].val)){ (*mcinputtypes[mcinputtable[i].type].printer)(Parameters, mcinputtable[i].par); fprintf(f, "%sParam: %s=%s\n", pre, mcinputtable[i].name, Parameters); /* ... and those without */ }else{ fprintf(f, "%sParam: %s=NULL\n", pre, mcinputtable[i].name); } } } fflush(f); } /* mcruninfo_out */ /******************************************************************************* * siminfo_out: wrapper to fprintf(siminfo_file) *******************************************************************************/ void siminfo_out(char *format, ...) { va_list ap; if(siminfo_file && !mcdisable_output_files) { va_start(ap, format); vfprintf(siminfo_file, format, ap); va_end(ap); } } /* siminfo_out */ /******************************************************************************* * mcdatainfo_out: output detector header * mcdatainfo_out(prefix, file_handle, detector) writes info to data file *******************************************************************************/ static void mcdatainfo_out(char *pre, FILE *f, MCDETECTOR detector) { if (!f || !detector.m || mcdisable_output_files) return; /* output data ============================================================ */ fprintf(f, "%sDate: %s (%li)\n", pre, detector.date, detector.date_l); fprintf(f, "%stype: %s\n", pre, detector.type); fprintf(f, "%sSource: %s\n", pre, detector.instrument); fprintf(f, "%scomponent: %s\n", pre, detector.component); fprintf(f, "%sposition: %s\n", pre, detector.position); fprintf(f, "%stitle: %s\n", pre, detector.title); fprintf(f, !mcget_run_num() || mcget_run_num() >= mcget_ncount() ? "%sNcount: %s\n" : "%sratio: %s\n", pre, detector.ncount); if (strlen(detector.filename)) { fprintf(f, "%sfilename: %s\n", pre, detector.filename); } fprintf(f, "%sstatistics: %s\n", pre, detector.statistics); fprintf(f, "%ssignal: %s\n", pre, detector.signal); fprintf(f, "%svalues: %s\n", pre, detector.values); if (detector.rank >= 1) { fprintf(f, "%sxvar: %s\n", pre, detector.xvar); fprintf(f, "%syvar: %s\n", pre, detector.yvar); fprintf(f, "%sxlabel: %s\n", pre, detector.xlabel); fprintf(f, "%sylabel: %s\n", pre, detector.ylabel); if (detector.rank > 1) { fprintf(f, "%szvar: %s\n", pre, detector.zvar); fprintf(f, "%szlabel: %s\n", pre, detector.zlabel); } } fprintf(f, abs(detector.rank)==1 ? "%sxlimits: %s\n" : "%sxylimits: %s\n", pre, detector.limits); fprintf(f, "%svariables: %s\n", pre, strcasestr(detector.format, "list") ? detector.ylabel : detector.variables); fflush(f); } /* mcdatainfo_out */ /* mcdetector_out_array_ascii: output a single array to a file * m: columns * n: rows * p: array * f: file handle (already opened) */ static void mcdetector_out_array_ascii(long m, long n, double *p, FILE *f, char istransposed) { if(f) { int i,j; for(j = 0; j < n; j++) { for(i = 0; i < m; i++) { fprintf(f, "%.10g ", p[!istransposed ? i*n + j : j*m+i]); } fprintf(f,"\n"); } } } /* mcdetector_out_array_ascii */ /******************************************************************************* * mcdetector_out_0D_ascii: called by mcdetector_out_0D for ascii output *******************************************************************************/ MCDETECTOR mcdetector_out_0D_ascii(MCDETECTOR detector) { int exists=0; FILE *outfile = NULL; /* Write data set information to simulation description file. */ MPI_MASTER( siminfo_out("\nbegin data\n"); // detector.component mcdatainfo_out(" ", siminfo_file, detector); siminfo_out("end data\n"); /* Don't write if filename is NULL: mcnew_file handles this (return NULL) */ outfile = mcnew_file(detector.component, "dat", &exists); if(outfile) { /* write data file header and entry in simulation description file */ mcruninfo_out( "# ", outfile); mcdatainfo_out("# ", outfile, detector); /* write I I_err N */ fprintf(outfile, "%g %g %g\n", detector.intensity, detector.error, detector.events); fclose(outfile); } ); /* MPI_MASTER */ return(detector); } /* mcdetector_out_0D_ascii */ /******************************************************************************* * mcdetector_out_1D_ascii: called by mcdetector_out_1D for ascii output *******************************************************************************/ MCDETECTOR mcdetector_out_1D_ascii(MCDETECTOR detector) { int exists=0; FILE *outfile = NULL; MPI_MASTER( /* Write data set information to simulation description file. */ siminfo_out("\nbegin data\n"); // detector.filename mcdatainfo_out(" ", siminfo_file, detector); siminfo_out("end data\n"); /* Loop over array elements, writing to file. */ /* Don't write if filename is NULL: mcnew_file handles this (return NULL) */ outfile = mcnew_file(detector.filename, "dat", &exists); if(outfile) { /* write data file header and entry in simulation description file */ mcruninfo_out( "# ", outfile); mcdatainfo_out("# ", outfile, detector); /* output the 1D array columns */ mcdetector_out_array_ascii(detector.m, detector.n, detector.p1, outfile, detector.istransposed); fclose(outfile); } ); /* MPI_MASTER */ return(detector); } /* mcdetector_out_1D_ascii */ /******************************************************************************* * mcdetector_out_2D_ascii: called by mcdetector_out_2D for ascii output *******************************************************************************/ MCDETECTOR mcdetector_out_2D_ascii(MCDETECTOR detector) { int exists=0; FILE *outfile = NULL; MPI_MASTER( /* Loop over array elements, writing to file. */ /* Don't write if filename is NULL: mcnew_file handles this (return NULL) */ outfile = mcnew_file(detector.filename, "dat", &exists); if(outfile) { /* write header only if file has just been created (not appending) */ if (!exists) { /* Write data set information to simulation description file. */ siminfo_out("\nbegin data\n"); // detector.filename mcdatainfo_out(" ", siminfo_file, detector); siminfo_out("end data\n"); mcruninfo_out( "# ", outfile); mcdatainfo_out("# ", outfile, detector); fprintf(outfile, "# Data [%s/%s] %s:\n", detector.component, detector.filename, detector.zvar); } mcdetector_out_array_ascii(detector.m, detector.n*detector.p, detector.p1, outfile, detector.istransposed); if (detector.p2) { fprintf(outfile, "# Errors [%s/%s] %s_err:\n", detector.component, detector.filename, detector.zvar); mcdetector_out_array_ascii(detector.m, detector.n*detector.p, detector.p2, outfile, detector.istransposed); } if (detector.p0) { fprintf(outfile, "# Events [%s/%s] N:\n", detector.component, detector.filename); mcdetector_out_array_ascii(detector.m, detector.n*detector.p, detector.p0, outfile, detector.istransposed); } fclose(outfile); if (!exists) { if (strcasestr(detector.format, "list")) printf("Events: \"%s\"\n", strlen(detector.filename) ? detector.filename : detector.component); } } /* if outfile */ ); /* MPI_MASTER */ #ifdef USE_MPI if (strcasestr(detector.format, "list") && mpi_node_count > 1) { int node_i=0; /* loop along MPI nodes to write sequentially */ for(node_i=0; node_i strlen(original)) n = strlen(original); else original += strlen(original)-n; strncpy(valid, original, n); for (i=0; i < n; i++) { if ( (valid[i] > 122) || (valid[i] < 32) || (strchr("!\"#$%&'()*+,-.:;<=>?@[\\]^`/ \n\r\t", valid[i]) != NULL) ) { if (i) valid[i] = '_'; else valid[i] = 'm'; } } valid[i] = '\0'; return(valid); } /* strcpy_valid */ /* end ascii output section ================================================= */ #ifdef USE_NEXUS /* ========================================================================== */ /* NeXus output */ /* ========================================================================== */ #define nxprintf(...) nxstr('d', __VA_ARGS__) #define nxprintattr(...) nxstr('a', __VA_ARGS__) /******************************************************************************* * nxstr: output a tag=value data set (char) in NeXus/current group * when 'format' is larger that 1024 chars it is used as value for the 'tag' * else the value is assembled with format and following arguments. * type='d' -> data set * 'a' -> attribute for current data set *******************************************************************************/ static int nxstr(char type, NXhandle *f, char *tag, char *format, ...) { va_list ap; char value[CHAR_BUF_LENGTH]; int i; int ret=NX_OK; if (!tag || !format || !strlen(tag) || !strlen(format)) return(NX_OK); /* assemble the value string */ if (strlen(format) < CHAR_BUF_LENGTH) { va_start(ap, format); ret = vsnprintf(value, CHAR_BUF_LENGTH, format, ap); va_end(ap); i = strlen(value); } else { i = strlen(format); } if (type == 'd') { /* open/put/close data set */ if (NXmakedata (f, tag, NX_CHAR, 1, &i) != NX_OK) return(NX_ERROR); NXopendata (f, tag); if (strlen(format) < CHAR_BUF_LENGTH) ret = NXputdata (f, value); else ret = NXputdata (f, format); NXclosedata(f); } else { if (strlen(format) < CHAR_BUF_LENGTH) ret = NXputattr (f, tag, value, strlen(value), NX_CHAR); else ret = NXputattr (f, tag, format, strlen(format), NX_CHAR); } return(ret); } /* nxstr */ /******************************************************************************* * mcinfo_readfile: read a full file into a string buffer which is allocated * Think to free the buffer after use. * Used in: mcinfo_out_nexus (nexus) *******************************************************************************/ char *mcinfo_readfile(char *filename) { FILE *f = fopen(filename, "rb"); if (!f) return(NULL); fseek(f, 0, SEEK_END); long fsize = ftell(f); rewind(f); char *string = malloc(fsize + 1); if (string) { int n = fread(string, fsize, 1, f); fclose(f); string[fsize] = 0; } return(string); } /******************************************************************************* * mcinfo_out: output instrument/simulation groups in NeXus file * Used in: siminfo_init (nexus) *******************************************************************************/ static void mcinfo_out_nexus(NXhandle f) { FILE *fid; /* for intrument source code/C/IDF */ char *buffer=NULL; time_t t =time(NULL); /* for date */ char entry0[CHAR_BUF_LENGTH]; int count=0; char name[CHAR_BUF_LENGTH]; char class[CHAR_BUF_LENGTH]; if (!f || mcdisable_output_files) return; /* write NeXus NXroot attributes */ /* automatically added: file_name, HDF5_Version, file_time, NeXus_version */ nxprintattr(f, "creator", "%s generated with " MCCODE_STRING, instrument_name); /* count the number of existing NXentry and create the next one */ NXgetgroupinfo(f, &count, name, class); sprintf(entry0, "entry%i", count+1); /* create the main NXentry (mandatory in NeXus) */ if (NXmakegroup(f, entry0, "NXentry") == NX_OK) if (NXopengroup(f, entry0, "NXentry") == NX_OK) { nxprintf(nxhandle, "program_name", MCCODE_STRING); nxprintf(f, "start_time", ctime(&t)); nxprintf(f, "title", "%s%s%s simulation generated by instrument %s", dirname && strlen(dirname) ? dirname : ".", MC_PATHSEP_S, siminfo_name, instrument_name); nxprintattr(f, "program_name", MCCODE_STRING); nxprintattr(f, "instrument", instrument_name); nxprintattr(f, "simulation", "%s%s%s", dirname && strlen(dirname) ? dirname : ".", MC_PATHSEP_S, siminfo_name); /* write NeXus instrument group */ if (NXmakegroup(f, "instrument", "NXinstrument") == NX_OK) if (NXopengroup(f, "instrument", "NXinstrument") == NX_OK) { int i; char *string=NULL; /* write NeXus parameters(types) data =================================== */ string = (char*)malloc(CHAR_BUF_LENGTH); if (string) { strcpy(string, ""); for(i = 0; i < numipar; i++) { char ThisParam[CHAR_BUF_LENGTH]; snprintf(ThisParam, CHAR_BUF_LENGTH, " %s(%s)", mcinputtable[i].name, (*mcinputtypes[mcinputtable[i].type].parminfo) (mcinputtable[i].name)); if (strlen(string) + strlen(ThisParam) < CHAR_BUF_LENGTH) strcat(string, ThisParam); } nxprintattr(f, "Parameters", string); free(string); } nxprintattr(f, "name", instrument_name); nxprintf (f, "name", instrument_name); nxprintattr(f, "Source", instrument_source); nxprintattr(f, "Trace_enabled", traceenabled ? "yes" : "no"); nxprintattr(f, "Default_main", defaultmain ? "yes" : "no"); nxprintattr(f, "Embedded_runtime", #ifdef MC_EMBEDDED_RUNTIME "yes" #else "no" #endif ); /* add instrument source code when available */ buffer = mcinfo_readfile(instrument_source); if (buffer && strlen(buffer)) { long length=strlen(buffer); nxprintf (f, "description", buffer); NXopendata(f,"description"); nxprintattr(f, "file_name", instrument_source); nxprintattr(f, "file_size", "%li", length); nxprintattr(f, "MCCODE_STRING", MCCODE_STRING); NXclosedata(f); nxprintf (f,"instrument_source", "%s " MCCODE_NAME " " MCCODE_PARTICLE " Monte Carlo simulation", instrument_name); free(buffer); } else nxprintf (f, "description", "File %s not found (instrument description %s is missing)", instrument_source, instrument_name); /* add Mantid/IDF.xml when available */ char *IDFfile=NULL; IDFfile = (char*)malloc(CHAR_BUF_LENGTH); sprintf(IDFfile,"%s%s",instrument_source,".xml"); buffer = mcinfo_readfile(IDFfile); if (buffer && strlen(buffer)) { NXmakegroup (nxhandle, "instrument_xml", "NXnote"); NXopengroup (nxhandle, "instrument_xml", "NXnote"); nxprintf(f, "data", buffer); nxprintf(f, "description", "IDF.xml file found with instrument %s", instrument_source); nxprintf(f, "type", "text/xml"); NXclosegroup(f); /* instrument_xml */ free(buffer); } free(IDFfile); NXclosegroup(f); /* instrument */ } /* NXinstrument */ /* write NeXus simulation group */ if (NXmakegroup(f, "simulation", "NXnote") == NX_OK) if (NXopengroup(f, "simulation", "NXnote") == NX_OK) { nxprintattr(f, "name", "%s%s%s", dirname && strlen(dirname) ? dirname : ".", MC_PATHSEP_S, siminfo_name); nxprintf (f, "name", "%s", siminfo_name); nxprintattr(f, "Format", mcformat && strlen(mcformat) ? mcformat : MCCODE_NAME); nxprintattr(f, "URL", "http://www.mccode.org"); nxprintattr(f, "program", MCCODE_STRING); nxprintattr(f, "Instrument",instrument_source); nxprintattr(f, "Trace", mcdotrace ? "yes" : "no"); nxprintattr(f, "Gravitation",mcgravitation ? "yes" : "no"); nxprintattr(f, "Seed", "%li", mcseed); nxprintattr(f, "Directory", dirname); #ifdef USE_MPI if (mpi_node_count > 1) nxprintf(f, "Nodes", "%i", mpi_node_count); #endif /* output parameter string ================================================ */ if (NXmakegroup(f, "Param", "NXparameters") == NX_OK) if (NXopengroup(f, "Param", "NXparameters") == NX_OK) { int i; char string[CHAR_BUF_LENGTH]; for(i = 0; i < numipar; i++) { if (mcget_run_num() || (mcinputtable[i].val && strlen(mcinputtable[i].val))) { if (mcinputtable[i].par == NULL) strncpy(string, (mcinputtable[i].val ? mcinputtable[i].val : ""), CHAR_BUF_LENGTH); else (*mcinputtypes[mcinputtable[i].type].printer)(string, mcinputtable[i].par); nxprintf(f, mcinputtable[i].name, "%s", string); nxprintattr(f, mcinputtable[i].name, string); } } NXclosegroup(f); /* Param */ } /* NXparameters */ NXclosegroup(f); /* simulation */ } /* NXsimulation */ /* create a group to hold all monitors */ NXmakegroup(f, "data", "NXdetector"); /* leave the NXentry opened (closed at exit) */ } /* NXentry */ } /* mcinfo_out_nexus */ /******************************************************************************* * mcdatainfo_out_nexus: output detector header * mcdatainfo_out_nexus(detector) create group and write info to NeXus data file * open data:NXdetector then filename:NXdata and write headers/attributes * requires: NXentry to be opened *******************************************************************************/ static void mcdatainfo_out_nexus(NXhandle f, MCDETECTOR detector) { char data_name[32]; if (!f || !detector.m || mcdisable_output_files) return; strcpy_valid(data_name, detector.filename && strlen(detector.filename) ? detector.filename : detector.component); /* the NXdetector group has been created in mcinfo_out_nexus (siminfo_init) */ if (NXopengroup(f, "data", "NXdetector") == NX_OK) { /* create and open the data group */ /* this may fail when appending to list -> ignore/skip */ NXMDisableErrorReporting(); /* unactivate NeXus error messages, as creation may fail */ if (NXmakegroup(f, data_name, "NXdata") == NX_OK) if (NXopengroup(f, data_name, "NXdata") == NX_OK) { /* output metadata (as attributes) ======================================== */ nxprintattr(f, "Date", detector.date); nxprintattr(f, "type", detector.type); nxprintattr(f, "Source", detector.instrument); nxprintattr(f, "component", detector.component); nxprintattr(f, "position", detector.position); nxprintattr(f, "title", detector.title); nxprintattr(f, !mcget_run_num() || mcget_run_num() >= mcget_ncount() ? "Ncount" : "ratio", detector.ncount); if (strlen(detector.filename)) { nxprintattr(f, "filename", detector.filename); } nxprintattr(f, "statistics", detector.statistics); nxprintattr(f, "signal", detector.signal); nxprintattr(f, "values", detector.values); if (detector.rank >= 1) { nxprintattr(f, "xvar", detector.xvar); nxprintattr(f, "yvar", detector.yvar); nxprintattr(f, "xlabel", detector.xlabel); nxprintattr(f, "ylabel", detector.ylabel); if (detector.rank > 1) { nxprintattr(f, "zvar", detector.zvar); nxprintattr(f, "zlabel", detector.zlabel); } } nxprintattr(f, abs(detector.rank)==1 ? "xlimits" : "xylimits", detector.limits); nxprintattr(f, "variables", strcasestr(detector.format, "list") ? detector.ylabel : detector.variables); nxprintf(f, "distance", detector.position); nxprintf(f, "acquisition_mode", strcasestr(detector.format, "list") ? "event" : "summed"); NXclosegroup(f); } /* NXdata (filename) */ NXMEnableErrorReporting(); /* re-enable NeXus error messages */ NXclosegroup(f); } /* NXdetector (data) */ } /* mcdatainfo_out_nexus */ /******************************************************************************* * mcdetector_out_axis_nexus: write detector axis into current NXdata * requires: NXdata to be opened *******************************************************************************/ int mcdetector_out_axis_nexus(NXhandle f, char *label, char *var, int rank, long length, double min, double max) { if (!f || length <= 1 || mcdisable_output_files || max == min) return(NX_OK); else { double axis[length]; char valid[32]; int dim=(int)length; int i; int nprimary=1; /* create an axis from [min:max] */ for(i = 0; i < length; i++) axis[i] = min+(max-min)*(i+0.5)/length; /* create the data set */ strcpy_valid(valid, label); NXcompmakedata(f, valid, NX_FLOAT64, 1, &dim, NX_COMP_LZW, &dim); /* open it */ if (NXopendata(f, valid) != NX_OK) { fprintf(stderr, "Warning: could not open axis rank %i '%s' (NeXus)\n", rank, valid); return(NX_ERROR); } /* put the axis and its attributes */ NXputdata (f, axis); nxprintattr(f, "long_name", label); nxprintattr(f, "short_name", var); NXputattr (f, "axis", &rank, 1, NX_INT32); nxprintattr(f, "units", var); NXputattr (f, "primary", &nprimary, 1, NX_INT32); NXclosedata(f); return(NX_OK); } } /* mcdetector_out_axis_nexus */ /******************************************************************************* * mcdetector_out_array_nexus: write detector array into current NXdata (1D,2D) * requires: NXdata to be opened *******************************************************************************/ int mcdetector_out_array_nexus(NXhandle f, char *part, double *data, MCDETECTOR detector) { int dims[3]={detector.m,detector.n,detector.p}; /* number of elements to write */ int signal=1; int exists=0; int current_dims[3]={0,0,0}; int ret=NX_OK; if (!f || !data || !detector.m || mcdisable_output_files) return(NX_OK); /* when this is a list, we set 1st dimension to NX_UNLIMITED for creation */ if (strcasestr(detector.format, "list")) dims[0] = NX_UNLIMITED; /* create the data set in NXdata group */ NXMDisableErrorReporting(); /* unactivate NeXus error messages, as creation may fail */ /* NXcompmakedata fails with NX_UNLIMITED */ if (strcasestr(detector.format, "list")) ret = NXmakedata( f, part, NX_FLOAT64, detector.rank, dims); else ret = NXcompmakedata(f, part, NX_FLOAT64, detector.rank, dims, NX_COMP_LZW, dims); if (ret != NX_OK) { /* failed: data set already exists */ int datatype=0; int rank=0; exists=1; /* inquire current size of data set (nb of events stored) */ NXopendata(f, part); NXgetinfo(f, &rank, current_dims, &datatype); NXclosedata(f); } NXMEnableErrorReporting(); /* re-enable NeXus error messages */ dims[0] = detector.m; /* restore actual dimension from data writing */ /* open the data set */ if (NXopendata(f, part) == NX_ERROR) { fprintf(stderr, "Warning: could not open DataSet %s '%s' (NeXus)\n", part, detector.title); return(NX_ERROR); } if (strcasestr(detector.format, "list")) { current_dims[1] = current_dims[2] = 0; /* set starting location for writing slab */ NXputslab(f, data, current_dims, dims); if (!exists) printf("Events: \"%s\"\n", strlen(detector.filename) ? detector.filename : detector.component); } else { NXputdata (f, data); } if (strstr(part,"data") || strstr(part, "events")) { NXputattr(f, "signal", &signal, 1, NX_INT32); nxprintattr(f, "short_name", detector.filename && strlen(detector.filename) ? detector.filename : detector.component); } nxprintattr(f, "long_name", "%s '%s'", part, detector.title); NXclosedata(f); return(NX_OK); } /* mcdetector_out_array_nexus */ /******************************************************************************* * mcdetector_out_data_nexus: write detector axes+data into current NXdata * The data:NXdetector is opened, then filename:NXdata * requires: NXentry to be opened *******************************************************************************/ int mcdetector_out_data_nexus(NXhandle f, MCDETECTOR detector) { char data_name[32]; if (!f || !detector.m || mcdisable_output_files) return(NX_OK); strcpy_valid(data_name, detector.filename && strlen(detector.filename) ? detector.filename : detector.component); /* the NXdetector group has been created in mcinfo_out_nexus (siminfo_init) */ if (NXopengroup(f, "data", "NXdetector") == NX_OK) { /* the NXdata group has been created in mcdatainfo_out_nexus */ if (NXopengroup(f, data_name, "NXdata") == NX_OK) { /* write axes, for histogram data sets, not for lists */ if (!strcasestr(detector.format, "list")) { mcdetector_out_axis_nexus(f, detector.xlabel, detector.xvar, 1, detector.m, detector.xmin, detector.xmax); mcdetector_out_axis_nexus(f, detector.ylabel, detector.yvar, 2, detector.n, detector.ymin, detector.ymax); mcdetector_out_axis_nexus(f, detector.zlabel, detector.zvar, 3, detector.p, detector.zmin, detector.zmax); } /* !list */ /* write the actual data (appended if already exists) */ if (!strcasestr(detector.format, "list")) { mcdetector_out_array_nexus(f, "data", detector.p1, detector); mcdetector_out_array_nexus(f, "errors", detector.p2, detector); mcdetector_out_array_nexus(f, "ncount", detector.p0, detector); } else mcdetector_out_array_nexus( f, "events", detector.p1, detector); NXclosegroup(f); } /* NXdata */ NXclosegroup(f); } /* NXdetector */ return(NX_OK); } /* mcdetector_out_array_nexus */ #ifdef USE_MPI /******************************************************************************* * mcdetector_out_list_slaves: slaves send their list data to master which writes * requires: NXentry to be opened * WARNING: this method has a flaw: it requires all nodes to flush the lists * the same number of times. In case one node is just below the buffer size * when finishing (e.g. monitor_nd), it may not trigger save but others may. * Then the number of recv/send is not constant along nodes, and simulation stalls. *******************************************************************************/ MCDETECTOR mcdetector_out_list_slaves(MCDETECTOR detector) { int node_i=0; MPI_MASTER( printf("\n** MPI master gathering slave node list data ** \n"); ); if (mpi_node_rank != mpi_node_root) { /* MPI slave: slaves send their data to master: 2 MPI_Send calls */ /* m, n, p must be sent first, since all slaves do not have the same number of events */ int mnp[3]={detector.m,detector.n,detector.p}; if (mc_MPI_Send(mnp, 3, MPI_INT, mpi_node_root)!= MPI_SUCCESS) fprintf(stderr, "Warning: proc %i to master: MPI_Send mnp list error (mcdetector_out_list_slaves)\n", mpi_node_rank); if (!detector.p1 || mc_MPI_Send(detector.p1, mnp[0]*mnp[1]*mnp[2], MPI_DOUBLE, mpi_node_root) != MPI_SUCCESS) fprintf(stderr, "Warning: proc %i to master: MPI_Send p1 list error: mnp=%i (mcdetector_out_list_slaves)\n", mpi_node_rank, abs(mnp[0]*mnp[1]*mnp[2])); /* slaves are done: sent mnp and p1 */ return (detector); } /* end slaves */ /* MPI master: receive data from slaves sequentially: 2 MPI_Recv calls */ if (mpi_node_rank == mpi_node_root) { for(node_i=0; node_i 1) { mcdetector_out_list_slaves(detector); } #endif /* USE_MPI */ return(detector); } /* mcdetector_out_2D_nexus */ #endif /* USE_NEXUS*/ /* ========================================================================== */ /* Main input functions */ /* DETECTOR_OUT_xD function calls -> ascii or NeXus */ /* ========================================================================== */ /******************************************************************************* * siminfo_init: open SIM and write header *******************************************************************************/ FILE *siminfo_init(FILE *f) { int exists=0; int index; /* check format */ if (!mcformat || !strlen(mcformat) || !strcasecmp(mcformat, "MCSTAS") || !strcasecmp(mcformat, "MCXTRACE") || !strcasecmp(mcformat, "PGPLOT") || !strcasecmp(mcformat, "GNUPLOT") || !strcasecmp(mcformat, "MCCODE") || !strcasecmp(mcformat, "MATLAB")) { mcformat="McCode"; #ifdef USE_NEXUS } else if (strcasestr(mcformat, "NeXus")) { /* Do nothing */ #endif } else { fprintf(stderr, "Warning: You have requested the output format %s which is unsupported by this binary. Resetting to standard %s format.\n",mcformat ,"McCode"); mcformat="McCode"; } /* open the SIM file if not defined yet */ if (siminfo_file || mcdisable_output_files) return (siminfo_file); #ifdef USE_NEXUS /* only master writes NeXus header: calls NXopen(nxhandle) */ if (mcformat && strcasestr(mcformat, "NeXus")) { MPI_MASTER( siminfo_file = mcnew_file(siminfo_name, "h5", &exists); if(!siminfo_file) fprintf(stderr, "Warning: could not open simulation description file '%s'\n", siminfo_name); else mcinfo_out_nexus(nxhandle); ); return(siminfo_file); /* points to nxhandle */ } #endif /* write main description file (only MASTER) */ MPI_MASTER( siminfo_file = mcnew_file(siminfo_name, "sim", &exists); if(!siminfo_file) fprintf(stderr, "Warning: could not open simulation description file '%s'\n", siminfo_name); else { /* write SIM header */ time_t t=time(NULL); siminfo_out("%s simulation description file for %s.\n", MCCODE_NAME, instrument_name); siminfo_out("Date: %s", ctime(&t)); /* includes \n */ siminfo_out("Program: %s\n\n", MCCODE_STRING); siminfo_out("begin instrument: %s\n", instrument_name); mcinfo_out( " ", siminfo_file); siminfo_out("end instrument\n"); siminfo_out("\nbegin simulation: %s\n", dirname); mcruninfo_out(" ", siminfo_file); siminfo_out("end simulation\n"); } return (siminfo_file); ); /* MPI_MASTER */ } /* siminfo_init */ /******************************************************************************* * siminfo_close: close SIM *******************************************************************************/ void siminfo_close() { #ifdef USE_MPI if(mpi_node_rank == mpi_node_root) { #endif if(siminfo_file && !mcdisable_output_files) { #ifdef USE_NEXUS if (mcformat && strcasestr(mcformat, "NeXus")) { time_t t=time(NULL); nxprintf(nxhandle, "end_time", ctime(&t)); nxprintf(nxhandle, "duration", "%li", (long)t-mcstartdate); NXclosegroup(nxhandle); /* NXentry */ NXclose(&nxhandle); } else { #endif fclose(siminfo_file); #ifdef USE_NEXUS } #endif #ifdef USE_MPI } #endif siminfo_file = NULL; } } /* siminfo_close */ /******************************************************************************* * mcdetector_out_0D: wrapper for 0D (single value). * Output single detector/monitor data (p0, p1, p2). * Title is t, component name is c. *******************************************************************************/ MCDETECTOR mcdetector_out_0D(char *t, double p0, double p1, double p2, char *c, Coords posa) { /* import and perform basic detector analysis (and handle MPI reduce) */ MCDETECTOR detector = detector_import(mcformat, c, (t ? t : MCCODE_STRING " data"), 1, 1, 1, "I", "", "", "I", "", "", 0, 0, 0, 0, 0, 0, "", &p0, &p1, &p2, posa); /* write Detector: line */ #ifdef USE_NEXUS if (strcasestr(detector.format, "NeXus")) return(mcdetector_out_0D_nexus(detector)); else #endif return(mcdetector_out_0D_ascii(detector)); } /* mcdetector_out_0D */ /******************************************************************************* * mcdetector_out_1D: wrapper for 1D. * Output 1d detector data (p0, p1, p2) for n bins linearly * distributed across the range x1..x2 (x1 is lower limit of first * bin, x2 is upper limit of last bin). Title is t, axis labels are xl * and yl. File name is f, component name is c. * * t: title * xl: x-label * yl: y-label * xvar: measured variable length * x1: x axus min * x2: x axis max * n: 1d data vector lenght * p0: pntr to start of data block#0 * p1: pntr to start of data block#1 * p2: pntr to start of data block#2 * f: filename * * Not included in the macro, and here forwarded to detector_import: * c: ? * posa: ? *******************************************************************************/ MCDETECTOR mcdetector_out_1D(char *t, char *xl, char *yl, char *xvar, double x1, double x2, long n, double *p0, double *p1, double *p2, char *f, char *c, Coords posa) { /* import and perform basic detector analysis (and handle MPI_Reduce) */ MCDETECTOR detector = detector_import(mcformat, c, (t ? t : MCCODE_STRING " 1D data"), n, 1, 1, xl, yl, (n > 1 ? "Signal per bin" : " Signal"), xvar, "(I,I_err)", "I", x1, x2, 0, 0, 0, 0, f, p0, p1, p2, posa); /* write Detector: line */ if (!detector.p1 || !detector.m) return(detector); #ifdef USE_NEXUS if (strcasestr(detector.format, "NeXus")) return(mcdetector_out_1D_nexus(detector)); else #endif return(mcdetector_out_1D_ascii(detector)); } /* mcdetector_out_1D */ /******************************************************************************* * mcdetector_out_2D: wrapper for 2D. * Special case for list: master creates file first, then slaves append their * blocks without header- * * t: title * xl: x-label * yl: y-label * x1: x axus min * x2: x axis max * y1: y axis min * y2: y axis max * m: dim 1 (x) size * n: dim 2 (y) size * p0: pntr to start of data block#0 * p1: pntr to start of data block#1 * p2: pntr to start of data block#2 * f: filename * * Not included in the macro, and here forwarded to detector_import: * c: ? * posa: ? *******************************************************************************/ MCDETECTOR mcdetector_out_2D(char *t, char *xl, char *yl, double x1, double x2, double y1, double y2, long m, long n, double *p0, double *p1, double *p2, char *f, char *c, Coords posa) { char xvar[CHAR_BUF_LENGTH]; char yvar[CHAR_BUF_LENGTH]; /* create short axes labels */ if (xl && strlen(xl)) { strncpy(xvar, xl, CHAR_BUF_LENGTH); xvar[2]='\0'; } else strcpy(xvar, "x"); if (yl && strlen(yl)) { strncpy(yvar, yl, CHAR_BUF_LENGTH); yvar[2]='\0'; } else strcpy(yvar, "y"); MCDETECTOR detector; /* import and perform basic detector analysis (and handle MPI_Reduce) */ if (abs(m) == 1) {/* n>1 on Y, m==1 on X: 1D, no X axis*/ detector = detector_import(mcformat, c, (t ? t : MCCODE_STRING " 1D data"), n, 1, 1, yl, "", "Signal per bin", yvar, "(I,Ierr)", "I", y1, y2, x1, x2, 0, 0, f, p0, p1, p2, posa); /* write Detector: line */ } else if (abs(n)==1) {/* m>1 on X, n==1 on Y: 1D, no Y axis*/ detector = detector_import(mcformat, c, (t ? t : MCCODE_STRING " 1D data"), m, 1, 1, xl, "", "Signal per bin", xvar, "(I,Ierr)", "I", x1, x2, y1, y2, 0, 0, f, p0, p1, p2, posa); /* write Detector: line */ }else { detector = detector_import(mcformat, c, (t ? t : MCCODE_STRING " 2D data"), m, n, 1, xl, yl, "Signal per bin", xvar, yvar, "I", x1, x2, y1, y2, 0, 0, f, p0, p1, p2, posa); /* write Detector: line */ } if (!detector.p1 || !detector.m) return(detector); #ifdef USE_NEXUS if (strcasestr(detector.format, "NeXus")) return(mcdetector_out_2D_nexus(detector)); else #endif return(mcdetector_out_2D_ascii(detector)); } /* mcdetector_out_2D */ /******************************************************************************* * mcdetector_out_list: wrapper for list output (calls out_2D with mcformat+"list"). * m=number of events, n=size of each event *******************************************************************************/ MCDETECTOR mcdetector_out_list(char *t, char *xl, char *yl, long m, long n, double *p1, char *f, char *c, Coords posa) { char format_new[CHAR_BUF_LENGTH]; char *format_org; MCDETECTOR detector; format_org = mcformat; strcpy(format_new, mcformat); strcat(format_new, " list"); mcformat = format_new; detector = mcdetector_out_2D(t, xl, yl, 1,abs(m),1,abs(n), m,n, NULL, p1, NULL, f, c, posa); mcformat = format_org; return(detector); } /******************************************************************************* * mcuse_dir: set data/sim storage directory and create it, * or exit with error if exists ******************************************************************************/ static void mcuse_dir(char *dir) { if (!dir || !strlen(dir)) return; #ifdef MC_PORTABLE fprintf(stderr, "Error: " "Directory output cannot be used with portable simulation (mcuse_dir)\n"); exit(1); #else /* !MC_PORTABLE */ /* handle file://directory URL type */ if (strncmp(dir, "file://", strlen("file://"))) dirname = dir; else dirname = dir+strlen("file://"); #ifdef USE_MPI if(mpi_node_rank == mpi_node_root) { #endif if(mkdir(dirname, 0777)) { #ifndef DANSE fprintf(stderr, "Error: unable to create directory '%s' (mcuse_dir)\n", dir); fprintf(stderr, "(Maybe the directory already exists?)\n"); #endif #ifdef USE_MPI MPI_Abort(MPI_COMM_WORLD, -1); #endif exit(-1); } #ifdef USE_MPI } #endif /* remove trailing PATHSEP (if any) */ while (strlen(dirname) && dirname[strlen(dirname) - 1] == MC_PATHSEP_C) dirname[strlen(dirname) - 1]='\0'; #endif /* !MC_PORTABLE */ } /* mcuse_dir */ /******************************************************************************* * mcinfo: display instrument simulation info to stdout and exit *******************************************************************************/ static void mcinfo(void) { fprintf(stdout, "begin instrument: %s\n", instrument_name); mcinfo_out(" ", stdout); fprintf(stdout, "end instrument\n"); fprintf(stdout, "begin simulation: %s\n", dirname ? dirname : "."); mcruninfo_out(" ", stdout); fprintf(stdout, "end simulation\n"); exit(0); /* includes MPI_Finalize in MPI mode */ } /* mcinfo */ #endif /* ndef MCCODE_R_IO_C */ /* end of the I/O section =================================================== */ /******************************************************************************* * mcset_ncount: set total number of rays to generate *******************************************************************************/ void mcset_ncount(unsigned long long int count) { mcncount = count; } /* mcget_ncount: get total number of rays to generate */ #pragma acc routine seq unsigned long long int mcget_ncount(void) { return mcncount; } /* mcget_run_num: get curent number of rays */ /* Within the TRACE scope we are now using _particle->uid directly */ unsigned long long int mcget_run_num() // shuld be (_class_particle* _particle) somehow { /* This function only remains for the few cases outside TRACE where we need to know the number of simulated particles */ return mcrun_num; } /* mcsetn_arg: get ncount from a string argument */ static void mcsetn_arg(char *arg) { mcset_ncount((long long int) strtod(arg, NULL)); } /* mcsetseed: set the random generator seed from a string argument */ static void mcsetseed(char *arg) { mcseed = atol(arg); if(!mcseed) { // srandom(mcseed); //} else { fprintf(stderr, "Error: seed must not be zero (mcsetseed)\n"); exit(1); } } /* Following part is only embedded when not redundent with mccode-r.h ========= */ #ifndef MCCODE_H /* SECTION: MCDISPLAY support. =============================================== */ /******************************************************************************* * Just output MCDISPLAY keywords to be caught by an external plotter client. *******************************************************************************/ void mcdis_magnify(char *what){ // Do nothing here, better use interactive zoom from the tools } void mcdis_line(double x1, double y1, double z1, double x2, double y2, double z2){ printf("MCDISPLAY: multiline(2,%g,%g,%g,%g,%g,%g)\n", x1,y1,z1,x2,y2,z2); } void mcdis_dashed_line(double x1, double y1, double z1, double x2, double y2, double z2, int n){ int i; const double dx = (x2-x1)/(2*n+1); const double dy = (y2-y1)/(2*n+1); const double dz = (z2-z1)/(2*n+1); for(i = 0; i < n+1; i++) mcdis_line(x1 + 2*i*dx, y1 + 2*i*dy, z1 + 2*i*dz, x1 + (2*i+1)*dx, y1 + (2*i+1)*dy, z1 + (2*i+1)*dz); } void mcdis_multiline(int count, ...){ va_list ap; double x,y,z; printf("MCDISPLAY: multiline(%d", count); va_start(ap, count); while(count--) { x = va_arg(ap, double); y = va_arg(ap, double); z = va_arg(ap, double); printf(",%g,%g,%g", x, y, z); } va_end(ap); printf(")\n"); } void mcdis_rectangle(char* plane, double x, double y, double z, double width, double height){ /* draws a rectangle in the plane */ /* x is ALWAYS width and y is ALWAYS height */ if (strcmp("xy", plane)==0) { mcdis_multiline(5, x - width/2, y - height/2, z, x + width/2, y - height/2, z, x + width/2, y + height/2, z, x - width/2, y + height/2, z, x - width/2, y - height/2, z); } else if (strcmp("xz", plane)==0) { mcdis_multiline(5, x - width/2, y, z - height/2, x + width/2, y, z - height/2, x + width/2, y, z + height/2, x - width/2, y, z + height/2, x - width/2, y, z - height/2); } else if (strcmp("yz", plane)==0) { mcdis_multiline(5, x, y - height/2, z - width/2, x, y - height/2, z + width/2, x, y + height/2, z + width/2, x, y + height/2, z - width/2, x, y - height/2, z - width/2); } else { fprintf(stderr, "Error: Definition of plane %s unknown\n", plane); exit(1); } } /* draws a box with center at (x, y, z) and width (deltax), height (deltay), length (deltaz) */ void mcdis_box(double x, double y, double z, double width, double height, double length){ mcdis_rectangle("xy", x, y, z-length/2, width, height); mcdis_rectangle("xy", x, y, z+length/2, width, height); mcdis_line(x-width/2, y-height/2, z-length/2, x-width/2, y-height/2, z+length/2); mcdis_line(x-width/2, y+height/2, z-length/2, x-width/2, y+height/2, z+length/2); mcdis_line(x+width/2, y-height/2, z-length/2, x+width/2, y-height/2, z+length/2); mcdis_line(x+width/2, y+height/2, z-length/2, x+width/2, y+height/2, z+length/2); } void mcdis_circle(char *plane, double x, double y, double z, double r){ printf("MCDISPLAY: circle('%s',%g,%g,%g,%g)\n", plane, x, y, z, r); } /* Draws a circle with center (x,y,z), radius (r), and in the plane * with normal (nx,ny,nz)*/ void mcdis_Circle(double x, double y, double z, double r, double nx, double ny, double nz){ int i; if(nx==0 && ny && nz==0){ for (i=0;i<24; i++){ mcdis_line(x+r*sin(i*2*PI/24),y,z+r*cos(i*2*PI/24), x+r*sin((i+1)*2*PI/24),y,z+r*cos((i+1)*2*PI/24)); } }else{ double mx,my,mz; /*generate perpendicular vector using (nx,ny,nz) and (0,1,0)*/ vec_prod(mx,my,mz, 0,1,0, nx,ny,nz); NORM(mx,my,mz); /*draw circle*/ for (i=0;i<24; i++){ double ux,uy,uz; double wx,wy,wz; rotate(ux,uy,uz, mx,my,mz, i*2*PI/24, nx,ny,nz); rotate(wx,wy,wz, mx,my,mz, (i+1)*2*PI/24, nx,ny,nz); mcdis_line(x+ux*r,y+uy*r,z+uz*r, x+wx*r,y+wy*r,z+wz*r); } } } /* Draws a cylinder with center at (x,y,z) with extent (r,height). * The cylinder axis is along the vector nx,ny,nz. * N determines how many vertical lines are drawn.*/ void mcdis_cylinder( double x, double y, double z, double r, double height, int N, double nx, double ny, double nz){ int i; /*no lines make little sense - so trigger the default*/ if(N<=0) N=5; NORM(nx,ny,nz); double h_2=height/2.0; mcdis_Circle(x+nx*h_2,y+ny*h_2,z+nz*h_2,r,nx,ny,nz); mcdis_Circle(x-nx*h_2,y-ny*h_2,z-nz*h_2,r,nx,ny,nz); double mx,my,mz; /*generate perpendicular vector using (nx,ny,nz) and (0,1,0)*/ if(nx==0 && ny && nz==0){ mx=my=0;mz=1; }else{ vec_prod(mx,my,mz, 0,1,0, nx,ny,nz); NORM(mx,my,mz); } /*draw circle*/ for (i=0; i<24; i++){ double ux,uy,uz; rotate(ux,uy,uz, mx,my,mz, i*2*PI/24, nx,ny,nz); mcdis_line(x+nx*h_2+ux*r, y+ny*h_2+uy*r, z+nz*h_2+uz*r, x-nx*h_2+ux*r, y-ny*h_2+uy*r, z-nz*h_2+uz*r); } } /* draws a sphere with center at (x,y,z) with extent (r) * The sphere is drawn using N longitudes and N latitudes.*/ void mcdis_sphere(double x, double y, double z, double r, int N){ double nx,ny,nz; int i; /*no lines make little sense - so trigger the default*/ if(N<=0) N=5; nx=0;ny=0;nz=1; mcdis_Circle(x,y,z,r,nx,ny,nz); for (i=1;ix /= temp; c->y /= temp; c->z /= temp; } /******************************************************************************* * The Rotation type implements a rotation transformation of a coordinate * system in the form of a double[3][3] matrix. * * Contrary to the Coords type in coords.c, rotations are passed by * reference. Functions that yield new rotations do so by writing to an * explicit result parameter; rotations are not returned from functions. The * reason for this is that arrays cannot by returned from functions (though * structures can; thus an alternative would have been to wrap the * double[3][3] array up in a struct). Such are the ways of C programming. * * A rotation represents the tranformation of the coordinates of a vector when * changing between coordinate systems that are rotated with respect to each * other. For example, suppose that coordinate system Q is rotated 45 degrees * around the Z axis with respect to coordinate system P. Let T be the * rotation transformation representing a 45 degree rotation around Z. Then to * get the coordinates of a vector r in system Q, apply T to the coordinates * of r in P. If r=(1,0,0) in P, it will be (sqrt(1/2),-sqrt(1/2),0) in * Q. Thus we should be careful when interpreting the sign of rotation angles: * they represent the rotation of the coordinate systems, not of the * coordinates (which has opposite sign). *******************************************************************************/ /******************************************************************************* * rot_set_rotation: Get transformation for rotation first phx around x axis, * then phy around y, then phz around z. *******************************************************************************/ #pragma acc routine seq void rot_set_rotation(Rotation t, double phx, double phy, double phz) { if ((phx == 0) && (phy == 0) && (phz == 0)) { t[0][0] = 1.0; t[0][1] = 0.0; t[0][2] = 0.0; t[1][0] = 0.0; t[1][1] = 1.0; t[1][2] = 0.0; t[2][0] = 0.0; t[2][1] = 0.0; t[2][2] = 1.0; } else { double cx = cos(phx); double sx = sin(phx); double cy = cos(phy); double sy = sin(phy); double cz = cos(phz); double sz = sin(phz); t[0][0] = cy*cz; t[0][1] = sx*sy*cz + cx*sz; t[0][2] = sx*sz - cx*sy*cz; t[1][0] = -cy*sz; t[1][1] = cx*cz - sx*sy*sz; t[1][2] = sx*cz + cx*sy*sz; t[2][0] = sy; t[2][1] = -sx*cy; t[2][2] = cx*cy; } } /******************************************************************************* * rot_test_identity: Test if rotation is identity *******************************************************************************/ #pragma acc routine seq int rot_test_identity(Rotation t) { return (t[0][0] + t[1][1] + t[2][2] == 3); } /******************************************************************************* * rot_mul: Matrix multiplication of transformations (this corresponds to * combining transformations). After rot_mul(T1, T2, T3), doing T3 is * equal to doing first T2, then T1. * Note that T3 must not alias (use the same array as) T1 or T2. *******************************************************************************/ #pragma acc routine seq void rot_mul(Rotation t1, Rotation t2, Rotation t3) { if (rot_test_identity(t1)) { rot_copy(t3, t2); } else if (rot_test_identity(t2)) { rot_copy(t3, t1); } else { int i,j; for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) t3[i][j] = t1[i][0]*t2[0][j] + t1[i][1]*t2[1][j] + t1[i][2]*t2[2][j]; } } /******************************************************************************* * rot_copy: Copy a rotation transformation (arrays cannot be assigned in C). *******************************************************************************/ #pragma acc routine seq void rot_copy(Rotation dest, Rotation src) { int i,j; for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) dest[i][j] = src[i][j]; } /******************************************************************************* * rot_transpose: Matrix transposition, which is inversion for Rotation matrices *******************************************************************************/ #pragma acc routine seq void rot_transpose(Rotation src, Rotation dst) { dst[0][0] = src[0][0]; dst[0][1] = src[1][0]; dst[0][2] = src[2][0]; dst[1][0] = src[0][1]; dst[1][1] = src[1][1]; dst[1][2] = src[2][1]; dst[2][0] = src[0][2]; dst[2][1] = src[1][2]; dst[2][2] = src[2][2]; } /******************************************************************************* * rot_apply: returns t*a *******************************************************************************/ #pragma acc routine seq Coords rot_apply(Rotation t, Coords a) { Coords b; if (rot_test_identity(t)) { return a; } else { b.x = t[0][0]*a.x + t[0][1]*a.y + t[0][2]*a.z; b.y = t[1][0]*a.x + t[1][1]*a.y + t[1][2]*a.z; b.z = t[2][0]*a.x + t[2][1]*a.y + t[2][2]*a.z; return b; } } /** * Pretty-printing of rotation matrices. */ void rot_print(Rotation rot) { printf("[ %4.2f %4.2f %4.2f ]\n", rot[0][0], rot[0][1], rot[0][2]); printf("[ %4.2f %4.2f %4.2f ]\n", rot[1][0], rot[1][1], rot[1][2]); printf("[ %4.2f %4.2f %4.2f ]\n\n", rot[2][0], rot[2][1], rot[2][2]); } /** * Vector product: used by vec_prod (mccode-r.h). Use coords_xp for Coords. */ #pragma acc routine seq void vec_prod_func(double *x, double *y, double *z, double x1, double y1, double z1, double x2, double y2, double z2) { *x = (y1)*(z2) - (y2)*(z1); *y = (z1)*(x2) - (z2)*(x1); *z = (x1)*(y2) - (x2)*(y1); } /** * Scalar product: use coords_sp for Coords. */ #pragma acc routine seq double scalar_prod( double x1, double y1, double z1, double x2, double y2, double z2) { return ((x1 * x2) + (y1 * y2) + (z1 * z2)); } #pragma acc routine seq mcstatic void norm_func(double *x, double *y, double *z) { double temp = (*x * *x) + (*y * *y) + (*z * *z); if (temp != 0) { temp = sqrt(temp); *x /= temp; *y /= temp; *z /= temp; } } /* SECTION: GPU algorithms ================================================== */ /* * Divide-and-conquer strategy for parallelizing this task: Sort absorbed * particles last. * * particles: the particle array, required to checking _absorbed * pbuffer: same-size particle buffer array required for parallel sort * len: sorting area-of-interest size (e.g. from previous calls) * buffer_len: total array size * flag_split: if set, multiply live particles into absorbed slots, up to buffer_len * multiplier: output arg, becomes the SPLIT multiplier if flag_split is set */ #ifdef FUNNEL long sort_absorb_last(_class_particle* particles, _class_particle* pbuffer, long len, long buffer_len, long flag_split, long* multiplier) { #define SAL_THREADS 1024 // num parallel sections if (len_absorbed)); // return (no SPLIT) if (flag_split != 1) return accumlen; // SPLIT - repeat the non-absorbed block N-1 times, where len % accumlen = N + R int mult = buffer_len / accumlen; // TODO: possibly use a new arg, bufferlen, rather than len // not enough space for full-block split, return if (mult <= 1) return accumlen; // copy non-absorbed block #pragma acc parallel loop present(particles) for (long tidx = 0; tidx < accumlen; tidx++) { // tidx: thread index unsigned long randstate[7]; _class_particle sourcebuffer; _class_particle targetbuffer; // assign reduced weight to all particles particles[tidx].p=particles[tidx].p/mult; #pragma acc loop seq for (long bidx = 1; bidx < mult; bidx++) { // bidx: block index // preserve absorbed particle (for randstate) sourcebuffer = particles[bidx*accumlen + tidx]; // buffer full particle struct targetbuffer = particles[tidx]; // reassign previous randstate targetbuffer.randstate[0] = sourcebuffer.randstate[0]; targetbuffer.randstate[1] = sourcebuffer.randstate[1]; targetbuffer.randstate[2] = sourcebuffer.randstate[2]; targetbuffer.randstate[3] = sourcebuffer.randstate[3]; targetbuffer.randstate[4] = sourcebuffer.randstate[4]; targetbuffer.randstate[5] = sourcebuffer.randstate[5]; targetbuffer.randstate[6] = sourcebuffer.randstate[6]; // apply particles[bidx*accumlen + tidx] = targetbuffer; } } // set out split multiplier value *multiplier = mult; // return expanded array size return accumlen * mult; } #endif /* * Fallback serial version of the one above. */ long sort_absorb_last_serial(_class_particle* particles, long len) { long i = 0; long j = len - 1; _class_particle pbuffer; // bubble while (i < j) { while (!particles[i]._absorbed && ix; b.y = particle->y; b.z = particle->z; c = rot_apply(t, b); b = coords_add(c, a); particle->x = b.x; particle->y = b.y; particle->z = b.z; #if MCCODE_PARTICLE_CODE == 2112 if (particle->vz != 0.0 || particle->vx != 0.0 || particle->vy != 0.0) mccoordschange_polarisation(t, &(particle->vx), &(particle->vy), &(particle->vz)); if (particle->sz != 0.0 || particle->sx != 0.0 || particle->sy != 0.0) mccoordschange_polarisation(t, &(particle->sx), &(particle->sy), &(particle->sz)); #elif MCCODE_PARTICLE_CODE == 22 if (particle->kz != 0.0 || particle->kx != 0.0 || particle->ky != 0.0) mccoordschange_polarisation(t, &(particle->kx), &(particle->ky), &(particle->kz)); if (particle->Ez != 0.0 || particle->Ex != 0.0 || particle->Ey != 0.0) mccoordschange_polarisation(t, &(particle->Ex), &(particle->Ey), &(particle->Ez)); #endif } /******************************************************************************* * mccoordschange_polarisation: applies rotation to vector (sx sy sz) *******************************************************************************/ #pragma acc routine seq void mccoordschange_polarisation(Rotation t, double *sx, double *sy, double *sz) { Coords b, c; b.x = *sx; b.y = *sy; b.z = *sz; c = rot_apply(t, b); *sx = c.x; *sy = c.y; *sz = c.z; } /* SECTION: vector math ==================================================== */ /* normal_vec_func: Compute normal vector to (x,y,z). */ #pragma acc routine seq void normal_vec(double *nx, double *ny, double *nz, double x, double y, double z) { double ax = fabs(x); double ay = fabs(y); double az = fabs(z); double l; if(x == 0 && y == 0 && z == 0) { *nx = 0; *ny = 0; *nz = 0; return; } if(ax < ay) { if(ax < az) { /* Use X axis */ l = sqrt(z*z + y*y); *nx = 0; *ny = z/l; *nz = -y/l; return; } } else { if(ay < az) { /* Use Y axis */ l = sqrt(z*z + x*x); *nx = z/l; *ny = 0; *nz = -x/l; return; } } /* Use Z axis */ l = sqrt(y*y + x*x); *nx = y/l; *ny = -x/l; *nz = 0; } /* normal_vec */ /******************************************************************************* * solve_2nd_order: second order equation solve: A*t^2 + B*t + C = 0 * solve_2nd_order(&t1, NULL, A,B,C) * returns 0 if no solution was found, or set 't1' to the smallest positive * solution. * solve_2nd_order(&t1, &t2, A,B,C) * same as with &t2=NULL, but also returns the second solution. * EXAMPLE usage for intersection of a trajectory with a plane in gravitation * field (gx,gy,gz): * The neutron starts at point r=(x,y,z) with velocityv=(vx vy vz). The plane * has a normal vector n=(nx,ny,nz) and contains the point W=(wx,wy,wz). * The problem consists in solving the 2nd order equation: * 1/2.n.g.t^2 + n.v.t + n.(r-W) = 0 * so that A = 0.5 n.g; B = n.v; C = n.(r-W); * Without acceleration, t=-n.(r-W)/n.v ******************************************************************************/ #pragma acc routine seq int solve_2nd_order(double *t1, double *t2, double A, double B, double C) { int ret=0; if (!t1) return 0; *t1 = 0; if (t2) *t2=0; if (fabs(A) < 1E-10) /* approximate to linear equation: A ~ 0 */ { if (B) { *t1 = -C/B; ret=1; if (t2) *t2=*t1; } /* else no intersection: A=B=0 ret=0 */ } else { double D; D = B*B - 4*A*C; if (D >= 0) /* Delta > 0: two solutions */ { double sD, dt1, dt2; sD = sqrt(D); dt1 = (-B + sD)/2/A; dt2 = (-B - sD)/2/A; /* we identify very small values with zero */ if (fabs(dt1) < 1e-10) dt1=0.0; if (fabs(dt2) < 1e-10) dt2=0.0; /* now we choose the smallest positive solution */ if (dt1<=0.0 && dt2>0.0) ret=2; /* dt2 positive */ else if (dt2<=0.0 && dt1>0.0) ret=1; /* dt1 positive */ else if (dt1> 0.0 && dt2>0.0) { if (dt1 < dt2) ret=1; else ret=2; } /* all positive: min(dt1,dt2) */ /* else two solutions are negative. ret=-1 */ if (ret==1) { *t1 = dt1; if (t2) *t2=dt2; } else { *t1 = dt2; if (t2) *t2=dt1; } ret=2; /* found 2 solutions and t1 is the positive one */ } /* else Delta <0: no intersection. ret=0 */ } return(ret); } /* solve_2nd_order */ /******************************************************************************* * randvec_target_circle: Choose random direction towards target at (x,y,z) * with given radius. * If radius is zero, choose random direction in full 4PI, no target. ******************************************************************************/ #pragma acc routine seq void _randvec_target_circle(double *xo, double *yo, double *zo, double *solid_angle, double xi, double yi, double zi, double radius, _class_particle* _particle) { double l2, phi, theta, nx, ny, nz, xt, yt, zt, xu, yu, zu; if(radius == 0.0) { /* No target, choose uniformly a direction in full 4PI solid angle. */ theta = acos(1 - rand0max(2)); phi = rand0max(2 * PI); if(solid_angle) *solid_angle = 4*PI; nx = 1; ny = 0; nz = 0; yi = sqrt(xi*xi+yi*yi+zi*zi); zi = 0; xi = 0; } else { double costheta0; l2 = xi*xi + yi*yi + zi*zi; /* sqr Distance to target. */ costheta0 = sqrt(l2/(radius*radius+l2)); if (radius < 0) costheta0 *= -1; if(solid_angle) { /* Compute solid angle of target as seen from origin. */ *solid_angle = 2*PI*(1 - costheta0); } /* Now choose point uniformly on circle surface within angle theta0 */ theta = acos (1 - rand0max(1 - costheta0)); /* radius on circle */ phi = rand0max(2 * PI); /* rotation on circle at given radius */ /* Now, to obtain the desired vector rotate (xi,yi,zi) angle theta around a perpendicular axis u=i x n and then angle phi around i. */ if(xi == 0 && zi == 0) { nx = 1; ny = 0; nz = 0; } else { nx = -zi; nz = xi; ny = 0; } } /* [xyz]u = [xyz]i x n[xyz] (usually vertical) */ vec_prod(xu, yu, zu, xi, yi, zi, nx, ny, nz); /* [xyz]t = [xyz]i rotated theta around [xyz]u */ rotate (xt, yt, zt, xi, yi, zi, theta, xu, yu, zu); /* [xyz]o = [xyz]t rotated phi around n[xyz] */ rotate (*xo, *yo, *zo, xt, yt, zt, phi, xi, yi, zi); } /* randvec_target_circle */ /******************************************************************************* * randvec_target_rect_angular: Choose random direction towards target at * (xi,yi,zi) with given ANGULAR dimension height x width. height=phi_x=[0,PI], * width=phi_y=[0,2*PI] (radians) * If height or width is zero, choose random direction in full 4PI, no target. *******************************************************************************/ #pragma acc routine seq void _randvec_target_rect_angular(double *xo, double *yo, double *zo, double *solid_angle, double xi, double yi, double zi, double width, double height, Rotation A, _class_particle* _particle) { double theta, phi, nx, ny, nz, xt, yt, zt, xu, yu, zu; Coords tmp; Rotation Ainverse; rot_transpose(A, Ainverse); if(height == 0.0 || width == 0.0) { randvec_target_circle(xo, yo, zo, solid_angle, xi, yi, zi, 0); return; } else { if(solid_angle) { /* Compute solid angle of target as seen from origin. */ *solid_angle = 2*fabs(width*sin(height/2)); } /* Go to global coordinate system */ tmp = coords_set(xi, yi, zi); tmp = rot_apply(Ainverse, tmp); coords_get(tmp, &xi, &yi, &zi); /* Now choose point uniformly on the unit sphere segment with angle theta/phi */ phi = width*randpm1()/2.0; theta = asin(randpm1()*sin(height/2.0)); /* Now, to obtain the desired vector rotate (xi,yi,zi) angle theta around n, and then phi around u. */ if(xi == 0 && zi == 0) { nx = 1; ny = 0; nz = 0; } else { nx = -zi; nz = xi; ny = 0; } } /* [xyz]u = [xyz]i x n[xyz] (usually vertical) */ vec_prod(xu, yu, zu, xi, yi, zi, nx, ny, nz); /* [xyz]t = [xyz]i rotated theta around [xyz]u */ rotate (xt, yt, zt, xi, yi, zi, theta, nx, ny, nz); /* [xyz]o = [xyz]t rotated phi around n[xyz] */ rotate (*xo, *yo, *zo, xt, yt, zt, phi, xu, yu, zu); /* Go back to local coordinate system */ tmp = coords_set(*xo, *yo, *zo); tmp = rot_apply(A, tmp); coords_get(tmp, &*xo, &*yo, &*zo); } /* randvec_target_rect_angular */ /******************************************************************************* * randvec_target_rect_real: Choose random direction towards target at (xi,yi,zi) * with given dimension height x width (in meters !). * * Local emission coordinate is taken into account and corrected for 'order' times. * (See remarks posted to mcstas-users by George Apostolopoulus ) * * If height or width is zero, choose random direction in full 4PI, no target. * * Traditionally, this routine had the name randvec_target_rect - this is now a * a define (see mcstas-r.h) pointing here. If you use the old rouine, you are NOT * taking the local emmission coordinate into account. *******************************************************************************/ #pragma acc routine seq void _randvec_target_rect_real(double *xo, double *yo, double *zo, double *solid_angle, double xi, double yi, double zi, double width, double height, Rotation A, double lx, double ly, double lz, int order, _class_particle* _particle) { double dx, dy, dist, dist_p, nx, ny, nz, mx, my, mz, n_norm, m_norm; double cos_theta; Coords tmp; Rotation Ainverse; rot_transpose(A, Ainverse); if(height == 0.0 || width == 0.0) { randvec_target_circle(xo, yo, zo, solid_angle, xi, yi, zi, 0); return; } else { /* Now choose point uniformly on rectangle within width x height */ dx = width*randpm1()/2.0; dy = height*randpm1()/2.0; /* Determine distance to target plane*/ dist = sqrt(xi*xi + yi*yi + zi*zi); /* Go to global coordinate system */ tmp = coords_set(xi, yi, zi); tmp = rot_apply(Ainverse, tmp); coords_get(tmp, &xi, &yi, &zi); /* Determine vector normal to trajectory axis (z) and gravity [0 1 0] */ vec_prod(nx, ny, nz, xi, yi, zi, 0, 1, 0); /* This now defines the x-axis, normalize: */ n_norm=sqrt(nx*nx + ny*ny + nz*nz); nx = nx/n_norm; ny = ny/n_norm; nz = nz/n_norm; /* Now, determine our y-axis (vertical in many cases...) */ vec_prod(mx, my, mz, xi, yi, zi, nx, ny, nz); m_norm=sqrt(mx*mx + my*my + mz*mz); mx = mx/m_norm; my = my/m_norm; mz = mz/m_norm; /* Our output, random vector can now be defined by linear combination: */ *xo = xi + dx * nx + dy * mx; *yo = yi + dx * ny + dy * my; *zo = zi + dx * nz + dy * mz; /* Go back to local coordinate system */ tmp = coords_set(*xo, *yo, *zo); tmp = rot_apply(A, tmp); coords_get(tmp, &*xo, &*yo, &*zo); /* Go back to local coordinate system */ tmp = coords_set(xi, yi, zi); tmp = rot_apply(A, tmp); coords_get(tmp, &xi, &yi, &zi); if (solid_angle) { /* Calculate vector from local point to remote random point */ lx = *xo - lx; ly = *yo - ly; lz = *zo - lz; dist_p = sqrt(lx*lx + ly*ly + lz*lz); /* Adjust the 'solid angle' */ /* 1/r^2 to the chosen point times cos(\theta) between the normal */ /* vector of the target rectangle and direction vector of the chosen point. */ cos_theta = (xi * lx + yi * ly + zi * lz) / (dist * dist_p); *solid_angle = width * height / (dist_p * dist_p); int counter; for (counter = 0; counter < order; counter++) { *solid_angle = *solid_angle * cos_theta; } } } } /* randvec_target_rect_real */ /* SECTION: random numbers ================================================== How to add a new RNG: - Use an rng with a manegable state vector, e.g. of lengt 4 or 7. The state will sit on the particle struct as a "randstate_t state[RANDSTATE_LEN]" - If the rng has a long state (as MT), set an empty "srandom" and initialize it explicitly using the appropriate define (RNG_ALG) - Add a seed and a random function (the transforms will be reused) - Write the proper defines in mccode-r.h, e.g. randstate_t and RANDSTATE_LEN, srandom and random. - Compile using -DRNG_ALG= ============================================================================= */ /* "Mersenne Twister", by Makoto Matsumoto and Takuji Nishimura. */ /* See http://www.math.keio.ac.jp/~matumoto/emt.html for original source. */ /* A C-program for MT19937, with initialization improved 2002/1/26. Coded by Takuji Nishimura and Makoto Matsumoto. Before using, initialize the state by using mt_srandom(seed) or init_by_array(init_key, key_length). Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Any feedback is very welcome. http://www.math.keio.ac.jp/matumoto/emt.html email: matumoto@math.keio.ac.jp */ #include /* Period parameters */ #define N 624 #define M 397 #define MATRIX_A 0x9908b0dfUL /* constant vector a */ #define UPPER_MASK 0x80000000UL /* most significant w-r bits */ #define LOWER_MASK 0x7fffffffUL /* least significant r bits */ unsigned long mt[N]; /* the array for the state vector */ int mti=N+1; /* mti==N+1 means mt[N] is not initialized */ // required for common rng alg interface (see RNG_ALG usage in mccode-r.h) void mt_srandom_empty() {} // initializes mt[N] with a seed void mt_srandom(unsigned long s) { mt[0]= s & 0xffffffffUL; for (mti=1; mti> 30)) + mti); /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ /* In the previous versions, MSBs of the seed affect */ /* only MSBs of the array mt[]. */ /* 2002/01/09 modified by Makoto Matsumoto */ mt[mti] &= 0xffffffffUL; /* for >32 bit machines */ } } /* Initialize by an array with array-length. Init_key is the array for initializing keys. key_length is its length. */ void init_by_array(unsigned long init_key[], unsigned long key_length) { int i, j, k; mt_srandom(19650218UL); i=1; j=0; k = (N>key_length ? N : key_length); for (; k; k--) { mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL)) + init_key[j] + j; /* non linear */ mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ i++; j++; if (i>=N) { mt[0] = mt[N-1]; i=1; } if (j>=key_length) j=0; } for (k=N-1; k; k--) { mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL)) - i; /* non linear */ mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ i++; if (i>=N) { mt[0] = mt[N-1]; i=1; } } mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */ } /* generates a random number on [0,0xffffffff]-interval */ unsigned long mt_random(void) { unsigned long y; unsigned long mag01[2]={0x0UL, MATRIX_A}; /* mag01[x] = x * MATRIX_A for x=0,1 */ if (mti >= N) { /* generate N words at one time */ int kk; if (mti == N+1) /* if mt_srandom() has not been called, */ mt_srandom(5489UL); /* a default initial seed is used */ for (kk=0;kk> 1) ^ mag01[y & 0x1UL]; } for (;kk> 1) ^ mag01[y & 0x1UL]; } y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK); mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL]; mti = 0; } y = mt[mti++]; /* Tempering */ y ^= (y >> 11); y ^= (y << 7) & 0x9d2c5680UL; y ^= (y << 15) & 0xefc60000UL; y ^= (y >> 18); return y; } #undef N #undef M #undef MATRIX_A #undef UPPER_MASK #undef LOWER_MASK /* End of "Mersenne Twister". */ /* KISS From: http://www.helsbreth.org/random/rng_kiss.html Scott Nelson 1999 Based on Marsaglia's KISS or (KISS+SWB) KISS - Keep it Simple Stupid PRNG the idea is to use simple, fast, individually promising generators to get a composite that will be fast, easy to code have a very long period and pass all the tests put to it. The three components of KISS are x(n)=a*x(n-1)+1 mod 2^32 y(n)=y(n-1)(I+L^13)(I+R^17)(I+L^5), z(n)=2*z(n-1)+z(n-2) +carry mod 2^32 The y's are a shift register sequence on 32bit binary vectors period 2^32-1; The z's are a simple multiply-with-carry sequence with period 2^63+2^32-1. The period of KISS is thus 2^32*(2^32-1)*(2^63+2^32-1) > 2^127 */ /* the KISS state is stored as a vector of 7 unsigned long */ /* 0 1 2 3 4 5 6 */ /* [ x, y, z, w, carry, k, m ] */ #pragma acc routine seq unsigned long *kiss_srandom(unsigned long state[7], unsigned long seed) { if (seed == 0) seed = 1; state[0] = seed | 1; // x state[1] = seed | 2; // y state[2] = seed | 4; // z state[3] = seed | 8; // w state[4] = 0; // carry return 0; } #pragma acc routine seq unsigned long kiss_random(unsigned long state[7]) { state[0] = state[0] * 69069 + 1; state[1] ^= state[1] << 13; state[1] ^= state[1] >> 17; state[1] ^= state[1] << 5; state[5] = (state[2] >> 2) + (state[3] >> 3) + (state[4] >> 2); state[6] = state[3] + state[3] + state[2] + state[4]; state[2] = state[3]; state[3] = state[6]; state[4] = state[5] >> 30; return state[0] + state[1] + state[3]; } /* end of "KISS" rng */ /* FAST KISS in another implementation (Hundt) */ ////////////////////////////////////////////////////////////////////////////// // fast keep it simple stupid generator ////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Thomas Mueller hash for initialization of rngs // http://stackoverflow.com/questions/664014/ // what-integer-hash-function-are-good-that-accepts-an-integer-hash-key ////////////////////////////////////////////////////////////////////////////// #pragma acc routine seq randstate_t _hash(randstate_t x) { x = ((x >> 16) ^ x) * 0x45d9f3b; x = ((x >> 16) ^ x) * 0x45d9f3b; x = ((x >> 16) ^ x); return x; } // fast kiss state is a pointer to 5 long [x,y,z,w,c] #pragma acc routine seq randstate_t fast_kiss(randstate_t * state) { state[1] ^= state[1] << 5; state[1] ^= state[1] >> 7; state[1] ^= state[1] << 22; randstate_t t = state[2]+state[3]+state[4]; state[2] = state[3]; state[4] = t < 0; state[3] = t & 2147483647; state[0] += 1411392427; // combine return state[0]+state[1]+state[3]; } randstate_t * fast_kiss_seed(randstate_t * state, randstate_t seed) { randstate_t num_iters=8; state[3] = !seed ? 4294967295 : seed; for (randstate_t iter = 0; iter < num_iters; iter++) { state[0] = _hash(state[3]); state[1] = _hash(state[0]); state[2] = _hash(state[1]); state[3] = _hash(state[2]); } return state; state[4] = 0; return state; } // SECTION: random number transforms ========================================== // generate a random number from normal law double _randnorm(randstate_t* state) { static double v1, v2, s; /* removing static breaks comparison with McStas <= 2.5 */ static int phase = 0; double X, u1, u2; if(phase == 0) { do { u1 = _rand01(state); u2 = _rand01(state); v1 = 2*u1 - 1; v2 = 2*u2 - 1; s = v1*v1 + v2*v2; } while(s >= 1 || s == 0); X = v1*sqrt(-2*log(s)/s); } else { X = v2*sqrt(-2*log(s)/s); } phase = 1 - phase; return X; } // another one #pragma acc routine seq double _randnorm2(randstate_t* state) { double x, y, r; do { x = 2.0 * _rand01(state) - 1.0; y = 2.0 * _rand01(state) - 1.0; r = x*x + y*y; } while (r == 0.0 || r >= 1.0); return x * sqrt((-2.0 * log(r)) / r); } #pragma acc routine seq double _gaussian_double(randstate_t * state) { double x, y, r; do { x = 2.0 * _uniform_double(state) - 1.0; y = 2.0 * _uniform_double(state) - 1.0; r = x*x + y*y; } while (r == 0.0 || r >= 1.0); return x * sqrt((-2.0 * log(r)) / r); } // Generate a random number from -1 to 1 with triangle distribution #pragma acc routine seq double _randtriangle(randstate_t* state) { double randnum = _rand01(state); if (randnum>0.5) return(1-sqrt(2*(randnum-0.5))); else return(sqrt(2*randnum)-1); } // Random number between 0.0 and 1.0 #pragma acc routine seq double _uniform_double(randstate_t * state) { randstate_t a = fast_kiss(state) >> 6; randstate_t b = fast_kiss(state) >> 5; double x = (a * 134217728.0 + b) / 9007199254740992.0; return x; } #pragma acc routine seq double _rand01(randstate_t* state) { double randnum; randnum = (double) _random(); // TODO: can we mult instead of div? randnum /= (double) MC_RAND_MAX + 1; return randnum; } // Return a random number between 1 and -1 #pragma acc routine seq double _randpm1(randstate_t* state) { double randnum; randnum = (double) _random(); randnum /= ((double) MC_RAND_MAX + 1) / 2; randnum -= 1; return randnum; } // Return a random number between 0 and max. #pragma acc routine seq double _rand0max(double max, randstate_t* state) { double randnum; randnum = (double) _random(); randnum /= ((double) MC_RAND_MAX + 1) / max; return randnum; } // Return a random number between min and max. #pragma acc routine seq double _randminmax(double min, double max, randstate_t* state) { return _rand0max(max - min, state) + max; } /* SECTION: main and signal handlers ======================================== */ /******************************************************************************* * mchelp: displays instrument executable help with possible options *******************************************************************************/ static void mchelp(char *pgmname) { int i; fprintf(stderr, "%s (%s) instrument simulation, generated with " MCCODE_STRING " (" MCCODE_DATE ")\n", instrument_name, instrument_source); fprintf(stderr, "Usage: %s [options] [parm=value ...]\n", pgmname); fprintf(stderr, "Options are:\n" " -s SEED --seed=SEED Set random seed (must be != 0)\n" " -n COUNT --ncount=COUNT Set number of particles to simulate.\n" " -d DIR --dir=DIR Put all data files in directory DIR.\n" " -t --trace Enable trace of " MCCODE_PARTICLE "s through instrument.\n" " -g --gravitation Enable gravitation for all trajectories.\n" " --no-output-files Do not write any data files.\n" " -h --help Show this help message.\n" " -i --info Detailed instrument information.\n" " --source Show the instrument code which was compiled.\n" " --format=FORMAT Output data files using FORMAT=" FLAVOR_UPPER #ifdef USE_NEXUS " NEXUS" #endif "\n\n" ); #ifdef USE_MPI fprintf(stderr, "This instrument has been compiled with MPI support.\n Use 'mpirun %s [options] [parm=value ...]'.\n", pgmname); #endif #ifdef OPENACC fprintf(stderr, "This instrument has been compiled with NVIDIA GPU support through OpenACC.\n Running on systems without such devices will lead to segfaults.\nFurter, fprintf, sprintf and printf have been removed from any component TRACE.\n"); #endif if(numipar > 0) { fprintf(stderr, "Instrument parameters are:\n"); for(i = 0; i < numipar; i++) if (mcinputtable[i].val && strlen(mcinputtable[i].val)) fprintf(stderr, " %-16s(%s) [default='%s']\n", mcinputtable[i].name, (*mcinputtypes[mcinputtable[i].type].parminfo)(mcinputtable[i].name), mcinputtable[i].val); else fprintf(stderr, " %-16s(%s)\n", mcinputtable[i].name, (*mcinputtypes[mcinputtable[i].type].parminfo)(mcinputtable[i].name)); } #ifndef NOSIGNALS fprintf(stderr, "Known signals are: " #ifdef SIGUSR1 "USR1 (status) " #endif #ifdef SIGUSR2 "USR2 (save) " #endif #ifdef SIGBREAK "BREAK (save) " #endif #ifdef SIGTERM "TERM (save and exit)" #endif "\n"); #endif /* !NOSIGNALS */ } /* mchelp */ /* mcshowhelp: show help and exit with 0 */ static void mcshowhelp(char *pgmname) { mchelp(pgmname); exit(0); } /* mcusage: display usage when error in input arguments and exit with 1 */ static void mcusage(char *pgmname) { fprintf(stderr, "Error: incorrect command line arguments\n"); mchelp(pgmname); exit(1); } /* mcenabletrace: enable trace/mcdisplay or error if requires recompile */ static void mcenabletrace(void) { if(traceenabled) mcdotrace = 1; else { fprintf(stderr, "Error: trace not enabled (mcenabletrace)\n" "Please re-run the " MCCODE_NAME " compiler " "with the --trace option, or rerun the\n" "C compiler with the MC_TRACE_ENABLED macro defined.\n"); exit(1); } } /******************************************************************************* * mcreadparams: request parameters from the prompt (or use default) *******************************************************************************/ void mcreadparams(void) { int i,j,status; static char buf[CHAR_BUF_LENGTH]; char *p; int len; MPI_MASTER(printf("Instrument parameters for %s (%s)\n", instrument_name, instrument_source)); for(i = 0; mcinputtable[i].name != 0; i++) { do { MPI_MASTER( if (mcinputtable[i].val && strlen(mcinputtable[i].val)) printf("Set value of instrument parameter %s (%s) [default='%s']:\n", mcinputtable[i].name, (*mcinputtypes[mcinputtable[i].type].parminfo) (mcinputtable[i].name), mcinputtable[i].val); else printf("Set value of instrument parameter %s (%s):\n", mcinputtable[i].name, (*mcinputtypes[mcinputtable[i].type].parminfo) (mcinputtable[i].name)); fflush(stdout); ); #ifdef USE_MPI if(mpi_node_rank == mpi_node_root) { p = fgets(buf, CHAR_BUF_LENGTH, stdin); if(p == NULL) { fprintf(stderr, "Error: empty input for paramater %s (mcreadparams)\n", mcinputtable[i].name); exit(1); } } else p = buf; MPI_Bcast(buf, CHAR_BUF_LENGTH, MPI_CHAR, mpi_node_root, MPI_COMM_WORLD); #else /* !USE_MPI */ p = fgets(buf, CHAR_BUF_LENGTH, stdin); if(p == NULL) { fprintf(stderr, "Error: empty input for paramater %s (mcreadparams)\n", mcinputtable[i].name); exit(1); } #endif /* USE_MPI */ len = strlen(buf); if (!len || (len == 1 && (buf[0] == '\n' || buf[0] == '\r'))) { if (mcinputtable[i].val && strlen(mcinputtable[i].val)) { strncpy(buf, mcinputtable[i].val, CHAR_BUF_LENGTH); /* use default value */ len = strlen(buf); } } for(j = 0; j < 2; j++) { if(len > 0 && (buf[len - 1] == '\n' || buf[len - 1] == '\r')) { len--; buf[len] = '\0'; } } status = (*mcinputtypes[mcinputtable[i].type].getparm) (buf, mcinputtable[i].par); if(!status) { (*mcinputtypes[mcinputtable[i].type].error)(mcinputtable[i].name, buf); if (!mcinputtable[i].val || strlen(mcinputtable[i].val)) { fprintf(stderr, " Change %s default value in instrument definition.\n", mcinputtable[i].name); exit(1); } } } while(!status); } } /* mcreadparams */ /******************************************************************************* * mcparseoptions: parse command line arguments (options, parameters) *******************************************************************************/ void mcparseoptions(int argc, char *argv[]) { int i, j; char *p; int paramset = 0, *paramsetarray; char *usedir=NULL; /* Add one to numipar to avoid allocating zero size memory block. */ paramsetarray = (int*)malloc((numipar + 1)*sizeof(*paramsetarray)); if(paramsetarray == NULL) { fprintf(stderr, "Error: insufficient memory (mcparseoptions)\n"); exit(1); } for(j = 0; j < numipar; j++) { paramsetarray[j] = 0; if (mcinputtable[j].val != NULL && strlen(mcinputtable[j].val)) { int status; char buf[CHAR_BUF_LENGTH]; strncpy(buf, mcinputtable[j].val, CHAR_BUF_LENGTH); status = (*mcinputtypes[mcinputtable[j].type].getparm) (buf, mcinputtable[j].par); if(!status) fprintf(stderr, "Invalid '%s' default value %s in instrument definition (mcparseoptions)\n", mcinputtable[j].name, buf); else paramsetarray[j] = 1; } else { (*mcinputtypes[mcinputtable[j].type].getparm) (NULL, mcinputtable[j].par); paramsetarray[j] = 0; } } for(i = 1; i < argc; i++) { if(!strcmp("-s", argv[i]) && (i + 1) < argc) mcsetseed(argv[++i]); else if(!strncmp("-s", argv[i], 2)) mcsetseed(&argv[i][2]); else if(!strcmp("--seed", argv[i]) && (i + 1) < argc) mcsetseed(argv[++i]); else if(!strncmp("--seed=", argv[i], 7)) mcsetseed(&argv[i][7]); else if(!strcmp("-n", argv[i]) && (i + 1) < argc) mcsetn_arg(argv[++i]); else if(!strncmp("-n", argv[i], 2)) mcsetn_arg(&argv[i][2]); else if(!strcmp("--ncount", argv[i]) && (i + 1) < argc) mcsetn_arg(argv[++i]); else if(!strncmp("--ncount=", argv[i], 9)) mcsetn_arg(&argv[i][9]); else if(!strcmp("-d", argv[i]) && (i + 1) < argc) usedir=argv[++i]; /* will create directory after parsing all arguments (end of this function) */ else if(!strncmp("-d", argv[i], 2)) usedir=&argv[i][2]; else if(!strcmp("--dir", argv[i]) && (i + 1) < argc) usedir=argv[++i]; else if(!strncmp("--dir=", argv[i], 6)) usedir=&argv[i][6]; else if(!strcmp("-h", argv[i])) mcshowhelp(argv[0]); else if(!strcmp("--help", argv[i]) || !strcmp("--version", argv[i])) mcshowhelp(argv[0]); else if(!strcmp("-i", argv[i])) { mcformat=FLAVOR_UPPER; mcinfo(); } else if(!strcmp("--info", argv[i])) mcinfo(); else if(!strcmp("-t", argv[i])) mcenabletrace(); else if(!strcmp("--trace", argv[i]) || !strcmp("--verbose", argv[i])) mcenabletrace(); else if(!strcmp("--gravitation", argv[i])) mcgravitation = 1; else if(!strcmp("-g", argv[i])) mcgravitation = 1; else if(!strncmp("--format=", argv[i], 9)) { mcformat=&argv[i][9]; } else if(!strcmp("--format", argv[i]) && (i + 1) < argc) { mcformat=argv[++i]; } else if(!strcmp("--no-output-files", argv[i])) mcdisable_output_files = 1; else if(!strcmp("--source", argv[i])) { printf("/* Source code %s from %s: */\n" "/******************************************************************************/\n" "%s\n" "/******************************************************************************/\n" "/* End of source code %s from %s */\n", instrument_name, instrument_source, instrument_code, instrument_name, instrument_source); exit(1); } else if(argv[i][0] != '-' && (p = strchr(argv[i], '=')) != NULL) { *p++ = '\0'; for(j = 0; j < numipar; j++) if(!strcmp(mcinputtable[j].name, argv[i])) { int status; status = (*mcinputtypes[mcinputtable[j].type].getparm)(p, mcinputtable[j].par); if(!status || !strlen(p)) { (*mcinputtypes[mcinputtable[j].type].error) (mcinputtable[j].name, p); exit(1); } paramsetarray[j] = 1; paramset = 1; break; } if(j == numipar) { /* Unrecognized parameter name */ fprintf(stderr, "Error: unrecognized parameter %s (mcparseoptions)\n", argv[i]); exit(1); } } else if(argv[i][0] == '-') { fprintf(stderr, "Error: unrecognized option argument %s (mcparseoptions). Ignored.\n", argv[i++]); } else { fprintf(stderr, "Error: unrecognized argument %s (mcparseoptions). Aborting.\n", argv[i]); mcusage(argv[0]); } } if(!paramset) mcreadparams(); /* Prompt for parameters if not specified. */ else { for(j = 0; j < numipar; j++) if(!paramsetarray[j]) { fprintf(stderr, "Error: Instrument parameter %s left unset (mcparseoptions)\n", mcinputtable[j].name); exit(1); } } free(paramsetarray); #ifdef USE_MPI if (mcdotrace) mpi_node_count=1; /* disable threading when in trace mode */ #endif if (usedir && strlen(usedir) && !mcdisable_output_files) mcuse_dir(usedir); } /* mcparseoptions */ #ifndef NOSIGNALS /******************************************************************************* * sighandler: signal handler that makes simulation stop, and save results *******************************************************************************/ void sighandler(int sig) { /* MOD: E. Farhi, Sep 20th 2001: give more info */ time_t t1, t0; #define SIG_SAVE 0 #define SIG_TERM 1 #define SIG_STAT 2 #define SIG_ABRT 3 printf("\n# " MCCODE_STRING ": [pid %i] Signal %i detected", getpid(), sig); #ifdef USE_MPI printf(" [proc %i]", mpi_node_rank); #endif #if defined(SIGUSR1) && defined(SIGUSR2) && defined(SIGKILL) if (!strcmp(mcsig_message, "sighandler") && (sig != SIGUSR1) && (sig != SIGUSR2)) { printf("\n# Fatal : unrecoverable loop ! Suicide (naughty boy).\n"); kill(0, SIGKILL); /* kill myself if error occurs within sighandler: loops */ } #endif switch (sig) { #ifdef SIGINT case SIGINT : printf(" SIGINT (interrupt from terminal, Ctrl-C)"); sig = SIG_TERM; break; #endif #ifdef SIGILL case SIGILL : printf(" SIGILL (Illegal instruction)"); sig = SIG_ABRT; break; #endif #ifdef SIGFPE case SIGFPE : printf(" SIGFPE (Math Error)"); sig = SIG_ABRT; break; #endif #ifdef SIGSEGV case SIGSEGV : printf(" SIGSEGV (Mem Error)"); sig = SIG_ABRT; break; #endif #ifdef SIGTERM case SIGTERM : printf(" SIGTERM (Termination)"); sig = SIG_TERM; break; #endif #ifdef SIGABRT case SIGABRT : printf(" SIGABRT (Abort)"); sig = SIG_ABRT; break; #endif #ifdef SIGQUIT case SIGQUIT : printf(" SIGQUIT (Quit from terminal)"); sig = SIG_TERM; break; #endif #ifdef SIGTRAP case SIGTRAP : printf(" SIGTRAP (Trace trap)"); sig = SIG_ABRT; break; #endif #ifdef SIGPIPE case SIGPIPE : printf(" SIGPIPE (Broken pipe)"); sig = SIG_ABRT; break; #endif #ifdef SIGUSR1 case SIGUSR1 : printf(" SIGUSR1 (Display info)"); sig = SIG_STAT; break; #endif #ifdef SIGUSR2 case SIGUSR2 : printf(" SIGUSR2 (Save simulation)"); sig = SIG_SAVE; break; #endif #ifdef SIGHUP case SIGHUP : printf(" SIGHUP (Hangup/update)"); sig = SIG_SAVE; break; #endif #ifdef SIGBUS case SIGBUS : printf(" SIGBUS (Bus error)"); sig = SIG_ABRT; break; #endif #ifdef SIGURG case SIGURG : printf(" SIGURG (Urgent socket condition)"); sig = SIG_ABRT; break; #endif #ifdef SIGBREAK case SIGBREAK: printf(" SIGBREAK (Break signal, Ctrl-Break)"); sig = SIG_SAVE; break; #endif default : printf(" (look at signal list for signification)"); sig = SIG_ABRT; break; } printf("\n"); printf("# Simulation: %s (%s) \n", instrument_name, instrument_source); printf("# Breakpoint: %s ", mcsig_message); if (strstr(mcsig_message, "Save") && (sig == SIG_SAVE)) sig = SIG_STAT; SIG_MESSAGE("sighandler"); if (mcget_ncount() == 0) printf("(0 %%)\n" ); else { printf("%.2f %% (%10.1f/%10.1f)\n", 100.0*mcget_run_num()/mcget_ncount(), 1.0*mcget_run_num(), 1.0*mcget_ncount()); } t0 = (time_t)mcstartdate; t1 = time(NULL); printf("# Date: %s", ctime(&t1)); printf("# Started: %s", ctime(&t0)); if (sig == SIG_STAT) { printf("# " MCCODE_STRING ": Resuming simulation (continue)\n"); fflush(stdout); return; } else if (sig == SIG_SAVE) { printf("# " MCCODE_STRING ": Saving data and resume simulation (continue)\n"); save(NULL); fflush(stdout); return; } else if (sig == SIG_TERM) { printf("# " MCCODE_STRING ": Finishing simulation (save results and exit)\n"); finally(); exit(0); } else { fflush(stdout); perror("# Last I/O Error"); printf("# " MCCODE_STRING ": Simulation stop (abort).\n"); // This portion of the signal handling only works on UNIX #if defined(__unix__) || defined(__APPLE__) signal(sig, SIG_DFL); /* force to use default sighandler now */ kill(getpid(), sig); /* and trigger it with the current signal */ #endif exit(-1); } #undef SIG_SAVE #undef SIG_TERM #undef SIG_STAT #undef SIG_ABRT } /* sighandler */ #endif /* !NOSIGNALS */ #ifdef NEUTRONICS /*Main neutronics function steers the McStas calls, initializes parameters etc */ /* Only called in case NEUTRONICS = TRUE */ void neutronics_main_(float *inx, float *iny, float *inz, float *invx, float *invy, float *invz, float *intime, float *insx, float *insy, float *insz, float *inw, float *outx, float *outy, float *outz, float *outvx, float *outvy, float *outvz, float *outtime, float *outsx, float *outsy, float *outsz, float *outwgt) { extern double mcnx, mcny, mcnz, mcnvx, mcnvy, mcnvz; extern double mcnt, mcnsx, mcnsy, mcnsz, mcnp; /* External code governs iteration - McStas is iterated once per call to neutronics_main. I.e. below counter must be initiancated for each call to neutronics_main*/ mcrun_num=0; time_t t; t = (time_t)mcstartdate; mcstartdate = t; /* set start date before parsing options and creating sim file */ init(); /* *** parse options *** */ SIG_MESSAGE("[" __FILE__ "] main START"); mcformat=getenv(FLAVOR_UPPER "_FORMAT") ? getenv(FLAVOR_UPPER "_FORMAT") : FLAVOR_UPPER; /* Set neutron state based on input from neutronics code */ mcsetstate(*inx,*iny,*inz,*invx,*invy,*invz,*intime,*insx,*insy,*insz,*inw); /* main neutron event loop - runs only one iteration */ //mcstas_raytrace(&mcncount); /* prior to McStas 1.12 */ mcallowbackprop = 1; //avoid absorbtion from negative dt int argc=1; char *argv[0]; int dummy = mccode_main(argc, argv); *outx = mcnx; *outy = mcny; *outz = mcnz; *outvx = mcnvx; *outvy = mcnvy; *outvz = mcnvz; *outtime = mcnt; *outsx = mcnsx; *outsy = mcnsy; *outsz = mcnsz; *outwgt = mcnp; return; } /* neutronics_main */ #endif /*NEUTRONICS*/ #endif /* !MCCODE_H */ /* End of file "mccode-r.c". */ /* End of file "mccode-r.c". */ /* embedding file "mcstas-r.c" */ /******************************************************************************* * * McStas, neutron ray-tracing package * Copyright (C) 1997-2009, All rights reserved * Risoe National Laboratory, Roskilde, Denmark * Institut Laue Langevin, Grenoble, France * * Runtime: share/mcstas-r.c * * %Identification * Written by: KN * Date: Aug 29, 1997 * Release: McStas X.Y * Version: $Revision$ * * Runtime system for McStas. * Embedded within instrument in runtime mode. * * Usage: Automatically embbeded in the c code whenever required. * * $Id$ * *******************************************************************************/ #ifndef MCSTAS_R_H #include "mcstas-r.h" #endif #ifdef DANSE #include "mcstas-globals.h" #endif /******************************************************************************* * The I/O format definitions and functions *******************************************************************************/ /*the magnet stack*/ #ifdef MC_POL_COMPAT void (*mcMagnetPrecession) (double, double, double, double, double, double, double, double*, double*, double*, double, Coords, Rotation)=NULL; Coords mcMagnetPos; Rotation mcMagnetRot; double* mcMagnetData = NULL; /* mcMagneticField(x, y, z, t, Bx, By, Bz) */ int (*mcMagneticField) (double, double, double, double, double*, double*, double*, void *) = NULL; #endif #ifndef MCSTAS_H /******************************************************************************* * mcsetstate: transfer parameters into global McStas variables *******************************************************************************/ #pragma acc routine seq _class_particle mcsetstate(double x, double y, double z, double vx, double vy, double vz, double t, double sx, double sy, double sz, double p, int mcgravitation, int mcMagnet, int mcallowbackprop) { _class_particle mcneutron; mcneutron.x = x; mcneutron.y = y; mcneutron.z = z; mcneutron.vx = vx; mcneutron.vy = vy; mcneutron.vz = vz; mcneutron.t = t; mcneutron.sx = sx; mcneutron.sy = sy; mcneutron.sz = sz; mcneutron.p = p; mcneutron.mcgravitation = mcgravitation; mcneutron.mcMagnet = mcMagnet; mcneutron.allow_backprop = mcallowbackprop; mcneutron._uid = 0; mcneutron._index = 1; mcneutron._absorbed = 0; mcneutron._restore = 0; mcneutron._scattered = 0; return(mcneutron); } /* mcsetstate */ /******************************************************************************* * mcgetstate: get neutron parameters from particle structure *******************************************************************************/ #pragma acc routine seq _class_particle mcgetstate(_class_particle mcneutron, double *x, double *y, double *z, double *vx, double *vy, double *vz, double *t, double *sx, double *sy, double *sz, double *p) { *x = mcneutron.x; *y = mcneutron.y; *z = mcneutron.z; *vx = mcneutron.vx; *vy = mcneutron.vy; *vz = mcneutron.vz; *t = mcneutron.t; *sx = mcneutron.sx; *sy = mcneutron.sy; *sz = mcneutron.sz; *p = mcneutron.p; return(mcneutron); } /* mcgetstate */ /******************************************************************************* * mcgenstate: set default neutron parameters *******************************************************************************/ // Moved to generated code /* #pragma acc routine seq */ /* _class_particle mcgenstate(void) */ /* { */ /* return(mcsetstate(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, mcgravitation, mcMagnet, mcallowbackprop)); */ /* } */ /******************************************************************************* * mccoordschanges: old style rotation routine rot -> (x y z) ,(vx vy vz),(sx,sy,sz) *******************************************************************************/ void mccoordschanges(Coords a, Rotation t, double *x, double *y, double *z, double *vx, double *vy, double *vz, double *sx, double *sy, double *sz) { Coords b, c; b.x = *x; b.y = *y; b.z = *z; c = rot_apply(t, b); b = coords_add(c, a); *x = b.x; *y = b.y; *z = b.z; if ( (vz && vy && vx) && (*vz != 0.0 || *vx != 0.0 || *vy != 0.0) ) mccoordschange_polarisation(t, vx, vy, vz); if ( (sz && sy && sx) && (*sz != 0.0 || *sx != 0.0 || *sy != 0.0) ) mccoordschange_polarisation(t, sx, sy, sz); } /* intersection routines ==================================================== */ /******************************************************************************* * inside_rectangle: Check if (x,y) is inside rectangle (xwidth, yheight) * return 0 if outside and 1 if inside *******************************************************************************/ #pragma acc routine seq int inside_rectangle(double x, double y, double xwidth, double yheight) { if (x>-xwidth/2 && x-yheight/2 && y -dy/2 && y_in < dy/2 && z_in > -dz/2 && z_in < dz/2) t[0] = tt; else t[0] = 0; tt = (dx/2 - x)/vx; y_in = y + tt*vy; z_in = z + tt*vz; if( y_in > -dy/2 && y_in < dy/2 && z_in > -dz/2 && z_in < dz/2) t[1] = tt; else t[1] = 0; } else t[0] = t[1] = 0; if(vy != 0) { tt = -(dy/2 + y)/vy; x_in = x + tt*vx; z_in = z + tt*vz; if( x_in > -dx/2 && x_in < dx/2 && z_in > -dz/2 && z_in < dz/2) t[2] = tt; else t[2] = 0; tt = (dy/2 - y)/vy; x_in = x + tt*vx; z_in = z + tt*vz; if( x_in > -dx/2 && x_in < dx/2 && z_in > -dz/2 && z_in < dz/2) t[3] = tt; else t[3] = 0; } else t[2] = t[3] = 0; if(vz != 0) { tt = -(dz/2 + z)/vz; x_in = x + tt*vx; y_in = y + tt*vy; if( x_in > -dx/2 && x_in < dx/2 && y_in > -dy/2 && y_in < dy/2) t[4] = tt; else t[4] = 0; tt = (dz/2 - z)/vz; x_in = x + tt*vx; y_in = y + tt*vy; if( x_in > -dx/2 && x_in < dx/2 && y_in > -dy/2 && y_in < dy/2) t[5] = tt; else t[5] = 0; } else t[4] = t[5] = 0; /* The intersection is evaluated and *dt_in and *dt_out are assigned */ a = b = s = 0; count = 0; for( i = 0; i < 6; i = i + 1 ) if( t[i] == 0 ) s = s+1; else if( count == 0 ) { a = t[i]; count = 1; } else { b = t[i]; count = 2; } if ( a == 0 && b == 0 ) return 0; else if( a < b ) { *dt_in = a; *dt_out = b; return 1; } else { *dt_in = b; *dt_out = a; return 1; } } /* box_intersect */ /******************************************************************************* * cylinder_intersect: compute intersection with a cylinder * returns 0 when no intersection is found * or 2/4/8/16 bits depending on intersection, * and resulting times t0 and t1 * Written by: EM,NB,ABA 4.2.98 *******************************************************************************/ #pragma acc routine seq int cylinder_intersect(double *t0, double *t1, double x, double y, double z, double vx, double vy, double vz, double r, double h) { double D, t_in, t_out, y_in, y_out; int ret=1; D = (2*vx*x + 2*vz*z)*(2*vx*x + 2*vz*z) - 4*(vx*vx + vz*vz)*(x*x + z*z - r*r); if (D>=0) { if (vz*vz + vx*vx) { t_in = (-(2*vz*z + 2*vx*x) - sqrt(D))/(2*(vz*vz + vx*vx)); t_out = (-(2*vz*z + 2*vx*x) + sqrt(D))/(2*(vz*vz + vx*vx)); } else if (vy) { /* trajectory parallel to cylinder axis */ t_in = (-h/2-y)/vy; t_out = (h/2-y)/vy; if (t_in>t_out){ double tmp=t_in; t_in=t_out;t_out=tmp; } } else return 0; y_in = vy*t_in + y; y_out =vy*t_out + y; if ( (y_in > h/2 && y_out > h/2) || (y_in < -h/2 && y_out < -h/2) ) return 0; else { if (y_in > h/2) { t_in = ((h/2)-y)/vy; ret += 2; } else if (y_in < -h/2) { t_in = ((-h/2)-y)/vy; ret += 4; } if (y_out > h/2) { t_out = ((h/2)-y)/vy; ret += 8; } else if (y_out < -h/2) { t_out = ((-h/2)-y)/vy; ret += 16; } } *t0 = t_in; *t1 = t_out; return ret; } else { *t0 = *t1 = 0; return 0; } } /* cylinder_intersect */ /******************************************************************************* * sphere_intersect: Calculate intersection between a line and a sphere. * returns 0 when no intersection is found * or 1 in case of intersection with resulting times t0 and t1 *******************************************************************************/ #pragma acc routine seq int sphere_intersect(double *t0, double *t1, double x, double y, double z, double vx, double vy, double vz, double r) { double A, B, C, D, v; v = sqrt(vx*vx + vy*vy + vz*vz); A = v*v; B = 2*(x*vx + y*vy + z*vz); C = x*x + y*y + z*z - r*r; D = B*B - 4*A*C; if(D < 0) return 0; D = sqrt(D); *t0 = (-B - D) / (2*A); *t1 = (-B + D) / (2*A); return 1; } /* sphere_intersect */ /******************************************************************************* * plane_intersect: Calculate intersection between a plane and a line. * returns 0 when no intersection is found (i.e. line is parallel to the plane) * returns 1 or -1 when intersection time is positive and negative respectively *******************************************************************************/ #pragma acc routine seq int plane_intersect(double *t, double x, double y, double z, double vx, double vy, double vz, double nx, double ny, double nz, double wx, double wy, double wz) { double s; if (fabs(s=scalar_prod(nx,ny,nz,vx,vy,vz)) #include #include typedef struct struct_table { char filename[1024]; long filesize; char *header; /* text header, e.g. comments */ double *data; /* vector { x[0], y[0], ... x[n-1], y[n-1]... } */ double min_x; /* min value of first column */ double max_x; /* max value of first column */ double step_x; /* minimal step value of first column */ long rows; /* number of rows in matrix block */ long columns; /* number of columns in matrix block */ long begin; /* start fseek index of block */ long end; /* stop fseek index of block */ long block_number; /* block index. 0 is catenation of all */ long array_length; /* number of elements in the t_Table array */ char monotonic; /* true when 1st column/vector data is monotonic */ char constantstep; /* true when 1st column/vector data has constant step */ char method[32]; /* interpolation method: nearest, linear */ } t_Table; typedef struct t_Read_table_file_item { int ref_count; t_Table *table_ref; } t_Read_table_file_item; typedef enum enum_Read_table_file_actions {STORE,FIND,GC} t_Read_table_file_actions; /* read_table-lib function prototypes */ /* ========================================================================= */ /* 'public' functions */ long Table_Read (t_Table *Table, char *File, long block_number); long Table_Read_Offset (t_Table *Table, char *File, long block_number, long *offset, long max_lines); long Table_Read_Offset_Binary(t_Table *Table, char *File, char *Type, long *Offset, long Rows, long Columns); long Table_Rebin(t_Table *Table); /* rebin table with regular 1st column and interpolate all columns 2:end */ long Table_Info (t_Table Table); double Table_Index(t_Table Table, long i, long j); /* get indexed value */ double Table_Value(t_Table Table, double X, long j); /* search X in 1st column and return interpolated value in j-column */ t_Table *Table_Read_Array(char *File, long *blocks); void Table_Free_Array(t_Table *Table); long Table_Info_Array(t_Table *Table); int Table_SetElement(t_Table *Table, long i, long j, double value); long Table_Init(t_Table *Table, long rows, long columns); /* create a Table */ double Table_Value2d(t_Table Table, double X, double Y); /* same as Table_Index with non-integer indices and 2d interpolation */ MCDETECTOR Table_Write(t_Table Table, char*file, char*xl, char*yl, double x1, double x2, double y1, double y2); /* write Table to disk */ void * Table_File_List_Handler(t_Read_table_file_actions action, void *item, void *item_modifier); t_Table *Table_File_List_find(char *name, int block, int offset); int Table_File_List_gc(t_Table *tab); void Table_File_List_store(t_Table *tab); #define Table_ParseHeader(header, ...) \ Table_ParseHeader_backend(header,__VA_ARGS__,NULL); char **Table_ParseHeader_backend(char *header, ...); /* private functions */ void Table_Free(t_Table *Table); long Table_Read_Handle(t_Table *Table, FILE *fid, long block_number, long max_lines, char *name); static void Table_Stat(t_Table *Table); double Table_Interp1d(double x, double x1, double y1, double x2, double y2); double Table_Interp1d_nearest(double x, double x1, double y1, double x2, double y2); double Table_Interp2d(double x, double y, double x1, double y1, double x2, double y2, double z11, double z12, double z21, double z22); #endif /* end of read_table-lib.h */ /******************************************************************************* * * McStas, neutron ray-tracing package * Copyright (C) 1997-2009, All rights reserved * Risoe National Laboratory, Roskilde, Denmark * Institut Laue Langevin, Grenoble, France * * Library: share/read_table-lib.c * * %Identification * Written by: EF * Date: Aug 28, 2002 * Origin: ILL * Release: McStas CVS_090504 * Version: $Revision$ * * This file is to be imported by components that may read data from table files * It handles some shared functions. Embedded within instrument in runtime mode. * * Usage: within SHARE * %include "read_table-lib" * *******************************************************************************/ #ifndef READ_TABLE_LIB_H #include "read_table-lib.h" #endif /******************************************************************************* * void *Table_File_List_Handler(action, item, item_modifier) * ACTION: handle file entries in the read_table-lib file list. If a file is read - it is supposed to be * stored in a list such that we can avoid reading the same file many times. * input action: FIND, STORE, GC. check if file exists in the list, store an item in the list, or check if it can be garbage collected. * input item: depends on the action. * FIND) item is a filename, and item_modifier is the block number * STORE) item is the Table to store - item_modifier is ignored * GC) item is the Table to check. If it has a ref_count >1 then this is simply decremented. * return depends on the action * FIND) return a reference to a table+ref_count item if found - NULL otherwise. I.e. NULL means the file has not been read before and must be read again. * STORE) return NULL always * GC) return NULL if no garbage collection is needed, return an adress to the t_Table which should be garbage collected. 0x1 is returned if * the item is not found in the list *******************************************************************************/ void * Table_File_List_Handler(t_Read_table_file_actions action, void *item, void *item_modifier){ /* logic here is Read_Table should include a call to FIND. If found the return value should just be used as * if the table had been read from disk. If not found then read the table and STORE. * Table_Free should include a call to GC. If this returns non-NULL then we should proceed with freeing the memory * associated with the table item - otherwise only decrement the reference counter since there are more references * that may need it.*/ static t_Read_table_file_item read_table_file_list[1024]; static int read_table_file_count=0; t_Read_table_file_item *tr; switch(action){ case FIND: /*interpret data item as a filename, if it is found return a pointer to the table and increment refcount. * if not found return the item itself*/ tr=read_table_file_list; while ( tr->table_ref!=NULL ){ int i=*((int*) item_modifier); int j=*( ((int*) item_modifier)+1); if ( !strcmp(tr->table_ref->filename,(char *) item) && tr->table_ref->block_number==i && tr->table_ref->begin==j ){ tr->ref_count++; return (void *) tr; } tr++; } return NULL; case STORE: /*find an available slot and store references to table there*/ tr=&(read_table_file_list[read_table_file_count++]); tr->table_ref = ((t_Table *) item); tr->ref_count++; return NULL; case GC: /* Should this item be garbage collected (freed) - if so scratch the entry and return the address of the item - * else decrement ref_count and return NULL. * A non-NULL return expects the item to actually be freed afterwards.*/ tr=read_table_file_list; while ( tr->table_ref!=NULL ){ if ( tr->table_ref->data ==((t_Table *)item)->data && tr->table_ref->block_number == ((t_Table *)item)->block_number){ /*matching item found*/ if (tr->ref_count>1){ /*the item is found and no garbage collection needed*/ tr->ref_count--; return NULL; }else{ /* The item is found and the reference counter is 1. * This means we should garbage collect. Move remaining list items up one slot, * and return the table for garbage collection by caller*/ while (tr->table_ref!=NULL){ *tr=*(tr+1); tr++; } read_table_file_count--; return (t_Table *) item; } } tr++; } /* item not found, and so should be garbage collected. This could be the case if freeing a * Table that has been constructed from code - not read from file. Return 0x1 to flag it for * collection.*/ return (void *) 0x1 ; } } /* Access functions to the handler*/ /******************************************** * t_Table *Table_File_List_find(char *name, int block, int offset) * input name: filename to search for in the file list * input block: data block in the file as each file may contain more than 1 data block. * return a ref. to a table if it is found (you may use this pointer and skip reading the file), NULL otherwise (i.e. go ahead and read the file) *********************************************/ t_Table *Table_File_List_find(char *name, int block, int offset){ int vars[2]={block,offset}; t_Read_table_file_item *item = Table_File_List_Handler(FIND,name, vars); if (item == NULL){ return NULL; }else{ return item->table_ref; } } /******************************************** * int Table_File_List_gc(t_Table *tab) * input tab: the table to check for references. * return 0: no garbage collection needed * 1: Table's data and header (at least) should be freed. *********************************************/ int Table_File_List_gc(t_Table *tab){ void *rval=Table_File_List_Handler(GC,tab,0); if (rval==NULL) return 0; else return 1; } /***************************************************************************** * void *Table_File_List_store(t_Table *tab) * input tab: pointer to table to store. * return None. *******************************************************************************/ void Table_File_List_store(t_Table *tab){ Table_File_List_Handler(STORE,tab,0); } /******************************************************************************* * FILE *Open_File(char *name, char *Mode, char *path) * ACTION: search for a file and open it. Optionally return the opened path. * input name: file name from which table should be extracted * mode: "r", "w", "a" or any valid fopen mode * path: NULL or a pointer to at least 1024 allocated chars * return initialized file handle or NULL in case of error *******************************************************************************/ FILE *Open_File(char *File, const char *Mode, char *Path) { char path[1024]; FILE *hfile = NULL; if (!File || File[0]=='\0') return(NULL); if (!strcmp(File,"NULL") || !strcmp(File,"0")) return(NULL); /* search in current or full path */ strncpy(path, File, 1024); hfile = fopen(path, Mode); if(!hfile) { char dir[1024]; if (!hfile && instrument_source[0] != '\0' && strlen(instrument_source)) /* search in instrument source location */ { char *path_pos = NULL; /* extract path: searches for last file separator */ path_pos = strrchr(instrument_source, MC_PATHSEP_C); /* last PATHSEP */ if (path_pos) { long path_length = path_pos +1 - instrument_source; /* from start to path+sep */ if (path_length) { strncpy(dir, instrument_source, path_length); dir[path_length] = '\0'; snprintf(path, 1024, "%s%c%s", dir, MC_PATHSEP_C, File); hfile = fopen(path, Mode); } } } if (!hfile && instrument_exe[0] != '\0' && strlen(instrument_exe)) /* search in PWD instrument executable location */ { char *path_pos = NULL; /* extract path: searches for last file separator */ path_pos = strrchr(instrument_exe, MC_PATHSEP_C); /* last PATHSEP */ if (path_pos) { long path_length = path_pos +1 - instrument_exe; /* from start to path+sep */ if (path_length) { strncpy(dir, instrument_exe, path_length); dir[path_length] = '\0'; snprintf(path, 1024, "%s%c%s", dir, MC_PATHSEP_C, File); hfile = fopen(path, Mode); } } } if (!hfile) /* search in HOME or . */ { strcpy(dir, getenv("HOME") ? getenv("HOME") : "."); snprintf(path, 1024, "%s%c%s", dir, MC_PATHSEP_C, File); hfile = fopen(path, Mode); } if (!hfile) /* search in MCSTAS/data */ { strcpy(dir, getenv(FLAVOR_UPPER) ? getenv(FLAVOR_UPPER) : MCSTAS); snprintf(path, 1024, "%s%c%s%c%s", dir, MC_PATHSEP_C, "data", MC_PATHSEP_C, File); hfile = fopen(path, Mode); } if (!hfile) /* search in MVCSTAS/contrib */ { strcpy(dir, getenv(FLAVOR_UPPER) ? getenv(FLAVOR_UPPER) : MCSTAS); snprintf(path, 1024, "%s%c%s%c%s", dir, MC_PATHSEP_C, "contrib", MC_PATHSEP_C, File); hfile = fopen(path, Mode); } if(!hfile) { fprintf(stderr, "Error: Could not open input file '%s' (Open_File)\n", File); return (NULL); } } if (Path) strncpy(Path, path, 1024); return(hfile); } /* end Open_File */ /******************************************************************************* * long Read_Table(t_Table *Table, char *name, int block_number) * ACTION: read a single Table from a text file * input Table: pointer to a t_Table structure * name: file name from which table should be extracted * block_number: if the file does contain more than one * data block, then indicates which one to get (from index 1) * a 0 value means append/catenate all * return initialized single Table t_Table structure containing data, header, ... * number of read elements (-1: error, 0:header only) * The routine stores any line starting with '#', '%' and ';' into the header * File is opened, read and closed * Other lines are interpreted as numerical data, and stored. * Data block should be a rectangular matrix or vector. * Data block may be rebinned with Table_Rebin (also sort in ascending order) *******************************************************************************/ long Table_Read(t_Table *Table, char *File, long block_number) { /* reads all or a single data block from 'file' and returns a Table structure */ return(Table_Read_Offset(Table, File, block_number, NULL, 0)); } /* end Table_Read */ /******************************************************************************* * long Table_Read_Offset(t_Table *Table, char *name, int block_number, long *offset * long max_rows) * ACTION: read a single Table from a text file, starting at offset * Same as Table_Read(..) except: * input offset: pointer to an offset (*offset should be 0 at start) * max_rows: max number of data rows to read from file (0 means all) * return initialized single Table t_Table structure containing data, header, ... * number of read elements (-1: error, 0:header only) * updated *offset position (where end of reading occured) *******************************************************************************/ long Table_Read_Offset(t_Table *Table, char *File, long block_number, long *offset, long max_rows) { /* reads all/a data block in 'file' and returns a Table structure */ FILE *hfile; long nelements=0; long begin=0; long filesize=0; char name[1024]; char path[1024]; struct stat stfile; /*Need to be able to store the pointer*/ if (!Table) return(-1); //if (offset && *offset) snprintf(name, 1024, "%s@%li", File, *offset); //else strncpy(name, File, 1024); if(offset && *offset){ begin=*offset; } /* Check if the table has already been read from file. * If so just reuse the table, if not (this is flagged by returning NULL * set up a new table and read the data into it */ t_Table *tab_p= Table_File_List_find(name,block_number,begin); if ( tab_p!=NULL ){ /*table was found in the Table_File_List*/ // printf("Reusing input file '%s' (Table_Read_Offset)\n", name); *Table=*tab_p; return Table->rows*Table->columns; } /* open the file */ hfile = Open_File(File, "r", path); if (!hfile) return(-1); else { MPI_MASTER( printf("Opening input file '%s' (Table_Read_Offset)\n", path); ); } /* read file state */ stat(path,&stfile); filesize = stfile.st_size; if (offset && *offset) fseek(hfile, *offset, SEEK_SET); begin = ftell(hfile); Table_Init(Table, 0, 0); /* read file content and set the Table */ nelements = Table_Read_Handle(Table, hfile, block_number, max_rows, name); Table->begin = begin; Table->end = ftell(hfile); Table->filesize = (filesize>0 ? filesize : 0); Table_Stat(Table); Table_File_List_store(Table); if (offset) *offset=Table->end; fclose(hfile); return(nelements); } /* end Table_Read_Offset */ /******************************************************************************* * long Table_Read_Offset_Binary(t_Table *Table, char *File, char *type, * long *offset, long rows, long columns) * ACTION: read a single Table from a binary file, starting at offset * Same as Table_Read_Offset(..) except that it handles binary files. * input type: may be "float"/NULL or "double" * offset: pointer to an offset (*offset should be 0 at start) * rows : number of rows (0 means read all) * columns: number of columns * return initialized single Table t_Table structure containing data, header, ... * number of read elements (-1: error, 0:header only) * updated *offset position (where end of reading occured) *******************************************************************************/ long Table_Read_Offset_Binary(t_Table *Table, char *File, char *type, long *offset, long rows, long columns) { /* reads all/a data block in binary 'file' and returns a Table structure */ long nelements, sizeofelement; long filesize; FILE *hfile; char path[1024]; struct stat stfile; double *data; long i; long begin; if (!Table) return(-1); Table_Init(Table, 0, 0); /* open the file */ hfile = Open_File(File, "r", path); if (!hfile) return(-1); else { MPI_MASTER( printf("Opening input file '%s' (Table_Read, Binary)\n", path); ); } /* read file state */ stat(File,&stfile); filesize = stfile.st_size; Table->filesize=filesize; /* read file content */ if (type && !strcmp(type,"double")) sizeofelement = sizeof(double); else sizeofelement = sizeof(float); if (offset && *offset) fseek(hfile, *offset, SEEK_SET); begin = ftell(hfile); if (rows && filesize > sizeofelement*columns*rows) nelements = columns*rows; else nelements = (long)(filesize/sizeofelement); if (!nelements || filesize <= *offset) return(0); data = (double*)malloc(nelements*sizeofelement); if (!data) { fprintf(stderr,"Error: allocating %ld elements for %s file '%s'. Too big (Table_Read_Offset_Binary).\n", nelements, type, File); exit(-1); } nelements = fread(data, sizeofelement, nelements, hfile); if (!data || !nelements) { fprintf(stderr,"Error: reading %ld elements from %s file '%s' (Table_Read_Offset_Binary)\n", nelements, type, File); exit(-1); } Table->begin = begin; Table->end = ftell(hfile); if (offset) *offset=Table->end; fclose(hfile); data = (double*)realloc(data, (double)nelements*sizeofelement); /* copy file data into Table */ if (type && !strcmp(type,"double")) Table->data = data; else { float *s; double *dataf; s = (float*)data; dataf = (double*)malloc(sizeof(double)*nelements); for (i=0; idata = dataf; } strncpy(Table->filename, File, 1024); Table->rows = nelements/columns; Table->columns = columns; Table->array_length = 1; Table->block_number = 1; Table_Stat(Table); return(nelements); } /* end Table_Read_Offset_Binary */ /******************************************************************************* * long Table_Read_Handle(t_Table *Table, FILE *fid, int block_number, long max_rows, char *name) * ACTION: read a single Table from a text file handle (private) * input Table:pointer to a t_Table structure * fid: pointer to FILE handle * block_number: if the file does contain more than one * data block, then indicates which one to get (from index 1) * a 0 value means append/catenate all * max_rows: if non 0, only reads that number of lines * return initialized single Table t_Table structure containing data, header, ... * modified Table t_Table structure containing data, header, ... * number of read elements (-1: error, 0:header only) * The routine stores any line starting with '#', '%' and ';' into the header * Other lines are interpreted as numerical data, and stored. * Data block should be a rectangular matrix or vector. * Data block may be rebined with Table_Rebin (also sort in ascending order) *******************************************************************************/ long Table_Read_Handle(t_Table *Table, FILE *hfile, long block_number, long max_rows, char *name) { /* reads all/a data block from 'file' handle and returns a Table structure */ double *Data; char *Header = NULL; long malloc_size = CHAR_BUF_LENGTH; long malloc_size_h = 4096; long Rows = 0, Columns = 0; long count_in_array = 0; long count_in_header = 0; long block_Current_index = 0; char flag_End_row_loop = 0; if (!Table) return(-1); Table_Init(Table, 0, 0); if (name && name[0]!='\0') strncpy(Table->filename, name, 1024); if(!hfile) { fprintf(stderr, "Error: File handle is NULL (Table_Read_Handle).\n"); return (-1); } Header = (char*) calloc(malloc_size_h, sizeof(char)); Data = (double*)calloc(malloc_size, sizeof(double)); if ((Header == NULL) || (Data == NULL)) { fprintf(stderr, "Error: Could not allocate Table and Header (Table_Read_Handle).\n"); return (-1); } int flag_In_array = 0; do { /* while (!flag_End_row_loop) */ char line[1024*CHAR_BUF_LENGTH]; long back_pos=0; /* ftell start of line */ back_pos = ftell(hfile); if (fgets(line, 1024*CHAR_BUF_LENGTH, hfile) != NULL) { /* analyse line */ /* first skip blank and tabulation characters */ int i = strspn(line, " \t"); /* handle comments: stored in header */ if (NULL != strchr("#%;/", line[i])) { /* line is a comment */ count_in_header += strlen(line); if (count_in_header >= malloc_size_h) { /* if succeed and in array : add (and realloc if necessary) */ malloc_size_h = count_in_header+4096; Header = (char*)realloc(Header, malloc_size_h*sizeof(char)); } strncat(Header, line, 4096); flag_In_array=0; /* exit line and file if passed desired block */ if (block_number > 0 && block_number == block_Current_index) { flag_End_row_loop = 1; } /* Continue with next line */ continue; } /* get the number of columns splitting line with strtok */ char *lexeme; char flag_End_Line = 0; long block_Num_Columns = 0; const char seps[] = " ,;\t\n\r"; lexeme = strtok(line, seps); while (!flag_End_Line) { if ((lexeme != NULL) && (lexeme[0] != '\0')) { /* reading line: the token is not empty */ double X; int count=1; /* test if we have 'NaN','Inf' */ if (!strncasecmp(lexeme,"NaN",3)) X = 0; else if (!strncasecmp(lexeme,"Inf",3) || !strncasecmp(lexeme,"+Inf",4)) X = FLT_MAX; else if (!strncasecmp(lexeme,"-Inf",4)) X = -FLT_MAX; else count = sscanf(lexeme,"%lg",&X); if (count == 1) { /* reading line: the token is a number in the line */ if (!flag_In_array) { /* reading num: not already in a block: starts a new data block */ block_Current_index++; flag_In_array = 1; block_Num_Columns= 0; if (block_number > 0) { /* initialise a new data block */ Rows = 0; count_in_array = 0; } /* else append */ } /* reading num: all blocks or selected block */ if (flag_In_array && (block_number == 0 || block_number == block_Current_index)) { /* starting block: already the desired number of rows ? */ if (block_Num_Columns == 0 && max_rows > 0 && Rows >= max_rows) { flag_End_Line = 1; flag_End_row_loop = 1; flag_In_array = 0; /* reposition to begining of line (ignore line) */ fseek(hfile, back_pos, SEEK_SET); } else { /* store into data array */ if (count_in_array >= malloc_size) { /* realloc data buffer if necessary */ malloc_size = count_in_array*1.5; Data = (double*) realloc(Data, malloc_size*sizeof(double)); if (Data == NULL) { fprintf(stderr, "Error: Can not re-allocate memory %li (Table_Read_Handle).\n", malloc_size*sizeof(double)); return (-1); } } if (0 == block_Num_Columns) Rows++; Data[count_in_array] = X; count_in_array++; block_Num_Columns++; } } /* reading num: end if flag_In_array */ } /* end reading num: end if sscanf lexeme -> numerical */ else { /* reading line: the token is not numerical in that line. end block */ if (block_Current_index == block_number) { flag_End_Line = 1; flag_End_row_loop = 1; } else { flag_In_array = 0; flag_End_Line = 1; } } } else { /* no more tokens in line */ flag_End_Line = 1; if (block_Num_Columns > 0) Columns = block_Num_Columns; } // parse next token lexeme = strtok(NULL, seps); } /* while (!flag_End_Line) */ } /* end: if fgets */ else flag_End_row_loop = 1; /* else fgets : end of file */ } while (!flag_End_row_loop); /* end while flag_End_row_loop */ Table->block_number = block_number; Table->array_length = 1; // shrink header to actual size (plus terminating 0-byte) if (count_in_header) { Header = (char*)realloc(Header, count_in_header*sizeof(char) + 1); } Table->header = Header; if (count_in_array*Rows*Columns == 0) { Table->rows = 0; Table->columns = 0; free(Data); return (0); } if (Rows * Columns != count_in_array) { fprintf(stderr, "Warning: Read_Table :%s %s Data has %li values that should be %li x %li\n", (Table->filename[0] != '\0' ? Table->filename : ""), (!block_number ? " catenated" : ""), count_in_array, Rows, Columns); Columns = count_in_array; Rows = 1; } Data = (double*)realloc(Data, count_in_array*sizeof(double)); Table->data = Data; Table->rows = Rows; Table->columns = Columns; return (count_in_array); } /* end Table_Read_Handle */ /******************************************************************************* * long Table_Rebin(t_Table *Table) * ACTION: rebin a single Table, sorting 1st column in ascending order * input Table: single table containing data. * The data block is reallocated in this process * return updated Table with increasing, evenly spaced first column (index 0) * number of data elements (-1: error, 0:empty data) *******************************************************************************/ long Table_Rebin(t_Table *Table) { double new_step=0; long i; /* performs linear interpolation on X axis (0-th column) */ if (!Table) return(-1); if (!Table->data || Table->rows*Table->columns == 0 || !Table->step_x) return(0); Table_Stat(Table); /* recompute statitstics and minimal step */ new_step = Table->step_x; /* minimal step in 1st column */ if (!(Table->constantstep)) /* not already evenly spaced */ { long Length_Table; double *New_Table; Length_Table = ceil(fabs(Table->max_x - Table->min_x)/new_step)+1; New_Table = (double*)malloc(Length_Table*Table->columns*sizeof(double)); for (i=0; i < Length_Table; i++) { long j; double X; X = Table->min_x + i*new_step; New_Table[i*Table->columns] = X; for (j=1; j < Table->columns; j++) New_Table[i*Table->columns+j] = Table_Value(*Table, X, j); } /* end for i */ Table->rows = Length_Table; Table->step_x = new_step; Table->max_x = Table->min_x + (Length_Table-1)*new_step; /*max might not be the same anymore * Use Length_Table -1 since the first and laset rows are the limits of the defined interval.*/ free(Table->data); Table->data = New_Table; Table->constantstep=1; } /* end else (!constantstep) */ return (Table->rows*Table->columns); } /* end Table_Rebin */ /******************************************************************************* * double Table_Index(t_Table Table, long i, long j) * ACTION: read an element [i,j] of a single Table * input Table: table containing data * i : index of row (0:Rows-1) * j : index of column (0:Columns-1) * return Value = data[i][j] * Returns Value from the i-th row, j-th column of Table * Tests are performed on indexes i,j to avoid errors *******************************************************************************/ #ifndef MIN #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX #define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif #pragma acc routine seq double Table_Index(t_Table Table, long i, long j) { long AbsIndex; if (Table.rows == 1 || Table.columns == 1) { /* vector */ j = MIN(MAX(0, i+j), Table.columns*Table.rows - 1); i = 0; } else { /* matrix */ i = MIN(MAX(0, i), Table.rows - 1); j = MIN(MAX(0, j), Table.columns - 1); } /* handle vectors specifically */ AbsIndex = i*(Table.columns)+j; if (Table.data != NULL) return (Table.data[AbsIndex]); else return 0; } /* end Table_Index */ /******************************************************************************* * void Table_SetElement(t_Table *Table, long i, long j, double value) * ACTION: set an element [i,j] of a single Table * input Table: table containing data * i : index of row (0:Rows-1) * j : index of column (0:Columns-1) * value = data[i][j] * Returns 0 in case of error * Tests are performed on indexes i,j to avoid errors *******************************************************************************/ int Table_SetElement(t_Table *Table, long i, long j, double value) { long AbsIndex; if (Table->rows == 1 || Table->columns == 1) { /* vector */ j = MIN(MAX(0, i+j), Table->columns*Table->rows - 1); i=0; } else { /* matrix */ i = MIN(MAX(0, i), Table->rows - 1); j = MIN(MAX(0, j), Table->columns - 1); } AbsIndex = i*(Table->columns)+j; if (Table->data != NULL) { Table->data[AbsIndex] = value; return 1; } return 0; } /* end Table_SetElement */ /******************************************************************************* * double Table_Value(t_Table Table, double X, long j) * ACTION: read column [j] of a single Table at row which 1st column is X * input Table: table containing data. * X : data value in the first column (index 0) * j : index of column from which is extracted the Value (0:Columns-1) * return Value = data[index for X][j] with linear interpolation * Returns Value from the j-th column of Table corresponding to the * X value for the 1st column (index 0) * Tests are performed (within Table_Index) on indexes i,j to avoid errors * NOTE: data should rather be monotonic, and evenly sampled. *******************************************************************************/ #pragma acc routine seq double Table_Value(t_Table Table, double X, long j) { long Index = -1; double X1=0, Y1=0, X2=0, Y2=0; double ret=0; if (X > Table.max_x) return Table_Index(Table,Table.rows-1 ,j); if (X < Table.min_x) return Table_Index(Table,0 ,j); // Use constant-time lookup when possible if(Table.constantstep) { Index = (long)floor( (X - Table.min_x) / (Table.max_x - Table.min_x) * (Table.rows-1)); X1 = Table_Index(Table,Index ,0); X2 = Table_Index(Table,Index+1,0); } // Use binary search on large, monotonic tables else if(Table.monotonic && Table.rows > 100) { long left = Table.min_x; long right = Table.max_x; while (!((X1 <= X) && (X < X2)) && (right - left > 1)) { Index = (left + right) / 2; X1 = Table_Index(Table, Index-1, 0); X2 = Table_Index(Table, Index, 0); if (X < X1) { right = Index; } else { left = Index; } } } // Fall back to linear search, if no-one else has set X1, X2 correctly if (!((X1 <= X) && (X < X2))) { /* look for index surrounding X in the table -> Index */ for (Index=1; Index <= Table.rows-1; Index++) { X1 = Table_Index(Table, Index-1,0); X2 = Table_Index(Table, Index ,0); if ((X1 <= X) && (X < X2)) break; } /* end for Index */ } Y1 = Table_Index(Table,Index, j); Y2 = Table_Index(Table,Index+1, j); #ifdef OPENACC #define strcmp(a,b) str_comp(a,b) #endif if (!strcmp(Table.method,"linear")) { ret = Table_Interp1d(X, X1,Y1, X2,Y2); } else if (!strcmp(Table.method,"nearest")) { ret = Table_Interp1d_nearest(X, X1,Y1, X2,Y2); } #ifdef OPENACC #ifdef strcmp #undef strcmp #endif #endif return ret; } /* end Table_Value */ /******************************************************************************* * double Table_Value2d(t_Table Table, double X, double Y) * ACTION: read element [X,Y] of a matrix Table * input Table: table containing data. * X : row index, may be non integer * Y : column index, may be non integer * return Value = data[index X][index Y] with bi-linear interpolation * Returns Value for the indices [X,Y] * Tests are performed (within Table_Index) on indexes i,j to avoid errors * NOTE: data should rather be monotonic, and evenly sampled. *******************************************************************************/ #pragma acc routine seq double Table_Value2d(t_Table Table, double X, double Y) { long x1,x2,y1,y2; double z11,z12,z21,z22; double ret=0; x1 = (long)floor(X); y1 = (long)floor(Y); if (x1 > Table.rows-1 || x1 < 0) { x2 = x1; } else { x2 = x1 + 1; } if (y1 > Table.columns-1 || y1 < 0) { y2 = y1; } else { y2 = y1 + 1; } z11 = Table_Index(Table, x1, y1); if (y2 != y1) z12=Table_Index(Table, x1, y2); else z12 = z11; if (x2 != x1) z21=Table_Index(Table, x2, y1); else z21 = z11; if (y2 != y1) z22=Table_Index(Table, x2, y2); else z22 = z21; #ifdef OPENACC #define strcmp(a,b) str_comp(a,b) #endif if (!strcmp(Table.method,"linear")) ret = Table_Interp2d(X,Y, x1,y1,x2,y2, z11,z12,z21,z22); #ifdef OPENACC #ifdef strcmp #undef strcmp #endif #endif else { if (fabs(X-x1) < fabs(X-x2)) { if (fabs(Y-y1) < fabs(Y-y2)) ret = z11; else ret = z12; } else { if (fabs(Y-y1) < fabs(Y-y2)) ret = z21; else ret = z22; } } return ret; } /* end Table_Value2d */ /******************************************************************************* * void Table_Free(t_Table *Table) * ACTION: free a single Table. First Call Table_File_list_gc. If this returns * non-zero it means there are more refernces to the table, and so the table * should not bee freed. * return: empty Table *******************************************************************************/ void Table_Free(t_Table *Table) { if( !Table_File_List_gc(Table) ){ return; } if (!Table) return; if (Table->data != NULL) free(Table->data); if (Table->header != NULL) free(Table->header); Table->data = NULL; Table->header = NULL; } /* end Table_Free */ /****************************************************************************** * void Table_Info(t_Table Table) * ACTION: print informations about a single Table *******************************************************************************/ long Table_Info(t_Table Table) { char buffer[256]; long ret=0; if (!Table.block_number) strcpy(buffer, "catenated"); else sprintf(buffer, "block %li", Table.block_number); printf("Table from file '%s' (%s)", Table.filename[0] != '\0' ? Table.filename : "", buffer); if ((Table.data != NULL) && (Table.rows*Table.columns)) { printf(" is %li x %li ", Table.rows, Table.columns); if (Table.rows*Table.columns > 1) printf("(x=%g:%g)", Table.min_x, Table.max_x); else printf("(x=%g) ", Table.min_x); ret = Table.rows*Table.columns; if (Table.monotonic) printf(", monotonic"); if (Table.constantstep) printf(", constant step"); printf(". interpolation: %s\n", Table.method); } else printf(" is empty.\n"); if (Table.header && strlen(Table.header)) { char *header; int i; header = malloc(80); if (!header) return(ret); for (i=0; i<80; header[i++]=0); strncpy(header, Table.header, 75); if (strlen(Table.header) > 75) { strcat( header, " ..."); } for (i=0; iheader = NULL; Table->filename[0]= '\0'; Table->filesize= 0; Table->min_x = 0; Table->max_x = 0; Table->step_x = 0; Table->block_number = 0; Table->array_length = 0; Table->monotonic = 0; Table->constantstep = 0; Table->begin = 0; Table->end = 0; strcpy(Table->method,"linear"); if (rows*columns >= 1) { data = (double*)malloc(rows*columns*sizeof(double)); if (data) for (i=0; i < rows*columns; data[i++]=0); else { fprintf(stderr,"Error: allocating %ld double elements." "Too big (Table_Init).\n", rows*columns); rows = columns = 0; } } Table->rows = (rows >= 1 ? rows : 0); Table->columns = (columns >= 1 ? columns : 0); Table->data = data; return(Table->rows*Table->columns); } /* end Table_Init */ /****************************************************************************** * long Table_Write(t_Table Table, char *file, x1,x2, y1,y2) * ACTION: write a Table to disk (ascii). * when x1=x2=0 or y1=y2=0, the table default limits are used. * return: 0=all is fine, non-0: error *******************************************************************************/ MCDETECTOR Table_Write(t_Table Table, char *file, char *xl, char *yl, double x1, double x2, double y1, double y2) { long i =0; MCDETECTOR detector; if ((Table.data == NULL) && (Table.rows*Table.columns)) { detector.m = 0; return(detector); /* Table is empty - nothing to do */ } if (!x1 && !x2) { x1 = Table.min_x; x2 = Table.max_x; } if (!y1 && !y2) { y1 = 1; y2 = Table.columns; } /* transfer content of the Table into a 2D detector */ Coords coords = { 0, 0, 0}; if (Table.rows == 1 || Table.columns == 1) { detector = mcdetector_out_1D(Table.filename, xl ? xl : "", yl ? yl : "", "x", x1, x2, Table.rows * Table.columns, NULL, Table.data, NULL, file, file, coords); } else { detector = mcdetector_out_2D(Table.filename, xl ? xl : "", yl ? yl : "", x1, x2, y1, y2, Table.rows, Table.columns, NULL, Table.data, NULL, file, file, coords); } return(detector); } /****************************************************************************** * void Table_Stat(t_Table *Table) * ACTION: computes min/max/mean step of 1st column for a single table (private) * return: updated Table *******************************************************************************/ static void Table_Stat(t_Table *Table) { long i; double max_x, min_x; double row=1; char monotonic=1; char constantstep=1; double step=0; long n; if (!Table) return; if (!Table->rows || !Table->columns) return; if (Table->rows == 1) row=0; // single row max_x = -FLT_MAX; min_x = FLT_MAX; n = (row ? Table->rows : Table->columns); /* get min and max of first column/vector */ for (i=0; i < n; i++) { double X; X = (row ? Table_Index(*Table,i ,0) : Table_Index(*Table,0, i)); if (X < min_x) min_x = X; if (X > max_x) max_x = X; } /* for */ /* test for monotonicity and constant step if the table is an XY or single vector */ if (n > 1) { /* mean step */ step = (max_x - min_x)/(n-1); /* now test if table is monotonic on first column, and get minimal step size */ for (i=0; i < n-1; i++) { double X, diff;; X = (row ? Table_Index(*Table,i ,0) : Table_Index(*Table,0, i)); diff = (row ? Table_Index(*Table,i+1,0) : Table_Index(*Table,0, i+1)) - X; if (diff && fabs(diff) < fabs(step)) step = diff; /* change sign ? */ if ((max_x - min_x)*diff < 0 && monotonic) monotonic = 0; } /* end for */ /* now test if steps are constant within READ_TABLE_STEPTOL */ if(!step){ /*means there's a disconitnuity -> not constantstep*/ constantstep=0; }else if (monotonic) { for (i=0; i < n-1; i++) { double X, diff; X = (row ? Table_Index(*Table,i ,0) : Table_Index(*Table,0, i)); diff = (row ? Table_Index(*Table,i+1,0) : Table_Index(*Table,0, i+1)) - X; if ( fabs(step)*(1+READ_TABLE_STEPTOL) < fabs(diff) || fabs(diff) < fabs(step)*(1-READ_TABLE_STEPTOL) ) { constantstep = 0; break; } } } } Table->step_x= step; Table->max_x = max_x; Table->min_x = min_x; Table->monotonic = monotonic; Table->constantstep = constantstep; } /* end Table_Stat */ /****************************************************************************** * t_Table *Table_Read_Array(char *File, long *blocks) * ACTION: read as many data blocks as available, iteratively from file * return: initialized t_Table array, last element is an empty Table. * the number of extracted blocks in non NULL pointer *blocks *******************************************************************************/ t_Table *Table_Read_Array(char *File, long *blocks) { t_Table *Table_Array=NULL; long offset=0; long block_number=0; long allocated=256; long nelements=1; /* first allocate an initial empty t_Table array */ Table_Array = (t_Table *)malloc(allocated*sizeof(t_Table)); if (!Table_Array) { fprintf(stderr, "Error: Can not allocate memory %li (Table_Read_Array).\n", allocated*sizeof(t_Table)); *blocks = 0; return (NULL); } while (nelements > 0) { t_Table Table; /* if ok, set t_Table block number else exit loop */ block_number++; Table.block_number = block_number; /* access file at offset and get following block. Block number is from the set offset * hence the hardcoded 1 - i.e. the next block counted from offset.*/ nelements = Table_Read_Offset(&Table, File, 1, &offset,0); /*if the block is empty - don't store it*/ if (nelements>0){ /* if t_Table array is not long enough, expand and realocate */ if (block_number >= allocated-1) { allocated += 256; Table_Array = (t_Table *)realloc(Table_Array, allocated*sizeof(t_Table)); if (!Table_Array) { fprintf(stderr, "Error: Can not re-allocate memory %li (Table_Read_Array).\n", allocated*sizeof(t_Table)); *blocks = 0; return (NULL); } } /* store it into t_Table array */ //snprintf(Table.filename, 1024, "%s#%li", File, block_number-1); Table_Array[block_number-1] = Table; } /* continues until we find an empty block */ } /* send back number of extracted blocks */ if (blocks) *blocks = block_number-1; /* now store total number of elements in Table array */ for (offset=0; offset < block_number; Table_Array[offset++].array_length = block_number-1); return(Table_Array); } /* end Table_Read_Array */ /******************************************************************************* * void Table_Free_Array(t_Table *Table) * ACTION: free a Table array *******************************************************************************/ void Table_Free_Array(t_Table *Table) { long index; if (!Table) return; for (index=0;index < Table[0].array_length; index++){ Table_Free(&Table[index]); } free(Table); } /* end Table_Free_Array */ /****************************************************************************** * long Table_Info_Array(t_Table *Table) * ACTION: print informations about a Table array * return: number of elements in the Table array *******************************************************************************/ long Table_Info_Array(t_Table *Table) { long index=0; if (!Table) return(-1); while (index < Table[index].array_length && (Table[index].data || Table[index].header) && (Table[index].rows*Table[index].columns) ) { Table_Info(Table[index]); index++; } printf("This Table array contains %li elements\n", index); return(index); } /* end Table_Info_Array */ /****************************************************************************** * char **Table_ParseHeader(char *header, symbol1, symbol2, ..., NULL) * ACTION: search for char* symbols in header and return their value or NULL * the search is not case sensitive. * Last argument MUST be NULL * return: array of char* with line following each symbol, or NULL if not found *******************************************************************************/ #ifndef MyNL_ARGMAX #define MyNL_ARGMAX 50 #endif char **Table_ParseHeader_backend(char *header, ...){ va_list ap; char exit_flag=0; int counter =0; char **ret =NULL; if (!header || header[0]=='\0') return(NULL); ret = (char**)calloc(MyNL_ARGMAX, sizeof(char*)); if (!ret) { printf("Table_ParseHeader: Cannot allocate %i values array for Parser (Table_ParseHeader).\n", MyNL_ARGMAX); return(NULL); } for (counter=0; counter < MyNL_ARGMAX; ret[counter++] = NULL); counter=0; va_start(ap, header); while(!exit_flag && counter < MyNL_ARGMAX-1) { char *arg_char=NULL; char *pos =NULL; /* get variable argument value as a char */ arg_char = va_arg(ap, char *); if (!arg_char || arg_char[0]=='\0'){ exit_flag = 1; break; } /* search for the symbol in the header */ pos = (char*)strcasestr(header, arg_char); if (pos) { char *eol_pos; eol_pos = strchr(pos+strlen(arg_char), '\n'); if (!eol_pos) eol_pos = strchr(pos+strlen(arg_char), '\r'); if (!eol_pos) eol_pos = pos+strlen(pos)-1; ret[counter] = (char*)malloc(eol_pos - pos); if (!ret[counter]) { printf("Table_ParseHeader: Cannot allocate value[%i] array for Parser searching for %s (Table_ParseHeader).\n", counter, arg_char); exit_flag = 1; break; } strncpy(ret[counter], pos+strlen(arg_char), eol_pos - pos - strlen(arg_char)); ret[counter][eol_pos - pos - strlen(arg_char)]='\0'; } counter++; } va_end(ap); return(ret); } /* Table_ParseHeader */ /****************************************************************************** * double Table_Interp1d(x, x1, y1, x2, y2) * ACTION: interpolates linearly at x between y1=f(x1) and y2=f(x2) * return: y=f(x) value *******************************************************************************/ #pragma acc routine seq double Table_Interp1d(double x, double x1, double y1, double x2, double y2) { double slope; if (x2 == x1) return (y1+y2)/2; if (y1 == y2) return y1; slope = (y2 - y1)/(x2 - x1); return y1+slope*(x - x1); } /* Table_Interp1d */ /****************************************************************************** * double Table_Interp1d_nearest(x, x1, y1, x2, y2) * ACTION: table lookup with nearest method at x between y1=f(x1) and y2=f(x2) * return: y=f(x) value *******************************************************************************/ #pragma acc routine seq double Table_Interp1d_nearest(double x, double x1, double y1, double x2, double y2) { if (fabs(x-x1) < fabs(x-x2)) return (y1); else return(y2); } /* Table_Interp1d_nearest */ /****************************************************************************** * double Table_Interp2d(x,y, x1,y1, x2,y2, z11,z12,z21,z22) * ACTION: interpolates bi-linearly at (x,y) between z1=f(x1,y1) and z2=f(x2,y2) * return: z=f(x,y) value * x,y | x1 x2 * ---------------- * y1 | z11 z21 * y2 | z12 z22 *******************************************************************************/ #pragma acc routine seq double Table_Interp2d(double x, double y, double x1, double y1, double x2, double y2, double z11, double z12, double z21, double z22) { double ratio_x, ratio_y; if (x2 == x1) return Table_Interp1d(y, y1,z11, y2,z12); if (y1 == y2) return Table_Interp1d(x, x1,z11, x2,z21); ratio_y = (y - y1)/(y2 - y1); ratio_x = (x - x1)/(x2 - x1); return (1-ratio_x)*(1-ratio_y)*z11 + ratio_x*(1-ratio_y)*z21 + ratio_x*ratio_y*z22 + (1-ratio_x)*ratio_y*z12; } /* Table_Interp2d */ /* end of read_table-lib.c */ #ifndef SOURCE_GEN_DEF #define SOURCE_GEN_DEF /******************************************************************************* * str_dup_numeric: replaces non 'valid name' chars with spaces *******************************************************************************/ char *str_dup_numeric(char *orig) { long i; if (!orig || !strlen(orig)) return(NULL); for (i=0; i < strlen(orig); i++) { if ( (orig[i] > 122) || (orig[i] < 32) || (strchr("!\"#$%&'()*,:;<=>?@[\\]^`/ ", orig[i]) != NULL) ) { orig[i] = ' '; } } orig[i] = '\0'; /* now skip spaces */ for (i=0; i < strlen(orig); i++) { if (*orig == ' ') orig++; else break; } return(orig); } /* str_dup_numeric */ /* A normalised Maxwellian distribution : Integral over all l = 1 */ #pragma acc routine seq double SG_Maxwell(double l, double temp) { double a=949.0/temp; return 2*a*a*exp(-a/(l*l))/(l*l*l*l*l); } #endif /* Shared user declarations for all components types 'Guide_gravity'. */ /***************************************************************************** * * McStas, neutron ray-tracing package * Copyright 1997-2006, All rights reserved * Risoe National Laboratory, Roskilde, Denmark * Institut Laue Langevin, Grenoble, France * * Library: share/ref-lib.h * * %Identification * Written by: Peter Christiansen * Date: August, 2006 * Origin: RISOE * Release: McStas 1.10 * Version: $Revision$ * * Commonly used reflection functions are declared in this file which * are used by some guide and mirror components. * * Depends on read_table-lib * * Usage: within SHARE * %include "ref-lib" * ****************************************************************************/ #ifndef REF_LIB_H #define REF_LIB_H "$Revision$" void StdReflecFunc(double, double*, double*); void TableReflecFunc(double, t_Table*, double*); #endif /* end of ref-lib.h */ /**************************************************************************** * * McStas, neutron ray-tracing package * Copyright 1997-2006, All rights reserved * Risoe National Laboratory, Roskilde, Denmark * Institut Laue Langevin, Grenoble, France * * Library: share/ref-lib.c * * %Identification * Written by: Peter Christiansen * Date: August, 2006 * Origin: RISOE * Release: McStas 1.10 * Version: $Revision$ * * Commonly used reflection functions are declared in this file which * are used by some guide and mirror components. * * Variable names have prefix 'mc_ref_' for 'McStas Reflection' * to avoid conflicts * * Usage: within SHARE * %include "ref-lib" * ****************************************************************************/ #ifndef REF_LIB_H #include "ref-lib.h" #endif #ifndef READ_TABLE_LIB_H #include "read_table-lib.h" #include "read_table-lib.c" #endif /**************************************************************************** * void StdReflecFunc(double q, double *par, double *r) * * The McStas standard analytic parametrization of the reflectivity. * The parameters are: * R0: [1] Low-angle reflectivity * Qc: [AA-1] Critical scattering vector * alpha: [AA] Slope of reflectivity * m: [1] m-value of material. Zero means completely absorbing. * W: [AA-1] Width of supermirror cut-off *****************************************************************************/ #pragma acc routine seq void StdReflecFunc(double mc_pol_q, double *mc_pol_par, double *mc_pol_r) { double R0 = mc_pol_par[0]; double Qc = mc_pol_par[1]; double alpha = mc_pol_par[2]; double m = mc_pol_par[3]; double W = mc_pol_par[4]; double beta = 0; mc_pol_q = fabs(mc_pol_q); double arg; /* Simpler parametrization from Henrik Jacobsen uses these values that depend on m only. double m_value=m*0.9853+0.1978; double W=-0.0002*m_value+0.0022; double alpha=0.2304*m_value+5.0944; double beta=-7.6251*m_value+68.1137; If W and alpha are set to 0, use Henrik's approach for estimating these parameters and apply the formulation: arg = R0*0.5*(1-tanh(arg))*(1-alpha*(q-Qc)+beta*(q-Qc)*(q-Qc)); */ if (W==0 && alpha==0) { m=m*0.9853+0.1978; W=-0.0002*m+0.0022; alpha=0.2304*m+5.0944; beta=-7.6251*m+68.1137; if (m<=3) { alpha=m; beta=0; } } arg = W > 0 ? (mc_pol_q - m*Qc)/W : 11; if (arg > 10 || m <= 0 || Qc <=0 || R0 <= 0) { *mc_pol_r = 0; return; } if (m < 1) { Qc *= m; m=1; } if(mc_pol_q <= Qc) { *mc_pol_r = R0; return; } *mc_pol_r = R0*0.5*(1 - tanh(arg))*(1 - alpha*(mc_pol_q - Qc) + beta*(mc_pol_q - Qc)*(mc_pol_q - Qc)); return; } /**************************************************************************** * void TableReflecFunc(double q, t_Table *par, double *r) { * * Looks up the reflectivity in a table using the routines in read_table-lib. *****************************************************************************/ #pragma acc routine seq void TableReflecFunc(double mc_pol_q, t_Table *mc_pol_par, double *mc_pol_r) { *mc_pol_r = Table_Value(*mc_pol_par, mc_pol_q, 1); if(*mc_pol_r>1) *mc_pol_r = 1; return; } /* end of ref-lib.c */ #ifndef Gravity_guide_Version #define Gravity_guide_Version "$Revision$" #ifndef PROP_GRAV_DT #error McStas : You need PROP_GRAV_DT (McStas >= 1.4.3) to run this component #endif /* * G: (m/s^2) Gravitation acceleration along y axis [-9.81] * Gx: (m/s^2) Gravitation acceleration along x axis [0] * Gy: (m/s^2) Gravitation acceleration along y axis [-9.81] * Gz: (m/s^2) Gravitation acceleration along z axis [0] * mh: (1) m-value of material for left/right vert. mirrors * mv: (1) m-value of material for top/bottom horz. mirrors * mx: (1) m-value of material for left/right vert. mirrors * my: (1) m-value of material for top/bottom horz. mirrors */ typedef struct Gravity_guide_Vars { double gx; double gy; double gz; double nx[6], ny[6], nz[6]; double wx[6], wy[6], wz[6]; double A[6], norm_n2[6], norm_n[6]; long N_reflection[7]; double w1c, h1c; double w2c, h2c; double M[5]; double Alpha[5]; double nzC[5], norm_n2xy[5], Axy[5]; double wav_lr, wav_tb, wav_z; double chamfer_z, chamfer_lr, chamfer_tb; char compcurname[256]; double fc_freq, fc_phase; double warnings; } Gravity_guide_Vars_type; void Gravity_guide_Init(Gravity_guide_Vars_type *aVars, MCNUM a_w1, MCNUM a_h1, MCNUM a_w2, MCNUM a_h2, MCNUM a_l, MCNUM a_R0, MCNUM a_Qc, MCNUM a_alpha, MCNUM a_m, MCNUM a_W, MCNUM a_nslit, MCNUM a_d, MCNUM a_Gx, MCNUM a_Gy, MCNUM a_Gz, MCNUM a_mleft, MCNUM a_mright, MCNUM a_mtop, MCNUM a_mbottom, MCNUM a_nhslit, MCNUM a_wavy_lr, MCNUM a_wavy_tb, MCNUM a_wavy_z, MCNUM a_wavy, MCNUM a_chamfers_z, MCNUM a_chamfers_lr, MCNUM a_chamfers_tb, MCNUM a_chamfers, MCNUM a_nu, MCNUM a_phase, MCNUM a_aleft, MCNUM a_aright, MCNUM a_atop, MCNUM a_abottom) { int i; for (i=0; i<7; aVars->N_reflection[i++] = 0); for (i=0; i<5; aVars->M[i++] = 0); for (i=0; i<5; aVars->Alpha[i++] = 0); aVars->gx = a_Gx; /* The gravitation vector in the current component axis system */ aVars->gy = a_Gy; aVars->gz = a_Gz; aVars->warnings=0; if (a_nslit <= 0 || a_nhslit <= 0) { fprintf(stderr,"%s: Fatal: no channel in this guide (nhslit or nslit=0).\n", aVars->compcurname); exit(-1); } if (a_d < 0) { fprintf(stderr,"%s: Fatal: subdividing walls have negative thickness in this guide (d<0).\n", aVars->compcurname); exit(-1); } aVars->w1c = (a_w1 - (a_nslit-1) *a_d)/(double)a_nslit; aVars->w2c = (a_w2 - (a_nslit-1) *a_d)/(double)a_nslit; aVars->h1c = (a_h1 - (a_nhslit-1)*a_d)/(double)a_nhslit; aVars->h2c = (a_h2 - (a_nhslit-1)*a_d)/(double)a_nhslit; for (i=0; i <= 4; aVars->M[i++]=a_m); for (i=0; i <= 4; aVars->Alpha[i++]=a_alpha); if (a_mleft >= 0) aVars->M[1] =a_mleft ; if (a_mright >= 0) aVars->M[2] =a_mright ; if (a_mtop >= 0) aVars->M[3] =a_mtop ; if (a_mbottom >= 0) aVars->M[4] =a_mbottom; if (a_aleft >= 0) aVars->Alpha[1] =a_aleft ; if (a_aright >= 0) aVars->Alpha[2] =a_aright ; if (a_atop >= 0) aVars->Alpha[3] =a_atop ; if (a_abottom >= 0) aVars->Alpha[4] =a_abottom; /* n: normal vectors to surfaces */ aVars->nx[1] = a_l; aVars->ny[1] = 0; aVars->nz[1] = 0.5*(aVars->w2c-aVars->w1c); /* 1:+X left */ aVars->nx[2] = -a_l; aVars->ny[2] = 0; aVars->nz[2] = -aVars->nz[1]; /* 2:-X right */ aVars->nx[3] = 0; aVars->ny[3] = a_l; aVars->nz[3] = 0.5*(aVars->h2c-aVars->h1c); /* 3:+Y top */ aVars->nx[4] = 0; aVars->ny[4] = -a_l; aVars->nz[4] = -aVars->nz[3]; /* 4:-Y bottom */ aVars->nx[5] = 0; aVars->ny[5] = 0; aVars->nz[5] = a_l; /* 5:+Z exit */ aVars->nx[0] = 0; aVars->ny[0] = 0; aVars->nz[0] = -a_l; /* 0:Z0 input */ /* w: a point on these surfaces */ aVars->wx[1] = +(aVars->w1c)/2; aVars->wy[1] = 0; aVars->wz[1] = 0; /* 1:+X left */ aVars->wx[2] = -(aVars->w1c)/2; aVars->wy[2] = 0; aVars->wz[2] = 0; /* 2:-X right */ aVars->wx[3] = 0; aVars->wy[3] = +(aVars->h1c)/2; aVars->wz[3] = 0; /* 3:+Y top */ aVars->wx[4] = 0; aVars->wy[4] = -(aVars->h1c)/2; aVars->wz[4] = 0; /* 4:-Y bottom */ aVars->wx[5] = 0; aVars->wy[5] = 0; aVars->wz[5] = a_l; /* 5:+Z exit */ aVars->wx[0] = 0; aVars->wy[0] = 0; aVars->wz[0] = 0; /* 0:Z0 input */ for (i=0; i <= 5; i++) { aVars->A[i] = scalar_prod(aVars->nx[i], aVars->ny[i], aVars->nz[i], aVars->gx, aVars->gy, aVars->gz)/2; aVars->norm_n2[i] = aVars->nx[i]*aVars->nx[i] + aVars->ny[i]*aVars->ny[i] + aVars->nz[i]*aVars->nz[i]; if (aVars->norm_n2[i] <= 0) { fprintf(stderr,"%s: Fatal: normal vector norm %i is null/negative ! check guide dimensions.\n", aVars->compcurname, i); exit(-1); } /* should never occur */ else aVars->norm_n[i] = sqrt(aVars->norm_n2[i]); } /* partial computations for l/r/t/b sides, to save computing time */ for (i=1; i <= 4; i++) { /* stores nz that changes in case non box element (focus/defocus) */ aVars->nzC[i] = aVars->nz[i]; /* partial xy terms */ aVars->norm_n2xy[i]= aVars->nx[i]*aVars->nx[i] + aVars->ny[i]*aVars->ny[i]; aVars->Axy[i] = (aVars->nx[i]*aVars->gx + aVars->ny[i]*aVars->gy)/2; } /* handle waviness init */ if (a_wavy && (!a_wavy_tb && !a_wavy_lr && !a_wavy_z)) { aVars->wav_tb=aVars->wav_lr=aVars->wav_z=a_wavy; } else { aVars->wav_tb=a_wavy_tb; aVars->wav_lr=a_wavy_lr; aVars->wav_z=a_wavy_z; } aVars->wav_tb *= DEG2RAD/(sqrt(8*log(2))); /* Convert from deg FWHM to rad Gaussian sigma */ aVars->wav_lr *= DEG2RAD/(sqrt(8*log(2))); aVars->wav_z *= DEG2RAD/(sqrt(8*log(2))); /* handle chamfers init */ if (a_chamfers && (!a_chamfers_z && !a_chamfers_lr && !a_chamfers_tb)) { aVars->chamfer_z=aVars->chamfer_lr=aVars->chamfer_tb=a_chamfers; } else { aVars->chamfer_z=a_chamfers_z; aVars->chamfer_lr=a_chamfers_lr; aVars->chamfer_tb=a_chamfers_tb; } aVars->fc_freq = a_nu; aVars->fc_phase = a_phase; } #pragma acc routine seq int Gravity_guide_Trace(double *dt, Gravity_guide_Vars_type *aVars, double cx, double cy, double cz, double cvx, double cvy, double cvz, double cxnum, double cxk, double cynum, double cyk, double *cnx, double *cny, double *cnz, _class_particle* _particle) { double B, C; int ret=0; int side=0; double n1; double dt0, dt_min=0; int i; double loc_num, loc_nslit; int i_slope=3; /* look if there is a previous intersection with guide sides */ /* A = 0.5 n.g; B = n.v; C = n.(r-W); */ /* 5=+Z side: n=(0, 0, -l) ; W = (0, 0, l) (at z=l, guide exit)*/ B = aVars->nz[5]*cvz; C = aVars->nz[5]*(cz - aVars->wz[5]); ret = solve_2nd_order(&dt0, NULL, aVars->A[5], B, C); if (ret && dt0>1e-10) { dt_min = dt0; side=5; } loc_num = cynum; loc_nslit = cyk; for (i=4; i>0; i--) { if (i == 2) { i_slope=1; loc_num = cxnum; loc_nslit = cxk; } if (aVars->nzC[i_slope] != 0) { n1 = loc_nslit - 2*(loc_num); /* slope of l/r/u/d sides depends on the channel ! */ loc_num++; /* use partial computations to alter nz and A */ aVars->nz[i]= aVars->nzC[i]*n1; aVars->A[i] = aVars->Axy[i] + aVars->nz[i]*aVars->gz/2; } if (i < 3) { B = aVars->nx[i]*cvx + aVars->nz[i]*cvz; C = aVars->nx[i]*(cx-aVars->wx[i]) + aVars->nz[i]*cz; } else { B = aVars->ny[i]*cvy + aVars->nz[i]*cvz; C = aVars->ny[i]*(cy-aVars->wy[i]) + aVars->nz[i]*cz; } ret = solve_2nd_order(&dt0, NULL, aVars->A[i], B, C); if (ret && dt0>1e-10 && (dt0nzC[i] != 0) { aVars->norm_n2[i] = aVars->norm_n2xy[i] + aVars->nz[i]*aVars->nz[i]; aVars->norm_n[i] = sqrt(aVars->norm_n2[i]); } } } *dt = dt_min; /* handles waviness: rotate n vector */ if (side > 0 && side < 5 && (aVars->wav_z || aVars->wav_lr || aVars->wav_tb)) { double nt_x, nt_y, nt_z; /* transverse vector */ double nn_x, nn_y, nn_z; /* normal vector (tmp) */ double phi; /* normal vector n_z = [ 0,0,1], n_t = n x n_z; */ vec_prod(nt_x,nt_y,nt_z, aVars->nx[side],aVars->ny[side],aVars->nz[side], 0,0,1); /* rotate n with angle wavy_z around n_t -> nn */ if (aVars->wav_z) { phi = aVars->wav_z; rotate(nn_x,nn_y,nn_z, aVars->nx[side],aVars->ny[side],aVars->nz[side], aVars->wav_z*randnorm(), nt_x,nt_y,nt_z); } else { nn_x=aVars->nx[side]; nn_y=aVars->ny[side]; nn_z=aVars->nz[side]; } /* rotate n with angle wavy_{x|y} around n_z -> nt */ phi = (side <=2) ? aVars->wav_lr : aVars->wav_tb; if (phi) { rotate(nt_x,nt_y,nt_z, nn_x,nn_y,nn_z, phi*randnorm(), 0,0,1); } else { nt_x=nn_x; nt_y=nn_y; nt_z=nn_z; } *cnx=nt_x; *cny=nt_y; *cnz=nt_z; } else { *cnx=aVars->nx[side]; *cny=aVars->ny[side]; *cnz=aVars->nz[side]; } return (side); } #endif /* Shared user declarations for all components types 'Al_window'. */ /* ToDo: Should be component local names. */ #ifndef AL_WINDOW #define avogadro 6.022 /* 10E23 Atoms per mole (mol-1) */ #define Al_sigma_a .231 /* Absorption cross section per atom (barns) at 2200m/s */ #define Al_sigma_i .0082 /* Incoherent scattering cross section per atom (barns) */ #define Al_rho 2.7 /* density (gcm-3) */ #define Al_mmol 27 /* molar mass Al (gmol-1) */ #define Al_my_s (Al_rho / Al_mmol * Al_sigma_i * avogadro * 10) /* inc. XS (barn) */ #define Al_my_a_v (Al_rho / Al_mmol * Al_sigma_a * avogadro * 10 * 2200 ) /* Define Constants for Polynomial Fit of sigma_tot(lambda)=A+B1*X+B2*X^2+B3*X^3+B4*X^4+... */ #define Al_pf_A 1.34722 #define Al_pf_B1 .12409 #define Al_pf_B2 .01078 #define Al_pf_B3 -3.25895e-5 #define Al_pf_B4 3.74731e-6 #define AL_WINDOW #endif /* Shared user declarations for all components types 'Filter_gen'. */ #ifndef FILTER_GEN #define FILTER_GEN $Revision$ #define UNKNOWN_TABLE 0 #define ENERGY_TABLE 1 #define WAVEVECTOR_TABLE 2 #define WAVELENGTH_TABLE 3 #define FLUX_ADAPT_SET 0 #define FLUX_ADAPT_MULT 1 #define FLUX_ADAPT_ADD 2 char FilterGen_Mode(char *str, char *Mode, char *Type, double *verbose) { long i; char *c; if (!str || !strlen(str)) return(0); c = malloc(strlen(str)); for (i=0; i0 && yheight>0 && zdepth>0 ); int iscyl = ( yheight>0 && radius>0 ); int issphere = ( !iscyl && radius>0 ); int nshapes = (isbox?1:0)+(iscyl?1:0)+(issphere?1:0); if (nshapes==0) NCMCERR2(name_comp,"must specify more parameters to define shape"); if ( nshapes > 1 || ( iscyl && ( xwidth>0 || zdepth>0 ) ) || ( issphere && ( xwidth>0 || yheight > 0 || zdepth>0 ) ) ) NCMCERR2(name_comp,"conflicting shape parameters specified (pick either parameters for box, cylinder or sphere, not more than one)"); if (isbox) { geom->shape = NC_BOX; geom->dx = xwidth; geom->dy = yheight; geom->dz = zdepth; geom->radius = 0.0; } else if (iscyl) { geom->shape = NC_CYLINDER; geom->dx = 0.0; geom->dy = yheight; geom->dz = 0.0; geom->radius = radius; } else { if (!issphere) NCMCERR2(name_comp,"logic error in shape selection"); geom->shape = NC_SPHERE; geom->dx = 0.0; geom->dy = 0.0; geom->dz = 0.0; geom->radius = radius; } } int ncrystalsample_surfintersect(ncrystalsamplegeom_t* geom, double *t0, double *t1, double x, double y, double z, double vx, double vy, double vz) { switch (geom->shape) { case NC_CYLINDER: return cylinder_intersect(t0,t1,x,y,z,vx,vy,vz,geom->radius, geom->dy); case NC_BOX: return box_intersect(t0, t1, x, y, z, vx, vy, vz,geom->dx, geom->dy, geom->dz); case NC_SPHERE: return sphere_intersect(t0,t1,x,y,z,vx,vy,vz,geom->radius); }; } #ifndef NCMCERR /* more convenient form (only works in TRACE section, not in SHARE functions) */ # define NCMCERR(msg) NCMCERR2(NAME_CURRENT_COMP,msg) #endif double randloc() { /* NCrystal-local wrapper for legacy McStas MT RNG */ double randnum; randnum = (double) mt_random(); randnum /= (double) ((unsigned long)0xffffffff) + 1; return randnum; } /* ************************************************************************** */ /* End of SHARE user declarations for all components */ /* ************************************************************************** */ /* ********************** component definition declarations. **************** */ /* component origin=Progress_bar() [1] DECLARE */ /* Parameter definition for component type 'Progress_bar' */ struct _struct_Progress_bar_parameters { /* Component type 'Progress_bar' setting parameters */ char profile[16384]; MCNUM percent; MCNUM flag_save; MCNUM minutes; /* Component type 'Progress_bar' private parameters */ double IntermediateCnts; time_t StartTime; time_t EndTime; time_t CurrentTime; }; /* _struct_Progress_bar_parameters */ typedef struct _struct_Progress_bar_parameters _class_Progress_bar_parameters; /* Parameters for component type 'Progress_bar' */ struct _struct_Progress_bar { char _name[256]; /* e.g. origin */ char _type[256]; /* Progress_bar */ long _index; /* e.g. 2 index in TRACE list */ Coords _position_absolute; Coords _position_relative; /* wrt PREVIOUS */ Rotation _rotation_absolute; Rotation _rotation_relative; /* wrt PREVIOUS */ int _rotation_is_identity; _class_Progress_bar_parameters _parameters; }; typedef struct _struct_Progress_bar _class_Progress_bar; _class_Progress_bar _origin_var; #pragma acc declare create ( _origin_var ) /* component ColdSource=Source_gen() [2] DECLARE */ /* Parameter definition for component type 'Source_gen' */ struct _struct_Source_gen_parameters { /* Component type 'Source_gen' setting parameters */ char flux_file[16384]; char xdiv_file[16384]; char ydiv_file[16384]; MCNUM radius; MCNUM dist; MCNUM focus_xw; MCNUM focus_yh; MCNUM focus_aw; MCNUM focus_ah; MCNUM E0; MCNUM dE; MCNUM lambda0; MCNUM dlambda; MCNUM I1; MCNUM yheight; MCNUM xwidth; MCNUM verbose; MCNUM T1; MCNUM flux_file_perAA; MCNUM flux_file_log; MCNUM Lmin; MCNUM Lmax; MCNUM Emin; MCNUM Emax; MCNUM T2; MCNUM I2; MCNUM T3; MCNUM I3; MCNUM zdepth; long target_index; /* Component type 'Source_gen' private parameters */ double p_in; double lambda1; double lambda2; double lambda3; t_Table pTable; t_Table pTable_x; t_Table pTable_y; double pTable_xmin; double pTable_xmax; double pTable_xsum; double pTable_ymin; double pTable_ymax; double pTable_ysum; double pTable_dxmin; double pTable_dxmax; double pTable_dymin; double pTable_dymax; }; /* _struct_Source_gen_parameters */ typedef struct _struct_Source_gen_parameters _class_Source_gen_parameters; /* Parameters for component type 'Source_gen' */ struct _struct_Source_gen { char _name[256]; /* e.g. ColdSource */ char _type[256]; /* Source_gen */ long _index; /* e.g. 2 index in TRACE list */ Coords _position_absolute; Coords _position_relative; /* wrt PREVIOUS */ Rotation _rotation_absolute; Rotation _rotation_relative; /* wrt PREVIOUS */ int _rotation_is_identity; _class_Source_gen_parameters _parameters; }; typedef struct _struct_Source_gen _class_Source_gen; _class_Source_gen _ColdSource_var; #pragma acc declare create ( _ColdSource_var ) /* component PrimaryBeam=Arm() [3] DECLARE */ /* Parameter definition for component type 'Arm' */ struct _struct_Arm_parameters { char Arm_has_no_parameters; }; /* _struct_Arm_parameters */ typedef struct _struct_Arm_parameters _class_Arm_parameters; /* Parameters for component type 'Arm' */ struct _struct_Arm { char _name[256]; /* e.g. PrimaryBeam */ char _type[256]; /* Arm */ long _index; /* e.g. 2 index in TRACE list */ Coords _position_absolute; Coords _position_relative; /* wrt PREVIOUS */ Rotation _rotation_absolute; Rotation _rotation_relative; /* wrt PREVIOUS */ int _rotation_is_identity; _class_Arm_parameters _parameters; }; typedef struct _struct_Arm _class_Arm; _class_Arm _PrimaryBeam_var; #pragma acc declare create ( _PrimaryBeam_var ) /* component NL_SR2_1=Guide_gravity() [4] DECLARE */ /* Parameter definition for component type 'Guide_gravity' */ struct _struct_Guide_gravity_parameters { /* Component type 'Guide_gravity' setting parameters */ MCNUM w1; MCNUM h1; MCNUM w2; MCNUM h2; MCNUM l; MCNUM R0; MCNUM Qc; MCNUM alpha; MCNUM m; MCNUM W; MCNUM nslit; MCNUM d; MCNUM mleft; MCNUM mright; MCNUM mtop; MCNUM mbottom; MCNUM nhslit; MCNUM G; MCNUM aleft; MCNUM aright; MCNUM atop; MCNUM abottom; MCNUM wavy; MCNUM wavy_z; MCNUM wavy_tb; MCNUM wavy_lr; MCNUM chamfers; MCNUM chamfers_z; MCNUM chamfers_lr; MCNUM chamfers_tb; MCNUM nelements; MCNUM nu; MCNUM phase; char reflect[16384]; /* Component type 'Guide_gravity' private parameters */ Gravity_guide_Vars_type GVars; t_Table pTable; int table_present; }; /* _struct_Guide_gravity_parameters */ typedef struct _struct_Guide_gravity_parameters _class_Guide_gravity_parameters; /* Parameters for component type 'Guide_gravity' */ struct _struct_Guide_gravity { char _name[256]; /* e.g. NL_SR2_1 */ char _type[256]; /* Guide_gravity */ long _index; /* e.g. 2 index in TRACE list */ Coords _position_absolute; Coords _position_relative; /* wrt PREVIOUS */ Rotation _rotation_absolute; Rotation _rotation_relative; /* wrt PREVIOUS */ int _rotation_is_identity; _class_Guide_gravity_parameters _parameters; }; typedef struct _struct_Guide_gravity _class_Guide_gravity; _class_Guide_gravity _NL_SR2_1_var; #pragma acc declare create ( _NL_SR2_1_var ) _class_Guide_gravity _NL_SR2_2a_var; #pragma acc declare create ( _NL_SR2_2a_var ) _class_Guide_gravity _NL_SR2_2b_var; #pragma acc declare create ( _NL_SR2_2b_var ) _class_Guide_gravity _NL_SR2_2c_var; #pragma acc declare create ( _NL_SR2_2c_var ) _class_Guide_gravity _NL_SR2_3_var; #pragma acc declare create ( _NL_SR2_3_var ) /* component SR2_Beamportwindow=Al_window() [9] DECLARE */ /* Parameter definition for component type 'Al_window' */ struct _struct_Al_window_parameters { /* Component type 'Al_window' setting parameters */ MCNUM thickness; }; /* _struct_Al_window_parameters */ typedef struct _struct_Al_window_parameters _class_Al_window_parameters; /* Parameters for component type 'Al_window' */ struct _struct_Al_window { char _name[256]; /* e.g. SR2_Beamportwindow */ char _type[256]; /* Al_window */ long _index; /* e.g. 2 index in TRACE list */ Coords _position_absolute; Coords _position_relative; /* wrt PREVIOUS */ Rotation _rotation_absolute; Rotation _rotation_relative; /* wrt PREVIOUS */ int _rotation_is_identity; _class_Al_window_parameters _parameters; }; typedef struct _struct_Al_window _class_Al_window; _class_Al_window _SR2_Beamportwindow_var; #pragma acc declare create ( _SR2_Beamportwindow_var ) _class_Arm _SR2_eob_var; #pragma acc declare create ( _SR2_eob_var ) /* component PANDA_ca1=Collimator_linear() [11] DECLARE */ /* Parameter definition for component type 'Collimator_linear' */ struct _struct_Collimator_linear_parameters { /* Component type 'Collimator_linear' setting parameters */ MCNUM xmin; MCNUM xmax; MCNUM ymin; MCNUM ymax; MCNUM xwidth; MCNUM yheight; MCNUM length; MCNUM divergence; MCNUM transmission; MCNUM divergenceV; /* Component type 'Collimator_linear' private parameters */ double slope; double slopeV; }; /* _struct_Collimator_linear_parameters */ typedef struct _struct_Collimator_linear_parameters _class_Collimator_linear_parameters; /* Parameters for component type 'Collimator_linear' */ struct _struct_Collimator_linear { char _name[256]; /* e.g. PANDA_ca1 */ char _type[256]; /* Collimator_linear */ long _index; /* e.g. 2 index in TRACE list */ Coords _position_absolute; Coords _position_relative; /* wrt PREVIOUS */ Rotation _rotation_absolute; Rotation _rotation_relative; /* wrt PREVIOUS */ int _rotation_is_identity; _class_Collimator_linear_parameters _parameters; }; typedef struct _struct_Collimator_linear _class_Collimator_linear; _class_Collimator_linear _PANDA_ca1_var; #pragma acc declare create ( _PANDA_ca1_var ) /* component PANDA_sapphire=Filter_gen() [12] DECLARE */ /* Parameter definition for component type 'Filter_gen' */ struct _struct_Filter_gen_parameters { /* Component type 'Filter_gen' setting parameters */ char filename[16384]; char options[16384]; MCNUM xmin; MCNUM xmax; MCNUM ymin; MCNUM ymax; MCNUM xwidth; MCNUM yheight; MCNUM thickness; MCNUM scaling; MCNUM verbose; /* Component type 'Filter_gen' private parameters */ char Mode_Table; char Type_Table; t_Table pTable; }; /* _struct_Filter_gen_parameters */ typedef struct _struct_Filter_gen_parameters _class_Filter_gen_parameters; /* Parameters for component type 'Filter_gen' */ struct _struct_Filter_gen { char _name[256]; /* e.g. PANDA_sapphire */ char _type[256]; /* Filter_gen */ long _index; /* e.g. 2 index in TRACE list */ Coords _position_absolute; Coords _position_relative; /* wrt PREVIOUS */ Rotation _rotation_absolute; Rotation _rotation_relative; /* wrt PREVIOUS */ int _rotation_is_identity; _class_Filter_gen_parameters _parameters; }; typedef struct _struct_Filter_gen _class_Filter_gen; _class_Filter_gen _PANDA_sapphire_var; #pragma acc declare create ( _PANDA_sapphire_var ) /* component sk1_in=Slit() [13] DECLARE */ /* Parameter definition for component type 'Slit' */ struct _struct_Slit_parameters { /* Component type 'Slit' setting parameters */ MCNUM xmin; MCNUM xmax; MCNUM ymin; MCNUM ymax; MCNUM radius; MCNUM xwidth; MCNUM yheight; }; /* _struct_Slit_parameters */ typedef struct _struct_Slit_parameters _class_Slit_parameters; /* Parameters for component type 'Slit' */ struct _struct_Slit { char _name[256]; /* e.g. sk1_in */ char _type[256]; /* Slit */ long _index; /* e.g. 2 index in TRACE list */ Coords _position_absolute; Coords _position_relative; /* wrt PREVIOUS */ Rotation _rotation_absolute; Rotation _rotation_relative; /* wrt PREVIOUS */ int _rotation_is_identity; _class_Slit_parameters _parameters; }; typedef struct _struct_Slit _class_Slit; _class_Slit _sk1_in_var; #pragma acc declare create ( _sk1_in_var ) _class_Slit _sk1_out_var; #pragma acc declare create ( _sk1_out_var ) _class_Slit _PANDA_ms1_var; #pragma acc declare create ( _PANDA_ms1_var ) _class_Slit _sk2_in_var; #pragma acc declare create ( _sk2_in_var ) _class_Slit _sk2_out_var; #pragma acc declare create ( _sk2_out_var ) /* component PSD_PrimBeam=PSD_monitor() [18] DECLARE */ /* Parameter definition for component type 'PSD_monitor' */ struct _struct_PSD_monitor_parameters { /* Component type 'PSD_monitor' setting parameters */ MCNUM nx; MCNUM ny; char filename[16384]; MCNUM xmin; MCNUM xmax; MCNUM ymin; MCNUM ymax; MCNUM xwidth; MCNUM yheight; MCNUM restore_neutron; long nowritefile; /* Component type 'PSD_monitor' private parameters */ DArray2d PSD_N; DArray2d PSD_p; DArray2d PSD_p2; }; /* _struct_PSD_monitor_parameters */ typedef struct _struct_PSD_monitor_parameters _class_PSD_monitor_parameters; /* Parameters for component type 'PSD_monitor' */ struct _struct_PSD_monitor { char _name[256]; /* e.g. PSD_PrimBeam */ char _type[256]; /* PSD_monitor */ long _index; /* e.g. 2 index in TRACE list */ Coords _position_absolute; Coords _position_relative; /* wrt PREVIOUS */ Rotation _rotation_absolute; Rotation _rotation_relative; /* wrt PREVIOUS */ int _rotation_is_identity; _class_PSD_monitor_parameters _parameters; }; typedef struct _struct_PSD_monitor _class_PSD_monitor; _class_PSD_monitor _PSD_PrimBeam_var; #pragma acc declare create ( _PSD_PrimBeam_var ) /* component LAM_PrimBeam=L_monitor() [19] DECLARE */ /* Parameter definition for component type 'L_monitor' */ struct _struct_L_monitor_parameters { /* Component type 'L_monitor' setting parameters */ MCNUM nL; char filename[16384]; MCNUM xmin; MCNUM xmax; MCNUM ymin; MCNUM ymax; MCNUM xwidth; MCNUM yheight; MCNUM Lmin; MCNUM Lmax; MCNUM restore_neutron; /* Component type 'L_monitor' private parameters */ DArray1d L_N; DArray1d L_p; DArray1d L_p2; }; /* _struct_L_monitor_parameters */ typedef struct _struct_L_monitor_parameters _class_L_monitor_parameters; /* Parameters for component type 'L_monitor' */ struct _struct_L_monitor { char _name[256]; /* e.g. LAM_PrimBeam */ char _type[256]; /* L_monitor */ long _index; /* e.g. 2 index in TRACE list */ Coords _position_absolute; Coords _position_relative; /* wrt PREVIOUS */ Rotation _rotation_absolute; Rotation _rotation_relative; /* wrt PREVIOUS */ int _rotation_is_identity; _class_L_monitor_parameters _parameters; }; typedef struct _struct_L_monitor _class_L_monitor; _class_L_monitor _LAM_PrimBeam_var; #pragma acc declare create ( _LAM_PrimBeam_var ) /* component DIV_PrimBeam=Divergence_monitor() [20] DECLARE */ /* Parameter definition for component type 'Divergence_monitor' */ struct _struct_Divergence_monitor_parameters { /* Component type 'Divergence_monitor' setting parameters */ MCNUM nh; MCNUM nv; char filename[16384]; MCNUM xmin; MCNUM xmax; MCNUM ymin; MCNUM ymax; MCNUM xwidth; MCNUM yheight; MCNUM maxdiv_h; MCNUM maxdiv_v; MCNUM restore_neutron; MCNUM nx; MCNUM ny; MCNUM nz; /* Component type 'Divergence_monitor' private parameters */ DArray2d Div_N; DArray2d Div_p; DArray2d Div_p2; }; /* _struct_Divergence_monitor_parameters */ typedef struct _struct_Divergence_monitor_parameters _class_Divergence_monitor_parameters; /* Parameters for component type 'Divergence_monitor' */ struct _struct_Divergence_monitor { char _name[256]; /* e.g. DIV_PrimBeam */ char _type[256]; /* Divergence_monitor */ long _index; /* e.g. 2 index in TRACE list */ Coords _position_absolute; Coords _position_relative; /* wrt PREVIOUS */ Rotation _rotation_absolute; Rotation _rotation_relative; /* wrt PREVIOUS */ int _rotation_is_identity; _class_Divergence_monitor_parameters _parameters; }; typedef struct _struct_Divergence_monitor _class_Divergence_monitor; _class_Divergence_monitor _DIV_PrimBeam_var; #pragma acc declare create ( _DIV_PrimBeam_var ) _class_Arm _PANDA_mth_var; #pragma acc declare create ( _PANDA_mth_var ) _class_Arm _a_mono_var; #pragma acc declare create ( _a_mono_var ) /* component PG002_mono=Monochromator_curved() [23] DECLARE */ /* Parameter definition for component type 'Monochromator_curved' */ struct _struct_Monochromator_curved_parameters { /* Component type 'Monochromator_curved' setting parameters */ char reflect[16384]; char transmit[16384]; MCNUM zwidth; MCNUM yheight; MCNUM gap; long NH; long NV; MCNUM mosaich; MCNUM mosaicv; MCNUM r0; MCNUM t0; MCNUM Q; MCNUM RV; MCNUM RH; MCNUM DM; MCNUM mosaic; MCNUM width; MCNUM height; MCNUM verbose; MCNUM order; /* Component type 'Monochromator_curved' private parameters */ double mos_rms_y; double mos_rms_z; double mos_rms_max; double mono_Q; double SlabWidth; double SlabHeight; t_Table rTable; t_Table tTable; int rTableFlag; int tTableFlag; double * tiltH; double * tiltV; }; /* _struct_Monochromator_curved_parameters */ typedef struct _struct_Monochromator_curved_parameters _class_Monochromator_curved_parameters; /* Parameters for component type 'Monochromator_curved' */ struct _struct_Monochromator_curved { char _name[256]; /* e.g. PG002_mono */ char _type[256]; /* Monochromator_curved */ long _index; /* e.g. 2 index in TRACE list */ Coords _position_absolute; Coords _position_relative; /* wrt PREVIOUS */ Rotation _rotation_absolute; Rotation _rotation_relative; /* wrt PREVIOUS */ int _rotation_is_identity; _class_Monochromator_curved_parameters _parameters; }; typedef struct _struct_Monochromator_curved _class_Monochromator_curved; _class_Monochromator_curved _PG002_mono_var; #pragma acc declare create ( _PG002_mono_var ) _class_Arm _PANDA_mtt_var; #pragma acc declare create ( _PANDA_mtt_var ) _class_Slit _sk3_in_var; #pragma acc declare create ( _sk3_in_var ) _class_Collimator_linear _PANDA_ca2_var; #pragma acc declare create ( _PANDA_ca2_var ) _class_Slit _sk3_out_var; #pragma acc declare create ( _sk3_out_var ) _class_PSD_monitor _PSD_mon1_var; #pragma acc declare create ( _PSD_mon1_var ) _class_L_monitor _LAM_mon1_var; #pragma acc declare create ( _LAM_mon1_var ) _class_Slit _PANDA_ss1_var; #pragma acc declare create ( _PANDA_ss1_var ) _class_PSD_monitor _PSD_samplepos_var; #pragma acc declare create ( _PSD_samplepos_var ) /* component Mon_samplepos2=Monitor() [32] DECLARE */ /* Parameter definition for component type 'Monitor' */ struct _struct_Monitor_parameters { /* Component type 'Monitor' setting parameters */ MCNUM xmin; MCNUM xmax; MCNUM ymin; MCNUM ymax; MCNUM xwidth; MCNUM yheight; MCNUM restore_neutron; /* Component type 'Monitor' private parameters */ double Nsum; double psum; double p2sum; }; /* _struct_Monitor_parameters */ typedef struct _struct_Monitor_parameters _class_Monitor_parameters; /* Parameters for component type 'Monitor' */ struct _struct_Monitor { char _name[256]; /* e.g. Mon_samplepos2 */ char _type[256]; /* Monitor */ long _index; /* e.g. 2 index in TRACE list */ Coords _position_absolute; Coords _position_relative; /* wrt PREVIOUS */ Rotation _rotation_absolute; Rotation _rotation_relative; /* wrt PREVIOUS */ int _rotation_is_identity; _class_Monitor_parameters _parameters; }; typedef struct _struct_Monitor _class_Monitor; _class_Monitor _Mon_samplepos2_var; #pragma acc declare create ( _Mon_samplepos2_var ) _class_Arm _PANDA_sth_var; #pragma acc declare create ( _PANDA_sth_var ) _class_Arm _sample_var; #pragma acc declare create ( _sample_var ) /* component PANDA_cryst=NCrystal_sample() [35] DECLARE */ /* Parameter definition for component type 'NCrystal_sample' */ struct _struct_NCrystal_sample_parameters { /* Component type 'NCrystal_sample' setting parameters */ char cfg[16384]; MCNUM absorptionmode; MCNUM multscat; MCNUM xwidth; MCNUM yheight; MCNUM zdepth; MCNUM radius; /* Component type 'NCrystal_sample' private parameters */ ncrystalsample_t params; ncrystalsamplegeom_t geoparams; double ncrystal_convfact_vsq2ekin; double ncrystal_convfact_ekin2vsq; }; /* _struct_NCrystal_sample_parameters */ typedef struct _struct_NCrystal_sample_parameters _class_NCrystal_sample_parameters; /* Parameters for component type 'NCrystal_sample' */ struct _struct_NCrystal_sample { char _name[256]; /* e.g. PANDA_cryst */ char _type[256]; /* NCrystal_sample */ long _index; /* e.g. 2 index in TRACE list */ Coords _position_absolute; Coords _position_relative; /* wrt PREVIOUS */ Rotation _rotation_absolute; Rotation _rotation_relative; /* wrt PREVIOUS */ int _rotation_is_identity; _class_NCrystal_sample_parameters _parameters; }; typedef struct _struct_NCrystal_sample _class_NCrystal_sample; _class_NCrystal_sample _PANDA_cryst_var; #pragma acc declare create ( _PANDA_cryst_var ) _class_Arm _PANDA_stt_var; #pragma acc declare create ( _PANDA_stt_var ) _class_PSD_monitor _PSD_scattered_var; #pragma acc declare create ( _PSD_scattered_var ) _class_Slit _PANDA_ss2_var; #pragma acc declare create ( _PANDA_ss2_var ) _class_Slit _sk4_in_var; #pragma acc declare create ( _sk4_in_var ) _class_Collimator_linear _PANDA_ca3_var; #pragma acc declare create ( _PANDA_ca3_var ) _class_Slit _sk4_out_var; #pragma acc declare create ( _sk4_out_var ) _class_PSD_monitor _PSD_mon2_var; #pragma acc declare create ( _PSD_mon2_var ) _class_Arm _PANDA_ath_var; #pragma acc declare create ( _PANDA_ath_var ) _class_Arm _analyser_var; #pragma acc declare create ( _analyser_var ) _class_Monochromator_curved _PG002_ana_var; #pragma acc declare create ( _PG002_ana_var ) _class_Arm _PANDA_att_var; #pragma acc declare create ( _PANDA_att_var ) _class_Slit _sk5_in_var; #pragma acc declare create ( _sk5_in_var ) _class_Collimator_linear _PANDA_ca4_var; #pragma acc declare create ( _PANDA_ca4_var ) _class_Slit _sk5_out_var; #pragma acc declare create ( _sk5_out_var ) _class_Arm _a_detector_var; #pragma acc declare create ( _a_detector_var ) _class_PSD_monitor _PSD_det_var; #pragma acc declare create ( _PSD_det_var ) _class_PSD_monitor _PSD_det1_var; #pragma acc declare create ( _PSD_det1_var ) _class_PSD_monitor _PSD_det2_var; #pragma acc declare create ( _PSD_det2_var ) int mcNUMCOMP = 53; /* User declarations from instrument definition. Can define functions. */ double ca1_div,ca2_div,ca3_div,ca4_div; double a1,a2,a3,a4,a5,a6; double my_ki,my_kf,my_thetas; double Lam,dLam,MINLam,MAXLam; double d_PG002; #undef compcurname #undef compcurtype #undef compcurindex /* end of instrument 'PANDA' and components DECLARE */ /* ***************************************************************************** * instrument 'PANDA' and components INITIALISE ***************************************************************************** */ /* component origin=Progress_bar() SETTING, POSITION/ROTATION */ int _origin_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_origin_setpos] component origin=Progress_bar() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../misc/Progress_bar.comp:57]"); stracpy(_origin_var._name, "origin", 16384); stracpy(_origin_var._type, "Progress_bar", 16384); _origin_var._index=1; if("NULL" && strlen("NULL")) stracpy(_origin_var._parameters.profile, "NULL" ? "NULL" : "", 16384); else _origin_var._parameters.profile[0]='\0'; _origin_var._parameters.percent = 10; _origin_var._parameters.flag_save = 0; _origin_var._parameters.minutes = 0; /* component origin=Progress_bar() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(_origin_var._rotation_absolute, (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD); rot_copy(_origin_var._rotation_relative, _origin_var._rotation_absolute); _origin_var._rotation_is_identity = rot_test_identity(_origin_var._rotation_relative); _origin_var._position_absolute = coords_set( 0, 0, 0); tc1 = coords_neg(_origin_var._position_absolute); _origin_var._position_relative = rot_apply(_origin_var._rotation_absolute, tc1); } /* origin=Progress_bar() AT ROTATED */ DEBUG_COMPONENT("origin", _origin_var._position_absolute, _origin_var._rotation_absolute); instrument->_position_absolute[1] = _origin_var._position_absolute; instrument->_position_relative[1] = _origin_var._position_relative; instrument->counter_N[1] = instrument->counter_P[1] = instrument->counter_P2[1] = 0; instrument->counter_AbsorbProp[1]= 0; return(0); } /* _origin_setpos */ /* component ColdSource=Source_gen() SETTING, POSITION/ROTATION */ int _ColdSource_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_ColdSource_setpos] component ColdSource=Source_gen() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../sources/Source_gen.comp:207]"); stracpy(_ColdSource_var._name, "ColdSource", 16384); stracpy(_ColdSource_var._type, "Source_gen", 16384); _ColdSource_var._index=2; if("NULL" && strlen("NULL")) stracpy(_ColdSource_var._parameters.flux_file, "NULL" ? "NULL" : "", 16384); else _ColdSource_var._parameters.flux_file[0]='\0'; if("NULL" && strlen("NULL")) stracpy(_ColdSource_var._parameters.xdiv_file, "NULL" ? "NULL" : "", 16384); else _ColdSource_var._parameters.xdiv_file[0]='\0'; if("NULL" && strlen("NULL")) stracpy(_ColdSource_var._parameters.ydiv_file, "NULL" ? "NULL" : "", 16384); else _ColdSource_var._parameters.ydiv_file[0]='\0'; _ColdSource_var._parameters.radius = 0.0; _ColdSource_var._parameters.dist = 0.79045 + 0.39063; _ColdSource_var._parameters.focus_xw = 0.11; _ColdSource_var._parameters.focus_yh = 0.1; _ColdSource_var._parameters.focus_aw = 0; _ColdSource_var._parameters.focus_ah = 0; _ColdSource_var._parameters.E0 = 0; _ColdSource_var._parameters.dE = 0; _ColdSource_var._parameters.lambda0 = Lam; _ColdSource_var._parameters.dlambda = dLam; _ColdSource_var._parameters.I1 = 7.22e12; _ColdSource_var._parameters.yheight = 0.08; _ColdSource_var._parameters.xwidth = 0.135; _ColdSource_var._parameters.verbose = 0; _ColdSource_var._parameters.T1 = 361.9; _ColdSource_var._parameters.flux_file_perAA = 0; _ColdSource_var._parameters.flux_file_log = 0; _ColdSource_var._parameters.Lmin = 0; _ColdSource_var._parameters.Lmax = 0; _ColdSource_var._parameters.Emin = 0; _ColdSource_var._parameters.Emax = 0; _ColdSource_var._parameters.T2 = 159.0; _ColdSource_var._parameters.I2 = 6.74e12; _ColdSource_var._parameters.T3 = 35.66; _ColdSource_var._parameters.I3 = 6.435e12; _ColdSource_var._parameters.zdepth = 0; _ColdSource_var._parameters.target_index = + 1; /* component ColdSource=Source_gen() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _origin_var._rotation_absolute, _ColdSource_var._rotation_absolute); rot_transpose(_origin_var._rotation_absolute, tr1); rot_mul(_ColdSource_var._rotation_absolute, tr1, _ColdSource_var._rotation_relative); _ColdSource_var._rotation_is_identity = rot_test_identity(_ColdSource_var._rotation_relative); tc1 = coords_set( 0, 0, 0); rot_transpose(_origin_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _ColdSource_var._position_absolute = coords_add(_origin_var._position_absolute, tc2); tc1 = coords_sub(_origin_var._position_absolute, _ColdSource_var._position_absolute); _ColdSource_var._position_relative = rot_apply(_ColdSource_var._rotation_absolute, tc1); } /* ColdSource=Source_gen() AT ROTATED */ DEBUG_COMPONENT("ColdSource", _ColdSource_var._position_absolute, _ColdSource_var._rotation_absolute); instrument->_position_absolute[2] = _ColdSource_var._position_absolute; instrument->_position_relative[2] = _ColdSource_var._position_relative; instrument->counter_N[2] = instrument->counter_P[2] = instrument->counter_P2[2] = 0; instrument->counter_AbsorbProp[2]= 0; return(0); } /* _ColdSource_setpos */ /* component PrimaryBeam=Arm() SETTING, POSITION/ROTATION */ int _PrimaryBeam_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PrimaryBeam_setpos] component PrimaryBeam=Arm() SETTING [Arm:0]"); stracpy(_PrimaryBeam_var._name, "PrimaryBeam", 16384); stracpy(_PrimaryBeam_var._type, "Arm", 16384); _PrimaryBeam_var._index=3; /* component PrimaryBeam=Arm() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _origin_var._rotation_absolute, _PrimaryBeam_var._rotation_absolute); rot_transpose(_ColdSource_var._rotation_absolute, tr1); rot_mul(_PrimaryBeam_var._rotation_absolute, tr1, _PrimaryBeam_var._rotation_relative); _PrimaryBeam_var._rotation_is_identity = rot_test_identity(_PrimaryBeam_var._rotation_relative); tc1 = coords_set( 0, 0, 0); rot_transpose(_origin_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PrimaryBeam_var._position_absolute = coords_add(_origin_var._position_absolute, tc2); tc1 = coords_sub(_ColdSource_var._position_absolute, _PrimaryBeam_var._position_absolute); _PrimaryBeam_var._position_relative = rot_apply(_PrimaryBeam_var._rotation_absolute, tc1); } /* PrimaryBeam=Arm() AT ROTATED */ DEBUG_COMPONENT("PrimaryBeam", _PrimaryBeam_var._position_absolute, _PrimaryBeam_var._rotation_absolute); instrument->_position_absolute[3] = _PrimaryBeam_var._position_absolute; instrument->_position_relative[3] = _PrimaryBeam_var._position_relative; instrument->counter_N[3] = instrument->counter_P[3] = instrument->counter_P2[3] = 0; instrument->counter_AbsorbProp[3]= 0; return(0); } /* _PrimaryBeam_setpos */ /* component NL_SR2_1=Guide_gravity() SETTING, POSITION/ROTATION */ int _NL_SR2_1_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_NL_SR2_1_setpos] component NL_SR2_1=Guide_gravity() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Guide_gravity.comp:341]"); stracpy(_NL_SR2_1_var._name, "NL_SR2_1", 16384); stracpy(_NL_SR2_1_var._type, "Guide_gravity", 16384); _NL_SR2_1_var._index=4; _NL_SR2_1_var._parameters.w1 = 0.105; _NL_SR2_1_var._parameters.h1 = 0.098; _NL_SR2_1_var._parameters.w2 = 0.105; _NL_SR2_1_var._parameters.h2 = 0.118; _NL_SR2_1_var._parameters.l = 1.307; _NL_SR2_1_var._parameters.R0 = 0.99; _NL_SR2_1_var._parameters.Qc = 0.02174; _NL_SR2_1_var._parameters.alpha = 3.0; _NL_SR2_1_var._parameters.m = 1.0; _NL_SR2_1_var._parameters.W = 0.001; _NL_SR2_1_var._parameters.nslit = 1; _NL_SR2_1_var._parameters.d = 0.0005; _NL_SR2_1_var._parameters.mleft = 3.0; _NL_SR2_1_var._parameters.mright = 3.0; _NL_SR2_1_var._parameters.mtop = 3.0; _NL_SR2_1_var._parameters.mbottom = 3.0; _NL_SR2_1_var._parameters.nhslit = 1; _NL_SR2_1_var._parameters.G = 0; _NL_SR2_1_var._parameters.aleft = -1; _NL_SR2_1_var._parameters.aright = -1; _NL_SR2_1_var._parameters.atop = -1; _NL_SR2_1_var._parameters.abottom = -1; _NL_SR2_1_var._parameters.wavy = 0; _NL_SR2_1_var._parameters.wavy_z = 0; _NL_SR2_1_var._parameters.wavy_tb = 0; _NL_SR2_1_var._parameters.wavy_lr = 0; _NL_SR2_1_var._parameters.chamfers = 0; _NL_SR2_1_var._parameters.chamfers_z = 0; _NL_SR2_1_var._parameters.chamfers_lr = 0; _NL_SR2_1_var._parameters.chamfers_tb = 0; _NL_SR2_1_var._parameters.nelements = 1; _NL_SR2_1_var._parameters.nu = 0; _NL_SR2_1_var._parameters.phase = 0; if("NULL" && strlen("NULL")) stracpy(_NL_SR2_1_var._parameters.reflect, "NULL" ? "NULL" : "", 16384); else _NL_SR2_1_var._parameters.reflect[0]='\0'; /* component NL_SR2_1=Guide_gravity() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PrimaryBeam_var._rotation_absolute, _NL_SR2_1_var._rotation_absolute); rot_transpose(_PrimaryBeam_var._rotation_absolute, tr1); rot_mul(_NL_SR2_1_var._rotation_absolute, tr1, _NL_SR2_1_var._rotation_relative); _NL_SR2_1_var._rotation_is_identity = rot_test_identity(_NL_SR2_1_var._rotation_relative); tc1 = coords_set( 0, 0, 1.1960); rot_transpose(_PrimaryBeam_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _NL_SR2_1_var._position_absolute = coords_add(_PrimaryBeam_var._position_absolute, tc2); tc1 = coords_sub(_PrimaryBeam_var._position_absolute, _NL_SR2_1_var._position_absolute); _NL_SR2_1_var._position_relative = rot_apply(_NL_SR2_1_var._rotation_absolute, tc1); } /* NL_SR2_1=Guide_gravity() AT ROTATED */ DEBUG_COMPONENT("NL_SR2_1", _NL_SR2_1_var._position_absolute, _NL_SR2_1_var._rotation_absolute); instrument->_position_absolute[4] = _NL_SR2_1_var._position_absolute; instrument->_position_relative[4] = _NL_SR2_1_var._position_relative; instrument->counter_N[4] = instrument->counter_P[4] = instrument->counter_P2[4] = 0; instrument->counter_AbsorbProp[4]= 0; return(0); } /* _NL_SR2_1_setpos */ /* component NL_SR2_2a=Guide_gravity() SETTING, POSITION/ROTATION */ int _NL_SR2_2a_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_NL_SR2_2a_setpos] component NL_SR2_2a=Guide_gravity() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Guide_gravity.comp:341]"); stracpy(_NL_SR2_2a_var._name, "NL_SR2_2a", 16384); stracpy(_NL_SR2_2a_var._type, "Guide_gravity", 16384); _NL_SR2_2a_var._index=5; _NL_SR2_2a_var._parameters.w1 = 0.106; _NL_SR2_2a_var._parameters.h1 = 0.119; _NL_SR2_2a_var._parameters.w2 = 0.106; _NL_SR2_2a_var._parameters.h2 = 0.134; _NL_SR2_2a_var._parameters.l = 0.997; _NL_SR2_2a_var._parameters.R0 = 0.99; _NL_SR2_2a_var._parameters.Qc = 0.02174; _NL_SR2_2a_var._parameters.alpha = 3.0; _NL_SR2_2a_var._parameters.m = 1.0; _NL_SR2_2a_var._parameters.W = 0.001; _NL_SR2_2a_var._parameters.nslit = 1; _NL_SR2_2a_var._parameters.d = 0.0005; _NL_SR2_2a_var._parameters.mleft = 3.0; _NL_SR2_2a_var._parameters.mright = 3.0; _NL_SR2_2a_var._parameters.mtop = 0; _NL_SR2_2a_var._parameters.mbottom = 0; _NL_SR2_2a_var._parameters.nhslit = 1; _NL_SR2_2a_var._parameters.G = 0; _NL_SR2_2a_var._parameters.aleft = -1; _NL_SR2_2a_var._parameters.aright = -1; _NL_SR2_2a_var._parameters.atop = -1; _NL_SR2_2a_var._parameters.abottom = -1; _NL_SR2_2a_var._parameters.wavy = 0; _NL_SR2_2a_var._parameters.wavy_z = 0; _NL_SR2_2a_var._parameters.wavy_tb = 0; _NL_SR2_2a_var._parameters.wavy_lr = 0; _NL_SR2_2a_var._parameters.chamfers = 0; _NL_SR2_2a_var._parameters.chamfers_z = 0; _NL_SR2_2a_var._parameters.chamfers_lr = 0; _NL_SR2_2a_var._parameters.chamfers_tb = 0; _NL_SR2_2a_var._parameters.nelements = 1; _NL_SR2_2a_var._parameters.nu = 0; _NL_SR2_2a_var._parameters.phase = 0; if("NULL" && strlen("NULL")) stracpy(_NL_SR2_2a_var._parameters.reflect, "NULL" ? "NULL" : "", 16384); else _NL_SR2_2a_var._parameters.reflect[0]='\0'; /* component NL_SR2_2a=Guide_gravity() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PrimaryBeam_var._rotation_absolute, _NL_SR2_2a_var._rotation_absolute); rot_transpose(_NL_SR2_1_var._rotation_absolute, tr1); rot_mul(_NL_SR2_2a_var._rotation_absolute, tr1, _NL_SR2_2a_var._rotation_relative); _NL_SR2_2a_var._rotation_is_identity = rot_test_identity(_NL_SR2_2a_var._rotation_relative); tc1 = coords_set( 0, 0, 2.540); rot_transpose(_PrimaryBeam_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _NL_SR2_2a_var._position_absolute = coords_add(_PrimaryBeam_var._position_absolute, tc2); tc1 = coords_sub(_NL_SR2_1_var._position_absolute, _NL_SR2_2a_var._position_absolute); _NL_SR2_2a_var._position_relative = rot_apply(_NL_SR2_2a_var._rotation_absolute, tc1); } /* NL_SR2_2a=Guide_gravity() AT ROTATED */ DEBUG_COMPONENT("NL_SR2_2a", _NL_SR2_2a_var._position_absolute, _NL_SR2_2a_var._rotation_absolute); instrument->_position_absolute[5] = _NL_SR2_2a_var._position_absolute; instrument->_position_relative[5] = _NL_SR2_2a_var._position_relative; instrument->counter_N[5] = instrument->counter_P[5] = instrument->counter_P2[5] = 0; instrument->counter_AbsorbProp[5]= 0; return(0); } /* _NL_SR2_2a_setpos */ /* component NL_SR2_2b=Guide_gravity() SETTING, POSITION/ROTATION */ int _NL_SR2_2b_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_NL_SR2_2b_setpos] component NL_SR2_2b=Guide_gravity() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Guide_gravity.comp:341]"); stracpy(_NL_SR2_2b_var._name, "NL_SR2_2b", 16384); stracpy(_NL_SR2_2b_var._type, "Guide_gravity", 16384); _NL_SR2_2b_var._index=6; _NL_SR2_2b_var._parameters.w1 = 0.050; _NL_SR2_2b_var._parameters.h1 = 0.099; _NL_SR2_2b_var._parameters.w2 = 0.050; _NL_SR2_2b_var._parameters.h2 = 0.107; _NL_SR2_2b_var._parameters.l = 0.997; _NL_SR2_2b_var._parameters.R0 = 0.99; _NL_SR2_2b_var._parameters.Qc = 0.02174; _NL_SR2_2b_var._parameters.alpha = 3.0; _NL_SR2_2b_var._parameters.m = 1.0; _NL_SR2_2b_var._parameters.W = 0.001; _NL_SR2_2b_var._parameters.nslit = 1; _NL_SR2_2b_var._parameters.d = 0.0005; _NL_SR2_2b_var._parameters.mleft = 0; _NL_SR2_2b_var._parameters.mright = 0; _NL_SR2_2b_var._parameters.mtop = 0; _NL_SR2_2b_var._parameters.mbottom = 0; _NL_SR2_2b_var._parameters.nhslit = 1; _NL_SR2_2b_var._parameters.G = 0; _NL_SR2_2b_var._parameters.aleft = -1; _NL_SR2_2b_var._parameters.aright = -1; _NL_SR2_2b_var._parameters.atop = -1; _NL_SR2_2b_var._parameters.abottom = -1; _NL_SR2_2b_var._parameters.wavy = 0; _NL_SR2_2b_var._parameters.wavy_z = 0; _NL_SR2_2b_var._parameters.wavy_tb = 0; _NL_SR2_2b_var._parameters.wavy_lr = 0; _NL_SR2_2b_var._parameters.chamfers = 0; _NL_SR2_2b_var._parameters.chamfers_z = 0; _NL_SR2_2b_var._parameters.chamfers_lr = 0; _NL_SR2_2b_var._parameters.chamfers_tb = 0; _NL_SR2_2b_var._parameters.nelements = 1; _NL_SR2_2b_var._parameters.nu = 0; _NL_SR2_2b_var._parameters.phase = 0; if("NULL" && strlen("NULL")) stracpy(_NL_SR2_2b_var._parameters.reflect, "NULL" ? "NULL" : "", 16384); else _NL_SR2_2b_var._parameters.reflect[0]='\0'; /* component NL_SR2_2b=Guide_gravity() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PrimaryBeam_var._rotation_absolute, _NL_SR2_2b_var._rotation_absolute); rot_transpose(_NL_SR2_2a_var._rotation_absolute, tr1); rot_mul(_NL_SR2_2b_var._rotation_absolute, tr1, _NL_SR2_2b_var._rotation_relative); _NL_SR2_2b_var._rotation_is_identity = rot_test_identity(_NL_SR2_2b_var._rotation_relative); tc1 = coords_set( 0, 0, 2.540); rot_transpose(_PrimaryBeam_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _NL_SR2_2b_var._position_absolute = coords_add(_PrimaryBeam_var._position_absolute, tc2); tc1 = coords_sub(_NL_SR2_2a_var._position_absolute, _NL_SR2_2b_var._position_absolute); _NL_SR2_2b_var._position_relative = rot_apply(_NL_SR2_2b_var._rotation_absolute, tc1); } /* NL_SR2_2b=Guide_gravity() AT ROTATED */ DEBUG_COMPONENT("NL_SR2_2b", _NL_SR2_2b_var._position_absolute, _NL_SR2_2b_var._rotation_absolute); instrument->_position_absolute[6] = _NL_SR2_2b_var._position_absolute; instrument->_position_relative[6] = _NL_SR2_2b_var._position_relative; instrument->counter_N[6] = instrument->counter_P[6] = instrument->counter_P2[6] = 0; instrument->counter_AbsorbProp[6]= 0; return(0); } /* _NL_SR2_2b_setpos */ /* component NL_SR2_2c=Guide_gravity() SETTING, POSITION/ROTATION */ int _NL_SR2_2c_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_NL_SR2_2c_setpos] component NL_SR2_2c=Guide_gravity() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Guide_gravity.comp:341]"); stracpy(_NL_SR2_2c_var._name, "NL_SR2_2c", 16384); stracpy(_NL_SR2_2c_var._type, "Guide_gravity", 16384); _NL_SR2_2c_var._index=7; _NL_SR2_2c_var._parameters.w1 = 0.040; _NL_SR2_2c_var._parameters.h1 = 0.119; _NL_SR2_2c_var._parameters.w2 = 0.040; _NL_SR2_2c_var._parameters.h2 = 0.134; _NL_SR2_2c_var._parameters.l = 0.997; _NL_SR2_2c_var._parameters.R0 = 0.99; _NL_SR2_2c_var._parameters.Qc = 0.02174; _NL_SR2_2c_var._parameters.alpha = 3.0; _NL_SR2_2c_var._parameters.m = 1.0; _NL_SR2_2c_var._parameters.W = 0.001; _NL_SR2_2c_var._parameters.nslit = 1; _NL_SR2_2c_var._parameters.d = 0.0005; _NL_SR2_2c_var._parameters.mleft = 2.0; _NL_SR2_2c_var._parameters.mright = 2.0; _NL_SR2_2c_var._parameters.mtop = 0; _NL_SR2_2c_var._parameters.mbottom = 0; _NL_SR2_2c_var._parameters.nhslit = 1; _NL_SR2_2c_var._parameters.G = 0; _NL_SR2_2c_var._parameters.aleft = -1; _NL_SR2_2c_var._parameters.aright = -1; _NL_SR2_2c_var._parameters.atop = -1; _NL_SR2_2c_var._parameters.abottom = -1; _NL_SR2_2c_var._parameters.wavy = 0; _NL_SR2_2c_var._parameters.wavy_z = 0; _NL_SR2_2c_var._parameters.wavy_tb = 0; _NL_SR2_2c_var._parameters.wavy_lr = 0; _NL_SR2_2c_var._parameters.chamfers = 0; _NL_SR2_2c_var._parameters.chamfers_z = 0; _NL_SR2_2c_var._parameters.chamfers_lr = 0; _NL_SR2_2c_var._parameters.chamfers_tb = 0; _NL_SR2_2c_var._parameters.nelements = 1; _NL_SR2_2c_var._parameters.nu = 0; _NL_SR2_2c_var._parameters.phase = 0; if("NULL" && strlen("NULL")) stracpy(_NL_SR2_2c_var._parameters.reflect, "NULL" ? "NULL" : "", 16384); else _NL_SR2_2c_var._parameters.reflect[0]='\0'; /* component NL_SR2_2c=Guide_gravity() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PrimaryBeam_var._rotation_absolute, _NL_SR2_2c_var._rotation_absolute); rot_transpose(_NL_SR2_2b_var._rotation_absolute, tr1); rot_mul(_NL_SR2_2c_var._rotation_absolute, tr1, _NL_SR2_2c_var._rotation_relative); _NL_SR2_2c_var._rotation_is_identity = rot_test_identity(_NL_SR2_2c_var._rotation_relative); tc1 = coords_set( 0, 0, 2.540); rot_transpose(_PrimaryBeam_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _NL_SR2_2c_var._position_absolute = coords_add(_PrimaryBeam_var._position_absolute, tc2); tc1 = coords_sub(_NL_SR2_2b_var._position_absolute, _NL_SR2_2c_var._position_absolute); _NL_SR2_2c_var._position_relative = rot_apply(_NL_SR2_2c_var._rotation_absolute, tc1); } /* NL_SR2_2c=Guide_gravity() AT ROTATED */ DEBUG_COMPONENT("NL_SR2_2c", _NL_SR2_2c_var._position_absolute, _NL_SR2_2c_var._rotation_absolute); instrument->_position_absolute[7] = _NL_SR2_2c_var._position_absolute; instrument->_position_relative[7] = _NL_SR2_2c_var._position_relative; instrument->counter_N[7] = instrument->counter_P[7] = instrument->counter_P2[7] = 0; instrument->counter_AbsorbProp[7]= 0; return(0); } /* _NL_SR2_2c_setpos */ /* component NL_SR2_3=Guide_gravity() SETTING, POSITION/ROTATION */ int _NL_SR2_3_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_NL_SR2_3_setpos] component NL_SR2_3=Guide_gravity() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Guide_gravity.comp:341]"); stracpy(_NL_SR2_3_var._name, "NL_SR2_3", 16384); stracpy(_NL_SR2_3_var._type, "Guide_gravity", 16384); _NL_SR2_3_var._index=8; _NL_SR2_3_var._parameters.w1 = 0.107; _NL_SR2_3_var._parameters.h1 = 0.135; _NL_SR2_3_var._parameters.w2 = 0.107; _NL_SR2_3_var._parameters.h2 = 0.138; _NL_SR2_3_var._parameters.l = 0.180; _NL_SR2_3_var._parameters.R0 = 0.99; _NL_SR2_3_var._parameters.Qc = 0.02174; _NL_SR2_3_var._parameters.alpha = 3.0; _NL_SR2_3_var._parameters.m = 1.0; _NL_SR2_3_var._parameters.W = 0.001; _NL_SR2_3_var._parameters.nslit = 1; _NL_SR2_3_var._parameters.d = 0.0005; _NL_SR2_3_var._parameters.mleft = 2.0; _NL_SR2_3_var._parameters.mright = 2.0; _NL_SR2_3_var._parameters.mtop = 0; _NL_SR2_3_var._parameters.mbottom = 0; _NL_SR2_3_var._parameters.nhslit = 1; _NL_SR2_3_var._parameters.G = 0; _NL_SR2_3_var._parameters.aleft = -1; _NL_SR2_3_var._parameters.aright = -1; _NL_SR2_3_var._parameters.atop = -1; _NL_SR2_3_var._parameters.abottom = -1; _NL_SR2_3_var._parameters.wavy = 0; _NL_SR2_3_var._parameters.wavy_z = 0; _NL_SR2_3_var._parameters.wavy_tb = 0; _NL_SR2_3_var._parameters.wavy_lr = 0; _NL_SR2_3_var._parameters.chamfers = 0; _NL_SR2_3_var._parameters.chamfers_z = 0; _NL_SR2_3_var._parameters.chamfers_lr = 0; _NL_SR2_3_var._parameters.chamfers_tb = 0; _NL_SR2_3_var._parameters.nelements = 1; _NL_SR2_3_var._parameters.nu = 0; _NL_SR2_3_var._parameters.phase = 0; if("NULL" && strlen("NULL")) stracpy(_NL_SR2_3_var._parameters.reflect, "NULL" ? "NULL" : "", 16384); else _NL_SR2_3_var._parameters.reflect[0]='\0'; /* component NL_SR2_3=Guide_gravity() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PrimaryBeam_var._rotation_absolute, _NL_SR2_3_var._rotation_absolute); rot_transpose(_NL_SR2_2c_var._rotation_absolute, tr1); rot_mul(_NL_SR2_3_var._rotation_absolute, tr1, _NL_SR2_3_var._rotation_relative); _NL_SR2_3_var._rotation_is_identity = rot_test_identity(_NL_SR2_3_var._rotation_relative); tc1 = coords_set( 0, 0, 3.5460); rot_transpose(_PrimaryBeam_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _NL_SR2_3_var._position_absolute = coords_add(_PrimaryBeam_var._position_absolute, tc2); tc1 = coords_sub(_NL_SR2_2c_var._position_absolute, _NL_SR2_3_var._position_absolute); _NL_SR2_3_var._position_relative = rot_apply(_NL_SR2_3_var._rotation_absolute, tc1); } /* NL_SR2_3=Guide_gravity() AT ROTATED */ DEBUG_COMPONENT("NL_SR2_3", _NL_SR2_3_var._position_absolute, _NL_SR2_3_var._rotation_absolute); instrument->_position_absolute[8] = _NL_SR2_3_var._position_absolute; instrument->_position_relative[8] = _NL_SR2_3_var._position_relative; instrument->counter_N[8] = instrument->counter_P[8] = instrument->counter_P2[8] = 0; instrument->counter_AbsorbProp[8]= 0; return(0); } /* _NL_SR2_3_setpos */ /* component SR2_Beamportwindow=Al_window() SETTING, POSITION/ROTATION */ int _SR2_Beamportwindow_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_SR2_Beamportwindow_setpos] component SR2_Beamportwindow=Al_window() SETTING [Al_window:0]"); stracpy(_SR2_Beamportwindow_var._name, "SR2_Beamportwindow", 16384); stracpy(_SR2_Beamportwindow_var._type, "Al_window", 16384); _SR2_Beamportwindow_var._index=9; _SR2_Beamportwindow_var._parameters.thickness = 0.003; /* component SR2_Beamportwindow=Al_window() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PrimaryBeam_var._rotation_absolute, _SR2_Beamportwindow_var._rotation_absolute); rot_transpose(_NL_SR2_3_var._rotation_absolute, tr1); rot_mul(_SR2_Beamportwindow_var._rotation_absolute, tr1, _SR2_Beamportwindow_var._rotation_relative); _SR2_Beamportwindow_var._rotation_is_identity = rot_test_identity(_SR2_Beamportwindow_var._rotation_relative); tc1 = coords_set( 0, 0, 3.8100); rot_transpose(_PrimaryBeam_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _SR2_Beamportwindow_var._position_absolute = coords_add(_PrimaryBeam_var._position_absolute, tc2); tc1 = coords_sub(_NL_SR2_3_var._position_absolute, _SR2_Beamportwindow_var._position_absolute); _SR2_Beamportwindow_var._position_relative = rot_apply(_SR2_Beamportwindow_var._rotation_absolute, tc1); } /* SR2_Beamportwindow=Al_window() AT ROTATED */ DEBUG_COMPONENT("SR2_Beamportwindow", _SR2_Beamportwindow_var._position_absolute, _SR2_Beamportwindow_var._rotation_absolute); instrument->_position_absolute[9] = _SR2_Beamportwindow_var._position_absolute; instrument->_position_relative[9] = _SR2_Beamportwindow_var._position_relative; instrument->counter_N[9] = instrument->counter_P[9] = instrument->counter_P2[9] = 0; instrument->counter_AbsorbProp[9]= 0; return(0); } /* _SR2_Beamportwindow_setpos */ /* component SR2_eob=Arm() SETTING, POSITION/ROTATION */ int _SR2_eob_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_SR2_eob_setpos] component SR2_eob=Arm() SETTING [Arm:0]"); stracpy(_SR2_eob_var._name, "SR2_eob", 16384); stracpy(_SR2_eob_var._type, "Arm", 16384); _SR2_eob_var._index=10; /* component SR2_eob=Arm() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _SR2_Beamportwindow_var._rotation_absolute, _SR2_eob_var._rotation_absolute); rot_transpose(_SR2_Beamportwindow_var._rotation_absolute, tr1); rot_mul(_SR2_eob_var._rotation_absolute, tr1, _SR2_eob_var._rotation_relative); _SR2_eob_var._rotation_is_identity = rot_test_identity(_SR2_eob_var._rotation_relative); tc1 = coords_set( 0, 0, 0.0031); rot_transpose(_SR2_Beamportwindow_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _SR2_eob_var._position_absolute = coords_add(_SR2_Beamportwindow_var._position_absolute, tc2); tc1 = coords_sub(_SR2_Beamportwindow_var._position_absolute, _SR2_eob_var._position_absolute); _SR2_eob_var._position_relative = rot_apply(_SR2_eob_var._rotation_absolute, tc1); } /* SR2_eob=Arm() AT ROTATED */ DEBUG_COMPONENT("SR2_eob", _SR2_eob_var._position_absolute, _SR2_eob_var._rotation_absolute); instrument->_position_absolute[10] = _SR2_eob_var._position_absolute; instrument->_position_relative[10] = _SR2_eob_var._position_relative; instrument->counter_N[10] = instrument->counter_P[10] = instrument->counter_P2[10] = 0; instrument->counter_AbsorbProp[10]= 0; return(0); } /* _SR2_eob_setpos */ /* component PANDA_ca1=Collimator_linear() SETTING, POSITION/ROTATION */ int _PANDA_ca1_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PANDA_ca1_setpos] component PANDA_ca1=Collimator_linear() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Collimator_linear.comp:55]"); stracpy(_PANDA_ca1_var._name, "PANDA_ca1", 16384); stracpy(_PANDA_ca1_var._type, "Collimator_linear", 16384); _PANDA_ca1_var._index=11; _PANDA_ca1_var._parameters.xmin = -0.02; _PANDA_ca1_var._parameters.xmax = 0.02; _PANDA_ca1_var._parameters.ymin = -0.05; _PANDA_ca1_var._parameters.ymax = 0.05; _PANDA_ca1_var._parameters.xwidth = 0.108; _PANDA_ca1_var._parameters.yheight = 0.160; _PANDA_ca1_var._parameters.length = 0.50; _PANDA_ca1_var._parameters.divergence = ca1_div; _PANDA_ca1_var._parameters.transmission = 1; _PANDA_ca1_var._parameters.divergenceV = 0; /* component PANDA_ca1=Collimator_linear() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _SR2_eob_var._rotation_absolute, _PANDA_ca1_var._rotation_absolute); rot_transpose(_SR2_eob_var._rotation_absolute, tr1); rot_mul(_PANDA_ca1_var._rotation_absolute, tr1, _PANDA_ca1_var._rotation_relative); _PANDA_ca1_var._rotation_is_identity = rot_test_identity(_PANDA_ca1_var._rotation_relative); tc1 = coords_set( 0, 0, 0.1000); rot_transpose(_SR2_eob_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PANDA_ca1_var._position_absolute = coords_add(_SR2_eob_var._position_absolute, tc2); tc1 = coords_sub(_SR2_eob_var._position_absolute, _PANDA_ca1_var._position_absolute); _PANDA_ca1_var._position_relative = rot_apply(_PANDA_ca1_var._rotation_absolute, tc1); } /* PANDA_ca1=Collimator_linear() AT ROTATED */ DEBUG_COMPONENT("PANDA_ca1", _PANDA_ca1_var._position_absolute, _PANDA_ca1_var._rotation_absolute); instrument->_position_absolute[11] = _PANDA_ca1_var._position_absolute; instrument->_position_relative[11] = _PANDA_ca1_var._position_relative; instrument->counter_N[11] = instrument->counter_P[11] = instrument->counter_P2[11] = 0; instrument->counter_AbsorbProp[11]= 0; return(0); } /* _PANDA_ca1_setpos */ /* component PANDA_sapphire=Filter_gen() SETTING, POSITION/ROTATION */ int _PANDA_sapphire_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PANDA_sapphire_setpos] component PANDA_sapphire=Filter_gen() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Filter_gen.comp:126]"); stracpy(_PANDA_sapphire_var._name, "PANDA_sapphire", 16384); stracpy(_PANDA_sapphire_var._type, "Filter_gen", 16384); _PANDA_sapphire_var._index=12; if("Al2O3_sapphire.trm" && strlen("Al2O3_sapphire.trm")) stracpy(_PANDA_sapphire_var._parameters.filename, "Al2O3_sapphire.trm" ? "Al2O3_sapphire.trm" : "", 16384); else _PANDA_sapphire_var._parameters.filename[0]='\0'; _PANDA_sapphire_var._parameters.options[0]='\0'; _PANDA_sapphire_var._parameters.xmin = -0.05; _PANDA_sapphire_var._parameters.xmax = 0.05; _PANDA_sapphire_var._parameters.ymin = -0.05; _PANDA_sapphire_var._parameters.ymax = 0.05; _PANDA_sapphire_var._parameters.xwidth = 0; _PANDA_sapphire_var._parameters.yheight = 0; _PANDA_sapphire_var._parameters.thickness = 0.86; _PANDA_sapphire_var._parameters.scaling = 1; _PANDA_sapphire_var._parameters.verbose = 0; /* component PANDA_sapphire=Filter_gen() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _SR2_eob_var._rotation_absolute, _PANDA_sapphire_var._rotation_absolute); rot_transpose(_PANDA_ca1_var._rotation_absolute, tr1); rot_mul(_PANDA_sapphire_var._rotation_absolute, tr1, _PANDA_sapphire_var._rotation_relative); _PANDA_sapphire_var._rotation_is_identity = rot_test_identity(_PANDA_sapphire_var._rotation_relative); tc1 = coords_set( 0, 0, 0.9000); rot_transpose(_SR2_eob_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PANDA_sapphire_var._position_absolute = coords_add(_SR2_eob_var._position_absolute, tc2); tc1 = coords_sub(_PANDA_ca1_var._position_absolute, _PANDA_sapphire_var._position_absolute); _PANDA_sapphire_var._position_relative = rot_apply(_PANDA_sapphire_var._rotation_absolute, tc1); } /* PANDA_sapphire=Filter_gen() AT ROTATED */ DEBUG_COMPONENT("PANDA_sapphire", _PANDA_sapphire_var._position_absolute, _PANDA_sapphire_var._rotation_absolute); instrument->_position_absolute[12] = _PANDA_sapphire_var._position_absolute; instrument->_position_relative[12] = _PANDA_sapphire_var._position_relative; instrument->counter_N[12] = instrument->counter_P[12] = instrument->counter_P2[12] = 0; instrument->counter_AbsorbProp[12]= 0; return(0); } /* _PANDA_sapphire_setpos */ /* component sk1_in=Slit() SETTING, POSITION/ROTATION */ int _sk1_in_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_sk1_in_setpos] component sk1_in=Slit() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Slit.comp:50]"); stracpy(_sk1_in_var._name, "sk1_in", 16384); stracpy(_sk1_in_var._type, "Slit", 16384); _sk1_in_var._index=13; _sk1_in_var._parameters.xmin = 0; _sk1_in_var._parameters.xmax = 0; _sk1_in_var._parameters.ymin = 0; _sk1_in_var._parameters.ymax = 0; _sk1_in_var._parameters.radius = 0; _sk1_in_var._parameters.xwidth = 0.11; _sk1_in_var._parameters.yheight = 0.15; /* component sk1_in=Slit() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _SR2_eob_var._rotation_absolute, _sk1_in_var._rotation_absolute); rot_transpose(_PANDA_sapphire_var._rotation_absolute, tr1); rot_mul(_sk1_in_var._rotation_absolute, tr1, _sk1_in_var._rotation_relative); _sk1_in_var._rotation_is_identity = rot_test_identity(_sk1_in_var._rotation_relative); tc1 = coords_set( 0, 0, 1.0100); rot_transpose(_SR2_eob_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _sk1_in_var._position_absolute = coords_add(_SR2_eob_var._position_absolute, tc2); tc1 = coords_sub(_PANDA_sapphire_var._position_absolute, _sk1_in_var._position_absolute); _sk1_in_var._position_relative = rot_apply(_sk1_in_var._rotation_absolute, tc1); } /* sk1_in=Slit() AT ROTATED */ DEBUG_COMPONENT("sk1_in", _sk1_in_var._position_absolute, _sk1_in_var._rotation_absolute); instrument->_position_absolute[13] = _sk1_in_var._position_absolute; instrument->_position_relative[13] = _sk1_in_var._position_relative; instrument->counter_N[13] = instrument->counter_P[13] = instrument->counter_P2[13] = 0; instrument->counter_AbsorbProp[13]= 0; return(0); } /* _sk1_in_setpos */ /* component sk1_out=Slit() SETTING, POSITION/ROTATION */ int _sk1_out_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_sk1_out_setpos] component sk1_out=Slit() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Slit.comp:50]"); stracpy(_sk1_out_var._name, "sk1_out", 16384); stracpy(_sk1_out_var._type, "Slit", 16384); _sk1_out_var._index=14; _sk1_out_var._parameters.xmin = 0; _sk1_out_var._parameters.xmax = 0; _sk1_out_var._parameters.ymin = 0; _sk1_out_var._parameters.ymax = 0; _sk1_out_var._parameters.radius = 0; _sk1_out_var._parameters.xwidth = 0.09; _sk1_out_var._parameters.yheight = 0.180; /* component sk1_out=Slit() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _SR2_eob_var._rotation_absolute, _sk1_out_var._rotation_absolute); rot_transpose(_sk1_in_var._rotation_absolute, tr1); rot_mul(_sk1_out_var._rotation_absolute, tr1, _sk1_out_var._rotation_relative); _sk1_out_var._rotation_is_identity = rot_test_identity(_sk1_out_var._rotation_relative); tc1 = coords_set( 0, 0, 2.0300); rot_transpose(_SR2_eob_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _sk1_out_var._position_absolute = coords_add(_SR2_eob_var._position_absolute, tc2); tc1 = coords_sub(_sk1_in_var._position_absolute, _sk1_out_var._position_absolute); _sk1_out_var._position_relative = rot_apply(_sk1_out_var._rotation_absolute, tc1); } /* sk1_out=Slit() AT ROTATED */ DEBUG_COMPONENT("sk1_out", _sk1_out_var._position_absolute, _sk1_out_var._rotation_absolute); instrument->_position_absolute[14] = _sk1_out_var._position_absolute; instrument->_position_relative[14] = _sk1_out_var._position_relative; instrument->counter_N[14] = instrument->counter_P[14] = instrument->counter_P2[14] = 0; instrument->counter_AbsorbProp[14]= 0; return(0); } /* _sk1_out_setpos */ /* component PANDA_ms1=Slit() SETTING, POSITION/ROTATION */ int _PANDA_ms1_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PANDA_ms1_setpos] component PANDA_ms1=Slit() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Slit.comp:50]"); stracpy(_PANDA_ms1_var._name, "PANDA_ms1", 16384); stracpy(_PANDA_ms1_var._type, "Slit", 16384); _PANDA_ms1_var._index=15; _PANDA_ms1_var._parameters.xmin = 0; _PANDA_ms1_var._parameters.xmax = 0; _PANDA_ms1_var._parameters.ymin = 0; _PANDA_ms1_var._parameters.ymax = 0; _PANDA_ms1_var._parameters.radius = 0; _PANDA_ms1_var._parameters.xwidth = _instrument_var._parameters.ms1; _PANDA_ms1_var._parameters.yheight = 0.180; /* component PANDA_ms1=Slit() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _SR2_eob_var._rotation_absolute, _PANDA_ms1_var._rotation_absolute); rot_transpose(_sk1_out_var._rotation_absolute, tr1); rot_mul(_PANDA_ms1_var._rotation_absolute, tr1, _PANDA_ms1_var._rotation_relative); _PANDA_ms1_var._rotation_is_identity = rot_test_identity(_PANDA_ms1_var._rotation_relative); tc1 = coords_set( 0, 0, 2.1800); rot_transpose(_SR2_eob_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PANDA_ms1_var._position_absolute = coords_add(_SR2_eob_var._position_absolute, tc2); tc1 = coords_sub(_sk1_out_var._position_absolute, _PANDA_ms1_var._position_absolute); _PANDA_ms1_var._position_relative = rot_apply(_PANDA_ms1_var._rotation_absolute, tc1); } /* PANDA_ms1=Slit() AT ROTATED */ DEBUG_COMPONENT("PANDA_ms1", _PANDA_ms1_var._position_absolute, _PANDA_ms1_var._rotation_absolute); instrument->_position_absolute[15] = _PANDA_ms1_var._position_absolute; instrument->_position_relative[15] = _PANDA_ms1_var._position_relative; instrument->counter_N[15] = instrument->counter_P[15] = instrument->counter_P2[15] = 0; instrument->counter_AbsorbProp[15]= 0; return(0); } /* _PANDA_ms1_setpos */ /* component sk2_in=Slit() SETTING, POSITION/ROTATION */ int _sk2_in_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_sk2_in_setpos] component sk2_in=Slit() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Slit.comp:50]"); stracpy(_sk2_in_var._name, "sk2_in", 16384); stracpy(_sk2_in_var._type, "Slit", 16384); _sk2_in_var._index=16; _sk2_in_var._parameters.xmin = 0; _sk2_in_var._parameters.xmax = 0; _sk2_in_var._parameters.ymin = 0; _sk2_in_var._parameters.ymax = 0; _sk2_in_var._parameters.radius = 0; _sk2_in_var._parameters.xwidth = 0.050; _sk2_in_var._parameters.yheight = 0.180; /* component sk2_in=Slit() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _SR2_eob_var._rotation_absolute, _sk2_in_var._rotation_absolute); rot_transpose(_PANDA_ms1_var._rotation_absolute, tr1); rot_mul(_sk2_in_var._rotation_absolute, tr1, _sk2_in_var._rotation_relative); _sk2_in_var._rotation_is_identity = rot_test_identity(_sk2_in_var._rotation_relative); tc1 = coords_set( 0, 0, 2.4760); rot_transpose(_SR2_eob_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _sk2_in_var._position_absolute = coords_add(_SR2_eob_var._position_absolute, tc2); tc1 = coords_sub(_PANDA_ms1_var._position_absolute, _sk2_in_var._position_absolute); _sk2_in_var._position_relative = rot_apply(_sk2_in_var._rotation_absolute, tc1); } /* sk2_in=Slit() AT ROTATED */ DEBUG_COMPONENT("sk2_in", _sk2_in_var._position_absolute, _sk2_in_var._rotation_absolute); instrument->_position_absolute[16] = _sk2_in_var._position_absolute; instrument->_position_relative[16] = _sk2_in_var._position_relative; instrument->counter_N[16] = instrument->counter_P[16] = instrument->counter_P2[16] = 0; instrument->counter_AbsorbProp[16]= 0; return(0); } /* _sk2_in_setpos */ /* component sk2_out=Slit() SETTING, POSITION/ROTATION */ int _sk2_out_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_sk2_out_setpos] component sk2_out=Slit() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Slit.comp:50]"); stracpy(_sk2_out_var._name, "sk2_out", 16384); stracpy(_sk2_out_var._type, "Slit", 16384); _sk2_out_var._index=17; _sk2_out_var._parameters.xmin = 0; _sk2_out_var._parameters.xmax = 0; _sk2_out_var._parameters.ymin = 0; _sk2_out_var._parameters.ymax = 0; _sk2_out_var._parameters.radius = 0; _sk2_out_var._parameters.xwidth = 0.070; _sk2_out_var._parameters.yheight = 0.200; /* component sk2_out=Slit() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _SR2_eob_var._rotation_absolute, _sk2_out_var._rotation_absolute); rot_transpose(_sk2_in_var._rotation_absolute, tr1); rot_mul(_sk2_out_var._rotation_absolute, tr1, _sk2_out_var._rotation_relative); _sk2_out_var._rotation_is_identity = rot_test_identity(_sk2_out_var._rotation_relative); tc1 = coords_set( 0, 0, 2.9360); rot_transpose(_SR2_eob_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _sk2_out_var._position_absolute = coords_add(_SR2_eob_var._position_absolute, tc2); tc1 = coords_sub(_sk2_in_var._position_absolute, _sk2_out_var._position_absolute); _sk2_out_var._position_relative = rot_apply(_sk2_out_var._rotation_absolute, tc1); } /* sk2_out=Slit() AT ROTATED */ DEBUG_COMPONENT("sk2_out", _sk2_out_var._position_absolute, _sk2_out_var._rotation_absolute); instrument->_position_absolute[17] = _sk2_out_var._position_absolute; instrument->_position_relative[17] = _sk2_out_var._position_relative; instrument->counter_N[17] = instrument->counter_P[17] = instrument->counter_P2[17] = 0; instrument->counter_AbsorbProp[17]= 0; return(0); } /* _sk2_out_setpos */ /* component PSD_PrimBeam=PSD_monitor() SETTING, POSITION/ROTATION */ int _PSD_PrimBeam_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PSD_PrimBeam_setpos] component PSD_PrimBeam=PSD_monitor() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/PSD_monitor.comp:62]"); stracpy(_PSD_PrimBeam_var._name, "PSD_PrimBeam", 16384); stracpy(_PSD_PrimBeam_var._type, "PSD_monitor", 16384); _PSD_PrimBeam_var._index=18; _PSD_PrimBeam_var._parameters.nx = 80; _PSD_PrimBeam_var._parameters.ny = 200; if("PSD_PrimBeam.psd" && strlen("PSD_PrimBeam.psd")) stracpy(_PSD_PrimBeam_var._parameters.filename, "PSD_PrimBeam.psd" ? "PSD_PrimBeam.psd" : "", 16384); else _PSD_PrimBeam_var._parameters.filename[0]='\0'; _PSD_PrimBeam_var._parameters.xmin = -0.04; _PSD_PrimBeam_var._parameters.xmax = 0.04; _PSD_PrimBeam_var._parameters.ymin = -0.10; _PSD_PrimBeam_var._parameters.ymax = 0.10; _PSD_PrimBeam_var._parameters.xwidth = 0; _PSD_PrimBeam_var._parameters.yheight = 0; _PSD_PrimBeam_var._parameters.restore_neutron = 1; _PSD_PrimBeam_var._parameters.nowritefile = 0; /* component PSD_PrimBeam=PSD_monitor() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _sk2_out_var._rotation_absolute, _PSD_PrimBeam_var._rotation_absolute); rot_transpose(_sk2_out_var._rotation_absolute, tr1); rot_mul(_PSD_PrimBeam_var._rotation_absolute, tr1, _PSD_PrimBeam_var._rotation_relative); _PSD_PrimBeam_var._rotation_is_identity = rot_test_identity(_PSD_PrimBeam_var._rotation_relative); tc1 = coords_set( 0, 0, 0.0001); rot_transpose(_sk2_out_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PSD_PrimBeam_var._position_absolute = coords_add(_sk2_out_var._position_absolute, tc2); tc1 = coords_sub(_sk2_out_var._position_absolute, _PSD_PrimBeam_var._position_absolute); _PSD_PrimBeam_var._position_relative = rot_apply(_PSD_PrimBeam_var._rotation_absolute, tc1); } /* PSD_PrimBeam=PSD_monitor() AT ROTATED */ DEBUG_COMPONENT("PSD_PrimBeam", _PSD_PrimBeam_var._position_absolute, _PSD_PrimBeam_var._rotation_absolute); instrument->_position_absolute[18] = _PSD_PrimBeam_var._position_absolute; instrument->_position_relative[18] = _PSD_PrimBeam_var._position_relative; instrument->counter_N[18] = instrument->counter_P[18] = instrument->counter_P2[18] = 0; instrument->counter_AbsorbProp[18]= 0; return(0); } /* _PSD_PrimBeam_setpos */ /* component LAM_PrimBeam=L_monitor() SETTING, POSITION/ROTATION */ int _LAM_PrimBeam_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_LAM_PrimBeam_setpos] component LAM_PrimBeam=L_monitor() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/L_monitor.comp:65]"); stracpy(_LAM_PrimBeam_var._name, "LAM_PrimBeam", 16384); stracpy(_LAM_PrimBeam_var._type, "L_monitor", 16384); _LAM_PrimBeam_var._index=19; _LAM_PrimBeam_var._parameters.nL = 100; if("LAM_PrimBeam.L" && strlen("LAM_PrimBeam.L")) stracpy(_LAM_PrimBeam_var._parameters.filename, "LAM_PrimBeam.L" ? "LAM_PrimBeam.L" : "", 16384); else _LAM_PrimBeam_var._parameters.filename[0]='\0'; _LAM_PrimBeam_var._parameters.xmin = -0.04; _LAM_PrimBeam_var._parameters.xmax = 0.04; _LAM_PrimBeam_var._parameters.ymin = -0.15; _LAM_PrimBeam_var._parameters.ymax = 0.15; _LAM_PrimBeam_var._parameters.xwidth = 0; _LAM_PrimBeam_var._parameters.yheight = 0; _LAM_PrimBeam_var._parameters.Lmin = MINLam; _LAM_PrimBeam_var._parameters.Lmax = MAXLam; _LAM_PrimBeam_var._parameters.restore_neutron = 1; /* component LAM_PrimBeam=L_monitor() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PSD_PrimBeam_var._rotation_absolute, _LAM_PrimBeam_var._rotation_absolute); rot_transpose(_PSD_PrimBeam_var._rotation_absolute, tr1); rot_mul(_LAM_PrimBeam_var._rotation_absolute, tr1, _LAM_PrimBeam_var._rotation_relative); _LAM_PrimBeam_var._rotation_is_identity = rot_test_identity(_LAM_PrimBeam_var._rotation_relative); tc1 = coords_set( 0, 0, 0.0001); rot_transpose(_PSD_PrimBeam_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _LAM_PrimBeam_var._position_absolute = coords_add(_PSD_PrimBeam_var._position_absolute, tc2); tc1 = coords_sub(_PSD_PrimBeam_var._position_absolute, _LAM_PrimBeam_var._position_absolute); _LAM_PrimBeam_var._position_relative = rot_apply(_LAM_PrimBeam_var._rotation_absolute, tc1); } /* LAM_PrimBeam=L_monitor() AT ROTATED */ DEBUG_COMPONENT("LAM_PrimBeam", _LAM_PrimBeam_var._position_absolute, _LAM_PrimBeam_var._rotation_absolute); instrument->_position_absolute[19] = _LAM_PrimBeam_var._position_absolute; instrument->_position_relative[19] = _LAM_PrimBeam_var._position_relative; instrument->counter_N[19] = instrument->counter_P[19] = instrument->counter_P2[19] = 0; instrument->counter_AbsorbProp[19]= 0; return(0); } /* _LAM_PrimBeam_setpos */ /* component DIV_PrimBeam=Divergence_monitor() SETTING, POSITION/ROTATION */ int _DIV_PrimBeam_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_DIV_PrimBeam_setpos] component DIV_PrimBeam=Divergence_monitor() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/Divergence_monitor.comp:71]"); stracpy(_DIV_PrimBeam_var._name, "DIV_PrimBeam", 16384); stracpy(_DIV_PrimBeam_var._type, "Divergence_monitor", 16384); _DIV_PrimBeam_var._index=20; _DIV_PrimBeam_var._parameters.nh = 40; _DIV_PrimBeam_var._parameters.nv = 40; if("DIV_PrimBeam.dat" && strlen("DIV_PrimBeam.dat")) stracpy(_DIV_PrimBeam_var._parameters.filename, "DIV_PrimBeam.dat" ? "DIV_PrimBeam.dat" : "", 16384); else _DIV_PrimBeam_var._parameters.filename[0]='\0'; _DIV_PrimBeam_var._parameters.xmin = -0.04; _DIV_PrimBeam_var._parameters.xmax = 0.04; _DIV_PrimBeam_var._parameters.ymin = -0.15; _DIV_PrimBeam_var._parameters.ymax = 0.15; _DIV_PrimBeam_var._parameters.xwidth = 0; _DIV_PrimBeam_var._parameters.yheight = 0; _DIV_PrimBeam_var._parameters.maxdiv_h = 2; _DIV_PrimBeam_var._parameters.maxdiv_v = 2; _DIV_PrimBeam_var._parameters.restore_neutron = 1; _DIV_PrimBeam_var._parameters.nx = 0; _DIV_PrimBeam_var._parameters.ny = 0; _DIV_PrimBeam_var._parameters.nz = 1; /* component DIV_PrimBeam=Divergence_monitor() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _LAM_PrimBeam_var._rotation_absolute, _DIV_PrimBeam_var._rotation_absolute); rot_transpose(_LAM_PrimBeam_var._rotation_absolute, tr1); rot_mul(_DIV_PrimBeam_var._rotation_absolute, tr1, _DIV_PrimBeam_var._rotation_relative); _DIV_PrimBeam_var._rotation_is_identity = rot_test_identity(_DIV_PrimBeam_var._rotation_relative); tc1 = coords_set( 0, 0, 0.0001); rot_transpose(_LAM_PrimBeam_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _DIV_PrimBeam_var._position_absolute = coords_add(_LAM_PrimBeam_var._position_absolute, tc2); tc1 = coords_sub(_LAM_PrimBeam_var._position_absolute, _DIV_PrimBeam_var._position_absolute); _DIV_PrimBeam_var._position_relative = rot_apply(_DIV_PrimBeam_var._rotation_absolute, tc1); } /* DIV_PrimBeam=Divergence_monitor() AT ROTATED */ DEBUG_COMPONENT("DIV_PrimBeam", _DIV_PrimBeam_var._position_absolute, _DIV_PrimBeam_var._rotation_absolute); instrument->_position_absolute[20] = _DIV_PrimBeam_var._position_absolute; instrument->_position_relative[20] = _DIV_PrimBeam_var._position_relative; instrument->counter_N[20] = instrument->counter_P[20] = instrument->counter_P2[20] = 0; instrument->counter_AbsorbProp[20]= 0; return(0); } /* _DIV_PrimBeam_setpos */ /* component PANDA_mth=Arm() SETTING, POSITION/ROTATION */ int _PANDA_mth_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PANDA_mth_setpos] component PANDA_mth=Arm() SETTING [Arm:0]"); stracpy(_PANDA_mth_var._name, "PANDA_mth", 16384); stracpy(_PANDA_mth_var._type, "Arm", 16384); _PANDA_mth_var._index=21; /* component PANDA_mth=Arm() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (180 - a1)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _SR2_eob_var._rotation_absolute, _PANDA_mth_var._rotation_absolute); rot_transpose(_DIV_PrimBeam_var._rotation_absolute, tr1); rot_mul(_PANDA_mth_var._rotation_absolute, tr1, _PANDA_mth_var._rotation_relative); _PANDA_mth_var._rotation_is_identity = rot_test_identity(_PANDA_mth_var._rotation_relative); tc1 = coords_set( 0, 0, 5.000); rot_transpose(_SR2_eob_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PANDA_mth_var._position_absolute = coords_add(_SR2_eob_var._position_absolute, tc2); tc1 = coords_sub(_DIV_PrimBeam_var._position_absolute, _PANDA_mth_var._position_absolute); _PANDA_mth_var._position_relative = rot_apply(_PANDA_mth_var._rotation_absolute, tc1); } /* PANDA_mth=Arm() AT ROTATED */ DEBUG_COMPONENT("PANDA_mth", _PANDA_mth_var._position_absolute, _PANDA_mth_var._rotation_absolute); instrument->_position_absolute[21] = _PANDA_mth_var._position_absolute; instrument->_position_relative[21] = _PANDA_mth_var._position_relative; instrument->counter_N[21] = instrument->counter_P[21] = instrument->counter_P2[21] = 0; instrument->counter_AbsorbProp[21]= 0; return(0); } /* _PANDA_mth_setpos */ /* component a_mono=Arm() SETTING, POSITION/ROTATION */ int _a_mono_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_a_mono_setpos] component a_mono=Arm() SETTING [Arm:0]"); stracpy(_a_mono_var._name, "a_mono", 16384); stracpy(_a_mono_var._type, "Arm", 16384); _a_mono_var._index=22; /* component a_mono=Arm() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (_instrument_var._parameters.mgy)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_mth_var._rotation_absolute, _a_mono_var._rotation_absolute); rot_transpose(_PANDA_mth_var._rotation_absolute, tr1); rot_mul(_a_mono_var._rotation_absolute, tr1, _a_mono_var._rotation_relative); _a_mono_var._rotation_is_identity = rot_test_identity(_a_mono_var._rotation_relative); tc1 = coords_set( _instrument_var._parameters.mty, 0, _instrument_var._parameters.mtx); rot_transpose(_PANDA_mth_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _a_mono_var._position_absolute = coords_add(_PANDA_mth_var._position_absolute, tc2); tc1 = coords_sub(_PANDA_mth_var._position_absolute, _a_mono_var._position_absolute); _a_mono_var._position_relative = rot_apply(_a_mono_var._rotation_absolute, tc1); } /* a_mono=Arm() AT ROTATED */ DEBUG_COMPONENT("a_mono", _a_mono_var._position_absolute, _a_mono_var._rotation_absolute); instrument->_position_absolute[22] = _a_mono_var._position_absolute; instrument->_position_relative[22] = _a_mono_var._position_relative; instrument->counter_N[22] = instrument->counter_P[22] = instrument->counter_P2[22] = 0; instrument->counter_AbsorbProp[22]= 0; return(0); } /* _a_mono_setpos */ /* component PG002_mono=Monochromator_curved() SETTING, POSITION/ROTATION */ int _PG002_mono_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PG002_mono_setpos] component PG002_mono=Monochromator_curved() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Monochromator_curved.comp:134]"); stracpy(_PG002_mono_var._name, "PG002_mono", 16384); stracpy(_PG002_mono_var._type, "Monochromator_curved", 16384); _PG002_mono_var._index=23; if("HOPG.rfl" && strlen("HOPG.rfl")) stracpy(_PG002_mono_var._parameters.reflect, "HOPG.rfl" ? "HOPG.rfl" : "", 16384); else _PG002_mono_var._parameters.reflect[0]='\0'; if("NULL" && strlen("NULL")) stracpy(_PG002_mono_var._parameters.transmit, "NULL" ? "NULL" : "", 16384); else _PG002_mono_var._parameters.transmit[0]='\0'; _PG002_mono_var._parameters.zwidth = 0.02; _PG002_mono_var._parameters.yheight = 0.018; _PG002_mono_var._parameters.gap = 0.002; _PG002_mono_var._parameters.NH = 11; _PG002_mono_var._parameters.NV = 11; _PG002_mono_var._parameters.mosaich = 30.0; _PG002_mono_var._parameters.mosaicv = 30.0; _PG002_mono_var._parameters.r0 = 0.7; _PG002_mono_var._parameters.t0 = 1.0; _PG002_mono_var._parameters.Q = 1.873; _PG002_mono_var._parameters.RV = _instrument_var._parameters.mfv; _PG002_mono_var._parameters.RH = _instrument_var._parameters.mfh; _PG002_mono_var._parameters.DM = 0; _PG002_mono_var._parameters.mosaic = 20; _PG002_mono_var._parameters.width = 0; _PG002_mono_var._parameters.height = 0; _PG002_mono_var._parameters.verbose = 0; _PG002_mono_var._parameters.order = 0; /* component PG002_mono=Monochromator_curved() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD); rot_mul(tr1, _a_mono_var._rotation_absolute, _PG002_mono_var._rotation_absolute); rot_transpose(_a_mono_var._rotation_absolute, tr1); rot_mul(_PG002_mono_var._rotation_absolute, tr1, _PG002_mono_var._rotation_relative); _PG002_mono_var._rotation_is_identity = rot_test_identity(_PG002_mono_var._rotation_relative); tc1 = coords_set( 0, 0, 0); rot_transpose(_a_mono_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PG002_mono_var._position_absolute = coords_add(_a_mono_var._position_absolute, tc2); tc1 = coords_sub(_a_mono_var._position_absolute, _PG002_mono_var._position_absolute); _PG002_mono_var._position_relative = rot_apply(_PG002_mono_var._rotation_absolute, tc1); } /* PG002_mono=Monochromator_curved() AT ROTATED */ DEBUG_COMPONENT("PG002_mono", _PG002_mono_var._position_absolute, _PG002_mono_var._rotation_absolute); instrument->_position_absolute[23] = _PG002_mono_var._position_absolute; instrument->_position_relative[23] = _PG002_mono_var._position_relative; instrument->counter_N[23] = instrument->counter_P[23] = instrument->counter_P2[23] = 0; instrument->counter_AbsorbProp[23]= 0; return(0); } /* _PG002_mono_setpos */ /* component PANDA_mtt=Arm() SETTING, POSITION/ROTATION */ int _PANDA_mtt_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PANDA_mtt_setpos] component PANDA_mtt=Arm() SETTING [Arm:0]"); stracpy(_PANDA_mtt_var._name, "PANDA_mtt", 16384); stracpy(_PANDA_mtt_var._type, "Arm", 16384); _PANDA_mtt_var._index=24; /* component PANDA_mtt=Arm() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (- a2)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PrimaryBeam_var._rotation_absolute, _PANDA_mtt_var._rotation_absolute); rot_transpose(_PG002_mono_var._rotation_absolute, tr1); rot_mul(_PANDA_mtt_var._rotation_absolute, tr1, _PANDA_mtt_var._rotation_relative); _PANDA_mtt_var._rotation_is_identity = rot_test_identity(_PANDA_mtt_var._rotation_relative); tc1 = coords_set( 0, 0, 0); rot_transpose(_PANDA_mth_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PANDA_mtt_var._position_absolute = coords_add(_PANDA_mth_var._position_absolute, tc2); tc1 = coords_sub(_PG002_mono_var._position_absolute, _PANDA_mtt_var._position_absolute); _PANDA_mtt_var._position_relative = rot_apply(_PANDA_mtt_var._rotation_absolute, tc1); } /* PANDA_mtt=Arm() AT ROTATED */ DEBUG_COMPONENT("PANDA_mtt", _PANDA_mtt_var._position_absolute, _PANDA_mtt_var._rotation_absolute); instrument->_position_absolute[24] = _PANDA_mtt_var._position_absolute; instrument->_position_relative[24] = _PANDA_mtt_var._position_relative; instrument->counter_N[24] = instrument->counter_P[24] = instrument->counter_P2[24] = 0; instrument->counter_AbsorbProp[24]= 0; return(0); } /* _PANDA_mtt_setpos */ /* component sk3_in=Slit() SETTING, POSITION/ROTATION */ int _sk3_in_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_sk3_in_setpos] component sk3_in=Slit() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Slit.comp:50]"); stracpy(_sk3_in_var._name, "sk3_in", 16384); stracpy(_sk3_in_var._type, "Slit", 16384); _sk3_in_var._index=25; _sk3_in_var._parameters.xmin = 0; _sk3_in_var._parameters.xmax = 0; _sk3_in_var._parameters.ymin = 0; _sk3_in_var._parameters.ymax = 0; _sk3_in_var._parameters.radius = 0; _sk3_in_var._parameters.xwidth = 0.136; _sk3_in_var._parameters.yheight = 0.174; /* component sk3_in=Slit() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_mtt_var._rotation_absolute, _sk3_in_var._rotation_absolute); rot_transpose(_PANDA_mtt_var._rotation_absolute, tr1); rot_mul(_sk3_in_var._rotation_absolute, tr1, _sk3_in_var._rotation_relative); _sk3_in_var._rotation_is_identity = rot_test_identity(_sk3_in_var._rotation_relative); tc1 = coords_set( 0, 0, 0.2660); rot_transpose(_PANDA_mtt_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _sk3_in_var._position_absolute = coords_add(_PANDA_mtt_var._position_absolute, tc2); tc1 = coords_sub(_PANDA_mtt_var._position_absolute, _sk3_in_var._position_absolute); _sk3_in_var._position_relative = rot_apply(_sk3_in_var._rotation_absolute, tc1); } /* sk3_in=Slit() AT ROTATED */ DEBUG_COMPONENT("sk3_in", _sk3_in_var._position_absolute, _sk3_in_var._rotation_absolute); instrument->_position_absolute[25] = _sk3_in_var._position_absolute; instrument->_position_relative[25] = _sk3_in_var._position_relative; instrument->counter_N[25] = instrument->counter_P[25] = instrument->counter_P2[25] = 0; instrument->counter_AbsorbProp[25]= 0; return(0); } /* _sk3_in_setpos */ /* component PANDA_ca2=Collimator_linear() SETTING, POSITION/ROTATION */ int _PANDA_ca2_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PANDA_ca2_setpos] component PANDA_ca2=Collimator_linear() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Collimator_linear.comp:55]"); stracpy(_PANDA_ca2_var._name, "PANDA_ca2", 16384); stracpy(_PANDA_ca2_var._type, "Collimator_linear", 16384); _PANDA_ca2_var._index=26; _PANDA_ca2_var._parameters.xmin = -0.02; _PANDA_ca2_var._parameters.xmax = 0.02; _PANDA_ca2_var._parameters.ymin = -0.05; _PANDA_ca2_var._parameters.ymax = 0.05; _PANDA_ca2_var._parameters.xwidth = 0.040; _PANDA_ca2_var._parameters.yheight = 0.120; _PANDA_ca2_var._parameters.length = 0.20; _PANDA_ca2_var._parameters.divergence = ca2_div; _PANDA_ca2_var._parameters.transmission = 1; _PANDA_ca2_var._parameters.divergenceV = 0; /* component PANDA_ca2=Collimator_linear() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_mtt_var._rotation_absolute, _PANDA_ca2_var._rotation_absolute); rot_transpose(_sk3_in_var._rotation_absolute, tr1); rot_mul(_PANDA_ca2_var._rotation_absolute, tr1, _PANDA_ca2_var._rotation_relative); _PANDA_ca2_var._rotation_is_identity = rot_test_identity(_PANDA_ca2_var._rotation_relative); tc1 = coords_set( 0, 0, 0.9000); rot_transpose(_PANDA_mtt_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PANDA_ca2_var._position_absolute = coords_add(_PANDA_mtt_var._position_absolute, tc2); tc1 = coords_sub(_sk3_in_var._position_absolute, _PANDA_ca2_var._position_absolute); _PANDA_ca2_var._position_relative = rot_apply(_PANDA_ca2_var._rotation_absolute, tc1); } /* PANDA_ca2=Collimator_linear() AT ROTATED */ DEBUG_COMPONENT("PANDA_ca2", _PANDA_ca2_var._position_absolute, _PANDA_ca2_var._rotation_absolute); instrument->_position_absolute[26] = _PANDA_ca2_var._position_absolute; instrument->_position_relative[26] = _PANDA_ca2_var._position_relative; instrument->counter_N[26] = instrument->counter_P[26] = instrument->counter_P2[26] = 0; instrument->counter_AbsorbProp[26]= 0; return(0); } /* _PANDA_ca2_setpos */ /* component sk3_out=Slit() SETTING, POSITION/ROTATION */ int _sk3_out_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_sk3_out_setpos] component sk3_out=Slit() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Slit.comp:50]"); stracpy(_sk3_out_var._name, "sk3_out", 16384); stracpy(_sk3_out_var._type, "Slit", 16384); _sk3_out_var._index=27; _sk3_out_var._parameters.xmin = 0; _sk3_out_var._parameters.xmax = 0; _sk3_out_var._parameters.ymin = 0; _sk3_out_var._parameters.ymax = 0; _sk3_out_var._parameters.radius = 0; _sk3_out_var._parameters.xwidth = 0.06; _sk3_out_var._parameters.yheight = 0.10; /* component sk3_out=Slit() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_mtt_var._rotation_absolute, _sk3_out_var._rotation_absolute); rot_transpose(_PANDA_ca2_var._rotation_absolute, tr1); rot_mul(_sk3_out_var._rotation_absolute, tr1, _sk3_out_var._rotation_relative); _sk3_out_var._rotation_is_identity = rot_test_identity(_sk3_out_var._rotation_relative); tc1 = coords_set( 0, 0, 1.1500); rot_transpose(_PANDA_mtt_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _sk3_out_var._position_absolute = coords_add(_PANDA_mtt_var._position_absolute, tc2); tc1 = coords_sub(_PANDA_ca2_var._position_absolute, _sk3_out_var._position_absolute); _sk3_out_var._position_relative = rot_apply(_sk3_out_var._rotation_absolute, tc1); } /* sk3_out=Slit() AT ROTATED */ DEBUG_COMPONENT("sk3_out", _sk3_out_var._position_absolute, _sk3_out_var._rotation_absolute); instrument->_position_absolute[27] = _sk3_out_var._position_absolute; instrument->_position_relative[27] = _sk3_out_var._position_relative; instrument->counter_N[27] = instrument->counter_P[27] = instrument->counter_P2[27] = 0; instrument->counter_AbsorbProp[27]= 0; return(0); } /* _sk3_out_setpos */ /* component PSD_mon1=PSD_monitor() SETTING, POSITION/ROTATION */ int _PSD_mon1_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PSD_mon1_setpos] component PSD_mon1=PSD_monitor() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/PSD_monitor.comp:62]"); stracpy(_PSD_mon1_var._name, "PSD_mon1", 16384); stracpy(_PSD_mon1_var._type, "PSD_monitor", 16384); _PSD_mon1_var._index=28; _PSD_mon1_var._parameters.nx = 80; _PSD_mon1_var._parameters.ny = 120; if("PSD_mon1.psd" && strlen("PSD_mon1.psd")) stracpy(_PSD_mon1_var._parameters.filename, "PSD_mon1.psd" ? "PSD_mon1.psd" : "", 16384); else _PSD_mon1_var._parameters.filename[0]='\0'; _PSD_mon1_var._parameters.xmin = -0.04; _PSD_mon1_var._parameters.xmax = 0.04; _PSD_mon1_var._parameters.ymin = -0.06; _PSD_mon1_var._parameters.ymax = 0.06; _PSD_mon1_var._parameters.xwidth = 0; _PSD_mon1_var._parameters.yheight = 0; _PSD_mon1_var._parameters.restore_neutron = 1; _PSD_mon1_var._parameters.nowritefile = 0; /* component PSD_mon1=PSD_monitor() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _sk3_out_var._rotation_absolute, _PSD_mon1_var._rotation_absolute); rot_transpose(_sk3_out_var._rotation_absolute, tr1); rot_mul(_PSD_mon1_var._rotation_absolute, tr1, _PSD_mon1_var._rotation_relative); _PSD_mon1_var._rotation_is_identity = rot_test_identity(_PSD_mon1_var._rotation_relative); tc1 = coords_set( 0, 0, 0.0001); rot_transpose(_sk3_out_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PSD_mon1_var._position_absolute = coords_add(_sk3_out_var._position_absolute, tc2); tc1 = coords_sub(_sk3_out_var._position_absolute, _PSD_mon1_var._position_absolute); _PSD_mon1_var._position_relative = rot_apply(_PSD_mon1_var._rotation_absolute, tc1); } /* PSD_mon1=PSD_monitor() AT ROTATED */ DEBUG_COMPONENT("PSD_mon1", _PSD_mon1_var._position_absolute, _PSD_mon1_var._rotation_absolute); instrument->_position_absolute[28] = _PSD_mon1_var._position_absolute; instrument->_position_relative[28] = _PSD_mon1_var._position_relative; instrument->counter_N[28] = instrument->counter_P[28] = instrument->counter_P2[28] = 0; instrument->counter_AbsorbProp[28]= 0; return(0); } /* _PSD_mon1_setpos */ /* component LAM_mon1=L_monitor() SETTING, POSITION/ROTATION */ int _LAM_mon1_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_LAM_mon1_setpos] component LAM_mon1=L_monitor() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/L_monitor.comp:65]"); stracpy(_LAM_mon1_var._name, "LAM_mon1", 16384); stracpy(_LAM_mon1_var._type, "L_monitor", 16384); _LAM_mon1_var._index=29; _LAM_mon1_var._parameters.nL = 100; if("LAM_mon1.L" && strlen("LAM_mon1.L")) stracpy(_LAM_mon1_var._parameters.filename, "LAM_mon1.L" ? "LAM_mon1.L" : "", 16384); else _LAM_mon1_var._parameters.filename[0]='\0'; _LAM_mon1_var._parameters.xmin = -0.04; _LAM_mon1_var._parameters.xmax = 0.04; _LAM_mon1_var._parameters.ymin = -0.06; _LAM_mon1_var._parameters.ymax = 0.06; _LAM_mon1_var._parameters.xwidth = 0; _LAM_mon1_var._parameters.yheight = 0; _LAM_mon1_var._parameters.Lmin = MINLam; _LAM_mon1_var._parameters.Lmax = MAXLam; _LAM_mon1_var._parameters.restore_neutron = 1; /* component LAM_mon1=L_monitor() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PSD_mon1_var._rotation_absolute, _LAM_mon1_var._rotation_absolute); rot_transpose(_PSD_mon1_var._rotation_absolute, tr1); rot_mul(_LAM_mon1_var._rotation_absolute, tr1, _LAM_mon1_var._rotation_relative); _LAM_mon1_var._rotation_is_identity = rot_test_identity(_LAM_mon1_var._rotation_relative); tc1 = coords_set( 0, 0, 0.0001); rot_transpose(_PSD_mon1_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _LAM_mon1_var._position_absolute = coords_add(_PSD_mon1_var._position_absolute, tc2); tc1 = coords_sub(_PSD_mon1_var._position_absolute, _LAM_mon1_var._position_absolute); _LAM_mon1_var._position_relative = rot_apply(_LAM_mon1_var._rotation_absolute, tc1); } /* LAM_mon1=L_monitor() AT ROTATED */ DEBUG_COMPONENT("LAM_mon1", _LAM_mon1_var._position_absolute, _LAM_mon1_var._rotation_absolute); instrument->_position_absolute[29] = _LAM_mon1_var._position_absolute; instrument->_position_relative[29] = _LAM_mon1_var._position_relative; instrument->counter_N[29] = instrument->counter_P[29] = instrument->counter_P2[29] = 0; instrument->counter_AbsorbProp[29]= 0; return(0); } /* _LAM_mon1_setpos */ /* component PANDA_ss1=Slit() SETTING, POSITION/ROTATION */ int _PANDA_ss1_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PANDA_ss1_setpos] component PANDA_ss1=Slit() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Slit.comp:50]"); stracpy(_PANDA_ss1_var._name, "PANDA_ss1", 16384); stracpy(_PANDA_ss1_var._type, "Slit", 16384); _PANDA_ss1_var._index=30; _PANDA_ss1_var._parameters.xmin = 0; _PANDA_ss1_var._parameters.xmax = 0; _PANDA_ss1_var._parameters.ymin = 0; _PANDA_ss1_var._parameters.ymax = 0; _PANDA_ss1_var._parameters.radius = 0; _PANDA_ss1_var._parameters.xwidth = _instrument_var._parameters.ss1_width; _PANDA_ss1_var._parameters.yheight = _instrument_var._parameters.ss1_height; /* component PANDA_ss1=Slit() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_mtt_var._rotation_absolute, _PANDA_ss1_var._rotation_absolute); rot_transpose(_LAM_mon1_var._rotation_absolute, tr1); rot_mul(_PANDA_ss1_var._rotation_absolute, tr1, _PANDA_ss1_var._rotation_relative); _PANDA_ss1_var._rotation_is_identity = rot_test_identity(_PANDA_ss1_var._rotation_relative); tc1 = coords_set( 0, 0, 1.7000); rot_transpose(_PANDA_mtt_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PANDA_ss1_var._position_absolute = coords_add(_PANDA_mtt_var._position_absolute, tc2); tc1 = coords_sub(_LAM_mon1_var._position_absolute, _PANDA_ss1_var._position_absolute); _PANDA_ss1_var._position_relative = rot_apply(_PANDA_ss1_var._rotation_absolute, tc1); } /* PANDA_ss1=Slit() AT ROTATED */ DEBUG_COMPONENT("PANDA_ss1", _PANDA_ss1_var._position_absolute, _PANDA_ss1_var._rotation_absolute); instrument->_position_absolute[30] = _PANDA_ss1_var._position_absolute; instrument->_position_relative[30] = _PANDA_ss1_var._position_relative; instrument->counter_N[30] = instrument->counter_P[30] = instrument->counter_P2[30] = 0; instrument->counter_AbsorbProp[30]= 0; return(0); } /* _PANDA_ss1_setpos */ /* component PSD_samplepos=PSD_monitor() SETTING, POSITION/ROTATION */ int _PSD_samplepos_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PSD_samplepos_setpos] component PSD_samplepos=PSD_monitor() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/PSD_monitor.comp:62]"); stracpy(_PSD_samplepos_var._name, "PSD_samplepos", 16384); stracpy(_PSD_samplepos_var._type, "PSD_monitor", 16384); _PSD_samplepos_var._index=31; _PSD_samplepos_var._parameters.nx = 100; _PSD_samplepos_var._parameters.ny = 200; if("PSD_samplepos.psd" && strlen("PSD_samplepos.psd")) stracpy(_PSD_samplepos_var._parameters.filename, "PSD_samplepos.psd" ? "PSD_samplepos.psd" : "", 16384); else _PSD_samplepos_var._parameters.filename[0]='\0'; _PSD_samplepos_var._parameters.xmin = -0.05; _PSD_samplepos_var._parameters.xmax = 0.05; _PSD_samplepos_var._parameters.ymin = -0.1; _PSD_samplepos_var._parameters.ymax = 0.1; _PSD_samplepos_var._parameters.xwidth = 0; _PSD_samplepos_var._parameters.yheight = 0; _PSD_samplepos_var._parameters.restore_neutron = 1; _PSD_samplepos_var._parameters.nowritefile = 0; /* component PSD_samplepos=PSD_monitor() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_mtt_var._rotation_absolute, _PSD_samplepos_var._rotation_absolute); rot_transpose(_PANDA_ss1_var._rotation_absolute, tr1); rot_mul(_PSD_samplepos_var._rotation_absolute, tr1, _PSD_samplepos_var._rotation_relative); _PSD_samplepos_var._rotation_is_identity = rot_test_identity(_PSD_samplepos_var._rotation_relative); tc1 = coords_set( 0, 0, 2.1000); rot_transpose(_PANDA_mtt_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PSD_samplepos_var._position_absolute = coords_add(_PANDA_mtt_var._position_absolute, tc2); tc1 = coords_sub(_PANDA_ss1_var._position_absolute, _PSD_samplepos_var._position_absolute); _PSD_samplepos_var._position_relative = rot_apply(_PSD_samplepos_var._rotation_absolute, tc1); } /* PSD_samplepos=PSD_monitor() AT ROTATED */ DEBUG_COMPONENT("PSD_samplepos", _PSD_samplepos_var._position_absolute, _PSD_samplepos_var._rotation_absolute); instrument->_position_absolute[31] = _PSD_samplepos_var._position_absolute; instrument->_position_relative[31] = _PSD_samplepos_var._position_relative; instrument->counter_N[31] = instrument->counter_P[31] = instrument->counter_P2[31] = 0; instrument->counter_AbsorbProp[31]= 0; return(0); } /* _PSD_samplepos_setpos */ /* component Mon_samplepos2=Monitor() SETTING, POSITION/ROTATION */ int _Mon_samplepos2_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_Mon_samplepos2_setpos] component Mon_samplepos2=Monitor() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/Monitor.comp:58]"); stracpy(_Mon_samplepos2_var._name, "Mon_samplepos2", 16384); stracpy(_Mon_samplepos2_var._type, "Monitor", 16384); _Mon_samplepos2_var._index=32; _Mon_samplepos2_var._parameters.xmin = -0.05; _Mon_samplepos2_var._parameters.xmax = 0.05; _Mon_samplepos2_var._parameters.ymin = -0.05; _Mon_samplepos2_var._parameters.ymax = 0.05; _Mon_samplepos2_var._parameters.xwidth = 0.01; _Mon_samplepos2_var._parameters.yheight = 0.02; _Mon_samplepos2_var._parameters.restore_neutron = 1; /* component Mon_samplepos2=Monitor() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_mtt_var._rotation_absolute, _Mon_samplepos2_var._rotation_absolute); rot_transpose(_PSD_samplepos_var._rotation_absolute, tr1); rot_mul(_Mon_samplepos2_var._rotation_absolute, tr1, _Mon_samplepos2_var._rotation_relative); _Mon_samplepos2_var._rotation_is_identity = rot_test_identity(_Mon_samplepos2_var._rotation_relative); tc1 = coords_set( 0, 0, 2.1000); rot_transpose(_PANDA_mtt_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _Mon_samplepos2_var._position_absolute = coords_add(_PANDA_mtt_var._position_absolute, tc2); tc1 = coords_sub(_PSD_samplepos_var._position_absolute, _Mon_samplepos2_var._position_absolute); _Mon_samplepos2_var._position_relative = rot_apply(_Mon_samplepos2_var._rotation_absolute, tc1); } /* Mon_samplepos2=Monitor() AT ROTATED */ DEBUG_COMPONENT("Mon_samplepos2", _Mon_samplepos2_var._position_absolute, _Mon_samplepos2_var._rotation_absolute); instrument->_position_absolute[32] = _Mon_samplepos2_var._position_absolute; instrument->_position_relative[32] = _Mon_samplepos2_var._position_relative; instrument->counter_N[32] = instrument->counter_P[32] = instrument->counter_P2[32] = 0; instrument->counter_AbsorbProp[32]= 0; return(0); } /* _Mon_samplepos2_setpos */ /* component PANDA_sth=Arm() SETTING, POSITION/ROTATION */ int _PANDA_sth_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PANDA_sth_setpos] component PANDA_sth=Arm() SETTING [Arm:0]"); stracpy(_PANDA_sth_var._name, "PANDA_sth", 16384); stracpy(_PANDA_sth_var._type, "Arm", 16384); _PANDA_sth_var._index=33; /* component PANDA_sth=Arm() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (a3)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_mtt_var._rotation_absolute, _PANDA_sth_var._rotation_absolute); rot_transpose(_Mon_samplepos2_var._rotation_absolute, tr1); rot_mul(_PANDA_sth_var._rotation_absolute, tr1, _PANDA_sth_var._rotation_relative); _PANDA_sth_var._rotation_is_identity = rot_test_identity(_PANDA_sth_var._rotation_relative); tc1 = coords_set( 0, 0, 2.1000); rot_transpose(_PANDA_mtt_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PANDA_sth_var._position_absolute = coords_add(_PANDA_mtt_var._position_absolute, tc2); tc1 = coords_sub(_Mon_samplepos2_var._position_absolute, _PANDA_sth_var._position_absolute); _PANDA_sth_var._position_relative = rot_apply(_PANDA_sth_var._rotation_absolute, tc1); } /* PANDA_sth=Arm() AT ROTATED */ DEBUG_COMPONENT("PANDA_sth", _PANDA_sth_var._position_absolute, _PANDA_sth_var._rotation_absolute); instrument->_position_absolute[33] = _PANDA_sth_var._position_absolute; instrument->_position_relative[33] = _PANDA_sth_var._position_relative; instrument->counter_N[33] = instrument->counter_P[33] = instrument->counter_P2[33] = 0; instrument->counter_AbsorbProp[33]= 0; return(0); } /* _PANDA_sth_setpos */ /* component sample=Arm() SETTING, POSITION/ROTATION */ int _sample_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_sample_setpos] component sample=Arm() SETTING [Arm:0]"); stracpy(_sample_var._name, "sample", 16384); stracpy(_sample_var._type, "Arm", 16384); _sample_var._index=34; /* component sample=Arm() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (_instrument_var._parameters.sgy)*DEG2RAD, (0)*DEG2RAD, (_instrument_var._parameters.sgx)*DEG2RAD); rot_mul(tr1, _PANDA_sth_var._rotation_absolute, _sample_var._rotation_absolute); rot_transpose(_PANDA_sth_var._rotation_absolute, tr1); rot_mul(_sample_var._rotation_absolute, tr1, _sample_var._rotation_relative); _sample_var._rotation_is_identity = rot_test_identity(_sample_var._rotation_relative); tc1 = coords_set( _instrument_var._parameters.sty, _instrument_var._parameters.stz, _instrument_var._parameters.stx); rot_transpose(_PANDA_sth_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _sample_var._position_absolute = coords_add(_PANDA_sth_var._position_absolute, tc2); tc1 = coords_sub(_PANDA_sth_var._position_absolute, _sample_var._position_absolute); _sample_var._position_relative = rot_apply(_sample_var._rotation_absolute, tc1); } /* sample=Arm() AT ROTATED */ DEBUG_COMPONENT("sample", _sample_var._position_absolute, _sample_var._rotation_absolute); instrument->_position_absolute[34] = _sample_var._position_absolute; instrument->_position_relative[34] = _sample_var._position_relative; instrument->counter_N[34] = instrument->counter_P[34] = instrument->counter_P2[34] = 0; instrument->counter_AbsorbProp[34]= 0; return(0); } /* _sample_setpos */ /* component PANDA_cryst=NCrystal_sample() SETTING, POSITION/ROTATION */ int _PANDA_cryst_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PANDA_cryst_setpos] component PANDA_cryst=NCrystal_sample() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../contrib/NCrystal_sample.comp:173]"); stracpy(_PANDA_cryst_var._name, "PANDA_cryst", 16384); stracpy(_PANDA_cryst_var._type, "NCrystal_sample", 16384); _PANDA_cryst_var._index=35; if("./Ag_sg225.ncmat" && strlen("./Ag_sg225.ncmat")) stracpy(_PANDA_cryst_var._parameters.cfg, "./Ag_sg225.ncmat" ? "./Ag_sg225.ncmat" : "", 16384); else _PANDA_cryst_var._parameters.cfg[0]='\0'; _PANDA_cryst_var._parameters.absorptionmode = 1; _PANDA_cryst_var._parameters.multscat = 1; _PANDA_cryst_var._parameters.xwidth = 0.01; _PANDA_cryst_var._parameters.yheight = 0.01; _PANDA_cryst_var._parameters.zdepth = 0.01; _PANDA_cryst_var._parameters.radius = 0; /* component PANDA_cryst=NCrystal_sample() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (45)*DEG2RAD); rot_mul(tr1, _sample_var._rotation_absolute, _PANDA_cryst_var._rotation_absolute); rot_transpose(_sample_var._rotation_absolute, tr1); rot_mul(_PANDA_cryst_var._rotation_absolute, tr1, _PANDA_cryst_var._rotation_relative); _PANDA_cryst_var._rotation_is_identity = rot_test_identity(_PANDA_cryst_var._rotation_relative); tc1 = coords_set( 0, 0, 0); rot_transpose(_sample_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PANDA_cryst_var._position_absolute = coords_add(_sample_var._position_absolute, tc2); tc1 = coords_sub(_sample_var._position_absolute, _PANDA_cryst_var._position_absolute); _PANDA_cryst_var._position_relative = rot_apply(_PANDA_cryst_var._rotation_absolute, tc1); } /* PANDA_cryst=NCrystal_sample() AT ROTATED */ DEBUG_COMPONENT("PANDA_cryst", _PANDA_cryst_var._position_absolute, _PANDA_cryst_var._rotation_absolute); instrument->_position_absolute[35] = _PANDA_cryst_var._position_absolute; instrument->_position_relative[35] = _PANDA_cryst_var._position_relative; instrument->counter_N[35] = instrument->counter_P[35] = instrument->counter_P2[35] = 0; instrument->counter_AbsorbProp[35]= 0; return(0); } /* _PANDA_cryst_setpos */ /* component PANDA_stt=Arm() SETTING, POSITION/ROTATION */ int _PANDA_stt_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PANDA_stt_setpos] component PANDA_stt=Arm() SETTING [Arm:0]"); stracpy(_PANDA_stt_var._name, "PANDA_stt", 16384); stracpy(_PANDA_stt_var._type, "Arm", 16384); _PANDA_stt_var._index=36; /* component PANDA_stt=Arm() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (a4)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_mtt_var._rotation_absolute, _PANDA_stt_var._rotation_absolute); rot_transpose(_PANDA_cryst_var._rotation_absolute, tr1); rot_mul(_PANDA_stt_var._rotation_absolute, tr1, _PANDA_stt_var._rotation_relative); _PANDA_stt_var._rotation_is_identity = rot_test_identity(_PANDA_stt_var._rotation_relative); tc1 = coords_set( 0, 0, 0); rot_transpose(_PANDA_sth_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PANDA_stt_var._position_absolute = coords_add(_PANDA_sth_var._position_absolute, tc2); tc1 = coords_sub(_PANDA_cryst_var._position_absolute, _PANDA_stt_var._position_absolute); _PANDA_stt_var._position_relative = rot_apply(_PANDA_stt_var._rotation_absolute, tc1); } /* PANDA_stt=Arm() AT ROTATED */ DEBUG_COMPONENT("PANDA_stt", _PANDA_stt_var._position_absolute, _PANDA_stt_var._rotation_absolute); instrument->_position_absolute[36] = _PANDA_stt_var._position_absolute; instrument->_position_relative[36] = _PANDA_stt_var._position_relative; instrument->counter_N[36] = instrument->counter_P[36] = instrument->counter_P2[36] = 0; instrument->counter_AbsorbProp[36]= 0; return(0); } /* _PANDA_stt_setpos */ /* component PSD_scattered=PSD_monitor() SETTING, POSITION/ROTATION */ int _PSD_scattered_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PSD_scattered_setpos] component PSD_scattered=PSD_monitor() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/PSD_monitor.comp:62]"); stracpy(_PSD_scattered_var._name, "PSD_scattered", 16384); stracpy(_PSD_scattered_var._type, "PSD_monitor", 16384); _PSD_scattered_var._index=37; _PSD_scattered_var._parameters.nx = 100; _PSD_scattered_var._parameters.ny = 100; if("scattered.psd" && strlen("scattered.psd")) stracpy(_PSD_scattered_var._parameters.filename, "scattered.psd" ? "scattered.psd" : "", 16384); else _PSD_scattered_var._parameters.filename[0]='\0'; _PSD_scattered_var._parameters.xmin = -0.1; _PSD_scattered_var._parameters.xmax = 0.1; _PSD_scattered_var._parameters.ymin = -0.1; _PSD_scattered_var._parameters.ymax = 0.1; _PSD_scattered_var._parameters.xwidth = 0; _PSD_scattered_var._parameters.yheight = 0; _PSD_scattered_var._parameters.restore_neutron = 1; _PSD_scattered_var._parameters.nowritefile = 0; /* component PSD_scattered=PSD_monitor() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_stt_var._rotation_absolute, _PSD_scattered_var._rotation_absolute); rot_transpose(_PANDA_stt_var._rotation_absolute, tr1); rot_mul(_PSD_scattered_var._rotation_absolute, tr1, _PSD_scattered_var._rotation_relative); _PSD_scattered_var._rotation_is_identity = rot_test_identity(_PSD_scattered_var._rotation_relative); tc1 = coords_set( 0, 0, 0.2); rot_transpose(_PANDA_stt_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PSD_scattered_var._position_absolute = coords_add(_PANDA_stt_var._position_absolute, tc2); tc1 = coords_sub(_PANDA_stt_var._position_absolute, _PSD_scattered_var._position_absolute); _PSD_scattered_var._position_relative = rot_apply(_PSD_scattered_var._rotation_absolute, tc1); } /* PSD_scattered=PSD_monitor() AT ROTATED */ DEBUG_COMPONENT("PSD_scattered", _PSD_scattered_var._position_absolute, _PSD_scattered_var._rotation_absolute); instrument->_position_absolute[37] = _PSD_scattered_var._position_absolute; instrument->_position_relative[37] = _PSD_scattered_var._position_relative; instrument->counter_N[37] = instrument->counter_P[37] = instrument->counter_P2[37] = 0; instrument->counter_AbsorbProp[37]= 0; return(0); } /* _PSD_scattered_setpos */ /* component PANDA_ss2=Slit() SETTING, POSITION/ROTATION */ int _PANDA_ss2_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PANDA_ss2_setpos] component PANDA_ss2=Slit() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Slit.comp:50]"); stracpy(_PANDA_ss2_var._name, "PANDA_ss2", 16384); stracpy(_PANDA_ss2_var._type, "Slit", 16384); _PANDA_ss2_var._index=38; _PANDA_ss2_var._parameters.xmin = 0; _PANDA_ss2_var._parameters.xmax = 0; _PANDA_ss2_var._parameters.ymin = 0; _PANDA_ss2_var._parameters.ymax = 0; _PANDA_ss2_var._parameters.radius = 0; _PANDA_ss2_var._parameters.xwidth = _instrument_var._parameters.ss2_width; _PANDA_ss2_var._parameters.yheight = _instrument_var._parameters.ss2_height; /* component PANDA_ss2=Slit() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_stt_var._rotation_absolute, _PANDA_ss2_var._rotation_absolute); rot_transpose(_PSD_scattered_var._rotation_absolute, tr1); rot_mul(_PANDA_ss2_var._rotation_absolute, tr1, _PANDA_ss2_var._rotation_relative); _PANDA_ss2_var._rotation_is_identity = rot_test_identity(_PANDA_ss2_var._rotation_relative); tc1 = coords_set( 0, 0, 0.4000); rot_transpose(_PANDA_stt_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PANDA_ss2_var._position_absolute = coords_add(_PANDA_stt_var._position_absolute, tc2); tc1 = coords_sub(_PSD_scattered_var._position_absolute, _PANDA_ss2_var._position_absolute); _PANDA_ss2_var._position_relative = rot_apply(_PANDA_ss2_var._rotation_absolute, tc1); } /* PANDA_ss2=Slit() AT ROTATED */ DEBUG_COMPONENT("PANDA_ss2", _PANDA_ss2_var._position_absolute, _PANDA_ss2_var._rotation_absolute); instrument->_position_absolute[38] = _PANDA_ss2_var._position_absolute; instrument->_position_relative[38] = _PANDA_ss2_var._position_relative; instrument->counter_N[38] = instrument->counter_P[38] = instrument->counter_P2[38] = 0; instrument->counter_AbsorbProp[38]= 0; return(0); } /* _PANDA_ss2_setpos */ /* component sk4_in=Slit() SETTING, POSITION/ROTATION */ int _sk4_in_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_sk4_in_setpos] component sk4_in=Slit() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Slit.comp:50]"); stracpy(_sk4_in_var._name, "sk4_in", 16384); stracpy(_sk4_in_var._type, "Slit", 16384); _sk4_in_var._index=39; _sk4_in_var._parameters.xmin = 0; _sk4_in_var._parameters.xmax = 0; _sk4_in_var._parameters.ymin = 0; _sk4_in_var._parameters.ymax = 0; _sk4_in_var._parameters.radius = 0; _sk4_in_var._parameters.xwidth = 0.04; _sk4_in_var._parameters.yheight = 0.12; /* component sk4_in=Slit() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_stt_var._rotation_absolute, _sk4_in_var._rotation_absolute); rot_transpose(_PANDA_ss2_var._rotation_absolute, tr1); rot_mul(_sk4_in_var._rotation_absolute, tr1, _sk4_in_var._rotation_relative); _sk4_in_var._rotation_is_identity = rot_test_identity(_sk4_in_var._rotation_relative); tc1 = coords_set( 0, 0, _instrument_var._parameters.lsa -0.600); rot_transpose(_PANDA_stt_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _sk4_in_var._position_absolute = coords_add(_PANDA_stt_var._position_absolute, tc2); tc1 = coords_sub(_PANDA_ss2_var._position_absolute, _sk4_in_var._position_absolute); _sk4_in_var._position_relative = rot_apply(_sk4_in_var._rotation_absolute, tc1); } /* sk4_in=Slit() AT ROTATED */ DEBUG_COMPONENT("sk4_in", _sk4_in_var._position_absolute, _sk4_in_var._rotation_absolute); instrument->_position_absolute[39] = _sk4_in_var._position_absolute; instrument->_position_relative[39] = _sk4_in_var._position_relative; instrument->counter_N[39] = instrument->counter_P[39] = instrument->counter_P2[39] = 0; instrument->counter_AbsorbProp[39]= 0; return(0); } /* _sk4_in_setpos */ /* component PANDA_ca3=Collimator_linear() SETTING, POSITION/ROTATION */ int _PANDA_ca3_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PANDA_ca3_setpos] component PANDA_ca3=Collimator_linear() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Collimator_linear.comp:55]"); stracpy(_PANDA_ca3_var._name, "PANDA_ca3", 16384); stracpy(_PANDA_ca3_var._type, "Collimator_linear", 16384); _PANDA_ca3_var._index=40; _PANDA_ca3_var._parameters.xmin = -0.02; _PANDA_ca3_var._parameters.xmax = 0.02; _PANDA_ca3_var._parameters.ymin = -0.05; _PANDA_ca3_var._parameters.ymax = 0.05; _PANDA_ca3_var._parameters.xwidth = 0.040; _PANDA_ca3_var._parameters.yheight = 0.140; _PANDA_ca3_var._parameters.length = 0.2; _PANDA_ca3_var._parameters.divergence = ca3_div; _PANDA_ca3_var._parameters.transmission = 1; _PANDA_ca3_var._parameters.divergenceV = 0; /* component PANDA_ca3=Collimator_linear() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_stt_var._rotation_absolute, _PANDA_ca3_var._rotation_absolute); rot_transpose(_sk4_in_var._rotation_absolute, tr1); rot_mul(_PANDA_ca3_var._rotation_absolute, tr1, _PANDA_ca3_var._rotation_relative); _PANDA_ca3_var._rotation_is_identity = rot_test_identity(_PANDA_ca3_var._rotation_relative); tc1 = coords_set( 0, 0, _instrument_var._parameters.lsa -0.550); rot_transpose(_PANDA_stt_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PANDA_ca3_var._position_absolute = coords_add(_PANDA_stt_var._position_absolute, tc2); tc1 = coords_sub(_sk4_in_var._position_absolute, _PANDA_ca3_var._position_absolute); _PANDA_ca3_var._position_relative = rot_apply(_PANDA_ca3_var._rotation_absolute, tc1); } /* PANDA_ca3=Collimator_linear() AT ROTATED */ DEBUG_COMPONENT("PANDA_ca3", _PANDA_ca3_var._position_absolute, _PANDA_ca3_var._rotation_absolute); instrument->_position_absolute[40] = _PANDA_ca3_var._position_absolute; instrument->_position_relative[40] = _PANDA_ca3_var._position_relative; instrument->counter_N[40] = instrument->counter_P[40] = instrument->counter_P2[40] = 0; instrument->counter_AbsorbProp[40]= 0; return(0); } /* _PANDA_ca3_setpos */ /* component sk4_out=Slit() SETTING, POSITION/ROTATION */ int _sk4_out_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_sk4_out_setpos] component sk4_out=Slit() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Slit.comp:50]"); stracpy(_sk4_out_var._name, "sk4_out", 16384); stracpy(_sk4_out_var._type, "Slit", 16384); _sk4_out_var._index=41; _sk4_out_var._parameters.xmin = 0; _sk4_out_var._parameters.xmax = 0; _sk4_out_var._parameters.ymin = 0; _sk4_out_var._parameters.ymax = 0; _sk4_out_var._parameters.radius = 0; _sk4_out_var._parameters.xwidth = 0.06; _sk4_out_var._parameters.yheight = 0.1; /* component sk4_out=Slit() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_stt_var._rotation_absolute, _sk4_out_var._rotation_absolute); rot_transpose(_PANDA_ca3_var._rotation_absolute, tr1); rot_mul(_sk4_out_var._rotation_absolute, tr1, _sk4_out_var._rotation_relative); _sk4_out_var._rotation_is_identity = rot_test_identity(_sk4_out_var._rotation_relative); tc1 = coords_set( 0, 0, _instrument_var._parameters.lsa -0.200); rot_transpose(_PANDA_stt_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _sk4_out_var._position_absolute = coords_add(_PANDA_stt_var._position_absolute, tc2); tc1 = coords_sub(_PANDA_ca3_var._position_absolute, _sk4_out_var._position_absolute); _sk4_out_var._position_relative = rot_apply(_sk4_out_var._rotation_absolute, tc1); } /* sk4_out=Slit() AT ROTATED */ DEBUG_COMPONENT("sk4_out", _sk4_out_var._position_absolute, _sk4_out_var._rotation_absolute); instrument->_position_absolute[41] = _sk4_out_var._position_absolute; instrument->_position_relative[41] = _sk4_out_var._position_relative; instrument->counter_N[41] = instrument->counter_P[41] = instrument->counter_P2[41] = 0; instrument->counter_AbsorbProp[41]= 0; return(0); } /* _sk4_out_setpos */ /* component PSD_mon2=PSD_monitor() SETTING, POSITION/ROTATION */ int _PSD_mon2_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PSD_mon2_setpos] component PSD_mon2=PSD_monitor() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/PSD_monitor.comp:62]"); stracpy(_PSD_mon2_var._name, "PSD_mon2", 16384); stracpy(_PSD_mon2_var._type, "PSD_monitor", 16384); _PSD_mon2_var._index=42; _PSD_mon2_var._parameters.nx = 100; _PSD_mon2_var._parameters.ny = 120; if("PSD_mon2.psd" && strlen("PSD_mon2.psd")) stracpy(_PSD_mon2_var._parameters.filename, "PSD_mon2.psd" ? "PSD_mon2.psd" : "", 16384); else _PSD_mon2_var._parameters.filename[0]='\0'; _PSD_mon2_var._parameters.xmin = -0.05; _PSD_mon2_var._parameters.xmax = 0.05; _PSD_mon2_var._parameters.ymin = -0.06; _PSD_mon2_var._parameters.ymax = 0.06; _PSD_mon2_var._parameters.xwidth = 0; _PSD_mon2_var._parameters.yheight = 0; _PSD_mon2_var._parameters.restore_neutron = 1; _PSD_mon2_var._parameters.nowritefile = 0; /* component PSD_mon2=PSD_monitor() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _sk4_out_var._rotation_absolute, _PSD_mon2_var._rotation_absolute); rot_transpose(_sk4_out_var._rotation_absolute, tr1); rot_mul(_PSD_mon2_var._rotation_absolute, tr1, _PSD_mon2_var._rotation_relative); _PSD_mon2_var._rotation_is_identity = rot_test_identity(_PSD_mon2_var._rotation_relative); tc1 = coords_set( 0, 0, 0.1); rot_transpose(_sk4_out_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PSD_mon2_var._position_absolute = coords_add(_sk4_out_var._position_absolute, tc2); tc1 = coords_sub(_sk4_out_var._position_absolute, _PSD_mon2_var._position_absolute); _PSD_mon2_var._position_relative = rot_apply(_PSD_mon2_var._rotation_absolute, tc1); } /* PSD_mon2=PSD_monitor() AT ROTATED */ DEBUG_COMPONENT("PSD_mon2", _PSD_mon2_var._position_absolute, _PSD_mon2_var._rotation_absolute); instrument->_position_absolute[42] = _PSD_mon2_var._position_absolute; instrument->_position_relative[42] = _PSD_mon2_var._position_relative; instrument->counter_N[42] = instrument->counter_P[42] = instrument->counter_P2[42] = 0; instrument->counter_AbsorbProp[42]= 0; return(0); } /* _PSD_mon2_setpos */ /* component PANDA_ath=Arm() SETTING, POSITION/ROTATION */ int _PANDA_ath_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PANDA_ath_setpos] component PANDA_ath=Arm() SETTING [Arm:0]"); stracpy(_PANDA_ath_var._name, "PANDA_ath", 16384); stracpy(_PANDA_ath_var._type, "Arm", 16384); _PANDA_ath_var._index=43; /* component PANDA_ath=Arm() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (180 - a5)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_stt_var._rotation_absolute, _PANDA_ath_var._rotation_absolute); rot_transpose(_PSD_mon2_var._rotation_absolute, tr1); rot_mul(_PANDA_ath_var._rotation_absolute, tr1, _PANDA_ath_var._rotation_relative); _PANDA_ath_var._rotation_is_identity = rot_test_identity(_PANDA_ath_var._rotation_relative); tc1 = coords_set( 0, 0, _instrument_var._parameters.lsa); rot_transpose(_PANDA_stt_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PANDA_ath_var._position_absolute = coords_add(_PANDA_stt_var._position_absolute, tc2); tc1 = coords_sub(_PSD_mon2_var._position_absolute, _PANDA_ath_var._position_absolute); _PANDA_ath_var._position_relative = rot_apply(_PANDA_ath_var._rotation_absolute, tc1); } /* PANDA_ath=Arm() AT ROTATED */ DEBUG_COMPONENT("PANDA_ath", _PANDA_ath_var._position_absolute, _PANDA_ath_var._rotation_absolute); instrument->_position_absolute[43] = _PANDA_ath_var._position_absolute; instrument->_position_relative[43] = _PANDA_ath_var._position_relative; instrument->counter_N[43] = instrument->counter_P[43] = instrument->counter_P2[43] = 0; instrument->counter_AbsorbProp[43]= 0; return(0); } /* _PANDA_ath_setpos */ /* component analyser=Arm() SETTING, POSITION/ROTATION */ int _analyser_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_analyser_setpos] component analyser=Arm() SETTING [Arm:0]"); stracpy(_analyser_var._name, "analyser", 16384); stracpy(_analyser_var._type, "Arm", 16384); _analyser_var._index=44; /* component analyser=Arm() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (_instrument_var._parameters.agy)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_ath_var._rotation_absolute, _analyser_var._rotation_absolute); rot_transpose(_PANDA_ath_var._rotation_absolute, tr1); rot_mul(_analyser_var._rotation_absolute, tr1, _analyser_var._rotation_relative); _analyser_var._rotation_is_identity = rot_test_identity(_analyser_var._rotation_relative); tc1 = coords_set( _instrument_var._parameters.aty, 0, 0); rot_transpose(_PANDA_ath_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _analyser_var._position_absolute = coords_add(_PANDA_ath_var._position_absolute, tc2); tc1 = coords_sub(_PANDA_ath_var._position_absolute, _analyser_var._position_absolute); _analyser_var._position_relative = rot_apply(_analyser_var._rotation_absolute, tc1); } /* analyser=Arm() AT ROTATED */ DEBUG_COMPONENT("analyser", _analyser_var._position_absolute, _analyser_var._rotation_absolute); instrument->_position_absolute[44] = _analyser_var._position_absolute; instrument->_position_relative[44] = _analyser_var._position_relative; instrument->counter_N[44] = instrument->counter_P[44] = instrument->counter_P2[44] = 0; instrument->counter_AbsorbProp[44]= 0; return(0); } /* _analyser_setpos */ /* component PG002_ana=Monochromator_curved() SETTING, POSITION/ROTATION */ int _PG002_ana_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PG002_ana_setpos] component PG002_ana=Monochromator_curved() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Monochromator_curved.comp:134]"); stracpy(_PG002_ana_var._name, "PG002_ana", 16384); stracpy(_PG002_ana_var._type, "Monochromator_curved", 16384); _PG002_ana_var._index=45; if("HOPG.rfl" && strlen("HOPG.rfl")) stracpy(_PG002_ana_var._parameters.reflect, "HOPG.rfl" ? "HOPG.rfl" : "", 16384); else _PG002_ana_var._parameters.reflect[0]='\0'; if("NULL" && strlen("NULL")) stracpy(_PG002_ana_var._parameters.transmit, "NULL" ? "NULL" : "", 16384); else _PG002_ana_var._parameters.transmit[0]='\0'; _PG002_ana_var._parameters.zwidth = 0.013; _PG002_ana_var._parameters.yheight = 0.025; _PG002_ana_var._parameters.gap = 0.003; _PG002_ana_var._parameters.NH = 13; _PG002_ana_var._parameters.NV = 6; _PG002_ana_var._parameters.mosaich = 30.0; _PG002_ana_var._parameters.mosaicv = 30.0; _PG002_ana_var._parameters.r0 = 0.7; _PG002_ana_var._parameters.t0 = 1.0; _PG002_ana_var._parameters.Q = 1.873; _PG002_ana_var._parameters.RV = _instrument_var._parameters.afv; _PG002_ana_var._parameters.RH = _instrument_var._parameters.afh; _PG002_ana_var._parameters.DM = 0; _PG002_ana_var._parameters.mosaic = 20; _PG002_ana_var._parameters.width = 0; _PG002_ana_var._parameters.height = 0; _PG002_ana_var._parameters.verbose = 0; _PG002_ana_var._parameters.order = 0; /* component PG002_ana=Monochromator_curved() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0.0)*DEG2RAD, (0.0)*DEG2RAD, (0.0)*DEG2RAD); rot_mul(tr1, _analyser_var._rotation_absolute, _PG002_ana_var._rotation_absolute); rot_transpose(_analyser_var._rotation_absolute, tr1); rot_mul(_PG002_ana_var._rotation_absolute, tr1, _PG002_ana_var._rotation_relative); _PG002_ana_var._rotation_is_identity = rot_test_identity(_PG002_ana_var._rotation_relative); tc1 = coords_set( 0, 0, 0); rot_transpose(_analyser_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PG002_ana_var._position_absolute = coords_add(_analyser_var._position_absolute, tc2); tc1 = coords_sub(_analyser_var._position_absolute, _PG002_ana_var._position_absolute); _PG002_ana_var._position_relative = rot_apply(_PG002_ana_var._rotation_absolute, tc1); } /* PG002_ana=Monochromator_curved() AT ROTATED */ DEBUG_COMPONENT("PG002_ana", _PG002_ana_var._position_absolute, _PG002_ana_var._rotation_absolute); instrument->_position_absolute[45] = _PG002_ana_var._position_absolute; instrument->_position_relative[45] = _PG002_ana_var._position_relative; instrument->counter_N[45] = instrument->counter_P[45] = instrument->counter_P2[45] = 0; instrument->counter_AbsorbProp[45]= 0; return(0); } /* _PG002_ana_setpos */ /* component PANDA_att=Arm() SETTING, POSITION/ROTATION */ int _PANDA_att_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PANDA_att_setpos] component PANDA_att=Arm() SETTING [Arm:0]"); stracpy(_PANDA_att_var._name, "PANDA_att", 16384); stracpy(_PANDA_att_var._type, "Arm", 16384); _PANDA_att_var._index=46; /* component PANDA_att=Arm() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (- a6)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_stt_var._rotation_absolute, _PANDA_att_var._rotation_absolute); rot_transpose(_PG002_ana_var._rotation_absolute, tr1); rot_mul(_PANDA_att_var._rotation_absolute, tr1, _PANDA_att_var._rotation_relative); _PANDA_att_var._rotation_is_identity = rot_test_identity(_PANDA_att_var._rotation_relative); tc1 = coords_set( 0, 0, 0); rot_transpose(_PANDA_ath_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PANDA_att_var._position_absolute = coords_add(_PANDA_ath_var._position_absolute, tc2); tc1 = coords_sub(_PG002_ana_var._position_absolute, _PANDA_att_var._position_absolute); _PANDA_att_var._position_relative = rot_apply(_PANDA_att_var._rotation_absolute, tc1); } /* PANDA_att=Arm() AT ROTATED */ DEBUG_COMPONENT("PANDA_att", _PANDA_att_var._position_absolute, _PANDA_att_var._rotation_absolute); instrument->_position_absolute[46] = _PANDA_att_var._position_absolute; instrument->_position_relative[46] = _PANDA_att_var._position_relative; instrument->counter_N[46] = instrument->counter_P[46] = instrument->counter_P2[46] = 0; instrument->counter_AbsorbProp[46]= 0; return(0); } /* _PANDA_att_setpos */ /* component sk5_in=Slit() SETTING, POSITION/ROTATION */ int _sk5_in_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_sk5_in_setpos] component sk5_in=Slit() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Slit.comp:50]"); stracpy(_sk5_in_var._name, "sk5_in", 16384); stracpy(_sk5_in_var._type, "Slit", 16384); _sk5_in_var._index=47; _sk5_in_var._parameters.xmin = 0; _sk5_in_var._parameters.xmax = 0; _sk5_in_var._parameters.ymin = 0; _sk5_in_var._parameters.ymax = 0; _sk5_in_var._parameters.radius = 0; _sk5_in_var._parameters.xwidth = 0.04; _sk5_in_var._parameters.yheight = 0.12; /* component sk5_in=Slit() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_att_var._rotation_absolute, _sk5_in_var._rotation_absolute); rot_transpose(_PANDA_att_var._rotation_absolute, tr1); rot_mul(_sk5_in_var._rotation_absolute, tr1, _sk5_in_var._rotation_relative); _sk5_in_var._rotation_is_identity = rot_test_identity(_sk5_in_var._rotation_relative); tc1 = coords_set( 0, 0, 0.4000); rot_transpose(_PANDA_att_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _sk5_in_var._position_absolute = coords_add(_PANDA_att_var._position_absolute, tc2); tc1 = coords_sub(_PANDA_att_var._position_absolute, _sk5_in_var._position_absolute); _sk5_in_var._position_relative = rot_apply(_sk5_in_var._rotation_absolute, tc1); } /* sk5_in=Slit() AT ROTATED */ DEBUG_COMPONENT("sk5_in", _sk5_in_var._position_absolute, _sk5_in_var._rotation_absolute); instrument->_position_absolute[47] = _sk5_in_var._position_absolute; instrument->_position_relative[47] = _sk5_in_var._position_relative; instrument->counter_N[47] = instrument->counter_P[47] = instrument->counter_P2[47] = 0; instrument->counter_AbsorbProp[47]= 0; return(0); } /* _sk5_in_setpos */ /* component PANDA_ca4=Collimator_linear() SETTING, POSITION/ROTATION */ int _PANDA_ca4_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PANDA_ca4_setpos] component PANDA_ca4=Collimator_linear() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Collimator_linear.comp:55]"); stracpy(_PANDA_ca4_var._name, "PANDA_ca4", 16384); stracpy(_PANDA_ca4_var._type, "Collimator_linear", 16384); _PANDA_ca4_var._index=48; _PANDA_ca4_var._parameters.xmin = -0.02; _PANDA_ca4_var._parameters.xmax = 0.02; _PANDA_ca4_var._parameters.ymin = -0.05; _PANDA_ca4_var._parameters.ymax = 0.05; _PANDA_ca4_var._parameters.xwidth = 0.040; _PANDA_ca4_var._parameters.yheight = 0.140; _PANDA_ca4_var._parameters.length = 0.2; _PANDA_ca4_var._parameters.divergence = ca4_div; _PANDA_ca4_var._parameters.transmission = 1; _PANDA_ca4_var._parameters.divergenceV = 0; /* component PANDA_ca4=Collimator_linear() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_att_var._rotation_absolute, _PANDA_ca4_var._rotation_absolute); rot_transpose(_sk5_in_var._rotation_absolute, tr1); rot_mul(_PANDA_ca4_var._rotation_absolute, tr1, _PANDA_ca4_var._rotation_relative); _PANDA_ca4_var._rotation_is_identity = rot_test_identity(_PANDA_ca4_var._rotation_relative); tc1 = coords_set( 0, 0, 0.4100); rot_transpose(_PANDA_att_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PANDA_ca4_var._position_absolute = coords_add(_PANDA_att_var._position_absolute, tc2); tc1 = coords_sub(_sk5_in_var._position_absolute, _PANDA_ca4_var._position_absolute); _PANDA_ca4_var._position_relative = rot_apply(_PANDA_ca4_var._rotation_absolute, tc1); } /* PANDA_ca4=Collimator_linear() AT ROTATED */ DEBUG_COMPONENT("PANDA_ca4", _PANDA_ca4_var._position_absolute, _PANDA_ca4_var._rotation_absolute); instrument->_position_absolute[48] = _PANDA_ca4_var._position_absolute; instrument->_position_relative[48] = _PANDA_ca4_var._position_relative; instrument->counter_N[48] = instrument->counter_P[48] = instrument->counter_P2[48] = 0; instrument->counter_AbsorbProp[48]= 0; return(0); } /* _PANDA_ca4_setpos */ /* component sk5_out=Slit() SETTING, POSITION/ROTATION */ int _sk5_out_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_sk5_out_setpos] component sk5_out=Slit() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Slit.comp:50]"); stracpy(_sk5_out_var._name, "sk5_out", 16384); stracpy(_sk5_out_var._type, "Slit", 16384); _sk5_out_var._index=49; _sk5_out_var._parameters.xmin = 0; _sk5_out_var._parameters.xmax = 0; _sk5_out_var._parameters.ymin = 0; _sk5_out_var._parameters.ymax = 0; _sk5_out_var._parameters.radius = 0; _sk5_out_var._parameters.xwidth = 0.03; _sk5_out_var._parameters.yheight = 0.12; /* component sk5_out=Slit() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_att_var._rotation_absolute, _sk5_out_var._rotation_absolute); rot_transpose(_PANDA_ca4_var._rotation_absolute, tr1); rot_mul(_sk5_out_var._rotation_absolute, tr1, _sk5_out_var._rotation_relative); _sk5_out_var._rotation_is_identity = rot_test_identity(_sk5_out_var._rotation_relative); tc1 = coords_set( 0, 0, _instrument_var._parameters.lad -0.1); rot_transpose(_PANDA_att_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _sk5_out_var._position_absolute = coords_add(_PANDA_att_var._position_absolute, tc2); tc1 = coords_sub(_PANDA_ca4_var._position_absolute, _sk5_out_var._position_absolute); _sk5_out_var._position_relative = rot_apply(_sk5_out_var._rotation_absolute, tc1); } /* sk5_out=Slit() AT ROTATED */ DEBUG_COMPONENT("sk5_out", _sk5_out_var._position_absolute, _sk5_out_var._rotation_absolute); instrument->_position_absolute[49] = _sk5_out_var._position_absolute; instrument->_position_relative[49] = _sk5_out_var._position_relative; instrument->counter_N[49] = instrument->counter_P[49] = instrument->counter_P2[49] = 0; instrument->counter_AbsorbProp[49]= 0; return(0); } /* _sk5_out_setpos */ /* component a_detector=Arm() SETTING, POSITION/ROTATION */ int _a_detector_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_a_detector_setpos] component a_detector=Arm() SETTING [Arm:0]"); stracpy(_a_detector_var._name, "a_detector", 16384); stracpy(_a_detector_var._type, "Arm", 16384); _a_detector_var._index=50; /* component a_detector=Arm() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PANDA_att_var._rotation_absolute, _a_detector_var._rotation_absolute); rot_transpose(_sk5_out_var._rotation_absolute, tr1); rot_mul(_a_detector_var._rotation_absolute, tr1, _a_detector_var._rotation_relative); _a_detector_var._rotation_is_identity = rot_test_identity(_a_detector_var._rotation_relative); tc1 = coords_set( 0, 0, _instrument_var._parameters.lad); rot_transpose(_PANDA_att_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _a_detector_var._position_absolute = coords_add(_PANDA_att_var._position_absolute, tc2); tc1 = coords_sub(_sk5_out_var._position_absolute, _a_detector_var._position_absolute); _a_detector_var._position_relative = rot_apply(_a_detector_var._rotation_absolute, tc1); } /* a_detector=Arm() AT ROTATED */ DEBUG_COMPONENT("a_detector", _a_detector_var._position_absolute, _a_detector_var._rotation_absolute); instrument->_position_absolute[50] = _a_detector_var._position_absolute; instrument->_position_relative[50] = _a_detector_var._position_relative; instrument->counter_N[50] = instrument->counter_P[50] = instrument->counter_P2[50] = 0; instrument->counter_AbsorbProp[50]= 0; return(0); } /* _a_detector_setpos */ /* component PSD_det=PSD_monitor() SETTING, POSITION/ROTATION */ int _PSD_det_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PSD_det_setpos] component PSD_det=PSD_monitor() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/PSD_monitor.comp:62]"); stracpy(_PSD_det_var._name, "PSD_det", 16384); stracpy(_PSD_det_var._type, "PSD_monitor", 16384); _PSD_det_var._index=51; _PSD_det_var._parameters.nx = 60; _PSD_det_var._parameters.ny = 200; if("PSD_det.psd" && strlen("PSD_det.psd")) stracpy(_PSD_det_var._parameters.filename, "PSD_det.psd" ? "PSD_det.psd" : "", 16384); else _PSD_det_var._parameters.filename[0]='\0'; _PSD_det_var._parameters.xmin = -0.03; _PSD_det_var._parameters.xmax = 0.03; _PSD_det_var._parameters.ymin = -0.10; _PSD_det_var._parameters.ymax = 0.10; _PSD_det_var._parameters.xwidth = 0; _PSD_det_var._parameters.yheight = 0; _PSD_det_var._parameters.restore_neutron = 1; _PSD_det_var._parameters.nowritefile = 0; /* component PSD_det=PSD_monitor() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _a_detector_var._rotation_absolute, _PSD_det_var._rotation_absolute); rot_transpose(_a_detector_var._rotation_absolute, tr1); rot_mul(_PSD_det_var._rotation_absolute, tr1, _PSD_det_var._rotation_relative); _PSD_det_var._rotation_is_identity = rot_test_identity(_PSD_det_var._rotation_relative); tc1 = coords_set( 0, 0, 0.0001); rot_transpose(_a_detector_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PSD_det_var._position_absolute = coords_add(_a_detector_var._position_absolute, tc2); tc1 = coords_sub(_a_detector_var._position_absolute, _PSD_det_var._position_absolute); _PSD_det_var._position_relative = rot_apply(_PSD_det_var._rotation_absolute, tc1); } /* PSD_det=PSD_monitor() AT ROTATED */ DEBUG_COMPONENT("PSD_det", _PSD_det_var._position_absolute, _PSD_det_var._rotation_absolute); instrument->_position_absolute[51] = _PSD_det_var._position_absolute; instrument->_position_relative[51] = _PSD_det_var._position_relative; instrument->counter_N[51] = instrument->counter_P[51] = instrument->counter_P2[51] = 0; instrument->counter_AbsorbProp[51]= 0; return(0); } /* _PSD_det_setpos */ /* component PSD_det1=PSD_monitor() SETTING, POSITION/ROTATION */ int _PSD_det1_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PSD_det1_setpos] component PSD_det1=PSD_monitor() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/PSD_monitor.comp:62]"); stracpy(_PSD_det1_var._name, "PSD_det1", 16384); stracpy(_PSD_det1_var._type, "PSD_monitor", 16384); _PSD_det1_var._index=52; _PSD_det1_var._parameters.nx = 25; _PSD_det1_var._parameters.ny = 100; if("PSD_det1.psd" && strlen("PSD_det1.psd")) stracpy(_PSD_det1_var._parameters.filename, "PSD_det1.psd" ? "PSD_det1.psd" : "", 16384); else _PSD_det1_var._parameters.filename[0]='\0'; _PSD_det1_var._parameters.xmin = -0.0125; _PSD_det1_var._parameters.xmax = 0.0125; _PSD_det1_var._parameters.ymin = -0.05; _PSD_det1_var._parameters.ymax = 0.05; _PSD_det1_var._parameters.xwidth = 0; _PSD_det1_var._parameters.yheight = 0; _PSD_det1_var._parameters.restore_neutron = 1; _PSD_det1_var._parameters.nowritefile = 0; /* component PSD_det1=PSD_monitor() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PSD_det_var._rotation_absolute, _PSD_det1_var._rotation_absolute); rot_transpose(_PSD_det_var._rotation_absolute, tr1); rot_mul(_PSD_det1_var._rotation_absolute, tr1, _PSD_det1_var._rotation_relative); _PSD_det1_var._rotation_is_identity = rot_test_identity(_PSD_det1_var._rotation_relative); tc1 = coords_set( 0, 0, 0.0001); rot_transpose(_PSD_det_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PSD_det1_var._position_absolute = coords_add(_PSD_det_var._position_absolute, tc2); tc1 = coords_sub(_PSD_det_var._position_absolute, _PSD_det1_var._position_absolute); _PSD_det1_var._position_relative = rot_apply(_PSD_det1_var._rotation_absolute, tc1); } /* PSD_det1=PSD_monitor() AT ROTATED */ DEBUG_COMPONENT("PSD_det1", _PSD_det1_var._position_absolute, _PSD_det1_var._rotation_absolute); instrument->_position_absolute[52] = _PSD_det1_var._position_absolute; instrument->_position_relative[52] = _PSD_det1_var._position_relative; instrument->counter_N[52] = instrument->counter_P[52] = instrument->counter_P2[52] = 0; instrument->counter_AbsorbProp[52]= 0; return(0); } /* _PSD_det1_setpos */ /* component PSD_det2=PSD_monitor() SETTING, POSITION/ROTATION */ int _PSD_det2_setpos(void) { /* sets initial component parameters, position and rotation */ SIG_MESSAGE("[_PSD_det2_setpos] component PSD_det2=PSD_monitor() SETTING [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/PSD_monitor.comp:62]"); stracpy(_PSD_det2_var._name, "PSD_det2", 16384); stracpy(_PSD_det2_var._type, "PSD_monitor", 16384); _PSD_det2_var._index=53; _PSD_det2_var._parameters.nx = 50; _PSD_det2_var._parameters.ny = 100; if("PSD_det2.psd" && strlen("PSD_det2.psd")) stracpy(_PSD_det2_var._parameters.filename, "PSD_det2.psd" ? "PSD_det2.psd" : "", 16384); else _PSD_det2_var._parameters.filename[0]='\0'; _PSD_det2_var._parameters.xmin = -0.025; _PSD_det2_var._parameters.xmax = 0.025; _PSD_det2_var._parameters.ymin = -0.05; _PSD_det2_var._parameters.ymax = 0.05; _PSD_det2_var._parameters.xwidth = 0; _PSD_det2_var._parameters.yheight = 0; _PSD_det2_var._parameters.restore_neutron = 1; _PSD_det2_var._parameters.nowritefile = 0; /* component PSD_det2=PSD_monitor() AT ROTATED */ { Coords tc1, tc2; Rotation tr1; rot_set_rotation(tr1, (0)*DEG2RAD, (0)*DEG2RAD, (0)*DEG2RAD); rot_mul(tr1, _PSD_det1_var._rotation_absolute, _PSD_det2_var._rotation_absolute); rot_transpose(_PSD_det1_var._rotation_absolute, tr1); rot_mul(_PSD_det2_var._rotation_absolute, tr1, _PSD_det2_var._rotation_relative); _PSD_det2_var._rotation_is_identity = rot_test_identity(_PSD_det2_var._rotation_relative); tc1 = coords_set( 0, 0, 0.0001); rot_transpose(_PSD_det1_var._rotation_absolute, tr1); tc2 = rot_apply(tr1, tc1); _PSD_det2_var._position_absolute = coords_add(_PSD_det1_var._position_absolute, tc2); tc1 = coords_sub(_PSD_det1_var._position_absolute, _PSD_det2_var._position_absolute); _PSD_det2_var._position_relative = rot_apply(_PSD_det2_var._rotation_absolute, tc1); } /* PSD_det2=PSD_monitor() AT ROTATED */ DEBUG_COMPONENT("PSD_det2", _PSD_det2_var._position_absolute, _PSD_det2_var._rotation_absolute); instrument->_position_absolute[53] = _PSD_det2_var._position_absolute; instrument->_position_relative[53] = _PSD_det2_var._position_relative; instrument->counter_N[53] = instrument->counter_P[53] = instrument->counter_P2[53] = 0; instrument->counter_AbsorbProp[53]= 0; return(0); } /* _PSD_det2_setpos */ _class_Progress_bar *class_Progress_bar_init(_class_Progress_bar *_comp ) { #define profile (_comp->_parameters.profile) #define percent (_comp->_parameters.percent) #define flag_save (_comp->_parameters.flag_save) #define minutes (_comp->_parameters.minutes) #define IntermediateCnts (_comp->_parameters.IntermediateCnts) #define StartTime (_comp->_parameters.StartTime) #define EndTime (_comp->_parameters.EndTime) #define CurrentTime (_comp->_parameters.CurrentTime) SIG_MESSAGE("[_origin_init] component origin=Progress_bar() INITIALISE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../misc/Progress_bar.comp:57]"); IntermediateCnts=0; StartTime=0; EndTime=0; CurrentTime=0; fprintf(stdout, "[%s] Initialize\n", instrument_name); if (percent*mcget_ncount()/100 < 1e5) { percent=1e5*100.0/mcget_ncount(); } #ifdef OPENACC time(&StartTime); #endif #undef profile #undef percent #undef flag_save #undef minutes #undef IntermediateCnts #undef StartTime #undef EndTime #undef CurrentTime return(_comp); } /* class_Progress_bar_init */ _class_Source_gen *class_Source_gen_init(_class_Source_gen *_comp ) { #define flux_file (_comp->_parameters.flux_file) #define xdiv_file (_comp->_parameters.xdiv_file) #define ydiv_file (_comp->_parameters.ydiv_file) #define radius (_comp->_parameters.radius) #define dist (_comp->_parameters.dist) #define focus_xw (_comp->_parameters.focus_xw) #define focus_yh (_comp->_parameters.focus_yh) #define focus_aw (_comp->_parameters.focus_aw) #define focus_ah (_comp->_parameters.focus_ah) #define E0 (_comp->_parameters.E0) #define dE (_comp->_parameters.dE) #define lambda0 (_comp->_parameters.lambda0) #define dlambda (_comp->_parameters.dlambda) #define I1 (_comp->_parameters.I1) #define yheight (_comp->_parameters.yheight) #define xwidth (_comp->_parameters.xwidth) #define verbose (_comp->_parameters.verbose) #define T1 (_comp->_parameters.T1) #define flux_file_perAA (_comp->_parameters.flux_file_perAA) #define flux_file_log (_comp->_parameters.flux_file_log) #define Lmin (_comp->_parameters.Lmin) #define Lmax (_comp->_parameters.Lmax) #define Emin (_comp->_parameters.Emin) #define Emax (_comp->_parameters.Emax) #define T2 (_comp->_parameters.T2) #define I2 (_comp->_parameters.I2) #define T3 (_comp->_parameters.T3) #define I3 (_comp->_parameters.I3) #define zdepth (_comp->_parameters.zdepth) #define target_index (_comp->_parameters.target_index) #define p_in (_comp->_parameters.p_in) #define lambda1 (_comp->_parameters.lambda1) #define lambda2 (_comp->_parameters.lambda2) #define lambda3 (_comp->_parameters.lambda3) #define pTable (_comp->_parameters.pTable) #define pTable_x (_comp->_parameters.pTable_x) #define pTable_y (_comp->_parameters.pTable_y) #define pTable_xmin (_comp->_parameters.pTable_xmin) #define pTable_xmax (_comp->_parameters.pTable_xmax) #define pTable_xsum (_comp->_parameters.pTable_xsum) #define pTable_ymin (_comp->_parameters.pTable_ymin) #define pTable_ymax (_comp->_parameters.pTable_ymax) #define pTable_ysum (_comp->_parameters.pTable_ysum) #define pTable_dxmin (_comp->_parameters.pTable_dxmin) #define pTable_dxmax (_comp->_parameters.pTable_dxmax) #define pTable_dymin (_comp->_parameters.pTable_dymin) #define pTable_dymax (_comp->_parameters.pTable_dymax) SIG_MESSAGE("[_ColdSource_init] component ColdSource=Source_gen() INITIALISE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../sources/Source_gen.comp:207]"); pTable_xsum=0; pTable_ysum=0; double source_area, k; if (target_index && !dist) { Coords ToTarget; double tx,ty,tz; ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP); ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget); coords_get(ToTarget, &tx, &ty, &tz); dist=sqrt(tx*tx+ty*ty+tz*tz); } /* spectrum characteristics */ if (flux_file && strlen(flux_file) && strcmp(flux_file,"NULL") && strcmp(flux_file,"0")) { if (Table_Read(&pTable, flux_file, 1) <= 0) /* read 1st block data from file into pTable */ exit(fprintf(stderr, "Source_gen: %s: can not read flux file %s\n", NAME_CURRENT_COMP, flux_file)); /* put table in Log scale */ int i; if (pTable.columns < 2) exit(fprintf(stderr, "Source_gen: %s: Flux file %s should contain at least 2 columns [wavelength in Angs,flux].\n", NAME_CURRENT_COMP, flux_file)); double table_lmin=FLT_MAX, table_lmax=-FLT_MAX; double tmin=FLT_MAX, tmax=-FLT_MAX; for (i=0; i tmax) tmax=val; if (val < tmin) tmin=val; } for (i=0; i 0 ? val : tmin/10); Table_SetElement(&pTable, i, 1, val); val = Table_Index(pTable, i,0); /* lambda */ if (val > table_lmax) table_lmax=val; if (val < table_lmin) table_lmin=val; } if (!Lmin && !Lmax && !lambda0 && !dlambda && !E0 && !dE && !Emin && !Emax) { Lmin = table_lmin; Lmax = table_lmax; } if (Lmax > table_lmax) { if (verbose) fprintf(stderr, "Source_gen: %s: Maximum wavelength %g is beyond table range upper limit %g. Constraining.\n", NAME_CURRENT_COMP, Lmax, table_lmax); Lmax = table_lmax; } if (Lmin < table_lmin) { if (verbose) fprintf(stderr, "Source_gen: %s: Minimum wavelength %g is below table range lower limit %g. Constraining.\n", NAME_CURRENT_COMP, Lmin, table_lmin); Lmin = table_lmin; } } /* end flux file */ else { k = 1.38066e-23; /* k_B */ if (T1 > 0) { lambda1 = 1.0e10*sqrt(HBAR*HBAR*4.0*PI*PI/2.0/MNEUTRON/k/T1); } else { lambda1 = lambda0; } if (T2 > 0) { lambda2 = 1.0e10*sqrt(HBAR*HBAR*4.0*PI*PI/2.0/MNEUTRON/k/T2); } else { lambda2 = lambda0; } if (T3 > 0) { lambda3 = 1.0e10*sqrt(HBAR*HBAR*4.0*PI*PI/2.0/MNEUTRON/k/T3); } else { lambda3 = lambda0; } } /* now read position-divergence files, if any */ if (xdiv_file && strlen(xdiv_file) && strcmp(xdiv_file,"NULL") && strcmp(xdiv_file,"0")) { int i,j; if (Table_Read(&pTable_x, xdiv_file, 1) <= 0) /* read 1st block data from file into pTable */ exit(fprintf(stderr, "Source_gen: %s: can not read XDiv file %s\n", NAME_CURRENT_COMP, xdiv_file)); pTable_xsum = 0; for (i=0; i 0) || (dE > 0 && dE >= E0)) { fprintf(stderr,"Source_gen: %s: Error: minimal energy cannot be less or equal zero\n", NAME_CURRENT_COMP); exit(-1); } if ((Emax >= Emin) && (Emin > 0)) { E0 = (Emax+Emin)/2; dE = (Emax-Emin)/2; } if ((E0 > dE) && (dE >= 0)) { Lmin = sqrt(81.81/(E0+dE)); /* Angstroem */ Lmax = sqrt(81.81/(E0-dE)); } if (Lmax > 0) { lambda0 = (Lmax+Lmin)/2; dlambda = (Lmax-Lmin)/2; } if (lambda0 <= 0 || (lambda0 < dlambda) || (dlambda < 0)) { fprintf(stderr,"Source_gen: %s: Error: Wavelength range %.3f +/- %.3f AA calculated \n", NAME_CURRENT_COMP, lambda0, dlambda); fprintf(stderr,"- whole wavelength range must be >= 0 \n"); fprintf(stderr,"- range must be > 0; otherwise intensity gets zero, use other sources in this case \n\n"); exit(-1); } radius = fabs(radius); xwidth=fabs(xwidth); yheight=fabs(yheight); I1=fabs(I1); lambda0=fabs(lambda0); dlambda=fabs(dlambda); focus_xw = fabs(focus_xw); focus_yh=fabs(focus_yh); dist=fabs(dist); if ((!focus_ah && !focus_aw) && (!focus_xw && !focus_yh)) { fprintf(stderr,"Source_gen: %s: Error: No focusing information.\n" " Specify focus_xw, focus_yh or focus_aw, focus_ah\n", NAME_CURRENT_COMP); exit(-1); } Lmin = lambda0 - dlambda; /* Angstroem */ Lmax = lambda0 + dlambda; /* compute initial weight factor p_in to get [n/s] */ if ((I1 > 0 && T1 >= 0) || (flux_file && strlen(flux_file) && strcmp(flux_file,"NULL") && strcmp(flux_file,"0"))) { /* the I1,2,3 are usually in [n/s/cm2/st/AA] */ if (radius) source_area = radius*radius*PI*1e4; /* circular cm^2 */ else source_area = yheight*xwidth*1e4; /* square cm^2 */ p_in = source_area; /* cm2 */ p_in *= (Lmax-Lmin); /* AA. 1 bin=AA/n */ if (flux_file && strlen(flux_file) && strcmp(flux_file,"NULL") && strcmp(flux_file,"0") && !flux_file_perAA) p_in *= pTable.rows/(Lmax-Lmin); } else p_in = 1.0/4/PI; /* Small angle approx. */ p_in /= mcget_ncount(); if (!T1 && I1) p_in *= I1; if (radius == 0 && yheight == 0 && xwidth == 0) { fprintf(stderr,"Source_gen: %s: Error: Please specify source geometry (radius, yheight, xwidth)\n", NAME_CURRENT_COMP); exit(-1); } if (focus_xw*focus_yh == 0) { fprintf(stderr,"Source_gen: %s: Error: Please specify source target (focus_xw, focus_yh)\n", NAME_CURRENT_COMP); exit(-1); } MPI_MASTER( if (verbose) { printf("Source_gen: component %s ", NAME_CURRENT_COMP); if ((yheight == 0) || (xwidth == 0)) printf("(disk, radius=%g)", radius); else printf("(square %g x %g)",xwidth,yheight); if (dist) printf("\n focusing distance dist=%g area=%g x %g\n", dist, focus_xw, focus_yh); printf(" spectra "); printf("%.3f to %.3f AA (%.3f to %.3f meV)", Lmin, Lmax, 81.81/Lmax/Lmax, 81.81/Lmin/Lmin); printf("\n"); if (flux_file && strlen(flux_file) && strcmp(flux_file,"NULL") && strcmp(flux_file,"0")) { printf(" File %s for flux distribution used. Flux is dPhi/dlambda in [n/s/AA]. \n", flux_file); Table_Info(pTable); } else if (T1>=0 && I1) { if (T1 != 0) printf(" T1=%.1f K (%.3f AA)", T1, lambda1); if (T2*I2 != 0) printf(", T2=%.1f K (%.3f AA)", T2, lambda2); if (T3*I3 != 0) printf(", T3=%.1f K (%.3f AA)", T3, lambda3); if (T1) printf("\n"); printf(" Flux is dPhi/dlambda in [n/s/cm2].\n"); } else { printf(" Flux is Phi in [n/s].\n"); } if (xdiv_file && strlen(xdiv_file) && strcmp(xdiv_file,"NULL") && strcmp(xdiv_file,"0")) printf(" File %s x=[%g:%g] [m] xdiv=[%g:%g] [deg] used as horizontal phase space distribution.\n", xdiv_file, pTable_xmin, pTable_xmax, pTable_dxmin, pTable_dxmax); if (ydiv_file && strlen(ydiv_file) && strcmp(ydiv_file,"NULL") && strcmp(ydiv_file,"0")) printf(" File %s y=[%g:%g] [m] ydiv=[%g:%g] [deg] used as vertical phase space distribution.\n", ydiv_file, pTable_ymin, pTable_ymax, pTable_dymin, pTable_dymax); } else if (verbose == -1) printf("Source_gen: component %s unactivated", NAME_CURRENT_COMP); ); #undef flux_file #undef xdiv_file #undef ydiv_file #undef radius #undef dist #undef focus_xw #undef focus_yh #undef focus_aw #undef focus_ah #undef E0 #undef dE #undef lambda0 #undef dlambda #undef I1 #undef yheight #undef xwidth #undef verbose #undef T1 #undef flux_file_perAA #undef flux_file_log #undef Lmin #undef Lmax #undef Emin #undef Emax #undef T2 #undef I2 #undef T3 #undef I3 #undef zdepth #undef target_index #undef p_in #undef lambda1 #undef lambda2 #undef lambda3 #undef pTable #undef pTable_x #undef pTable_y #undef pTable_xmin #undef pTable_xmax #undef pTable_xsum #undef pTable_ymin #undef pTable_ymax #undef pTable_ysum #undef pTable_dxmin #undef pTable_dxmax #undef pTable_dymin #undef pTable_dymax return(_comp); } /* class_Source_gen_init */ _class_Guide_gravity *class_Guide_gravity_init(_class_Guide_gravity *_comp ) { #define w1 (_comp->_parameters.w1) #define h1 (_comp->_parameters.h1) #define w2 (_comp->_parameters.w2) #define h2 (_comp->_parameters.h2) #define l (_comp->_parameters.l) #define R0 (_comp->_parameters.R0) #define Qc (_comp->_parameters.Qc) #define alpha (_comp->_parameters.alpha) #define m (_comp->_parameters.m) #define W (_comp->_parameters.W) #define nslit (_comp->_parameters.nslit) #define d (_comp->_parameters.d) #define mleft (_comp->_parameters.mleft) #define mright (_comp->_parameters.mright) #define mtop (_comp->_parameters.mtop) #define mbottom (_comp->_parameters.mbottom) #define nhslit (_comp->_parameters.nhslit) #define G (_comp->_parameters.G) #define aleft (_comp->_parameters.aleft) #define aright (_comp->_parameters.aright) #define atop (_comp->_parameters.atop) #define abottom (_comp->_parameters.abottom) #define wavy (_comp->_parameters.wavy) #define wavy_z (_comp->_parameters.wavy_z) #define wavy_tb (_comp->_parameters.wavy_tb) #define wavy_lr (_comp->_parameters.wavy_lr) #define chamfers (_comp->_parameters.chamfers) #define chamfers_z (_comp->_parameters.chamfers_z) #define chamfers_lr (_comp->_parameters.chamfers_lr) #define chamfers_tb (_comp->_parameters.chamfers_tb) #define nelements (_comp->_parameters.nelements) #define nu (_comp->_parameters.nu) #define phase (_comp->_parameters.phase) #define reflect (_comp->_parameters.reflect) #define GVars (_comp->_parameters.GVars) #define pTable (_comp->_parameters.pTable) #define table_present (_comp->_parameters.table_present) SIG_MESSAGE("[_NL_SR2_1_init] component NL_SR2_1=Guide_gravity() INITIALISE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Guide_gravity.comp:341]"); double Gx=0, Gy=-GRAVITY, Gz=0; Coords mcLocG; int i; if (reflect && strlen(reflect) && strcmp(reflect,"NULL") && strcmp(reflect,"0")) { if (Table_Read(&pTable, reflect, 1) <= 0) /* read 1st block data from file into pTable */ exit(fprintf(stderr,"Guide_gravity: %s: can not read file %s\n", NAME_CURRENT_COMP, reflect)); table_present=1; } else { table_present=0; if (W < 0 || R0 < 0 || Qc < 0) { fprintf(stderr,"Guide_gravity: %s: W R0 Qc must be >0.\n", NAME_CURRENT_COMP); exit(-1); } } if (nslit <= 0 || nhslit <= 0) { fprintf(stderr,"Guide_gravity: %s: nslit nhslit must be >0.\n", NAME_CURRENT_COMP); exit(-1); } if (!w1 || !h1) { fprintf(stderr,"Guide_gravity: %s: input window is closed (w1=h1=0).\n", NAME_CURRENT_COMP); exit(-1); } if (d*nslit > w1) exit(fprintf(stderr, "Guide_gravity: %s: absorbing walls fill input window. No space left for transmission (d*nslit > w1).\n", NAME_CURRENT_COMP)); if (!w2) w2=w1; if (!h2) h2=h1; if (mcgravitation) G=-GRAVITY; mcLocG = rot_apply(ROT_A_CURRENT_COMP, coords_set(0,G,0)); coords_get(mcLocG, &Gx, &Gy, &Gz); strcpy(GVars.compcurname, NAME_CURRENT_COMP); if (l > 0 && nelements > 0) { Gravity_guide_Init(&GVars, w1, h1, w2, h2, l, R0, Qc, alpha, m, W, nslit, d, Gx, Gy, Gz, mleft, mright, mtop, mbottom, nhslit, wavy_lr, wavy_tb, wavy_z, wavy, chamfers_z, chamfers_lr, chamfers_tb, chamfers,nu,phase,aleft,aright,atop,abottom); if (!G) for (i=0; i<5; GVars.A[i++] = 0); if (GVars.fc_freq != 0 || GVars.fc_phase != 0) { if (w1 != w2 || h1 != h2) exit(fprintf(stderr,"Guide_gravity: %s: rotating slit pack must be straight (w1=w2 and h1=h2).\n", NAME_CURRENT_COMP)); printf("Guide_gravity: %s: Fermi Chopper mode: frequency=%g [Hz] phase=%g [deg]\n", NAME_CURRENT_COMP, GVars.fc_freq, GVars.fc_phase); } } else printf("Guide_gravity: %s: unactivated (l=0 or nelements=0)\n", NAME_CURRENT_COMP); #undef w1 #undef h1 #undef w2 #undef h2 #undef l #undef R0 #undef Qc #undef alpha #undef m #undef W #undef nslit #undef d #undef mleft #undef mright #undef mtop #undef mbottom #undef nhslit #undef G #undef aleft #undef aright #undef atop #undef abottom #undef wavy #undef wavy_z #undef wavy_tb #undef wavy_lr #undef chamfers #undef chamfers_z #undef chamfers_lr #undef chamfers_tb #undef nelements #undef nu #undef phase #undef reflect #undef GVars #undef pTable #undef table_present return(_comp); } /* class_Guide_gravity_init */ _class_Collimator_linear *class_Collimator_linear_init(_class_Collimator_linear *_comp ) { #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define length (_comp->_parameters.length) #define divergence (_comp->_parameters.divergence) #define transmission (_comp->_parameters.transmission) #define divergenceV (_comp->_parameters.divergenceV) #define slope (_comp->_parameters.slope) #define slopeV (_comp->_parameters.slopeV) SIG_MESSAGE("[_PANDA_ca1_init] component PANDA_ca1=Collimator_linear() INITIALISE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Collimator_linear.comp:55]"); slope = tan(MIN2RAD*divergence); slopeV= tan(MIN2RAD*divergenceV); if (xwidth > 0) { xmax = xwidth/2; xmin = -xmax; } if (yheight > 0) { ymax = yheight/2; ymin = -ymax; } if ((xmin >= xmax) || (ymin >= ymax)) { printf("Collimator_linear: %s: Null slit opening area !\n" "ERROR (xwidth,yheight,xmin,xmax,ymin,ymax). Exiting", NAME_CURRENT_COMP); exit(0); } #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef length #undef divergence #undef transmission #undef divergenceV #undef slope #undef slopeV return(_comp); } /* class_Collimator_linear_init */ _class_Filter_gen *class_Filter_gen_init(_class_Filter_gen *_comp ) { #define filename (_comp->_parameters.filename) #define options (_comp->_parameters.options) #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define thickness (_comp->_parameters.thickness) #define scaling (_comp->_parameters.scaling) #define verbose (_comp->_parameters.verbose) #define Mode_Table (_comp->_parameters.Mode_Table) #define Type_Table (_comp->_parameters.Type_Table) #define pTable (_comp->_parameters.pTable) SIG_MESSAGE("[_PANDA_sapphire_init] component PANDA_sapphire=Filter_gen() INITIALISE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Filter_gen.comp:126]"); Mode_Table = FLUX_ADAPT_MULT; Type_Table = UNKNOWN_TABLE; if (xwidth > 0) { xmax = xwidth/2; xmin = -xmax; } if (yheight > 0) { ymax = yheight/2; ymin = -ymax; } FilterGen_Mode(options, &Mode_Table, &Type_Table, &verbose); if (filename != NULL && strlen(filename) && strcmp(filename,"NULL") && strcmp(filename,"0")) { if (Table_Read(&pTable, filename, 1) <= 0) /* read 1st block data from filename into pTable */ exit(fprintf(stderr,"Filter_gen: %s: can not read filename %s\n", NAME_CURRENT_COMP, filename)); Table_Rebin(&pTable); /* rebin as evenly, increasing array */ if (pTable.rows < 2 || !pTable.step_x) { Table_Free(&pTable); } if (pTable.data) { FilterGen_Mode(pTable.header, &Mode_Table, &Type_Table, &verbose); if (verbose) { Table_Info(pTable); printf("Filter_gen: %s: Filter data [", NAME_CURRENT_COMP); if (Type_Table == ENERGY_TABLE) printf("Energy"); if (Type_Table == WAVEVECTOR_TABLE) printf("Wavevector"); if (Type_Table == WAVELENGTH_TABLE) printf("Wavelength"); if (Type_Table == UNKNOWN_TABLE) printf("UNKNOWN (not used)"); printf(", Flux] in "); if (Mode_Table == FLUX_ADAPT_MULT) printf("multiply"); else if (Mode_Table == FLUX_ADAPT_ADD) printf("add"); else printf("set"); printf(" mode\n"); } } else fprintf(stderr,"Filter_gen: %s: file %s contains no data.\n", NAME_CURRENT_COMP, filename); } else pTable.data = NULL; #undef filename #undef options #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef thickness #undef scaling #undef verbose #undef Mode_Table #undef Type_Table #undef pTable return(_comp); } /* class_Filter_gen_init */ _class_Slit *class_Slit_init(_class_Slit *_comp ) { #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define radius (_comp->_parameters.radius) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) SIG_MESSAGE("[_sk1_in_init] component sk1_in=Slit() INITIALISE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Slit.comp:50]"); if (xwidth > 0) { if (!xmin && !xmax) { xmax=xwidth/2; xmin=-xmax; } else { fprintf(stderr,"Slit: %s: Error: please specify EITHER xmin & xmax or xwidth\n", NAME_CURRENT_COMP); exit(-1); } } if (yheight > 0) { if (!ymin && !ymax) { ymax=yheight/2; ymin=-ymax; } else { fprintf(stderr,"Slit: %s: Error: please specify EITHER ymin & ymax or ywidth\n", NAME_CURRENT_COMP); exit(-1); } } if (xmin == 0 && xmax == 0 && ymin == 0 && ymax == 0 && radius == 0) { fprintf(stderr,"Slit: %s: Warning: Running with CLOSED slit - is this intentional?? \n", NAME_CURRENT_COMP); } #undef xmin #undef xmax #undef ymin #undef ymax #undef radius #undef xwidth #undef yheight return(_comp); } /* class_Slit_init */ _class_PSD_monitor *class_PSD_monitor_init(_class_PSD_monitor *_comp ) { #define nx (_comp->_parameters.nx) #define ny (_comp->_parameters.ny) #define filename (_comp->_parameters.filename) #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define restore_neutron (_comp->_parameters.restore_neutron) #define nowritefile (_comp->_parameters.nowritefile) #define PSD_N (_comp->_parameters.PSD_N) #define PSD_p (_comp->_parameters.PSD_p) #define PSD_p2 (_comp->_parameters.PSD_p2) SIG_MESSAGE("[_PSD_PrimBeam_init] component PSD_PrimBeam=PSD_monitor() INITIALISE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/PSD_monitor.comp:62]"); if (xwidth > 0) { xmax = xwidth/2; xmin = -xmax; } if (yheight > 0) { ymax = yheight/2; ymin = -ymax; } if ((xmin >= xmax) || (ymin >= ymax)){ printf("PSD_monitor: %s: Null detection area !\n" "ERROR (xwidth,yheight,xmin,xmax,ymin,ymax). Exiting", NAME_CURRENT_COMP); exit(0); } PSD_N = create_darr2d(nx, ny); PSD_p = create_darr2d(nx, ny); PSD_p2 = create_darr2d(nx, ny); int i, j; for (i=0; i_parameters.nL) #define filename (_comp->_parameters.filename) #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define Lmin (_comp->_parameters.Lmin) #define Lmax (_comp->_parameters.Lmax) #define restore_neutron (_comp->_parameters.restore_neutron) #define L_N (_comp->_parameters.L_N) #define L_p (_comp->_parameters.L_p) #define L_p2 (_comp->_parameters.L_p2) SIG_MESSAGE("[_LAM_PrimBeam_init] component LAM_PrimBeam=L_monitor() INITIALISE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/L_monitor.comp:65]"); if (xwidth > 0) { xmax = xwidth/2; xmin = -xmax; } if (yheight > 0) { ymax = yheight/2; ymin = -ymax; } if ((xmin >= xmax) || (ymin >= ymax)) { printf("L_monitor: %s: Null detection area !\n" "ERROR (xwidth,yheight,xmin,xmax,ymin,ymax). Exiting", NAME_CURRENT_COMP); exit(0); } L_N = create_darr1d(nL); L_p = create_darr1d(nL); L_p2 = create_darr1d(nL); int i; for (i=0; i_parameters.nh) #define nv (_comp->_parameters.nv) #define filename (_comp->_parameters.filename) #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define maxdiv_h (_comp->_parameters.maxdiv_h) #define maxdiv_v (_comp->_parameters.maxdiv_v) #define restore_neutron (_comp->_parameters.restore_neutron) #define nx (_comp->_parameters.nx) #define ny (_comp->_parameters.ny) #define nz (_comp->_parameters.nz) #define Div_N (_comp->_parameters.Div_N) #define Div_p (_comp->_parameters.Div_p) #define Div_p2 (_comp->_parameters.Div_p2) SIG_MESSAGE("[_DIV_PrimBeam_init] component DIV_PrimBeam=Divergence_monitor() INITIALISE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/Divergence_monitor.comp:71]"); int i,j; if (xwidth > 0) { xmax = xwidth/2; xmin = -xmax; } if (yheight > 0) { ymax = yheight/2; ymin = -ymax; } if ((xmin >= xmax) || (ymin >= ymax)) { printf("Divergence_monitor: %s: Null detection area !\n" "ERROR (xwidth,yheight,xmin,xmax,ymin,ymax). Exiting", NAME_CURRENT_COMP); exit(0); } Div_N = create_darr2d(nh, nv); Div_p = create_darr2d(nh, nv); Div_p2 = create_darr2d(nh, nv); for (i=0; i_parameters.reflect) #define transmit (_comp->_parameters.transmit) #define zwidth (_comp->_parameters.zwidth) #define yheight (_comp->_parameters.yheight) #define gap (_comp->_parameters.gap) #define NH (_comp->_parameters.NH) #define NV (_comp->_parameters.NV) #define mosaich (_comp->_parameters.mosaich) #define mosaicv (_comp->_parameters.mosaicv) #define r0 (_comp->_parameters.r0) #define t0 (_comp->_parameters.t0) #define Q (_comp->_parameters.Q) #define RV (_comp->_parameters.RV) #define RH (_comp->_parameters.RH) #define DM (_comp->_parameters.DM) #define mosaic (_comp->_parameters.mosaic) #define width (_comp->_parameters.width) #define height (_comp->_parameters.height) #define verbose (_comp->_parameters.verbose) #define order (_comp->_parameters.order) #define mos_rms_y (_comp->_parameters.mos_rms_y) #define mos_rms_z (_comp->_parameters.mos_rms_z) #define mos_rms_max (_comp->_parameters.mos_rms_max) #define mono_Q (_comp->_parameters.mono_Q) #define SlabWidth (_comp->_parameters.SlabWidth) #define SlabHeight (_comp->_parameters.SlabHeight) #define rTable (_comp->_parameters.rTable) #define tTable (_comp->_parameters.tTable) #define rTableFlag (_comp->_parameters.rTableFlag) #define tTableFlag (_comp->_parameters.tTableFlag) #define tiltH (_comp->_parameters.tiltH) #define tiltV (_comp->_parameters.tiltV) SIG_MESSAGE("[_PG002_mono_init] component PG002_mono=Monochromator_curved() INITIALISE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Monochromator_curved.comp:134]"); int i; if (mosaic != 0) { mos_rms_y = MIN2RAD*mosaic/sqrt(8*log(2)); mos_rms_z = mos_rms_y; } else { mos_rms_y = MIN2RAD*mosaich/sqrt(8*log(2)); mos_rms_z = MIN2RAD*mosaicv/sqrt(8*log(2)); } mos_rms_max = mos_rms_y > mos_rms_z ? mos_rms_y : mos_rms_z; mono_Q = Q; if (DM != 0) mono_Q = 2*PI/DM; if (mono_Q <= 0) { fprintf(stderr,"Monochromator_curved: %s: Error scattering vector Q = 0\n", NAME_CURRENT_COMP); exit(-1); } if (r0 < 0) { fprintf(stderr,"Monochromator_curved: %s: Error reflectivity r0 is negative\n", NAME_CURRENT_COMP); exit(-1); } if (r0 == 0) { fprintf(stderr,"Monochromator_curved: %s: Reflectivity r0 is null. Ignoring component.\n", NAME_CURRENT_COMP); } if (NH*NV == 0) { fprintf(stderr,"Monochromator_curved: %s: no slabs ??? (NH or NV=0)\n", NAME_CURRENT_COMP); exit(-1); } if (verbose && r0) { printf("Monochromator_curved: component %s Q=%.3g Angs-1 (DM=%.4g Angs)\n", NAME_CURRENT_COMP, mono_Q, 2*PI/mono_Q); if (NH*NV == 1) printf(" flat.\n"); else { if (NH > 1) { printf(" horizontal: %i blades", (int)NH); if (RH != 0) printf(" focusing with RH=%.3g [m]", RH); printf("\n"); } if (NV > 1) { printf(" vertical: %i blades", (int)NV); if (RV != 0) printf(" focusing with RV=%.3g [m]", RV); printf("\n"); } } } if (reflect != NULL && r0 && strlen(reflect) && strcmp(reflect,"NULL") && strcmp(reflect,"0")) { if (verbose) fprintf(stdout, "Monochromator_curved: %s: Reflectivity data (k, R) from %s\n", NAME_CURRENT_COMP, reflect); Table_Read(&rTable, reflect, 1); /* read 1st block data from file into rTable */ Table_Rebin(&rTable); /* rebin as evenly, increasing array */ if (rTable.rows < 2) Table_Free(&rTable); if (verbose) Table_Info(rTable); rTableFlag = 1; } else { rTableFlag = 0; } if (transmit != NULL && strlen(transmit) && strcmp(transmit,"NULL") && strcmp(transmit,"0")) { if (verbose) fprintf(stdout, "Monochromator_curved: %s: Transmission data (k, T) from %s\n", NAME_CURRENT_COMP, transmit); Table_Read(&tTable, transmit, 1); /* read 1st block data from file into rTable */ Table_Rebin(&tTable); /* rebin as evenly, increasing array */ if (tTable.rows < 2) Table_Free(&tTable); if (verbose) Table_Info(tTable); tTableFlag = 1; } else { tTableFlag = 0; } if (width == 0) SlabWidth = zwidth; else SlabWidth = (width+gap)/NH - gap; if (height == 0) SlabHeight = yheight; else SlabHeight = (height+gap)/NV - gap; tiltH=calloc((int)2*(NH+1),sizeof(double)); tiltV=calloc((int)2*(NV+1),sizeof(double)); if (!tiltH) printf("Monochromator_curved: %s: Warning: not enough memory to allocate tilts (NH=%g).\n", NAME_CURRENT_COMP, NH); else if (RH) { /* pre-compute tilts */ for (i=0;i<=NH;i++){ tiltH[i]=asin((i-(NH+1)/2)*(SlabWidth+gap)/RH); } } if (!tiltV) printf("Monochromator_curved: %s: Warning: not enough memory to allocate tilts (NV=%g).\n", NAME_CURRENT_COMP, NV); else if (RV) { for (i=0;i<=NV;i++){ tiltV[i]=-asin((i-(NV+1)/2)*(SlabHeight+gap)/RV); } } #undef reflect #undef transmit #undef zwidth #undef yheight #undef gap #undef NH #undef NV #undef mosaich #undef mosaicv #undef r0 #undef t0 #undef Q #undef RV #undef RH #undef DM #undef mosaic #undef width #undef height #undef verbose #undef order #undef mos_rms_y #undef mos_rms_z #undef mos_rms_max #undef mono_Q #undef SlabWidth #undef SlabHeight #undef rTable #undef tTable #undef rTableFlag #undef tTableFlag #undef tiltH #undef tiltV return(_comp); } /* class_Monochromator_curved_init */ _class_Monitor *class_Monitor_init(_class_Monitor *_comp ) { #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define restore_neutron (_comp->_parameters.restore_neutron) #define Nsum (_comp->_parameters.Nsum) #define psum (_comp->_parameters.psum) #define p2sum (_comp->_parameters.p2sum) SIG_MESSAGE("[_Mon_samplepos2_init] component Mon_samplepos2=Monitor() INITIALISE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/Monitor.comp:58]"); psum = 0; p2sum = 0; Nsum = 0; if (xwidth > 0) { xmax = xwidth/2; xmin = -xmax; } if (yheight > 0) { ymax = yheight/2; ymin = -ymax; } if ((xmin >= xmax) || (ymin >= ymax)) { printf("Monitor: %s: Null detection area !\n" "ERROR (xwidth,yheight,xmin,xmax,ymin,ymax). Exiting", NAME_CURRENT_COMP); exit(0); } #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef restore_neutron #undef Nsum #undef psum #undef p2sum return(_comp); } /* class_Monitor_init */ _class_NCrystal_sample *class_NCrystal_sample_init(_class_NCrystal_sample *_comp ) { #define cfg (_comp->_parameters.cfg) #define absorptionmode (_comp->_parameters.absorptionmode) #define multscat (_comp->_parameters.multscat) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define zdepth (_comp->_parameters.zdepth) #define radius (_comp->_parameters.radius) #define params (_comp->_parameters.params) #define geoparams (_comp->_parameters.geoparams) #define ncrystal_convfact_vsq2ekin (_comp->_parameters.ncrystal_convfact_vsq2ekin) #define ncrystal_convfact_ekin2vsq (_comp->_parameters.ncrystal_convfact_ekin2vsq) SIG_MESSAGE("[_PANDA_cryst_init] component PANDA_cryst=NCrystal_sample() INITIALISE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../contrib/NCrystal_sample.comp:173]"); //Print NCrystal version + sanity check setup. if ( NCRYSTAL_VERSION != ncrystal_version() ) { NCMCERR("Inconsistency detected between included ncrystal.h and linked NCrystal library!"); } if (ncsample_reported_version != ncrystal_version()) { if (ncsample_reported_version) { NCMCERR("Inconsistent NCrystal library versions detected - this should normally not be possible!"); } ncsample_reported_version = ncrystal_version(); printf( "NCrystal: McStas sample component(s) are using version %s of the NCrystal library.\n",ncrystal_version_str()); } //The following conversion factors might look slightly odd. They reflect the //fact that the various conversion factors used in McStas and NCrystal are not //completely consistent among each other (TODO: Follow up on this with McStas //developers!). Also McStas's V2K*K2V is not exactly 1. All in all, this can //give issues when a McStas user is trying to set up a narrow beam very //precisely in an instrument file, attempting to carefully hit a certain //narrow Bragg reflection in this NCrystal component. We can not completely //work around all issues here, but for now, we assume that the user is //carefully setting up things by specifying the wavelength to some source //component. That wavelength is then converted to the McStas state pars //(vx,vy,vz) via K2V. We thus here first use 1/K2V (and *not* V2K) to convert //back to a wavelength, and then we use NCrystal's conversion constants to //convert the resulting wavelength to kinetic energy needed for NCrystal's //interfaces. // 0.0253302959105844428609698658024319097260896937 is 1/(4*pi^2) ncrystal_convfact_vsq2ekin = ncrystal_wl2ekin(1.0) * 0.0253302959105844428609698658024319097260896937 / ( K2V*K2V ); ncrystal_convfact_ekin2vsq = 1.0 / ncrystal_convfact_vsq2ekin; //for our sanity, zero-initialise all instance-specific data: memset(¶ms,0,sizeof(params)); memset(¶ms,0,sizeof(geoparams)); ncrystalsample_initgeom(&geoparams, NAME_CURRENT_COMP, xwidth, yheight, zdepth, radius); if (!(absorptionmode==0||absorptionmode==1||absorptionmode==2)) NCMCERR("Invalid value of absorptionmode"); params.absmode = absorptionmode; /* Make sure NCrystal uses the legacy McStas MT RNG (ok if more than one component instance does this): */ /* NCrystal used an RNG internally, and can not accept an rng footprint with content, i.e. _rand01(_particle->randstate) */ /* - we therefore fall back to a hardcoded MT with a local randloc function in SHARE ^ */ mt_srandom(mcseed); ncrystal_setrandgen(randloc); /* access powder packingfactor (nb: always 1.0 for non-powders): */ double packingfactor = ncrystal_decodecfg_packfact(cfg); /* access crystal structure to get number density (natoms/volume): */ ncrystal_info_t info = ncrystal_create_info(cfg); double numberdensity = ncrystal_info_getnumberdensity(info); if( numberdensity <= 0.0 ) NCMCERR("Number density information is unavailable in the loaded NCrystal Info"); ncrystal_unref(&info); //numberdensity is the atomic number density in units of Aa^-3=1e30m^3, and //given that we have cross-sections in barn (1e-28m^2) and want to generate //distances in meters with -log(R)/(numberdensity*xsect), we get the unit //conversion factor of 0.01. We also apply the powder packing factor here (it //is guaranteed to be non-zero): params.density_factor = - 0.01 / ( numberdensity * packingfactor ); params.inv_density_factor = 1.0/params.density_factor; //TODO: The density used here is in principle different from the one //used in the Geant4 interface, which is possibly inconsistent when not using //.ncmat files (more info at https://github.com/mctools/ncrystal/issues/9). //Setup scattering: params.scat = ncrystal_create_scatter(cfg); params.proc_scat = ncrystal_cast_scat2proc(params.scat); params.proc_scat_isoriented = ! ncrystal_isnonoriented(params.proc_scat);; //Setup absorption: if (params.absmode) { params.proc_abs = ncrystal_cast_abs2proc(ncrystal_create_absorption(cfg)); if (!ncrystal_isnonoriented(params.proc_abs)) NCMCERR("Encountered oriented NCAbsorption process which is not currently supported by this component."); } #undef cfg #undef absorptionmode #undef multscat #undef xwidth #undef yheight #undef zdepth #undef radius #undef params #undef geoparams #undef ncrystal_convfact_vsq2ekin #undef ncrystal_convfact_ekin2vsq return(_comp); } /* class_NCrystal_sample_init */ int init(void) { /* called by mccode_main for PANDA:INITIALISE */ DEBUG_INSTR(); /* code_main/parseoptions/readparams sets instrument parameters value */ stracpy(instrument->_name, "PANDA", 256); /* Instrument 'PANDA' INITIALISE */ SIG_MESSAGE("[PANDA] INITIALISE [PANDA_Michal_DV_draft.instr:143]"); #define prim_shut_pos (instrument->_parameters.prim_shut_pos) #define sapphire (instrument->_parameters.sapphire) #define ca1 (instrument->_parameters.ca1) #define ca2 (instrument->_parameters.ca2) #define ca3 (instrument->_parameters.ca3) #define ca4 (instrument->_parameters.ca4) #define ms1 (instrument->_parameters.ms1) #define lms (instrument->_parameters.lms) #define lsa (instrument->_parameters.lsa) #define lad (instrument->_parameters.lad) #define ki (instrument->_parameters.ki) #define kf (instrument->_parameters.kf) #define dE (instrument->_parameters.dE) #define Q (instrument->_parameters.Q) #define mth (instrument->_parameters.mth) #define mtt (instrument->_parameters.mtt) #define mtx (instrument->_parameters.mtx) #define mty (instrument->_parameters.mty) #define mgy (instrument->_parameters.mgy) #define mfh (instrument->_parameters.mfh) #define mfv (instrument->_parameters.mfv) #define scatsense (instrument->_parameters.scatsense) #define sth (instrument->_parameters.sth) #define stt (instrument->_parameters.stt) #define stx (instrument->_parameters.stx) #define sty (instrument->_parameters.sty) #define stz (instrument->_parameters.stz) #define sgx (instrument->_parameters.sgx) #define sgy (instrument->_parameters.sgy) #define ss1_width (instrument->_parameters.ss1_width) #define ss1_height (instrument->_parameters.ss1_height) #define ss2_width (instrument->_parameters.ss2_width) #define ss2_height (instrument->_parameters.ss2_height) #define ath (instrument->_parameters.ath) #define att (instrument->_parameters.att) #define atx (instrument->_parameters.atx) #define aty (instrument->_parameters.aty) #define agy (instrument->_parameters.agy) #define afh (instrument->_parameters.afh) #define afv (instrument->_parameters.afv) { Lam = 4.0; dLam = 0.1; d_PG002 = 3.35461; switch(ca1) { case 20 : ca1_div = 20;break; case 40 : ca1_div = 40;break; case 60 : ca1_div = 60;break; default: ca1_div = 120;} switch(ca2) { case 15 : ca2_div = 15;break; case 40 : ca2_div = 40;break; case 60 : ca2_div = 60;break; default: ca2_div = 120;} switch(ca3) { case 15 : ca3_div = 15;break; case 40 : ca3_div = 40;break; case 60 : ca3_div = 60;break; default: ca3_div = 120;} switch(ca4) { case 15 : ca4_div = 15;break; case 40 : ca4_div = 40;break; case 60 : ca4_div = 60;break; default: ca4_div = 120;} /* input data decides the relevant params */ a1=0;a2=0;a3=0;a4=0;a5=0;a6=0; if (kf) { /* calculate default ath,att angles from kf */ my_kf = kf; if (dE){my_ki = sqrt(dE / 2.072 + kf*kf);} // meV and A-1 else {my_ki = kf;}; Lam = 2*PI/my_ki; dLam = 0.03 * Lam;} else if (ki) { /* calculate default mth,mtt angles from ki */ my_ki = ki; if (dE){my_kf = sqrt( ki*ki - dE /2.072);} // meV and A-1 else { my_kf = ki;}; // dE = 0 : ki = kf Lam = 2*PI/my_ki; dLam = 0.03 * Lam;} /* sample related parameters */ if ((Q) && (my_ki) && (my_kf)) { // calculate stt from momentum transfer my_thetas = acos ( (my_ki*my_ki + my_kf*my_kf - Q*Q)/ 2/my_ki/my_kf); a4 = my_thetas*RAD2DEG;} else {a4 = stt;}; a3 = sth; a1 = asin ( PI/d_PG002/my_ki)*RAD2DEG; a2 = 2*a1; a5 = asin ( PI/d_PG002/my_kf)*RAD2DEG; a6 = 2*a5; MINLam = Lam -dLam; MAXLam = Lam +dLam; printf("ki: %f A-1\n",my_ki); printf("kf: %f A-1\n",my_kf); printf("dE: %f meV\n",dE); printf("Lam: %f A\n",Lam); printf("dLam: %f A\n",dLam); printf("mth: %f deg\n",a1); printf("mtt: %f deg\n",a2); printf("sth: %f deg\n",a3); printf("stt: %f deg\n",a4); printf("ath: %f deg\n",a5); printf("att: %f deg\n",a6); } #undef prim_shut_pos #undef sapphire #undef ca1 #undef ca2 #undef ca3 #undef ca4 #undef ms1 #undef lms #undef lsa #undef lad #undef ki #undef kf #undef dE #undef Q #undef mth #undef mtt #undef mtx #undef mty #undef mgy #undef mfh #undef mfv #undef scatsense #undef sth #undef stt #undef stx #undef sty #undef stz #undef sgx #undef sgy #undef ss1_width #undef ss1_height #undef ss2_width #undef ss2_height #undef ath #undef att #undef atx #undef aty #undef agy #undef afh #undef afv _origin_setpos(); /* type Progress_bar */ _ColdSource_setpos(); /* type Source_gen */ _PrimaryBeam_setpos(); /* type Arm */ _NL_SR2_1_setpos(); /* type Guide_gravity */ _NL_SR2_2a_setpos(); /* type Guide_gravity */ _NL_SR2_2b_setpos(); /* type Guide_gravity */ _NL_SR2_2c_setpos(); /* type Guide_gravity */ _NL_SR2_3_setpos(); /* type Guide_gravity */ _SR2_Beamportwindow_setpos(); /* type Al_window */ _SR2_eob_setpos(); /* type Arm */ _PANDA_ca1_setpos(); /* type Collimator_linear */ _PANDA_sapphire_setpos(); /* type Filter_gen */ _sk1_in_setpos(); /* type Slit */ _sk1_out_setpos(); /* type Slit */ _PANDA_ms1_setpos(); /* type Slit */ _sk2_in_setpos(); /* type Slit */ _sk2_out_setpos(); /* type Slit */ _PSD_PrimBeam_setpos(); /* type PSD_monitor */ _LAM_PrimBeam_setpos(); /* type L_monitor */ _DIV_PrimBeam_setpos(); /* type Divergence_monitor */ _PANDA_mth_setpos(); /* type Arm */ _a_mono_setpos(); /* type Arm */ _PG002_mono_setpos(); /* type Monochromator_curved */ _PANDA_mtt_setpos(); /* type Arm */ _sk3_in_setpos(); /* type Slit */ _PANDA_ca2_setpos(); /* type Collimator_linear */ _sk3_out_setpos(); /* type Slit */ _PSD_mon1_setpos(); /* type PSD_monitor */ _LAM_mon1_setpos(); /* type L_monitor */ _PANDA_ss1_setpos(); /* type Slit */ _PSD_samplepos_setpos(); /* type PSD_monitor */ _Mon_samplepos2_setpos(); /* type Monitor */ _PANDA_sth_setpos(); /* type Arm */ _sample_setpos(); /* type Arm */ _PANDA_cryst_setpos(); /* type NCrystal_sample */ _PANDA_stt_setpos(); /* type Arm */ _PSD_scattered_setpos(); /* type PSD_monitor */ _PANDA_ss2_setpos(); /* type Slit */ _sk4_in_setpos(); /* type Slit */ _PANDA_ca3_setpos(); /* type Collimator_linear */ _sk4_out_setpos(); /* type Slit */ _PSD_mon2_setpos(); /* type PSD_monitor */ _PANDA_ath_setpos(); /* type Arm */ _analyser_setpos(); /* type Arm */ _PG002_ana_setpos(); /* type Monochromator_curved */ _PANDA_att_setpos(); /* type Arm */ _sk5_in_setpos(); /* type Slit */ _PANDA_ca4_setpos(); /* type Collimator_linear */ _sk5_out_setpos(); /* type Slit */ _a_detector_setpos(); /* type Arm */ _PSD_det_setpos(); /* type PSD_monitor */ _PSD_det1_setpos(); /* type PSD_monitor */ _PSD_det2_setpos(); /* type PSD_monitor */ /* call iteratively all components INITIALISE */ class_Progress_bar_init(&_origin_var); class_Source_gen_init(&_ColdSource_var); class_Guide_gravity_init(&_NL_SR2_1_var); class_Guide_gravity_init(&_NL_SR2_2a_var); class_Guide_gravity_init(&_NL_SR2_2b_var); class_Guide_gravity_init(&_NL_SR2_2c_var); class_Guide_gravity_init(&_NL_SR2_3_var); class_Collimator_linear_init(&_PANDA_ca1_var); class_Filter_gen_init(&_PANDA_sapphire_var); class_Slit_init(&_sk1_in_var); class_Slit_init(&_sk1_out_var); class_Slit_init(&_PANDA_ms1_var); class_Slit_init(&_sk2_in_var); class_Slit_init(&_sk2_out_var); class_PSD_monitor_init(&_PSD_PrimBeam_var); class_L_monitor_init(&_LAM_PrimBeam_var); class_Divergence_monitor_init(&_DIV_PrimBeam_var); class_Monochromator_curved_init(&_PG002_mono_var); class_Slit_init(&_sk3_in_var); class_Collimator_linear_init(&_PANDA_ca2_var); class_Slit_init(&_sk3_out_var); class_PSD_monitor_init(&_PSD_mon1_var); class_L_monitor_init(&_LAM_mon1_var); class_Slit_init(&_PANDA_ss1_var); class_PSD_monitor_init(&_PSD_samplepos_var); class_Monitor_init(&_Mon_samplepos2_var); class_NCrystal_sample_init(&_PANDA_cryst_var); class_PSD_monitor_init(&_PSD_scattered_var); class_Slit_init(&_PANDA_ss2_var); class_Slit_init(&_sk4_in_var); class_Collimator_linear_init(&_PANDA_ca3_var); class_Slit_init(&_sk4_out_var); class_PSD_monitor_init(&_PSD_mon2_var); class_Monochromator_curved_init(&_PG002_ana_var); class_Slit_init(&_sk5_in_var); class_Collimator_linear_init(&_PANDA_ca4_var); class_Slit_init(&_sk5_out_var); class_PSD_monitor_init(&_PSD_det_var); class_PSD_monitor_init(&_PSD_det1_var); class_PSD_monitor_init(&_PSD_det2_var); if (mcdotrace) display(); DEBUG_INSTR_END(); #ifdef OPENACC # include #ifdef USE_MPI int num_devices = acc_get_num_devices(acc_device_nvidia); int my_device = mpi_node_rank % num_devices; printf("Node %i should use device %i\n",mpi_node_rank,my_device); #pragma acc set device_num(my_device) device_type(acc_device_nvidia) #endif acc_attach( (void*)&_origin_var ); acc_attach( (void*)&_ColdSource_var ); acc_attach( (void*)&_PrimaryBeam_var ); acc_attach( (void*)&_NL_SR2_1_var ); acc_attach( (void*)&_NL_SR2_2a_var ); acc_attach( (void*)&_NL_SR2_2b_var ); acc_attach( (void*)&_NL_SR2_2c_var ); acc_attach( (void*)&_NL_SR2_3_var ); acc_attach( (void*)&_SR2_Beamportwindow_var ); acc_attach( (void*)&_SR2_eob_var ); acc_attach( (void*)&_PANDA_ca1_var ); acc_attach( (void*)&_PANDA_sapphire_var ); acc_attach( (void*)&_sk1_in_var ); acc_attach( (void*)&_sk1_out_var ); acc_attach( (void*)&_PANDA_ms1_var ); acc_attach( (void*)&_sk2_in_var ); acc_attach( (void*)&_sk2_out_var ); acc_attach( (void*)&_PSD_PrimBeam_var ); acc_attach( (void*)&_LAM_PrimBeam_var ); acc_attach( (void*)&_DIV_PrimBeam_var ); acc_attach( (void*)&_PANDA_mth_var ); acc_attach( (void*)&_a_mono_var ); acc_attach( (void*)&_PG002_mono_var ); acc_attach( (void*)&_PANDA_mtt_var ); acc_attach( (void*)&_sk3_in_var ); acc_attach( (void*)&_PANDA_ca2_var ); acc_attach( (void*)&_sk3_out_var ); acc_attach( (void*)&_PSD_mon1_var ); acc_attach( (void*)&_LAM_mon1_var ); acc_attach( (void*)&_PANDA_ss1_var ); acc_attach( (void*)&_PSD_samplepos_var ); acc_attach( (void*)&_Mon_samplepos2_var ); acc_attach( (void*)&_PANDA_sth_var ); acc_attach( (void*)&_sample_var ); acc_attach( (void*)&_PANDA_cryst_var ); acc_attach( (void*)&_PANDA_stt_var ); acc_attach( (void*)&_PSD_scattered_var ); acc_attach( (void*)&_PANDA_ss2_var ); acc_attach( (void*)&_sk4_in_var ); acc_attach( (void*)&_PANDA_ca3_var ); acc_attach( (void*)&_sk4_out_var ); acc_attach( (void*)&_PSD_mon2_var ); acc_attach( (void*)&_PANDA_ath_var ); acc_attach( (void*)&_analyser_var ); acc_attach( (void*)&_PG002_ana_var ); acc_attach( (void*)&_PANDA_att_var ); acc_attach( (void*)&_sk5_in_var ); acc_attach( (void*)&_PANDA_ca4_var ); acc_attach( (void*)&_sk5_out_var ); acc_attach( (void*)&_a_detector_var ); acc_attach( (void*)&_PSD_det_var ); acc_attach( (void*)&_PSD_det1_var ); acc_attach( (void*)&_PSD_det2_var ); #pragma acc update device(_origin_var) #pragma acc update device(_ColdSource_var) #pragma acc update device(_PrimaryBeam_var) #pragma acc update device(_NL_SR2_1_var) #pragma acc update device(_NL_SR2_2a_var) #pragma acc update device(_NL_SR2_2b_var) #pragma acc update device(_NL_SR2_2c_var) #pragma acc update device(_NL_SR2_3_var) #pragma acc update device(_SR2_Beamportwindow_var) #pragma acc update device(_SR2_eob_var) #pragma acc update device(_PANDA_ca1_var) #pragma acc update device(_PANDA_sapphire_var) #pragma acc update device(_sk1_in_var) #pragma acc update device(_sk1_out_var) #pragma acc update device(_PANDA_ms1_var) #pragma acc update device(_sk2_in_var) #pragma acc update device(_sk2_out_var) #pragma acc update device(_PSD_PrimBeam_var) #pragma acc update device(_LAM_PrimBeam_var) #pragma acc update device(_DIV_PrimBeam_var) #pragma acc update device(_PANDA_mth_var) #pragma acc update device(_a_mono_var) #pragma acc update device(_PG002_mono_var) #pragma acc update device(_PANDA_mtt_var) #pragma acc update device(_sk3_in_var) #pragma acc update device(_PANDA_ca2_var) #pragma acc update device(_sk3_out_var) #pragma acc update device(_PSD_mon1_var) #pragma acc update device(_LAM_mon1_var) #pragma acc update device(_PANDA_ss1_var) #pragma acc update device(_PSD_samplepos_var) #pragma acc update device(_Mon_samplepos2_var) #pragma acc update device(_PANDA_sth_var) #pragma acc update device(_sample_var) #pragma acc update device(_PANDA_cryst_var) #pragma acc update device(_PANDA_stt_var) #pragma acc update device(_PSD_scattered_var) #pragma acc update device(_PANDA_ss2_var) #pragma acc update device(_sk4_in_var) #pragma acc update device(_PANDA_ca3_var) #pragma acc update device(_sk4_out_var) #pragma acc update device(_PSD_mon2_var) #pragma acc update device(_PANDA_ath_var) #pragma acc update device(_analyser_var) #pragma acc update device(_PG002_ana_var) #pragma acc update device(_PANDA_att_var) #pragma acc update device(_sk5_in_var) #pragma acc update device(_PANDA_ca4_var) #pragma acc update device(_sk5_out_var) #pragma acc update device(_a_detector_var) #pragma acc update device(_PSD_det_var) #pragma acc update device(_PSD_det1_var) #pragma acc update device(_PSD_det2_var) acc_attach( (void*)&_instrument_var ); #pragma acc update device(_instrument_var) #endif return(0); } /* init */ /******************************************************************************* * components TRACE *******************************************************************************/ #define x (_particle->x) #define y (_particle->y) #define z (_particle->z) #define vx (_particle->vx) #define vy (_particle->vy) #define vz (_particle->vz) #define t (_particle->t) #define sx (_particle->sx) #define sy (_particle->sy) #define sz (_particle->sz) #define p (_particle->p) #define mcgravitation (_particle->mcgravitation) #define mcMagnet (_particle->mcMagnet) #define allow_backprop (_particle->allow_backprop) /* if on GPU, globally nullify sprintf,fprintf,printfs */ /* (Similar defines are available in each comp trace but */ /* those are not enough to handle external libs etc. ) */ #ifdef OPENACC #ifndef MULTICORE #define fprintf(stderr,...) printf(__VA_ARGS__) #define sprintf(string,...) printf(__VA_ARGS__) #define printf(...) noprintf() #define exit(...) noprintf() #define strcmp(a,b) str_comp(a,b) #define strlen(a) str_len(a) #endif #endif #define SCATTERED (_particle->_scattered) #define RESTORE (_particle->_restore) #define RESTORE_NEUTRON(_index, ...) _particle->_restore = _index; #define ABSORBED (_particle->_absorbed) #define mcget_run_num() _particle->_uid #define ABSORB0 do { DEBUG_STATE(); DEBUG_ABSORB(); MAGNET_OFF; ABSORBED++; return(_comp); } while(0) #define ABSORB ABSORB0 #pragma acc routine _class_Progress_bar *class_Progress_bar_trace(_class_Progress_bar *_comp , _class_particle *_particle) { ABSORBED=SCATTERED=RESTORE=0; #define profile (_comp->_parameters.profile) #define percent (_comp->_parameters.percent) #define flag_save (_comp->_parameters.flag_save) #define minutes (_comp->_parameters.minutes) #define IntermediateCnts (_comp->_parameters.IntermediateCnts) #define StartTime (_comp->_parameters.StartTime) #define EndTime (_comp->_parameters.EndTime) #define CurrentTime (_comp->_parameters.CurrentTime) SIG_MESSAGE("[_origin_trace] component origin=Progress_bar() TRACE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../misc/Progress_bar.comp:73]"); #ifndef OPENACC double ncount; ncount = mcget_run_num(); if (!StartTime) { time(&StartTime); /* compute starting time */ IntermediateCnts = 1e3; } time_t NowTime; time(&NowTime); /* compute initial estimate of computation duration */ if (!EndTime && ncount >= IntermediateCnts) { CurrentTime = NowTime; if (difftime(NowTime,StartTime) > 10 && ncount) { /* wait 10 sec before writing ETA */ EndTime = StartTime + (time_t)(difftime(NowTime,StartTime) *(double)mcget_ncount()/ncount); IntermediateCnts = 0; fprintf(stdout, "\nTrace ETA "); if (difftime(EndTime,StartTime) < 60.0) fprintf(stdout, "%g [s] %% ", difftime(EndTime,StartTime)); else if (difftime(EndTime,StartTime) > 3600.0) fprintf(stdout, "%g [h] %% ", difftime(EndTime,StartTime)/3600.0); else fprintf(stdout, "%g [min] %% ", difftime(EndTime,StartTime)/60.0); } else IntermediateCnts += 1e3; fflush(stdout); } /* display percentage when percent or minutes have reached step */ if (EndTime && mcget_ncount() && ( (minutes && difftime(NowTime,CurrentTime) > minutes*60) || (percent && !minutes && ncount >= IntermediateCnts)) ) { fprintf(stdout, "%d ", (int)(ncount*100.0/mcget_ncount())); fflush(stdout); CurrentTime = NowTime; IntermediateCnts = ncount + percent*mcget_ncount()/100; /* check that next intermediate ncount check is a multiple of the desired percentage */ IntermediateCnts = floor(IntermediateCnts*100/percent/mcget_ncount())*percent*mcget_ncount()/100; /* raise flag to indicate that we did something */ SCATTER; if (flag_save) save(NULL); } #endif /* Check for nan or inf particle parms */ if(isnan(p) || isinf(p)) ABSORB; if(isnan(t) || isinf(t)) ABSORB; if(isnan(vx) || isinf(vx)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(x) || isinf(x)) ABSORB; if(isnan(y) || isinf(y)) ABSORB; if(isnan(z) || isinf(z)) ABSORB; #undef profile #undef percent #undef flag_save #undef minutes #undef IntermediateCnts #undef StartTime #undef EndTime #undef CurrentTime return(_comp); } /* class_Progress_bar_trace */ #pragma acc routine _class_Source_gen *class_Source_gen_trace(_class_Source_gen *_comp , _class_particle *_particle) { ABSORBED=SCATTERED=RESTORE=0; #define flux_file (_comp->_parameters.flux_file) #define xdiv_file (_comp->_parameters.xdiv_file) #define ydiv_file (_comp->_parameters.ydiv_file) #define radius (_comp->_parameters.radius) #define dist (_comp->_parameters.dist) #define focus_xw (_comp->_parameters.focus_xw) #define focus_yh (_comp->_parameters.focus_yh) #define focus_aw (_comp->_parameters.focus_aw) #define focus_ah (_comp->_parameters.focus_ah) #define E0 (_comp->_parameters.E0) #define dE (_comp->_parameters.dE) #define lambda0 (_comp->_parameters.lambda0) #define dlambda (_comp->_parameters.dlambda) #define I1 (_comp->_parameters.I1) #define yheight (_comp->_parameters.yheight) #define xwidth (_comp->_parameters.xwidth) #define verbose (_comp->_parameters.verbose) #define T1 (_comp->_parameters.T1) #define flux_file_perAA (_comp->_parameters.flux_file_perAA) #define flux_file_log (_comp->_parameters.flux_file_log) #define Lmin (_comp->_parameters.Lmin) #define Lmax (_comp->_parameters.Lmax) #define Emin (_comp->_parameters.Emin) #define Emax (_comp->_parameters.Emax) #define T2 (_comp->_parameters.T2) #define I2 (_comp->_parameters.I2) #define T3 (_comp->_parameters.T3) #define I3 (_comp->_parameters.I3) #define zdepth (_comp->_parameters.zdepth) #define target_index (_comp->_parameters.target_index) #define p_in (_comp->_parameters.p_in) #define lambda1 (_comp->_parameters.lambda1) #define lambda2 (_comp->_parameters.lambda2) #define lambda3 (_comp->_parameters.lambda3) #define pTable (_comp->_parameters.pTable) #define pTable_x (_comp->_parameters.pTable_x) #define pTable_y (_comp->_parameters.pTable_y) #define pTable_xmin (_comp->_parameters.pTable_xmin) #define pTable_xmax (_comp->_parameters.pTable_xmax) #define pTable_xsum (_comp->_parameters.pTable_xsum) #define pTable_ymin (_comp->_parameters.pTable_ymin) #define pTable_ymax (_comp->_parameters.pTable_ymax) #define pTable_ysum (_comp->_parameters.pTable_ysum) #define pTable_dxmin (_comp->_parameters.pTable_dxmin) #define pTable_dxmax (_comp->_parameters.pTable_dxmax) #define pTable_dymin (_comp->_parameters.pTable_dymin) #define pTable_dymax (_comp->_parameters.pTable_dymax) SIG_MESSAGE("[_ColdSource_trace] component ColdSource=Source_gen() TRACE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../sources/Source_gen.comp:480]"); double dx=0,dy=0,xf,yf,rf,pdir,chi,v,r, lambda; double Maxwell; if (verbose >= 0) { z=0; if (radius) { chi=2*PI*rand01(); /* Choose point on source */ r=sqrt(rand01())*radius; /* with uniform distribution. */ x=r*cos(chi); y=r*sin(chi); } else { x = xwidth*randpm1()/2; /* select point on source (uniform) */ y = yheight*randpm1()/2; } if (zdepth != 0) z = zdepth*randpm1()/2; /* Assume linear wavelength distribution */ lambda = lambda0+dlambda*randpm1(); if (lambda <= 0) ABSORB; v = K2V*(2*PI/lambda); if (!focus_ah && !focus_aw) { randvec_target_rect_real(&xf, &yf, &rf, &pdir, 0, 0, dist, focus_xw, focus_yh, ROT_A_CURRENT_COMP, x, y, z, 2); dx = xf-x; dy = yf-y; rf = sqrt(dx*dx+dy*dy+dist*dist); vz=v*dist/rf; vy=v*dy/rf; vx=v*dx/rf; } else { randvec_target_rect_angular(&vx, &vy, &vz, &pdir, 0, 0, 1, focus_aw*DEG2RAD, focus_ah*DEG2RAD, ROT_A_CURRENT_COMP); dx = vx; dy = vy; /* from unit vector */ vx *= v; vy *= v; vz *= v; } p = p_in*pdir; /* spectral dependency from files or Maxwellians */ if (flux_file && strlen(flux_file) && strcmp(flux_file,"NULL") && strcmp(flux_file,"0")) { double binwidth=Table_Value(pTable, lambda, 1); if (flux_file_log) binwidth=exp(binwidth); p *= binwidth; } else if (T1 > 0 && I1 > 0) { Maxwell = I1 * SG_Maxwell(lambda, T1);; /* 1/AA */ if ((T2 > 0) && (I2 > 0)) { Maxwell += I2 * SG_Maxwell(lambda, T2); } if ((T3 > 0) && (I3 > 0)) { Maxwell += I3 * SG_Maxwell(lambda, T3);; } p *= Maxwell; } /* optional x-xdiv and y-ydiv weightening: position=along columns, div=along rows */ if (xdiv_file && strlen(xdiv_file) && strcmp(xdiv_file,"NULL") && strcmp(xdiv_file,"0") && pTable_xsum > 0) { double i,j; j = (x- pTable_xmin) /(pTable_xmax -pTable_xmin) *pTable_x.columns; i = (atan2(dx,rf)*RAD2DEG-pTable_dxmin)/(pTable_dxmax-pTable_dxmin)*pTable_x.rows; r = Table_Value2d(pTable_x, i,j); /* row, column */ p *= r/pTable_xsum; } if (ydiv_file && strlen(ydiv_file) && strcmp(ydiv_file,"NULL") && strcmp(ydiv_file,"0") && pTable_ysum > 0) { double i,j; j = (y- pTable_ymin) /(pTable_ymax -pTable_ymin) *pTable_y.columns; i = (atan2(dy,rf)*RAD2DEG- pTable_dymin)/(pTable_dymax-pTable_dymin)*pTable_y.rows; r = Table_Value2d(pTable_y, i,j); p *= r/pTable_ysum; } SCATTER; } /* Check for nan or inf particle parms */ if(isnan(p) || isinf(p)) ABSORB; if(isnan(t) || isinf(t)) ABSORB; if(isnan(vx) || isinf(vx)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(x) || isinf(x)) ABSORB; if(isnan(y) || isinf(y)) ABSORB; if(isnan(z) || isinf(z)) ABSORB; #undef flux_file #undef xdiv_file #undef ydiv_file #undef radius #undef dist #undef focus_xw #undef focus_yh #undef focus_aw #undef focus_ah #undef E0 #undef dE #undef lambda0 #undef dlambda #undef I1 #undef yheight #undef xwidth #undef verbose #undef T1 #undef flux_file_perAA #undef flux_file_log #undef Lmin #undef Lmax #undef Emin #undef Emax #undef T2 #undef I2 #undef T3 #undef I3 #undef zdepth #undef target_index #undef p_in #undef lambda1 #undef lambda2 #undef lambda3 #undef pTable #undef pTable_x #undef pTable_y #undef pTable_xmin #undef pTable_xmax #undef pTable_xsum #undef pTable_ymin #undef pTable_ymax #undef pTable_ysum #undef pTable_dxmin #undef pTable_dxmax #undef pTable_dymin #undef pTable_dymax return(_comp); } /* class_Source_gen_trace */ #pragma acc routine _class_Guide_gravity *class_Guide_gravity_trace(_class_Guide_gravity *_comp , _class_particle *_particle) { ABSORBED=SCATTERED=RESTORE=0; #define w1 (_comp->_parameters.w1) #define h1 (_comp->_parameters.h1) #define w2 (_comp->_parameters.w2) #define h2 (_comp->_parameters.h2) #define l (_comp->_parameters.l) #define R0 (_comp->_parameters.R0) #define Qc (_comp->_parameters.Qc) #define alpha (_comp->_parameters.alpha) #define m (_comp->_parameters.m) #define W (_comp->_parameters.W) #define nslit (_comp->_parameters.nslit) #define d (_comp->_parameters.d) #define mleft (_comp->_parameters.mleft) #define mright (_comp->_parameters.mright) #define mtop (_comp->_parameters.mtop) #define mbottom (_comp->_parameters.mbottom) #define nhslit (_comp->_parameters.nhslit) #define G (_comp->_parameters.G) #define aleft (_comp->_parameters.aleft) #define aright (_comp->_parameters.aright) #define atop (_comp->_parameters.atop) #define abottom (_comp->_parameters.abottom) #define wavy (_comp->_parameters.wavy) #define wavy_z (_comp->_parameters.wavy_z) #define wavy_tb (_comp->_parameters.wavy_tb) #define wavy_lr (_comp->_parameters.wavy_lr) #define chamfers (_comp->_parameters.chamfers) #define chamfers_z (_comp->_parameters.chamfers_z) #define chamfers_lr (_comp->_parameters.chamfers_lr) #define chamfers_tb (_comp->_parameters.chamfers_tb) #define nelements (_comp->_parameters.nelements) #define nu (_comp->_parameters.nu) #define phase (_comp->_parameters.phase) #define reflect (_comp->_parameters.reflect) #define GVars (_comp->_parameters.GVars) #define pTable (_comp->_parameters.pTable) #define table_present (_comp->_parameters.table_present) SIG_MESSAGE("[_NL_SR2_1_trace] component NL_SR2_1=Guide_gravity() TRACE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Guide_gravity.comp:396]"); if (l > 0 && nelements > 0) { double B, C, dt; int ret, bounces = 0, i=0; double this_width, this_height; double angle=0; if (GVars.fc_freq != 0 || GVars.fc_phase != 0) { /* rotate neutron w/r to guide element */ /* approximation of rotating straight Fermi Chopper */ Coords X = coords_set(x,y,z-l/2); /* current coordinates of neutron in centered static frame */ Rotation R; double dt=(-z+l/2)/vz; /* time shift to each center of slit package */ angle=fmod(360*GVars.fc_freq*(t+dt)+GVars.fc_phase, 360); /* in deg */ /* modify angle so that Z0 guide side is always in front of incoming neutron */ if (angle > 90 && angle < 270) { angle -= 180; } angle *= DEG2RAD; rot_set_rotation(R, 0, -angle, 0); /* will rotate neutron instead of comp: negative side */ /* apply rotation to centered coordinates */ Coords RX = rot_apply(R, X); coords_get(RX, &x, &y, &z); z = z+l/2; /* rotate speed */ X = coords_set(vx,vy,vz); RX = rot_apply(R, X); coords_get(RX, &vx, &vy, &vz); } for (i=0; i<7; GVars.N_reflection[i++] = 0); /* propagate to box input (with gravitation) in comp local coords */ /* A = 0.5 n.g; B = n.v; C = n.(r-W); */ /* 0=Z0 side: n=(0, 0, -l) ; W = (0, 0, 0) (at z=0, guide input)*/ B = -l*vz; C = -l*z; ret = solve_2nd_order(&dt, NULL, GVars.A[0], B, C); if (ret==0) ABSORB; if (dt>0.0) PROP_GRAV_DT(dt, GVars.gx, GVars.gy, GVars.gz); else if (angle) ABSORB; GVars.N_reflection[6]++; this_width = w1; this_height = h1; /* check if we are in the box input, else absorb */ if (fabs(x) > this_width/2 || fabs(y) > this_height/2) ABSORB; else { double w_edge, w_adj; /* Channel displacement on X */ double h_edge, h_adj; /* Channel displacement on Y */ double w_chnum,h_chnum; /* channel indexes */ SCATTER; /* X: Shift origin to center of channel hit (absorb if hit dividing walls) */ x += w1/2.0; w_chnum = floor(x/(GVars.w1c+d)); /* 0= right side, nslit+1=left side */ w_edge = w_chnum*(GVars.w1c+d); if(x - w_edge > GVars.w1c) { x -= w1/2.0; /* Re-adjust origin */ ABSORB; } w_adj = w_edge + (GVars.w1c)/2.0; x -= w_adj; w_adj -= w1/2.0; /* Y: Shift origin to center of channel hit (absorb if hit dividing walls) */ y += h1/2.0; h_chnum = floor(y/(GVars.h1c+d)); /* 0= lower side, nslit+1=upper side */ h_edge = h_chnum*(GVars.h1c+d); if(y - h_edge > GVars.h1c) { y -= h1/2.0; /* Re-adjust origin */ ABSORB; } h_adj = h_edge + (GVars.h1c)/2.0; y -= h_adj; h_adj -= h1/2.0; /* neutron is now in the input window of the guide */ /* do loops on reflections in the box */ for(;;) { /* get intersections for all box sides */ double q, nx,ny,nz; double this_length; int side=0; bounces++; /* now look for intersection with guide sides and exit */ side = Gravity_guide_Trace(&dt, &GVars, x, y, z, vx, vy, vz, w_chnum, nslit, h_chnum, nhslit, &nx, &ny, &nz, _particle); /* only positive dt are valid */ /* exit reflection loops if no intersection (neutron is after box) */ if (side == 0 || dt <= 0) { if (GVars.warnings < 100) fprintf(stderr,"%s: warning: neutron has entered guide, but can not exit !\n", GVars.compcurname); GVars.warnings++; x += w_adj; y += h_adj; ABSORB; } /* should never occur */ /* propagate to dt */ PROP_GRAV_DT(dt, GVars.gx, GVars.gy, GVars.gz); /* do reflection on speed for l/r/u/d sides */ if (side == 5) /* neutron reaches end of guide: end loop and exit comp */ { GVars.N_reflection[side]++; x += w_adj; y += h_adj; SCATTER; x -= w_adj; y -= h_adj; break; } /* else reflection on a guide wall */ if(GVars.M[side] == 0 || Qc == 0 || R0 == 0) /* walls are absorbing */ { x += w_adj; y += h_adj; ABSORB; } /* handle chamfers */ this_width = w1+(w2-w1)*z/l; this_height= h1+(h2-h1)*z/l; this_length= fmod(z, l/nelements); /* absorb on input/output of element parts */ if (GVars.chamfer_z && (this_lengthl/nelements-GVars.chamfer_z)) { x += w_adj; y += h_adj; ABSORB; } /* absorb on l/r/t/b sides */ if (GVars.chamfer_lr && (side==1 || side==2) && (fabs(y+h_adj)>this_height/2-GVars.chamfer_lr)) { x += w_adj; y += h_adj; ABSORB; } if (GVars.chamfer_tb && (side==3 || side==4) && (fabs(x+w_adj)>this_width/2- GVars.chamfer_tb)) { x += w_adj; y += h_adj; ABSORB; } /* change/mirror velocity: h_f = v - n.2*n.v/|n|^2 */ GVars.N_reflection[side]++; /* GVars.norm_n2 > 0 was checked at INIT */ /* compute n.v using current values */ B = scalar_prod(vx,vy,vz,nx,ny,nz); dt = 2*B/GVars.norm_n2[side]; /* 2*n.v/|n|^2 */ vx -= nx*dt; vy -= ny*dt; vz -= nz*dt; /* compute q and modify neutron weight */ /* scattering q=|n_i-n_f| = V2Q*|vf - v| = V2Q*2*n.v/|n| */ q = 2*V2Q*fabs(B)/GVars.norm_n[side]; if (table_present==1) TableReflecFunc(q, &pTable, &B); else { double par[] = {R0, Qc, GVars.Alpha[side], GVars.M[side], W}; StdReflecFunc(q, par, &B); } if (B <= 0) { x += w_adj; y += h_adj; ABSORB; } else p *= B; x += w_adj; y += h_adj; SCATTER; x -= w_adj; y -= h_adj; GVars.N_reflection[0]++; /* go to the next reflection */ if (bounces > 1000) ABSORB; } /* end for */ x += w_adj; y += h_adj; /* Re-adjust origin after SCATTER */ } if (GVars.fc_freq != 0 || GVars.fc_phase != 0) { /* rotate back neutron w/r to guide element */ /* approximation of rotating straight Fermi Chopper */ Coords X = coords_set(x,y,z-l/2); /* current coordinates of neutron in centered static frame */ Rotation R; rot_set_rotation(R, 0, angle, 0); /* will rotate back neutron: positive side */ /* apply rotation to centered coordinates */ Coords RX = rot_apply(R, X); coords_get(RX, &x, &y, &z); z = z+l/2; /* rotate speed */ X = coords_set(vx,vy,vz); RX = rot_apply(R, X); coords_get(RX, &vx, &vy, &vz); } } /* if l */ /* Check for nan or inf particle parms */ if(isnan(p) || isinf(p)) ABSORB; if(isnan(t) || isinf(t)) ABSORB; if(isnan(vx) || isinf(vx)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(x) || isinf(x)) ABSORB; if(isnan(y) || isinf(y)) ABSORB; if(isnan(z) || isinf(z)) ABSORB; #undef w1 #undef h1 #undef w2 #undef h2 #undef l #undef R0 #undef Qc #undef alpha #undef m #undef W #undef nslit #undef d #undef mleft #undef mright #undef mtop #undef mbottom #undef nhslit #undef G #undef aleft #undef aright #undef atop #undef abottom #undef wavy #undef wavy_z #undef wavy_tb #undef wavy_lr #undef chamfers #undef chamfers_z #undef chamfers_lr #undef chamfers_tb #undef nelements #undef nu #undef phase #undef reflect #undef GVars #undef pTable #undef table_present return(_comp); } /* class_Guide_gravity_trace */ #pragma acc routine _class_Al_window *class_Al_window_trace(_class_Al_window *_comp , _class_particle *_particle) { ABSORBED=SCATTERED=RESTORE=0; #define thickness (_comp->_parameters.thickness) SIG_MESSAGE("[_SR2_Beamportwindow_trace] component SR2_Beamportwindow=Al_window() TRACE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../contrib/Al_window.comp:68]"); double v; /* Neutron velocity */ double dt0; /* Flight times through sample */ double dist; double Al_s_tot_lambda,Al_my_tot,Al_my_a ; /* total XS (barn), total scattering length (m-1), absorption scat. length */ double lambda; /* neutrons wavelength */ PROP_Z0; dt0=thickness/vz; v=sqrt(vx*vx+vy*vy+vz*vz); PROP_DT(dt0); dist=v*dt0; lambda=sqrt(81.81/(VS2E*v*v)); Al_s_tot_lambda= Al_pf_A+Al_pf_B1*lambda+ Al_pf_B2*lambda*lambda+ Al_pf_B3*lambda*lambda*lambda; Al_s_tot_lambda+=Al_pf_B4*lambda*lambda*lambda*lambda; Al_my_tot=Al_rho / Al_mmol * Al_s_tot_lambda * avogadro * 10; Al_my_a = Al_my_a_v/v; p *=exp(-Al_my_a*dist);/* neutron passes window without any interaction */ /* TODO: scatter in Debye-Scherrer cone */ /* Check for nan or inf particle parms */ if(isnan(p) || isinf(p)) ABSORB; if(isnan(t) || isinf(t)) ABSORB; if(isnan(vx) || isinf(vx)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(x) || isinf(x)) ABSORB; if(isnan(y) || isinf(y)) ABSORB; if(isnan(z) || isinf(z)) ABSORB; #undef thickness return(_comp); } /* class_Al_window_trace */ #pragma acc routine _class_Collimator_linear *class_Collimator_linear_trace(_class_Collimator_linear *_comp , _class_particle *_particle) { ABSORBED=SCATTERED=RESTORE=0; #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define length (_comp->_parameters.length) #define divergence (_comp->_parameters.divergence) #define transmission (_comp->_parameters.transmission) #define divergenceV (_comp->_parameters.divergenceV) #define slope (_comp->_parameters.slope) #define slopeV (_comp->_parameters.slopeV) SIG_MESSAGE("[_PANDA_ca1_trace] component PANDA_ca1=Collimator_linear() TRACE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Collimator_linear.comp:70]"); double phi, dt; PROP_Z0; if (xxmax || yymax) ABSORB; dt = length/vz; PROP_DT(dt); if (xxmax || yymax) ABSORB; if(slope > 0.0) { phi = fabs(vx/vz); if (phi > slope) ABSORB; else p *= transmission*(1.0 - phi/slope); SCATTER; } if (slopeV > 0) { phi = fabs(vy/vz); if (phi > slopeV) ABSORB; else p *= transmission*(1.0 - phi/slopeV); SCATTER; } /* Check for nan or inf particle parms */ if(isnan(p) || isinf(p)) ABSORB; if(isnan(t) || isinf(t)) ABSORB; if(isnan(vx) || isinf(vx)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(x) || isinf(x)) ABSORB; if(isnan(y) || isinf(y)) ABSORB; if(isnan(z) || isinf(z)) ABSORB; #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef length #undef divergence #undef transmission #undef divergenceV #undef slope #undef slopeV return(_comp); } /* class_Collimator_linear_trace */ #pragma acc routine _class_Filter_gen *class_Filter_gen_trace(_class_Filter_gen *_comp , _class_particle *_particle) { ABSORBED=SCATTERED=RESTORE=0; #define filename (_comp->_parameters.filename) #define options (_comp->_parameters.options) #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define thickness (_comp->_parameters.thickness) #define scaling (_comp->_parameters.scaling) #define verbose (_comp->_parameters.verbose) #define Mode_Table (_comp->_parameters.Mode_Table) #define Type_Table (_comp->_parameters.Type_Table) #define pTable (_comp->_parameters.pTable) SIG_MESSAGE("[_PANDA_sapphire_trace] component PANDA_sapphire=Filter_gen() TRACE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Filter_gen.comp:167]"); double v2, K, L, E, X, new_p; PROP_Z0; if (Type_Table && (x>xmin && xymin && y_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define radius (_comp->_parameters.radius) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) SIG_MESSAGE("[_sk1_in_trace] component sk1_in=Slit() TRACE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Slit.comp:71]"); PROP_Z0; if (((radius == 0) && (xxmax || yymax)) || ((radius != 0) && (x*x + y*y > radius*radius))) ABSORB; else SCATTER; /* Check for nan or inf particle parms */ if(isnan(p) || isinf(p)) ABSORB; if(isnan(t) || isinf(t)) ABSORB; if(isnan(vx) || isinf(vx)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(x) || isinf(x)) ABSORB; if(isnan(y) || isinf(y)) ABSORB; if(isnan(z) || isinf(z)) ABSORB; #undef xmin #undef xmax #undef ymin #undef ymax #undef radius #undef xwidth #undef yheight return(_comp); } /* class_Slit_trace */ #pragma acc routine _class_PSD_monitor *class_PSD_monitor_trace(_class_PSD_monitor *_comp , _class_particle *_particle) { ABSORBED=SCATTERED=RESTORE=0; #define nx (_comp->_parameters.nx) #define ny (_comp->_parameters.ny) #define filename (_comp->_parameters.filename) #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define restore_neutron (_comp->_parameters.restore_neutron) #define nowritefile (_comp->_parameters.nowritefile) #define PSD_N (_comp->_parameters.PSD_N) #define PSD_p (_comp->_parameters.PSD_p) #define PSD_p2 (_comp->_parameters.PSD_p2) SIG_MESSAGE("[_PSD_PrimBeam_trace] component PSD_PrimBeam=PSD_monitor() TRACE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/PSD_monitor.comp:88]"); PROP_Z0; if (x>xmin && xymin && y_parameters.nL) #define filename (_comp->_parameters.filename) #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define Lmin (_comp->_parameters.Lmin) #define Lmax (_comp->_parameters.Lmax) #define restore_neutron (_comp->_parameters.restore_neutron) #define L_N (_comp->_parameters.L_N) #define L_p (_comp->_parameters.L_p) #define L_p2 (_comp->_parameters.L_p2) SIG_MESSAGE("[_LAM_PrimBeam_trace] component LAM_PrimBeam=L_monitor() TRACE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/L_monitor.comp:90]"); PROP_Z0; if (x>xmin && xymin && y= 0 && i < nL) { double p2 = p*p; #pragma acc atomic L_N[i] = L_N[i] +1; #pragma acc atomic L_p[i] = L_p[i] + p; #pragma acc atomic L_p2[i] = L_p2[i] + p2; SCATTER; } } if (restore_neutron) { RESTORE_NEUTRON(INDEX_CURRENT_COMP, x, y, z, vx, vy, vz, t, sx, sy, sz, p); } /* Check for nan or inf particle parms */ if(isnan(p) || isinf(p)) ABSORB; if(isnan(t) || isinf(t)) ABSORB; if(isnan(vx) || isinf(vx)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(x) || isinf(x)) ABSORB; if(isnan(y) || isinf(y)) ABSORB; if(isnan(z) || isinf(z)) ABSORB; #undef nL #undef filename #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef Lmin #undef Lmax #undef restore_neutron #undef L_N #undef L_p #undef L_p2 return(_comp); } /* class_L_monitor_trace */ #pragma acc routine _class_Divergence_monitor *class_Divergence_monitor_trace(_class_Divergence_monitor *_comp , _class_particle *_particle) { ABSORBED=SCATTERED=RESTORE=0; #define nh (_comp->_parameters.nh) #define nv (_comp->_parameters.nv) #define filename (_comp->_parameters.filename) #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define maxdiv_h (_comp->_parameters.maxdiv_h) #define maxdiv_v (_comp->_parameters.maxdiv_v) #define restore_neutron (_comp->_parameters.restore_neutron) #define nx (_comp->_parameters.nx) #define ny (_comp->_parameters.ny) #define nz (_comp->_parameters.nz) #define Div_N (_comp->_parameters.Div_N) #define Div_p (_comp->_parameters.Div_p) #define Div_p2 (_comp->_parameters.Div_p2) SIG_MESSAGE("[_DIV_PrimBeam_trace] component DIV_PrimBeam=Divergence_monitor() TRACE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/Divergence_monitor.comp:99]"); int i,j; double h_div, v_div; double v, vn; PROP_Z0; if (x>xmin && xymin && y -maxdiv_h && v_div < maxdiv_v && v_div > -maxdiv_v) { i = floor((h_div + maxdiv_h)*nh/(2.0*maxdiv_h)); j = floor((v_div + maxdiv_v)*nv/(2.0*maxdiv_v)); double p2 = p*p; #pragma acc atomic Div_N[i][j] = Div_N[i][j] + 1; #pragma acc atomic Div_p[i][j] = Div_p[i][j] + p; #pragma acc atomic Div_p2[i][j] = Div_p2[i][j] + p2; SCATTER; } } if (restore_neutron) { RESTORE_NEUTRON(INDEX_CURRENT_COMP, x, y, z, vx, vy, vz, t, sx, sy, sz, p); } /* Check for nan or inf particle parms */ if(isnan(p) || isinf(p)) ABSORB; if(isnan(t) || isinf(t)) ABSORB; if(isnan(vx) || isinf(vx)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(x) || isinf(x)) ABSORB; if(isnan(y) || isinf(y)) ABSORB; if(isnan(z) || isinf(z)) ABSORB; #undef nh #undef nv #undef filename #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef maxdiv_h #undef maxdiv_v #undef restore_neutron #undef nx #undef ny #undef nz #undef Div_N #undef Div_p #undef Div_p2 return(_comp); } /* class_Divergence_monitor_trace */ #pragma acc routine _class_Monochromator_curved *class_Monochromator_curved_trace(_class_Monochromator_curved *_comp , _class_particle *_particle) { ABSORBED=SCATTERED=RESTORE=0; #define reflect (_comp->_parameters.reflect) #define transmit (_comp->_parameters.transmit) #define zwidth (_comp->_parameters.zwidth) #define yheight (_comp->_parameters.yheight) #define gap (_comp->_parameters.gap) #define NH (_comp->_parameters.NH) #define NV (_comp->_parameters.NV) #define mosaich (_comp->_parameters.mosaich) #define mosaicv (_comp->_parameters.mosaicv) #define r0 (_comp->_parameters.r0) #define t0 (_comp->_parameters.t0) #define Q (_comp->_parameters.Q) #define RV (_comp->_parameters.RV) #define RH (_comp->_parameters.RH) #define DM (_comp->_parameters.DM) #define mosaic (_comp->_parameters.mosaic) #define width (_comp->_parameters.width) #define height (_comp->_parameters.height) #define verbose (_comp->_parameters.verbose) #define order (_comp->_parameters.order) #define mos_rms_y (_comp->_parameters.mos_rms_y) #define mos_rms_z (_comp->_parameters.mos_rms_z) #define mos_rms_max (_comp->_parameters.mos_rms_max) #define mono_Q (_comp->_parameters.mono_Q) #define SlabWidth (_comp->_parameters.SlabWidth) #define SlabHeight (_comp->_parameters.SlabHeight) #define rTable (_comp->_parameters.rTable) #define tTable (_comp->_parameters.tTable) #define rTableFlag (_comp->_parameters.rTableFlag) #define tTableFlag (_comp->_parameters.tTableFlag) #define tiltH (_comp->_parameters.tiltH) #define tiltV (_comp->_parameters.tiltV) SIG_MESSAGE("[_PG002_mono_trace] component PG002_mono=Monochromator_curved() TRACE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Monochromator_curved.comp:219]"); double dt; double Gauss_X[] = {-0.987992518020485, -0.937273392400706, -0.848206583410427, -0.724417731360170, -0.570972172608539, -0.394151347077563, -0.201194093997435, 0, 0.201194093997435, 0.394151347077563, 0.570972172608539, 0.724417731360170, 0.848206583410427, 0.937273392400706, 0.987992518020485}; double Gauss_W[] = {0.030753241996117, 0.070366047488108, 0.107159220467172, 0.139570677926154, 0.166269205816994, 0.186161000115562, 0.198431485327111, 0.202578241925561, 0.198431485327111, 0.186161000115562, 0.166269205816994, 0.139570677926154, 0.107159220467172, 0.070366047488108, 0.030753241996117}; if(vx != 0.0 && (dt = -x/vx) >= 0.0 && r0) { /* Moving towards crystal? */ double zmin,zmax, ymin,ymax; double yy,zz; zmax = ((NH*(SlabWidth+gap))-gap)/2.0; zmin = -zmax; ymax = ((NV*(SlabHeight+gap))-gap)/2.0; ymin = -ymax; /* Test-propagate to crystal plane */ zz=z+vz*dt; yy=y+vy*dt; if (zz>zmin && zzymin && yy 2*k/mono_Q) Q_order--; if((!order && Q_order > 0) || (Q_order == fabs(order) && order)) { /* Bragg scattering possible? */ double q0, q0x, theta, delta, p_reflect, my_r0; q0 = Q_order*mono_Q; q0x = ratio < 0 ? -q0 : q0; theta = asin(q0/(2*k)); /* Actual bragg angle */ /* Make MC choice: reflect or transmit? */ delta = asin(fabs(kux)) - theta; if (rTableFlag) { my_r0 = r0*Table_Value(rTable, k, 1); /* 2nd column */ } else my_r0 = r0; if (my_r0 > 1) { if (my_r0 > 1.01 && verbose) fprintf(stdout, "Warning: Monochromator_curved : lowered reflectivity from %f to 1 (k=%f)\n", my_r0, k); my_r0=0.999; } if (my_r0 < 0) { if (verbose) fprintf(stdout, "Warning: Monochromator_curved : raised reflectivity from %f to 0 (k=%f)\n", my_r0, k); my_r0=0; } p_reflect = fabs(my_r0)*exp(-kiz*kiz/(kiy*kiy + kiz*kiz)*(delta*delta)/ (2*mos_rms_y*mos_rms_y))* exp(-kiy*kiy/(kiy*kiy + kiz*kiz)*(delta*delta)/ (2*mos_rms_z*mos_rms_z)); double rr=rand01(); if(rr <= p_reflect) { /* Reflect */ double bx,by,bz,ax,ay,az,phi; double cos_2theta,k_sin_2theta,cos_phi,sin_phi,q_x,q_y,q_z; double total,c1x,c1y,c1z,w,mos_sample; int i=0; cos_2theta = cos(2*theta); k_sin_2theta = k*sin(2*theta); /* Get unit normal to plane containing ki and most probable kf */ vec_prod(bx, by, bz, kix, kiy, kiz, q0x, 0, 0); NORM(bx,by,bz); bx = bx * k_sin_2theta; by = by * k_sin_2theta; bz = bz * k_sin_2theta; /* Get unit vector normal to ki and b */ vec_prod(ax, ay, az, bx, by, bz, kux, kuy, kuz); /* Compute the total scattering probability at this ki */ total = 0; /* Choose width of Gaussian distribution to sample the angle * phi on the Debye-Scherrer cone for the scattered neutron. * The radius of the Debye-Scherrer cone is smaller by a * factor 1/cos(theta) than the radius of the (partial) sphere * describing the possible orientations of Q due to mosaicity, so we * start with a width 1/cos(theta) greater than the largest of * the two mosaics. */ mos_sample = mos_rms_max/cos(theta); c1x = kix*(cos_2theta-1); c1y = kiy*(cos_2theta-1); c1z = kiz*(cos_2theta-1); /* Loop, repeatedly reducing the sample width until it is small * enough to avoid sampling scattering directions with * ridiculously low scattering probability. * Use a cut-off at 5 times the gauss width for considering * scattering probability as well as for integration limits * when integrating the sampled distribution below. */ for(i=0; i<100; i++) { w = 5*mos_sample; cos_phi = cos(w); sin_phi = sin(w); q_x = c1x + cos_phi*ax + sin_phi*bx; q_y = (c1y + cos_phi*ay + sin_phi*by)/mos_rms_z; q_z = (c1z + cos_phi*az + sin_phi*bz)/mos_rms_y; /* Stop when we get near a factor of 25=5^2. */ if(q_z*q_z + q_y*q_y < (25/(2.0/3.0))*(q_x*q_x)) break; mos_sample *= (2.0/3.0); } /* Now integrate the chosen sampling distribution, using a * cut-off at five times sigma. */ for(i = 0; i < (sizeof(Gauss_X)/sizeof(double)); i++) { phi = w*Gauss_X[i]; cos_phi = cos(phi); sin_phi = sin(phi); q_x = c1x + cos_phi*ax + sin_phi*bx; q_y = c1y + cos_phi*ay + sin_phi*by; q_z = c1z + cos_phi*az + sin_phi*bz; p_reflect = GAUSS_monocurved((q_z/q_x),0,mos_rms_y)* GAUSS_monocurved((q_y/q_x),0,mos_rms_z); total += Gauss_W[i]*p_reflect; } total *= w; /* Choose point on Debye-Scherrer cone. Sample from a Gaussian of * width 1/cos(theta) greater than the mosaic and correct for any * error by adjusting the neutron weight later. */ phi = mos_sample*randnorm(); /* Compute final wave vector kf and scattering vector q = ki - kf */ cos_phi = cos(phi); sin_phi = sin(phi); q_x = c1x + cos_phi*ax + sin_phi*bx; q_y = c1y + cos_phi*ay + sin_phi*by; q_z = c1z + cos_phi*az + sin_phi*bz; p_reflect = GAUSS_monocurved((q_z/q_x),0,mos_rms_y)* GAUSS_monocurved((q_y/q_x),0,mos_rms_z); vx = K2V*(kix+q_x); vy = K2V*(kiy+q_y); vz = K2V*(kiz+q_z); p_reflect /= total*GAUSS_monocurved(phi,0,mos_sample); if (p_reflect <= 0) ABSORB; if (p_reflect > 1) p_reflect = 1; p = p * p_reflect; } /* End MC choice to reflect or transmit neutron (if tmp 1) { if (my_t0 > 1.01 && verbose) fprintf(stdout, "Warning: Monochromator_curved : lowered transmission from %f to 1 (k=%f)\n", my_t0, k); my_t0=0.999; } if (my_t0 > 0) p = p * my_t0; else ABSORB; } } /* end if not in gap */ /* rotate back in component frame */ Rotation TT; rot_transpose(T, TT); /* now make the coordinate system change */ mccoordschange_polarisation(TT, &vx, &vy, &vz); coords_get(rot_apply(TT,coords_set(x,y,z)),&x,&y,&z); y= y+center_y; z= z+center_z; /* Visualise scattering point in proper, component frame - but only if the neutron is reflected, that is none of: * transmitted * falling outside the slab material */ if(!do_transmit) SCATTER; /* mccoordschange_polarisation(tt, &sx, &sy, &sz); */ } /* End intersect the crystal (if z) */ else { /* restore neutron state when no interaction */ RESTORE_NEUTRON(INDEX_CURRENT_COMP, x, y, z, vx, vy, vz, t, sx, sy, sz, p); } } /* End neutron moving towards crystal (if vx)*/ /* Check for nan or inf particle parms */ if(isnan(p) || isinf(p)) ABSORB; if(isnan(t) || isinf(t)) ABSORB; if(isnan(vx) || isinf(vx)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(x) || isinf(x)) ABSORB; if(isnan(y) || isinf(y)) ABSORB; if(isnan(z) || isinf(z)) ABSORB; #undef reflect #undef transmit #undef zwidth #undef yheight #undef gap #undef NH #undef NV #undef mosaich #undef mosaicv #undef r0 #undef t0 #undef Q #undef RV #undef RH #undef DM #undef mosaic #undef width #undef height #undef verbose #undef order #undef mos_rms_y #undef mos_rms_z #undef mos_rms_max #undef mono_Q #undef SlabWidth #undef SlabHeight #undef rTable #undef tTable #undef rTableFlag #undef tTableFlag #undef tiltH #undef tiltV return(_comp); } /* class_Monochromator_curved_trace */ #pragma acc routine _class_Monitor *class_Monitor_trace(_class_Monitor *_comp , _class_particle *_particle) { ABSORBED=SCATTERED=RESTORE=0; #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define restore_neutron (_comp->_parameters.restore_neutron) #define Nsum (_comp->_parameters.Nsum) #define psum (_comp->_parameters.psum) #define p2sum (_comp->_parameters.p2sum) SIG_MESSAGE("[_Mon_samplepos2_trace] component Mon_samplepos2=Monitor() TRACE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/Monitor.comp:75]"); PROP_Z0; if (x>xmin && xymin && y_parameters.cfg) #define absorptionmode (_comp->_parameters.absorptionmode) #define multscat (_comp->_parameters.multscat) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define zdepth (_comp->_parameters.zdepth) #define radius (_comp->_parameters.radius) #define params (_comp->_parameters.params) #define geoparams (_comp->_parameters.geoparams) #define ncrystal_convfact_vsq2ekin (_comp->_parameters.ncrystal_convfact_vsq2ekin) #define ncrystal_convfact_ekin2vsq (_comp->_parameters.ncrystal_convfact_ekin2vsq) SIG_MESSAGE("[_PANDA_cryst_trace] component PANDA_cryst=NCrystal_sample() TRACE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../contrib/NCrystal_sample.comp:258]"); /* Handle arbitrary incoming neutron with state vector (x,y,z,vx,vy,vz,t,sx,sy,sz,p) */ do { /* neutron is outside our surface at this point. First check if it intersects it... */ double t0,t1; if (!ncrystalsample_surfintersect(&geoparams,&t0,&t1,x,y,z,vx,vy,vz)) break;//no intersections with our sample geometry, so nothing more to do. /* Propagate the neutron to our surface (t0<=0 means we started inside!) */ if (t0>0) PROP_DT(t0); /* let the neutron fly in a straight line for t0 */ double dir[3], dirout[3]; double v2 = vx*vx+vy*vy+vz*vz; double absv = sqrt(v2); double inv_absv = 1.0/absv; dir[0] = vx*inv_absv; dir[1] = vy*inv_absv; dir[2] = vz*inv_absv; double ekin = ncrystal_convfact_vsq2ekin * v2; double xsect_scat = 0.0; double xsect_abs = 0.0; ncrystal_crosssection(params.proc_scat,ekin,(const double(*)[3])&dir,&xsect_scat); if (params.absmode) ncrystal_crosssection_nonoriented(params.proc_abs, ekin,&xsect_abs); #ifndef INFINITY #define INFINITY DBL_MAX #endif while(1) { /* Make the calculations and pick the final state before exiting the sample */ double xsect_step = xsect_scat; if (params.absmode==2) xsect_step += xsect_abs; double distance = xsect_step ? log( rand01() ) * params.density_factor / xsect_step : INFINITY; /* in m */ double timestep = distance * inv_absv; /* Test when the neutron would reach the outer surface in absence of interactions: */ if (!ncrystalsample_surfintersect(&geoparams,&t0,&t1,x,y,z,vx,vy,vz)) NCMCERR("Can not propagate to surface from inside volume!"); if(timestep>t1) { /* neutron reaches surface, move forward to surface and apply intensity reduction if absmode=1 */ if (params.absmode==1) p *= exp( absv * t1 * xsect_abs * params.inv_density_factor ); PROP_DT(t1); break;//end stepping inside volume } /*move neutron forward*/ PROP_DT(timestep); /* perform reaction */ if (params.absmode==2 && xsect_abs > rand01()*xsect_step ) { /* reaction was full-blooded absorption */ ABSORB;/* kill track (uses goto to jump out of current loop context)*/ } else if (params.absmode==1) { /* reaction was scatter and we model absorption by intensity-reduction */ p *= exp( distance * xsect_abs * params.inv_density_factor ); } else { /* reaction was scatter and we do not perform any intensity-reduction */ } /* scattering */ double delta_ekin; ncrystal_genscatter( params.scat,ekin, (const double(*)[3])&dir, &dirout, &delta_ekin); if (delta_ekin) { ekin += delta_ekin; if (ekin<=0) { //not expected to happen much, but an interaction could in principle bring the neutron to rest. ABSORB; } v2 = ncrystal_convfact_ekin2vsq * ekin; absv = sqrt(v2); inv_absv = 1.0/absv; } vx=dirout[0]*absv; vy=dirout[1]*absv; vz=dirout[2]*absv; dir[0]=dirout[0]; dir[1]=dirout[1]; dir[2]=dirout[2]; SCATTER;/* update mcstas scatter counter and potentially enable trajectory visualisation */ if (multscat) { //Must update x-sects if energy changed or processes are oriented: if (delta_ekin&¶ms.absmode) ncrystal_crosssection_nonoriented(params.proc_abs, ekin,&xsect_abs); if (delta_ekin||params.proc_scat_isoriented) ncrystal_crosssection(params.proc_scat,ekin,(const double(*)[3])&dir,&xsect_scat); } else { //Multiple scattering disabled, so we just need to propagate the neutron //out of the sample and (if absmode==1) apply one more intensity //reduction factor. We handle this by putting cross-sections to 0 here, //which will result in an infinife step length of the next step. xsect_scat = 0.0; if (params.absmode!=1) xsect_abs = 0.0; } }/*exited at a surface*/ /* Exited the surface. We let the while condition below always be false for * * now, since we only support convex bodies, so there is no need to check if * * we might be able to enter our shape again: */ } while (0); /* Check for nan or inf particle parms */ if(isnan(p) || isinf(p)) ABSORB; if(isnan(t) || isinf(t)) ABSORB; if(isnan(vx) || isinf(vx)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(vy) || isinf(vy)) ABSORB; if(isnan(x) || isinf(x)) ABSORB; if(isnan(y) || isinf(y)) ABSORB; if(isnan(z) || isinf(z)) ABSORB; #undef cfg #undef absorptionmode #undef multscat #undef xwidth #undef yheight #undef zdepth #undef radius #undef params #undef geoparams #undef ncrystal_convfact_vsq2ekin #undef ncrystal_convfact_ekin2vsq return(_comp); } /* class_NCrystal_sample_trace */ /* ***************************************************************************** * instrument 'PANDA' TRACE ***************************************************************************** */ #ifndef FUNNEL #pragma acc routine seq int raytrace(_class_particle* _particle) { /* single event propagation, called by mccode_main for PANDA:TRACE */ /* init variables and counters for TRACE */ #undef ABSORB0 #undef ABSORB #define ABSORB0 do { DEBUG_ABSORB(); MAGNET_OFF; ABSORBED++; return(ABSORBED);} while(0) #define ABSORB ABSORB0 DEBUG_ENTER(); DEBUG_STATE(); /* the main iteration loop for one incoming event */ while (!ABSORBED) { /* iterate event until absorbed */ _class_particle _particle_save; /* send particle event to component instance, one after the other */ char flag_nocoordschange=0; if (!ABSORBED && _particle->_index == 1) { /* begin component origin=Progress_bar() [1] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_origin_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _origin_var._position_relative),&x, &y, &z); } else mccoordschange(_origin_var._position_relative, _origin_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_origin_var._name); DEBUG_STATE(); class_Progress_bar_trace(&_origin_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component origin [1] */ if (!ABSORBED && _particle->_index == 2) { /* begin component ColdSource=Source_gen() [2] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_ColdSource_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _ColdSource_var._position_relative),&x, &y, &z); } else mccoordschange(_ColdSource_var._position_relative, _ColdSource_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_ColdSource_var._name); DEBUG_STATE(); class_Source_gen_trace(&_ColdSource_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component ColdSource [2] */ if (!ABSORBED && _particle->_index == 3) { /* begin component PrimaryBeam=Arm() [3] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PrimaryBeam_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PrimaryBeam_var._position_relative),&x, &y, &z); } else mccoordschange(_PrimaryBeam_var._position_relative, _PrimaryBeam_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PrimaryBeam_var._name); DEBUG_STATE(); _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PrimaryBeam [3] */ if (!ABSORBED && _particle->_index == 4) { /* begin component NL_SR2_1=Guide_gravity() [4] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_NL_SR2_1_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _NL_SR2_1_var._position_relative),&x, &y, &z); } else mccoordschange(_NL_SR2_1_var._position_relative, _NL_SR2_1_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_NL_SR2_1_var._name); DEBUG_STATE(); class_Guide_gravity_trace(&_NL_SR2_1_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component NL_SR2_1 [4] */ if (!ABSORBED && _particle->_index == 5) { /* begin component NL_SR2_2a=Guide_gravity() [5] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_NL_SR2_2a_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _NL_SR2_2a_var._position_relative),&x, &y, &z); } else mccoordschange(_NL_SR2_2a_var._position_relative, _NL_SR2_2a_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_NL_SR2_2a_var._name); DEBUG_STATE(); if ((( _instrument_var._parameters.prim_shut_pos == 1 ))) // conditional WHEN execution class_Guide_gravity_trace(&_NL_SR2_2a_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component NL_SR2_2a [5] */ if (!ABSORBED && _particle->_index == 6) { /* begin component NL_SR2_2b=Guide_gravity() [6] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_NL_SR2_2b_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _NL_SR2_2b_var._position_relative),&x, &y, &z); } else mccoordschange(_NL_SR2_2b_var._position_relative, _NL_SR2_2b_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_NL_SR2_2b_var._name); DEBUG_STATE(); if ((( _instrument_var._parameters.prim_shut_pos == 2 ))) // conditional WHEN execution class_Guide_gravity_trace(&_NL_SR2_2b_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component NL_SR2_2b [6] */ if (!ABSORBED && _particle->_index == 7) { /* begin component NL_SR2_2c=Guide_gravity() [7] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_NL_SR2_2c_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _NL_SR2_2c_var._position_relative),&x, &y, &z); } else mccoordschange(_NL_SR2_2c_var._position_relative, _NL_SR2_2c_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_NL_SR2_2c_var._name); DEBUG_STATE(); if ((( _instrument_var._parameters.prim_shut_pos == 3 ))) // conditional WHEN execution class_Guide_gravity_trace(&_NL_SR2_2c_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component NL_SR2_2c [7] */ if (!ABSORBED && _particle->_index == 8) { /* begin component NL_SR2_3=Guide_gravity() [8] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_NL_SR2_3_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _NL_SR2_3_var._position_relative),&x, &y, &z); } else mccoordschange(_NL_SR2_3_var._position_relative, _NL_SR2_3_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_NL_SR2_3_var._name); DEBUG_STATE(); class_Guide_gravity_trace(&_NL_SR2_3_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component NL_SR2_3 [8] */ if (!ABSORBED && _particle->_index == 9) { /* begin component SR2_Beamportwindow=Al_window() [9] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_SR2_Beamportwindow_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _SR2_Beamportwindow_var._position_relative),&x, &y, &z); } else mccoordschange(_SR2_Beamportwindow_var._position_relative, _SR2_Beamportwindow_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_SR2_Beamportwindow_var._name); DEBUG_STATE(); class_Al_window_trace(&_SR2_Beamportwindow_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component SR2_Beamportwindow [9] */ if (!ABSORBED && _particle->_index == 10) { /* begin component SR2_eob=Arm() [10] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_SR2_eob_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _SR2_eob_var._position_relative),&x, &y, &z); } else mccoordschange(_SR2_eob_var._position_relative, _SR2_eob_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_SR2_eob_var._name); DEBUG_STATE(); _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component SR2_eob [10] */ if (!ABSORBED && _particle->_index == 11) { /* begin component PANDA_ca1=Collimator_linear() [11] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PANDA_ca1_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PANDA_ca1_var._position_relative),&x, &y, &z); } else mccoordschange(_PANDA_ca1_var._position_relative, _PANDA_ca1_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PANDA_ca1_var._name); DEBUG_STATE(); if ((( ca1_div < 80 ))) // conditional WHEN execution class_Collimator_linear_trace(&_PANDA_ca1_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PANDA_ca1 [11] */ if (!ABSORBED && _particle->_index == 12) { /* begin component PANDA_sapphire=Filter_gen() [12] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PANDA_sapphire_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PANDA_sapphire_var._position_relative),&x, &y, &z); } else mccoordschange(_PANDA_sapphire_var._position_relative, _PANDA_sapphire_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PANDA_sapphire_var._name); DEBUG_STATE(); if ((( _instrument_var._parameters.sapphire == 1 ))) // conditional WHEN execution class_Filter_gen_trace(&_PANDA_sapphire_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PANDA_sapphire [12] */ if (!ABSORBED && _particle->_index == 13) { /* begin component sk1_in=Slit() [13] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_sk1_in_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _sk1_in_var._position_relative),&x, &y, &z); } else mccoordschange(_sk1_in_var._position_relative, _sk1_in_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_sk1_in_var._name); DEBUG_STATE(); class_Slit_trace(&_sk1_in_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component sk1_in [13] */ if (!ABSORBED && _particle->_index == 14) { /* begin component sk1_out=Slit() [14] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_sk1_out_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _sk1_out_var._position_relative),&x, &y, &z); } else mccoordschange(_sk1_out_var._position_relative, _sk1_out_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_sk1_out_var._name); DEBUG_STATE(); class_Slit_trace(&_sk1_out_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component sk1_out [14] */ if (!ABSORBED && _particle->_index == 15) { /* begin component PANDA_ms1=Slit() [15] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PANDA_ms1_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PANDA_ms1_var._position_relative),&x, &y, &z); } else mccoordschange(_PANDA_ms1_var._position_relative, _PANDA_ms1_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PANDA_ms1_var._name); DEBUG_STATE(); class_Slit_trace(&_PANDA_ms1_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PANDA_ms1 [15] */ if (!ABSORBED && _particle->_index == 16) { /* begin component sk2_in=Slit() [16] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_sk2_in_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _sk2_in_var._position_relative),&x, &y, &z); } else mccoordschange(_sk2_in_var._position_relative, _sk2_in_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_sk2_in_var._name); DEBUG_STATE(); class_Slit_trace(&_sk2_in_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component sk2_in [16] */ if (!ABSORBED && _particle->_index == 17) { /* begin component sk2_out=Slit() [17] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_sk2_out_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _sk2_out_var._position_relative),&x, &y, &z); } else mccoordschange(_sk2_out_var._position_relative, _sk2_out_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_sk2_out_var._name); DEBUG_STATE(); class_Slit_trace(&_sk2_out_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component sk2_out [17] */ if (!ABSORBED && _particle->_index == 18) { /* begin component PSD_PrimBeam=PSD_monitor() [18] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PSD_PrimBeam_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PSD_PrimBeam_var._position_relative),&x, &y, &z); } else mccoordschange(_PSD_PrimBeam_var._position_relative, _PSD_PrimBeam_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PSD_PrimBeam_var._name); DEBUG_STATE(); class_PSD_monitor_trace(&_PSD_PrimBeam_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PSD_PrimBeam [18] */ if (!ABSORBED && _particle->_index == 19) { /* begin component LAM_PrimBeam=L_monitor() [19] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_LAM_PrimBeam_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _LAM_PrimBeam_var._position_relative),&x, &y, &z); } else mccoordschange(_LAM_PrimBeam_var._position_relative, _LAM_PrimBeam_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_LAM_PrimBeam_var._name); DEBUG_STATE(); class_L_monitor_trace(&_LAM_PrimBeam_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component LAM_PrimBeam [19] */ if (!ABSORBED && _particle->_index == 20) { /* begin component DIV_PrimBeam=Divergence_monitor() [20] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_DIV_PrimBeam_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _DIV_PrimBeam_var._position_relative),&x, &y, &z); } else mccoordschange(_DIV_PrimBeam_var._position_relative, _DIV_PrimBeam_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_DIV_PrimBeam_var._name); DEBUG_STATE(); class_Divergence_monitor_trace(&_DIV_PrimBeam_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component DIV_PrimBeam [20] */ if (!ABSORBED && _particle->_index == 21) { /* begin component PANDA_mth=Arm() [21] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PANDA_mth_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PANDA_mth_var._position_relative),&x, &y, &z); } else mccoordschange(_PANDA_mth_var._position_relative, _PANDA_mth_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PANDA_mth_var._name); DEBUG_STATE(); _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PANDA_mth [21] */ if (!ABSORBED && _particle->_index == 22) { /* begin component a_mono=Arm() [22] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_a_mono_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _a_mono_var._position_relative),&x, &y, &z); } else mccoordschange(_a_mono_var._position_relative, _a_mono_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_a_mono_var._name); DEBUG_STATE(); _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component a_mono [22] */ #ifndef NOSPLIT /* start SPLIT at PG002_mono */ if (!ABSORBED) { _class_particle Split_PG002_mono_particle=*_particle; int Split_PG002_mono_counter; int SplitS_PG002_mono = 20; for (Split_PG002_mono_counter = 0; Split_PG002_mono_counter< SplitS_PG002_mono; Split_PG002_mono_counter++) { randstate_t randbackup = *_particle->randstate; *_particle=Split_PG002_mono_particle; *_particle->randstate = randbackup; srandom(_hash(_particle->_uid* 23 *(1+Split_PG002_mono_counter))); p /= SplitS_PG002_mono > 0 ? SplitS_PG002_mono : 1; #endif if (!ABSORBED && _particle->_index == 23) { /* begin component PG002_mono=Monochromator_curved() [23] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PG002_mono_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PG002_mono_var._position_relative),&x, &y, &z); } else mccoordschange(_PG002_mono_var._position_relative, _PG002_mono_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PG002_mono_var._name); DEBUG_STATE(); class_Monochromator_curved_trace(&_PG002_mono_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PG002_mono [23] */ if (!ABSORBED && _particle->_index == 24) { /* begin component PANDA_mtt=Arm() [24] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PANDA_mtt_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PANDA_mtt_var._position_relative),&x, &y, &z); } else mccoordschange(_PANDA_mtt_var._position_relative, _PANDA_mtt_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PANDA_mtt_var._name); DEBUG_STATE(); _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PANDA_mtt [24] */ if (!ABSORBED && _particle->_index == 25) { /* begin component sk3_in=Slit() [25] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_sk3_in_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _sk3_in_var._position_relative),&x, &y, &z); } else mccoordschange(_sk3_in_var._position_relative, _sk3_in_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_sk3_in_var._name); DEBUG_STATE(); class_Slit_trace(&_sk3_in_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component sk3_in [25] */ if (!ABSORBED && _particle->_index == 26) { /* begin component PANDA_ca2=Collimator_linear() [26] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PANDA_ca2_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PANDA_ca2_var._position_relative),&x, &y, &z); } else mccoordschange(_PANDA_ca2_var._position_relative, _PANDA_ca2_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PANDA_ca2_var._name); DEBUG_STATE(); if ((( ca2_div < 61 ))) // conditional WHEN execution class_Collimator_linear_trace(&_PANDA_ca2_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PANDA_ca2 [26] */ if (!ABSORBED && _particle->_index == 27) { /* begin component sk3_out=Slit() [27] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_sk3_out_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _sk3_out_var._position_relative),&x, &y, &z); } else mccoordschange(_sk3_out_var._position_relative, _sk3_out_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_sk3_out_var._name); DEBUG_STATE(); class_Slit_trace(&_sk3_out_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component sk3_out [27] */ if (!ABSORBED && _particle->_index == 28) { /* begin component PSD_mon1=PSD_monitor() [28] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PSD_mon1_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PSD_mon1_var._position_relative),&x, &y, &z); } else mccoordschange(_PSD_mon1_var._position_relative, _PSD_mon1_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PSD_mon1_var._name); DEBUG_STATE(); class_PSD_monitor_trace(&_PSD_mon1_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PSD_mon1 [28] */ if (!ABSORBED && _particle->_index == 29) { /* begin component LAM_mon1=L_monitor() [29] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_LAM_mon1_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _LAM_mon1_var._position_relative),&x, &y, &z); } else mccoordschange(_LAM_mon1_var._position_relative, _LAM_mon1_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_LAM_mon1_var._name); DEBUG_STATE(); class_L_monitor_trace(&_LAM_mon1_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component LAM_mon1 [29] */ if (!ABSORBED && _particle->_index == 30) { /* begin component PANDA_ss1=Slit() [30] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PANDA_ss1_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PANDA_ss1_var._position_relative),&x, &y, &z); } else mccoordschange(_PANDA_ss1_var._position_relative, _PANDA_ss1_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PANDA_ss1_var._name); DEBUG_STATE(); class_Slit_trace(&_PANDA_ss1_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PANDA_ss1 [30] */ if (!ABSORBED && _particle->_index == 31) { /* begin component PSD_samplepos=PSD_monitor() [31] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PSD_samplepos_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PSD_samplepos_var._position_relative),&x, &y, &z); } else mccoordschange(_PSD_samplepos_var._position_relative, _PSD_samplepos_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PSD_samplepos_var._name); DEBUG_STATE(); class_PSD_monitor_trace(&_PSD_samplepos_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PSD_samplepos [31] */ if (!ABSORBED && _particle->_index == 32) { /* begin component Mon_samplepos2=Monitor() [32] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_Mon_samplepos2_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _Mon_samplepos2_var._position_relative),&x, &y, &z); } else mccoordschange(_Mon_samplepos2_var._position_relative, _Mon_samplepos2_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_Mon_samplepos2_var._name); DEBUG_STATE(); class_Monitor_trace(&_Mon_samplepos2_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component Mon_samplepos2 [32] */ if (!ABSORBED && _particle->_index == 33) { /* begin component PANDA_sth=Arm() [33] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PANDA_sth_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PANDA_sth_var._position_relative),&x, &y, &z); } else mccoordschange(_PANDA_sth_var._position_relative, _PANDA_sth_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PANDA_sth_var._name); DEBUG_STATE(); _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PANDA_sth [33] */ if (!ABSORBED && _particle->_index == 34) { /* begin component sample=Arm() [34] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_sample_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _sample_var._position_relative),&x, &y, &z); } else mccoordschange(_sample_var._position_relative, _sample_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_sample_var._name); DEBUG_STATE(); _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component sample [34] */ if (!ABSORBED && _particle->_index == 35) { /* begin component PANDA_cryst=NCrystal_sample() [35] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PANDA_cryst_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PANDA_cryst_var._position_relative),&x, &y, &z); } else mccoordschange(_PANDA_cryst_var._position_relative, _PANDA_cryst_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PANDA_cryst_var._name); DEBUG_STATE(); class_NCrystal_sample_trace(&_PANDA_cryst_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PANDA_cryst [35] */ if (!ABSORBED && _particle->_index == 36) { /* begin component PANDA_stt=Arm() [36] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PANDA_stt_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PANDA_stt_var._position_relative),&x, &y, &z); } else mccoordschange(_PANDA_stt_var._position_relative, _PANDA_stt_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PANDA_stt_var._name); DEBUG_STATE(); _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PANDA_stt [36] */ if (!ABSORBED && _particle->_index == 37) { /* begin component PSD_scattered=PSD_monitor() [37] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PSD_scattered_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PSD_scattered_var._position_relative),&x, &y, &z); } else mccoordschange(_PSD_scattered_var._position_relative, _PSD_scattered_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PSD_scattered_var._name); DEBUG_STATE(); class_PSD_monitor_trace(&_PSD_scattered_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PSD_scattered [37] */ if (!ABSORBED && _particle->_index == 38) { /* begin component PANDA_ss2=Slit() [38] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PANDA_ss2_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PANDA_ss2_var._position_relative),&x, &y, &z); } else mccoordschange(_PANDA_ss2_var._position_relative, _PANDA_ss2_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PANDA_ss2_var._name); DEBUG_STATE(); class_Slit_trace(&_PANDA_ss2_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PANDA_ss2 [38] */ if (!ABSORBED && _particle->_index == 39) { /* begin component sk4_in=Slit() [39] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_sk4_in_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _sk4_in_var._position_relative),&x, &y, &z); } else mccoordschange(_sk4_in_var._position_relative, _sk4_in_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_sk4_in_var._name); DEBUG_STATE(); class_Slit_trace(&_sk4_in_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component sk4_in [39] */ if (!ABSORBED && _particle->_index == 40) { /* begin component PANDA_ca3=Collimator_linear() [40] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PANDA_ca3_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PANDA_ca3_var._position_relative),&x, &y, &z); } else mccoordschange(_PANDA_ca3_var._position_relative, _PANDA_ca3_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PANDA_ca3_var._name); DEBUG_STATE(); if ((( ca3_div < 61 ))) // conditional WHEN execution class_Collimator_linear_trace(&_PANDA_ca3_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PANDA_ca3 [40] */ if (!ABSORBED && _particle->_index == 41) { /* begin component sk4_out=Slit() [41] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_sk4_out_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _sk4_out_var._position_relative),&x, &y, &z); } else mccoordschange(_sk4_out_var._position_relative, _sk4_out_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_sk4_out_var._name); DEBUG_STATE(); class_Slit_trace(&_sk4_out_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component sk4_out [41] */ if (!ABSORBED && _particle->_index == 42) { /* begin component PSD_mon2=PSD_monitor() [42] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PSD_mon2_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PSD_mon2_var._position_relative),&x, &y, &z); } else mccoordschange(_PSD_mon2_var._position_relative, _PSD_mon2_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PSD_mon2_var._name); DEBUG_STATE(); class_PSD_monitor_trace(&_PSD_mon2_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PSD_mon2 [42] */ if (!ABSORBED && _particle->_index == 43) { /* begin component PANDA_ath=Arm() [43] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PANDA_ath_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PANDA_ath_var._position_relative),&x, &y, &z); } else mccoordschange(_PANDA_ath_var._position_relative, _PANDA_ath_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PANDA_ath_var._name); DEBUG_STATE(); _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PANDA_ath [43] */ if (!ABSORBED && _particle->_index == 44) { /* begin component analyser=Arm() [44] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_analyser_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _analyser_var._position_relative),&x, &y, &z); } else mccoordschange(_analyser_var._position_relative, _analyser_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_analyser_var._name); DEBUG_STATE(); _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component analyser [44] */ #ifndef NOSPLIT /* start SPLIT at PG002_ana */ if (!ABSORBED) { _class_particle Split_PG002_ana_particle=*_particle; int Split_PG002_ana_counter; int SplitS_PG002_ana = 20; for (Split_PG002_ana_counter = 0; Split_PG002_ana_counter< SplitS_PG002_ana; Split_PG002_ana_counter++) { randstate_t randbackup = *_particle->randstate; *_particle=Split_PG002_ana_particle; *_particle->randstate = randbackup; srandom(_hash(_particle->_uid* 45 *(1+Split_PG002_ana_counter))); p /= SplitS_PG002_ana > 0 ? SplitS_PG002_ana : 1; #endif if (!ABSORBED && _particle->_index == 45) { /* begin component PG002_ana=Monochromator_curved() [45] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PG002_ana_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PG002_ana_var._position_relative),&x, &y, &z); } else mccoordschange(_PG002_ana_var._position_relative, _PG002_ana_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PG002_ana_var._name); DEBUG_STATE(); class_Monochromator_curved_trace(&_PG002_ana_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PG002_ana [45] */ if (!ABSORBED && _particle->_index == 46) { /* begin component PANDA_att=Arm() [46] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PANDA_att_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PANDA_att_var._position_relative),&x, &y, &z); } else mccoordschange(_PANDA_att_var._position_relative, _PANDA_att_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PANDA_att_var._name); DEBUG_STATE(); _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PANDA_att [46] */ if (!ABSORBED && _particle->_index == 47) { /* begin component sk5_in=Slit() [47] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_sk5_in_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _sk5_in_var._position_relative),&x, &y, &z); } else mccoordschange(_sk5_in_var._position_relative, _sk5_in_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_sk5_in_var._name); DEBUG_STATE(); class_Slit_trace(&_sk5_in_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component sk5_in [47] */ if (!ABSORBED && _particle->_index == 48) { /* begin component PANDA_ca4=Collimator_linear() [48] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PANDA_ca4_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PANDA_ca4_var._position_relative),&x, &y, &z); } else mccoordschange(_PANDA_ca4_var._position_relative, _PANDA_ca4_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PANDA_ca4_var._name); DEBUG_STATE(); if ((( ca4_div < 80 ))) // conditional WHEN execution class_Collimator_linear_trace(&_PANDA_ca4_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PANDA_ca4 [48] */ if (!ABSORBED && _particle->_index == 49) { /* begin component sk5_out=Slit() [49] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_sk5_out_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _sk5_out_var._position_relative),&x, &y, &z); } else mccoordschange(_sk5_out_var._position_relative, _sk5_out_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_sk5_out_var._name); DEBUG_STATE(); class_Slit_trace(&_sk5_out_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component sk5_out [49] */ if (!ABSORBED && _particle->_index == 50) { /* begin component a_detector=Arm() [50] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_a_detector_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _a_detector_var._position_relative),&x, &y, &z); } else mccoordschange(_a_detector_var._position_relative, _a_detector_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_a_detector_var._name); DEBUG_STATE(); _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component a_detector [50] */ if (!ABSORBED && _particle->_index == 51) { /* begin component PSD_det=PSD_monitor() [51] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PSD_det_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PSD_det_var._position_relative),&x, &y, &z); } else mccoordschange(_PSD_det_var._position_relative, _PSD_det_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PSD_det_var._name); DEBUG_STATE(); class_PSD_monitor_trace(&_PSD_det_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PSD_det [51] */ if (!ABSORBED && _particle->_index == 52) { /* begin component PSD_det1=PSD_monitor() [52] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PSD_det1_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PSD_det1_var._position_relative),&x, &y, &z); } else mccoordschange(_PSD_det1_var._position_relative, _PSD_det1_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PSD_det1_var._name); DEBUG_STATE(); class_PSD_monitor_trace(&_PSD_det1_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PSD_det1 [52] */ if (!ABSORBED && _particle->_index == 53) { /* begin component PSD_det2=PSD_monitor() [53] */ if (!flag_nocoordschange) { // flag activated by JUMP to pass coords change if (_PSD_det2_var._rotation_is_identity) { coords_get(coords_add(coords_set(x,y,z), _PSD_det2_var._position_relative),&x, &y, &z); } else mccoordschange(_PSD_det2_var._position_relative, _PSD_det2_var._rotation_relative, _particle); } else flag_nocoordschange=0; _particle_save = *_particle; DEBUG_COMP(_PSD_det2_var._name); DEBUG_STATE(); class_PSD_monitor_trace(&_PSD_det2_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; if (!ABSORBED) DEBUG_STATE(); } /* end component PSD_det2 [53] */ #ifndef NOSPLIT } /* end SPLIT at PG002_ana */ } /* if (!ABSORBED) relating to SPLIT at PG002_ana */ #endif #ifndef NOSPLIT } /* end SPLIT at PG002_mono */ } /* if (!ABSORBED) relating to SPLIT at PG002_mono */ #endif if (_particle->_index > 53) ABSORBED++; /* absorbed when passed all components */ } /* while !ABSORBED */ DEBUG_LEAVE() DEBUG_STATE() return(_particle->_index); } /* raytrace */ /* loop to generate events and call raytrace() propagate them */ void raytrace_all(unsigned long long ncount, unsigned long seed) { /* CPU-loop */ unsigned long long loops; #ifndef GPU_INNERLOOP #define GPU_INNERLOOP 2147483647 #endif long innerloop=GPU_INNERLOOP; loops = ceil((double)ncount/innerloop); /* if on GPU, printf has been globally nullified, re-enable here */ #ifdef OPENACC #ifndef MULTICORE #undef printf #endif #endif if (ncount>innerloop) { printf("Defining %llu CPU loops around kernel and adjusting ncount\n",loops); mcset_ncount(loops*innerloop); } else { loops=1; innerloop = ncount; } for (unsigned long long cloop=0; cloop1) fprintf(stdout, "%d..", (int)cloop); fflush(stdout); /* if on GPU, re-nullify printf */ #ifdef OPENACC #ifndef MULTICORE #define printf(...) noprintf() #endif #endif #ifndef VECSIZE #define VECSIZE 128 #endif #pragma acc parallel loop gang vector vector_length(VECSIZE) for (unsigned long pidx=0 ; pidx < innerloop ; pidx++) { _class_particle particleN = mcgenstate(); // initial particle _class_particle* _particle = &particleN; particleN._uid = pidx; srandom(_hash(pidx + pidx*seed)); particle_uservar_init(_particle); raytrace(_particle); } /* inner for */ seed = seed+innerloop; mcncount += innerloop; } /* CPU for */ /* if on GPU, printf has been globally nullified, re-enable here */ #ifdef OPENACC #ifndef MULTICORE #undef printf #endif #endif MPI_MASTER( printf("*** TRACE end *** \n"); ); } /* raytrace_all */ #endif //no-FUNNEL #ifdef FUNNEL // Alternative raytrace algorithm which iterates all particles through // one component at the time, can remove absorbs from the next loop and // switch between cpu/gpu. void raytrace_all_funnel(unsigned long long ncount, unsigned long seed) { // set up outer (CPU) loop / particle batches unsigned long long loops; #ifndef GPU_FUNNEL_INNERLOOP #define GPU_FUNNEL_INNERLOOP 1024*1024 #endif long innerloop=GPU_FUNNEL_INNERLOOP; // <-- tune by memory capacity here (max threads: 2147483647); loops = ceil((double)ncount/innerloop); if (ncount>innerloop) { printf("Defining %llu CPU loops around kernel and adjusting ncount\n",loops); mcset_ncount(loops*2147483647); } else { loops=1; innerloop = ncount; } // create particles struct and pointer arrays (same memory used by all batches) _class_particle* particles = malloc(innerloop*sizeof(_class_particle)); _class_particle* pbuffer = malloc(innerloop*sizeof(_class_particle)); long livebatchsize = innerloop; // outer loop / particle batches for (unsigned long long cloop=0; cloop1) fprintf(stdout, "%d..", (int)cloop); fflush(stdout); // init particles #pragma acc parallel loop present(particles) for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) { // generate particle state, set loop index and seed particles[pidx] = mcgenstate(); _class_particle* _particle = particles + pidx; _particle->_uid = pidx; srandom(_hash(pidx + seed)); // _particle->state usage built into srandom macro particle_uservar_init(_particle); } // iterate components #pragma acc parallel loop present(particles) for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) { _class_particle* _particle = &particles[pidx]; _class_particle _particle_save; // origin if (!ABSORBED) { if (_origin_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _origin_var._position_relative),&x, &y, &z); else mccoordschange(_origin_var._position_relative, _origin_var._rotation_relative, _particle); _particle_save = *_particle; class_Progress_bar_trace(&_origin_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // ColdSource if (!ABSORBED) { if (_ColdSource_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _ColdSource_var._position_relative),&x, &y, &z); else mccoordschange(_ColdSource_var._position_relative, _ColdSource_var._rotation_relative, _particle); _particle_save = *_particle; class_Source_gen_trace(&_ColdSource_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PrimaryBeam if (!ABSORBED) { if (_PrimaryBeam_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PrimaryBeam_var._position_relative),&x, &y, &z); else mccoordschange(_PrimaryBeam_var._position_relative, _PrimaryBeam_var._rotation_relative, _particle); _particle_save = *_particle; _particle->_index++; } // NL_SR2_1 if (!ABSORBED) { if (_NL_SR2_1_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _NL_SR2_1_var._position_relative),&x, &y, &z); else mccoordschange(_NL_SR2_1_var._position_relative, _NL_SR2_1_var._rotation_relative, _particle); _particle_save = *_particle; class_Guide_gravity_trace(&_NL_SR2_1_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // NL_SR2_2a if (!ABSORBED) { if (_NL_SR2_2a_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _NL_SR2_2a_var._position_relative),&x, &y, &z); else mccoordschange(_NL_SR2_2a_var._position_relative, _NL_SR2_2a_var._rotation_relative, _particle); _particle_save = *_particle; if ((( _instrument_var._parameters.prim_shut_pos == 1 ))) // conditional WHEN class_Guide_gravity_trace(&_NL_SR2_2a_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // NL_SR2_2b if (!ABSORBED) { if (_NL_SR2_2b_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _NL_SR2_2b_var._position_relative),&x, &y, &z); else mccoordschange(_NL_SR2_2b_var._position_relative, _NL_SR2_2b_var._rotation_relative, _particle); _particle_save = *_particle; if ((( _instrument_var._parameters.prim_shut_pos == 2 ))) // conditional WHEN class_Guide_gravity_trace(&_NL_SR2_2b_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // NL_SR2_2c if (!ABSORBED) { if (_NL_SR2_2c_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _NL_SR2_2c_var._position_relative),&x, &y, &z); else mccoordschange(_NL_SR2_2c_var._position_relative, _NL_SR2_2c_var._rotation_relative, _particle); _particle_save = *_particle; if ((( _instrument_var._parameters.prim_shut_pos == 3 ))) // conditional WHEN class_Guide_gravity_trace(&_NL_SR2_2c_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // NL_SR2_3 if (!ABSORBED) { if (_NL_SR2_3_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _NL_SR2_3_var._position_relative),&x, &y, &z); else mccoordschange(_NL_SR2_3_var._position_relative, _NL_SR2_3_var._rotation_relative, _particle); _particle_save = *_particle; class_Guide_gravity_trace(&_NL_SR2_3_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // SR2_Beamportwindow if (!ABSORBED) { if (_SR2_Beamportwindow_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _SR2_Beamportwindow_var._position_relative),&x, &y, &z); else mccoordschange(_SR2_Beamportwindow_var._position_relative, _SR2_Beamportwindow_var._rotation_relative, _particle); _particle_save = *_particle; class_Al_window_trace(&_SR2_Beamportwindow_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // SR2_eob if (!ABSORBED) { if (_SR2_eob_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _SR2_eob_var._position_relative),&x, &y, &z); else mccoordschange(_SR2_eob_var._position_relative, _SR2_eob_var._rotation_relative, _particle); _particle_save = *_particle; _particle->_index++; } // PANDA_ca1 if (!ABSORBED) { if (_PANDA_ca1_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PANDA_ca1_var._position_relative),&x, &y, &z); else mccoordschange(_PANDA_ca1_var._position_relative, _PANDA_ca1_var._rotation_relative, _particle); _particle_save = *_particle; if ((( ca1_div < 80 ))) // conditional WHEN class_Collimator_linear_trace(&_PANDA_ca1_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PANDA_sapphire if (!ABSORBED) { if (_PANDA_sapphire_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PANDA_sapphire_var._position_relative),&x, &y, &z); else mccoordschange(_PANDA_sapphire_var._position_relative, _PANDA_sapphire_var._rotation_relative, _particle); _particle_save = *_particle; if ((( _instrument_var._parameters.sapphire == 1 ))) // conditional WHEN class_Filter_gen_trace(&_PANDA_sapphire_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // sk1_in if (!ABSORBED) { if (_sk1_in_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _sk1_in_var._position_relative),&x, &y, &z); else mccoordschange(_sk1_in_var._position_relative, _sk1_in_var._rotation_relative, _particle); _particle_save = *_particle; class_Slit_trace(&_sk1_in_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // sk1_out if (!ABSORBED) { if (_sk1_out_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _sk1_out_var._position_relative),&x, &y, &z); else mccoordschange(_sk1_out_var._position_relative, _sk1_out_var._rotation_relative, _particle); _particle_save = *_particle; class_Slit_trace(&_sk1_out_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PANDA_ms1 if (!ABSORBED) { if (_PANDA_ms1_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PANDA_ms1_var._position_relative),&x, &y, &z); else mccoordschange(_PANDA_ms1_var._position_relative, _PANDA_ms1_var._rotation_relative, _particle); _particle_save = *_particle; class_Slit_trace(&_PANDA_ms1_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // sk2_in if (!ABSORBED) { if (_sk2_in_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _sk2_in_var._position_relative),&x, &y, &z); else mccoordschange(_sk2_in_var._position_relative, _sk2_in_var._rotation_relative, _particle); _particle_save = *_particle; class_Slit_trace(&_sk2_in_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // sk2_out if (!ABSORBED) { if (_sk2_out_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _sk2_out_var._position_relative),&x, &y, &z); else mccoordschange(_sk2_out_var._position_relative, _sk2_out_var._rotation_relative, _particle); _particle_save = *_particle; class_Slit_trace(&_sk2_out_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PSD_PrimBeam if (!ABSORBED) { if (_PSD_PrimBeam_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PSD_PrimBeam_var._position_relative),&x, &y, &z); else mccoordschange(_PSD_PrimBeam_var._position_relative, _PSD_PrimBeam_var._rotation_relative, _particle); _particle_save = *_particle; class_PSD_monitor_trace(&_PSD_PrimBeam_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // LAM_PrimBeam if (!ABSORBED) { if (_LAM_PrimBeam_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _LAM_PrimBeam_var._position_relative),&x, &y, &z); else mccoordschange(_LAM_PrimBeam_var._position_relative, _LAM_PrimBeam_var._rotation_relative, _particle); _particle_save = *_particle; class_L_monitor_trace(&_LAM_PrimBeam_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // DIV_PrimBeam if (!ABSORBED) { if (_DIV_PrimBeam_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _DIV_PrimBeam_var._position_relative),&x, &y, &z); else mccoordschange(_DIV_PrimBeam_var._position_relative, _DIV_PrimBeam_var._rotation_relative, _particle); _particle_save = *_particle; class_Divergence_monitor_trace(&_DIV_PrimBeam_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PANDA_mth if (!ABSORBED) { if (_PANDA_mth_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PANDA_mth_var._position_relative),&x, &y, &z); else mccoordschange(_PANDA_mth_var._position_relative, _PANDA_mth_var._rotation_relative, _particle); _particle_save = *_particle; _particle->_index++; } // a_mono if (!ABSORBED) { if (_a_mono_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _a_mono_var._position_relative),&x, &y, &z); else mccoordschange(_a_mono_var._position_relative, _a_mono_var._rotation_relative, _particle); _particle_save = *_particle; _particle->_index++; } } // SPLIT with available livebatchsize long mult_PG002_mono; livebatchsize = sort_absorb_last(particles, pbuffer, livebatchsize, innerloop, 1, &mult_PG002_mono); //printf("livebatchsize: %ld, split: %ld\n", livebatchsize, mult); #pragma acc parallel loop present(particles) for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) { _class_particle* _particle = &particles[pidx]; _class_particle _particle_save; // PG002_mono if (!ABSORBED) { if (_PG002_mono_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PG002_mono_var._position_relative),&x, &y, &z); else mccoordschange(_PG002_mono_var._position_relative, _PG002_mono_var._rotation_relative, _particle); _particle_save = *_particle; class_Monochromator_curved_trace(&_PG002_mono_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PANDA_mtt if (!ABSORBED) { if (_PANDA_mtt_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PANDA_mtt_var._position_relative),&x, &y, &z); else mccoordschange(_PANDA_mtt_var._position_relative, _PANDA_mtt_var._rotation_relative, _particle); _particle_save = *_particle; _particle->_index++; } // sk3_in if (!ABSORBED) { if (_sk3_in_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _sk3_in_var._position_relative),&x, &y, &z); else mccoordschange(_sk3_in_var._position_relative, _sk3_in_var._rotation_relative, _particle); _particle_save = *_particle; class_Slit_trace(&_sk3_in_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PANDA_ca2 if (!ABSORBED) { if (_PANDA_ca2_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PANDA_ca2_var._position_relative),&x, &y, &z); else mccoordschange(_PANDA_ca2_var._position_relative, _PANDA_ca2_var._rotation_relative, _particle); _particle_save = *_particle; if ((( ca2_div < 61 ))) // conditional WHEN class_Collimator_linear_trace(&_PANDA_ca2_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // sk3_out if (!ABSORBED) { if (_sk3_out_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _sk3_out_var._position_relative),&x, &y, &z); else mccoordschange(_sk3_out_var._position_relative, _sk3_out_var._rotation_relative, _particle); _particle_save = *_particle; class_Slit_trace(&_sk3_out_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PSD_mon1 if (!ABSORBED) { if (_PSD_mon1_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PSD_mon1_var._position_relative),&x, &y, &z); else mccoordschange(_PSD_mon1_var._position_relative, _PSD_mon1_var._rotation_relative, _particle); _particle_save = *_particle; class_PSD_monitor_trace(&_PSD_mon1_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // LAM_mon1 if (!ABSORBED) { if (_LAM_mon1_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _LAM_mon1_var._position_relative),&x, &y, &z); else mccoordschange(_LAM_mon1_var._position_relative, _LAM_mon1_var._rotation_relative, _particle); _particle_save = *_particle; class_L_monitor_trace(&_LAM_mon1_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PANDA_ss1 if (!ABSORBED) { if (_PANDA_ss1_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PANDA_ss1_var._position_relative),&x, &y, &z); else mccoordschange(_PANDA_ss1_var._position_relative, _PANDA_ss1_var._rotation_relative, _particle); _particle_save = *_particle; class_Slit_trace(&_PANDA_ss1_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PSD_samplepos if (!ABSORBED) { if (_PSD_samplepos_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PSD_samplepos_var._position_relative),&x, &y, &z); else mccoordschange(_PSD_samplepos_var._position_relative, _PSD_samplepos_var._rotation_relative, _particle); _particle_save = *_particle; class_PSD_monitor_trace(&_PSD_samplepos_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // Mon_samplepos2 if (!ABSORBED) { if (_Mon_samplepos2_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _Mon_samplepos2_var._position_relative),&x, &y, &z); else mccoordschange(_Mon_samplepos2_var._position_relative, _Mon_samplepos2_var._rotation_relative, _particle); _particle_save = *_particle; class_Monitor_trace(&_Mon_samplepos2_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PANDA_sth if (!ABSORBED) { if (_PANDA_sth_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PANDA_sth_var._position_relative),&x, &y, &z); else mccoordschange(_PANDA_sth_var._position_relative, _PANDA_sth_var._rotation_relative, _particle); _particle_save = *_particle; _particle->_index++; } // sample if (!ABSORBED) { if (_sample_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _sample_var._position_relative),&x, &y, &z); else mccoordschange(_sample_var._position_relative, _sample_var._rotation_relative, _particle); _particle_save = *_particle; _particle->_index++; } } for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) { _class_particle* _particle = &particles[pidx]; _class_particle _particle_save; // PANDA_cryst if (!ABSORBED) { if (_PANDA_cryst_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PANDA_cryst_var._position_relative),&x, &y, &z); else mccoordschange(_PANDA_cryst_var._position_relative, _PANDA_cryst_var._rotation_relative, _particle); _particle_save = *_particle; class_NCrystal_sample_trace(&_PANDA_cryst_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } } #pragma acc parallel loop present(particles) for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) { _class_particle* _particle = &particles[pidx]; _class_particle _particle_save; // PANDA_stt if (!ABSORBED) { if (_PANDA_stt_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PANDA_stt_var._position_relative),&x, &y, &z); else mccoordschange(_PANDA_stt_var._position_relative, _PANDA_stt_var._rotation_relative, _particle); _particle_save = *_particle; _particle->_index++; } // PSD_scattered if (!ABSORBED) { if (_PSD_scattered_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PSD_scattered_var._position_relative),&x, &y, &z); else mccoordschange(_PSD_scattered_var._position_relative, _PSD_scattered_var._rotation_relative, _particle); _particle_save = *_particle; class_PSD_monitor_trace(&_PSD_scattered_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PANDA_ss2 if (!ABSORBED) { if (_PANDA_ss2_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PANDA_ss2_var._position_relative),&x, &y, &z); else mccoordschange(_PANDA_ss2_var._position_relative, _PANDA_ss2_var._rotation_relative, _particle); _particle_save = *_particle; class_Slit_trace(&_PANDA_ss2_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // sk4_in if (!ABSORBED) { if (_sk4_in_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _sk4_in_var._position_relative),&x, &y, &z); else mccoordschange(_sk4_in_var._position_relative, _sk4_in_var._rotation_relative, _particle); _particle_save = *_particle; class_Slit_trace(&_sk4_in_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PANDA_ca3 if (!ABSORBED) { if (_PANDA_ca3_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PANDA_ca3_var._position_relative),&x, &y, &z); else mccoordschange(_PANDA_ca3_var._position_relative, _PANDA_ca3_var._rotation_relative, _particle); _particle_save = *_particle; if ((( ca3_div < 61 ))) // conditional WHEN class_Collimator_linear_trace(&_PANDA_ca3_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // sk4_out if (!ABSORBED) { if (_sk4_out_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _sk4_out_var._position_relative),&x, &y, &z); else mccoordschange(_sk4_out_var._position_relative, _sk4_out_var._rotation_relative, _particle); _particle_save = *_particle; class_Slit_trace(&_sk4_out_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PSD_mon2 if (!ABSORBED) { if (_PSD_mon2_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PSD_mon2_var._position_relative),&x, &y, &z); else mccoordschange(_PSD_mon2_var._position_relative, _PSD_mon2_var._rotation_relative, _particle); _particle_save = *_particle; class_PSD_monitor_trace(&_PSD_mon2_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PANDA_ath if (!ABSORBED) { if (_PANDA_ath_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PANDA_ath_var._position_relative),&x, &y, &z); else mccoordschange(_PANDA_ath_var._position_relative, _PANDA_ath_var._rotation_relative, _particle); _particle_save = *_particle; _particle->_index++; } // analyser if (!ABSORBED) { if (_analyser_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _analyser_var._position_relative),&x, &y, &z); else mccoordschange(_analyser_var._position_relative, _analyser_var._rotation_relative, _particle); _particle_save = *_particle; _particle->_index++; } } // SPLIT with available livebatchsize long mult_PG002_ana; livebatchsize = sort_absorb_last(particles, pbuffer, livebatchsize, innerloop, 1, &mult_PG002_ana); //printf("livebatchsize: %ld, split: %ld\n", livebatchsize, mult); #pragma acc parallel loop present(particles) for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) { _class_particle* _particle = &particles[pidx]; _class_particle _particle_save; // PG002_ana if (!ABSORBED) { if (_PG002_ana_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PG002_ana_var._position_relative),&x, &y, &z); else mccoordschange(_PG002_ana_var._position_relative, _PG002_ana_var._rotation_relative, _particle); _particle_save = *_particle; class_Monochromator_curved_trace(&_PG002_ana_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PANDA_att if (!ABSORBED) { if (_PANDA_att_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PANDA_att_var._position_relative),&x, &y, &z); else mccoordschange(_PANDA_att_var._position_relative, _PANDA_att_var._rotation_relative, _particle); _particle_save = *_particle; _particle->_index++; } // sk5_in if (!ABSORBED) { if (_sk5_in_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _sk5_in_var._position_relative),&x, &y, &z); else mccoordschange(_sk5_in_var._position_relative, _sk5_in_var._rotation_relative, _particle); _particle_save = *_particle; class_Slit_trace(&_sk5_in_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PANDA_ca4 if (!ABSORBED) { if (_PANDA_ca4_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PANDA_ca4_var._position_relative),&x, &y, &z); else mccoordschange(_PANDA_ca4_var._position_relative, _PANDA_ca4_var._rotation_relative, _particle); _particle_save = *_particle; if ((( ca4_div < 80 ))) // conditional WHEN class_Collimator_linear_trace(&_PANDA_ca4_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // sk5_out if (!ABSORBED) { if (_sk5_out_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _sk5_out_var._position_relative),&x, &y, &z); else mccoordschange(_sk5_out_var._position_relative, _sk5_out_var._rotation_relative, _particle); _particle_save = *_particle; class_Slit_trace(&_sk5_out_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // a_detector if (!ABSORBED) { if (_a_detector_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _a_detector_var._position_relative),&x, &y, &z); else mccoordschange(_a_detector_var._position_relative, _a_detector_var._rotation_relative, _particle); _particle_save = *_particle; _particle->_index++; } // PSD_det if (!ABSORBED) { if (_PSD_det_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PSD_det_var._position_relative),&x, &y, &z); else mccoordschange(_PSD_det_var._position_relative, _PSD_det_var._rotation_relative, _particle); _particle_save = *_particle; class_PSD_monitor_trace(&_PSD_det_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PSD_det1 if (!ABSORBED) { if (_PSD_det1_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PSD_det1_var._position_relative),&x, &y, &z); else mccoordschange(_PSD_det1_var._position_relative, _PSD_det1_var._rotation_relative, _particle); _particle_save = *_particle; class_PSD_monitor_trace(&_PSD_det1_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } // PSD_det2 if (!ABSORBED) { if (_PSD_det2_var._rotation_is_identity) coords_get(coords_add(coords_set(x,y,z), _PSD_det2_var._position_relative),&x, &y, &z); else mccoordschange(_PSD_det2_var._position_relative, _PSD_det2_var._rotation_relative, _particle); _particle_save = *_particle; class_PSD_monitor_trace(&_PSD_det2_var, _particle); if (_particle->_restore) *_particle = _particle_save; _particle->_index++; } } // finalize particle batch #pragma acc parallel loop present(particles) for (unsigned long pidx=0 ; pidx < livebatchsize ; pidx++) { _class_particle* _particle = &particles[pidx]; if (_particle->_index > 4) ABSORBED++; /* absorbed when passed all components */ } // jump to next viable seed seed = seed + innerloop; } // outer loop / particle batches free(particles); free(pbuffer); printf("\n"); } /* raytrace_all_funnel */ #endif // FUNNEL #undef x #undef y #undef z #undef vx #undef vy #undef vz #undef t #undef sx #undef sy #undef sz #undef p #undef mcgravitation #undef mcMagnet #undef allow_backprop #ifdef OPENACC #ifndef MULTICORE #undef strlen #undef strcmp #undef exit #undef printf #undef sprintf #undef fprintf #endif #endif #undef SCATTERED #undef RESTORE #undef RESTORE_NEUTRON #undef STORE_NEUTRON #undef ABSORBED #undef ABSORB #undef ABSORB0 /* ***************************************************************************** * instrument 'PANDA' and components SAVE ***************************************************************************** */ _class_Progress_bar *class_Progress_bar_save(_class_Progress_bar *_comp ) { #define profile (_comp->_parameters.profile) #define percent (_comp->_parameters.percent) #define flag_save (_comp->_parameters.flag_save) #define minutes (_comp->_parameters.minutes) #define IntermediateCnts (_comp->_parameters.IntermediateCnts) #define StartTime (_comp->_parameters.StartTime) #define EndTime (_comp->_parameters.EndTime) #define CurrentTime (_comp->_parameters.CurrentTime) SIG_MESSAGE("[_origin_save] component origin=Progress_bar() SAVE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../misc/Progress_bar.comp:120]"); MPI_MASTER(fprintf(stdout, "\nSave [%s]\n", instrument_name);); if (profile && strlen(profile) && strcmp(profile,"NULL") && strcmp(profile,"0")) { char filename[256]; if (!strlen(profile) || !strcmp(profile,"NULL") || !strcmp(profile,"0")) strcpy(filename, instrument_name); else strcpy(filename, profile); DETECTOR_OUT_1D( "Intensity profiler", "Component index [1]", "Intensity", "prof", 1, mcNUMCOMP, mcNUMCOMP-1, &(instrument->counter_N[1]),&(instrument->counter_P[1]),&(instrument->counter_P2[1]), filename); } #undef profile #undef percent #undef flag_save #undef minutes #undef IntermediateCnts #undef StartTime #undef EndTime #undef CurrentTime return(_comp); } /* class_Progress_bar_save */ _class_PSD_monitor *class_PSD_monitor_save(_class_PSD_monitor *_comp ) { #define nx (_comp->_parameters.nx) #define ny (_comp->_parameters.ny) #define filename (_comp->_parameters.filename) #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define restore_neutron (_comp->_parameters.restore_neutron) #define nowritefile (_comp->_parameters.nowritefile) #define PSD_N (_comp->_parameters.PSD_N) #define PSD_p (_comp->_parameters.PSD_p) #define PSD_p2 (_comp->_parameters.PSD_p2) SIG_MESSAGE("[_PSD_PrimBeam_save] component PSD_PrimBeam=PSD_monitor() SAVE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/PSD_monitor.comp:112]"); if (!nowritefile) { DETECTOR_OUT_2D( "PSD monitor", "X position [cm]", "Y position [cm]", xmin*100.0, xmax*100.0, ymin*100.0, ymax*100.0, nx, ny, &PSD_N[0][0],&PSD_p[0][0],&PSD_p2[0][0], filename); } #undef nx #undef ny #undef filename #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef restore_neutron #undef nowritefile #undef PSD_N #undef PSD_p #undef PSD_p2 return(_comp); } /* class_PSD_monitor_save */ _class_L_monitor *class_L_monitor_save(_class_L_monitor *_comp ) { #define nL (_comp->_parameters.nL) #define filename (_comp->_parameters.filename) #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define Lmin (_comp->_parameters.Lmin) #define Lmax (_comp->_parameters.Lmax) #define restore_neutron (_comp->_parameters.restore_neutron) #define L_N (_comp->_parameters.L_N) #define L_p (_comp->_parameters.L_p) #define L_p2 (_comp->_parameters.L_p2) SIG_MESSAGE("[_LAM_PrimBeam_save] component LAM_PrimBeam=L_monitor() SAVE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/L_monitor.comp:114]"); DETECTOR_OUT_1D( "Wavelength monitor", "Wavelength [AA]", "Intensity", "L", Lmin, Lmax, nL, &L_N[0],&L_p[0],&L_p2[0], filename); #undef nL #undef filename #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef Lmin #undef Lmax #undef restore_neutron #undef L_N #undef L_p #undef L_p2 return(_comp); } /* class_L_monitor_save */ _class_Divergence_monitor *class_Divergence_monitor_save(_class_Divergence_monitor *_comp ) { #define nh (_comp->_parameters.nh) #define nv (_comp->_parameters.nv) #define filename (_comp->_parameters.filename) #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define maxdiv_h (_comp->_parameters.maxdiv_h) #define maxdiv_v (_comp->_parameters.maxdiv_v) #define restore_neutron (_comp->_parameters.restore_neutron) #define nx (_comp->_parameters.nx) #define ny (_comp->_parameters.ny) #define nz (_comp->_parameters.nz) #define Div_N (_comp->_parameters.Div_N) #define Div_p (_comp->_parameters.Div_p) #define Div_p2 (_comp->_parameters.Div_p2) SIG_MESSAGE("[_DIV_PrimBeam_save] component DIV_PrimBeam=Divergence_monitor() SAVE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/Divergence_monitor.comp:132]"); DETECTOR_OUT_2D( "Divergence monitor", "X divergence [deg]", "Y divergence [deg]", -maxdiv_h, maxdiv_h, -maxdiv_v, maxdiv_v, nh, nv, &Div_N[0][0],&Div_p[0][0],&Div_p2[0][0], filename); #undef nh #undef nv #undef filename #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef maxdiv_h #undef maxdiv_v #undef restore_neutron #undef nx #undef ny #undef nz #undef Div_N #undef Div_p #undef Div_p2 return(_comp); } /* class_Divergence_monitor_save */ _class_Monitor *class_Monitor_save(_class_Monitor *_comp ) { #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define restore_neutron (_comp->_parameters.restore_neutron) #define Nsum (_comp->_parameters.Nsum) #define psum (_comp->_parameters.psum) #define p2sum (_comp->_parameters.p2sum) SIG_MESSAGE("[_Mon_samplepos2_save] component Mon_samplepos2=Monitor() SAVE [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/Monitor.comp:94]"); char title[1024]; sprintf(title, "Single monitor %s", NAME_CURRENT_COMP); DETECTOR_OUT_0D(title, Nsum, psum, p2sum); #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef restore_neutron #undef Nsum #undef psum #undef p2sum return(_comp); } /* class_Monitor_save */ int save(FILE *handle) { /* called by mccode_main for PANDA:SAVE */ if (!handle) siminfo_init(NULL); /* call iteratively all components SAVE */ class_Progress_bar_save(&_origin_var); class_PSD_monitor_save(&_PSD_PrimBeam_var); class_L_monitor_save(&_LAM_PrimBeam_var); class_Divergence_monitor_save(&_DIV_PrimBeam_var); class_PSD_monitor_save(&_PSD_mon1_var); class_L_monitor_save(&_LAM_mon1_var); class_PSD_monitor_save(&_PSD_samplepos_var); class_Monitor_save(&_Mon_samplepos2_var); class_PSD_monitor_save(&_PSD_scattered_var); class_PSD_monitor_save(&_PSD_mon2_var); class_PSD_monitor_save(&_PSD_det_var); class_PSD_monitor_save(&_PSD_det1_var); class_PSD_monitor_save(&_PSD_det2_var); if (!handle) siminfo_close(); return(0); } /* save */ /* ***************************************************************************** * instrument 'PANDA' and components FINALLY ***************************************************************************** */ _class_Progress_bar *class_Progress_bar_finally(_class_Progress_bar *_comp ) { #define profile (_comp->_parameters.profile) #define percent (_comp->_parameters.percent) #define flag_save (_comp->_parameters.flag_save) #define minutes (_comp->_parameters.minutes) #define IntermediateCnts (_comp->_parameters.IntermediateCnts) #define StartTime (_comp->_parameters.StartTime) #define EndTime (_comp->_parameters.EndTime) #define CurrentTime (_comp->_parameters.CurrentTime) SIG_MESSAGE("[_origin_finally] component origin=Progress_bar() FINALLY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../misc/Progress_bar.comp:138]"); time_t NowTime; time(&NowTime); fprintf(stdout, "\nFinally [%s: %s]. Time: ", instrument_name, dirname ? dirname : "."); if (difftime(NowTime,StartTime) < 60.0) fprintf(stdout, "%g [s] ", difftime(NowTime,StartTime)); else if (difftime(NowTime,StartTime) > 3600.0) fprintf(stdout, "%g [h] ", difftime(NowTime,StartTime)/3660.0); else fprintf(stdout, "%g [min] ", difftime(NowTime,StartTime)/60.0); fprintf(stdout, "\n"); #undef profile #undef percent #undef flag_save #undef minutes #undef IntermediateCnts #undef StartTime #undef EndTime #undef CurrentTime return(_comp); } /* class_Progress_bar_finally */ _class_Source_gen *class_Source_gen_finally(_class_Source_gen *_comp ) { #define flux_file (_comp->_parameters.flux_file) #define xdiv_file (_comp->_parameters.xdiv_file) #define ydiv_file (_comp->_parameters.ydiv_file) #define radius (_comp->_parameters.radius) #define dist (_comp->_parameters.dist) #define focus_xw (_comp->_parameters.focus_xw) #define focus_yh (_comp->_parameters.focus_yh) #define focus_aw (_comp->_parameters.focus_aw) #define focus_ah (_comp->_parameters.focus_ah) #define E0 (_comp->_parameters.E0) #define dE (_comp->_parameters.dE) #define lambda0 (_comp->_parameters.lambda0) #define dlambda (_comp->_parameters.dlambda) #define I1 (_comp->_parameters.I1) #define yheight (_comp->_parameters.yheight) #define xwidth (_comp->_parameters.xwidth) #define verbose (_comp->_parameters.verbose) #define T1 (_comp->_parameters.T1) #define flux_file_perAA (_comp->_parameters.flux_file_perAA) #define flux_file_log (_comp->_parameters.flux_file_log) #define Lmin (_comp->_parameters.Lmin) #define Lmax (_comp->_parameters.Lmax) #define Emin (_comp->_parameters.Emin) #define Emax (_comp->_parameters.Emax) #define T2 (_comp->_parameters.T2) #define I2 (_comp->_parameters.I2) #define T3 (_comp->_parameters.T3) #define I3 (_comp->_parameters.I3) #define zdepth (_comp->_parameters.zdepth) #define target_index (_comp->_parameters.target_index) #define p_in (_comp->_parameters.p_in) #define lambda1 (_comp->_parameters.lambda1) #define lambda2 (_comp->_parameters.lambda2) #define lambda3 (_comp->_parameters.lambda3) #define pTable (_comp->_parameters.pTable) #define pTable_x (_comp->_parameters.pTable_x) #define pTable_y (_comp->_parameters.pTable_y) #define pTable_xmin (_comp->_parameters.pTable_xmin) #define pTable_xmax (_comp->_parameters.pTable_xmax) #define pTable_xsum (_comp->_parameters.pTable_xsum) #define pTable_ymin (_comp->_parameters.pTable_ymin) #define pTable_ymax (_comp->_parameters.pTable_ymax) #define pTable_ysum (_comp->_parameters.pTable_ysum) #define pTable_dxmin (_comp->_parameters.pTable_dxmin) #define pTable_dxmax (_comp->_parameters.pTable_dxmax) #define pTable_dymin (_comp->_parameters.pTable_dymin) #define pTable_dymax (_comp->_parameters.pTable_dymax) SIG_MESSAGE("[_ColdSource_finally] component ColdSource=Source_gen() FINALLY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../sources/Source_gen.comp:576]"); Table_Free(&pTable); Table_Free(&pTable_x); Table_Free(&pTable_y); #undef flux_file #undef xdiv_file #undef ydiv_file #undef radius #undef dist #undef focus_xw #undef focus_yh #undef focus_aw #undef focus_ah #undef E0 #undef dE #undef lambda0 #undef dlambda #undef I1 #undef yheight #undef xwidth #undef verbose #undef T1 #undef flux_file_perAA #undef flux_file_log #undef Lmin #undef Lmax #undef Emin #undef Emax #undef T2 #undef I2 #undef T3 #undef I3 #undef zdepth #undef target_index #undef p_in #undef lambda1 #undef lambda2 #undef lambda3 #undef pTable #undef pTable_x #undef pTable_y #undef pTable_xmin #undef pTable_xmax #undef pTable_xsum #undef pTable_ymin #undef pTable_ymax #undef pTable_ysum #undef pTable_dxmin #undef pTable_dxmax #undef pTable_dymin #undef pTable_dymax return(_comp); } /* class_Source_gen_finally */ _class_Guide_gravity *class_Guide_gravity_finally(_class_Guide_gravity *_comp ) { #define w1 (_comp->_parameters.w1) #define h1 (_comp->_parameters.h1) #define w2 (_comp->_parameters.w2) #define h2 (_comp->_parameters.h2) #define l (_comp->_parameters.l) #define R0 (_comp->_parameters.R0) #define Qc (_comp->_parameters.Qc) #define alpha (_comp->_parameters.alpha) #define m (_comp->_parameters.m) #define W (_comp->_parameters.W) #define nslit (_comp->_parameters.nslit) #define d (_comp->_parameters.d) #define mleft (_comp->_parameters.mleft) #define mright (_comp->_parameters.mright) #define mtop (_comp->_parameters.mtop) #define mbottom (_comp->_parameters.mbottom) #define nhslit (_comp->_parameters.nhslit) #define G (_comp->_parameters.G) #define aleft (_comp->_parameters.aleft) #define aright (_comp->_parameters.aright) #define atop (_comp->_parameters.atop) #define abottom (_comp->_parameters.abottom) #define wavy (_comp->_parameters.wavy) #define wavy_z (_comp->_parameters.wavy_z) #define wavy_tb (_comp->_parameters.wavy_tb) #define wavy_lr (_comp->_parameters.wavy_lr) #define chamfers (_comp->_parameters.chamfers) #define chamfers_z (_comp->_parameters.chamfers_z) #define chamfers_lr (_comp->_parameters.chamfers_lr) #define chamfers_tb (_comp->_parameters.chamfers_tb) #define nelements (_comp->_parameters.nelements) #define nu (_comp->_parameters.nu) #define phase (_comp->_parameters.phase) #define reflect (_comp->_parameters.reflect) #define GVars (_comp->_parameters.GVars) #define pTable (_comp->_parameters.pTable) #define table_present (_comp->_parameters.table_present) SIG_MESSAGE("[_NL_SR2_1_finally] component NL_SR2_1=Guide_gravity() FINALLY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Guide_gravity.comp:566]"); if (GVars.warnings > 100) { fprintf(stderr,"%s: warning: neutron has entered guide, but can not exit !\n", GVars.compcurname); fprintf(stderr,"%s: warning: This message has been repeated %g times\n", GVars.compcurname, GVars.warnings); } #undef w1 #undef h1 #undef w2 #undef h2 #undef l #undef R0 #undef Qc #undef alpha #undef m #undef W #undef nslit #undef d #undef mleft #undef mright #undef mtop #undef mbottom #undef nhslit #undef G #undef aleft #undef aright #undef atop #undef abottom #undef wavy #undef wavy_z #undef wavy_tb #undef wavy_lr #undef chamfers #undef chamfers_z #undef chamfers_lr #undef chamfers_tb #undef nelements #undef nu #undef phase #undef reflect #undef GVars #undef pTable #undef table_present return(_comp); } /* class_Guide_gravity_finally */ _class_Filter_gen *class_Filter_gen_finally(_class_Filter_gen *_comp ) { #define filename (_comp->_parameters.filename) #define options (_comp->_parameters.options) #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define thickness (_comp->_parameters.thickness) #define scaling (_comp->_parameters.scaling) #define verbose (_comp->_parameters.verbose) #define Mode_Table (_comp->_parameters.Mode_Table) #define Type_Table (_comp->_parameters.Type_Table) #define pTable (_comp->_parameters.pTable) SIG_MESSAGE("[_PANDA_sapphire_finally] component PANDA_sapphire=Filter_gen() FINALLY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Filter_gen.comp:203]"); Table_Free(&pTable); #undef filename #undef options #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef thickness #undef scaling #undef verbose #undef Mode_Table #undef Type_Table #undef pTable return(_comp); } /* class_Filter_gen_finally */ _class_L_monitor *class_L_monitor_finally(_class_L_monitor *_comp ) { #define nL (_comp->_parameters.nL) #define filename (_comp->_parameters.filename) #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define Lmin (_comp->_parameters.Lmin) #define Lmax (_comp->_parameters.Lmax) #define restore_neutron (_comp->_parameters.restore_neutron) #define L_N (_comp->_parameters.L_N) #define L_p (_comp->_parameters.L_p) #define L_p2 (_comp->_parameters.L_p2) SIG_MESSAGE("[_LAM_PrimBeam_finally] component LAM_PrimBeam=L_monitor() FINALLY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/L_monitor.comp:125]"); destroy_darr1d(L_N); destroy_darr1d(L_p); destroy_darr1d(L_p2); #undef nL #undef filename #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef Lmin #undef Lmax #undef restore_neutron #undef L_N #undef L_p #undef L_p2 return(_comp); } /* class_L_monitor_finally */ _class_Divergence_monitor *class_Divergence_monitor_finally(_class_Divergence_monitor *_comp ) { #define nh (_comp->_parameters.nh) #define nv (_comp->_parameters.nv) #define filename (_comp->_parameters.filename) #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define maxdiv_h (_comp->_parameters.maxdiv_h) #define maxdiv_v (_comp->_parameters.maxdiv_v) #define restore_neutron (_comp->_parameters.restore_neutron) #define nx (_comp->_parameters.nx) #define ny (_comp->_parameters.ny) #define nz (_comp->_parameters.nz) #define Div_N (_comp->_parameters.Div_N) #define Div_p (_comp->_parameters.Div_p) #define Div_p2 (_comp->_parameters.Div_p2) SIG_MESSAGE("[_DIV_PrimBeam_finally] component DIV_PrimBeam=Divergence_monitor() FINALLY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/Divergence_monitor.comp:144]"); destroy_darr2d(Div_N); destroy_darr2d(Div_p); destroy_darr2d(Div_p2); #undef nh #undef nv #undef filename #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef maxdiv_h #undef maxdiv_v #undef restore_neutron #undef nx #undef ny #undef nz #undef Div_N #undef Div_p #undef Div_p2 return(_comp); } /* class_Divergence_monitor_finally */ _class_Monochromator_curved *class_Monochromator_curved_finally(_class_Monochromator_curved *_comp ) { #define reflect (_comp->_parameters.reflect) #define transmit (_comp->_parameters.transmit) #define zwidth (_comp->_parameters.zwidth) #define yheight (_comp->_parameters.yheight) #define gap (_comp->_parameters.gap) #define NH (_comp->_parameters.NH) #define NV (_comp->_parameters.NV) #define mosaich (_comp->_parameters.mosaich) #define mosaicv (_comp->_parameters.mosaicv) #define r0 (_comp->_parameters.r0) #define t0 (_comp->_parameters.t0) #define Q (_comp->_parameters.Q) #define RV (_comp->_parameters.RV) #define RH (_comp->_parameters.RH) #define DM (_comp->_parameters.DM) #define mosaic (_comp->_parameters.mosaic) #define width (_comp->_parameters.width) #define height (_comp->_parameters.height) #define verbose (_comp->_parameters.verbose) #define order (_comp->_parameters.order) #define mos_rms_y (_comp->_parameters.mos_rms_y) #define mos_rms_z (_comp->_parameters.mos_rms_z) #define mos_rms_max (_comp->_parameters.mos_rms_max) #define mono_Q (_comp->_parameters.mono_Q) #define SlabWidth (_comp->_parameters.SlabWidth) #define SlabHeight (_comp->_parameters.SlabHeight) #define rTable (_comp->_parameters.rTable) #define tTable (_comp->_parameters.tTable) #define rTableFlag (_comp->_parameters.rTableFlag) #define tTableFlag (_comp->_parameters.tTableFlag) #define tiltH (_comp->_parameters.tiltH) #define tiltV (_comp->_parameters.tiltV) SIG_MESSAGE("[_PG002_mono_finally] component PG002_mono=Monochromator_curved() FINALLY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Monochromator_curved.comp:474]"); if(rTableFlag){ Table_Free(&rTable); } if(tTableFlag){ Table_Free(&tTable); } if (tiltH) free(tiltH); if (tiltV) free(tiltV); #undef reflect #undef transmit #undef zwidth #undef yheight #undef gap #undef NH #undef NV #undef mosaich #undef mosaicv #undef r0 #undef t0 #undef Q #undef RV #undef RH #undef DM #undef mosaic #undef width #undef height #undef verbose #undef order #undef mos_rms_y #undef mos_rms_z #undef mos_rms_max #undef mono_Q #undef SlabWidth #undef SlabHeight #undef rTable #undef tTable #undef rTableFlag #undef tTableFlag #undef tiltH #undef tiltV return(_comp); } /* class_Monochromator_curved_finally */ _class_NCrystal_sample *class_NCrystal_sample_finally(_class_NCrystal_sample *_comp ) { #define cfg (_comp->_parameters.cfg) #define absorptionmode (_comp->_parameters.absorptionmode) #define multscat (_comp->_parameters.multscat) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define zdepth (_comp->_parameters.zdepth) #define radius (_comp->_parameters.radius) #define params (_comp->_parameters.params) #define geoparams (_comp->_parameters.geoparams) #define ncrystal_convfact_vsq2ekin (_comp->_parameters.ncrystal_convfact_vsq2ekin) #define ncrystal_convfact_ekin2vsq (_comp->_parameters.ncrystal_convfact_ekin2vsq) SIG_MESSAGE("[_PANDA_cryst_finally] component PANDA_cryst=NCrystal_sample() FINALLY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../contrib/NCrystal_sample.comp:372]"); ncrystal_unref(¶ms.scat); ncrystal_invalidate(¶ms.proc_scat);//a cast of params.scat, so just invalidate handle don't unref if (params.absmode) ncrystal_unref(¶ms.proc_abs); #undef cfg #undef absorptionmode #undef multscat #undef xwidth #undef yheight #undef zdepth #undef radius #undef params #undef geoparams #undef ncrystal_convfact_vsq2ekin #undef ncrystal_convfact_ekin2vsq return(_comp); } /* class_NCrystal_sample_finally */ int finally(void) { /* called by mccode_main for PANDA:FINALLY */ #pragma acc update host(_origin_var) #pragma acc update host(_ColdSource_var) #pragma acc update host(_PrimaryBeam_var) #pragma acc update host(_NL_SR2_1_var) #pragma acc update host(_NL_SR2_2a_var) #pragma acc update host(_NL_SR2_2b_var) #pragma acc update host(_NL_SR2_2c_var) #pragma acc update host(_NL_SR2_3_var) #pragma acc update host(_SR2_Beamportwindow_var) #pragma acc update host(_SR2_eob_var) #pragma acc update host(_PANDA_ca1_var) #pragma acc update host(_PANDA_sapphire_var) #pragma acc update host(_sk1_in_var) #pragma acc update host(_sk1_out_var) #pragma acc update host(_PANDA_ms1_var) #pragma acc update host(_sk2_in_var) #pragma acc update host(_sk2_out_var) #pragma acc update host(_PSD_PrimBeam_var) #pragma acc update host(_LAM_PrimBeam_var) #pragma acc update host(_DIV_PrimBeam_var) #pragma acc update host(_PANDA_mth_var) #pragma acc update host(_a_mono_var) #pragma acc update host(_PG002_mono_var) #pragma acc update host(_PANDA_mtt_var) #pragma acc update host(_sk3_in_var) #pragma acc update host(_PANDA_ca2_var) #pragma acc update host(_sk3_out_var) #pragma acc update host(_PSD_mon1_var) #pragma acc update host(_LAM_mon1_var) #pragma acc update host(_PANDA_ss1_var) #pragma acc update host(_PSD_samplepos_var) #pragma acc update host(_Mon_samplepos2_var) #pragma acc update host(_PANDA_sth_var) #pragma acc update host(_sample_var) #pragma acc update host(_PANDA_cryst_var) #pragma acc update host(_PANDA_stt_var) #pragma acc update host(_PSD_scattered_var) #pragma acc update host(_PANDA_ss2_var) #pragma acc update host(_sk4_in_var) #pragma acc update host(_PANDA_ca3_var) #pragma acc update host(_sk4_out_var) #pragma acc update host(_PSD_mon2_var) #pragma acc update host(_PANDA_ath_var) #pragma acc update host(_analyser_var) #pragma acc update host(_PG002_ana_var) #pragma acc update host(_PANDA_att_var) #pragma acc update host(_sk5_in_var) #pragma acc update host(_PANDA_ca4_var) #pragma acc update host(_sk5_out_var) #pragma acc update host(_a_detector_var) #pragma acc update host(_PSD_det_var) #pragma acc update host(_PSD_det1_var) #pragma acc update host(_PSD_det2_var) #pragma acc update host(_instrument_var) siminfo_init(NULL); save(siminfo_file); /* save data when simulation ends */ /* call iteratively all components FINALLY */ class_Progress_bar_finally(&_origin_var); class_Source_gen_finally(&_ColdSource_var); class_Guide_gravity_finally(&_NL_SR2_1_var); class_Guide_gravity_finally(&_NL_SR2_2a_var); class_Guide_gravity_finally(&_NL_SR2_2b_var); class_Guide_gravity_finally(&_NL_SR2_2c_var); class_Guide_gravity_finally(&_NL_SR2_3_var); class_Filter_gen_finally(&_PANDA_sapphire_var); class_L_monitor_finally(&_LAM_PrimBeam_var); class_Divergence_monitor_finally(&_DIV_PrimBeam_var); class_Monochromator_curved_finally(&_PG002_mono_var); class_L_monitor_finally(&_LAM_mon1_var); class_NCrystal_sample_finally(&_PANDA_cryst_var); class_Monochromator_curved_finally(&_PG002_ana_var); siminfo_close(); return(0); } /* finally */ /* ***************************************************************************** * instrument 'PANDA' and components DISPLAY ***************************************************************************** */ #define magnify mcdis_magnify #define line mcdis_line #define dashed_line mcdis_dashed_line #define multiline mcdis_multiline #define rectangle mcdis_rectangle #define box mcdis_box #define circle mcdis_circle #define cylinder mcdis_cylinder #define sphere mcdis_sphere _class_Progress_bar *class_Progress_bar_display(_class_Progress_bar *_comp ) { #define profile (_comp->_parameters.profile) #define percent (_comp->_parameters.percent) #define flag_save (_comp->_parameters.flag_save) #define minutes (_comp->_parameters.minutes) #define IntermediateCnts (_comp->_parameters.IntermediateCnts) #define StartTime (_comp->_parameters.StartTime) #define EndTime (_comp->_parameters.EndTime) #define CurrentTime (_comp->_parameters.CurrentTime) SIG_MESSAGE("[_origin_display] component origin=Progress_bar() DISPLAY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../misc/Progress_bar.comp:152]"); printf("MCDISPLAY: component %s\n", _comp->_name); #undef profile #undef percent #undef flag_save #undef minutes #undef IntermediateCnts #undef StartTime #undef EndTime #undef CurrentTime return(_comp); } /* class_Progress_bar_display */ _class_Source_gen *class_Source_gen_display(_class_Source_gen *_comp ) { #define flux_file (_comp->_parameters.flux_file) #define xdiv_file (_comp->_parameters.xdiv_file) #define ydiv_file (_comp->_parameters.ydiv_file) #define radius (_comp->_parameters.radius) #define dist (_comp->_parameters.dist) #define focus_xw (_comp->_parameters.focus_xw) #define focus_yh (_comp->_parameters.focus_yh) #define focus_aw (_comp->_parameters.focus_aw) #define focus_ah (_comp->_parameters.focus_ah) #define E0 (_comp->_parameters.E0) #define dE (_comp->_parameters.dE) #define lambda0 (_comp->_parameters.lambda0) #define dlambda (_comp->_parameters.dlambda) #define I1 (_comp->_parameters.I1) #define yheight (_comp->_parameters.yheight) #define xwidth (_comp->_parameters.xwidth) #define verbose (_comp->_parameters.verbose) #define T1 (_comp->_parameters.T1) #define flux_file_perAA (_comp->_parameters.flux_file_perAA) #define flux_file_log (_comp->_parameters.flux_file_log) #define Lmin (_comp->_parameters.Lmin) #define Lmax (_comp->_parameters.Lmax) #define Emin (_comp->_parameters.Emin) #define Emax (_comp->_parameters.Emax) #define T2 (_comp->_parameters.T2) #define I2 (_comp->_parameters.I2) #define T3 (_comp->_parameters.T3) #define I3 (_comp->_parameters.I3) #define zdepth (_comp->_parameters.zdepth) #define target_index (_comp->_parameters.target_index) #define p_in (_comp->_parameters.p_in) #define lambda1 (_comp->_parameters.lambda1) #define lambda2 (_comp->_parameters.lambda2) #define lambda3 (_comp->_parameters.lambda3) #define pTable (_comp->_parameters.pTable) #define pTable_x (_comp->_parameters.pTable_x) #define pTable_y (_comp->_parameters.pTable_y) #define pTable_xmin (_comp->_parameters.pTable_xmin) #define pTable_xmax (_comp->_parameters.pTable_xmax) #define pTable_xsum (_comp->_parameters.pTable_xsum) #define pTable_ymin (_comp->_parameters.pTable_ymin) #define pTable_ymax (_comp->_parameters.pTable_ymax) #define pTable_ysum (_comp->_parameters.pTable_ysum) #define pTable_dxmin (_comp->_parameters.pTable_dxmin) #define pTable_dxmax (_comp->_parameters.pTable_dxmax) #define pTable_dymin (_comp->_parameters.pTable_dymin) #define pTable_dymax (_comp->_parameters.pTable_dymax) SIG_MESSAGE("[_ColdSource_display] component ColdSource=Source_gen() DISPLAY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../sources/Source_gen.comp:583]"); printf("MCDISPLAY: component %s\n", _comp->_name); double xmin; double xmax; double ymin; double ymax; if (radius) { circle("xy",0,0,0,radius); if (zdepth) { circle("xy",0,0,-zdepth/2,radius); circle("xy",0,0, zdepth/2,radius); } } else { xmin = -xwidth/2; xmax = xwidth/2; ymin = -yheight/2; ymax = yheight/2; multiline(5, (double)xmin, (double)ymin, 0.0, (double)xmax, (double)ymin, 0.0, (double)xmax, (double)ymax, 0.0, (double)xmin, (double)ymax, 0.0, (double)xmin, (double)ymin, 0.0); if (zdepth) { multiline(5, (double)xmin, (double)ymin, -zdepth/2, (double)xmax, (double)ymin, -zdepth/2, (double)xmax, (double)ymax, -zdepth/2, (double)xmin, (double)ymax, -zdepth/2, (double)xmin, (double)ymin, -zdepth/2); multiline(5, (double)xmin, (double)ymin, zdepth/2, (double)xmax, (double)ymin, zdepth/2, (double)xmax, (double)ymax, zdepth/2, (double)xmin, (double)ymax, zdepth/2, (double)xmin, (double)ymin, zdepth/2); } } if (dist) { if (focus_aw) focus_xw=dist*tan(focus_aw*DEG2RAD); if (focus_ah) focus_yh=dist*tan(focus_ah*DEG2RAD); dashed_line(0,0,0, -focus_xw/2,-focus_yh/2,dist, 4); dashed_line(0,0,0, focus_xw/2,-focus_yh/2,dist, 4); dashed_line(0,0,0, focus_xw/2, focus_yh/2,dist, 4); dashed_line(0,0,0, -focus_xw/2, focus_yh/2,dist, 4); } #undef flux_file #undef xdiv_file #undef ydiv_file #undef radius #undef dist #undef focus_xw #undef focus_yh #undef focus_aw #undef focus_ah #undef E0 #undef dE #undef lambda0 #undef dlambda #undef I1 #undef yheight #undef xwidth #undef verbose #undef T1 #undef flux_file_perAA #undef flux_file_log #undef Lmin #undef Lmax #undef Emin #undef Emax #undef T2 #undef I2 #undef T3 #undef I3 #undef zdepth #undef target_index #undef p_in #undef lambda1 #undef lambda2 #undef lambda3 #undef pTable #undef pTable_x #undef pTable_y #undef pTable_xmin #undef pTable_xmax #undef pTable_xsum #undef pTable_ymin #undef pTable_ymax #undef pTable_ysum #undef pTable_dxmin #undef pTable_dxmax #undef pTable_dymin #undef pTable_dymax return(_comp); } /* class_Source_gen_display */ _class_Arm *class_Arm_display(_class_Arm *_comp ) { SIG_MESSAGE("[_PrimaryBeam_display] component PrimaryBeam=Arm() DISPLAY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Arm.comp:40]"); printf("MCDISPLAY: component %s\n", _comp->_name); /* A bit ugly; hard-coded dimensions. */ line(0,0,0,0.2,0,0); line(0,0,0,0,0.2,0); line(0,0,0,0,0,0.2); return(_comp); } /* class_Arm_display */ _class_Guide_gravity *class_Guide_gravity_display(_class_Guide_gravity *_comp ) { #define w1 (_comp->_parameters.w1) #define h1 (_comp->_parameters.h1) #define w2 (_comp->_parameters.w2) #define h2 (_comp->_parameters.h2) #define l (_comp->_parameters.l) #define R0 (_comp->_parameters.R0) #define Qc (_comp->_parameters.Qc) #define alpha (_comp->_parameters.alpha) #define m (_comp->_parameters.m) #define W (_comp->_parameters.W) #define nslit (_comp->_parameters.nslit) #define d (_comp->_parameters.d) #define mleft (_comp->_parameters.mleft) #define mright (_comp->_parameters.mright) #define mtop (_comp->_parameters.mtop) #define mbottom (_comp->_parameters.mbottom) #define nhslit (_comp->_parameters.nhslit) #define G (_comp->_parameters.G) #define aleft (_comp->_parameters.aleft) #define aright (_comp->_parameters.aright) #define atop (_comp->_parameters.atop) #define abottom (_comp->_parameters.abottom) #define wavy (_comp->_parameters.wavy) #define wavy_z (_comp->_parameters.wavy_z) #define wavy_tb (_comp->_parameters.wavy_tb) #define wavy_lr (_comp->_parameters.wavy_lr) #define chamfers (_comp->_parameters.chamfers) #define chamfers_z (_comp->_parameters.chamfers_z) #define chamfers_lr (_comp->_parameters.chamfers_lr) #define chamfers_tb (_comp->_parameters.chamfers_tb) #define nelements (_comp->_parameters.nelements) #define nu (_comp->_parameters.nu) #define phase (_comp->_parameters.phase) #define reflect (_comp->_parameters.reflect) #define GVars (_comp->_parameters.GVars) #define pTable (_comp->_parameters.pTable) #define table_present (_comp->_parameters.table_present) SIG_MESSAGE("[_NL_SR2_1_display] component NL_SR2_1=Guide_gravity() DISPLAY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Guide_gravity.comp:575]"); printf("MCDISPLAY: component %s\n", _comp->_name); if (l > 0 && nelements > 0) { int i,j,n; double x1,x2,x3,x4; double y1,y2,y3,y4; double nel = (nelements > 11 ? 11 : nelements); for (n=0; n_parameters.thickness) SIG_MESSAGE("[_SR2_Beamportwindow_display] component SR2_Beamportwindow=Al_window() DISPLAY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../contrib/Al_window.comp:95]"); printf("MCDISPLAY: component %s\n", _comp->_name); /* A bit ugly; hard-coded dimensions. */ line(0,0,0,0.2,0,0); line(0,0,0,0,0.2,0); line(0,0,0,0,0,0.2); #undef thickness return(_comp); } /* class_Al_window_display */ _class_Collimator_linear *class_Collimator_linear_display(_class_Collimator_linear *_comp ) { #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define length (_comp->_parameters.length) #define divergence (_comp->_parameters.divergence) #define transmission (_comp->_parameters.transmission) #define divergenceV (_comp->_parameters.divergenceV) #define slope (_comp->_parameters.slope) #define slopeV (_comp->_parameters.slopeV) SIG_MESSAGE("[_PANDA_ca1_display] component PANDA_ca1=Collimator_linear() DISPLAY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Collimator_linear.comp:101]"); printf("MCDISPLAY: component %s\n", _comp->_name); double x; int i; for(x = xmin, i = 0; i <= 3; i++, x += (xmax - xmin)/3.0) multiline(5, x, (double)ymin, 0.0, x, (double)ymax, 0.0, x, (double)ymax, (double)length, x, (double)ymin, (double)length, x, (double)ymin, 0.0); line(xmin, ymin, 0, xmax, ymin, 0); line(xmin, ymax, 0, xmax, ymax, 0); line(xmin, ymin, length, xmax, ymin, length); line(xmin, ymax, length, xmax, ymax, length); #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef length #undef divergence #undef transmission #undef divergenceV #undef slope #undef slopeV return(_comp); } /* class_Collimator_linear_display */ _class_Filter_gen *class_Filter_gen_display(_class_Filter_gen *_comp ) { #define filename (_comp->_parameters.filename) #define options (_comp->_parameters.options) #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define thickness (_comp->_parameters.thickness) #define scaling (_comp->_parameters.scaling) #define verbose (_comp->_parameters.verbose) #define Mode_Table (_comp->_parameters.Mode_Table) #define Type_Table (_comp->_parameters.Type_Table) #define pTable (_comp->_parameters.pTable) SIG_MESSAGE("[_PANDA_sapphire_display] component PANDA_sapphire=Filter_gen() DISPLAY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Filter_gen.comp:208]"); printf("MCDISPLAY: component %s\n", _comp->_name); multiline(5, (double)xmin, (double)ymin, 0.0, (double)xmax, (double)ymin, 0.0, (double)xmax, (double)ymax, 0.0, (double)xmin, (double)ymax, 0.0, (double)xmin, (double)ymin, 0.0); #undef filename #undef options #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef thickness #undef scaling #undef verbose #undef Mode_Table #undef Type_Table #undef pTable return(_comp); } /* class_Filter_gen_display */ _class_Slit *class_Slit_display(_class_Slit *_comp ) { #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define radius (_comp->_parameters.radius) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) SIG_MESSAGE("[_sk1_in_display] component sk1_in=Slit() DISPLAY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Slit.comp:81]"); printf("MCDISPLAY: component %s\n", _comp->_name); if (radius == 0) { double xw, yh; xw = (xmax - xmin)/2.0; yh = (ymax - ymin)/2.0; multiline(3, xmin-xw, (double)ymax, 0.0, (double)xmin, (double)ymax, 0.0, (double)xmin, ymax+yh, 0.0); multiline(3, xmax+xw, (double)ymax, 0.0, (double)xmax, (double)ymax, 0.0, (double)xmax, ymax+yh, 0.0); multiline(3, xmin-xw, (double)ymin, 0.0, (double)xmin, (double)ymin, 0.0, (double)xmin, ymin-yh, 0.0); multiline(3, xmax+xw, (double)ymin, 0.0, (double)xmax, (double)ymin, 0.0, (double)xmax, ymin-yh, 0.0); } else { circle("xy",0,0,0,radius); } #undef xmin #undef xmax #undef ymin #undef ymax #undef radius #undef xwidth #undef yheight return(_comp); } /* class_Slit_display */ _class_PSD_monitor *class_PSD_monitor_display(_class_PSD_monitor *_comp ) { #define nx (_comp->_parameters.nx) #define ny (_comp->_parameters.ny) #define filename (_comp->_parameters.filename) #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define restore_neutron (_comp->_parameters.restore_neutron) #define nowritefile (_comp->_parameters.nowritefile) #define PSD_N (_comp->_parameters.PSD_N) #define PSD_p (_comp->_parameters.PSD_p) #define PSD_p2 (_comp->_parameters.PSD_p2) SIG_MESSAGE("[_PSD_PrimBeam_display] component PSD_PrimBeam=PSD_monitor() DISPLAY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/PSD_monitor.comp:126]"); printf("MCDISPLAY: component %s\n", _comp->_name); multiline(5, (double)xmin, (double)ymin, 0.0, (double)xmax, (double)ymin, 0.0, (double)xmax, (double)ymax, 0.0, (double)xmin, (double)ymax, 0.0, (double)xmin, (double)ymin, 0.0); #undef nx #undef ny #undef filename #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef restore_neutron #undef nowritefile #undef PSD_N #undef PSD_p #undef PSD_p2 return(_comp); } /* class_PSD_monitor_display */ _class_L_monitor *class_L_monitor_display(_class_L_monitor *_comp ) { #define nL (_comp->_parameters.nL) #define filename (_comp->_parameters.filename) #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define Lmin (_comp->_parameters.Lmin) #define Lmax (_comp->_parameters.Lmax) #define restore_neutron (_comp->_parameters.restore_neutron) #define L_N (_comp->_parameters.L_N) #define L_p (_comp->_parameters.L_p) #define L_p2 (_comp->_parameters.L_p2) SIG_MESSAGE("[_LAM_PrimBeam_display] component LAM_PrimBeam=L_monitor() DISPLAY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/L_monitor.comp:132]"); printf("MCDISPLAY: component %s\n", _comp->_name); multiline(5, (double)xmin, (double)ymin, 0.0, (double)xmax, (double)ymin, 0.0, (double)xmax, (double)ymax, 0.0, (double)xmin, (double)ymax, 0.0, (double)xmin, (double)ymin, 0.0); #undef nL #undef filename #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef Lmin #undef Lmax #undef restore_neutron #undef L_N #undef L_p #undef L_p2 return(_comp); } /* class_L_monitor_display */ _class_Divergence_monitor *class_Divergence_monitor_display(_class_Divergence_monitor *_comp ) { #define nh (_comp->_parameters.nh) #define nv (_comp->_parameters.nv) #define filename (_comp->_parameters.filename) #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define maxdiv_h (_comp->_parameters.maxdiv_h) #define maxdiv_v (_comp->_parameters.maxdiv_v) #define restore_neutron (_comp->_parameters.restore_neutron) #define nx (_comp->_parameters.nx) #define ny (_comp->_parameters.ny) #define nz (_comp->_parameters.nz) #define Div_N (_comp->_parameters.Div_N) #define Div_p (_comp->_parameters.Div_p) #define Div_p2 (_comp->_parameters.Div_p2) SIG_MESSAGE("[_DIV_PrimBeam_display] component DIV_PrimBeam=Divergence_monitor() DISPLAY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/Divergence_monitor.comp:151]"); printf("MCDISPLAY: component %s\n", _comp->_name); multiline(5, (double)xmin, (double)ymin, 0.0, (double)xmax, (double)ymin, 0.0, (double)xmax, (double)ymax, 0.0, (double)xmin, (double)ymax, 0.0, (double)xmin, (double)ymin, 0.0); #undef nh #undef nv #undef filename #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef maxdiv_h #undef maxdiv_v #undef restore_neutron #undef nx #undef ny #undef nz #undef Div_N #undef Div_p #undef Div_p2 return(_comp); } /* class_Divergence_monitor_display */ _class_Monochromator_curved *class_Monochromator_curved_display(_class_Monochromator_curved *_comp ) { #define reflect (_comp->_parameters.reflect) #define transmit (_comp->_parameters.transmit) #define zwidth (_comp->_parameters.zwidth) #define yheight (_comp->_parameters.yheight) #define gap (_comp->_parameters.gap) #define NH (_comp->_parameters.NH) #define NV (_comp->_parameters.NV) #define mosaich (_comp->_parameters.mosaich) #define mosaicv (_comp->_parameters.mosaicv) #define r0 (_comp->_parameters.r0) #define t0 (_comp->_parameters.t0) #define Q (_comp->_parameters.Q) #define RV (_comp->_parameters.RV) #define RH (_comp->_parameters.RH) #define DM (_comp->_parameters.DM) #define mosaic (_comp->_parameters.mosaic) #define width (_comp->_parameters.width) #define height (_comp->_parameters.height) #define verbose (_comp->_parameters.verbose) #define order (_comp->_parameters.order) #define mos_rms_y (_comp->_parameters.mos_rms_y) #define mos_rms_z (_comp->_parameters.mos_rms_z) #define mos_rms_max (_comp->_parameters.mos_rms_max) #define mono_Q (_comp->_parameters.mono_Q) #define SlabWidth (_comp->_parameters.SlabWidth) #define SlabHeight (_comp->_parameters.SlabHeight) #define rTable (_comp->_parameters.rTable) #define tTable (_comp->_parameters.tTable) #define rTableFlag (_comp->_parameters.rTableFlag) #define tTableFlag (_comp->_parameters.tTableFlag) #define tiltH (_comp->_parameters.tiltH) #define tiltV (_comp->_parameters.tiltV) SIG_MESSAGE("[_PG002_mono_display] component PG002_mono=Monochromator_curved() DISPLAY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../optics/Monochromator_curved.comp:486]"); printf("MCDISPLAY: component %s\n", _comp->_name); int ih; for(ih = 0; ih < NH; ih++) { int iv; for(iv = 0; iv < NV; iv++) { double zmin,zmax,ymin,ymax; double xt, yt; zmin = (SlabWidth+gap)*(ih-NH/2.0)+gap/2; zmax = zmin+SlabWidth; ymin = (SlabHeight+gap)*(iv-NV/2.0)+gap/2; ymax = ymin+SlabHeight; if (RH) xt = -(zmax*zmax - zmin*zmin)/RH/2; else xt = 0; if (RV) yt = -(ymax*ymax - ymin*ymin)/RV/2; else yt = 0; multiline(5, xt+yt, (double)ymin, (double)zmin, xt-yt, (double)ymax, (double)zmin, -xt-yt, (double)ymax, (double)zmax, -xt+yt, (double)ymin, (double)zmax, xt+yt, (double)ymin, (double)zmin); } } #undef reflect #undef transmit #undef zwidth #undef yheight #undef gap #undef NH #undef NV #undef mosaich #undef mosaicv #undef r0 #undef t0 #undef Q #undef RV #undef RH #undef DM #undef mosaic #undef width #undef height #undef verbose #undef order #undef mos_rms_y #undef mos_rms_z #undef mos_rms_max #undef mono_Q #undef SlabWidth #undef SlabHeight #undef rTable #undef tTable #undef rTableFlag #undef tTableFlag #undef tiltH #undef tiltV return(_comp); } /* class_Monochromator_curved_display */ _class_Monitor *class_Monitor_display(_class_Monitor *_comp ) { #define xmin (_comp->_parameters.xmin) #define xmax (_comp->_parameters.xmax) #define ymin (_comp->_parameters.ymin) #define ymax (_comp->_parameters.ymax) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define restore_neutron (_comp->_parameters.restore_neutron) #define Nsum (_comp->_parameters.Nsum) #define psum (_comp->_parameters.psum) #define p2sum (_comp->_parameters.p2sum) SIG_MESSAGE("[_Mon_samplepos2_display] component Mon_samplepos2=Monitor() DISPLAY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../monitors/Monitor.comp:101]"); printf("MCDISPLAY: component %s\n", _comp->_name); multiline(5, (double)xmin, (double)ymin, 0.0, (double)xmax, (double)ymin, 0.0, (double)xmax, (double)ymax, 0.0, (double)xmin, (double)ymax, 0.0, (double)xmin, (double)ymin, 0.0); #undef xmin #undef xmax #undef ymin #undef ymax #undef xwidth #undef yheight #undef restore_neutron #undef Nsum #undef psum #undef p2sum return(_comp); } /* class_Monitor_display */ _class_NCrystal_sample *class_NCrystal_sample_display(_class_NCrystal_sample *_comp ) { #define cfg (_comp->_parameters.cfg) #define absorptionmode (_comp->_parameters.absorptionmode) #define multscat (_comp->_parameters.multscat) #define xwidth (_comp->_parameters.xwidth) #define yheight (_comp->_parameters.yheight) #define zdepth (_comp->_parameters.zdepth) #define radius (_comp->_parameters.radius) #define params (_comp->_parameters.params) #define geoparams (_comp->_parameters.geoparams) #define ncrystal_convfact_vsq2ekin (_comp->_parameters.ncrystal_convfact_vsq2ekin) #define ncrystal_convfact_ekin2vsq (_comp->_parameters.ncrystal_convfact_ekin2vsq) SIG_MESSAGE("[_PANDA_cryst_display] component PANDA_cryst=NCrystal_sample() DISPLAY [/usr/share/mcstas/3.0/tools/Python/mcrun/../mccodelib/../../../contrib/NCrystal_sample.comp:380]"); printf("MCDISPLAY: component %s\n", _comp->_name); //NB: Future McStas (2.5?) is slated to introduce mcdis_cylinder and //mcdis_sphere functions, which we at that point should likely use. #ifdef radius #undef radius #endif switch (geoparams.shape) { case NC_CYLINDER: mcdis_circle("xz", 0, geoparams.dy/2.0, 0, geoparams.radius); mcdis_circle("xz", 0, -geoparams.dy/2.0, 0, geoparams.radius); mcdis_line(-geoparams.radius, -geoparams.dy/2.0, 0, -geoparams.radius, +yheight/2.0, 0); mcdis_line(+geoparams.radius, -geoparams.dy/2.0, 0, +geoparams.radius, +yheight/2.0, 0); mcdis_line(0, -geoparams.dy/2.0, -geoparams.radius, 0, +geoparams.dy/2.0, -geoparams.radius); mcdis_line(0, -geoparams.dy/2.0, +geoparams.radius, 0, +geoparams.dy/2.0, +geoparams.radius); break; case NC_BOX: mcdis_box(0., 0., 0., geoparams.dx, geoparams.dy, geoparams.dz); break; case NC_SPHERE: mcdis_circle("xy", 0., 0., 0., geoparams.radius); mcdis_circle("xz", 0., 0., 0., geoparams.radius); mcdis_circle("yz", 0., 0., 0., geoparams.radius); break; }; #undef cfg #undef absorptionmode #undef multscat #undef xwidth #undef yheight #undef zdepth #undef radius #undef params #undef geoparams #undef ncrystal_convfact_vsq2ekin #undef ncrystal_convfact_ekin2vsq return(_comp); } /* class_NCrystal_sample_display */ #undef magnify #undef line #undef dashed_line #undef multiline #undef rectangle #undef box #undef circle #undef cylinder #undef sphere int display(void) { /* called by mccode_main for PANDA:DISPLAY */ printf("MCDISPLAY: start\n"); /* call iteratively all components DISPLAY */ class_Progress_bar_display(&_origin_var); class_Source_gen_display(&_ColdSource_var); class_Arm_display(&_PrimaryBeam_var); class_Guide_gravity_display(&_NL_SR2_1_var); class_Guide_gravity_display(&_NL_SR2_2a_var); class_Guide_gravity_display(&_NL_SR2_2b_var); class_Guide_gravity_display(&_NL_SR2_2c_var); class_Guide_gravity_display(&_NL_SR2_3_var); class_Al_window_display(&_SR2_Beamportwindow_var); class_Arm_display(&_SR2_eob_var); class_Collimator_linear_display(&_PANDA_ca1_var); class_Filter_gen_display(&_PANDA_sapphire_var); class_Slit_display(&_sk1_in_var); class_Slit_display(&_sk1_out_var); class_Slit_display(&_PANDA_ms1_var); class_Slit_display(&_sk2_in_var); class_Slit_display(&_sk2_out_var); class_PSD_monitor_display(&_PSD_PrimBeam_var); class_L_monitor_display(&_LAM_PrimBeam_var); class_Divergence_monitor_display(&_DIV_PrimBeam_var); class_Arm_display(&_PANDA_mth_var); class_Arm_display(&_a_mono_var); class_Monochromator_curved_display(&_PG002_mono_var); class_Arm_display(&_PANDA_mtt_var); class_Slit_display(&_sk3_in_var); class_Collimator_linear_display(&_PANDA_ca2_var); class_Slit_display(&_sk3_out_var); class_PSD_monitor_display(&_PSD_mon1_var); class_L_monitor_display(&_LAM_mon1_var); class_Slit_display(&_PANDA_ss1_var); class_PSD_monitor_display(&_PSD_samplepos_var); class_Monitor_display(&_Mon_samplepos2_var); class_Arm_display(&_PANDA_sth_var); class_Arm_display(&_sample_var); class_NCrystal_sample_display(&_PANDA_cryst_var); class_Arm_display(&_PANDA_stt_var); class_PSD_monitor_display(&_PSD_scattered_var); class_Slit_display(&_PANDA_ss2_var); class_Slit_display(&_sk4_in_var); class_Collimator_linear_display(&_PANDA_ca3_var); class_Slit_display(&_sk4_out_var); class_PSD_monitor_display(&_PSD_mon2_var); class_Arm_display(&_PANDA_ath_var); class_Arm_display(&_analyser_var); class_Monochromator_curved_display(&_PG002_ana_var); class_Arm_display(&_PANDA_att_var); class_Slit_display(&_sk5_in_var); class_Collimator_linear_display(&_PANDA_ca4_var); class_Slit_display(&_sk5_out_var); class_Arm_display(&_a_detector_var); class_PSD_monitor_display(&_PSD_det_var); class_PSD_monitor_display(&_PSD_det1_var); class_PSD_monitor_display(&_PSD_det2_var); printf("MCDISPLAY: end\n"); return(0); } /* display */ void* _getvar_parameters(char* compname) /* enables settings parameters based use of the GETPAR macro */ { #ifdef OPENACC #define strcmp(a,b) str_comp(a,b) #endif if (!strcmp(compname, "origin")) return (void *) &(_origin_var._parameters); if (!strcmp(compname, "ColdSource")) return (void *) &(_ColdSource_var._parameters); if (!strcmp(compname, "PrimaryBeam")) return (void *) &(_PrimaryBeam_var._parameters); if (!strcmp(compname, "NL_SR2_1")) return (void *) &(_NL_SR2_1_var._parameters); if (!strcmp(compname, "NL_SR2_2a")) return (void *) &(_NL_SR2_2a_var._parameters); if (!strcmp(compname, "NL_SR2_2b")) return (void *) &(_NL_SR2_2b_var._parameters); if (!strcmp(compname, "NL_SR2_2c")) return (void *) &(_NL_SR2_2c_var._parameters); if (!strcmp(compname, "NL_SR2_3")) return (void *) &(_NL_SR2_3_var._parameters); if (!strcmp(compname, "SR2_Beamportwindow")) return (void *) &(_SR2_Beamportwindow_var._parameters); if (!strcmp(compname, "SR2_eob")) return (void *) &(_SR2_eob_var._parameters); if (!strcmp(compname, "PANDA_ca1")) return (void *) &(_PANDA_ca1_var._parameters); if (!strcmp(compname, "PANDA_sapphire")) return (void *) &(_PANDA_sapphire_var._parameters); if (!strcmp(compname, "sk1_in")) return (void *) &(_sk1_in_var._parameters); if (!strcmp(compname, "sk1_out")) return (void *) &(_sk1_out_var._parameters); if (!strcmp(compname, "PANDA_ms1")) return (void *) &(_PANDA_ms1_var._parameters); if (!strcmp(compname, "sk2_in")) return (void *) &(_sk2_in_var._parameters); if (!strcmp(compname, "sk2_out")) return (void *) &(_sk2_out_var._parameters); if (!strcmp(compname, "PSD_PrimBeam")) return (void *) &(_PSD_PrimBeam_var._parameters); if (!strcmp(compname, "LAM_PrimBeam")) return (void *) &(_LAM_PrimBeam_var._parameters); if (!strcmp(compname, "DIV_PrimBeam")) return (void *) &(_DIV_PrimBeam_var._parameters); if (!strcmp(compname, "PANDA_mth")) return (void *) &(_PANDA_mth_var._parameters); if (!strcmp(compname, "a_mono")) return (void *) &(_a_mono_var._parameters); if (!strcmp(compname, "PG002_mono")) return (void *) &(_PG002_mono_var._parameters); if (!strcmp(compname, "PANDA_mtt")) return (void *) &(_PANDA_mtt_var._parameters); if (!strcmp(compname, "sk3_in")) return (void *) &(_sk3_in_var._parameters); if (!strcmp(compname, "PANDA_ca2")) return (void *) &(_PANDA_ca2_var._parameters); if (!strcmp(compname, "sk3_out")) return (void *) &(_sk3_out_var._parameters); if (!strcmp(compname, "PSD_mon1")) return (void *) &(_PSD_mon1_var._parameters); if (!strcmp(compname, "LAM_mon1")) return (void *) &(_LAM_mon1_var._parameters); if (!strcmp(compname, "PANDA_ss1")) return (void *) &(_PANDA_ss1_var._parameters); if (!strcmp(compname, "PSD_samplepos")) return (void *) &(_PSD_samplepos_var._parameters); if (!strcmp(compname, "Mon_samplepos2")) return (void *) &(_Mon_samplepos2_var._parameters); if (!strcmp(compname, "PANDA_sth")) return (void *) &(_PANDA_sth_var._parameters); if (!strcmp(compname, "sample")) return (void *) &(_sample_var._parameters); if (!strcmp(compname, "PANDA_cryst")) return (void *) &(_PANDA_cryst_var._parameters); if (!strcmp(compname, "PANDA_stt")) return (void *) &(_PANDA_stt_var._parameters); if (!strcmp(compname, "PSD_scattered")) return (void *) &(_PSD_scattered_var._parameters); if (!strcmp(compname, "PANDA_ss2")) return (void *) &(_PANDA_ss2_var._parameters); if (!strcmp(compname, "sk4_in")) return (void *) &(_sk4_in_var._parameters); if (!strcmp(compname, "PANDA_ca3")) return (void *) &(_PANDA_ca3_var._parameters); if (!strcmp(compname, "sk4_out")) return (void *) &(_sk4_out_var._parameters); if (!strcmp(compname, "PSD_mon2")) return (void *) &(_PSD_mon2_var._parameters); if (!strcmp(compname, "PANDA_ath")) return (void *) &(_PANDA_ath_var._parameters); if (!strcmp(compname, "analyser")) return (void *) &(_analyser_var._parameters); if (!strcmp(compname, "PG002_ana")) return (void *) &(_PG002_ana_var._parameters); if (!strcmp(compname, "PANDA_att")) return (void *) &(_PANDA_att_var._parameters); if (!strcmp(compname, "sk5_in")) return (void *) &(_sk5_in_var._parameters); if (!strcmp(compname, "PANDA_ca4")) return (void *) &(_PANDA_ca4_var._parameters); if (!strcmp(compname, "sk5_out")) return (void *) &(_sk5_out_var._parameters); if (!strcmp(compname, "a_detector")) return (void *) &(_a_detector_var._parameters); if (!strcmp(compname, "PSD_det")) return (void *) &(_PSD_det_var._parameters); if (!strcmp(compname, "PSD_det1")) return (void *) &(_PSD_det1_var._parameters); if (!strcmp(compname, "PSD_det2")) return (void *) &(_PSD_det2_var._parameters); return 0; } void* _get_particle_var(char *token, _class_particle *p) /* enables setpars based use of GET_PARTICLE_DVAR macro and similar */ { return 0; } /* embedding file "mccode_main.c" */ /******************************************************************************* * mccode_main: McCode main() function. *******************************************************************************/ int mccode_main(int argc, char *argv[]) { /* double run_num = 0; */ time_t t; clock_t ct; #ifdef USE_MPI char mpi_node_name[MPI_MAX_PROCESSOR_NAME]; int mpi_node_name_len; #endif /* USE_MPI */ #ifdef MAC argc = ccommand(&argv); #endif #ifdef USE_MPI MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD, &mpi_node_count); /* get number of nodes */ MPI_Comm_rank(MPI_COMM_WORLD, &mpi_node_rank); MPI_Comm_set_name(MPI_COMM_WORLD, instrument_name); MPI_Get_processor_name(mpi_node_name, &mpi_node_name_len); #endif /* USE_MPI */ //ct = clock(); /* we use clock rather than time to set the default seed */ //mcseed=(long)ct; // device and host functional RNG seed struct timeval tm; gettimeofday(&tm, NULL); mcseed = (long) tm.tv_sec*1000000 + tm.tv_usec; // init global _particle.randstate for random number use // during init(), finally() and display(). NOTE: during trace, a local // "_particle" variable is present and thus used instead. srandom(_hash(mcseed-1)); #ifdef USE_MPI /* *** print number of nodes *********************************************** */ if (mpi_node_count > 1) { MPI_MASTER( printf("Simulation '%s' (%s): running on %i nodes (master is '%s', MPI version %i.%i).\n", instrument_name, instrument_source, mpi_node_count, mpi_node_name, MPI_VERSION, MPI_SUBVERSION); ); /* share the same seed, then adapt random seed for each node */ MPI_Bcast(&mcseed, 1, MPI_LONG, 0, MPI_COMM_WORLD); /* root sends its seed to slaves */ mcseed += mpi_node_rank; /* make sure we use different seeds per noe */ } #endif /* USE_MPI */ // COMMON seed - not functional //time_t t; mcstartdate = (long)t; /* set start date before parsing options and creating sim file */ /* *** parse options ******************************************************* */ SIG_MESSAGE("[" __FILE__ "] main START"); mcformat = getenv(FLAVOR_UPPER "_FORMAT") ? getenv(FLAVOR_UPPER "_FORMAT") : FLAVOR_UPPER; instrument_exe = argv[0]; /* store the executable path */ /* read simulation parameters and options */ mcparseoptions(argc, argv); /* sets output dir and format */ #ifdef USE_MPI if (mpi_node_count > 1) { /* share the same seed, then adapt random seed for each node */ MPI_Bcast(&mcseed, 1, MPI_LONG, 0, MPI_COMM_WORLD); /* root sends its seed to slaves */ mcseed += mpi_node_rank; /* make sure we use different seeds per node */ } #endif /* *** install sig handler, but only once !! after parameters parsing ******* */ #ifndef NOSIGNALS #ifdef SIGQUIT if (signal( SIGQUIT ,sighandler) == SIG_IGN) signal( SIGQUIT,SIG_IGN); /* quit (ASCII FS) */ #endif #ifdef SIGABRT if (signal( SIGABRT ,sighandler) == SIG_IGN) signal( SIGABRT,SIG_IGN); /* used by abort, replace SIGIOT in the future */ #endif #ifdef SIGTERM if (signal( SIGTERM ,sighandler) == SIG_IGN) signal( SIGTERM,SIG_IGN); /* software termination signal from kill */ #endif #ifdef SIGUSR1 if (signal( SIGUSR1 ,sighandler) == SIG_IGN) signal( SIGUSR1,SIG_IGN); /* display simulation status */ #endif #ifdef SIGUSR2 if (signal( SIGUSR2 ,sighandler) == SIG_IGN) signal( SIGUSR2,SIG_IGN); #endif #ifdef SIGHUP if (signal( SIGHUP ,sighandler) == SIG_IGN) signal( SIGHUP,SIG_IGN); #endif #ifdef SIGILL if (signal( SIGILL ,sighandler) == SIG_IGN) signal( SIGILL,SIG_IGN); /* illegal instruction (not reset when caught) */ #endif #ifdef SIGFPE if (signal( SIGFPE ,sighandler) == SIG_IGN) signal( SIGSEGV,SIG_IGN); /* floating point exception */ #endif #ifdef SIGBUS if (signal( SIGBUS ,sighandler) == SIG_IGN) signal( SIGSEGV,SIG_IGN); /* bus error */ #endif #ifdef SIGSEGV if (signal( SIGSEGV ,sighandler) == SIG_IGN) signal( SIGSEGV,SIG_IGN); /* segmentation violation */ #endif #endif /* !NOSIGNALS */ // init executed by master/host siminfo_init(NULL); /* open SIM */ SIG_MESSAGE("[" __FILE__ "] main INITIALISE"); init(); #ifndef NOSIGNALS #ifdef SIGINT if (signal( SIGINT ,sighandler) == SIG_IGN) signal( SIGINT,SIG_IGN); /* interrupt (rubout) only after INIT */ #endif #endif /* !NOSIGNALS */ /* ================ main particle generation/propagation loop ================ */ #ifdef USE_MPI /* sliced Ncount on each MPI node */ mcncount = mpi_node_count > 1 ? floor(mcncount / mpi_node_count) : mcncount; /* number of rays per node */ #endif // MT specific init, note that per-ray init is empty #if RNG_ALG == 2 mt_srandom(mcseed); #endif // main raytrace work loop #ifndef FUNNEL // legacy version raytrace_all(mcncount, mcseed); #else MPI_MASTER( // "funneled" version in which propagation is more parallelizable printf("\nNOTE: CPU COMPONENT grammar activated:\n 1) \"FUNNEL\" raytrace algorithm enabled.\n 2) Any SPLIT's are dynamically allocated based on available buffer size. \n"); ); raytrace_all_funnel(mcncount, mcseed); #endif #ifdef USE_MPI /* merge run_num from MPI nodes */ if (mpi_node_count > 1) { double mcrun_num_double = (double)mcrun_num; mc_MPI_Sum(&mcrun_num_double, 1); mcrun_num = (unsigned long long)mcrun_num_double; } #endif // save/finally executed by master node/thread/host finally(); #ifdef USE_MPI MPI_Finalize(); #endif /* USE_MPI */ return 0; } /* mccode_main */ /* End of file "mccode_main.c". */ /* end of generated C code ./PANDA_Michal_DV_draft.c */