Example #1
0
/*
Calculate the number of cells on the maximum refinement level overlapping the list of dccrg cells in cells.
*/
int getNumberOfCellsOnMaxRefLvl(dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid, const std::vector<CellID>& cells) {

   int nCells = 0;
   auto maxRefLvl = mpiGrid.mapping.get_maximum_refinement_level();
   
   for (auto cellid : cells) {
      auto refLvl = mpiGrid.get_refinement_level(cellid);
      nCells += pow(pow(2,maxRefLvl-refLvl),3);
   }

   return nCells;
   
}
Example #2
0
std::vector<CellID> mapDccrgIdToFsGridGlobalID(dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
					       CellID dccrgID) {
   const auto maxRefLvl  = mpiGrid.get_maximum_refinement_level();
   const auto refLvl = mpiGrid.get_refinement_level(dccrgID);
   const auto cellLength = pow(2,maxRefLvl-refLvl);
   const auto topLeftIndices = mpiGrid.mapping.get_indices(dccrgID);
   std::array<int,3> fsgridDims;
   
   fsgridDims[0] = P::xcells_ini * pow(2,mpiGrid.get_maximum_refinement_level());
   fsgridDims[1] = P::ycells_ini * pow(2,mpiGrid.get_maximum_refinement_level());
   fsgridDims[2] = P::zcells_ini * pow(2,mpiGrid.get_maximum_refinement_level());

   std::vector<CellID> fsgridIDs(cellLength * cellLength * cellLength);
   for (uint k = 0; k < cellLength; ++k) {
      for (uint j = 0; j < cellLength; ++j) {
         for (uint i = 0; i < cellLength; ++i) {
	   const std::array<uint64_t,3> indices = {{topLeftIndices[0] + i,topLeftIndices[1] + j,topLeftIndices[2] + k}};
	   fsgridIDs[k*cellLength*cellLength + j*cellLength + i] = indices[0] + indices[1] * fsgridDims[0] + indices[2] * fsgridDims[1] * fsgridDims[0];
	 }
      }
   }
   return fsgridIDs;
}
Example #3
0
setOfPencils buildPencils( dccrg::Dccrg<grid_data> grid,
			   setOfPencils &pencils, vector<CellID> idsOut,
			   vector<CellID> idsIn, int dimension, 
			   vector<pair<bool,bool>> path) {

  // Not necessary since c++ passes a copy by default.
  // Copy the input ids to a working set of ids
  // vector<int> ids( idsIn );
  // Copy the already computed pencil to the output list
  // vector<int> idsOut( idsInPencil );
  
  uint i = 0;
  uint length = idsIn.size();
  
  // Walk along the input pencil. Initially length is equal to the length of the
  // Unrefined pencil. When refined cells are encountered, the length is increased
  // accordingly to go through the entire pencil.
  while (i < length) {

    uint i1 = i + 1;
    uint id = idsIn[i];

    vector<CellID> children = grid.get_all_children(id);
    bool hasChildren = ( grid.get_parent(children[0]) == id );
    
    // Check if the current cell contains refined cells
    if (hasChildren) {
      
      // Check if we have encountered this refinement level before and stored
      // the path this builder followed
      if (path.size() > grid.get_refinement_level(id)) {

	// Get children using the stored path	
	vector<CellID> myChildren = getMyChildren(children,dimension,
						  path[grid.get_refinement_level(id)].first,
						  path[grid.get_refinement_level(id)].second);
	
	// Add the children to the working set at index i1

	insertVectorIntoVector(idsIn,myChildren,i1);
	length += myChildren.size();	
      
      } else {

	// Spawn new builders to construct pencils at the new refinement level
	
	for (bool left : { true, false }) {	
	  for (bool up : { true, false }) {
	    
	    // Store the path this builder has chosen
	    vector < pair <bool,bool>> myPath = path;
	    myPath.push_back(pair<bool, bool>(up,left));
	    
	    // Get children along my path.
	    vector<CellID> myChildren = getMyChildren(children,dimension,up,left);
	    // Get the ids that have not been processed yet.
	    vector<CellID> remainingIds(idsIn.begin() + i1, idsIn.end());
	    
	    // The current builder continues along the bottom-right path.
	    // Other paths will spawn a new builder.
	    if (!up && !left) {
	      
	      // Add the children to the working set. Next iteration of the
	      // main loop (over idsIn) will start on the first child

	      // Add the children to the working set at index i1
	      insertVectorIntoVector(idsIn,myChildren,i1);
	      length += myChildren.size();
	      path = myPath;
	      
	    } else {
	      
	      // Create a new working set by adding the remainder of the old
	      // working set to the end of the current children list

	      myChildren.insert(myChildren.end(),remainingIds.begin(),remainingIds.end());

	      buildPencils(grid,pencils,idsOut,myChildren,dimension,myPath);
	      
	    };
	    
	  };	  
	};      
      };
    
    } else {

      // Add unrefined cells to the pencil directly

      idsOut.push_back(id);
      
    }; // closes if(isRefined)

    // Move to the next cell
    i++;
    
  }; // closes loop over ids

  pencils.addPencil(idsOut,0.0,0.0);
  return pencils;
  
} // closes function