2
/// This file is part of Rheolef.
4
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
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.
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.
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
20
/// =========================================================================
22
NAME: @code{geo} - plot a finite element mesh
26
@cindex mesh graphic representation
30
geo @var{options} @var{mesh}[.geo[.gz]]
34
Plot or upgrade a finite element mesh.
42
Plot a mesh into a file:
44
geo square.geo -image-format png
46
Convert from a old geo file format to the new one:
48
geo -upgrade - < square-old.geo > square.geo
50
See below for the geo file format scpecification.
51
The old file format does not contains edges and faces connectivity in 3d geometries,
52
or edges connectivity in 2d geometries.
53
The converter add it automatically into the upgraded file format.
54
Conversely, the old file format is usefull when combined with a
55
translator from another file format that do not provides edges and faces connectivity.
57
INPUT FILE SPECIFICATION:
60
specifies the name of the file containing
62
The ".geo" suffix extension is assumed.
64
read mesh on standard input instead on a file.
66
when mesh comes from standard input, the mesh name
67
is not known and is set to "output" by default.
68
This option allows to change this default.
69
Useful when dealing with output formats (graphic, format conversion)
70
that creates auxilliary files, based on this name.
71
@cindex RHEOPATH environment variable
74
Add @var{dir} to the rheolef file search path.
75
This mechanism initializes a search path given by the environment variable @samp{RHEOPATH}.
76
If the environment variable @samp{RHEOPATH} is not set, the default value is the current directory.
78
Check that element orientation is positive.
83
@fiindex @file{.bamg} mesh file
85
@fiindex @file{.vtk} mesh file
87
@itemx -if @var{format}
88
@itemx -input-format @var{format}
89
load mesh in @var{format} file format,
90
instead of plotting it.
91
Supported output formats are: @code{geo}, @code{bamg}, @code{vtk}.
92
When loading from a file, the corresponding suffix extension is assumed.
96
@cindex graphic render
97
@toindex @code{gnuplot}
102
@toindex @code{mayavi}
104
use @code{mayavi} tool.
111
When using a high order geometry, the lattice inside any element appears.
113
@itemx -subdivide int
114
When using a high order geometry, the number of points per edge used to draw
115
a curved element. Default value is the mesh order.
118
All internal edges appears, for 3d meshes.
122
Fill mesh faces using light effects, when available.
123
@cindex @code{stereo 3D rendering}
126
Rendering mode suitable for red-blue anaglyph 3D stereoscopic glasses.
127
Option only available with @code{mayavi}.
130
cut by plane and clip (with @code{mayavi} only).
133
OUTPUT FILE FORMAT OPTIONS:
136
output mesh on standard output stream in geo text file format,
137
instead of plotting it.
139
Convert from a old geo file format to the new one.
141
@fiindex @file{.gmsh} mesh file
143
output mesh on standard output stream in gmsh text file format,
144
instead of plotting it.
145
@cindex graphic render
146
@cindex image file format
147
@cindex graphic render
148
@fiindex @file{.png} image
149
@fiindex @file{.gif} image
150
@fiindex @file{.jpg} image
151
@fiindex @file{.ps} image
152
@fiindex @file{.pdf} image
153
@itemx -image-format @code{string}
154
The argument is any valid image format, such as
155
bitmap @code{png}, @code{jpg}, @code{gif} or vectorial @code{ps} or @code{pdf}
156
image file formats, and that could be handled by the corresponding render.
157
The output file is e.g. @file{@emph{basename}.png} when @emph{basename}
158
is the name of the mesh, or can be set with the @code{-name} option.
164
check for a domain named "boundary"; If this domain
165
does not exists, extract the boundary of the geometry
166
and append it to the domain list.
168
This command is usefull for mesh converted from
169
generators, as @code{bamg}, that cannot have more than
170
one domain specification per boundary edge.
173
print messages related to graphic files created and
174
command system calls (this is the default).
177
does not print previous messages.
180
clear temporary graphic files (this is the default).
183
does not clear temporary graphic files.
186
execute graphic command (this is the default).
189
does not execute graphic command. Generates only
190
graphic files. This is usefull in conjuction with the
195
used for debug purpose.
204
AUTHOR: Pierre.Saramito@imag.fr
205
DATE: 16 september 2011
209
# include "rheolef/geo.h"
210
# include "rheolef/iorheo.h"
211
# include "rheolef/iofem.h"
212
# include "rheolef/rheostream.h"
213
using namespace rheolef;
216
cerr << "geo: usage:" << endl
218
<< "{-|file[.geo[.gz]]}"
222
<< "[-if {geo,bamg,vtk}] "
223
<< "[-geo|-gmsh|-gnuplot|-mayavi] "
225
<< "[-[no]full|-[no]fill|-[no]lattice] "
226
<< "[-subdivide int] "
227
<< "[-[no]stereo|-[no]full|-[no]cut] "
228
<< "[-image-format string] "
229
<< "[-add-boundary] "
230
<< "[-[no]clean] [-[no]execute] [-[no]verbose] "
234
void set_input_format (idiststream& in, std::string input_format)
236
if (input_format == "bamg") in.is() >> bamg;
237
else if (input_format == "vtk") in.is() >> vtk;
238
else if (input_format == "geo") in.is() >> rheo;
240
cerr << "geo: invalid input format \""<<input_format<<"\"" << endl;
257
void add_boundary (const geo_basic<T,sequential>& omega)
260
typedef typename geo_basic<T,sequential>::size_type size_type;
261
typedef pair<size_type,size_type> pair_t;
262
typedef heap_allocator<size_type> alloc_t;
263
typedef geo_element_auto<alloc_t> element_t;
264
typedef array<element_t, sequential, alloc_t> e_array_t;
266
if (omega.have_domain_indirect ("boundary")) return;
267
size_type map_dim = omega.map_dimension();
268
if (map_dim == 0) return;
270
vector<index_set> ball[4];
272
// 1) vertice-to-element map:
273
ball[map_dim].resize (omega.n_vertex());
274
for (size_type ie = 0, ne = omega.size(map_dim); ie < ne; ie++) {
275
const geo_element& K = omega.get_geo_element (map_dim, ie);
276
for (size_type iloc = 0, nloc = K.size(); iloc < nloc; iloc++) {
277
ball [map_dim][K[iloc]].insert(ie);
280
// 2) scan sides, count adjacency and list bdry side indexes
281
size_type sub_map_dim = map_dim-1;
282
std::list<size_type, alloc_t> iside;
283
for (size_type is = 0, ns = omega.size(sub_map_dim); is < ns; is++) {
284
const geo_element& S = omega.get_geo_element (sub_map_dim, is);
285
index_set adj = ball [map_dim][S[0]];
286
for (size_type iloc = 1, nloc = S.size(); iloc < nloc; iloc++) {
287
adj.inplace_intersection (ball [map_dim][S[iloc]]);
289
if (adj.size() != 1) continue;
290
// here S is a boundary side:
291
iside.push_back (is);
294
// 3) copy sides to a bdry array
296
element_t dummy_elt (reference_element::p, 0, alloc);
297
e_array_t bdry_tmp (iside.size(), dummy_elt, alloc);
299
for (typename std::list<size_type, alloc_t>::const_iterator iter = iside.begin(), last = iside.end();
300
iter != last; ++iter, ++ibdr) {
301
size_type is = *iter;
302
bdry_tmp [ibdr] = omega.get_geo_element (sub_map_dim, is);
304
// 4) insert the bdry array into the mesh
305
domain_indirect_basic<sequential> bdry (bdry_tmp, omega, ball);
306
bdry.set_name ("boundary");
307
omega.insert_domain_indirect (bdry);
309
int main(int argc, char**argv) {
310
environment distributed(argc, argv);
311
check_macro (communicator().size() == 1, "geo: command may be used as mono-process only");
312
// ----------------------------
314
// ----------------------------
315
bool do_upgrade = false ;
316
bool do_check = false ;
317
bool do_add_bdry = false ;
318
string name = "output";
319
dout.os() << verbose; bool bverbose = true;
320
render_type render = no_render;
321
geo_basic<Float,sequential> omega;
322
dout.os() << lattice;
326
dout.os() << setorigin (point(0,0,0));
327
dout.os() << setnormal (point(1,0,0));
330
string input_format = "geo";
331
// ----------------------------
332
// scan the command line
333
// ----------------------------
334
for (int i = 1; i < argc; i++) {
337
if (strcmp (argv[i], "-clean") == 0) dout.os() << clean;
338
else if (strcmp (argv[i], "-noclean") == 0) dout.os() << noclean;
339
else if (strcmp (argv[i], "-execute") == 0) dout.os() << execute;
340
else if (strcmp (argv[i], "-noexecute") == 0) dout.os() << noexecute;
341
else if (strcmp (argv[i], "-verbose") == 0) { bverbose = true; dout.os() << verbose; }
342
else if (strcmp (argv[i], "-noverbose") == 0) { bverbose = false; dout.os() << noverbose; }
343
else if (strcmp (argv[i], "-add-boundary") == 0) { do_add_bdry = true; }
344
else if (strcmp (argv[i], "-I") == 0) {
345
if (i == argc-1) { cerr << "geo -I: option argument missing" << endl; usage(); }
346
append_dir_to_rheo_path (argv[++i]);
348
else if (argv [i][0] == '-' && argv [i][1] == 'I') { append_dir_to_rheo_path (argv[i]+2); }
349
// output file option:
350
else if (strcmp (argv[i], "-geo") == 0) { dout.os() << rheo; render = file_render; }
351
else if (strcmp (argv[i], "-gmsh") == 0) { dout.os() << gmsh; render = gmsh_render; }
354
else if (strcmp (argv[i], "-gnuplot") == 0) { dout.os() << gnuplot; render = gnuplot_render; }
355
else if (strcmp (argv[i], "-mayavi") == 0) { dout.os() << mayavi; render = mayavi_render; }
358
else if (strcmp (argv[i], "-full") == 0) { dout.os() << full; }
359
else if (strcmp (argv[i], "-nofull") == 0) { dout.os() << nofull; }
360
else if (strcmp (argv[i], "-fill") == 0) { dout.os() << fill; }
361
else if (strcmp (argv[i], "-nofill") == 0) { dout.os() << nofill; }
362
else if (strcmp (argv[i], "-stereo") == 0) { dout.os() << stereo << mayavi; render = mayavi_render; }
363
else if (strcmp (argv[i], "-nostereo") == 0) { dout.os() << nostereo; }
364
else if (strcmp (argv[i], "-cut") == 0) { dout.os() << cut; }
365
else if (strcmp (argv[i], "-nocut") == 0) { dout.os() << nocut; }
366
else if (strcmp (argv[i], "-lattice") == 0) { dout.os() << lattice; }
367
else if (strcmp (argv[i], "-nolattice") == 0) { dout.os() << nolattice; }
368
else if (strcmp (argv[i], "-subdivide") == 0) {
369
if (i == argc-1) { cerr << "geo -subdivide: option argument missing" << endl; usage(); }
370
size_t nsub = atoi(argv[++i]);
371
dout.os() << setsubdivide (nsub);
373
else if (strcmp (argv[i], "-image-format") == 0) {
374
if (i == argc-1) { cerr << "geo -image-format: option argument missing" << endl; usage(); }
375
string format = argv[++i];
376
if (format == "jpeg") format = "jpg";
377
if (format == "postscript") format = "ps";
378
dout.os() << setimage_format(format);
382
else if (strcmp (argv[i], "-upgrade") == 0) { do_upgrade = true; dout.os() << rheo; render = file_render; }
383
else if (strcmp (argv[i], "-check") == 0) { do_check = true; }
384
else if (strcmp (argv[i], "-name") == 0) {
385
if (i == argc-1) { cerr << "geo -name: option argument missing" << endl; usage(); }
388
else if (strcmp (argv[i], "-if") == 0 ||
389
strcmp (argv[i], "-input-format") == 0) {
390
if (i == argc-1) { cerr << "geo "<<argv[i]<<": option argument missing" << endl; usage(); }
391
input_format = argv[++i];
393
else if (strcmp (argv[i], "-") == 0) {
394
filename = "-"; // geo on stdin
396
else if (argv[i][0] != '-') {
397
filename = argv[i]; // input on file
401
// ----------------------------
403
// ----------------------------
404
if (filename == "") {
405
cerr << "geo: no input file specified" << endl;
407
} else if (filename == "-") {
409
if (do_upgrade) cin >> upgrade;
411
if (name != "output") thename = name;
412
cin >> setbasename(thename);
413
set_input_format (din, input_format);
415
dout.os() << setbasename(name) << reader_on_stdin;
418
string suffix = input_format;
419
if (name == "output") {
420
name = get_basename(delete_suffix (delete_suffix (filename, "gz"), suffix));
423
ips.open (filename, suffix);
424
check_macro(ips.good(), "\"" << filename << "[."<<suffix<<"[.gz]]\" not found.");
425
if (do_upgrade) ips.is() >> upgrade;
426
std::string root_name = delete_suffix (delete_suffix(filename, "gz"), suffix);
427
std::string name = get_basename (root_name);
428
ips.is() >> setbasename(name);
429
set_input_format (ips, input_format);
431
dout.os() << setbasename(name);
434
add_boundary (omega);
437
check_macro (omega.check(bverbose), "geo check failed");
439
if (render == no_render) { dout.os() << gnuplot; }