Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef GRID_CREATOR_HH
- #define GRID_CREATOR_HH
- namespace Dune {
- namespace Dorie {
- /// Read simplex Gmsh file in 2D or 3D, create a grid, and return a shared pointer to the grid
- /** Refine the grid globally and call default load balancing for multi-processing support.
- * \param inifile Parameter file parser
- * \return Shared pointer to grid
- */
- template<class GridType>
- std::shared_ptr<GridType> build_grid_gmsh (const Dune::ParameterTree& inifile, const Dune::MPIHelper& helper)
- {
- Dune::Timer timer;
- enum { dim = GridType::dimension };
- const int verbose = inifile.get<int>("output.verbose");
- const int level = inifile.get<int>("grid.initialLevel");
- const std::string meshfilename = inifile.get<std::string>("grid.gridFile");
- typedef std::vector<int> GmshIndexMap;
- if(verbose>0 && helper.rank()==0){
- std::cout << "GRID SETUP:" << std::endl;
- std::cout << " Reading Gmsh file " << meshfilename;
- if(verbose<3) std::cout << " quietly" << std::endl;
- else std::cout << std::endl << "--- GMSH READER OUTPUT ---" << std::endl;
- }
- auto grid = std::make_shared<GridType>();
- GmshIndexMap boundary_index_map;
- GmshIndexMap element_index_map;
- Dune::GridFactory<GridType> factory(grid.get());
- Dune::GmshReader<GridType>::read(factory,meshfilename,boundary_index_map,element_index_map,verbose>2?true:false,false);
- factory.createGrid();
- grid->globalRefine(level);
- grid->loadBalance();
- if(verbose>0 && helper.rank()==0){
- if (verbose>2) std::cout << "--- GMSH READER OUTPUT END ---" << std::endl;
- std::cout << " Global Refinement level: " << level << std::endl;
- if(verbose>1)
- std::cout << "::: grid setup time" << std::setw(12) << timer.elapsed() << std::endl;
- }
- return grid;
- }
- /// Read parameter file specifications, create a grid, and return a shared pointer to the grid
- /** Refine the grid globally and call default load balancing for multi-processing support.
- * \param inifile Parameter file parser
- * \return Shared pointer to grid
- */
- template<class GridType>
- std::shared_ptr<GridType> build_grid_cube (const Dune::ParameterTree& inifile, const Dune::MPIHelper& helper)
- {
- Dune::Timer timer;
- enum { dim = GridType::dimension };
- const int verbose = inifile.get<int>("output.verbose");
- const int level = inifile.get<int>("grid.initialLevel");
- const Dune::FieldVector<double,dim> lowerLeft(0.);
- const Dune::FieldVector<double,dim> upperRight = inifile.get<Dune::FieldVector<double,dim>>("grid.extensions");
- const Dune::array<unsigned int,dim> elements = inifile.get<Dune::array<unsigned int,dim>>("grid.cells");
- auto grid = Dune::StructuredGridFactory<GridType>::createCubeGrid(lowerLeft,upperRight,elements);
- grid->globalRefine(level);
- grid->loadBalance();
- if(verbose>0 && helper.rank()==0){
- std::cout << "GRID SETUP:" << std::endl;
- std::cout << " Creating Rectangular Grid in " << dim << " Dimensions." << std::endl;
- std::cout << " Grid Extensions: ";
- for (unsigned int i=0; i<dim; i++)
- std::cout << upperRight[i] << " ";
- std::cout << std::endl;
- std::cout << " Grid Cells: ";
- for (unsigned int i=0; i<dim; i++)
- std::cout << elements[i] << " ";
- std::cout << std::endl;
- std::cout << " Global Refinement level: " << level << std::endl;
- std::cout << "::: grid setup time" << std::setw(12) << timer.elapsed() << std::endl;
- }
- return grid;
- }
- }
- }
- #endif // GRID_CREATOR_HH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement