Rheolef  7.2
an efficient C++ finite element environment
p_laplacian_post.cc
Go to the documentation of this file.
1 #include "rheolef.h"
22 using namespace rheolef;
23 using namespace std;
24 #include "eta.h"
25 void usage(string name) {
26  derr << name << ": usage: "
27  << name << " "
28  << "[-|file[.field[.gz]]] "
29  << "[-check] "
30  << "[-residue] "
31  << "[-criteria] "
32  << endl;
33  exit (1);
34 }
35 field residue (Float p, const field& uh) {
36  const space& Xh = uh.get_space();
37  trial u (Xh); test v (Xh);
38  field lh = integrate (v);
39  form m = integrate (u*v);
40  form a = integrate (compose (eta(p), norm2(grad(uh)))*dot(grad(u),grad(v)));
41  field mrh = a*uh - lh;
42  mrh["boundary"] = 0;
43  field rh (Xh);
44  problem pm (m);
45  pm.solve(mrh, rh);
46  rh["boundary"] = 0;
47  return rh;
48 }
49 void check (Float p, const field& uh) {
50  field rh = residue(p, uh);
51  const space& Xh = rh.get_space();
52  trial u (Xh); test v (Xh);
53  form m = integrate (u*v);
54  Float res = sqrt(m(rh,rh));
55  derr << "check: residue = " << res << endl;
56  check_macro (res < 1e-3, "unexpected residue");
57 }
58 field criteria (Float p, const field& uh) {
59  const space& Xh = uh.get_space();
60  if (uh.get_approx() == "P1") return lazy_interpolate (Xh, abs(uh));
61  return lazy_interpolate (Xh, pow(norm(grad(uh)), p/2));
62 }
63 void
64 load (idiststream& in, Float& p, field& uh) {
65  in >> catchmark("p") >> p
66  >> catchmark("u") >> uh;
67 }
68 int main(int argc, char**argv) {
69  environment rheolef (argc,argv);
70  if (argc < 3) usage(argv[0]);
71  Float p;
72  field uh;
73  if (string (argv[1]) == "-") {
74  load (din, p, uh);
75  } else {
76  idiststream in;
77  in.open(argv[1], "field");
78  load (in, p, uh);
79  }
80  for (int i = 2; i < argc; i++) {
81  if (strcmp (argv[i], "-check") == 0) { check (p, uh); }
82  else if (strcmp (argv[i], "-residue") == 0) { dout << catchmark("ru") << residue (p, uh); }
83  else if (strcmp (argv[i], "-criteria") == 0) { dout << catchmark("c") << criteria (p, uh); }
84  else {
85  derr << argv[0] << ": unknown option \'" << argv[i] << "'" << endl;
86  usage(argv[0]);
87  }
88  }
89 }
field lh(Float epsilon, Float t, const test &v)
see the Float page for the full documentation
see the field page for the full documentation
see the form page for the full documentation
see the problem page for the full documentation
see the catchmark page for the full documentation
Definition: catchmark.h:67
see the environment page for the full documentation
Definition: environment.h:121
idiststream: see the diststream page for the full documentation
Definition: diststream.h:336
void open(std::string filename, std::string suffix="", const communicator &comm=communicator())
This routine opens a physical input file.
Definition: diststream.cc:85
idiststream din(cin)
see the diststream page for the full documentation
Definition: diststream.h:464
odiststream dout(cout)
see the diststream page for the full documentation
Definition: diststream.h:467
odiststream derr(cerr)
see the diststream page for the full documentation
Definition: diststream.h:473
see the space page for the full documentation
see the test page for the full documentation
see the test page for the full documentation
point u(const point &x)
The p-Laplacian problem – the eta function.
This file is part of Rheolef.
std::enable_if< details::has_field_rdof_interface< Expr >::value,details::field_expr_v2_nonlinear_terminal_field< typename Expr::scalar_type,typename Expr::memory_type,details::differentiate_option::gradient >>::type grad(const Expr &expr)
grad(uh): see the expression page for the full documentation
field_basic< T, M > lazy_interpolate(const space_basic< T, M > &X2h, const field_basic< T, M > &u1h)
see the interpolate page for the full documentation
Definition: field.h:871
T norm(const vec< T, M > &x)
norm(x): see the expression page for the full documentation
Definition: vec.h:387
rheolef::std enable_if ::type dot const Expr1 expr1, const Expr2 expr2 dot(const Expr1 &expr1, const Expr2 &expr2)
dot(x,y): see the expression page for the full documentation
Definition: vec_expr_v2.h:415
std::enable_if< details::is_field_expr_v2_nonlinear_arg< Expr >::value &&! is_undeterminated< Result >::value, Result >::type integrate(const geo_basic< T, M > &omega, const Expr &expr, const integrate_option &iopt, Result dummy=Result())
see the integrate page for the full documentation
Definition: integrate.h:211
T norm2(const vec< T, M > &x)
norm2(x): see the expression page for the full documentation
Definition: vec.h:379
space_mult_list< T, M > pow(const space_basic< T, M > &X, size_t n)
Definition: space_mult.h:120
details::field_expr_v2_nonlinear_node_nary< typename details::function_traits< Function >::functor_type,typename details::field_expr_v2_nonlinear_terminal_wrapper_traits< Exprs >::type... > ::type compose(const Function &f, const Exprs &... exprs)
see the compose page for the full documentation
Definition: compose.h:247
field residue(Float p, const field &uh)
int main(int argc, char **argv)
field criteria(Float p, const field &uh)
void check(Float p, const field &uh)
void usage(string name)
void load(idiststream &in, Float &p, field &uh)
rheolef - reference manual
Definition: eta.h:25
Definition: sphere.icc:25
Definition: leveque.h:25