From a3ff28e20172f60ba427aab0d334dd633c5a12fe Mon Sep 17 00:00:00 2001
From: Bernd Flemisch <bernd@iws.uni-stuttgart.de>
Date: Thu, 12 Jul 2018 15:18:10 +0200
Subject: [PATCH] [io][vtk] read switched primary variable names from input
 file

---
 dumux/io/loadsolution.hh                      | 20 +++++++++++++++----
 .../2p2c/implicit/test_2p2c_fv.input          |  5 +++++
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/dumux/io/loadsolution.hh b/dumux/io/loadsolution.hh
index b5dfdbb590..6c95e18946 100644
--- a/dumux/io/loadsolution.hh
+++ b/dumux/io/loadsolution.hh
@@ -126,8 +126,20 @@ auto loadSolutionFromVtuFile(const std::string fileName,
 template<class ModelTraits, class FluidSystem>
 std::string primaryVariableName(int pvIdx, int state)
 {
-    if (haveParam("LoadSolution.PrimaryVariableNames"))
-        DUNE_THROW(Dune::NotImplemented, "reading PrimaryVariableNames from input file");
+    using std::pow;
+    static auto numStates = pow(2, ModelTraits::numPhases()) - 1;
+    const auto paramNameWithState = "LoadSolution.PriVarNamesState" + std::to_string(state);
+
+    if (haveParam("LoadSolution.PriVarNames"))
+    {
+        DUNE_THROW(Dune::NotImplemented, "please provide LoadSolution.PriVarNamesState1..." << numStates
+                   << " or remove LoadSolution.PriVarNames to use default names");
+    }
+    else if (haveParam(paramNameWithState))
+    {
+        const auto pvNames = getParam<std::vector<std::string>>(paramNameWithState);
+        return pvNames[pvIdx];
+    }
     else
         return ModelTraits::template primaryVariableName<FluidSystem>(pvIdx, state);
 }
@@ -139,9 +151,9 @@ std::string primaryVariableName(int pvIdx, int state)
 template<class ModelTraits>
 std::string primaryVariableName(int pvIdx)
 {
-    if (haveParam("LoadSolution.PrimaryVariableNames"))
+    if (haveParam("LoadSolution.PriVarNames"))
     {
-        static auto pvNames = getParam<std::vector<std::string>>("LoadSolution.PrimaryVariableNames");
+        static auto pvNames = getParam<std::vector<std::string>>("LoadSolution.PriVarNames");
         return pvNames[pvIdx];
     }
     else
diff --git a/test/porousmediumflow/2p2c/implicit/test_2p2c_fv.input b/test/porousmediumflow/2p2c/implicit/test_2p2c_fv.input
index a2933a09dc..48f074e96d 100644
--- a/test/porousmediumflow/2p2c/implicit/test_2p2c_fv.input
+++ b/test/porousmediumflow/2p2c/implicit/test_2p2c_fv.input
@@ -19,3 +19,8 @@ PressureLow = 1e5 # [Pa] lower pressure limit for tabularization
 PressureHigh = 3e7 # [Pa] upper pressure limit for tabularization
 TemperatureLow = 312.15 # [Pa] lower temperature limit for tabularization
 TemperatureHigh = 314.15 # [Pa] upper temperature limit for tabularization
+
+[LoadSolution]
+PriVarNamesState1 = pw x_w^N2
+PriVarNamesState2 = pw x_n^H2O
+PriVarNamesState3 = pw Sn
-- 
GitLab