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
/// =========================================================================
23
// \int_\Omega 2 D(u):D(v) r dr dz
25
// check value on the unit square [0,1]^2
27
// component 0 : we check the u_r component : u_z = 0
28
// and u_r takes monomial values : 1, r, ...
29
// component 1 : u_r = 0 and u_z is monomial
31
#include "rheolef/rheolef.h"
34
typedef Float (*function_type)(const point&);
38
function_type function;
40
Float monom_1 (const point& x) { return 1; }
41
Float monom_r (const point& x) { return x[0]; }
42
Float monom_z (const point& x) { return x[1]; }
43
Float monom_r2 (const point& x) { return x[0]*x[0]; }
44
Float monom_rz (const point& x) { return x[0]*x[1]; }
45
Float monom_z2 (const point& x) { return x[1]*x[1]; }
49
list_type rz_monom_list [] = {
59
const unsigned int rz_monom_max = sizeof(rz_monom_list)/sizeof(list_type);
63
const Float infty = -1;
65
Float expect_table [2][2] [rz_monom_max][rz_monom_max] = {
70
{ infty, 2, infty, 1, 1, infty},
71
{ 2, 2, 1, 2, 1, T(2)/3},
72
{ infty, 1, infty, 0.5, 1, infty},
74
{ 1, 2, 0.5, 2.5, 1, T(1)/3},
75
{ 1, 1, 1, 1, T(11)/12, T(5)/6},
76
{ infty, T(2)/3, infty, T(1)/3, T(5)/6, infty}
82
{ 0, 0.5, 0, T(2)/3, 0.25, 0},
84
{ 0, T(1)/3, 0, 0.5, T(1)/6, 0},
85
{ 0, 0.5, 0, T(2)/3, T(1)/3, 0}
89
// a([0,uz],[vr,0]) : not yet
98
// a([0,uz],[0,vz]) : not yet
111
cerr << "form_2D_D_tst: usage: form_2D_D_tst"
114
<< " [-approx string]"
115
<< " [-u-component int]"
116
<< " [-v-component int]"
117
<< " [-u-monom string]"
118
<< " [-v-monom string]"
120
cerr << "example:\n";
121
cerr << " form_2D_D_tst square -u-monom rz -v-monom r -u-component 0 -v-component 0\n";
124
int main(int argc, char**argv)
127
// load geometry and options
130
string coord_sys = "rz";
131
string approx = "P2";
132
bool mesh_done = false;
135
string u_monom_id = "";
136
function_type u_monom_function = 0;
137
unsigned int u_monom_idx = 0;
138
string v_monom_id = "";
139
function_type v_monom_function = 0;
140
unsigned int v_monom_idx = 0;
142
if (argc <= 1) usage() ;
144
for (int i = 1; i < argc; i++ ) {
146
if (argv [i][0] == '-' && argv [i][1] == 'I')
147
append_dir_to_rheo_path (argv[i]+2) ;
148
else if (strcmp(argv[i], "-approx") == 0)
150
else if (strcmp(argv[i], "-u-component") == 0)
151
i_comp_u = atoi(argv[++i]);
152
else if (strcmp(argv[i], "-v-component") == 0)
153
i_comp_v = atoi(argv[++i]);
154
else if (strcmp(argv[i], "-u-monom") == 0) {
155
u_monom_id = argv[++i];
156
for (unsigned int i = 0; i < rz_monom_max; i++) {
157
if (u_monom_id == rz_monom_list [i].name) {
158
u_monom_function = rz_monom_list [i].function;
162
} else if (strcmp(argv[i], "-v-monom") == 0) {
163
v_monom_id = argv[++i];
164
for (unsigned int i = 0; i < rz_monom_max; i++) {
165
if (v_monom_id == rz_monom_list [i].name) {
166
v_monom_function = rz_monom_list [i].function;
170
} else if (strcmp(argv[i], "-") == 0) {
171
// input geo on standard input
172
if (mesh_done) usage() ;
173
cerr << " ! load geo on stdin" << endl ;
178
if (mesh_done) usage() ;
179
cerr << " ! load " << argv[i] << endl ;
180
omega = geo(argv[i]);
185
cerr << "form_2D_D_tst: no mesh specified" << endl;
188
omega.set_coordinate_system (coord_sys);
189
if (!u_monom_function) {
190
error_macro("invalid u-monom identifier: " << u_monom_id);
192
if (!v_monom_function) {
193
error_macro("invalid v-monom identifier: " << v_monom_id);
195
cerr << "syscoord = " << omega.coordinate_system() << endl;
196
cerr << "u_monom = " << u_monom_id << endl;
197
cerr << "v_monom = " << v_monom_id << endl;
198
space V0h(omega, approx);
200
field u_monom (Vh, Float(0));
201
u_monom[i_comp_u] = interpolate (V0h, u_monom_function);
202
field v_monom (Vh, Float(0));
203
v_monom[i_comp_v] = interpolate (V0h, v_monom_function);
204
form a (Vh,Vh,"2D_D");
205
Float result = a(u_monom, v_monom);
206
string u_vec_monom_id;
207
string v_vec_monom_id;
208
if (i_comp_u == 0) u_vec_monom_id = u_monom_id + ",0";
209
else u_vec_monom_id = "0," + u_monom_id;
210
if (i_comp_v == 0) v_vec_monom_id = v_monom_id + ",0";
211
else v_vec_monom_id = "0," + v_monom_id;
212
cerr << setprecision(numeric_limits<Float>::digits10)
213
<< "a(omega," << approx << "[" << u_vec_monom_id << "]," << approx << "[" << v_vec_monom_id << "]) = " << double(result) << endl;
214
Float expect = expect_table [i_comp_u][i_comp_v][u_monom_idx][v_monom_idx];
217
if (expect == infty) {
218
cerr << "ok (expect infty)" << endl;
220
} else if (fabs(result - expect) <= tol) {
221
cerr << "ok" << endl;
224
cerr << "but it was expected " << expect << endl;
225
cerr << "and error = " << fabs(result - expect) << endl;
226
cerr << "and tol = " << tol << endl;