diff --git a/dumux/freeflow/navierstokes/iofields.hh b/dumux/freeflow/navierstokes/iofields.hh index fae9c6fa8310f43994c7dde4e0d461d78d393252..704541c2ae46ee33d295e1846dca37cb4713711b 100644 --- a/dumux/freeflow/navierstokes/iofields.hh +++ b/dumux/freeflow/navierstokes/iofields.hh @@ -26,6 +26,8 @@ #include <dune/common/fvector.hh> #include <dune/common/deprecated.hh> +#include <dune/common/indices.hh> +#include <dune/istl/multitypeblockvector.hh> // TODO: needed? or is forward declare enough? #include <dumux/common/parameters.hh> #include <dumux/discretization/methods.hh> @@ -34,6 +36,44 @@ namespace Dumux { +/*! + * \ingroup InputOutput + * \ingroup NavierStokesModel + * \brief helper function to determine the names of cell-centered primary variables of a model with staggered grid discretization + * \note use this as input for the load solution function + */ +template<class ModelTraits, class IOFields, class FluidSystem, std::size_t cellCenterIdx = 0, class ...Args, std::size_t i> +std::function<std::string(int,int)> createStaggeredPVNameFunction(const Dune::MultiTypeBlockVector<Args...>&, + Dune::index_constant<i> idx, + const std::string& paramGroup = "") +{ + using CellCenterPriVarsType = typename std::tuple_element_t<cellCenterIdx, std::tuple<Args...>>::block_type; + static constexpr auto offset = ModelTraits::numEq() - CellCenterPriVarsType::dimension; + + if (i == cellCenterIdx) // cell center + { + if (hasParamInGroup(paramGroup, "LoadSolution.CellCenterPriVarNames")) + { + const auto pvName = getParamFromGroup<std::vector<std::string>>(paramGroup, "LoadSolution.CellCenterPriVarNames"); + return [n = std::move(pvName)](int pvIdx, int state = 0){ return n[pvIdx]; }; + } + else + // add an offset to the pvIdx so that the velocities are skipped + return [](int pvIdx, int state = 0){ return IOFields::template primaryVariableName<ModelTraits ,FluidSystem>(pvIdx + offset, state); }; + } + else // face + { + if (hasParamInGroup(paramGroup, "LoadSolution.FacePriVarNames")) + { + const auto pvName = getParamFromGroup<std::vector<std::string>>(paramGroup, "LoadSolution.FacePriVarNames"); + return [n = std::move(pvName)](int pvIdx, int state = 0){ return n[pvIdx]; }; + } + else + // there is only one scalar-type primary variable called "v" living on the faces + return [](int pvIdx, int state = 0){ return IOFields::template primaryVariableName<ModelTraits, FluidSystem>(pvIdx , state); }; + } +} + /*! * \ingroup NavierStokesModel * \brief Adds I/O fields for the Navier-Stokes model