Guest User

Untitled

a guest
Jan 16th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.89 KB | None | 0 0
  1. [code]
  2. do {
  3. photon_condition = ALIVE;
  4. acc_pathLength = 0;
  5. x = 0,y = 0,z = 0;
  6. pPacketCounter++;
  7. it_2 = 0;
  8. cosine_Zen_Cont = p1.getzenithDir();
  9.  
  10. azimuth_cont = p1.getazimuthDir();
  11.  
  12. cont_sintheta = sqrt(1.0 - (cosine_Zen_Cont*cosine_Zen_Cont));
  13.  
  14.  
  15.  
  16. ux = cont_sintheta * cos(azimuth_cont);
  17. uy = cont_sintheta * sin(azimuth_cont);
  18. uz = cosine_Zen_Cont;
  19.  
  20.  
  21.  
  22. do {
  23.  
  24.  
  25. randomNumber = p1.getRandNum();
  26. while ((randomNumber <= 0.0));
  27. varS_cont = p1.getdeltaS() / avgSkinScattCoeff;
  28.  
  29. if (acc_pathLength + varS_cont >= photonPathLength[it_2]) {
  30. step_walk = photonPathLength[it_2] - acc_pathLength;
  31.  
  32.  
  33. x2 = x + (step_walk*ux);
  34. y2 = y + (step_walk*uy);
  35. z2 = z + (step_walk*uz);
  36.  
  37.  
  38. rhoPositionNow2 = p1.getRadialPos2(x2, y2, z2);
  39.  
  40. /*SECTION FOR THE GIBBS'S SAMPLER WHERE WE COLLECT THE DISTANCES
  41. TRAVERSED FOR X, Y, AND Z WHILE THE PHOTON IS ALIVE; CALCULATE
  42. MEAN 1,2,3 -> SIGMA 1,2,3 -> COVARIANCE 1,2,3 -> MAYBE CORRELATION
  43. COEFFICIENT RHO BETWEEN ALL 3 VARIABLES*/
  44.  
  45.  
  46.  
  47. //next we will create a radial index based off rho
  48. ir_2 = mc1.convertDoubToInt(rhoPositionNow2 / dr2);
  49. if (ir_2 > NR) {ir_2 = NR;
  50. }
  51.  
  52. Csph_pulsed[ir_2][it_2] += 1;
  53. it_2 += 1;
  54. }//if bracket
  55. x += ux * varS_cont;
  56. y += uy * varS_cont;
  57. z += uz * varS_cont;
  58.  
  59. acc_pathLength += varS_cont;
  60.  
  61.  
  62.  
  63. if (e == 0.0) {//isotropic scattering
  64. cosine_Zen_Cont = p1.getzenithDir();
  65. }
  66. else {
  67. //get forward peak of scattering by using a random number between 0 and 1
  68. tempStore1 = (1.0 - (e*e)) / (1.0 - e + (2.0*e*phaseScattVal));
  69. cosine_Zen_Cont = ((1.0 + e * e) - (tempStore1*tempStore1) / (2.0*e));
  70. }
  71. cont_sintheta = sqrt(fabs(1.0 - (cosine_Zen_Cont*cosine_Zen_Cont)));
  72.  
  73.  
  74. cosine_azimuth = cos(azimuth_cont);
  75. if (azimuth_cont < PI) {
  76. sin_azimuth = sqrt(1.0 - (cosine_azimuth*cosine_azimuth));
  77. }//if
  78. else {
  79. sin_azimuth = -sqrt(1.0 - (cosine_azimuth*cosine_azimuth));
  80.  
  81. }//else
  82.  
  83. /*Make a new travel path for the photon via successive runs*/
  84. if (1.0 - fabs(uz) <= NEAR_PERPEN) {
  85. ux_New = cont_sintheta * cosine_azimuth;
  86. uy_New = cont_sintheta * sin_azimuth;
  87. uz_New = cosine_Zen_Cont * SIGN(uz);
  88. }//if
  89.  
  90. else {
  91. tempStore1 = sqrt(1.0 - uz * uz);
  92. ux_New = cont_sintheta * (ux*uz*cosine_azimuth - uy *sin_azimuth)/(tempStore1 + (ux*cosine_Zen_Cont));
  93.  
  94. uy_New = cont_sintheta * (uy*uz*cosine_azimuth + ux * sin_azimuth)/ (tempStore1 + (uy*cosine_Zen_Cont));
  95.  
  96. uz_New = -1.0 * (cont_sintheta*cosine_azimuth*tempStore1) + (uz*cosine_Zen_Cont);
  97. }
  98. ux = ux_New;
  99. uy = uy_New;
  100. uz = uz_New; //update trajectory
  101.  
  102.  
  103.  
  104.  
  105.  
  106. pulsedXVal = (double*)calloc(photPacket, sizeof(double));
  107. pulsedYVal = (double*)calloc(photPacket, sizeof(double));
  108. pulsedZVal = (double*)calloc(photPacket, sizeof(double));
  109. up = 0;
  110. counterTotalX = photPacket + up;
  111. counterTotalY = photPacket + up;
  112. counterTotalZ = photPacket + up;
  113. for (int i = 0; i < counterTotalX; ++i) {
  114.  
  115. pulsedXVal[i] = x;
  116. pulsedYVal[i] = y;
  117. pulsedZVal[i] = z;
  118.  
  119. }
  120. if (acc_pathLength >= maxPathLength) {
  121.  
  122. photon_condition = DEAD;
  123. }
  124.  
  125. ++up;
  126. counterTotalX += up;
  127. counterTotalY += up;
  128. counterTotalZ += up;
  129. pulsedXVal = (double*)realloc(pulsedXVal, counterTotalX);
  130. pulsedYVal = (double*)realloc(pulsedYVal, counterTotalY);
  131. pulsedZVal = (double*)realloc(pulsedZVal, counterTotalZ);
  132.  
  133.  
  134. //loopIncrementer++;
  135.  
  136.  
  137.  
  138. } while (photon_condition == ALIVE);
  139. for (int i = 0; i < counterTotalX; ++i) {
  140. xCollect.push_back(pulsedXVal[i]);
  141. }
  142. for (int j = 0; j < counterTotalY; ++j) {
  143. yCollect.push_back(pulsedYVal[j]);
  144. }
  145. for (int k = 0; k < counterTotalZ; ++k) {
  146. zCollect.push_back(pulsedZVal[k]);
  147. }
  148.  
  149.  
  150. /*
  151. xCollectSum += x;
  152. yCollectSum += y;
  153. zCollectSum += z;
  154. */
  155. } while (pPacketCounter <= photPacket);
  156.  
  157. //NEW
  158. for (it4 = xCollect.begin(); it4 != xCollect.end(); ++it4) {
  159. xCollectSum += *it4;
  160.  
  161. }
  162. for (it5 = yCollect.begin(); it5 != yCollect.end(); ++it5) {
  163. yCollectSum += *it5;
  164. //yCollect.push_back(pulsedYVal[m]);
  165. }
  166. for (it6 = zCollect.begin(); it6 != zCollect.end(); ++it6) {
  167. //zCollect.push_back(pulsedZVal[n]);
  168. zCollectSum += *it6;
  169. }
  170.  
  171.  
  172.  
  173.  
  174. //NEW
  175. cout << "Pulsed simulation complete." << endl;
  176. averageX = xCollectSum / counterTotalX;
  177. averageY = yCollectSum / counterTotalY;
  178. averageZ = zCollectSum / counterTotalZ;
  179.  
  180. xCollectArr = (double*)calloc(counterTotalX,sizeof(double));
  181. yCollectArr = (double*)calloc(counterTotalY, sizeof(double));
  182. zCollectArr= (double*)calloc(counterTotalZ, sizeof(double));
  183. for(int a; a<counterTotalX;++a){
  184. for (it4 = xCollect.begin(); it4 != xCollect.end(); ++it4) {
  185. xCollectArr[a] = *it4;
  186. }
  187. }
  188. for (int b; b<counterTotalY; ++b) {
  189. for (it5 = xCollect.begin(); it5 != xCollect.end(); ++it5) {
  190. yCollectArr[b] = *it5;
  191. }
  192. }
  193. for (int c; a<counterTotalZ; ++c) {
  194. for (it6 = xCollect.begin(); it6 != xCollect.end(); ++it6) {
  195. zCollectArr[c] = *it6;
  196. }
  197. }
  198.  
  199. stdDevXRho = p1.getStdDev(averageX, counterTotalX, xCollectArr);
  200. stdDevYRho = p1.getStdDev(averageY, counterTotalY, yCollectArr);
  201. stdDevZRho = p1.getStdDev(averageZ, counterTotalZ, zCollectArr);
  202.  
  203. xyCorrelCoeff = p1.getSimpleCorrelation(xCollectArr, yCollectArr, counterTotalX, averageX, averageY);
  204. xzCorrelCoeff = p1.getSimpleCorrelation(xCollectArr, zCollectArr, counterTotalX, averageX, averageZ);
  205. yzCorrelCoeff = p1.getSimpleCorrelation(yCollectArr, zCollectArr, counterTotalX, averageY, averageZ);
  206. //Above will be the correlation coefficients
  207. multCorrelR = p1.getMultipleCorrelation(xyCorrelCoeff, xzCorrelCoeff, yzCorrelCoeff);
  208. //multiple correlation coefficient
  209.  
  210. //goes with rest of declared variables
  211. double* chain_x1_1 = NULL;
  212. double* chain_y1_2 = NULL;
  213. double* chain_x2_1 = NULL;
  214. double* chain_z2_2 = NULL;
  215. double* chain_y3_1 = NULL;
  216. double* chain_z3_2 = NULL;
  217.  
  218. chain_x1_1 = (double*)calloc(counterTotalX, sizeof(double));
  219. chain_y1_2 = (double*)calloc(counterTotalY, sizeof(double));
  220. chain_x2_1 = (double*)calloc(counterTotalX, sizeof(double));
  221. chain_z2_2 = (double*)calloc(counterTotalZ, sizeof(double));
  222. chain_y3_1 = (double*)calloc(counterTotalY, sizeof(double));
  223. chain_z3_2 = (double*)calloc(counterTotalZ, sizeof(double));
  224.  
  225.  
  226. if (chain_x1_1 == NULL || chain_y1_2 == NULL || chain_x2_1 == NULL || chain_z2_2 == NULL || chain_y3_1 == NULL || chain_z3_2 == NULL) {
  227. cerr << "Memory allocation failed(2)" << endl;
  228. }
  229.  
  230.  
  231. for (int i = 0; i<counterTotalX; i++) {
  232. chain_x1_1[0] = 0;
  233. chain_y1_2[0] = 0;
  234.  
  235. chain_x2_1[0] = 0;
  236. chain_z2_2[0] = 0;
  237.  
  238. chain_y3_1[0] = 0;
  239. chain_z3_2[0] = 0;
  240.  
  241.  
  242. chain_x1_1[i + 1] = p1.getGibbsConditionalSample(chain_y1_2[i], averageX, averageY, stdDevXRho, stdDevYRho, xyCorrelCoeff);
  243. chain_y1_2[i + 1] = p1.getGibbsConditionalSample(chain_x1_1[i + 1], averageY, averageX, stdDevYRho, stdDevXRho, xyCorrelCoeff);
  244.  
  245. [/code]
Add Comment
Please, Sign In to add comment