void updatePMLHFieldUtilHz(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 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); bzStore = BZ(p); mu = MUR(m)*MUNOT; 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 updatePMLHFieldUtilHz
static inline void calcH(void) { //todo mu = mu0? for(int i=1; i<N_PX-1; i++) for(int j=1; j<N_PY-1; j++) Hz[ind(i,j)] = BZ(i,j)/MU_0_S; }
static inline void calcH(void) { int i,j; for(i=1; i<N_PX-1; i++) for(j=1; j<N_PY-1; j++) Hz[ind(i,j)] = BZ(i,j)/MU_0_S; }
static inline void calcMB(void) { for(int i=1; i<N_PX-1; i++){ for(int j=1; j<N_PY-1; j++){ double complex nowMz = MZ(i,j); Mz[ind(i,j)] = CMZ(i,j)*MZ(i,j) - CMZEXEY(i,j)*(EY(i+1,j) - EY(i,j) - EX(i,j+1) + EX(i,j)); Bz[ind(i,j)] = CBZ(i,j)*BZ(i,j) + CBZMZ1(i,j)*MZ(i,j) - CBZMZ0(i,j)*nowMz; } } }
void SMACOF::run( const Matrix<double>& Weights, const Matrix<double>& Distances, const double& tol, const unsigned& maxloops, Matrix<double>& InitialZ ) { unsigned M = Distances.nrows(); // Calculate V Matrix<double> V(M,M); double totalWeight=0.; for(unsigned i=0; i<M; ++i) { for(unsigned j=0; j<M; ++j) { if(i==j) continue; V(i,j)=-Weights(i,j); if( j<i ) totalWeight+=Weights(i,j); } for(unsigned j=0; j<M; ++j) { if(i==j)continue; V(i,i)-=V(i,j); } } // And pseudo invert V Matrix<double> mypseudo(M, M); pseudoInvert(V, mypseudo); Matrix<double> dists( M, M ); double myfirstsig = calculateSigma( Weights, Distances, InitialZ, dists ) / totalWeight; // initial sigma is made up of the original distances minus the distances between the projections all squared. Matrix<double> temp( M, M ), BZ( M, M ), newZ( M, InitialZ.ncols() ); for(unsigned n=0; n<maxloops; ++n) { if(n==maxloops-1) plumed_merror("ran out of steps in SMACOF algorithm"); // Recompute BZ matrix for(unsigned i=0; i<M; ++i) { for(unsigned j=0; j<M; ++j) { if(i==j) continue; //skips over the diagonal elements if( dists(i,j)>0 ) BZ(i,j) = -Weights(i,j)*Distances(i,j) / dists(i,j); else BZ(i,j)=0.; } //the diagonal elements are -off diagonal elements BZ(i,i)-=BZ(i,j) (Equation 8.25) BZ(i,i)=0; //create the space memory for the diagonal elements which are scalars for(unsigned j=0; j<M; ++j) { if(i==j) continue; BZ(i,i)-=BZ(i,j); } } mult( mypseudo, BZ, temp); mult(temp, InitialZ, newZ); //Compute new sigma double newsig = calculateSigma( Weights, Distances, newZ, dists ) / totalWeight; //Computing whether the algorithm has converged (has the mass of the potato changed //when we put it back in the oven!) if( fabs( newsig - myfirstsig )<tol ) break; myfirstsig=newsig; InitialZ = newZ; } }
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 ; } }