38 #ifndef _MMC_MESH_UNIT_H 39 #define _MMC_MESH_UNIT_H 46 #include <smmintrin.h> 49 #if !defined(USE_OPENCL) && !defined(__NVCC__) 52 #include "mmc_rand_sfmt.c" 53 #elif defined MMC_XORSHIFT 54 #include "mmc_rand_xorshift128p.c" 56 #include "mmc_rand_posix.c" 59 #elif defined(__NVCC__) 62 #include "mmc_rand_xorshift128p.c" 65 #define MMC_UNDEFINED (3.40282347e+38F) 66 #define ID_UNDEFINED 0x7FFFFFFF 68 #define R_RAND_MAX (1.f/RAND_MAX) 69 #define TWO_PI (M_PI*2.0) 71 #define LOG_MT_MAX 22.1807097779182f 72 #define R_MIN_MUS 1e9f 73 #define R_C0 3.335640951981520e-12f //1/C0 in s/mm 74 #define DELTA_MUA 1e-4f 75 #define VERY_BIG 1e30f 76 #define MIN(a,b) ((a)<(b)?(a):(b)) 77 #define MAX(a,b) ((a)>(b)?(a):(b)) 79 #define MESH_ERROR(a) mesh_error((a),__FILE__,__LINE__) 149 void mesh_build(
tetmesh* mesh);
150 void mesh_error(
const char* msg,
const char* file,
const int linenum);
173 int mcx_throw_exception(
const int id,
const char* msg,
const char* filename,
const int linenum);
181 res->x = a->x + b->x;
182 res->y = a->y + b->y;
183 res->z = a->z + b->z;
187 res->x = b->x - a->x;
188 res->y = b->y - a->y;
189 res->z = b->z - a->z;
192 static inline void vec_mult(
float3* a,
float sa,
float3* res) {
198 static inline void vec_mult_add(
float3* a,
float3* b,
float sa,
float sb,
float3* res) {
199 res->x = sb * b->x + sa * a->x;
200 res->y = sb * b->y + sa * a->y;
201 res->z = sb * b->z + sa * a->z;
205 res->x = a->y * b->z - a->z * b->y;
206 res->y = a->z * b->x - a->x * b->z;
207 res->z = a->x * b->y - a->y * b->x;
210 static inline void mmc_sincosf(
float x,
float* sine,
float* cosine) {
211 #if defined(__GNUC__) && defined(__linux__) && !defined(__clang__) 212 __builtin_sincosf(x, sine, cosine);
221 return a->x * b->x + a->y * b->y + a->z * b->z;
252 return vec_dot(Pd, Am) + vec_dot(Pm, Ad);
257 return (p1->x - p0->x) * (p1->x - p0->x) + (p1->y - p0->y) * (p1->y - p0->y) + (p1->z - p0->z) * (p1->z - p0->z);
261 return sqrtf(dist2(p0, p1));
264 static inline float dist2d2(
float* p0,
float* p1) {
265 return (p1[0] - p0[0]) * (p1[0] - p0[0]) + (p1[1] - p0[1]) * (p1[1] - p0[1]);
268 static inline float mmc_rsqrtf(
float a) {
270 return _mm_cvtss_f32( _mm_rsqrt_ss( _mm_set_ss( a ) ) );
272 return 1.f / sqrtf(a);
This structure defines the problem settings (domain, filenames, session)
Definition: mmc_utils.h:184
void mesh_loadelemvol(tetmesh *mesh, mcconfig *cfg)
Load tet element volume file and initialize the related mesh properties.
Definition: mmc_mesh.c:517
double mesh_getreff(double n_in, double n_out)
Compute the effective reflection coefficient Reff.
Definition: mmc_mesh.c:1616
void mesh_loadseedfile(tetmesh *mesh, mcconfig *cfg)
Load previously saved photon seeds from an .mch file for replay.
Definition: mmc_mesh.c:604
void mesh_saveweight(tetmesh *mesh, mcconfig *cfg, int isref)
Save the fluence output to a file.
Definition: mmc_mesh.c:1237
int * elem2
Definition: mmc_mesh.h:98
float3 * d
Definition: mmc_mesh.h:131
float mc_next_scatter(float g, float3 *dir, RandType *ran, RandType *ran0, mcconfig *cfg, float *pmom)
Performing one scattering event of the photon.
Definition: mmc_mesh.c:1155
float * edgeroi
Definition: mmc_mesh.h:99
float3 * n
Definition: mmc_mesh.h:133
float4 nmax
Definition: mmc_mesh.h:115
int * type
Definition: mmc_mesh.h:106
double * weight
Definition: mmc_mesh.h:110
void tracer_clear(raytracer *tracer)
Clear the ray-tracing data structure.
Definition: mmc_mesh.c:1123
char method
Definition: mmc_mesh.h:130
void mesh_error(const char *msg, const char *file, const int linenum)
Error-handling in mesh operations.
Definition: mmc_mesh.c:182
int detelemlen
Definition: mmc_mesh.h:105
void mesh_loadnode(tetmesh *mesh, mcconfig *cfg)
Load node file and initialize the related mesh properties.
Definition: mmc_mesh.c:301
tetmesh * mesh
Definition: mmc_mesh.h:129
float mesh_getdetweight(int photonid, int colcount, float *ppath, mcconfig *cfg)
Recompute the detected photon weight from the partial-pathlengths.
Definition: mmc_mesh.c:1464
void mesh_init(tetmesh *mesh)
Initializing the mesh data structure with default values.
Definition: mmc_mesh.c:111
float3 * m
Definition: mmc_mesh.h:132
Basic FEM mesh data structrure.
Definition: mmc_mesh.h:90
This structure defines the optical properties for each medium.
Definition: mmc_utils.h:129
float * evol
Definition: mmc_mesh.h:112
Definition of program options and problem domain configurations.
int * srcelem
Definition: mmc_mesh.h:102
int ne
Definition: mmc_mesh.h:92
void mesh_loadmedia(tetmesh *mesh, mcconfig *cfg)
Load optical property file and initialize the related mesh properties.
Definition: mmc_mesh.c:339
void mesh_filenames(const char *format, char *foutput, mcconfig *cfg)
Construct a full mesh file name using cfg session and root path.
Definition: mmc_mesh.c:199
void mesh_loadelem(tetmesh *mesh, mcconfig *cfg)
Load element file and initialize the related mesh properties.
Definition: mmc_mesh.c:455
int * elem
Definition: mmc_mesh.h:97
float * nvol
Definition: mmc_mesh.h:113
void mesh_getdetimage(float *detmap, float *ppath, int count, mcconfig *cfg, tetmesh *mesh)
Save binned detected photon data over an area-detector as time-resolved 2D images.
Definition: mmc_mesh.c:1372
int * detelem
Definition: mmc_mesh.h:104
float3 * node
Definition: mmc_mesh.h:96
int srcelemlen
Definition: mmc_mesh.h:103
int nn
Definition: mmc_mesh.h:91
An interface to use the SFMT-19937 random number generator.
float * noderoi
Definition: mmc_mesh.h:101
float mesh_normalize(tetmesh *mesh, mcconfig *cfg, float Eabsorb, float Etotal, int pair)
Function to normalize the fluence and remove influence from photon number and volume.
Definition: mmc_mesh.c:1498
void tracer_prep(raytracer *tracer, mcconfig *cfg)
Preparing for the ray-tracing calculations.
Definition: mmc_mesh.c:818
double * dref
Definition: mmc_mesh.h:111
medium * med
Definition: mmc_mesh.h:108
int * facenb
Definition: mmc_mesh.h:107
int elemlen
Definition: mmc_mesh.h:95
float * faceroi
Definition: mmc_mesh.h:100
void mesh_srcdetelem(tetmesh *mesh, mcconfig *cfg)
Identify wide-field source and detector-related elements (type=-1 for source, type=-2 for det) ...
Definition: mmc_mesh.c:252
int prop
Definition: mmc_mesh.h:94
void mesh_init_from_cfg(tetmesh *mesh, mcconfig *cfg)
Loading user-specified mesh data.
Definition: mmc_mesh.c:153
void mesh_loadfaceneighbor(tetmesh *mesh, mcconfig *cfg)
Load face-neightbor element list and initialize the related mesh properties.
Definition: mmc_mesh.c:562
void mesh_loadroi(tetmesh *mesh, mcconfig *cfg)
Load edge/node/face roi for implicit MMC.
Definition: mmc_mesh.c:403
int nf
Definition: mmc_mesh.h:93
void mesh_savedetphoton(float *ppath, void *seeds, int count, int seedbyte, mcconfig *cfg)
Save detected photon data into an .mch history file.
Definition: mmc_mesh.c:1305
void mesh_savedetimage(float *detmap, mcconfig *cfg)
Save binned detected photon data over an area-detector.
Definition: mmc_mesh.c:1431
float4 nmin
Definition: mmc_mesh.h:114
floating-point triplet {x,y,z}
Definition: vector_types.h:73
void tracer_build(raytracer *tracer)
Pre-computed ray-tracing related data.
Definition: mmc_mesh.c:995
Ray-tracer data structrure for pre-computed data.
Definition: mmc_mesh.h:128
void tracer_init(raytracer *tracer, tetmesh *mesh, char methodid)
Initialize a data structure storing all pre-computed ray-tracing related data.
Definition: mmc_mesh.c:799
double mesh_getreff_approx(double n_in, double n_out)
Compute the effective reflection coefficient Reff using approximated formula.
Definition: mmc_mesh.c:1604
void mesh_clear(tetmesh *mesh)
Clearing the mesh data structure.
Definition: mmc_mesh.c:698
float * atte
Definition: mmc_mesh.h:109