Skip to content
Snippets Groups Projects
Commit 6be94734 authored by Jö Fahlke's avatar Jö Fahlke
Browse files

Directly output exact solution.

parent 4aa9ea94
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,7 @@
//== }
#include"problem.hh"
#include "gridoperator.hh"
#include "vtkfunction.hh"
template<typename GV>
void driver (const GV& gv, Dune::ParameterTree& ptree)
......@@ -151,13 +152,11 @@ void driver (const GV& gv, Dune::ParameterTree& ptree)
newton.apply();
// Write VTK output file
Z w(gfs); // Lagrange interpolation of exact solution
Dune::PDELab::interpolate(g,gfs,w);
int subsampling = ptree.get("output.subsampling",(int)1);
Dune::SubsamplingVTKWriter<GV> vtkwriter(gv,Dune::refinementIntervals(subsampling));
using Function = Dune::P1VTKFunction<GV, typename Z::Container>;
vtkwriter.addVertexData(std::make_shared<Function>(gv, *z.storage(),"fesol"));
vtkwriter.addVertexData(std::make_shared<Function>(gv, *w.storage(),"exact"));
vtkwriter.addVertexData(PPS::makeScalarVTKGridFunction<GV>(glambda, "exact"));
vtkwriter.write(ptree.get("output.filename","output"),
Dune::VTK::appendedraw);
}
......
#ifndef PACXX_PROJECTSEMINAR_2019_SRC_VTKFUNCTION_HH
#define PACXX_PROJECTSEMINAR_2019_SRC_VTKFUNCTION_HH
#include <memory>
#include <string>
#include <utility>
#include <dune/common/fvector.hh>
#include <dune/grid/io/file/vtk/function.hh>
namespace PPS {
template<class GridView, class Functor>
class ScalarVTKGridFunction :
public Dune::VTKFunction<GridView>
{
Functor functor_;
std::string name_;
public:
typedef typename GridView::ctype ctype;
enum { dim = GridView::dimension };
typedef typename GridView::template Codim< 0 >::Entity Entity;
ScalarVTKGridFunction(Functor functor, std::string name) :
functor_(std::move(functor)),
name_(std::move(name))
{ }
int ncomps() const override { return 1; }
std::string name () const override { return name_; }
double evaluate(int comp, const Entity& e,
const Dune::FieldVector<ctype,dim>& xi) const override
{
assert(comp == 0);
return functor_(e, xi);
}
};
template<class GridView, class Functor>
auto makeScalarVTKGridFunction(Functor functor, std::string name)
{
return std::make_unique<ScalarVTKGridFunction<GridView, Functor> >
(std::move(functor), std::move(name));
}
} // namespace PPS
#endif // PACXX_PROJECTSEMINAR_2019_SRC_VTKFUNCTION_HH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment