rheolef  6.6
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);
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]) == "-") {
58  } else {
59  idiststream in;
60  in.open(argv[1], "field");
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 }
quadrature_option_type - send options to the integrate function
boost::proto::result_of::make_expr< boost::proto::tag::function, vec_domain, const vec_detail::compose_< Function >, const vec< T, M > & >::type compose(const Function &f, const vec< T, M > &x)
define_sequential_odiststream_macro(char) define_sequential_odiststream_macro(int) define_sequential_odiststream_macro(unsigned int) define_sequential_odiststream_macro(long int) define_sequential_odiststream_macro(long unsigned int) define_sequential_odiststream_macro(float) define_sequential_odiststream_macro(double) define_sequential_odiststream_macro(long double) define_sequential_odiststream_macro(char *const ) define_sequential_odiststream_macro(st idiststream)()
Definition: diststream.h:228
field criteria(Float p, const field &uh)
field - piecewise polynomial finite element field
Definition: field.h:225
const vec< T, M > & u() const
Definition: field.h:279
field_nonlinear_expr< field_nonlinear_expr_uf< details::binder_first< details::pow_, typename field_basic< T, M >::scalar_type >,field_expr_terminal_field< T, M > >> pow(const typename field_basic< T, M >::scalar_type &x, const field_basic< T, M > &y)
field_vf_expr< field_vf_expr_grad< test_basic< T, M, VfTag > >> grad(const test_basic< T, M, VfTag > &x)
Definition: operators2.h:74
void check(Float p, const field &uh)
std::string get_approx() const
Definition: field.h:274
STL namespace.
vec< T, M > & set_u()
Definition: field.h:281
irheostream, orheostream - large data streams
Definition: compiler.h:7
field residue(Float p, const field &uh)
const csr< T, M > & uu() const
Definition: form.h:140
static field_basic< T, sequential > interpolate(const space_basic< T, sequential > &Vh, const field_basic< T, sequential > &uh)
solver_basic< T, M > ldlt(const csr< T, M > &a, const solver_option_type &opt=solver_option_type())
Definition: solver.h:207
T norm2(const vec< T, M > &x)
Definition: vec_expr.h:319
void load(idiststream &in, Float &p, field &uh)
T norm(const vec< T, M > &x)
Definition: vec_expr.h:326
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:177
vec< T, M > solve(const vec< T, M > &b) const
Definition: solver.h:276
field_nonlinear_expr< field_nonlinear_expr_uf< details::sqrt_,field_expr_terminal_field< T, M > > > sqrt(const field_basic< T, M > &x)
idiststream din(cin)
catchmark - iostream manipulator
Definition: catchmark.h:30
T dot(const vec< T, M > &x, const int &y)
const space_type & get_space() const
Definition: field.h:271
odiststream derr(cerr)
Definition: diststream.h:340
form - representation of a finite element bilinear form
Definition: form.h:98
solver - direct or interative solver interface
Definition: solver.h:8
void usage(string name)
boost::proto::result_of::make_expr< boost::proto::tag::function, vec_domain, const vec_detail::abs_, const vec< T, M > & >::type abs(const vec< T, M > &x)
Float u(const point &x)
int main(int argc, char **argv)
odiststream dout(cout)
Definition: diststream.h:317
field_basic< T, M > integrate(const geo_basic< T, M > &domain, const test_basic< T, M, details::vf_tag_01 > &expr, const quadrature_option_type &qopt=quadrature_option_type())
integrate - integrate a function or an expression
Definition: integrate.h:90