Commit 1ef2642a authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[io][vtk] introduce compatibility layer with new/old grid vars

parent b99fbb08
......@@ -43,7 +43,9 @@
#include <dumux/common/parameters.hh>
#include <dumux/io/format.hh>
#include <dumux/discretization/method.hh>
#include <dumux/discretization/fvgridvariables.hh>
#include "vtkfunction.hh"
#include "velocityoutput.hh"
......@@ -378,8 +380,18 @@ public:
}
protected:
// extract the grid volume variables from the grid variables (experimental interface)
template<bool isExperimental = Experimental::areExperimentalGridVars<GridVariables>,
std::enable_if_t<isExperimental, int> = 0>
decltype(auto) gridVolVars() const { return gridVariables_.gridVolVars(); }
// extract the grid volume variables from the grid variables (experimental interface)
template<bool isExperimental = Experimental::areExperimentalGridVars<GridVariables>,
std::enable_if_t<!isExperimental, int> = 0>
decltype(auto) gridVolVars() const { return gridVariables_.curGridVolVars(); }
// some return functions for differing implementations to use
const auto& problem() const { return gridVariables_.curGridVolVars().problem(); }
const auto& problem() const { return gridVolVars().problem(); }
const GridVariables& gridVariables() const { return gridVariables_; }
const GridGeometry& gridGeometry() const { return gridVariables_.gridGeometry(); }
const SolutionVector& sol() const { return sol_; }
......@@ -447,7 +459,7 @@ private:
const auto eIdxGlobal = gridGeometry().elementMapper().index(element);
auto fvGeometry = localView(gridGeometry());
auto elemVolVars = localView(gridVariables_.curGridVolVars());
auto elemVolVars = localView(gridVolVars());
// If velocity output is enabled we need to bind to the whole stencil
// otherwise element-local data is sufficient
......@@ -634,7 +646,7 @@ private:
const auto numCorners = element.subEntities(dim);
auto fvGeometry = localView(gridGeometry());
auto elemVolVars = localView(gridVariables_.curGridVolVars());
auto elemVolVars = localView(gridVolVars());
// resize element-local data containers
for (std::size_t i = 0; i < volVarScalarDataInfo_.size(); ++i)
......
......@@ -36,6 +36,7 @@
#include <dumux/common/parameters.hh>
#include <dumux/discretization/method.hh>
#include <dumux/discretization/elementsolution.hh>
#include <dumux/discretization/fvgridvariables.hh>
#include <dumux/flux/traits.hh>
namespace Dumux {
......@@ -108,7 +109,7 @@ public:
* \param gridVariables The grid variables
*/
PorousMediumFlowVelocity(const GridVariables& gridVariables)
: problem_(gridVariables.curGridVolVars().problem())
: problem_(getProblem_(gridVariables))
, gridGeometry_(gridVariables.gridGeometry())
, gridVariables_(gridVariables)
{
......@@ -460,6 +461,15 @@ private:
}
private:
// extract problem from grid vars (experimental interface)
template<class GV, std::enable_if_t<Experimental::areExperimentalGridVars<GV>, int> = 0>
const Problem& getProblem_(const GV& gv) { return gv.gridVolVars().problem(); }
// extract problem from grid vars (standards interface)
template<class GV, std::enable_if_t<!Experimental::areExperimentalGridVars<GV>, int> = 0>
const Problem& getProblem_(const GV& gv) { return gv.curGridVolVars().problem(); }
const Problem& problem_;
const GridGeometry& gridGeometry_;
const GridVariables& gridVariables_;
......
......@@ -29,9 +29,11 @@
#include <dune/common/float_cmp.hh>
#include <dumux/common/parameters.hh>
#include <dumux/io/velocityoutput.hh>
#include <dumux/discretization/method.hh>
#include <dumux/discretization/elementsolution.hh>
#include <dumux/discretization/fvgridvariables.hh>
#include <dumux/porousmediumflow/velocity.hh>
namespace Dumux {
......@@ -67,6 +69,15 @@ class PorousMediumFlowVelocityOutput : public VelocityOutput<GridVariables>
using Problem = typename GridVolumeVariables::Problem;
using VelocityBackend = PorousMediumFlowVelocity<GridVariables, FluxVariables>;
struct hasCurGridVolVars
{
template<class GV>
auto operator()(const GV& gv) -> decltype(gv.curGridVolVars()) {}
};
static constexpr auto isOldGVInterface =
decltype(isValid(hasCurGridVolVars())(std::declval<GridVariables>()))::value;
public:
using VelocityVector = typename ParentType::VelocityVector;
......@@ -78,7 +89,12 @@ public:
PorousMediumFlowVelocityOutput(const GridVariables& gridVariables)
{
// check, if velocity output can be used (works only for cubes so far)
enableOutput_ = getParamFromGroup<bool>(gridVariables.curGridVolVars().problem().paramGroup(), "Vtk.AddVelocity");
// compatibility layer with new and old-style grid variables
if constexpr (Experimental::areExperimentalGridVars<GridVariables>)
enableOutput_ = getParamFromGroup<bool>(gridVariables.gridVolVars().problem().paramGroup(), "Vtk.AddVelocity");
else
enableOutput_ = getParamFromGroup<bool>(gridVariables.curGridVolVars().problem().paramGroup(), "Vtk.AddVelocity");
if (enableOutput_)
velocityBackend = std::make_unique<VelocityBackend>(gridVariables);
}
......
Supports Markdown
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