libMesh
Functions
compare.C File Reference

Go to the source code of this file.

Functions

void usage (const std::string &progName)
 how to use this, and command line processor More...
 
void process_cmd_line (int argc, char **argv, std::vector< std::string > &names, unsigned char &dim, double &threshold, XdrMODE &format, bool &verbose, bool &quiet)
 
bool do_compare (EquationSystems &les, EquationSystems &res, double threshold, bool verbose)
 everything that is identical for the systems, and should not go into EquationSystems::compare(), can go in this do_compare(). More...
 
int main (int argc, char **argv)
 

Function Documentation

bool do_compare ( EquationSystems les,
EquationSystems res,
double  threshold,
bool  verbose 
)

everything that is identical for the systems, and should not go into EquationSystems::compare(), can go in this do_compare().

start comparing

Definition at line 240 of file compare.C.

References libMesh::EquationSystems::compare(), libMesh::out, and libMesh::EquationSystems::print_info().

Referenced by main().

244 {
245 
246  if (verbose)
247  {
248  libMesh::out << "********* LEFT SYSTEM *********" << std::endl;
249  les.print_info ();
250  libMesh::out << "********* RIGHT SYSTEM *********" << std::endl;
251  res.print_info ();
252  libMesh::out << "********* COMPARISON PHASE *********" << std::endl
253  << std::endl;
254  }
255 
259  bool result = les.compare(res, threshold, verbose);
260  if (verbose)
261  {
262  libMesh::out << "********* FINISHED *********" << std::endl;
263  }
264  return result;
265 }
virtual bool compare(const EquationSystems &other_es, const Real threshold, const bool verbose) const
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
OStreamProxy out
int main ( int  argc,
char **  argv 
)

build the left and right mesh for left, init them

build EquationSystems objects, read them

let's see what do_compare found out

Definition at line 276 of file compare.C.

References libMesh::LibMeshInit::comm(), dim, do_compare(), libMesh::TriangleWrapper::init(), libMesh::out, process_cmd_line(), libMesh::READ, libMesh::UnstructuredMesh::read(), libMesh::EquationSystems::read(), and libMesh::TOLERANCE.

277 {
278  LibMeshInit init(argc, argv);
279 
280  // these should not be contained in the following braces
281  bool quiet = false;
282  bool are_equal;
283 
284  PerfMon perfmon(argv[0]);
285 
286  // default values
287  std::vector<std::string> names;
288  unsigned char dim = static_cast<unsigned char>(-1);
289  double threshold = TOLERANCE;
290  XdrMODE format = READ;
291  bool verbose = false;
292 
293  // get commands
294  process_cmd_line(argc, argv,
295  names,
296  dim,
297  threshold,
298  format,
299  verbose,
300  quiet);
301 
302 
303  if (dim == static_cast<unsigned char>(-1))
304  libmesh_error_msg("ERROR: you must specify the dimension on " \
305  << "the command line!\n\n" \
306  << argv[0] \
307  << " -d 3 ... for example");
308 
309  if (quiet)
310  verbose = false;
311 
312  if (verbose)
313  {
314  libMesh::out << "Settings:" << std::endl
315  << " dimensionality = " << +dim << std::endl
316  << " mesh = " << names[0] << std::endl
317  << " left system = " << names[1] << std::endl
318  << " right system = " << names[2] << std::endl
319  << " threshold = " << threshold << std::endl
320  << " read format = " << format << std::endl
321  << std::endl;
322  }
323 
324 
328  Mesh left_mesh (init.comm(), dim);
329  Mesh right_mesh (init.comm(), dim);
330 
331 
332  if (!names.empty())
333  {
334  left_mesh.read (names[0]);
335  right_mesh.read (names[0]);
336 
337  if (verbose)
338  left_mesh.print_info();
339  }
340  else
341  {
342  libMesh::out << "No input specified." << std::endl;
343  return 1;
344  }
345 
346 
350  EquationSystems left_system (left_mesh);
351  EquationSystems right_system (right_mesh);
352 
353  if (names.size() == 3)
354  {
355  left_system.read (names[1], format);
356  right_system.read (names[2], format);
357  }
358  else
359  libmesh_error_msg("Bad input specified.");
360 
361  are_equal = do_compare (left_system, right_system, threshold, verbose);
362 
363 
367  unsigned int our_result;
368 
369  if (are_equal)
370  {
371  if (!quiet)
372  libMesh::out << std::endl
373  << " Congrat's, up to the defined threshold, the two"
374  << std::endl
375  << " are identical."
376  << std::endl;
377  our_result=0;
378  }
379  else
380  {
381  if (!quiet)
382  libMesh::out << std::endl
383  << " Oops, differences occurred!"
384  << std::endl
385  << " Use -v to obtain more information where differences occurred."
386  << std::endl;
387  our_result=1;
388  }
389 
390  // return libMesh::close();
391  return our_result;
392 }
This is the EquationSystems class.
virtual void read(const std::string &name, void *mesh_data=libmesh_nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false) libmesh_override
Reads the file specified by name.
unsigned int dim
static const Real TOLERANCE
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:62
XdrMODE
Defines an enum for read/write mode in Xdr format.
Definition: enum_xdr_mode.h:32
bool do_compare(EquationSystems &les, EquationSystems &res, double threshold, bool verbose)
everything that is identical for the systems, and should not go into EquationSystems::compare(), can go in this do_compare().
Definition: compare.C:240
void init(triangulateio &t)
Initializes the fields of t to NULL/0 as necessary.
PAPI stands for Performance Application Programming Interface.
Definition: perfmon.h:52
OStreamProxy out
void process_cmd_line(int argc, char **argv, std::vector< std::string > &names, unsigned char &dim, double &threshold, XdrMODE &format, bool &verbose, bool &quiet)
Definition: compare.C:88
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
void process_cmd_line ( int  argc,
char **  argv,
std::vector< std::string > &  names,
unsigned char &  dim,
double &  threshold,
XdrMODE format,
bool &  verbose,
bool &  quiet 
)

Get mesh file name

Get the mesh dimension

Get left file name

Get right file name

Get the comparison threshold

Use ascii format

Use binary format

Be verbose

Be totally quiet, no matter what -v says

Definition at line 88 of file compare.C.

References libMesh::DECODE, libMesh::READ, and usage().

Referenced by main().

96 {
97  char optionStr[] =
98  "d:m:l:r:t:abvq?h";
99 
100  int opt;
101 
102  bool format_set = false;
103  bool left_name_set = false;
104 
105  if (argc < 3)
106  usage(std::string(argv[0]));
107 
108 
109  while ((opt = getopt(argc, argv, optionStr)) != -1)
110  {
111  switch (opt)
112  {
113 
117  case 'm':
118  {
119  if (names.empty())
120  names.push_back(optarg);
121  else
122  libmesh_error_msg("ERROR: Mesh file name must precede left file name!");
123  break;
124  }
125 
129  case 'd':
130  {
131  dim = cast_int<unsigned char>(atoi(optarg));
132  break;
133  }
134 
138  case 'l':
139  {
140  if (!left_name_set)
141  {
142  names.push_back(optarg);
143  left_name_set = true;
144  }
145  else
146  libmesh_error_msg("ERROR: Mesh file name must precede right file name!");
147  break;
148  }
149 
153  case 'r':
154  {
155  if ((!names.empty()) && (left_name_set))
156  names.push_back(optarg);
157  else
158  libmesh_error_msg("ERROR: Mesh file name and left file name must precede right file name!");
159  break;
160  }
161 
165  case 't':
166  {
167  threshold = atof(optarg);
168  break;
169  }
170 
174  case 'a':
175  {
176  if (format_set)
177  libmesh_error_msg("ERROR: Equation system file format already set!");
178  else
179  {
180  format = READ;
181  format_set = true;
182  }
183  break;
184  }
185 
189  case 'b':
190  {
191  if (format_set)
192  libmesh_error_msg("ERROR: Equation system file format already set!");
193  else
194  {
195  format = DECODE;
196  format_set = true;
197  }
198  break;
199  }
200 
201 
205  case 'v':
206  {
207  verbose = true;
208  break;
209  }
210 
214  case 'q':
215  {
216  quiet = true;
217  break;
218  }
219 
220  case 'h':
221  case '?':
222  usage(argv[0]);
223 
224  default:
225  return;
226  }
227  }
228 
229 }
unsigned int dim
void usage(const std::string &progName)
how to use this, and command line processor
Definition: compare.C:48
void usage ( const std::string &  progName)

how to use this, and command line processor

Definition at line 48 of file compare.C.

Referenced by process_cmd_line().

49 {
50  std::ostringstream helpList;
51  helpList << "usage:\n"
52  << " "
53  << progName
54  << " [options] ...\n"
55  << "\n"
56  << "options:\n"
57  << " -d <dim> <dim>-dimensional mesh\n"
58  << " -m <string> Mesh file name\n"
59  << " -l <string> Left Equation Systems file name\n"
60  << " -r <string> Right Equation Systems file name\n"
61  << " -t <float> threshold\n"
62  << " -a ASCII format (default)\n"
63  << " -b binary format\n"
64  << " -v Verbose\n"
65  << " -q really quiet\n"
66  << " -h Print help menu\n"
67  << "\n"
68  << "\n"
69  << " This program is used to compare equation systems to a user-specified\n"
70  << " threshold. Equation systems are imported in the libMesh format\n"
71  << " provided through the read and write methods in class EquationSystems.\n"
72  << " \n"
73  << " ./compare -d 3 -m grid.xda -l leftfile.dat -r rightfile.dat -b -t 1.e-8\n"
74  << "\n"
75  << " will read in the mesh grid.xda, the equation systems leftfile.dat and\n"
76  << " rightfile.dat in binary format and compare systems, and especially the\n"
77  << " floats stored in vectors. The comparison is said to be passed when the\n"
78  << " floating point values agree up to the given threshold. When no threshold\n"
79  << " is set the default libMesh tolerance is used. If neither -a or -b are set,\n"
80  << " ASCII format is assumed.\n"
81  << "\n";
82 
83  libmesh_error_msg(helpList.str());
84 }