void updatePMLEFieldUtilEz(int xStart, int xEnd, int yStart, int yEnd, int zStart, int zEnd, int xBound, int yBound, int zBound, pmlConstStruct cx[], pmlConstStruct cy[], pmlConstStruct cz[], int n){ int i, j, k; // These are the indexes int x,y,z;// There are indexes for the pmlConstStruct indexs long p; int m; double dzStore; double eps; for (i=xStart;i<xEnd+1;i++){ x = abs(xBound - i)%PML_LAYERS; for (j=yStart;j<yEnd+1;j++){ y = abs(yBound - j)%PML_LAYERS; for (k=zStart;k<zEnd+1;k++){ z = abs(zBound - k)%PML_LAYERS; p = PMLINDEX(i,j,k); dzStore = DZ(p); m = MATERIALINDEX(i,j,k); eps = EPSR(m)*EPSNOT; DZ(p) = cx[x].c1*DZ(p) + cx[x].c2*(HY(i,j,k) - HY(i-1,j,k) - HX(i,j,k) + HX(i,j-1,k) - JSZ(m)); EZ(i,j,k) = cy[y].c3*EZ(i,j,k) + cy[y].c4*(cz[z].c5*DZ(p)-cz[z].c6*dzStore)/eps; }}} // end for }// end updatePMLEFieldUtilEz
void updatePMLHFieldUtilAll(int xStart, int xEnd, int yStart, int yEnd, int zStart, int zEnd, int xBound, int yBound, int zBound, pmlConstStruct cx[], pmlConstStruct cy[], pmlConstStruct cz[], int n){ int i, j, k; // These are the indexes int x,y,z;// There are indexes for the pmlConstStruct indexs long p; int m; double bxStore, byStore, bzStore; double mu; // Either this, or make cOnes a bigger array with number of elements which are the max of xLen, yLen, zLen for (i=xStart;i<xEnd+1;i++){ x = abs(xBound - i)%PML_LAYERS; for (j=yStart;j<yEnd+1;j++){ y = abs(yBound - j)%PML_LAYERS; for (k=zStart;k<zEnd+1;k++){ z = abs(zBound - k)%PML_LAYERS; p = PMLINDEX(i,j,k); bxStore = BX(p); byStore = BY(p); bzStore = BZ(p); mu = MUR(m)*MUNOT; BX(p) = cy[y].c1*BX(p) + cy[y].c2*(EY(i,j,k+1) - EY(i,j,k) + EZ(i,j,k) - EZ(i,j+1,k) - MSX(m)); HX(i,j,k) = cz[z].c3*HX(i,j,k) + cz[z].c4*(cx[x].c5*BX(p)-cx[x].c6*bxStore)/mu; BY(p) = cz[z].c1*BY(p) + cz[z].c2*(EZ(i+1,j,k) - EZ(i,j,k) + EX(i,j,k) - EX(i,j,k+1) - MSY(m)); HY(i,j,k) = cx[x].c3*HY(i,j,k) + cx[x].c4*(cy[y].c5*BY(p)-cy[y].c6*byStore)/mu; BZ(p) = cx[x].c1*BZ(p) + cx[x].c2*(EX(i,j+1,k) - EX(i,j,k) + EY(i,j,k) - EY(i+1,j,k) - MSZ(m)); HZ(i,j,k) = cy[y].c3*HZ(i,j,k) + cy[y].c4*(cz[z].c5*BZ(p)-cz[z].c6*bzStore)/mu; }}} // end for }// end updatePMLHFieldUtilAll
static void ATATimingManager_Quantize(ATATiming* pATATimingS, ATATiming* pATATimingR, unsigned uiTiming, unsigned uiUDMATiming) { pATATimingR->usSetup = EZ(pATATimingS->usSetup * 1000, uiTiming) ; pATATimingR->usAct8b = EZ(pATATimingS->usAct8b * 1000, uiTiming) ; pATATimingR->usRec8b = EZ(pATATimingS->usRec8b * 1000, uiTiming) ; pATATimingR->usCyc8b = EZ(pATATimingS->usCyc8b * 1000, uiTiming) ; pATATimingR->usAct = EZ(pATATimingS->usAct * 1000, uiTiming) ; pATATimingR->usRec = EZ(pATATimingS->usRec * 1000, uiTiming) ; pATATimingR->usCyc = EZ(pATATimingS->usCyc * 1000, uiTiming) ; pATATimingR->usUDMA = EZ(pATATimingS->usUDMA * 1000, uiUDMATiming) ; }
static void ide_timing_quantize(struct ide_timing *t, struct ide_timing *q, int T, int UT) { q->setup = EZ(t->setup * 1000, T); q->act8b = EZ(t->act8b * 1000, T); q->rec8b = EZ(t->rec8b * 1000, T); q->cyc8b = EZ(t->cyc8b * 1000, T); q->active = EZ(t->active * 1000, T); q->recover = EZ(t->recover * 1000, T); q->cycle = EZ(t->cycle * 1000, T); q->udma = EZ(t->udma * 1000, UT); }
//calculate M and B static inline void calcMB() { //todo code of EZ(i, j+1) and EZ(i,j) may be reverse ? for(int i=1; i<N_PX-1; i++){ for(int j=1; j<N_PY-1; j++){ double complex nowMx = MX(i,j); Mx[ind(i,j)] = CMX(i,j)*MX(i,j) - CMXEZ(i,j)*(EZ(i,j+1) - EZ(i,j)); Bx[ind(i,j)] = CBX(i,j)*BX(i,j) + CBXMX1(i,j)*MX(i,j) - CBXMX0(i,j)*nowMx; } } //todo code of EZ(i+1, j) and EZ(i,j) for(int i=1; i<N_PX-1; i++){ for(int j=1; j<N_PY-1; j++){ double complex nowMy = MY(i,j); My[ind(i,j)] = CMY(i,j)*MY(i,j) - CMYEZ(i,j)*(-EZ(i+1,j) + EZ(i,j)); By[ind(i,j)] = CBY(i,j)*BY(i,j) + CBYMY1(i,j)*MY(i,j) - CBYMY0(i,j)*nowMy; } } }
void updatePMLEFieldUtilAll(int xStart, int xEnd, int yStart, int yEnd, int zStart, int zEnd, int xBound, int yBound, int zBound, pmlConstStruct cx[], pmlConstStruct cy[], pmlConstStruct cz[], int n){ int i, j, k; // These are the indexes int x,y,z;// There are indexes for the pmlConstStruct indexs long p; int m; double dxStore, dyStore, dzStore; double eps; // Either this, or make cOnes a bigger array with number of elements which are the max of xLen, yLen, zLen for (i=xStart;i<xEnd+1;i++){ x = abs(xBound - i)%PML_LAYERS; for (j=yStart;j<yEnd+1;j++){ y = abs(yBound - j)%PML_LAYERS; for (k=zStart;k<zEnd+1;k++){ z = abs(zBound - k)%PML_LAYERS; //printf("(i,j,k) (%d, %d, %d), (x,y,z) (%d,%d,%d)\n", i,j,k,x,y,z); p = PMLINDEX(i,j,k); dxStore = DX(p); dyStore = DY(p); dzStore = DZ(p); m = MATERIALINDEX(i,j,k); eps = EPSR(m)*EPSNOT; DX(p) = cy[y].c1*DX(p) + cy[y].c2*(HZ(i,j,k) - HZ(i,j-1,k) - HY(i,j,k) + HY(i,j,k-1) - JSX(m)); EX(i,j,k) = cz[z].c3*EX(i,j,k) + cz[z].c4*(cx[x].c5*DX(p)-cx[x].c6*dxStore)/eps; DY(p) = cz[z].c1*DY(p) + cz[z].c2*(HX(i,j,k) - HX(i,j,k-1) + HZ(i-1,j,k) - HZ(i,j,k) - JSY(m)); EY(i,j,k) = cx[x].c3*EY(i,j,k) + cx[x].c4*(cy[y].c5*DY(p)-cy[y].c6*dyStore)/eps; DZ(p) = cx[x].c1*DZ(p) + cx[x].c2*(HY(i,j,k) - HY(i-1,j,k) - HX(i,j,k) + HX(i,j-1,k) - JSZ(m)); EZ(i,j,k) = cy[y].c3*EZ(i,j,k) + cy[y].c4*(cz[z].c5*DZ(p)-cz[z].c6*dzStore)/eps; }}} // end for }// end updatePMLEFieldUtilAll
double mapping(TString SimData, TString ExpData, TString background = "nobackground"){ /////////////////////// OPEN INPUT AND OUTPUT FILES /////////////////////// // open the data file ifstream input_exp; TString fullpathtofile = Form("%s",ExpData.Data() ) ; if(gVerbose>0) cout<<"opening file : |"<<ExpData<< "| ... "; input_exp.open( ExpData.Data() ); if (!input_exp) { cout<<"problem opening experimental data file " << fullpathtofile << endl; exit(-1);} else if(gVerbose>0) cout<<"Experimental file is opened "<<endl; //open the field files from comsol ifstream input_sim; fullpathtofile = Form("%s",SimData.Data() ) ; if(gVerbose>0) cout<<"opening file : |"<<SimData<< "| ... "; input_sim.open(SimData.Data() ) ; if(!input_sim.is_open()) { if(gVerbose>0) cout<<"problem opening simulation data file |"<< fullpathtofile <<"|"<< endl; SimData.ReplaceAll("./input/",""); fullpathtofile = Form("/data1/moukaddam/MagnetSimulation/%s",SimData.Data()) ; if(gVerbose>0) cout<<"trying main directory, opening file : |"<<fullpathtofile<< "| ... "; input_sim.open(fullpathtofile.Data() ) ; // from local input if not go seek in data 1 if (!input_sim.is_open()) { cout<<"problem opening simulation data file |"<< fullpathtofile <<"|"<< endl<<endl; exit(-1);} } else if(gVerbose>0) cout<<" Simulation file " << fullpathtofile << " is opened " <<endl; // create root output file ExpData.ReplaceAll("./input/",""); ExpData.ReplaceAll(".dat",""); ExpData.ReplaceAll(".txt",""); SimData.ReplaceAll("./input/",""); SimData.ReplaceAll(".dat",""); SimData.ReplaceAll(".txt",""); TString filename = "./output/compare_" + ExpData + "_" + SimData + ".root"; TFile outputFile(filename,"RECREATE"); TDirectory *dirquad[4] ; dirquad[0] = outputFile.mkdir("Quad_1"); dirquad[1] = outputFile.mkdir("Quad_2"); dirquad[2] = outputFile.mkdir("Quad_3"); dirquad[3] = outputFile.mkdir("Quad_4"); //Read the simulation file from comsol // dump the first lines from the top string s_buffer="buffer"; Int_t d_buffer=-1; Int_t counter1=0; // counter on the first lines Int_t counter2=0; // counter on the first lines // read the first lines Int_t dimX, dimY, dimZ; input_sim>>dimX>>dimY>>dimZ; if(gVerbose>0) cout<<"\nSimulated Field Table dimensions X : "<<dimX<<" Y : "<<dimY<<" Z : "<<dimZ<<endl; dimX=dimX+10; dimY=dimY+10; dimZ=dimZ+10; TH3D *f3DHistBx = new TH3D("f3DHistBX", "Bx" , dimX,-dimX, dimX, dimY,-dimY, dimY, dimZ, -dimZ, dimZ); TH3D *f3DHistBy = new TH3D("f3DHistBY", "By" , dimX,-dimX, dimX, dimY,-dimY, dimY, dimZ, -dimZ, dimZ); TH3D *f3DHistBz = new TH3D("f3DHistBZ", "Bz" , dimX,-dimX, dimX, dimY,-dimY, dimY, dimZ, -dimZ, dimZ); TH3D *f3DHistBmag = new TH3D("f3DHistBMAG", "Bmag" , dimX,-dimX, dimX, dimY,-dimY, dimY, dimZ, -dimZ, dimZ); TH3D *f3DHistBtan = new TH3D("f3DHistBTAN", "Btan" , dimX,-dimX, dimX, dimY,-dimY, dimY, dimZ, -dimZ, dimZ); TH3D *f3DHistBdiff = new TH3D("f3DHistBDIFF", "Bdiff", dimX,-dimX, dimX, dimY,-dimY, dimY, dimZ, -dimZ, dimZ); d_buffer=-1; while (d_buffer != 0 && counter1< 15){ // find a solution for this with do while input_sim>>d_buffer>>s_buffer; counter2++; } getline(input_sim,s_buffer); if(gVerbose>0) cout<< " Number of skipped lines in comsol file : " <<counter2 << " last line content : "<<s_buffer<<endl; // read and fill SimulationPoint* SimPoint = new SimulationPoint(); Double_t X(0), Y(0), Z(0), EX(-100), EY(-100), EZ(-100), Perm(0); Double_t BX(0), BY(0), BZ(0); Int_t line=0; while ( !input_sim.eof() ) { //Clear parameters SimPoint->ClearParameters(); // Choose format if(counter2<9) input_sim >> X >> Y >> Z >> BX >> BY >> BZ >> Perm ; else input_sim >> X >> Y >> Z >> BX >> BY >> BZ >> EX >> EY >> EZ >> Perm ; SimPoint->ReadLineAndTreat(X,Y,Z,BX,BY,BZ,EX,EY,EZ,Perm ); //SimPoint->Show(); // fill in TH3D all the simulation data Int_t binNumber = f3DHistBx->FindBin(X,Y,Z); f3DHistBx->SetBinContent(binNumber,BX); f3DHistBy->SetBinContent(binNumber,BY); f3DHistBz->SetBinContent(binNumber,BZ); f3DHistBmag->SetBinContent(binNumber,SimPoint->fBFieldMag); f3DHistBtan->SetBinContent(binNumber,SimPoint->fBFieldTan); f3DHistBdiff->SetBinContent(binNumber,SimPoint->fBFieldDiff); //fBFieldMag-fBFieldTan //count the lines for inspection line++; if (line%5000 == 0) { if(gVerbose>0) printf("\r @line : %d ... Still reading ...",line); if(gVerbose>1) cout<< X<<" "<<Y <<" "<<Z <<" "<<BX <<" "<<BY<<" "<<BZ <<" "<< EX<<" "<< EY<<" "<< EZ<<" "<< Perm<<endl ; } }