Commit 99d6750a authored by Santiago Ospina's avatar Santiago Ospina

removed duplicated output header

parent 12181e7b
#ifndef DUNE_DORIE_OUTPUT_WRITER_HH
#define DUNE_DORIE_OUTPUT_WRITER_HH
#include <string>
#include <memory>
#include <type_traits>
#include <dune/common/exceptions.hh>
#include <dune/common/parametertree.hh>
#include <dune/grid/io/file/vtk/vtksequencewriter.hh>
#include <dune/grid/io/file/vtk/subsamplingvtkwriter.hh>
#include <dune/pdelab/gridfunctionspace/gridfunctionspaceutilities.hh>
#include "../solver/util_vtk_adapters.hh"
namespace Dune{
namespace Dorie{
/// Dummy Output Writer class. Does nothing.
template<typename Traits>
class OutputWriterBase
{
private:
using RF = typename Traits::RF;
public:
OutputWriterBase () = default;
virtual ~OutputWriterBase () = default;
/// Do nothing
virtual void write_vtk_output (const RF time) {};
};
/// Default VTK Output Writer.
/** \tparam Traits BaseTraits struct
* \tparam GFS Solution GFS
* \tparam Param Parameter class
* \tparam U Solution Vector
*/
template<typename Traits, typename GFS, typename Param, typename U>
class OutputWriter : public OutputWriterBase<Traits>
{
private:
using RF = typename Traits::RF;
using GV = typename Traits::GV;
using VTKWriter = Dune::VTKSequenceWriter<GV>;
using SubVTK = Dune::SubsamplingVTKWriter<GV>;
using UDGF = Dune::PDELab::DiscreteGridFunction<GFS,U>;
using FluxDGF = Dune::Dorie::GradientFluxAdapter<GFS,U,Param>;
using ConDGF = Dune::Dorie::ConductivityAdapter<Traits,Param>;
using WaterDGF = Dune::Dorie::WaterContentAdapter<Traits,Param,UDGF>;
using SatDGF = Dune::Dorie::SaturationAdapter<Traits,Param,UDGF>;
VTKWriter vtkwriter;
UDGF udgf;
FluxDGF fluxdgf;
ConDGF condgf;
WaterDGF waterdgf;
SatDGF satdgf;
const Dune::VTK::OutputType output_type;
public:
/// Set up the VTK output writer. Create adapters and stack them to the sequence writer
/** \param _inifile Parameter file parser
* \param gv LeafGridView
* \param gfs Solution GFS
* \param param Parameter class
* \param unew Solution vector to write
*/
OutputWriter (Dune::ParameterTree& _inifile, GV& gv, GFS& gfs, Param& param, U& unew)
: OutputWriterBase<Traits>(),
vtkwriter(std::make_shared<SubVTK>(gv,
Dune::refinementLevels(_inifile.get<int>(
"output.subsamplingLevel", 0))),
_inifile.get<std::string>("output.fileName"),
_inifile.get<std::string>("output.outputPath"),
"./"),
udgf(gfs,unew),
fluxdgf(gfs,unew,param,udgf),
condgf(gv,param),
waterdgf(gv,param,udgf),
satdgf(gv,param,udgf),
output_type(_inifile.get<bool>("output.asciiVtk") ?
Dune::VTK::OutputType::ascii : Dune::VTK::OutputType::base64)
{
auto udgf_vtk = std::make_shared<Dune::PDELab::VTKGridFunctionAdapter<UDGF>>(udgf,"head");
auto fluxdgf_vtk = std::make_shared<Dune::PDELab::VTKGridFunctionAdapter<FluxDGF>>(fluxdgf,"flux");
auto condgf_vtk = std::make_shared<Dune::PDELab::VTKGridFunctionAdapter<ConDGF>>(condgf,"K_0");
auto waterdgf_vtk = std::make_shared<Dune::PDELab::VTKGridFunctionAdapter<WaterDGF>>(waterdgf,"theta_w");
auto satdgf_vtk = std::make_shared<Dune::PDELab::VTKGridFunctionAdapter<SatDGF>>(satdgf,"Theta");
if (_inifile.get<bool>("output.vertexData")) {
vtkwriter.addVertexData(udgf_vtk);
vtkwriter.addVertexData(fluxdgf_vtk);
vtkwriter.addVertexData(condgf_vtk);
vtkwriter.addVertexData(waterdgf_vtk);
vtkwriter.addVertexData(satdgf_vtk);
}
else {
vtkwriter.addCellData(udgf_vtk);
vtkwriter.addCellData(fluxdgf_vtk);
vtkwriter.addCellData(condgf_vtk);
vtkwriter.addCellData(waterdgf_vtk);
vtkwriter.addCellData(satdgf_vtk);
}
}
/// Write the VTK files for the current solution unew
/** \param time Current simulation time, will be saved into output
* \throw Dune::IOError Cannot write output
* (VTKWriter has bad exception handling)
*/
void write_vtk_output (const RF time) override
{
try{
vtkwriter.write(time,output_type);
}
catch(...){
DUNE_THROW(Dune::IOError,"Cannot write VTK output!");
}
}
};
/// Factory class for creating an OutputWriter based on Traits
/** \tparam Traits Dune::Dorie::BaseTraits defining the Simulation
* The constexpr boolean enable_adaptivity in Dune::Dorie::BaseTraits will
* define which create() function is enabled at compile time.
*/
template<typename Traits, typename GFS, typename Param, typename U>
struct OutputWriterFactory
{
private:
using OWB = OutputWriterBase<Traits>;
Dune::ParameterTree& inifile;
typename Traits::GV& gv;
GFS& gfs;
Param& param;
U& u;
public:
/// Create the factory. References will be forwarded to the writer.
/** \param _inifile Parameter file parser
* \param _gv GridView
* \param _gfs GridFunctionSpace of the solution
* \param _param Parameter class
* \param _u Solution vector to write
*/
OutputWriterFactory (Dune::ParameterTree& _inifile, typename Traits::GV& _gv, GFS& _gfs, Param& _param, U& _u) :
inifile(_inifile),
gv(_gv),
gfs(_gfs),
param(_param),
u(_u)
{ }
std::unique_ptr<OWB> create ()
{
std::unique_ptr<OWB> p;
p = std::make_unique<OutputWriter<Traits,GFS,Param,U>>(inifile,gv,gfs,param,u);
return p;
}
};
} // namespace Dorie
} // namespace Dune
#endif // DUNE_DORIE_OUTPUT_WRITER_HH
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment