rheolef  7.0
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);
20  quadrature_option qopt;
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 }
solver_basic< T, M > ldlt(const csr< T, M > &a, const solver_option &opt=solver_option())
Definition: solver.h:206
field criteria(Float p, const field &uh)
field - piecewise polynomial finite element field
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)
Definition: compose.h:157
space_mult_list< T, M > pow(const space_basic< T, M > &X, size_t n)
Definition: space_mult.h:87
rheolef::std enable_if ::type dot const Expr1 expr1, const Expr2 expr2 dot(const Expr1 &expr1, const Expr2 &expr2)
Definition: vec_expr_v2.h:335
std::string get_approx() const
Definition: field.h:286
vec< T, M > solve(const vec< T, M > &b) const
Definition: solver.h:275
void check(Float p, const field &uh)
quadrature_option - send options to the integrate function
STL namespace.
vec< T, M > & set_u()
Definition: field.h:293
irheostream, orheostream - large data streams
Definition: compiler.h:7
field residue(Float p, const field &uh)
static field_basic< T, sequential > interpolate(const space_basic< T, sequential > &Vh, const field_basic< T, sequential > &uh)
T norm2(const vec< T, M > &x)
Definition: vec.h:334
void load(idiststream &in, Float &p, field &uh)
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 quadrature_option &qopt, Result dummy=Result())
integrate - integrate a function or an expression
Definition: integrate.h:107
T norm(const vec< T, M > &x)
Definition: vec.h:341
space – piecewise polynomial finite element space
Definition: space.h:229
#define check_macro(ok_condition, message)
Definition: compiler.h:104
double Float
Definition: compiler.h:160
std::enable_if< details::is_field_expr_v2_linear_arg< Expr >::value,details::field_expr_v2_nonlinear_terminal_field_grad< typename Expr::scalar_type,typename Expr::memory_type >>::type grad(const Expr &expr)
idiststream din(cin)
catchmark - iostream manipulator
Definition: catchmark.h:30
const csr< T, M > & uu() const
Definition: form.h:140
const space_type & get_space() const
Definition: field.h:283
odiststream derr(cerr)
Definition: diststream.h:329
form - representation of a finite element bilinear form
Definition: form.h:98
void usage(string name)
Float u(const point &x)
const vec< T, M > & u() const
Definition: field.h:291
void set_family(family_type type)
int main(int argc, char **argv)
odiststream dout(cout)
Definition: diststream.h:313