Hi everybody. Below is part of code for a continuous infrared photon laser travelling scheme. The code is much bigger than this. It is part of the bottom half of code. The top half (not show here) runs fine but the when the compiler sees this loop and the rest of the bottom code for graphing (I am using ChartDirector) the black executable screen pauses forever(The cout statement (see below)"Continuous IR radiation simulation complete." never gets printed even when I wait for 2-4 minutes). But I do not get any abort screen appear like you would for an exception. I tried speeding up the running on visual studio 2017 properties but still the same problem. Is it stuck in an infinite loop. The loop is supposed to generate and track photon positions in the zenith and azimuth angles. Can you see something I am not seeing. cr1.photonN is the number of photons(=100000). If the photon drops below a certain weight it dies and a new photon is launched until current_Phot =cr1.photonN. I am using Chart director, which is supposed to plot the positions in the x, y and z direction according to the Metropolis Hasting's algorithm.
do {
x = 0, y = 0, z = 0; //1st ONE DONE FOR CONTINUOUS SETTING
p1.current_Phot++;
photon_condition = ALIVE;
zenith_cont = p1.getzenithDir(); //SAMPLING COSTHETA
cosine_Zen_Cont = p1.cosDeg(zenith_cont); //cosine of zenith_cont (like costheta)
azimuth_cont = p1.getazimuthDir();
//SAMPLING SINTHETA
cont_sintheta = sqrt(1.0 - (cosine_Zen_Cont*cosine_Zen_Cont));//(this is our sintheta)
varS_cont = p1.getdeltaS() / (totalSkinMua + avgSkinScattCoeff); //randomly generated steps
ux = cont_sintheta*p1.cosDeg(azimuth_cont);
uy = cont_sintheta*p1.sinDeg(azimuth_cont);
uz = cosine_Zen_Cont;
//ux, uy and uz move the photons in a certain angular direction
//END OF THE LAUNCH PROCESS OF STEP 3
//HOP STAGE 4(i)
do {//while photons still exists
x = x + ux*varS_cont;//THIS IS THE START OF THE PHOTON HOPPING
y = y + uy*varS_cont;
z = z + uz*varS_cont; //moves the coordinates to create a project past the origin
//END OF THE HOP STAGE 4(i)
//START OF DROP PHASE 4(ii)
//IN THE DROP PHASE OF PHOTON TRAVELLING (PUTTING WEIGHT INTO BINS)
cr1.skinAlbedo = avgSkinScattCoeff / (totalSkinMua + avgSkinScattCoeff);
skin_albedo = cr1.skinAlbedo;
//START OF TYPE 2 PHOTON TRACING BY TALLYING WEIGHT
//first epidermis probability of being absorbed
p1.probAbsorbtn = 1 - skin_albedo;
photonAbsorbF = photon_weight*(p1.probAbsorbtn); //proportion of weight lost to absorption
photon_weight -= photonAbsorbF; //photon weight left to continue further scattering
//THE 4 LINES OF CODE ABOVE GIVE US absorbed = w*(1-albedo);
//These are the rho positions that each photons move along by based of the TEST VECTOR TECHNIQUE
rhoPositionNow = p1.getRadialPos(x, y, z); //this gives us the position it moved to after the above calculation
//put the radial index into the spatial bin;
//SPACE FOR OPTICAL DEPTHS OF THICK AND THIN SKIN
current_pathTravel = current_pathTravel + rhoPositionNow;
ir =mc1.convertDoubToInt(rhoPositionNow / dr); //makes sure we have our new projection fit in the bin
//make a provision for overflow in case the photons overlow their respective dr
if (ir > NR_bins) {
ir = NR_bins;
}//FOR OVERFLOW
Csph[ir] += photonAbsorbF;
/*SPIN phase of photon travel: scattering photon according the zenith and azimuthal angles 4(ii)
and based of the Henyey Greenstein phase function; the zenith and azimuthal angles are
converted into cosines*/
if (e = 0.0) {//isotropic scattering
cosine_Zen_Cont = p1.cosDeg(zenith_cont);
}
else {
//get forward peak of scattering by using a random number between 0 and 1
tempStore1 = (1.0 - (e*e)) / (1.0 + (2.0 * phaseScattVal*e - e));
cosine_Zen_Cont = (1.0 + e*e - (tempStore1*tempStore1) / 2.0*e);
}
cont_sintheta = sqrt(1.0 - (cosine_Zen_Cont*cosine_Zen_Cont));
//Now we need to deal with the azimuthal angle depending on its angle orientation
cosine_azimuth = p1.cosDeg(azimuth_cont);
if (azimuth_cont < PI) {
sin_azimuth = sqrt(1.0 - cosine_azimuth*cosine_azimuth);
}//if
else {
sin_azimuth = -1.0*sqrt(1.0 - cosine_azimuth*cosine_azimuth);
}//else
/*Make a new travel path for the photon via successive runs*/
if (1.0 - fabs(uz) <= NEAR_PERPEN) {
ux_New = cont_sintheta*cosine_azimuth;
uy_New = cont_sintheta*sin_azimuth;
uz_New = cosine_Zen_Cont*SIGN(uz);
}//if
else {
tempStore1 = sqrt(1.0 - uz*uz);
ux_New = cont_sintheta* (ux*uz*cosine_azimuth - uy*sin_azimuth) / tempStore1 + ux*cosine_Zen_Cont;
uy_New = cont_sintheta*(uy*uz*cosine_azimuth + ux*sin_azimuth) / tempStore1 + uy*cosine_Zen_Cont;
uz_New = -1 * cont_sintheta*cosine_azimuth*tempStore1 + uz*cosine_Zen_Cont;
}
ux = ux_New;
uy = uy_New;
uz = uz_New; //update trajectory
//STEP 5: Roulette to determine if the photon should live of die based off a threshold
if (photon_weight < SURVIVE_THRESHOLD) {
if (randomNumber <= PROB_SURVIVAL) {
photon_weight = photon_weight / PROB_SURVIVAL;
}//inner if
else {
photon_condition = DEAD;
}
}//outer if
} while (photon_condition = ALIVE);
for (int i = 0; i < p1.current_Phot; i++) {//opening for
xVal.at(i) = x;
yVal.at(i) = y;
zVal.at(i) = z;
}//closing for
} while (p1.current_Phot < cr1.photonN); //end of do while loops (UNCOMMENT IN A MINUTE)
if (p1.current_Phot == cr1.photonN) {
cout << "Continuous IR radiation simulation complete." << endl;
}
Please don't start a new topic about the same subject, just continue with the same one - it doesn't matter if you have different questions about the same code.
With the indentation, there should be some sort of code formatting option in your IDE. At the moment it is terrible to read. Set your IDE to translate tabs to 4 spaces so it will display better here. AFAIK This site uses 8 spaces for tabs, so that might be why you have so much indentation here.
Put your comments before the line it refers to, not at the end of the code line. It makes the code too wide.
You need to make more use of functions, so far we can see 130 LOC in one function, but it is probably more.
One thing I noticed: Line 115 use == not = . = will always be true.