Rheolef  7.1
an efficient C++ finite element environment
zalesak_dg_adapt.cc

The Zalesak slotted disk benchmark – adaptive post-treatment

// usage exemple:
// cat leveque-o2-full-100-P2d-6000-e-0.field leveque-o2-full-100-P2d-6000-e-3000.field > in.branch
// ./zalesak_dg_adapt < in.branch > adapt.branch
// TODO: test zalesak L1 & mass error ; cf ctrl paras (field_error,subdivide)
# include "rheolef_seq.h"
using namespace rheolef;
using namespace std;
#include "zalesak.h"
Float heaviside (const Float& x) { return (x <= 0) ? 0 : 1; }
Float criterion (const Float& x, const Float& y) { return (x+y)/2; }
int main(int argc, char**argv) {
environment rheolef (argc, argv);
size_t subdivide = (argc > 1) ? atoi(argv[1]) : 3;
Float field_error = (argc > 2) ? atof(argv[2]) : 1e-3;
Float geo_error = 1e-7;
bool do_verbose = true;
bool do_clean = true;
string tmp = do_clean ? get_tmpdir() + "/" : "";
string cleanlist;
check_macro (communicator().size() == 1, "zalesak_dg_adapt: command may be used as mono-process only");
// ----------------------------------------
// 1. put criterion and phi0, phi in a file
// ----------------------------------------
Float t0, tf;
field_basic<Float,sequential> phi0_h, phi_h;
branch_basic<Float,sequential> ievent ("t","phi");
din >> ievent (t0, phi0_h);
while (din >> ievent (tf, phi_h));
const space& Xh = phi_h.get_space();
field_basic<Float,sequential> ch = interpolate (Xh, compose(criterion, compose (heaviside, phi0_h), compose (heaviside, phi_h)));
branch_basic<Float,sequential> oevent ("t", "c", "phi0", "phi");
dout << vtk << setbasename(tmp+"criterion")
<< oevent (t0, ch, phi0_h, phi_h);
cleanlist += tmp+"criterion-0.vtk";
// ----------------------------------------
// 2. run pvbatch
// ----------------------------------------
string py_name = tmp+"adapt.py";
odiststream py (py_name, io::nogz);
cleanlist += " "+py_name;
bool view_2d = phi_h.get_geo().map_dimension() < 3;
py << "#!/usr/bin/env pvbatch --script=" << endl
<< "# This is a paraview script automatically generated by rheolef." << endl
<< endl
<< "from paraview.simple import *" << endl
<< "from paraview_rheolef import * # load rheolef specific functions" << endl
<< endl
<< "opt = { \\" << endl
<< " 'mark' : 'c', \\" << endl
<< " 'view_2d' : " << view_2d << ", \\" << endl
<< " 'geo_error' : " << geo_error << ", \\" << endl
<< " 'field_error' : " << field_error << ", \\" << endl
<< " 'subdivide' : " << subdivide << " \\" << endl
<< " }" << endl
<< endl
<< "adapt_Pk_iso_P1 (paraview, \""<<tmp<<"criterion-0.vtk\", \""<<tmp<<"adapt.vtk\", opt)" << endl
<< endl
;
string prog = "pvbatch --force-offscreen-rendering ";
string command = "DISPLAY=:0.0 LANG=C PYTHONPATH=" + string(_RHEOLEF_PKGDATADIR) + " " + prog + py_name;
if (do_verbose) derr << "! " << command << endl;
check_macro (dis_system (command) == 0, "unix command failed");
cleanlist += " "+tmp+"adapt.vtk";
// ----------------------------------------------------
// 4. load phi0 & phi from adapt.vtk & put it on stdout
// ----------------------------------------------------
Float t;
field_basic<Float,sequential> c_ha, phi0_ha, phi_ha;
idiststream in_vtk (tmp+"adapt.vtk");
in_vtk.is() >> vtk;
iorheo::setbasename(in_vtk.is(),"adapt");
branch_basic<Float,sequential> ia_event ("t", "c", "phi0", "phi");
in_vtk >> ia_event (t, c_ha, phi0_ha, phi_ha);
c_ha.get_geo().save();
branch oa_event ("t", "phi");
dout << rheo
<< oa_event (t0, phi0_ha)
<< oa_event (tf, phi_ha);
// ----------------------------------------------------
// 5. clean tmp & statistics
// ----------------------------------------------------
if (do_clean) {
command = "rm -f " + cleanlist;
if (do_verbose) derr << "! " << command << endl;
check_macro (dis_system (command) == 0, "unix command failed");
}
if (do_verbose) {
cerr << "zalesak_dg_adapt: mesh size " << Xh.get_geo().size()
<< " -> " << phi_ha.get_geo().size() << endl;
}
}
see the Float page for the full documentation
see the branch page for the full documentation
idiststream din
see the diststream page for the full documentation
Definition: diststream.h:427
odiststream dout(cout)
see the diststream page for the full documentation
Definition: diststream.h:430
odiststream derr(cerr)
see the diststream page for the full documentation
Definition: diststream.h:436
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 > 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
int dis_system(const std::string &command, const communicator &comm)
Definition: diststream.cc:213
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
std::string get_tmpdir()
get_tmpdir: see the rheostream page for the full documentation
Definition: rheostream.cc:50
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)