Rheolef  7.1
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 }
rheolef::field_basic::get_space
const space_type & get_space() const
Definition: field.h:300
rheolef::get_tmpdir
std::string get_tmpdir()
get_tmpdir: see the rheostream page for the full documentation
Definition: rheostream.cc:50
main
int main(int argc, char **argv)
Definition: zalesak_dg_adapt.cc:35
rheolef::branch_basic
Definition: branch.h:83
space
see the space page for the full documentation
rheolef::io::nogz
@ nogz
Definition: rheostream.h:170
criterion
Float criterion(const Float &x, const Float &y)
Definition: zalesak_dg_adapt.cc:34
rheolef::field_basic::get_geo
const geo_type & get_geo() const
Definition: field.h:301
vtk
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
Definition: iorheo-members.h:113
rheolef::interpolate
field_basic< T, M > interpolate(const space_basic< T, M > &V2h, const field_basic< T, M > &u1h)
see the interpolate page for the full documentation
Definition: interpolate.cc:233
rheolef::din
idiststream din
see the diststream page for the full documentation
Definition: diststream.h:427
rheolef::field_basic
Definition: field_expr_utilities.h:38
rheolef::environment
see the environment page for the full documentation
Definition: environment.h:115
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::dis_system
int dis_system(const std::string &command, const communicator &comm)
Definition: diststream.cc:213
rheolef::derr
odiststream derr(cerr)
see the diststream page for the full documentation
Definition: diststream.h:436
rheolef::odiststream
odiststream: see the diststream page for the full documentation
Definition: diststream.h:126
Float
see the Float page for the full documentation
rheolef_seq.h
branch
see the branch page for the full documentation
heaviside
Float heaviside(const Float &x)
Definition: zalesak_dg_adapt.cc:33
rheolef::compose
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:246
_RHEOLEF_PKGDATADIR
#define _RHEOLEF_PKGDATADIR
Definition: config.h:240
rheo
verbose clean transpose logscale grid shrink ball stereo iso volume skipvtk deformation fastfieldload lattice reader_on_stdin color rheo
Definition: iorheo-members.h:65
rheolef::dout
odiststream dout(cout)
see the diststream page for the full documentation
Definition: diststream.h:430
mkgeo_ball.tmp
tmp
Definition: mkgeo_ball.sh:380
rheolef::std
Definition: vec_expr_v2.h:391
mkgeo_ball.command
command
Definition: mkgeo_ball.sh:136
zalesak.h
The Zalesak slotted disk benchmark – the exact solution.