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
// test des formes grad_grad_s et mass_s
26
using namespace rheolef;
27
// --------------------------------------------------------------------------------
29
// --------------------------------------------------------------------------------
30
point origin (0.5,0.5,0);
33
Float levelset_function (const point& x) {
34
return dot(normal, x-origin); // definition de la fonction level set//
38
Float u (const point& x) {
39
if (i_test == "1") return 1;
40
if (i_test == "x") return x[0];
41
if (i_test == "y") return x[1];
42
if (i_test == "z") return x[2];
43
if (i_test == "x2") return sqr(x[0]);
44
if (i_test == "y2") return sqr(x[1]);
45
if (i_test == "z2") return sqr(x[2]);
46
if (i_test == "xy") return x[0]*x[1];
47
if (i_test == "xz") return x[0]*x[2];
48
if (i_test == "yz") return x[1]*x[2];
49
error_macro ("invalid test " << i_test);
51
void save_as_matlab (const form& a, string name = "a") {
52
string filename = "matrix-" + name + ".m";
53
ofstream out (filename.c_str());
54
cerr << "! file " << filename << " created." << endl;
55
out << setprecision(15)
56
<< name << " = " << matlab << a.uu << ";" << endl
57
<< "vp = eig(" << name <<");" << endl
58
<< "printf (\"vp = %26.16g\\n\", vp);" << endl
59
<< "d = det(" << name << ")" << endl
63
void save_as_matlab (const field& u, string name = "u") {
64
string filename = "vector-" + name + ".m";
65
ofstream out (filename.c_str());
66
cerr << "! file " << filename << " created." << endl;
67
out << setprecision(15)
68
<< name << " = " << matlab << u.u << ";" << endl
74
cerr << "usage: grad_grad_tst "
84
int main (int argc, char**argv)
89
for (int i = 1; i < argc; i++) {
91
if (strcmp (argv[i], "-test") == 0) {
92
if (i+1 == argc) usage();
94
} else if (strcmp (argv[i], "-a") == 0) {
95
if (i+1 == argc || !is_float(argv[i+1])) usage();
96
a_valid = to_float (argv[++i]);
97
} else if (strcmp (argv[i], "-m") == 0) {
98
if (i+1 == argc || !is_float(argv[i+1])) usage();
99
m_valid = to_float (argv[++i]);
100
} else if ((strcmp (argv[i], "-origin") == 0) || (strcmp (argv[i], "-normal") == 0)) {
103
if (i+1 == argc || !is_float(argv[i+1])) {
104
warning_macro ("invalid argument to `" << argv[i] << "'");
107
x[0] = to_float (argv[++i]);
108
if (i+1 < argc && is_float(argv[i+1])) {
109
x[1] = to_float (argv[++i]);
110
if (i+1 < argc && is_float(argv[i+1])) {
111
x[2] = to_float (argv[++i]);
114
if (strcmp (argv[io], "-origin") == 0) {
124
if (filename == "") usage();
126
space Vh (mesh, "P1");
127
field phi_h_lambda = interpolate(Vh, levelset_function);
128
geo band = banded_level_set (phi_h_lambda);
129
if (mesh.dimension() == 3) {
130
cout << "$ DATA = CONTCURVE" << endl
131
<< "% equalscale" << endl
132
<< "%contstyle=2 # fill color painting" << endl
133
<< "%meshplot" << endl
134
<< "%contlabel=false # write labels when using line style contours" << endl;
136
phi_h_lambda.save("phi");
137
space Bh (band, "P1");
138
field phi_h = interpolate(Bh, levelset_function);
139
form a = form (Bh, Bh, "grad_grad_s", phi_h);
140
form m = form (Bh, Bh, "mass_s", phi_h);
141
save_as_matlab (a, "a");
142
save_as_matlab (m, "m");
143
save_as_matlab (phi_h, "phi");
144
field uh = interpolate (Bh, u);
145
Float a_tst = a(uh,uh);
146
Float m_tst = m(uh,uh);
147
cerr << setprecision(15);
148
cerr << "m(uh,uh)=" << m_tst << endl;
149
cerr << "a(uh,uh)=" << a_tst << endl;
151
bool status = (fabs(a_tst - a_valid) < tol) && (m_valid < 0 || fabs(m_tst - m_valid) < tol) ;
153
if ( fabs(a_tst - a_valid) >= tol) cerr << "ERROR: a(uh,uh)=" << a_tst << " != " << a_valid << endl;
154
if (m_valid >= 0 && fabs(m_tst - m_valid) >= tol) cerr << "ERROR: m(uh,uh)=" << m_tst << " != " << m_valid << endl;
156
return (status ? 0 : 1);