From d82bdbfe98e4dba5995ec36a3785ff971e1f91b3 Mon Sep 17 00:00:00 2001
From: Beatrix Becker <beatrix.becker@iws.uni-stuttgart.de>
Date: Mon, 16 Jul 2018 16:48:30 +0200
Subject: [PATCH] [exercise-fluidsystem][2pproblem] gnuplot to plot density of
 component

---
 exercises/exercise-fluidsystem/2pproblem.hh   | 24 +++++++++++++++++++
 .../exercise-fluidsystem_a.input              |  3 +++
 2 files changed, 27 insertions(+)

diff --git a/exercises/exercise-fluidsystem/2pproblem.hh b/exercises/exercise-fluidsystem/2pproblem.hh
index dc7347ae..0e5d7438 100644
--- a/exercises/exercise-fluidsystem/2pproblem.hh
+++ b/exercises/exercise-fluidsystem/2pproblem.hh
@@ -59,6 +59,9 @@
 // The two-phase immiscible fluid system
 #include <dumux/material/fluidsystems/2pimmiscible.hh>
 
+// The interface to create plots during simulation
+#include <dumux/io/gnuplotinterface.hh>
+
 namespace Dumux{
 // Forward declaration of the problem class
 template <class TypeTag> class ExerciseFluidsystemProblemTwoP;
@@ -156,6 +159,8 @@ public:
 
         // set the depth of the bottom of the reservoir
         depthBOR_ = this->fvGridGeometry().bBoxMax()[dimWorld-1];
+        if(getParam<bool>("Output.PlotDensity"))
+            plotDensity_();
     }
 
     /*!
@@ -282,8 +287,27 @@ public:
     }
 
 private:
+    void plotDensity_()
+    {
+        std::vector<double> x(100);
+        std::vector<double> y(100);
+        for (int i=0; i<100; ++i)
+            x[i] = 1e4 + i*100910;
+        for (int i=0; i<100; ++i)
+            y[i] = MyCompressibleComponent<Scalar>::liquidDensity(300, x[i]);
+        gnuplot_.resetPlot();
+        gnuplot_.setXRange(1e4, 1e7);
+        gnuplot_.setOption("set logscale x 10");
+        gnuplot_.setYRange(1440, 1480);
+        gnuplot_.setXlabel("pressure [Pa]");
+        gnuplot_.setYlabel("density [kg/m^3]");
+        gnuplot_.addDataSetToPlot(x, y, "YourComponent_density.dat", "w l t 'Liquid density of your component'");
+        gnuplot_.plot("YourComponent_density");
+    }
+
     Scalar eps_; //! small epsilon value
     Scalar depthBOR_; //! depth at the bottom of the reservoir
+    Dumux::GnuplotInterface<double> gnuplot_; //! collects data for plotting
 };
 }
 
diff --git a/exercises/exercise-fluidsystem/exercise-fluidsystem_a.input b/exercises/exercise-fluidsystem/exercise-fluidsystem_a.input
index c7c82904..8b18ca89 100644
--- a/exercises/exercise-fluidsystem/exercise-fluidsystem_a.input
+++ b/exercises/exercise-fluidsystem/exercise-fluidsystem_a.input
@@ -8,3 +8,6 @@ Name = exercise-fluidsystem_a # name will be given to e.g. to the vtk result fil
 [Grid]
 UpperRight = 60 60 # x-/y-coordinates of the upper-right corner of the grid [m]
 Cells = 60 60 # x-/y-resolution of the grid
+
+[Output]
+PlotDensity = false # plot density over pressure for your component
-- 
GitLab