geo.cc
Go to the documentation of this file.
//
// This file is part of Rheolef.
//
// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
//
// Rheolef is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Rheolef is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Rheolef; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// =========================================================================
// author: Pierre.Saramito@imag.fr
// date: 16 september 2011
namespace rheolef { } // namespace rheolef
# include "rheolef.h"
# include "rheolef/iofem.h"
using namespace rheolef;
void usage() {
std::cerr
<< "geo: usage:" << std::endl
<< "geo "
<< "{-|file[.geo[.gz]]}"
<< "[-Idir|-I dir] "
<< "[-check] "
<< "[-upgrade] "
<< "[-subdivide int] "
<< "[-if {geo,bamg,vtk}] "
<< "[-geo|-gmsh|-gnuplot|-paraview] "
<< "[-name string] "
<< "[-[no]full|-[no]fill|-[no]lattice] "
<< "[-[no]stereo|-[no]full|-[no]cut|-[no]shrink|-[no]showlabel] "
<< "[-image-format string] "
<< "[-resolution int [int]] "
<< "[-add-boundary] "
<< "[-zr|-rz] "
<< "[-size] [-n-vertex] "
<< "[-hmin] [-hmax] "
<< "[-[min|max]-element-measure] "
<< "[-round [float]] "
<< "[-[no]clean] [-[no]execute] [-[no]verbose] "
<< std::endl;
exit (1);
}
void set_input_format (idiststream& in, std::string input_format)
{
if (input_format == "bamg") in.is() >> bamg;
else if (input_format == "vtk") in.is() >> vtk;
else if (input_format == "geo") in.is() >> rheo;
else {
std::cerr << "geo: invalid input format \""<<input_format<<"\"" << std::endl;
usage();
}
}
typedef enum {
no_render,
gnuplot_render,
paraview_render,
plotmtv_render,
vtk_render,
gmsh_render,
atom_render,
x3d_render,
file_render
} render_type;
#ifdef TO_CLEAN
void h_extrema (const geo_basic<Float,sequential>& omega, Float& hmin, Float& hmax)
{
hmin = std::numeric_limits<Float>::max();
hmax = 0;
for (size_t iedg = 0, nedg = omega.geo_element_ownership(1).size(); iedg < nedg; ++iedg) {
const geo_element& E = omega.get_geo_element (1, iedg);
const point& x0 = omega.dis_node(E[0]);
const point& x1 = omega.dis_node(E[1]);
Float hloc = dist(x0,x1);
hmin = min(hmin, hloc);
hmax = max(hmax, hloc);
}
#ifdef TODO
// M=sequential here (just if this fct goes into the geo<M,T> class later)
#ifdef _RHEOLEF_HAVE_MPI
hmin = mpi::all_reduce (comm(), hmin, mpi::minimum<Float>());
hmax = mpi::all_reduce (comm(), hmax, mpi::maximum<Float>());
#endif // _RHEOLEF_HAVE_MPI
#endif // TODO
}
#endif // TO_CLEAN
Float extrema_element_measure (const geo_basic<Float,sequential>& omega, bool is_min)
{
space_basic<Float,sequential> Xh (omega, "P0");
form_basic<Float,sequential> m (Xh, Xh, "mass");
field_basic<Float,sequential> one (Xh, 1);
return is_min ? (m*one).min_abs() : (m*one).max_abs();
}
int main(int argc, char**argv) {
environment distributed(argc, argv);
check_macro (communicator().size() == 1, "geo: command may be used as mono-process only");
// ----------------------------
// default options
// ----------------------------
bool do_upgrade = false ;
bool do_check = false ;
bool do_add_bdry = false ;
bool do_stereo = false ;
bool show_n_element = false ;
bool show_n_vertex = false ;
bool show_sys_coord = false ;
bool show_hmin = false ;
bool show_hmax = false ;
bool show_xmin = false ;
bool show_xmax = false ;
bool show_min_element_measure = false ;
bool show_max_element_measure = false ;
bool do_round = false ;
Float round_prec = pow(10., -std::numeric_limits<Float>::digits10/2);
std::string name = "output";
dout.os() << verbose; bool bverbose = true;
render_type render = no_render;
geo_basic<Float,sequential> omega;
dout.os() << lattice;
dout.os() << nofill;
dout.os() << grid;
dout.os() << showlabel;
// this normal is not so bad for the dirichlet.cc demo on the cube:
dout.os() << setnormal(point(-0.015940197423022637, -0.9771157601293953, -0.21211011624358989));
dout.os() << setorigin(point(std::numeric_limits<Float>::max()));
std::string filename;
std::string input_format = "geo";
std::string sys_coord = "";
// ----------------------------
// scan the command line
// ----------------------------
for (int i = 1; i < argc; i++) {
// general options:
if (strcmp (argv[i], "-clean") == 0) dout.os() << clean;
else if (strcmp (argv[i], "-noclean") == 0) dout.os() << noclean;
else if (strcmp (argv[i], "-execute") == 0) dout.os() << execute;
else if (strcmp (argv[i], "-noexecute") == 0) dout.os() << noexecute;
else if (strcmp (argv[i], "-verbose") == 0) { bverbose = true; dout.os() << verbose; }
else if (strcmp (argv[i], "-noverbose") == 0) { bverbose = false; dout.os() << noverbose; }
else if (strcmp (argv[i], "-add-boundary") == 0) { do_add_bdry = true; }
else if (strcmp (argv[i], "-rz") == 0) { sys_coord = "rz"; }
else if (strcmp (argv[i], "-zr") == 0) { sys_coord = "zr"; }
else if (strcmp (argv[i], "-size") == 0) { show_n_element = true; }
else if (strcmp (argv[i], "-n-element") == 0) { show_n_element = true; }
else if (strcmp (argv[i], "-n-vertex") == 0) { show_n_vertex = true; }
else if (strcmp (argv[i], "-sys-coord") == 0) { show_sys_coord = true; }
else if (strcmp (argv[i], "-hmin") == 0) { show_hmin = true; }
else if (strcmp (argv[i], "-hmax") == 0) { show_hmax = true; }
else if (strcmp (argv[i], "-xmin") == 0) { show_xmin = true; }
else if (strcmp (argv[i], "-xmax") == 0) { show_xmax = true; }
else if (strcmp (argv[i], "-min-element-measure") == 0) { show_min_element_measure = true; }
else if (strcmp (argv[i], "-max-element-measure") == 0) { show_max_element_measure = true; }
else if (strcmp (argv[i], "-I") == 0) {
if (i == argc-1) { std::cerr << "geo -I: option argument missing" << std::endl; usage(); }
append_dir_to_rheo_path (argv[++i]);
}
else if (argv [i][0] == '-' && argv [i][1] == 'I') { append_dir_to_rheo_path (argv[i]+2); }
// output file option:
else if (strcmp (argv[i], "-geo") == 0) { dout.os() << rheo; render = file_render; }
else if (strcmp (argv[i], "-gmsh") == 0) { dout.os() << gmsh; render = gmsh_render; }
// render spec:
else if (strcmp (argv[i], "-gnuplot") == 0) { dout.os() << gnuplot; render = gnuplot_render; }
else if (strcmp (argv[i], "-paraview") == 0) { dout.os() << paraview; render = paraview_render; }
// render option:
else if (strcmp (argv[i], "-full") == 0) { dout.os() << full; }
else if (strcmp (argv[i], "-nofull") == 0) { dout.os() << nofull; }
else if (strcmp (argv[i], "-fill") == 0) { dout.os() << fill; }
else if (strcmp (argv[i], "-nofill") == 0) { dout.os() << nofill; }
else if (strcmp (argv[i], "-stereo") == 0) { dout.os() << stereo; do_stereo = true; }
else if (strcmp (argv[i], "-nostereo") == 0) { dout.os() << nostereo; }
else if (strcmp (argv[i], "-cut") == 0) { dout.os() << cut; }
else if (strcmp (argv[i], "-nocut") == 0) { dout.os() << nocut; }
else if (strcmp (argv[i], "-shrink") == 0) { dout.os() << shrink; }
else if (strcmp (argv[i], "-noshrink") == 0) { dout.os() << noshrink; }
else if (strcmp (argv[i], "-lattice") == 0) { dout.os() << lattice; }
else if (strcmp (argv[i], "-nolattice") == 0) { dout.os() << nolattice; }
else if (strcmp (argv[i], "-showlabel") == 0) { dout.os() << showlabel; }
else if (strcmp (argv[i], "-noshowlabel") == 0){ dout.os() << noshowlabel; }
else if (strcmp (argv[i], "-subdivide") == 0) {
if (i == argc-1) { std::cerr << "geo -subdivide: option argument missing" << std::endl; usage(); }
size_t nsub = atoi(argv[++i]);
dout.os() << setsubdivide (nsub);
}
else if (strcmp (argv[i], "-image-format") == 0) {
if (i == argc-1) { std::cerr << "geo -image-format: option argument missing" << std::endl; usage(); }
std::string format = argv[++i];
if (format == "jpeg") format = "jpg";
if (format == "postscript") format = "ps";
dout.os() << setimage_format(format);
}
else if (strcmp (argv[i], "-resolution") == 0) {
if (i == argc-1 || !isdigit(argv[i+1][0])) { std::cerr << "geo -resolution: option argument missing" << std::endl; usage(); }
size_t nx = atoi(argv[++i]);
size_t ny = (i < argc-1 && isdigit(argv[i+1][0])) ? atoi(argv[++i]) : nx;
dout.os() << setresolution(point_basic<size_t>(nx,ny));
}
else if (strcmp (argv[i], "-round") == 0) {
do_round = true;
if (i+1 < argc && is_float(argv[i+1])) {
round_prec = to_float (argv[++i]);
}
}
// input options:
else if (strcmp (argv[i], "-upgrade") == 0) { do_upgrade = true; dout.os() << rheo; render = file_render; }
else if (strcmp (argv[i], "-check") == 0) { do_check = true; }
else if (strcmp (argv[i], "-name") == 0) {
if (i == argc-1) { std::cerr << "geo -name: option argument missing" << std::endl; usage(); }
name = argv[++i];
}
else if (strcmp (argv[i], "-if") == 0 ||
strcmp (argv[i], "-input-format") == 0) {
if (i == argc-1) { std::cerr << "geo "<<argv[i]<<": option argument missing" << std::endl; usage(); }
input_format = argv[++i];
}
else if (strcmp (argv[i], "-") == 0) {
filename = "-"; // geo on stdin
}
else if (argv[i][0] != '-') {
filename = argv[i]; // input on file
}
else { usage(); }
}
// ----------------------------
// geo treatment
// ----------------------------
if (filename == "") {
std::cerr << "geo: no input file specified" << std::endl;
usage();
} else if (filename == "-") {
// geo on stdin
if (do_upgrade) std::cin >> upgrade;
std::string thename;
if (name != "output") thename = name;
std::cin >> setbasename(thename);
set_input_format (din, input_format);
din >> omega;
dout.os() << setbasename(name) << reader_on_stdin;
} else {
// input geo on file
std::string suffix = input_format;
if (name == "output") {
name = get_basename(delete_suffix (delete_suffix (filename, "gz"), suffix));
}
idiststream ips;
ips.open (filename, suffix);
check_macro(ips.good(), "\"" << filename << "[."<<suffix<<"[.gz]]\" not found.");
if (do_upgrade) ips.is() >> upgrade;
std::string root_name = delete_suffix (delete_suffix(filename, "gz"), suffix);
name = get_basename (root_name);
ips.is() >> setbasename(name);
set_input_format (ips, input_format);
ips >> omega;
dout.os() << setbasename(name);
}
if (sys_coord != "") { omega.set_coordinate_system(sys_coord); }
if (do_add_bdry) { omega.boundary(); }
if (render == file_render) {
size_t nsub = iorheo::getsubdivide (std::cout);
if (nsub >= 2) {
geo_basic<Float,sequential> new_omega;
new_omega.build_by_subdividing (omega, nsub);
omega = new_omega;
}
}
if (do_check) {
check_macro (omega.check(bverbose), "geo check failed");
}
bool show = show_min_element_measure
|| show_max_element_measure
|| show_hmin || show_hmax
|| show_xmin || show_xmax
|| show_n_element || show_n_vertex || show_sys_coord;
if (show) {
if (show_hmin) { dout << "hmin = " << omega.hmin() << std::endl; }
if (show_hmax) { dout << "hmax = " << omega.hmax() << std::endl; }
if (show_xmin) { dout << "xmin = " << omega.xmin() << std::endl; }
if (show_xmax) { dout << "xmax = " << omega.xmax() << std::endl; }
if (show_n_element) { dout << "size = " << omega.dis_size() << std::endl; }
if (show_n_vertex) { dout << "n_vertex = " << omega.dis_size(0) << std::endl; }
if (show_sys_coord) { dout << "sys_coord = " << omega.coordinate_system_name() << std::endl; }
if (show_min_element_measure) {
dout << "min_element_measure = " << extrema_element_measure (omega, true) << std::endl;
}
if (show_max_element_measure) {
dout << "max_element_measure = " << extrema_element_measure (omega, false) << std::endl;
}
return 0;
}
if (do_round) {
dout.os() << setrounding_precision(round_prec);
}
if (render == no_render) {
// try to choose the best render from dimension
#if (_RHEOLEF_PARAVIEW_VERSION_MAJOR >= 5) && (_RHEOLEF_PARAVIEW_VERSION_MINOR >= 5)
// paraview version >= 5.5 has high order elements
if (do_stereo || omega.dimension() >= 2) {
#else
if (do_stereo || omega.dimension() == 3) {
#endif
dout.os() << paraview;
} else {
dout.os() << gnuplot;
}
}
dout << omega;
}
render_type
render_type
Definition: branch.cc:491
usage
void usage()
Definition: geo.cc:438
main
int main(int argc, char **argv)
Definition: geo.cc:516
set_input_format
void set_input_format(idiststream &in, std::string input_format)
Definition: geo.cc:464
render_type
render_type
Definition: geo.cc:474
file_render
@ file_render
Definition: geo.cc:483
gnuplot_render
@ gnuplot_render
Definition: geo.cc:476
no_render
@ no_render
Definition: geo.cc:475
paraview_render
@ paraview_render
Definition: geo.cc:477
gmsh_render
@ gmsh_render
Definition: geo.cc:480
vtk_render
@ vtk_render
Definition: geo.cc:479
x3d_render
@ x3d_render
Definition: geo.cc:482
plotmtv_render
@ plotmtv_render
Definition: geo.cc:478
atom_render
@ atom_render
Definition: geo.cc:481
extrema_element_measure
Float extrema_element_measure(const geo_basic< Float, sequential > &omega, bool is_min)
Definition: geo.cc:509
Float
see the Float page for the full documentation
point
see the point page for the full documentation
rheolef::environment
see the environment page for the full documentation
Definition: environment.h:115
rheolef::field_basic
Definition: field.h:235
rheolef::form_basic
Definition: form.h:144
rheolef::geo_basic
generic mesh with rerefence counting
Definition: geo.h:1089
rheolef::geo_element
see the geo_element page for the full documentation
Definition: geo_element.h:102
rheolef::odiststream::os
std::ostream & os()
Definition: diststream.h:236
rheolef::point_basic< size_t >
rheolef::space_basic
the finite element space
Definition: space.h:352
rheolef::point
point_basic< Float > point
Definition: point.h:164
rheolef::distributed
distributed
Definition: asr.cc:228
rheolef::din
idiststream din
see the diststream page for the full documentation
Definition: diststream.h:427
rheolef::dout
odiststream dout(cout)
see the diststream page for the full documentation
Definition: diststream.h:430
check_macro
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
bamg
verbose clean transpose logscale grid shrink ball stereo iso volume skipvtk deformation fastfieldload lattice reader_on_stdin color format format bamg
Definition: iorheo-members.h:71
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 format format paraview
Definition: iorheo-members.h:125
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 format format format gnuplot
Definition: iorheo-members.h:121
vtk
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
Definition: iorheo-members.h:113
rheo
verbose clean transpose logscale grid shrink ball stereo iso volume skipvtk deformation fastfieldload lattice reader_on_stdin color rheo
Definition: iorheo-members.h:65
gmsh
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
Definition: iorheo-members.h:83
mkgeo_ball.clean
clean
Definition: mkgeo_ball.sh:335
mkgeo_ball.verbose
verbose
Definition: mkgeo_ball.sh:133
mkgeo_contraction.hmin
float hmin
Definition: mkgeo_contraction.sh:129
mkgeo_contraction.ny
ny
Definition: mkgeo_contraction.sh:150
mkgeo_contraction.nx
string nx
Definition: mkgeo_contraction.sh:124
mkgeo_contraction.name
string name
Definition: mkgeo_contraction.sh:133
mkgeo_grid.sys_coord
string sys_coord
Definition: mkgeo_grid.sh:171
mkgeo_sector.m
m
Definition: mkgeo_sector.sh:118
rheolef::details::max_abs
T max_abs(const T &x)
Definition: keller_details.h:47
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::dist
T dist(const point_basic< T > &x, const point_basic< T > &y)
Definition: point.h:299
rheolef::delete_suffix
string delete_suffix(const string &name, const string &suffix)
delete_suffix: see the rheostream page for the full documentation
Definition: rheostream.cc:222
rheolef::get_basename
string get_basename(const string &name)
get_basename: see the rheostream page for the full documentation
Definition: rheostream.cc:254
rheolef::is_float
bool is_float(const string &s)
is_float: see the rheostream page for the full documentation
Definition: rheostream.cc:476
rheolef::append_dir_to_rheo_path
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:330
rheolef::pow
space_mult_list< T, M > pow(const space_basic< T, M > &X, size_t n)
Definition: space_mult.h:120
rheolef::to_float
Float to_float(const string &s)
to_float: see the rheostream page for the full documentation
Definition: rheostream.cc:494
rheolef.h
rheolef - reference manual