From e6f8c1d5217b48dae1db59e8dd049cbecaf12d2d Mon Sep 17 00:00:00 2001
From: Norbert Grunwald <Norbert.Grunwald@ufz.de>
Date: Thu, 5 Sep 2019 09:58:10 +0200
Subject: [PATCH] added a Test for MPL IdealGasLaw property

---
 Tests/MaterialLib/TestMPLIdealGasLaw.cpp | 118 +++++++++++++++++++++++
 1 file changed, 118 insertions(+)
 create mode 100644 Tests/MaterialLib/TestMPLIdealGasLaw.cpp

diff --git a/Tests/MaterialLib/TestMPLIdealGasLaw.cpp b/Tests/MaterialLib/TestMPLIdealGasLaw.cpp
new file mode 100644
index 00000000000..bcdeb1d4e0e
--- /dev/null
+++ b/Tests/MaterialLib/TestMPLIdealGasLaw.cpp
@@ -0,0 +1,118 @@
+/**
+ * \file
+ *
+ * \copyright
+ * Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/project/license
+ *
+ */
+#include <gtest/gtest.h>
+#include <sstream>
+
+#include "TestMPL.h"
+#include "Tests/TestTools.h"
+
+#include "MaterialLib/MPL/Medium.h"
+#include "MaterialLib/MPL/Properties/IdealGasLaw.h"
+#include "MaterialLib/PhysicalConstant.h"
+
+TEST(MaterialPropertyLib, IdealGasLawOfPurePhase)
+{
+    const double pressure_norm = 101325.0;    // Pa
+    const double temperature_norm = 273.15;   // K
+    const double molar_mass_air = 0.02905;  // kg/mol
+    const auto R = MaterialLib::PhysicalConstant::IdealGasConstant;
+
+    const double density_norm_air =
+        pressure_norm * molar_mass_air / R / temperature_norm;
+
+    const double d_rho_dT_air = -density_norm_air / temperature_norm;
+    const double d_rho_dp_air = density_norm_air / pressure_norm;
+
+    const double d_rho2_dp2_air = 0.;
+    const double d_rho2_dT2_air =
+        2. * density_norm_air / temperature_norm / temperature_norm;
+    const double d_rho2_dTdp_air =
+        -density_norm_air / temperature_norm / pressure_norm;
+
+    std::stringstream m;
+    m << "<medium>\n";
+    m << "<phases><phase>\n";
+    m << "  <type>Gas</type>\n";
+    m << "  <properties>\n";
+    m << "    <property>\n";
+    m << "      <name>density</name>\n";
+    m << "      <type>IdealGaslaw</type>\n";
+    m << "    </property>\n";
+    m << "    <property>\n";
+    m << "      <name>molar_mass</name>\n";
+    m << "      <type>Constant</type>\n";
+    m << "      <value>" << molar_mass_air << "</value>\n";
+    m << "    </property>\n";
+    m << "  </properties>\n";
+    m << "</phase></phases>\n";
+    m << "<properties></properties>\n";
+    m << "</medium>\n";
+
+    auto const& medium = createTestMaterial(m.str());
+    auto const& gas_phase = medium->phase("Gas");
+
+    MaterialPropertyLib::VariableArray variable_array;
+    variable_array[static_cast<int>(
+        MaterialPropertyLib::Variable::phase_pressure)] = pressure_norm;
+    variable_array[static_cast<int>(
+        MaterialPropertyLib::Variable::temperature)] = temperature_norm;
+
+    ParameterLib::SpatialPosition const pos;
+    double const time = std::numeric_limits<double>::quiet_NaN();
+
+    auto const density =
+        gas_phase.property(MaterialPropertyLib::PropertyType::density)
+            .template value<double>(variable_array, pos, time);
+
+    auto const d_rho_dT =
+        gas_phase.property(MaterialPropertyLib::PropertyType::density)
+            .template dValue<double>(variable_array,
+                                     MaterialPropertyLib::Variable::temperature,
+                                     pos, time);
+
+    auto const d_rho_dp =
+        gas_phase.property(MaterialPropertyLib::PropertyType::density)
+            .template dValue<double>(
+                variable_array, MaterialPropertyLib::Variable::phase_pressure,
+                pos, time);
+
+    auto const d_rho2_dp2 =
+        gas_phase.property(MaterialPropertyLib::PropertyType::density)
+            .template d2Value<double>(
+                variable_array, MaterialPropertyLib::Variable::phase_pressure,
+                MaterialPropertyLib::Variable::phase_pressure, pos, time);
+
+    auto const d_rho2_dT2 =
+        gas_phase.property(MaterialPropertyLib::PropertyType::density)
+            .template d2Value<double>(
+                variable_array, MaterialPropertyLib::Variable::temperature,
+                MaterialPropertyLib::Variable::temperature, pos, time);
+
+    auto const d_rho2_dTdp =
+        gas_phase.property(MaterialPropertyLib::PropertyType::density)
+            .template d2Value<double>(
+                variable_array, MaterialPropertyLib::Variable::temperature,
+                MaterialPropertyLib::Variable::phase_pressure, pos, time);
+
+    auto const d_rho2_dpdT =
+        gas_phase.property(MaterialPropertyLib::PropertyType::density)
+            .template d2Value<double>(
+                variable_array, MaterialPropertyLib::Variable::phase_pressure,
+                MaterialPropertyLib::Variable::temperature, pos, time);
+
+    ASSERT_NEAR(density_norm_air, density, 1.e-10);
+    ASSERT_NEAR(d_rho_dT_air, d_rho_dT, 1.e-10);
+    ASSERT_NEAR(d_rho_dp_air, d_rho_dp, 1.e-10);
+    ASSERT_NEAR(d_rho2_dp2_air, d_rho2_dp2, 1.e-10);
+    ASSERT_NEAR(d_rho2_dT2_air, d_rho2_dT2, 1.e-10);
+    ASSERT_NEAR(d_rho2_dTdp_air, d_rho2_dTdp, 1.e-10);
+    ASSERT_EQ(d_rho2_dTdp, d_rho2_dpdT);
+}
\ No newline at end of file
-- 
GitLab