コード例 #1
0
ファイル: MazePlugin.cpp プロジェクト: sverch/mipscope
/*
 * Returns the accessible neighbors of the room identified by start (accessible meaning there's no wall in the way).
 * Fills buf[0]..buf[3] with the four room IDs for accessible rooms north, west, south, and east respectively. Stores 
 * the value zero in a location if there is no room there or if it is inaccessible from the start room.
 * 
 */ 
void MazePlugin::get_neighbors(State *s, int start, int* buf){
   point curr = cellLoc(start);
   if(getenv("MAZE_DEBUG"))
      cerr << "MAZE_DEBUG: call get_neighbors(" << curr << ", <buf>)" << endl;
   
   if (m_maze == NULL)
      maze_error(s, "MAZE: call to get_neighbors on uninitialized maze");

   point northRoom = m_maze->roomAt(curr,NORTH);
   buf[0] = northRoom.x == -1 ? 0 : cellID(northRoom);
   point westRoom = m_maze->roomAt(curr,WEST);
   buf[1] =  westRoom.x == -1 ? 0 : cellID(westRoom);
   point southRoom = m_maze->roomAt(curr,SOUTH);
   buf[2] = southRoom.x == -1 ? 0 : cellID(southRoom);
   point eastRoom = m_maze->roomAt(curr,EAST);
   buf[3] = eastRoom.x == -1 ? 0 : cellID(eastRoom);

   if(getenv("MAZE_DEBUG"))
      cerr << "MAZE_DEBUG: get_neighbors -> {" 
         << northRoom << ", " 
         << westRoom  << ", "
         << southRoom << ", "
         << eastRoom  << ")" 
         << endl;
}
コード例 #2
0
    /// Method for generating hit(s) using the information of G4Step object.
    template <> bool Geant4SensitiveAction<CalorimeterWithPreShowerLayer>::process(G4Step* step,G4TouchableHistory*) {
      typedef CalorimeterWithPreShowerLayer::Hit Hit;
      Geant4StepHandler h(step);
      HitContribution contrib = Hit::extractContribution(step);

      long long int cell;
      try {
        cell = cellID(step);
      } catch(std::runtime_error &e) {
        std::stringstream out;
        out << std::setprecision(20) << std::scientific;
        out << "ERROR: " << e.what()  << std::endl;
        out << "Position: "
            << "Pre (" << std::setw(24) << step->GetPreStepPoint()->GetPosition() << ") "
            << "Post (" << std::setw(24) << step->GetPostStepPoint()->GetPosition() << ") "
            << std::endl;
        out << "Momentum: "
            << " Pre (" <<std::setw(24) << step->GetPreStepPoint() ->GetMomentum()  << ") "
            << " Post (" <<std::setw(24) << step->GetPostStepPoint()->GetMomentum() << ") "
            << std::endl;

        std::cout << out.str();

        return true;
      }

      // get the layer number by decoding the cellID
      IDDescriptor idspec = m_sensitive.readout().idSpec() ;
      const DDSegmentation::BitFieldCoder& bc = *idspec.decoder() ;
      int layer = bc.get(cell, "layer") ;
      
      Geant4HitCollection*  coll = ( layer== m_userData._firstLayerNumber ?  collection( m_userData._preShowerCollectionID ) : collection(m_collectionID) ) ;
      
      Hit* hit = coll->find<Hit>(CellIDCompare<Hit>(cell));
      if ( h.totalEnergy() < std::numeric_limits<double>::epsilon() )  {
        return true;
      }
      else if ( !hit ) {
        Geant4TouchableHandler handler(step);
        DDSegmentation::Vector3D pos = m_segmentation.position(cell);
        Position global = h.localToGlobal(pos);
        hit = new Hit(global);
        hit->cellID = cell;
        coll->add(hit);
        printM2("%s> CREATE hit with deposit:%e MeV  Pos:%8.2f %8.2f %8.2f  %s",
                c_name(),contrib.deposit,pos.X,pos.Y,pos.Z,handler.path().c_str());
        if ( 0 == hit->cellID )  { // for debugging only!
          hit->cellID = cellID(step);
          except("+++ Invalid CELL ID for hit!");
        }
      }
      hit->truth.push_back(contrib);
      hit->energyDeposit += contrib.deposit;
      mark(step);
      return true;
    }
コード例 #3
0
ファイル: MazePlugin.cpp プロジェクト: sverch/mipscope
/*
 * spawns the maze GUI in a separate process/thread. waits for it to initialize, then requests the starting room and returns it
 */ 
int MazePlugin::init_maze(State *s) {
   if(getenv("MAZE_DEBUG"))
      cerr << "MAZE_DEBUG: call init_maze()" << endl;

   if (m_maze != NULL)
      maze_error(s, "Attempted to initialize Maze twice");
   
	
	//TODO add text-only option here
   if (m_textOnly) {
		m_maze = new MazeTui(this);
	}
	else {
		m_maze = new MazeGui((Gui*) m_ui, this);
	}
//   QEventLoop *eventLoop = new QEventLoop();
//   eventLoop->exec();

   if (!m_maze->initializeMaze())
      return false;

   point src = m_maze->getMazeSource();

   if(getenv("MAZE_DEBUG"))
      cerr << "MAZE_DEBUG init_maze() -> " << src << endl;

   return cellID(src);
}
コード例 #4
0
ファイル: main.cpp プロジェクト: JulianDomingo/EE312
/*
 * this function makes a random maze with exactly one path between
 * any two points in the maze
 *
 * If you're curious about the algorithm, come talk to me.  It's not very
 * complicated (although the code might be confusing)
 */
void makeMaze() {
	int num_visited = 1;
	int first;
	int finish_col;
	makeAllWalls();
	markCell(0, 0);  // mark the first cell as visited
	
	/* add the first cell (row 0, col 0) to the linked list of visited cells */
	first = cellID(0, 0);
	annotateCell(0, 0, 0);
	
	while(num_visited < MAZE_SIZE * MAZE_SIZE) {
		int visit = rand() % num_visited;
		int cell = first; 
		int row, col;
		int d;
		int nrow, ncol;

		findCell(cell, &row, &col);
		while (visit > 0) {
			cell = annotation(row, col);
			findCell(cell, &row, &col);
			visit -= 1;
		}
		d = rand() % 4;
		nrow = row; // row of neighbor cell
		ncol = col; // col of neighbor cell
		interpretDir(&nrow, &ncol, d);
		if (nrow >= 0 && nrow < MAZE_SIZE
			&& ncol >= 0 && ncol < MAZE_SIZE
			&& !isMarked(nrow, ncol)) {
			clearWall(row, col, d);
			num_visited += 1;
			markCell(nrow, ncol);
			annotateCell(nrow, ncol, first);
			first = cellID(nrow, ncol);	
		}
	}
	
	start_col = rand() % MAZE_SIZE;
	start_col = 2 * start_col + 1;
	maze[0][start_col] &= ~WALL;
	finish_col = rand() % MAZE_SIZE;
	maze[MATRIX_SIZE - 1][2 * finish_col + 1] &= ~WALL;
	//maze[MATRIX_SIZE - 1][0] &= ~WALL;
}
コード例 #5
0
bool GflashCalorimeterSD::ProcessHits(G4GFlashSpot* aSpot, G4TouchableHistory*) {
  // This method will be called if gflash parametrisation is performed
  G4double edep = aSpot->GetEnergySpot()->GetEnergy();
  // check if energy was deposited
  if (edep == 0.) return false;
  CLHEP::Hep3Vector geantPos = aSpot->GetEnergySpot()->GetPosition();
  dd4hep::Position pos(geantPos.x(), geantPos.y(), geantPos.z());
  // create a new hit
  // deleted in ~G4Event
  dd4hep::sim::Geant4CalorimeterHit* hit = new dd4hep::sim::Geant4CalorimeterHit(pos);
  hit->cellID = cellID(*aSpot);
  hit->energyDeposit = edep;
  m_calorimeterCollection->insert(hit);
  return true;
}
コード例 #6
0
ファイル: MazePlugin.cpp プロジェクト: sverch/mipscope
/*
 * instructs the GUI to draw the path from the previous (parent) node to this one. Pathsoare never erased
 */ 
void MazePlugin::draw_arrow(State *s, int status, int room, int parentRoom) {
   point roomP = cellLoc(room);
   point parentRoomP = cellLoc(parentRoom);
   if(getenv("MAZE_DEBUG"))
      cerr << "MAZE_DEBUG: call draw_arrow(" << roomP << ", " << parentRoomP << ")" << endl;
   
   if (m_maze == NULL)
      maze_error(s, "MAZE: call to draw_arrow on uninitialized maze");
   
   /*printPoint(&parentRoomP);
   cerr << " -> ";
   printPoint(&roomP);
   cerr << endl;*/

   m_searchStack.push(cellID(m_maze->getCurrCellLoc()));//parentRoom);

   m_maze->moveCurrent(roomP);

   if(getenv("MAZE_DEBUG"))
      cerr << "MAZE_DEBUG: draw_arrow() -> void" << endl;
   if(getenv("MAZE_SLOW") && status == RUNNING) {
      
		// Loop 1000 times, sleeping for 1000 milliseconds each time,
		// for a net sleep of 1 second.
		// Use system call usleep so we don't need to create our own QThread.
		// Use multiple sleeps so that the GUI still responds while sleeping.
		// (If we used a single sleep of 1 second, the GUI would lock up.)
		for (int i=0; i < 1000; i++) {
#ifdef Q_OS_WIN32
			Sleep(1);
#else
			usleep(1000);
#endif

		}
   }
}
コード例 #7
0
ファイル: MazePlugin.cpp プロジェクト: sverch/mipscope
static ostream& operator<< (ostream& s, const point& pt) {
   return s << cellID(pt) << " [room " << pt.x << "," << pt.y << "]";
}
コード例 #8
0
bool LeafClientHandler::rebindMesh() {
    ACE_GUARD_RETURN(ACE_SYNCH_RECURSIVE_MUTEX, ace_mon, m_lock, false);
    SthenoPacket *packet = 0;
    if (m_debugLeafClientHandler) {
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: LeafClientHandler:rebindMesh(): Peer(%s,%s\n"),
                m_uuid.get()->toString().c_str(),
                m_cellID->toString().c_str()));
    }

    UUIDPtr cellID(new CellID(m_cellID.get()));
    UUIDPtr dstCellID(new CellID(m_cellID.get()));
    int type = P3PeerInfo::SENSOR;
    
    ACE_Message_Block* mb = 0;
    EndpointPtr nullPoint;
    SAPInfoPtr discoverySAP;
    SAPInfoPtr meshSAP;
    SAPInfoPtr ftSAP;
    UUIDPtr runtimeUUID;
    m_mesh->getUUID(runtimeUUID);
    UUIDPtr fid;
    m_mesh->getFID(fid);
    packet = new RebindMeshPacket(runtimeUUID,
            cellID,
            //m_cell->getCellID(),
            m_uuid,
            dstCellID,
            0,
            type,
            m_uuid,
            m_cellID,
            m_cellID,
            nullPoint,
            nullPoint,
            discoverySAP,
            meshSAP,
            ftSAP,
            mb);
    RequestEngine<SthenoPacket*>::RequestPtr* request = sendRequest(packet, 0);
    delete packet;
    if (request == 0) {
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)ERROR: LeafClientHandler:rebindMesh() - Request failed\n")));
        return 0;
    }
    ACE_Time_Value timeout = ACE_OS::gettimeofday();
    ACE_Time_Value delta;
    delta.msec(JOIN_CELL_TIMEOUT_MS);
    timeout += delta;
    list<SthenoPacket*>* results = request->get()->waitFuture(0);
    ACE_DEBUG((LM_DEBUG,ACE_TEXT("(%t|%T) LeafClientHandler:rebindMesh() After future\n")));
    //ACE_DEBUG((LM_DEBUG,ACE_TEXT("(%t|%T)After future\n");
    if (results != 0 && results->size() > 0) {
        RebindMeshReplyPacket* replyPacket = static_cast<RebindMeshReplyPacket*> (results->front());
        bool status = replyPacket->getJoinResult();
        ListHelper<SthenoPacket*>::deleteList(results);
        if (m_debugLeafClientHandler) {
            ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: LeafClientHandler::rebindMesh() - Rebind (%d)\n"), status));
        }
        return status;
    } else {
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)ERROR: LeafClientHandler::rebindMesh() - No response\n")));
    }

    return false;

}
コード例 #9
0
ファイル: dragForce.C プロジェクト: aliozel/coarseningFoam
	void EulerianParticleVelocityForce
	(
		cfdemCloud& sm,			
		const fvMesh& mesh,
		volVectorField& Uf_,
		volVectorField&	Up_,
		volScalarField& rho_,
		volScalarField& alpf_,
		volScalarField& Pg_,
		volVectorField& MappedDragForce_,
		const labelListList& particleList_,
		const bool& weighting_
	)
	{		
		// Neighbouring cells
		CPCCellToCellStencil neighbourCells(mesh);
				
		// get viscosity field
		#ifdef comp
		    const volScalarField nufField = sm.turbulence().mu()/rho_;
		#else
		    const volScalarField& nufField = sm.turbulence().nu();
		#endif

		// Gas pressure gradient
		volVectorField gradPg_ = fvc::grad(Pg_);
		interpolationCellPoint<vector> gradPgInterpolator_(gradPg_);

		// Local variables	
		label  cellID(-1);
		vector drag(0,0,0);
		vector Ufluid(0,0,0);
		
		vector position(0,0,0);
		scalar voidfraction(1);
		
		vector Up(0,0,0);
		vector Ur(0,0,0);
		scalar ds(0);
		
		scalar nuf(0);
		scalar rhof(0);
		
		vector WenYuDrag(0,0,0);
		
		interpolationCellPoint<scalar> voidfractionInterpolator_(alpf_);
		interpolationCellPoint<vector> UInterpolator_(Uf_);	
		
		scalar dist_s(0);
		scalar sumWeights(0);
		
		scalarField               weightScalar(27,scalar(0.0));
		Field <Field <scalar> >   particleWeights(particleList_.size(),weightScalar);
		
		//Info << " particle size " << particleList_.size() << endl;
		
		// Number of particle in a cell
		scalarField np(mesh.cells().size(),scalar(0));
		
		// Particle volume
		scalar Volp(0);
		vector gradPg_int(0,0,0);
		
		for(int ii = 0; ii < particleList_.size(); ii++)
		{
			int index = particleList_[ii][0];
			
			cellID = sm.cellIDs()[index][0];
			position = sm.position(index);			    

                        Ufluid = UInterpolator_.interpolate(position,cellID); 
			Up = sm.velocity(index);
                        Ur = Ufluid-Up;

                        ds = 2*sm.radius(index);

                        // Calculate WenYu Drag 
                        voidfraction = voidfractionInterpolator_.interpolate(position,cellID);
                        nuf = nufField[cellID];
                        rhof = rho_[cellID];	
                        WenYuDragForce(Ur,ds,rhof,nuf,voidfraction,WenYuDrag);	
    
        		Volp = ds*ds*ds*M_PI/6;
			gradPg_int = gradPgInterpolator_.interpolate(position,cellID);
			
			//if (cellID > -1)  // particle centre is in domain
            		//{
				if(weighting_)
				{
					labelList& cellsNeigh = neighbourCells[cellID];
					sumWeights = 0;
					dist_s = 0;

					//Info << " index = " << index << " ii = " << ii << " cellID = " << cellID << endl;

					forAll(cellsNeigh,jj)
					{
						// Find distances between particle and neighbouring cells					
						dist_s = mag(sm.mesh().C()[cellsNeigh[jj]]-position)/pow(sm.mesh().V()[cellsNeigh[jj]],1./3.);

						if(dist_s <= 0.5)
						{		
							particleWeights[ii][jj] =  1./4.*pow(dist_s,4)-5./8.*pow(dist_s,2)+115./192.;
						}
						else if (dist_s > 0.5 && dist_s <= 1.5)
						{		
							particleWeights[ii][jj] = -1./6.*pow(dist_s,4)+5./6.*pow(dist_s,3)-5./4.*pow(dist_s,2)+5./24.*dist_s+55./96.;
						}
						else if (dist_s > 1.5 && dist_s <= 2.5)
						{		
							particleWeights[ii][jj] =  pow(2.5-dist_s,4)/24.;
						}
						else
						{		
							particleWeights[ii][jj] = 0;
						}

						sumWeights += particleWeights[ii][jj];

					}	

					forAll(cellsNeigh,jj)
					{	
						if ( sumWeights != 0 )
						{
							Up_[cellID] 	         +=  Up*particleWeights[ii][jj]/sumWeights;
							MappedDragForce_[cellID] += (WenYuDrag + Volp * gradPg_int) * particleWeights[ii][jj]/sumWeights;
						}
						else
						{
							Up_[cellID] 		 = vector(0,0,0);
							MappedDragForce_[cellID] = vector(0,0,0);	
						}
					}
				}
				else
				{
コード例 #10
0
ファイル: wfxListCtrl.cpp プロジェクト: wxtnote/wfc
void ListCtrl::onDraw( HDC hdc, const Rect& rcPaint )
{
	Rect rc = getRect();
	if (!verify())
	{
		WfxRender::drawFrame(hdc, rc, WBTN_BKGND_MOUSE, getDispatcher());
		return;
	}
	LCDrawItemInfo* pDrawItemInfo = getDrawItemInfo();
	pDrawItemInfo->clear();
	pDrawItemInfo->m_hDC = hdc;
	Rect rcCell;
	DWORD dwState = WCS_NORMAL;
	ULONG nLayer = 0;
	BOOL bRowexpanded = FALSE;
	COLORREF clrText = 0;
	LONG nLayerOffset = 0;
	LONG nTotalRow = getTotalRows();
	LONG nTotalCol = getTotalColumns();
	ULONG nSeqBarWidth = getRowNumBarWidth();
	ObjectAdapterBase* pOjbect = NULL;
	for (LONG nRow = m_nStartRow, nRowNum = 0; nRow <= m_nEndRow; nRow++, nRowNum++)
	{
		pDrawItemInfo->m_nRow = nRow;
		WFX_CONDITION(m_rgRowNumRect.size() > nRowNum);
		pDrawItemInfo->m_prcItem = &m_rgRowNumRect[nRowNum];
		pDrawItemInfo->m_dwState = 0;
		onDrawSeqBar(pDrawItemInfo);
		nLayer = getLayer(nRow);
		nLayerOffset = (nLayer - 1) * 30;
		clrText = getColor(nLayer);
		if (m_bHasSubItem)
		{
			bRowexpanded = isExpanded(nRow);
		}
		pOjbect = m_pArrayAdapter->getAt(nRow);
		WFX_CONDITION(pOjbect != NULL);

		for (LONG nCol = m_nStartCol; nCol <= m_nEndCol; nCol++)
		{
			WFX_CONDITION(nCol < pOjbect->getCount());
			AttributeBase* pAttribute = pOjbect->getAt(nCol);
			WFX_CONDITION(pAttribute != NULL);

			CellID cellID(nRow, nCol);
			dwState = WCS_NORMAL;
			if (m_bHasSubItem && nCol == 0)
			{
				if (bRowexpanded)
				{
					dwState |= WCS_EXPAND;
				}
				else
				{
					dwState |= WCS_CLOSE;
				}
			}
			if (m_cellSelected == cellID)
			{
				dwState |= WCS_SELECTED;
			}
			if (m_cellMouseMove == cellID)
			{
				dwState |= WCS_MOUSEMOVE;
			}
			rcCell = getCellRect(nRow, nCol);
			rcCell.left += nLayerOffset;
			pDrawItemInfo->m_nCol = nCol;
			pDrawItemInfo->m_prcItem = &rcCell;
			pDrawItemInfo->m_dwState = dwState;
			pDrawItemInfo->m_pszText = pAttribute->getText().c_str();
			pDrawItemInfo->m_dwFormat = pAttribute->getFormat();
			onDrawItem(pDrawItemInfo);
		}
	}
	WfxRender::drawFrame(hdc, rc, WBTN_BKGND_MOUSE, getDispatcher());
}