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

◆ do_compare()

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 230 of file compare.C.

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

Referenced by main().

234 {
235 
236  if (verbose)
237  {
238  libMesh::out << "********* LEFT SYSTEM *********" << std::endl;
239  les.print_info ();
240  libMesh::out << "********* RIGHT SYSTEM *********" << std::endl;
241  res.print_info ();
242  libMesh::out << "********* COMPARISON PHASE *********" << std::endl
243  << std::endl;
244  }
245 
249  bool result = les.compare(res, threshold, verbose);
250  if (verbose)
251  {
252  libMesh::out << "********* FINISHED *********" << std::endl;
253  }
254  return result;
255 }
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
OStreamProxy out
virtual bool compare(const EquationSystems &other_es, const Real threshold, const bool verbose) const

◆ main()

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 266 of file compare.C.

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

267 {
268  LibMeshInit init(argc, argv);
269 
270  // these should not be contained in the following braces
271  bool quiet = false;
272  bool are_equal;
273 
274  PerfMon perfmon(argv[0]);
275 
276  // default values
277  std::vector<std::string> names;
278  unsigned char dim = static_cast<unsigned char>(-1);
279  double threshold = double(TOLERANCE);
280  XdrMODE format = READ;
281  bool verbose = false;
282 
283  // get commands
284  process_cmd_line(argc, argv,
285  names,
286  dim,
287  threshold,
288  format,
289  verbose,
290  quiet);
291 
292  libmesh_error_msg_if(dim == static_cast<unsigned char>(-1),
293  "ERROR: you must specify the dimension on "
294  << "the command line!\n\n"
295  << argv[0]
296  << " -d 3 ... for example");
297 
298  if (quiet)
299  verbose = false;
300 
301  if (verbose)
302  {
303  libMesh::out << "Settings:" << std::endl
304  << " dimensionality = " << +dim << std::endl
305  << " mesh = " << names[0] << std::endl
306  << " left system = " << names[1] << std::endl
307  << " right system = " << names[2] << std::endl
308  << " threshold = " << threshold << std::endl
309  << " read format = " << format << std::endl
310  << std::endl;
311  }
312 
313 
317  Mesh left_mesh (init.comm(), dim);
318  Mesh right_mesh (init.comm(), dim);
319 
320 
321  if (!names.empty())
322  {
323  left_mesh.read (names[0]);
324  right_mesh.read (names[0]);
325 
326  if (verbose)
327  left_mesh.print_info();
328  }
329  else
330  {
331  libMesh::out << "No input specified." << std::endl;
332  return 1;
333  }
334 
335 
339  EquationSystems left_system (left_mesh);
340  EquationSystems right_system (right_mesh);
341 
342  libmesh_error_msg_if(names.size() != 3, "Bad input specified.");
343 
344  left_system.read (names[1], format);
345  right_system.read (names[2], format);
346 
347  are_equal = do_compare (left_system, right_system, threshold, verbose);
348 
349 
353  unsigned int our_result;
354 
355  if (are_equal)
356  {
357  if (!quiet)
358  libMesh::out << std::endl
359  << " Congrat's, up to the defined threshold, the two"
360  << std::endl
361  << " are identical."
362  << std::endl;
363  our_result=0;
364  }
365  else
366  {
367  if (!quiet)
368  libMesh::out << std::endl
369  << " Oops, differences occurred!"
370  << std::endl
371  << " Use -v to obtain more information where differences occurred."
372  << std::endl;
373  our_result=1;
374  }
375 
376  // return libMesh::close();
377  return our_result;
378 }
This is the EquationSystems class.
static constexpr Real TOLERANCE
unsigned int dim
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:90
XdrMODE
Defines an enum for read/write mode in Xdr format.
Definition: enum_xdr_mode.h:35
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:230
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
PAPI stands for Performance Application Programming Interface.
Definition: perfmon.h:57
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
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false) override
Reads the file specified by name.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50

◆ process_cmd_line()

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, dim, 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  libmesh_error_msg_if(!names.empty(), "ERROR: Mesh file name must precede left file name!");
120 
121  names.push_back(optarg);
122  break;
123  }
124 
128  case 'd':
129  {
130  dim = cast_int<unsigned char>(atoi(optarg));
131  break;
132  }
133 
137  case 'l':
138  {
139  libmesh_error_msg_if(left_name_set, "ERROR: Mesh file name must precede right file name!");
140 
141  names.push_back(optarg);
142  left_name_set = true;
143  break;
144  }
145 
149  case 'r':
150  {
151  libmesh_error_msg_if(names.empty() || !left_name_set,
152  "ERROR: Mesh file name and left file name must precede right file name!");
153 
154  names.push_back(optarg);
155  break;
156  }
157 
161  case 't':
162  {
163  threshold = atof(optarg);
164  break;
165  }
166 
170  case 'a':
171  {
172  libmesh_error_msg_if(format_set, "ERROR: Equation system file format already set!");
173 
174  format = READ;
175  format_set = true;
176  break;
177  }
178 
182  case 'b':
183  {
184  libmesh_error_msg_if(format_set, "ERROR: Equation system file format already set!");
185 
186  format = DECODE;
187  format_set = true;
188  break;
189  }
190 
191 
195  case 'v':
196  {
197  verbose = true;
198  break;
199  }
200 
204  case 'q':
205  {
206  quiet = true;
207  break;
208  }
209 
210  case 'h':
211  case '?':
212  usage(argv[0]);
213 
214  default:
215  return;
216  }
217  }
218 
219 }
unsigned int dim
void usage(const std::string &progName)
how to use this, and command line processor
Definition: compare.C:48

◆ usage()

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 }