Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.49 KB | None | 0 0
  1. #ifndef GRID_CREATOR_HH
  2. #define GRID_CREATOR_HH
  3.  
  4. namespace Dune {
  5.     namespace Dorie {
  6.  
  7.         /// Read simplex Gmsh file in 2D or 3D, create a grid, and return a shared pointer to the grid
  8.         /** Refine the grid globally and call default load balancing for multi-processing support.
  9.          *  \param inifile Parameter file parser
  10.          *  \return Shared pointer to grid
  11.          */
  12.         template<class GridType>
  13.         std::shared_ptr<GridType> build_grid_gmsh (const Dune::ParameterTree& inifile, const Dune::MPIHelper& helper)
  14.         {
  15.             Dune::Timer timer;
  16.             enum { dim = GridType::dimension };
  17.             const int verbose = inifile.get<int>("output.verbose");
  18.             const int level = inifile.get<int>("grid.initialLevel");
  19.             const std::string meshfilename = inifile.get<std::string>("grid.gridFile");
  20.             typedef std::vector<int> GmshIndexMap;
  21.  
  22.             if(verbose>0 && helper.rank()==0){
  23.                 std::cout << "GRID SETUP:" << std::endl;
  24.                 std::cout << "  Reading Gmsh file " << meshfilename;
  25.                 if(verbose<3) std::cout << " quietly" << std::endl;
  26.                 else std::cout << std::endl << "--- GMSH READER OUTPUT ---" << std::endl;
  27.             }
  28.  
  29.             auto grid = std::make_shared<GridType>();
  30.             GmshIndexMap boundary_index_map;
  31.             GmshIndexMap element_index_map;
  32.             Dune::GridFactory<GridType> factory(grid.get());
  33.             Dune::GmshReader<GridType>::read(factory,meshfilename,boundary_index_map,element_index_map,verbose>2?true:false,false);
  34.             factory.createGrid();
  35.  
  36.             grid->globalRefine(level);
  37.             grid->loadBalance();
  38.  
  39.             if(verbose>0 && helper.rank()==0){
  40.                 if (verbose>2) std::cout << "--- GMSH READER OUTPUT END ---" << std::endl;
  41.                 std::cout << "  Global Refinement level: " << level << std::endl;
  42.                 if(verbose>1)
  43.                     std::cout << "::: grid setup time" << std::setw(12)  << timer.elapsed() << std::endl;
  44.             }
  45.  
  46.             return grid;
  47.         }
  48.  
  49.         /// Read parameter file specifications, create a grid, and return a shared pointer to the grid
  50.         /** Refine the grid globally and call default load balancing for multi-processing support.
  51.          *  \param inifile Parameter file parser
  52.          *  \return Shared pointer to grid
  53.          */
  54.         template<class GridType>
  55.         std::shared_ptr<GridType> build_grid_cube (const Dune::ParameterTree& inifile, const Dune::MPIHelper& helper)
  56.         {
  57.             Dune::Timer timer;
  58.             enum { dim = GridType::dimension };
  59.             const int verbose = inifile.get<int>("output.verbose");
  60.             const int level = inifile.get<int>("grid.initialLevel");
  61.             const Dune::FieldVector<double,dim> lowerLeft(0.);
  62.             const Dune::FieldVector<double,dim> upperRight = inifile.get<Dune::FieldVector<double,dim>>("grid.extensions");
  63.             const Dune::array<unsigned int,dim> elements = inifile.get<Dune::array<unsigned int,dim>>("grid.cells");
  64.  
  65.             auto grid = Dune::StructuredGridFactory<GridType>::createCubeGrid(lowerLeft,upperRight,elements);
  66.             grid->globalRefine(level);
  67.             grid->loadBalance();
  68.  
  69.             if(verbose>0 && helper.rank()==0){
  70.                 std::cout << "GRID SETUP:" << std::endl;
  71.                 std::cout << "  Creating Rectangular Grid in " << dim << " Dimensions." << std::endl;
  72.                 std::cout << "  Grid Extensions: ";
  73.                 for (unsigned int i=0; i<dim; i++)
  74.                     std::cout << upperRight[i] << " ";
  75.                 std::cout << std::endl;
  76.                 std::cout << "  Grid Cells: ";
  77.                 for (unsigned int i=0; i<dim; i++)
  78.                     std::cout << elements[i] << " ";
  79.                 std::cout << std::endl;
  80.                 std::cout << "  Global Refinement level: " << level << std::endl;
  81.                 std::cout << "::: grid setup time" << std::setw(12) << timer.elapsed() << std::endl;
  82.             }
  83.  
  84.             return grid;
  85.         }
  86.     }
  87. }
  88. #endif // GRID_CREATOR_HH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement