dune-grid  2.1.1
gridinfo-gmsh-main.hh
Go to the documentation of this file.
00001 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002 // vi: set et ts=8 sw=2 sts=2:
00003 
00004 #ifndef DUNE_GRID_UTILITY_GRIDINFO_GMSH_MAIN_HH
00005 #define DUNE_GRID_UTILITY_GRIDINFO_GMSH_MAIN_HH
00006 
00007 #include <exception>
00008 #include <iostream>
00009 #include <ostream>
00010 #include <string>
00011 
00012 #include <dune/common/classname.hh>
00013 #include <dune/common/exceptions.hh>
00014 #include <dune/common/mpihelper.hh>
00015 #include <dune/common/shared_ptr.hh>
00016 
00017 #include <dune/grid/io/file/gmshreader.hh>
00018 #include <dune/grid/utility/gridinfo.hh>
00019 
00047 #ifdef HEADERCHECK
00048 // define so headercheck will run
00049 const std::string programName = "headercheck";
00050 #endif // HEADERCHECK
00051 
00052 #ifndef DOXYGEN
00053 namespace {
00054   // anonymous namespace so we don't freakishly conflict with another usage()
00055   // function that may be linked in from another compilation unit.
00056   void usage(std::ostream &stream) {
00057     stream << "USAGE:\n"
00058            << "  " << programName << " GRIDFILE\n"
00059            << "\n"
00060            << "PARAMTERS:\n"
00061            << "  GRIDFILE Name of the .msh file to read the grid from.\n"
00062            << std::flush;
00063   }
00064 }
00065 
00066 #ifndef HEADERCHECK
00067 int main(int argc, char **argv) {
00068   try {
00069     const Dune::MPIHelper &mpiHelper = Dune::MPIHelper::instance(argc, argv);
00070 
00071     // check that we are not run through mpirun
00072     if(mpiHelper.size() > 1) {
00073       if(mpiHelper.rank() == 0)
00074         std::cerr << programName << ": Sorry, this program works only in "
00075                   << "serial." << std::endl;
00076       return 1;
00077     }
00078 
00079     // check command line arguments
00080     if(argc < 2) {
00081       std::cerr << "Need name of a .msh file to read.\n"
00082                 << std::endl;
00083       usage(std::cerr);
00084       return 1;
00085     }
00086     if(argc > 2) {
00087       std::cerr << "Too many arguments.\n"
00088                 << std::endl;
00089       usage(std::cerr);
00090       return 1;
00091     }
00092     std::string gridFileName = argv[1];
00093     if(gridFileName == "-h" || gridFileName == "-?" ||
00094        gridFileName == "--help" || gridFileName == "-help")
00095     {
00096       usage(std::cout);
00097       return 0;
00098     }
00099 
00100     // read grid
00101     typedef Dune::GmshReader<Grid> Reader;
00102     Dune::shared_ptr<Grid> gridp(Reader::read(gridFileName));
00103 
00104     // collect information
00105     Dune::GridViewInfo<Grid::ctype> gridViewInfo;
00106     Dune::fillGridViewInfoSerial(gridp->leafView(), gridViewInfo);
00107 
00108     // print it
00109     std::cout << gridViewInfo << std::flush;
00110   }
00111   catch(const std::exception &e) {
00112     std::cerr << "Caught exception of type " << Dune::className(e)
00113               << std::endl
00114               << "e.what(): " << e.what() << std::endl;
00115     throw;
00116   }
00117   catch(const Dune::Exception &e) {
00118     std::cerr << "Caught exception of type " << Dune::className(e)
00119               << std::endl
00120               << "Exception message: " << e << std::endl;
00121     throw;
00122   }
00123   catch(const std::string &s) {
00124     std::cerr << "Caught exception of type " << Dune::className(s)
00125               << std::endl
00126               << "Exception message: " << s << std::endl;
00127     throw;
00128   }
00129   catch(...) {
00130     std::cerr << "Caught exception of unknown type" << std::endl;
00131     throw;
00132   }
00133 }
00134 #endif // !HEADERCHECK
00135 #endif // !DOXYGEN
00136 
00137 #endif // DUNE_GRID_UTILITY_GRIDINFO_GMSH_MAIN_HH