rheolef  6.5
p_laplacian_post.cc
Go to the documentation of this file.
1 #include "rheolef.h"
2 using namespace rheolef;
3 using namespace std;
4 #include "eta.icc"
5 void usage(string name) {
6  derr << name << ": usage: "
7  << name << " "
8  << "[-|file[.field[.gz]]] "
9  << "[-check] "
10  << "[-residue] "
11  << "[-criteria] "
12  << endl;
13  exit (1);
14 }
15 field residue (Float p, const field& uh) {
16  const space& Xh = uh.get_space();
17  trial u (Xh); test v (Xh);
18  field lh = integrate (v);
19  form m = integrate (u*v);
22  qopt.set_order (2*Xh.degree()-1);
23  form a = integrate (compose (eta(p), norm2(grad(uh)))*dot(grad(u),grad(v)), qopt);
24  field mrh = a*uh - lh;
25  mrh["boundary"] = 0;
26  field rh (Xh);
27  solver sm = ldlt(m.uu());
28  rh.set_u() = sm.solve(mrh.u());
29  rh["boundary"] = 0;
30  return rh;
31 }
32 void check (Float p, const field& uh) {
33  field rh = residue(p, uh);
34  const space& Xh = rh.get_space();
35  trial u (Xh); test v (Xh);
36  form m = integrate (u*v);
37  Float res = sqrt(m(rh,rh));
38  derr << "check: residue = " << res << endl;
39  check_macro (res < 1e-3, "unexpected residue");
40 }
41 field criteria (Float p, const field& uh) {
42  const space& Xh = uh.get_space();
43  if (uh.get_approx() == "P1") return interpolate (Xh, abs(uh));
44  return interpolate (Xh, pow(norm(grad(uh)), p/2));
45 }
46 void
47 load (idiststream& in, Float& p, field& uh) {
48  in >> catchmark("p") >> p
49  >> catchmark("u") >> uh;
50 }
51 int main(int argc, char**argv) {
52  environment rheolef (argc,argv);
53  if (argc < 3) usage(argv[0]);
54  Float p;
55  field uh;
56  if (string (argv[1]) == "-") {
57  load (din, p, uh);
58  } else {
59  idiststream in;
60  in.open(argv[1], "field");
61  load (in, p, uh);
62  }
63  for (int i = 2; i < argc; i++) {
64  if (strcmp (argv[i], "-check") == 0) { check (p, uh); }
65  else if (strcmp (argv[i], "-residue") == 0) { dout << catchmark("ru") << residue (p, uh); }
66  else if (strcmp (argv[i], "-criteria") == 0) { dout << catchmark("c") << criteria (p, uh); }
67  else {
68  derr << argv[0] << ": unknown option \'" << argv[i] << "'" << endl;
69  usage(argv[0]);
70  }
71  }
72 }
73