From d96cb7dffe83b8dbb3888046ad38b62f6905037a Mon Sep 17 00:00:00 2001
From: DennisGlaeser <dennis.glaeser@iws.uni-stuttgart.de>
Date: Tue, 10 Jan 2017 16:01:07 +0100
Subject: [PATCH] introduce non-isothermal model for easy temperature output

This commit also ports the 1pniconduction test to the new output module
---
 dumux/porousmediumflow/1p/implicit/model.hh   |  7 +-
 .../nonisothermal/implicit/model.hh           | 64 +++++++++++++++++++
 .../1p/implicit/1pniconductionproblem.hh      | 21 +++---
 .../1pniboxconduction-reference.vtu           |  4 +-
 4 files changed, 80 insertions(+), 16 deletions(-)
 create mode 100644 dumux/porousmediumflow/nonisothermal/implicit/model.hh

diff --git a/dumux/porousmediumflow/1p/implicit/model.hh b/dumux/porousmediumflow/1p/implicit/model.hh
index 28961f5159..a4de22a69b 100644
--- a/dumux/porousmediumflow/1p/implicit/model.hh
+++ b/dumux/porousmediumflow/1p/implicit/model.hh
@@ -27,7 +27,8 @@
 #ifndef DUMUX_1P_MODEL_HH
 #define DUMUX_1P_MODEL_HH
 
-#include <dumux/porousmediumflow/implicit/velocityoutput.hh>
+#include <dumux/porousmediumflow/nonisothermal/implicit/model.hh>
+
 #include "properties.hh"
 
 namespace Dumux
@@ -65,6 +66,8 @@ class OnePModel : public GET_PROP_TYPE(TypeTag, BaseModel)
     using Indices = typename GET_PROP_TYPE(TypeTag, Indices);
     using VolumeVariables = typename GET_PROP_TYPE(TypeTag, VolumeVariables);
 
+    using NonIsothermalModel = Dumux::NonIsothermalModel<TypeTag>;
+
     enum { dim = GridView::dimension };
     enum { dimWorld = GridView::dimensionworld };
 
@@ -79,6 +82,8 @@ public:
         // register standardized vtk output fields
         auto& vtkOutputModule = problem.vtkOutputModule();
         vtkOutputModule.addPrimaryVariable("pressure", Indices::pressureIdx);
+
+        NonIsothermalModel::maybeAddTemperature(vtkOutputModule);
     }
 };
 
diff --git a/dumux/porousmediumflow/nonisothermal/implicit/model.hh b/dumux/porousmediumflow/nonisothermal/implicit/model.hh
new file mode 100644
index 0000000000..80b0c50bf5
--- /dev/null
+++ b/dumux/porousmediumflow/nonisothermal/implicit/model.hh
@@ -0,0 +1,64 @@
+// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+// vi: set et ts=4 sw=4 sts=4:
+/*****************************************************************************
+ *   See the file COPYING for full copying permissions.                      *
+ *                                                                           *
+ *   This program is free software: you can redistribute it and/or modify    *
+ *   it under the terms of the GNU General Public License as published by    *
+ *   the Free Software Foundation, either version 2 of the License, or       *
+ *   (at your option) any later version.                                     *
+ *                                                                           *
+ *   This program is distributed in the hope that it will be useful,         *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
+ *   GNU General Public License for more details.                            *
+ *                                                                           *
+ *   You should have received a copy of the GNU General Public License       *
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
+ *****************************************************************************/
+/*!
+ * \file
+ *
+ * \brief TODO doc
+ */
+
+#ifndef DUMUX_POROUSMEDIUMFLOW_NONISOTHERMAL_MODEL_HH
+#define DUMUX_POROUSMEDIUMFLOW_NONISOTHERMAL_MODEL_HH
+
+// #include <dumux/implicit/properties.hh>
+
+namespace Dumux
+{
+//! declaration of the implementation
+template<class TypeTag, bool EnableEnergy>
+class NonIsothermalModelImplementation;
+
+template<class TypeTag>
+using NonIsothermalModel = NonIsothermalModelImplementation<TypeTag, GET_PROP_VALUE(TypeTag, EnableEnergyBalance)>;
+
+template<class TypeTag>
+class NonIsothermalModelImplementation<TypeTag, false>
+{
+public:
+    template<class VtkOutputModule>
+    static void maybeAddTemperature(VtkOutputModule& vtkOutputModule)
+    {}
+};
+
+template<class TypeTag>
+class NonIsothermalModelImplementation<TypeTag, true>
+{
+    using Indices = typename GET_PROP_TYPE(TypeTag, Indices);
+
+public:
+    template<class VtkOutputModule>
+    static void maybeAddTemperature(VtkOutputModule& vtkOutputModule)
+    {
+        // register vtk output field for temperature
+        vtkOutputModule.addPrimaryVariable("temperature", Indices::temperatureIdx);
+    }
+};
+
+} // end namespace Dumux
+
+#endif
diff --git a/test/porousmediumflow/1p/implicit/1pniconductionproblem.hh b/test/porousmediumflow/1p/implicit/1pniconductionproblem.hh
index 07751e5324..59ad311ddf 100644
--- a/test/porousmediumflow/1p/implicit/1pniconductionproblem.hh
+++ b/test/porousmediumflow/1p/implicit/1pniconductionproblem.hh
@@ -32,6 +32,9 @@
 #include <dumux/porousmediumflow/implicit/problem.hh>
 #include <dumux/material/components/h2o.hh>
 #include <dumux/material/fluidmatrixinteractions/1p/thermalconductivityaverage.hh>
+
+#include <dumux/io/vtkoutputmodule.hh>
+
 #include "1pnispatialparams.hh"
 
 namespace Dumux
@@ -156,20 +159,15 @@ public:
     }
 
     /*!
-     * \brief Append all quantities of interest which can be derived
-     *        from the solution of the current time step to the VTK
-     *        writer.
+     * \brief Adds additional VTK output data to the VTKWriter. Function is called by the output module on every write.
      */
-    void addOutputVtkFields()
+    void addVtkOutputFields(VtkOutputModule<TypeTag>& outputModule) const
     {
-        //Here we calculate the analytical solution
-        auto numDofs = this->model().numDofs();
-
-        auto& temperatureExact = *(this->resultWriter().allocateManagedBuffer(numDofs));
-        auto& temperature = *(this->resultWriter().allocateManagedBuffer(numDofs));
+        auto& temperatureExact = outputModule.createScalarField("temperatureExact", dofCodim);
 
         const auto someElement = *(elements(this->gridView()).begin());
         const auto someElemSol = this->model().elementSolution(someElement, this->model().curSol());
+        const auto someInitSol = initial_(someElement.geometry().center());
 
         auto someFvGeometry = localView(this->model().globalFvGeometry());
         someFvGeometry.bindElement(someElement);
@@ -198,13 +196,10 @@ public:
                 auto globalIdx = scv.dofIndex();
                 const auto& globalPos = scv.dofPosition();
 
-                temperatureExact[globalIdx] = temperatureHigh_ + (someElemSol[0][temperatureIdx] - temperatureHigh_)
+                temperatureExact[globalIdx] = temperatureHigh_ + (someInitSol[temperatureIdx] - temperatureHigh_)
                                               *std::erf(0.5*std::sqrt(globalPos[0]*globalPos[0]*storage/time/effectiveThermalConductivity));
-                temperature[globalIdx] = this->model().curSol()[globalIdx][temperatureIdx];
             }
         }
-        this->resultWriter().attachDofData(temperatureExact, "temperatureExact", isBox);
-        this->resultWriter().attachDofData(temperature, "temperature", isBox);
     }
     /*!
      * \name Problem parameters
diff --git a/test/references/1pniboxconduction-reference.vtu b/test/references/1pniboxconduction-reference.vtu
index ba0d4b3093..677c50d9ba 100644
--- a/test/references/1pniboxconduction-reference.vtu
+++ b/test/references/1pniboxconduction-reference.vtu
@@ -2,7 +2,7 @@
 <VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">
   <UnstructuredGrid>
     <Piece NumberOfCells="200" NumberOfPoints="402">
-      <PointData Scalars="p" Vectors="velocity">
+      <PointData Scalars="p" Vectors="velocity_H2O">
         <DataArray type="Float32" Name="p" NumberOfComponents="1" format="ascii">
           100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000
           100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000
@@ -39,7 +39,7 @@
           100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000
           100000 100000 100000 100000 100000 100000
         </DataArray>
-        <DataArray type="Float32" Name="velocity" NumberOfComponents="3" format="ascii">
+        <DataArray type="Float32" Name="velocity_H2O" NumberOfComponents="3" format="ascii">
           -1.17342e-09 8.52243e-19 0 -1.16807e-09 1.68217e-18 0 -1.17342e-09 8.52243e-19 0 -1.16807e-09 1.68217e-18 0
           -1.15247e-09 3.1127e-18 0 -1.15247e-09 3.1127e-18 0 -1.1275e-09 1.84323e-18 0 -1.1275e-09 1.84323e-18 0
           -1.09416e-09 3.84099e-18 0 -1.09416e-09 3.84099e-18 0 -1.05354e-09 1.9959e-18 0 -1.05354e-09 1.9959e-18 0
-- 
GitLab