예제 #1
0
void updatePMLEFieldUtilEy(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 dyStore;
	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);
		dyStore = DY(p);					
	
		m = MATERIALINDEX(i,j,k);
		eps = EPSR(m)*EPSNOT;
				
		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; 

	}}} // end for

}// end updatePMLEFieldUtilEy
예제 #2
0
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
예제 #3
0
파일: fdtdTE_upml.c 프로젝트: rennone/C
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; 
    }
  }
}
// variant: means by /nrow rather than /npairs when dealing with missing data
// deviates from R's pairwise.complete.obs, but highly similar.
// good results in context of particular biological validations,
// but formal correctness undetermined
void
pearson_distances_pairwise_complete_obs_variant(
	double * const d,
	const double * const matrix,
	int const nrow,
	int const ncol
){
	std::ptrdiff_t p(0);
	t_float EX(0), EY(0), EXX(0), EYY(0), EXY(0), x(0), y(0);
	for(int col1(0), end(ncol); col1<(end-1); ++col1){
		for(int col2(col1+1); col2<end; ++col2){
			// Pearson correlation distance
			EX=0, EY=0, EXX=0, EYY=0, EXY=0, x=0, y=0;
			unsigned npairs(0);
			for(int row(0); row<nrow; ++row){
				// R indexes its arrays BY COLUMN
				x = matrix[col1*nrow+row];
				y = matrix[col2*nrow+row];
				if(ISNA(x) || ISNA(y)) continue;
				++npairs;
				EX += x;
				EY += y;
				EXX += x*x;
				EYY += y*y;
				EXY += x*y;
			}
			if(npairs<1) d[p++] = 2.0;
			else d[p++] = 1.0 - (EXY - EX*EY/nrow) / sqrt( (EXX - EX*EX/nrow)*(EYY - EY*EY/nrow) );
		}
	}
}
예제 #5
0
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
예제 #6
0
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 ;
	   }
}  
예제 #7
0
파일: fdtdTE_upml.c 프로젝트: rennone/FDTD
static void ntff(void)
{
  const double C = LIGHT_SPEED_S;  
  const int cx = N_PX/2; //a center of field is origin
  const int cy = N_PY/2;  
  const int offset = 5;		// closed line offset
  const int tp = N_PY - N_PML - offset;	//上から-5
  const int bm = N_PML + offset;	//下から5
  const int rt = N_PX - N_PML - offset;	//右から-5
  const int lt = N_PML + offset;	//左から5
  const int len = tp-bm+1; //length
  const double RFperC = len*2;  //C = 1/√2,Rf=len*√2 => Rf/C = len*2  
  const double coef = 1.0/(4*M_PI*C);
  
  int m_e, m_h;
  double timeE = field_getTime() - 1;  //t - Δt  todo
  double timeH = field_getTime() - 0.5;  //t - Δt/2  todo
  double a_e, b_e, ab_e, a_h, b_h, ab_h;

  int ang;
  int i, j;
  for(ang=0; ang<360; ang++){
    double rad = ang*M_PI/180.0;
    double r1x = cos(rad), r1y = sin(rad);    
    //bottom side
    //normal vector n is (0,-1)
    //Js = n × H = (-Hz, 0, 0)  Ms = E × n = (0, 0, -Ex)

    for(i=lt; i<rt; i++){
      double r2x = i-cx+0.5, r2y = bm-cy;            //distance between origin to cell
      double timeShift = -(r1x*r2x + r1y*r2y)/C + RFperC;
      ntffCoef(timeE, timeShift, &m_e, &a_e, &b_e, &ab_e);
      ntffCoef(timeH, timeShift, &m_e, &a_e, &b_e, &ab_e);
      
      double complex ex = -EX(i,bm);
      double complex hz = -0.5*( HZ(i,bm) + HZ(i,bm-1) );
          
      Uz[ang][m_e-1] += ex*b_e*coef;
      Wx[ang][m_h-1] += hz*b_h*coef;
      Uz[ang][m_e]   += ex*ab_e*coef;
      Wx[ang][m_h]   += hz*ab_h*coef;
      Uz[ang][m_e+1] -= ex*a_e*coef;
      Wx[ang][m_h+1] -= hz*a_h*coef;      
    }

    //top side
    //normal vector n is (0,1)
    //Js = n × H = (Hz, 0, 0)  Ms = E × n = (0, 0, Ex)
    for(i=lt; i<rt; i++){
      double r2x = i-cx+0.5, r2y = tp-cy;
      double timeShift = -(r1x*r2x + r1y*r2y)/C + RFperC;      
      ntffCoef(timeE, timeShift, &m_e, &a_e, &b_e, &ab_e);
      ntffCoef(timeH, timeShift, &m_h, &a_h, &b_h, &ab_h);

      double complex ex = EX(i,bm);
      double complex hz = 0.5*( HZ(i,tp) + HZ(i,tp-1) );

      Uz[ang][m_e-1] += ex*b_e*coef;
      Wx[ang][m_h-1] += hz*b_h*coef;
      Uz[ang][m_e]   += ex*ab_e*coef;
      Wx[ang][m_h]   += hz*ab_h*coef;
      Uz[ang][m_e+1] -= ex*a_e*coef;
      Wx[ang][m_h+1] -= hz*a_h*coef;            
    }
    
    //left side
    //normal vector n is (-1,0)
    //Js = n × H = (0,Hz,0)    Ms = E × n = (0,0,Ey)
    for(j=bm; j<tp; j++){
      double r2x = lt-cx, r2y = j-cy+0.5;
      double timeShift = -(r1x*r2x + r1y*r2y)/C + RFperC;
      ntffCoef(timeE, timeShift, &m_e, &a_e, &b_e, &ab_e);
      ntffCoef(timeH, timeShift, &m_h, &a_h, &b_h, &ab_h);
      
      double complex ey = EY(lt,j);
      double complex hz = 0.5*( HZ(lt,j) + HZ(lt-1,j) );
      
      Uz[ang][m_e-1] += ey*b_e*coef;
      Wy[ang][m_h-1] += hz*b_h*coef;
      Uz[ang][m_e]   += ey*ab_e*coef;
      Wy[ang][m_h]   += hz*ab_h*coef;
      Uz[ang][m_e+1] -= ey*a_e*coef;
      Wy[ang][m_h+1] -= hz*a_h*coef;
    }

    //right side
    //normal vector n is (1,0)
    //Js = n × H = (0,-Hz,0)    Ms = E × n = (0,0,-Ey)    
    for(j=bm; j<tp; j++){
      double r2x = rt-cx, r2y = j-cy+0.5;
      double timeShift = -(r1x*r2x + r1y*r2y)/C + RFperC;
      ntffCoef(timeE, timeShift, &m_e, &a_e, &b_e, &ab_e);
      ntffCoef(timeH, timeShift, &m_h, &a_h, &b_h, &ab_h);

      double complex ey = -EY(lt,j);
      double complex hz = -0.5*( HZ(lt,j) + HZ(lt-1,j) );
      Uz[ang][m_e-1] += ey*b_e*coef;
      Wy[ang][m_h-1] += hz*b_h*coef;
      Uz[ang][m_e]   += ey*ab_e*coef;
      Wy[ang][m_h]   += hz*ab_h*coef;
      Uz[ang][m_e+1] -= ey*a_e*coef;
      Wy[ang][m_h+1] -= hz*a_h*coef;      
    }

  }
}