Rheolef  7.2
an efficient C++ finite element environment
zalesak_dg_adapt.cc
Go to the documentation of this file.
1 // usage exemple:
26 // cat leveque-o2-full-100-P2d-6000-e-0.field leveque-o2-full-100-P2d-6000-e-3000.field > in.branch
27 // ./zalesak_dg_adapt < in.branch > adapt.branch
28 // TODO: test zalesak L1 & mass error ; cf ctrl paras (field_error,subdivide)
29 # include "rheolef_seq.h"
30 using namespace rheolef;
31 using namespace std;
32 #include "zalesak.h"
33 Float heaviside (const Float& x) { return (x <= 0) ? 0 : 1; }
34 Float criterion (const Float& x, const Float& y) { return (x+y)/2; }
35 int main(int argc, char**argv) {
36  environment rheolef (argc, argv);
37  size_t subdivide = (argc > 1) ? atoi(argv[1]) : 3;
38  Float field_error = (argc > 2) ? atof(argv[2]) : 1e-3;
39  Float geo_error = 1e-7;
40  bool do_verbose = true;
41  bool do_clean = true;
42  string tmp = do_clean ? get_tmpdir() + "/" : "";
43  string cleanlist;
44  check_macro (communicator().size() == 1, "zalesak_dg_adapt: command may be used as mono-process only");
45  // ----------------------------------------
46  // 1. put criterion and phi0, phi in a file
47  // ----------------------------------------
48  Float t0, tf;
49  field_basic<Float,sequential> phi0_h, phi_h;
50  branch_basic<Float,sequential> ievent ("t","phi");
51  din >> ievent (t0, phi0_h);
52  while (din >> ievent (tf, phi_h));
53  const space& Xh = phi_h.get_space();
55  branch_basic<Float,sequential> oevent ("t", "c", "phi0", "phi");
56  dout << vtk << setbasename(tmp+"criterion")
57  << oevent (t0, ch, phi0_h, phi_h);
58  cleanlist += tmp+"criterion-0.vtk";
59  // ----------------------------------------
60  // 2. run pvbatch
61  // ----------------------------------------
62  string py_name = tmp+"adapt.py";
63  odiststream py (py_name, io::nogz);
64  cleanlist += " "+py_name;
65  bool view_2d = phi_h.get_geo().map_dimension() < 3;
66  py << "#!/usr/bin/env pvbatch --script=" << endl
67  << "# This is a paraview script automatically generated by rheolef." << endl
68  << endl
69  << "from paraview.simple import *" << endl
70  << "from paraview_rheolef import * # load rheolef specific functions" << endl
71  << endl
72  << "opt = { \\" << endl
73  << " 'mark' : 'c', \\" << endl
74  << " 'view_2d' : " << view_2d << ", \\" << endl
75  << " 'geo_error' : " << geo_error << ", \\" << endl
76  << " 'field_error' : " << field_error << ", \\" << endl
77  << " 'subdivide' : " << subdivide << " \\" << endl
78  << " }" << endl
79  << endl
80  << "adapt_Pk_iso_P1 (paraview, \""<<tmp<<"criterion-0.vtk\", \""<<tmp<<"adapt.vtk\", opt)" << endl
81  << endl
82  ;
83  string prog = "pvbatch --force-offscreen-rendering ";
84  string command = "DISPLAY=:0.0 LANG=C PYTHONPATH=" + string(_RHEOLEF_PKGDATADIR) + " " + prog + py_name;
85  if (do_verbose) derr << "! " << command << endl;
86  check_macro (dis_system (command) == 0, "unix command failed");
87  cleanlist += " "+tmp+"adapt.vtk";
88  // ----------------------------------------------------
89  // 4. load phi0 & phi from adapt.vtk & put it on stdout
90  // ----------------------------------------------------
91  Float t;
92  field_basic<Float,sequential> c_ha, phi0_ha, phi_ha;
93  idiststream in_vtk (tmp+"adapt.vtk");
94  in_vtk.is() >> vtk;
95  iorheo::setbasename(in_vtk.is(),"adapt");
96  branch_basic<Float,sequential> ia_event ("t", "c", "phi0", "phi");
97  in_vtk >> ia_event (t, c_ha, phi0_ha, phi_ha);
98  c_ha.get_geo().save();
99  branch oa_event ("t", "phi");
100  dout << rheo
101  << oa_event (t0, phi0_ha)
102  << oa_event (tf, phi_ha);
103  // ----------------------------------------------------
104  // 5. clean tmp & statistics
105  // ----------------------------------------------------
106  if (do_clean) {
107  command = "rm -f " + cleanlist;
108  if (do_verbose) derr << "! " << command << endl;
109  check_macro (dis_system (command) == 0, "unix command failed");
110  }
111  if (do_verbose) {
112  cerr << "zalesak_dg_adapt: mesh size " << Xh.get_geo().size()
113  << " -> " << phi_ha.get_geo().size() << endl;
114  }
115 }
see the Float page for the full documentation
see the branch page for the full documentation
see the environment page for the full documentation
Definition: environment.h:121
const space_type & get_space() const
Definition: field.h:270
const geo_type & get_geo() const
Definition: field.h:271
idiststream: see the diststream page for the full documentation
Definition: diststream.h:336
std::istream & is()
Definition: diststream.h:400
odiststream: see the diststream page for the full documentation
Definition: diststream.h:137
idiststream din(cin)
see the diststream page for the full documentation
Definition: diststream.h:464
rheolef::space_base_rep< T, M > t
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
#define _RHEOLEF_PKGDATADIR
Definition: config.h:234
verbose clean transpose logscale grid shrink ball stereo iso volume skipvtk deformation fastfieldload lattice reader_on_stdin color format format format format format format format format format format format format format format format format vtk
verbose clean transpose logscale grid shrink ball stereo iso volume skipvtk deformation fastfieldload lattice reader_on_stdin color rheo
string command
Definition: mkgeo_ball.sh:136
This file is part of Rheolef.
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
int dis_system(const std::string &command, const communicator &comm)
Definition: diststream.cc:214
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
std::string get_tmpdir()
get_tmpdir: see the rheostream page for the full documentation
Definition: rheostream.cc:54
The Zalesak slotted disk benchmark – the exact solution.
Float criterion(const Float &x, const Float &y)
int main(int argc, char **argv)
Float heaviside(const Float &x)