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
/// =========================================================================
21
# include <rheolef/compiler.h>
22
using namespace rheolef;
25
// generate a mesh for a square
26
// ----------------------------
36
# define no(i,j) ((i)*(ny+1)+(j))
38
void usage(const char *prog)
40
cerr << "uniform grid nx*ny for the [a,b]x[c,d] rectangle" << endl
43
<< "[-t|-q] [nx="<<nx<<"] [ny=nx] "
44
<< "[-a float=" << A << "] [-b float=" << B << "] [-c float=" << C << "] [-d float=" << D << "] "
45
<< "[-boundary] " << endl
46
<< "[-region] " << endl
48
<< "[-corner] " << endl
50
<< prog << " -t 10" << endl
51
<< prog << " -t 10 20" << endl
55
int main (int argc, char**argv)
58
bool boundary = false;
61
bool axisymmetric = false;
62
if (argc == 1) usage(prog);
64
// machine-dependent precision
65
int digits10 = numeric_limits<Float>::digits10;
66
cout << setprecision(digits10);
71
// default nb edge on x axis
74
// default nb edge on y axis
80
for (i = 1; i < argc; i++) {
85
if (strcmp (argv[i], "-boundary") == 0) { boundary = true; }
86
else if (strcmp (argv[i], "-region") == 0) { region = true; }
87
else if (strcmp (argv[i], "-rz") == 0) { axisymmetric = true; }
88
else if (strcmp (argv[i], "-corner") == 0) { corner = true; }
89
else switch (argv[i][1]) {
91
case 't' : type = TRI; break;
92
case 'q' : type = QUA; break;
94
case 'a' : A = atof (argv[++i]); break;
95
case 'b' : B = atof (argv[++i]); break;
96
case 'c' : C = atof (argv[++i]); break;
97
case 'd' : D = atof (argv[++i]); break;
99
default : usage(prog);
107
nx = ny = atoi(argv[i]);
113
if (A >= B || C >= D) {
114
cerr << prog << ": [a,b]x[c,d] may be non-empty.\n";
117
if (region && nx % 2 != 0) {
118
cerr << prog << ": region: nx may be an even number.\n";
121
if (type == TRI) cerr << "triangular" ; else cerr << "quadrangular" ;
122
cerr << " mesh " << nx << " x " << ny << "\n" ;
124
int n_vert = (nx+1)*(ny+1);
129
n_edg = 3*nx*ny+nx+ny; // = (nx+1)*ny + (ny+1)*nx + nx*ny
132
n_edg = 2*nx*ny+nx+ny; // = (nx+1)*ny + (ny+1)*nx
135
size_t version = (axisymmetric ? 3 : 2);
136
cout << "#!geo\n\nmesh\n"
137
<< version << " 2 " << n_vert << " " << n_elt << " " << n_edg << "\n";
139
cout << "coordinate_system rz" << endl;
143
for( i= 0 ; i <= nx ; i++ )
144
for( j= 0 ; j <= ny ; j++ )
145
cout << (B-A)*i/Float(nx)+A << " " << (D-C)*j/Float(ny)+C << "\n" ;
150
for (i = 0; i < nx; i++) {
151
for (j = 0; j < ny; j++) {
153
cout << "t\t" << no(i,j) << " " << no(i+1,j) << " " << no(i+1,j+1)
154
<< "\nt\t" << no(i,j) << " " << no(i+1,j+1) << " " << no(i,j+1) << "\n" ;
156
cout << "q\t" << no(i,j) << " " << no(i+1,j) << " "
157
<< no(i+1,j+1) << " " << no(i,j+1) << "\n" ;
163
for( int i_ve=0 ; i_ve < nx+1 ; i_ve++ )
164
for( int j_ve=0 ; j_ve < ny ; j_ve++ )
165
cout << no(i_ve, j_ve) << " " << no(i_ve, j_ve+1) << "\n" ;
167
for( int i_he=0 ; i_he < nx ; i_he++ )
168
for( int j_he=0 ; j_he < ny+1 ; j_he++ )
169
cout << no(i_he, j_he) << " " << no(i_he+1, j_he) << "\n" ;
170
// diagonal (TRI only)
172
for ( int i_elt = 0 ; i_elt < nx ; i_elt++ )
173
for ( int j_elt = 0 ; j_elt < ny ; j_elt++ )
174
cout << no(i_elt, j_elt) << " " << no(i_elt+1, j_elt+1) << "\n" ;
180
cout << "domain\nboundary\n1 1 " << 2*(nx+ny) << "\n" ;
182
cout << "domain\nbottom\n1 1 " << nx << "\n" ;
184
for (i = 0; i < nx; i++)
185
cout << no(i,0) << " " << no(i+1,0) << "\n" ;
187
if (!boundary) cout << "\ndomain\nright\n1 1 " << ny << "\n" ;
188
for (j = 0; j < ny; j++)
189
cout << no(nx,j) << " " << no(nx,j+1) << "\n" ;
191
if (!boundary) cout << "\ndomain\ntop\n1 1 " << nx << "\n" ;
192
for (i = 0; i < nx; i++)
193
cout << no(i+1,ny) << " " << no(i,ny) << "\n" ;
195
if (!boundary) cout << "\ndomain\nleft\n1 1 " << ny << "\n" ;
196
for (j = 0; j < ny; j++)
197
cout << no(0,j+1) << " " << no(0,j) << "\n" ;
201
int n_face = (type == TRI) ? nx*ny : nx*ny/2;
202
cout << "\ndomain\nwest\n1 2 " << n_face << "\n" ;
203
for (i = 0; i < nx/2; i++) {
204
for (j = 0; j < ny; j++) {
206
cout << "t\t" << no(i,j) << " " << no(i+1,j) << " " << no(i+1,j+1)
207
<< "\nt\t" << no(i,j) << " " << no(i+1,j+1) << " " << no(i,j+1) << "\n" ;
209
cout << "q\t" << no(i,j) << " " << no(i+1,j) << " "
210
<< no(i+1,j+1) << " " << no(i,j+1) << "\n" ;
214
cout << "\ndomain\neast\n1 2 " << n_face << "\n" ;
215
for (i = nx/2; i < nx; i++) {
216
for (j = 0; j < ny; j++) {
218
cout << "t\t" << no(i,j) << " " << no(i+1,j) << " " << no(i+1,j+1)
219
<< "\nt\t" << no(i,j) << " " << no(i+1,j+1) << " " << no(i,j+1) << "\n" ;
221
cout << "q\t" << no(i,j) << " " << no(i+1,j) << " "
222
<< no(i+1,j+1) << " " << no(i,j+1) << "\n" ;
226
// corners = 4 0d-domains
228
cout << "\ndomain\nleft_bottom\n1 0 1\n" << no( 0, 0) << endl
229
<< "\ndomain\nright_bottom\n1 0 1\n" << no(nx, 0) << endl
230
<< "\ndomain\nleft_top\n1 0 1\n" << no(0, ny) << endl
231
<< "\ndomain\nright_top\n1 0 1\n" << no(nx,ny) << endl