6#ifndef DUNE_GRID_UTILITY_GRIDINFO_GMSH_MAIN_HH
7#define DUNE_GRID_UTILITY_GRIDINFO_GMSH_MAIN_HH
24#include <dune/grid/io/file/gmshreader.hh>
25#include <dune/grid/utility/gridinfo.hh>
56const std::string programName =
"headercheck";
63 void usage(std::ostream &stream) {
65 <<
" " << programName <<
" [-R REFINES] GRIDFILE\n"
68 <<
" -R REFINES How many global refines to do after reading\n"
70 <<
" GRIDFILE Name of the .msh file to read the grid from.\n"
74 bool prefix_match(
const std::string &prefix,
const std::string &str)
76 return str.compare(0,prefix.size(), prefix) == 0;
79 void error_argument_required(
const std::string &opt) {
80 std::cerr <<
"Error: option " << opt <<
" requires argument\n";
85 void error_unknown_option(
const std::string &opt) {
86 std::cerr <<
"Error: unknown option: " << opt <<
"\n";
91 void error_parsing_optarg(
const std::string &opt,
const std::string &error) {
92 std::cerr <<
"Error: option " << opt <<
": " << error <<
"\n";
98 void parse(
const std::string &arg, T &val) {
99 std::istringstream s(arg);
101 bool good = !s.fail();
105 good = s.fail() && s.eof();
108 std::ostringstream s;
110 throw std::runtime_error(s.str());
114 std::size_t refines = 0;
115 std::string gridFileName =
"";
117 void parseOptions(
int argc,
char **argv) {
118 std::vector<std::string> params;
119 for(++argv; *argv; ++argv) {
120 std::string arg = *argv;
121 if(prefix_match(
"-", arg)) {
122 std::string opt = arg;
124 for(++argv; *argv; ++argv)
125 params.push_back(*argv);
128 else if(prefix_match(
"-h", opt) || prefix_match(
"-?", opt) ||
134 else if(opt ==
"-R" || opt ==
"--global-refines") {
136 if(!*argv) error_argument_required(opt);
137 try { parse(*argv, refines); }
138 catch(
const std::runtime_error &e)
139 { error_parsing_optarg(opt, e.what()); }
141 else if(prefix_match(
"-R", opt)) {
142 try { parse(*argv+std::strlen(
"-R"), refines); }
143 catch(
const std::runtime_error &e)
144 { error_parsing_optarg(opt, e.what()); }
146 else if(prefix_match(
"--global-refines=", opt)) {
147 try { parse(*argv+std::strlen(
"--global-refines="), refines); }
148 catch(
const std::runtime_error &e)
149 { error_parsing_optarg(opt, e.what()); }
152 error_unknown_option(opt);
155 params.push_back(arg);
158 if(params.size() < 1) {
159 std::cerr <<
"Need name of a .msh file to read.\n"
164 if(params.size() > 1) {
165 std::cerr <<
"Too many arguments.\n"
170 gridFileName = params[0];
175int main(
int argc,
char **argv) {
180 if(mpiHelper.
size() > 1) {
181 if(mpiHelper.
rank() == 0)
182 std::cerr << programName <<
": Sorry, this program works only in "
183 <<
"serial." << std::endl;
187 parseOptions(argc, argv);
191 std::shared_ptr<Grid> gridp(Reader::read(gridFileName));
192 gridp->globalRefine(refines);
199 std::cout << gridViewInfo << std::flush;
201 catch(
const std::exception &e) {
204 <<
"e.what(): " << e.what() << std::endl;
210 <<
"Exception message: " << e << std::endl;
213 catch(
const std::string &s) {
216 <<
"Exception message: " << s << std::endl;
220 std::cerr <<
"Caught exception of unknown type" << std::endl;
Base class for Dune-Exceptions.
Definition: exceptions.hh:96
Read Gmsh mesh file.
Definition: gmshreader.hh:805
A real mpi helper.
Definition: mpihelper.hh:179
int size() const
return number of processes
Definition: mpihelper.hh:272
static DUNE_EXPORT MPIHelper & instance(int &argc, char **&argv)
Get the singleton instance of the helper.
Definition: mpihelper.hh:246
int rank() const
return rank of process
Definition: mpihelper.hh:268
A free function to provide the demangled class name of a given object or type as a string.
A few common exception classes.
Helpers for dealing with MPI.
std::string className()
Provide the demangled class name of a type T as a string.
Definition: classname.hh:47
void fillGridViewInfoSerial(const GV &gv, GridViewInfo< typename GV::ctype > &gridViewInfo)
fill a GridViewInfo structure from a serial grid
Definition: gridinfo.hh:214
structure to hold information about a certain GridView.
Definition: gridinfo.hh:100