Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
//calculate H
static inline void calcH()
{
  //todo mu = mu0 ?  
  for(int i=1; i<N_PX-1; i++){
    for(int j=1; j<N_PY-1; j++){      
      Hx[ind(i,j)] = BX(i,j)/MU_0_S;  
    }
  }
  
  for(int i=1; i<N_PX-1; i++){
    for(int j=1; j<N_PY-1; j++){
      Hy[ind(i,j)] = BY(i,j)/MU_0_S;
    }
  }
}
Ejemplo n.º 3
0
	TESTCASE() {

		MAX_WAIT_TIME(3*USECSPERSEC);

		for (int i = 0; i < NUM_THREADS; i++)
		{
			CREATE_THREAD(i+1, increment_routine, (void*)counter);
		}

		//-----------------------------------------

		printf("counter->x: %lx\n", &counter->x);
		printf("counter->lock: %lx\n", &counter->mutex);

		EXISTS(t1, PTRUE, "Select thread t1");
		EXISTS(t2, NOT(t1), "Select thread t2");
//
		RUN_UNTIL(BY(t1), ENDS(), __, "Reads from x");
//
//		RUN_UNTIL(NOT_BY(t1), WRITES(&counter->x, t2), __, "Writes to x");
//
//		RUN_UNTIL(PTRUE, ENDS(t1), __, "Ends...");


//		WHILE_STAR
//		{
//			FORALL(t, (TID == t1 || TID == t2), "Select thread t");
//			RUN_UNTIL(BY(t), ENDS(), __, "Run until ends");
//		}



//			FORALL(t, PTRUE, "Select thread t");
//			RUN_UNTIL(BY(t), ENDS(), __, "Run until ends");



//			FORALL(t, PTRUE, "Select thread t");
//			RUN_UNTIL(BY(t), PTRUE, __, "Run until ends");
//		}

	}
Ejemplo n.º 4
0
//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;
    }
  }
}
Ejemplo n.º 5
0
cv::Mat_<int> cModel::__lbf_fast(const cv::Mat_<uchar>&img, const cv::Rect& bbox, const cv::Mat_<float>& shape,int markID, int stage)
{
	int max_stage = m_Model.__head.__num_stage;
	int num_node = m_Model.__head.__num_leaf + m_Model.__head.__num_node;
	int num_point = m_Model.__head.__num_point;
	int num_tree_per_point = m_Model.__head.__num_tree_per_point;
	int num_leaf = m_Model.__head.__num_leaf;
	
	m_AX[stage].row(markID) *= bbox.width;
	m_AY[stage].row(markID) *= bbox.height;
	m_BX[stage].row(markID) *= bbox.width;
	m_BY[stage].row(markID) *= bbox.height;	

	m_AX[stage].row(markID) += shape(markID, 0);
	m_AY[stage].row(markID) += shape(markID, 1);
	m_BX[stage].row(markID) += shape(markID, 0);
	m_BY[stage].row(markID) += shape(markID, 1);

	cv::Mat_<int> cind = cv::Mat::ones(m_AX[stage].cols, 1, CV_32SC1);
	cv::Mat_<float> AX = m_AX[stage].row(markID);
	cv::Mat_<float> AY = m_AY[stage].row(markID);
	cv::Mat_<float> BX = m_BX[stage].row(markID);
	cv::Mat_<float> BY = m_BY[stage].row(markID);
	cv::Mat_<float> Thresh = m_Thresh[stage].row(markID);	
	

	int width =  img.cols;
	int height = img.rows;	
	
	for (int j = 0; j < AX.cols; j += num_node){
		for (int index = 0; index < m_Model.__head.__num_node; index++){
			int pos = j + index;
			int a_x = (int)(AX(0, pos) + 0.5);
			int a_y = (int)(AY(0, pos) + 0.5);
			int b_x = (int)(BX(0, pos) + 0.5);
			int b_y = (int)(BY(0, pos) + 0.5);

			a_x = MAX(0, MIN(a_x, width - 1));
			a_y = MAX(0, MIN(a_y, height - 1));
			b_x = MAX(0, MIN(b_x, width - 1));
			b_y = MAX(0, MIN(b_y, height - 1));

			float pixel_v_a = (float)img(cv::Point(a_x, a_y));
			float pixel_v_b = (float)img(cv::Point(b_x, b_y));
			float val = pixel_v_a - pixel_v_b;
			
			if (val < (float)Thresh(0, pos)){
				cind(pos, 0) = 0;
			}
		}		
	}

	cv::Mat_<int> binfeature = cv::Mat::zeros(1, (int)cv::sum(m_Isleaf).val[0], CV_32SC1);

	int cumnum_nodes = 0;
	int cumnum_leafnodes = 0;

	for (int t = 0; t < num_tree_per_point; t++){		
		int id_cnode = 0;
		while (1){
			if (m_Isleaf(id_cnode + cumnum_nodes)){
				binfeature(0, cumnum_leafnodes + __getindex(m_Idleafnodes, id_cnode)) = 1;
				cumnum_nodes = cumnum_nodes + num_node;
				cumnum_leafnodes = cumnum_leafnodes + num_leaf;
				break;
			}
			id_cnode = m_Cnodes(cumnum_nodes + id_cnode, cind(cumnum_nodes + id_cnode, 0));
		}
	}
	return binfeature;	
}
Ejemplo n.º 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 ;
	   }
}  
Ejemplo n.º 7
0
TESTCASE() {

    ThreadVarPtr t_ip1 = CREATE_THREAD(insertpair_routine1, (void*)&multiset);
    ThreadVarPtr t_ip2 = CREATE_THREAD(insertpair_routine2, (void*)&multiset);
    ThreadVarPtr t_ip3 = CREATE_THREAD(insertpair_routine3, (void*)&multiset);

    ThreadVarPtr t_lu1 = CREATE_THREAD(lookup_routine1, (void*)&multiset);
    ThreadVarPtr t_lu2 = CREATE_THREAD(lookup_routine2, (void*)&multiset);
    ThreadVarPtr t_lu3 = CREATE_THREAD(lookup_routine3, (void*)&multiset);

    printf("=============================================\n"
           "=============================================\n");

    //----------------------------------------------------------------------------------
    //----------------------------------------------------------------------------------

    FORALL(t1, BY(t_ip1) || BY(t_ip2) || BY(t_ip3));
    RUN_UNTIL(BY(t1), ENDS(), __);

    FORALL(t2, (BY(t_ip1) || BY(t_ip2) || BY(t_ip3)) && NOT(t1));
    RUN_UNTIL(BY(t2), ENDS(), __);

    FORALL(t3, (BY(t_ip1) || BY(t_ip2) || BY(t_ip3)) && NOT(t1) && NOT(t2));
    RUN_UNTIL(BY(t3), ENDS(), __);

    RUN_UNTIL(BY(t_lu2), ENDS(), __);
    RUN_UNTIL(BY(t_lu1), ENDS(), __);
    RUN_UNTIL(BY(t_lu3), ENDS(), __);

    WHILE_STAR
    {
        EXISTS(t);
        RUN_UNTIL(PTRUE && !FINAL(), FINAL(t))

    }
    RUN_UNTIL(PTRUE, FINAL())
}