Rheolef  7.2
an efficient C++ finite element environment
geo.cc
Go to the documentation of this file.
1 //
2 // This file is part of Rheolef.
3 //
4 // Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
5 //
6 // Rheolef is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // Rheolef is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with Rheolef; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // =========================================================================
21 // author: Pierre.Saramito@imag.fr
22 // date: 16 september 2011
23 
24 namespace rheolef { } // namespace rheolef
434 
435 # include "rheolef.h"
436 # include "rheolef/iofem.h"
437 
438 #ifdef TO_CLEAN
439 // ****************************************************************
440 namespace rheolef {
441 // output all small objects that do not have
442 // ostdistream& operator<<
443 // but have
444 // ostream& operator<<
445 template <class T>
446 typename std::enable_if<
447  std::is_pointer<
448  decltype(
449  static_cast
450  <std::ostream& (*)(std::ostream&, const T&)>
451  (operator<<)
452  )
453  >::value
454  ,odiststream&
455 >::type
457 {
458  if (s.nop()) return s;
459  s.os() << x;
460  return s;
461 }
462 } // namespace rheolef {
463 // ****************************************************************
464 #endif // TO_CLEAN
465 
466 using namespace rheolef;
467 void usage() {
468  std::cerr
469  << "geo: usage:" << std::endl
470  << "geo "
471  << "{-|file[.geo[.gz]]}"
472  << "[-Idir|-I dir] "
473  << "[-check] "
474  << "[-upgrade] "
475  << "[-subdivide int] "
476  << "[-if {geo,bamg,vtk}] "
477  << "[-geo|-gmsh|-gnuplot|-paraview] "
478  << "[-name string] "
479  << "[-[no]full|-[no]fill|-[no]lattice] "
480  << "[-[no]stereo|-[no]full|-[no]cut|-[no]shrink|-[no]showlabel] "
481  << "[-image-format string] "
482  << "[-resolution int [int]] "
483  << "[-add-boundary] "
484  << "[-zr|-rz] "
485  << "[-size] [-n-vertex] "
486  << "[-hmin] [-hmax] "
487  << "[-[min|max]-element-measure] "
488  << "[-round [float]] "
489  << "[-[no]clean] [-[no]execute] [-[no]verbose] "
490  << std::endl;
491  exit (1);
492 }
493 void set_input_format (idiststream& in, std::string input_format)
494 {
495  if (input_format == "bamg") in.is() >> bamg;
496  else if (input_format == "vtk") in.is() >> vtk;
497  else if (input_format == "geo") in.is() >> rheo;
498  else {
499  std::cerr << "geo: invalid input format \""<<input_format<<"\"" << std::endl;
500  usage();
501  }
502 }
503 typedef enum {
514 
515 #ifdef TO_CLEAN
516 void h_extrema (const geo_basic<Float,sequential>& omega, Float& hmin, Float& hmax)
517 {
518  hmin = std::numeric_limits<Float>::max();
519  hmax = 0;
520  for (size_t iedg = 0, nedg = omega.geo_element_ownership(1).size(); iedg < nedg; ++iedg) {
521  const geo_element& E = omega.get_geo_element (1, iedg);
522  const point& x0 = omega.dis_node(E[0]);
523  const point& x1 = omega.dis_node(E[1]);
524  Float hloc = dist(x0,x1);
525  hmin = min(hmin, hloc);
526  hmax = max(hmax, hloc);
527  }
528 #ifdef TODO
529  // M=sequential here (just if this fct goes into the geo<M,T> class later)
530 #ifdef _RHEOLEF_HAVE_MPI
531  hmin = mpi::all_reduce (comm(), hmin, mpi::minimum<Float>());
532  hmax = mpi::all_reduce (comm(), hmax, mpi::maximum<Float>());
533 #endif // _RHEOLEF_HAVE_MPI
534 #endif // TODO
535 }
536 #endif // TO_CLEAN
537 
539 {
540  space_basic<Float,sequential> Xh (omega, "P0");
541  form_basic<Float,sequential> m (Xh, Xh, "mass");
542  field_basic<Float,sequential> one (Xh, 1);
543  return is_min ? (m*one).min_abs() : (m*one).max_abs();
544 }
545 int main(int argc, char**argv) {
546  environment distributed(argc, argv);
547  check_macro (communicator().size() == 1, "geo: command may be used as mono-process only");
548  // ----------------------------
549  // default options
550  // ----------------------------
551  bool do_upgrade = false ;
552  bool do_check = false ;
553  bool do_add_bdry = false ;
554  bool do_stereo = false ;
555  bool show_n_element = false ;
556  bool show_n_vertex = false ;
557  bool show_sys_coord = false ;
558  bool show_hmin = false ;
559  bool show_hmax = false ;
560  bool show_xmin = false ;
561  bool show_xmax = false ;
562  bool show_min_element_measure = false ;
563  bool show_max_element_measure = false ;
564  bool do_round = false ;
565  Float round_prec = pow(10., -std::numeric_limits<Float>::digits10/2);
566  std::string name = "output";
567  dout.os() << verbose; bool bverbose = true;
568  render_type render = no_render;
570  dout.os() << lattice;
571  dout.os() << nofill;
572  dout.os() << grid;
573  dout.os() << showlabel;
574  // this normal is not so bad for the dirichlet.cc demo on the cube:
575  dout.os() << setnormal(point(-0.015940197423022637, -0.9771157601293953, -0.21211011624358989));
576  dout.os() << setorigin(point(std::numeric_limits<Float>::max()));
577  std::string filename;
578  std::string input_format = "geo";
579  std::string sys_coord = "";
580  // ----------------------------
581  // scan the command line
582  // ----------------------------
583  for (int i = 1; i < argc; i++) {
584 
585  // general options:
586  if (strcmp (argv[i], "-clean") == 0) dout.os() << clean;
587  else if (strcmp (argv[i], "-noclean") == 0) dout.os() << noclean;
588  else if (strcmp (argv[i], "-execute") == 0) dout.os() << execute;
589  else if (strcmp (argv[i], "-noexecute") == 0) dout.os() << noexecute;
590  else if (strcmp (argv[i], "-verbose") == 0) { bverbose = true; dout.os() << verbose; }
591  else if (strcmp (argv[i], "-noverbose") == 0) { bverbose = false; dout.os() << noverbose; }
592  else if (strcmp (argv[i], "-add-boundary") == 0) { do_add_bdry = true; }
593  else if (strcmp (argv[i], "-rz") == 0) { sys_coord = "rz"; }
594  else if (strcmp (argv[i], "-zr") == 0) { sys_coord = "zr"; }
595  else if (strcmp (argv[i], "-size") == 0) { show_n_element = true; }
596  else if (strcmp (argv[i], "-n-element") == 0) { show_n_element = true; }
597  else if (strcmp (argv[i], "-n-vertex") == 0) { show_n_vertex = true; }
598  else if (strcmp (argv[i], "-sys-coord") == 0) { show_sys_coord = true; }
599  else if (strcmp (argv[i], "-hmin") == 0) { show_hmin = true; }
600  else if (strcmp (argv[i], "-hmax") == 0) { show_hmax = true; }
601  else if (strcmp (argv[i], "-xmin") == 0) { show_xmin = true; }
602  else if (strcmp (argv[i], "-xmax") == 0) { show_xmax = true; }
603  else if (strcmp (argv[i], "-min-element-measure") == 0) { show_min_element_measure = true; }
604  else if (strcmp (argv[i], "-max-element-measure") == 0) { show_max_element_measure = true; }
605  else if (strcmp (argv[i], "-I") == 0) {
606  if (i == argc-1) { std::cerr << "geo -I: option argument missing" << std::endl; usage(); }
607  append_dir_to_rheo_path (argv[++i]);
608  }
609  else if (argv [i][0] == '-' && argv [i][1] == 'I') { append_dir_to_rheo_path (argv[i]+2); }
610  // output file option:
611  else if (strcmp (argv[i], "-geo") == 0) { dout.os() << rheo; render = file_render; }
612  else if (strcmp (argv[i], "-gmsh") == 0) { dout.os() << gmsh; render = gmsh_render; }
613 
614  // render spec:
615  else if (strcmp (argv[i], "-gnuplot") == 0) { dout.os() << gnuplot; render = gnuplot_render; }
616  else if (strcmp (argv[i], "-paraview") == 0) { dout.os() << paraview; render = paraview_render; }
617 
618  // render option:
619  else if (strcmp (argv[i], "-full") == 0) { dout.os() << full; }
620  else if (strcmp (argv[i], "-nofull") == 0) { dout.os() << nofull; }
621  else if (strcmp (argv[i], "-fill") == 0) { dout.os() << fill; }
622  else if (strcmp (argv[i], "-nofill") == 0) { dout.os() << nofill; }
623  else if (strcmp (argv[i], "-stereo") == 0) { dout.os() << stereo; do_stereo = true; }
624  else if (strcmp (argv[i], "-nostereo") == 0) { dout.os() << nostereo; }
625  else if (strcmp (argv[i], "-cut") == 0) { dout.os() << cut; }
626  else if (strcmp (argv[i], "-nocut") == 0) { dout.os() << nocut; }
627  else if (strcmp (argv[i], "-shrink") == 0) { dout.os() << shrink; }
628  else if (strcmp (argv[i], "-noshrink") == 0) { dout.os() << noshrink; }
629  else if (strcmp (argv[i], "-lattice") == 0) { dout.os() << lattice; }
630  else if (strcmp (argv[i], "-nolattice") == 0) { dout.os() << nolattice; }
631  else if (strcmp (argv[i], "-showlabel") == 0) { dout.os() << showlabel; }
632  else if (strcmp (argv[i], "-noshowlabel") == 0){ dout.os() << noshowlabel; }
633  else if (strcmp (argv[i], "-subdivide") == 0) {
634  if (i == argc-1) { std::cerr << "geo -subdivide: option argument missing" << std::endl; usage(); }
635  size_t nsub = atoi(argv[++i]);
636  dout.os() << setsubdivide (nsub);
637  }
638  else if (strcmp (argv[i], "-image-format") == 0) {
639  if (i == argc-1) { std::cerr << "geo -image-format: option argument missing" << std::endl; usage(); }
640  std::string format = argv[++i];
641  if (format == "jpeg") format = "jpg";
642  if (format == "postscript") format = "ps";
643  dout.os() << setimage_format(format);
644  }
645  else if (strcmp (argv[i], "-resolution") == 0) {
646  if (i == argc-1 || !isdigit(argv[i+1][0])) { std::cerr << "geo -resolution: option argument missing" << std::endl; usage(); }
647  size_t nx = atoi(argv[++i]);
648  size_t ny = (i < argc-1 && isdigit(argv[i+1][0])) ? atoi(argv[++i]) : nx;
649  dout.os() << setresolution(point_basic<size_t>(nx,ny));
650  }
651  else if (strcmp (argv[i], "-round") == 0) {
652 
653  do_round = true;
654  if (i+1 < argc && is_float(argv[i+1])) {
655  round_prec = to_float (argv[++i]);
656  }
657  }
658  // input options:
659  else if (strcmp (argv[i], "-upgrade") == 0) { do_upgrade = true; dout.os() << rheo; render = file_render; }
660  else if (strcmp (argv[i], "-check") == 0) { do_check = true; }
661  else if (strcmp (argv[i], "-name") == 0) {
662  if (i == argc-1) { std::cerr << "geo -name: option argument missing" << std::endl; usage(); }
663  name = argv[++i];
664  }
665  else if (strcmp (argv[i], "-if") == 0 ||
666  strcmp (argv[i], "-input-format") == 0) {
667  if (i == argc-1) { std::cerr << "geo "<<argv[i]<<": option argument missing" << std::endl; usage(); }
668  input_format = argv[++i];
669  }
670  else if (strcmp (argv[i], "-") == 0) {
671  filename = "-"; // geo on stdin
672  }
673  else if (argv[i][0] != '-') {
674  filename = argv[i]; // input on file
675  }
676  else { usage(); }
677  }
678  // ----------------------------
679  // geo treatment
680  // ----------------------------
681  if (filename == "") {
682  std::cerr << "geo: no input file specified" << std::endl;
683  usage();
684  } else if (filename == "-") {
685  // geo on stdin
686  if (do_upgrade) std::cin >> upgrade;
687  std::string thename;
688  if (name != "output") thename = name;
689  std::cin >> setbasename(thename);
690  set_input_format (din, input_format);
691  din >> omega;
692  dout.os() << setbasename(name) << reader_on_stdin;
693  } else {
694  // input geo on file
695  std::string suffix = input_format;
696  if (name == "output") {
697  name = get_basename(delete_suffix (delete_suffix (filename, "gz"), suffix));
698  }
699  idiststream ips;
700  ips.open (filename, suffix);
701  check_macro(ips.good(), "\"" << filename << "[."<<suffix<<"[.gz]]\" not found.");
702  if (do_upgrade) ips.is() >> upgrade;
703  std::string root_name = delete_suffix (delete_suffix(filename, "gz"), suffix);
704  name = get_basename (root_name);
705  ips.is() >> setbasename(name);
706  set_input_format (ips, input_format);
707  ips >> omega;
708  dout.os() << setbasename(name);
709  }
710  if (sys_coord != "") { omega.set_coordinate_system(sys_coord); }
711  if (do_add_bdry) { omega.boundary(); }
712 
713  if (render == file_render) {
714  size_t nsub = iorheo::getsubdivide (std::cout);
715  if (nsub >= 2) {
716  geo_basic<Float,sequential> new_omega;
717  new_omega.build_by_subdividing (omega, nsub);
718  omega = new_omega;
719  }
720  }
721  if (do_check) {
722  check_macro (omega.check(bverbose), "geo check failed");
723  }
724  bool show = show_min_element_measure
725  || show_max_element_measure
726  || show_hmin || show_hmax
727  || show_xmin || show_xmax
728  || show_n_element || show_n_vertex || show_sys_coord;
729  if (show) {
730  if (show_hmin) { dout << "hmin = " << omega.hmin() << std::endl; }
731  if (show_hmax) { dout << "hmax = " << omega.hmax() << std::endl; }
732  if (show_xmin) { dout << "xmin = " << omega.xmin() << std::endl; }
733  if (show_xmax) { dout << "xmax = " << omega.xmax() << std::endl; }
734  if (show_n_element) { dout << "size = " << omega.dis_size() << std::endl; }
735  if (show_n_vertex) { dout << "n_vertex = " << omega.dis_size(0) << std::endl; }
736  if (show_sys_coord) { dout << "sys_coord = " << omega.coordinate_system_name() << std::endl; }
737  if (show_min_element_measure) {
738  dout << "min_element_measure = " << extrema_element_measure (omega, true) << std::endl;
739  }
740  if (show_max_element_measure) {
741  dout << "max_element_measure = " << extrema_element_measure (omega, false) << std::endl;
742  }
743  return 0;
744  }
745  if (do_round) {
746  dout.os() << setrounding_precision(round_prec);
747  }
748  if (render == no_render) {
749  // try to choose the best render from dimension
750 #if (_RHEOLEF_PARAVIEW_VERSION_MAJOR >= 5) && (_RHEOLEF_PARAVIEW_VERSION_MINOR >= 5)
751  // paraview version >= 5.5 has high order elements
752  if (do_stereo || omega.dimension() >= 2) {
753 #else
754  if (do_stereo || omega.dimension() == 3) {
755 #endif
756  dout.os() << paraview;
757  } else {
758  dout.os() << gnuplot;
759  }
760  }
761  dout << omega;
762 }
render_type
Definition: branch.cc:432
void usage()
Definition: geo.cc:467
int main(int argc, char **argv)
Definition: geo.cc:545
void set_input_format(idiststream &in, std::string input_format)
Definition: geo.cc:493
render_type
Definition: geo.cc:503
@ file_render
Definition: geo.cc:512
@ gnuplot_render
Definition: geo.cc:505
@ no_render
Definition: geo.cc:504
@ paraview_render
Definition: geo.cc:506
@ gmsh_render
Definition: geo.cc:509
@ vtk_render
Definition: geo.cc:508
@ x3d_render
Definition: geo.cc:511
@ plotmtv_render
Definition: geo.cc:507
@ atom_render
Definition: geo.cc:510
Float extrema_element_measure(const geo_basic< Float, sequential > &omega, bool is_min)
Definition: geo.cc:538
see the Float page for the full documentation
see the point page for the full documentation
see the environment page for the full documentation
Definition: environment.h:121
generic mesh with rerefence counting
Definition: geo.h:1089
see the geo_element page for the full documentation
Definition: geo_element.h:102
idiststream: see the diststream page for the full documentation
Definition: diststream.h:336
std::istream & is()
Definition: diststream.h:400
void open(std::string filename, std::string suffix="", const communicator &comm=communicator())
This routine opens a physical input file.
Definition: diststream.cc:85
bool good() const
Definition: diststream.cc:124
odiststream: see the diststream page for the full documentation
Definition: diststream.h:137
std::ostream & os()
Definition: diststream.h:247
the finite element space
Definition: space.h:382
point_basic< Float > point
Definition: point.h:163
idiststream din(cin)
see the diststream page for the full documentation
Definition: diststream.h:464
rheolef::std type
distributed
Definition: asr.cc:228
rheolef::std value
odiststream dout(cout)
see the diststream page for the full documentation
Definition: diststream.h:467
Expr1::float_type T
Definition: field_expr.h:230
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
verbose clean transpose logscale grid shrink ball stereo iso volume skipvtk deformation fastfieldload lattice reader_on_stdin color format format bamg
verbose clean transpose logscale grid shrink ball stereo iso volume skipvtk deformation fastfieldload lattice reader_on_stdin color format format format format format format format format format format format format format format format format format format format format format paraview
verbose clean transpose logscale grid shrink ball stereo iso volume skipvtk deformation fastfieldload lattice reader_on_stdin color format format format format format format format format format format format format format format format format format format format gnuplot
verbose clean transpose logscale grid shrink ball stereo iso volume skipvtk deformation fastfieldload lattice reader_on_stdin color format format format format format format format format format format format format format format format format vtk
verbose clean transpose logscale grid shrink ball stereo iso volume skipvtk deformation fastfieldload lattice reader_on_stdin color rheo
verbose clean transpose logscale grid shrink ball stereo iso volume skipvtk deformation fastfieldload lattice reader_on_stdin color format format format format format format gmsh
string sys_coord
Definition: mkgeo_grid.sh:171
T max_abs(const T &x)
This file is part of Rheolef.
T dist(const point_basic< T > &x, const point_basic< T > &y)
Definition: point.h:298
string delete_suffix(const string &name, const string &suffix)
delete_suffix: see the rheostream page for the full documentation
Definition: rheostream.cc:226
string get_basename(const string &name)
get_basename: see the rheostream page for the full documentation
Definition: rheostream.cc:258
bool is_float(const string &s)
is_float: see the rheostream page for the full documentation
Definition: rheostream.cc:480
void append_dir_to_rheo_path(const string &dir)
append_dir_to_rheo_path: see the rheostream page for the full documentation
Definition: rheostream.cc:334
std::ostream & operator<<(std::ostream &os, const catchmark &m)
Definition: catchmark.h:99
space_mult_list< T, M > pow(const space_basic< T, M > &X, size_t n)
Definition: space_mult.h:120
Float to_float(const string &s)
to_float: see the rheostream page for the full documentation
Definition: rheostream.cc:498
rheolef - reference manual