From b4df9bebbd98fdf4114e945b0101f61d8b53c60e Mon Sep 17 00:00:00 2001
From: Mirko Engelpracht <engelpracht@win.ltt.rwth-aachen.de>
Date: Thu, 19 Aug 2021 10:55:46 +0200
Subject: [PATCH] Added interface to SorpPropLib.

For issue #18.
---
 .../PartialSingleWPair_SorpPropLib.mo         | 217 ++++++++++++++++++
 .../SingleComponent/BaseClasses/package.order |   1 +
 .../Modelica_VLE/H2O_Silicagel123_Schawe.mo   |   2 +-
 .../H2O_Silicagel123_Schawe_SPL.mo            |  61 +++++
 .../Tester/TestH2O_Silicagel123_Schawe_SPL.mo |  62 +++++
 .../Modelica_VLE/Tester/package.order         |   1 +
 .../Modelica_VLE/package.order                |   1 +
 .../H2O_Silicagel123_Schawe.mo                |   2 +-
 .../H2O_Silicagel123_Schawe_SPL.mo            |  71 ++++++
 .../ParameterizedModels/package.order         |   1 +
 10 files changed, 417 insertions(+), 2 deletions(-)
 create mode 100644 SorpLib/Media/WorkingPair/SingleComponent/BaseClasses/PartialSingleWPair_SorpPropLib.mo
 create mode 100644 SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/H2O_Silicagel123_Schawe_SPL.mo
 create mode 100644 SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/Tester/TestH2O_Silicagel123_Schawe_SPL.mo
 create mode 100644 SorpLib/Media/WorkingPair/SingleComponent/ParameterizedModels/H2O_Silicagel123_Schawe_SPL.mo

diff --git a/SorpLib/Media/WorkingPair/SingleComponent/BaseClasses/PartialSingleWPair_SorpPropLib.mo b/SorpLib/Media/WorkingPair/SingleComponent/BaseClasses/PartialSingleWPair_SorpPropLib.mo
new file mode 100644
index 0000000..be40342
--- /dev/null
+++ b/SorpLib/Media/WorkingPair/SingleComponent/BaseClasses/PartialSingleWPair_SorpPropLib.mo
@@ -0,0 +1,217 @@
+within SorpLib.Media.WorkingPair.SingleComponent.BaseClasses;
+partial model PartialSingleWPair_SorpPropLib
+  "Base model for all working pairs models describing single component 
+  adsorption based on SorpPropLib"
+  extends PartialSingleWPair(
+    final type_SpecEnthalpyAdsorpt=
+      Internals.Types.SpecificEnthalpyAdsorpt.AdsEnthalpy,
+    final type_AdsorptionEnthalpy=
+      Internals.Types.AdsorptionEnthalpy.ClausiusClapeyron);
+
+  //
+  // Definition of parameters
+  //
+  parameter String path_db=
+    "D:/Engelpracht/01-Modelica/01-Bib/SorpPropLib/Resources/Data/sorpproplib.json"
+    "Path to database, i.e., JSON-file of database."
+    annotation (Dialog(tab="General", group = "Equilibrium Model"));
+
+  parameter String name_sorbent = "zeolite pellet"
+    "Name of sorbent, e.g., 'zeolite pellet'"
+    annotation (Dialog(tab="General", group = "Equilibrium Model"));
+  parameter String name_sorbent_sub_type = "13X"
+    "Sub-type of sorbent, e.g., '13X'"
+    annotation (Dialog(tab="General", group = "Equilibrium Model"));
+  parameter String name_refrigerant = "Water"
+    "Name of refrigerant, e.g., 'Water'"
+    annotation (Dialog(tab="General", group = "Equilibrium Model"));
+
+  parameter String func_isotherm = "Toth"
+    "Name of functional approach for isotherm, e.g., 'Toth'"
+    annotation (Dialog(tab="General", group = "Equilibrium Model"));
+  parameter Integer func_isotherm_ID = 1
+    "ID of functional approach for isotherm, e.g., '1'"
+    annotation (Dialog(tab="General", group = "Equilibrium Model"));
+
+  parameter String func_vapor_pressure = "VaporPressure_EoS1"
+    "Name of functional approach for vapor pressure, e.g., 'VaporPressure_EoS1'"
+    annotation (Dialog(tab="General", group = "Equilibrium Model"));
+  parameter Integer func_vapor_pressure_ID = 1
+    "ID of functional approach for vapor pressure, e.g., '1'"
+    annotation (Dialog(tab="General", group = "Equilibrium Model"));
+
+  parameter String func_saturated_liquid_density = "SaturatedLiquidDensity_EoS1"
+    "Name of functional approach for saturated liquid density, e.g. 'SaturatedLiquidDensity_EoS1'"
+    annotation (Dialog(tab="General", group = "Equilibrium Model"));
+  parameter Integer func_saturated_liquid_density_ID = 1
+    "ID of functional approach for saturated liquid density, e.g., '1'"
+    annotation (Dialog(tab="General", group = "Equilibrium Model"));
+
+  replaceable model MediaModel = PartialSingleMediaModel_Surface
+    constrainedby PartialSingleMediaModel_Surface
+    "Model containing media models to calculate fluid properties required by 
+     adsorption equilibrium models"
+    annotation (Dialog(tab = "Media", group = "Media Model"),
+                choicesAllMatching=true,
+                Evaluate=true);
+
+  //
+  // Instanziation of models
+  //
+  MediaModel mediaModels(
+    final p_adsorpt=if use_stateLimiter then max(p_min, p_adsorpt) else
+      p_adsorpt,
+    final T_adsorpt=T_adsorpt,
+    final calculate_caloric_properties=calculate_caloric_properties,
+    final type_AdsorptionEnthalpy=type_AdsorptionEnthalpy,
+    final type_SpecEnthalpySorptive=type_SpecEnthalpySorptive,
+    final type_SpecEnthalpyAdsorpt=type_SpecEnthalpyAdsorpt,
+    final type_SpecHeatCapacityAdsorpt=type_SpecHeatCapacityAdsorpt,
+    final cp_adsorpt_fixed=cp_adsorpt_fixed,
+    final use_SpecVolumeAdsorpt=use_SpecVolumeAdsorpt,
+    final type_SpecVolumeAdsorpt=type_SpecVolumeAdsorpt,
+    final avoid_events=avoid_events)
+    "Model containing media models to calculate fluid properties required by 
+     adsorption equilibrium models"
+    annotation (Placement(transformation(extent={{-20,-20},{20,20}})));
+
+  SorpPropLib.WorkingPair.WPair extObj=SorpPropLib.WorkingPair.WPair(path_db,
+        name_sorbent, name_sorbent_sub_type, name_refrigerant,
+        func_isotherm, func_isotherm_ID,
+        func_vapor_pressure, func_vapor_pressure_ID,
+        func_saturated_liquid_density, func_saturated_liquid_density_ID)
+    "Initialize external object of working pair by calling its class";
+
+equation
+  //
+  // Assertion to check for invalid parameter selections
+  //
+  assert(type_SpecEnthalpyAdsorpt<>
+    Internals.Types.SpecificEnthalpyAdsorpt.BondEnthalpy,
+    "Error in working pair model: Specific adsorption enthalpy cannot be 
+     derived from specific bonding and specific bubble enthalpies since 
+     specific bonding enthalpy is not defined for equilibrium models based on 
+     the surface approach!");
+
+  //
+  // Passing through fluid properties from the media models
+  //
+  h_sorptive = mediaModels.h_sorptive
+    "Specific enthalpy of sorptive";
+  v_adsorpt = mediaModels.v_adsorpt
+    "Specific volume of adsorpt";
+  cp_adsorpt = mediaModels.cp_adsorpt
+    "Specific heat capacity of adsorpt";
+
+  //
+  // Check form of isotherm
+  //
+  if type_isotherm == Internals.Types.Isotherm.Classical then
+    //
+    // Classical form (i.e., x(p,T))
+    //
+    x_adsorpt = SorpPropLib.WorkingPair.WPairFunctions.Adsorption.General.w_pT(
+      p_adsorpt,
+      T_adsorpt,
+      extObj=extObj)
+      "Calculate equlibrium loading of adsorpt";
+
+  else
+    //
+    // Inverse form (i.e., p(x,T))
+    //
+    p_adsorpt = SorpPropLib.WorkingPair.WPairFunctions.Adsorption.General.p_wT(
+      x_adsorpt,
+      T_adsorpt,
+      extObj=extObj)
+      "Calculate equlibrium pressure of adsorpt";
+
+  end if;
+
+  //
+  // Calculate specific enthalpy of adsorpt
+  //
+  if type_SpecEnthalpyAdsorpt==
+    Internals.Types.SpecificEnthalpyAdsorpt.AdsEnthalpy then
+    // Use definition of adsorption enthalpy to calculate specific enthalpy of
+    // adsorpt
+    //
+    h_adsorpt = if calculate_caloric_properties then
+      h_sorptive - dh_ads else -1
+      "Calculation of specific enthalpy of adsorpt";
+
+  else
+    // Currently, no other calculation approach is implemented
+    //
+    h_adsorpt = if calculate_caloric_properties then
+      h_sorptive - dh_ads else -1
+      "Calculation of specific enthalpy of adsorpt";
+
+  end if;
+
+  //
+  // Calculate specific adsorption enthalpy
+  //
+  dh_bond = -1
+    "Calculation of specific bonding enthalpy: Not defined for equilibrium
+     models based on the surface approach";
+
+  dh_ads =if calculate_caloric_properties then
+    Function.SingleComponent.AdsorptionEnthalpy.dhAds_ClausiusClapeyron(
+    R_adsorpt,
+    p_adsorpt,
+    T_adsorpt,
+    SorpPropLib.WorkingPair.WPairFunctions.Adsorption.General.dw_dT_pT(
+      p_adsorpt, T_adsorpt, extObj=extObj),
+    SorpPropLib.WorkingPair.WPairFunctions.Adsorption.General.dw_dp_pT(
+      p_adsorpt, T_adsorpt, extObj=extObj)) else -1
+    "Calculation of specific adsorption enthalpy";
+
+  //
+  // Annotations
+  //
+  annotation (Documentation(revisions="<html>
+<ul>
+  <li>
+  August 19, 2021, by Mirko Engelpracht:<br/>
+  First implementation.
+  </li>
+</ul>
+</html>", info="<html>
+<p>
+A short introduction.
+</p>
+<h4>Main equations</h4>
+<p>
+Most important equations (e.g., mass and energy balances).
+</p>
+<h4>Assumptions and limitations</h4>
+<p>
+Main assumptions and limitations (e.g., ideal mixture).
+</p>
+<h4>Typical use</h4>
+<p>
+Typical use of model (e.g., to calculate mass transfer within sorbent).
+</p>
+<h4>Important parameters and options</h4>
+<p>
+Main parameters and options of the model (e.g., description of most important flags).
+</p>
+<h4>Dynamics</h4>
+<p>
+Describe which states and dynamics are present in the model
+and which parameters may be used to influence them.
+This need not be added in partial classes.
+</p>
+<h4>Validation</h4>
+<p>
+Describe whether the validation was done using
+analytical validation, comparative model validation
+or empirical validation.
+</p>
+<h4>References</h4>
+<p>
+xxx
+</p>
+</html>"));
+end PartialSingleWPair_SorpPropLib;
diff --git a/SorpLib/Media/WorkingPair/SingleComponent/BaseClasses/package.order b/SorpLib/Media/WorkingPair/SingleComponent/BaseClasses/package.order
index e12540a..10ab17e 100644
--- a/SorpLib/Media/WorkingPair/SingleComponent/BaseClasses/package.order
+++ b/SorpLib/Media/WorkingPair/SingleComponent/BaseClasses/package.order
@@ -1,4 +1,5 @@
 PartialSingleWPair
+PartialSingleWPair_SorpPropLib
 PartialSingleWPair_Surface
 PartialSingleWPair_Volumetric
 PartialSingleMediaModel
diff --git a/SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/H2O_Silicagel123_Schawe.mo b/SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/H2O_Silicagel123_Schawe.mo
index 9f6d599..253e5f6 100644
--- a/SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/H2O_Silicagel123_Schawe.mo
+++ b/SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/H2O_Silicagel123_Schawe.mo
@@ -1,6 +1,6 @@
 within SorpLib.Media.WorkingPair.SingleComponent.Modelica_VLE;
 model H2O_Silicagel123_Schawe
-  "Modelica VLE | H2O / AQSOA Z02, published by Schawe (1991)"
+  "Modelica VLE | H2O / Silica gel 123, published by Schawe (1991)"
   extends ParameterizedModels.H2O_Silicagel123_Schawe(
     final type_Media=Internals.Types.MediaModel.Modelica_VLE,
     redeclare final model MediaModel =
diff --git a/SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/H2O_Silicagel123_Schawe_SPL.mo b/SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/H2O_Silicagel123_Schawe_SPL.mo
new file mode 100644
index 0000000..febb6a2
--- /dev/null
+++ b/SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/H2O_Silicagel123_Schawe_SPL.mo
@@ -0,0 +1,61 @@
+within SorpLib.Media.WorkingPair.SingleComponent.Modelica_VLE;
+model H2O_Silicagel123_Schawe_SPL
+  "Modelica VLE | H2O / Silica gel 123, published by Schawe (1991), calculated with SorpPropLib"
+  extends ParameterizedModels.H2O_Silicagel123_Schawe_SPL(
+    final type_Media=Internals.Types.MediaModel.Modelica_VLE,
+    redeclare final model MediaModel =
+      MediaModels.SingleMediaModel_Volumetric_Modelica_VLE (
+        redeclare final package Medium =
+          Modelica.Media.Water.WaterIF97_ph),
+    avoid_events=true,
+    final use_stateLimiter=true,
+    final p_min=611.657 + 1);
+
+  //
+  // Annotations
+  //
+  annotation (Documentation(revisions="<html>
+<ul>
+  <li>
+  August 19, 2021, by Mirko Engelpracht:<br/>
+  First implementation.
+  </li>
+</ul>
+</html>", info="<html>
+<p>
+A short introduction.
+</p>
+<h4>Main equations</h4>
+<p>
+Most important equations (e.g., mass and energy balances).
+</p>
+<h4>Assumptions and limitations</h4>
+<p>
+Main assumptions and limitations (e.g., ideal mixture).
+</p>
+<h4>Typical use</h4>
+<p>
+Typical use of model (e.g., to calculate mass transfer within sorbent).
+</p>
+<h4>Important parameters and options</h4>
+<p>
+Main parameters and options of the model (e.g., description of most important flags).
+</p>
+<h4>Dynamics</h4>
+<p>
+Describe which states and dynamics are present in the model
+and which parameters may be used to influence them.
+This need not be added in partial classes.
+</p>
+<h4>Validation</h4>
+<p>
+Describe whether the validation was done using
+analytical validation, comparative model validation
+or empirical validation.
+</p>
+<h4>References</h4>
+<p>
+xxx
+</p>
+</html>"));
+end H2O_Silicagel123_Schawe_SPL;
diff --git a/SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/Tester/TestH2O_Silicagel123_Schawe_SPL.mo b/SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/Tester/TestH2O_Silicagel123_Schawe_SPL.mo
new file mode 100644
index 0000000..30e913a
--- /dev/null
+++ b/SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/Tester/TestH2O_Silicagel123_Schawe_SPL.mo
@@ -0,0 +1,62 @@
+within SorpLib.Media.WorkingPair.SingleComponent.Modelica_VLE.Tester;
+model TestH2O_Silicagel123_Schawe_SPL
+  "Test model for working pair H2O / Silicagel 123, measured by Schawe (1991), calculated with SorpPropLib"
+  extends BaseClasses.PartialTester(
+    redeclare final model WorkingPair =
+      H2O_Silicagel123_Schawe_SPL,
+    workingPair(
+      type_isotherm=TransHeat.Internals.Types.Isotherm.Inverse,
+      calculate_caloric_properties=true,
+      type_SpecEnthalpySorptive=
+        TransHeat.Internals.Types.SpecificEnthalpySorptive.Media_pT,
+      type_SpecHeatCapacityAdsorpt=
+        TransHeat.Internals.Types.SpecificHeatCapacityAdsorpt.SatLiq));
+
+  //
+  // Annotations
+  //
+  annotation (experiment(StartTime=2, StopTime=20), Documentation(revisions="<html>
+<ul>
+  <li>
+  December 14, 2020, by Mirko Engelpracht:<br/>
+  First implementation.
+  </li>
+</ul>
+</html>", info="<html>
+<p>
+A short introduction.
+</p>
+<h4>Main equations</h4>
+<p>
+Most important equations (e.g., mass and energy balances).
+</p>
+<h4>Assumptions and limitations</h4>
+<p>
+Main assumptions and limitations (e.g., ideal mixture).
+</p>
+<h4>Typical use</h4>
+<p>
+Typical use of model (e.g., to calculate mass transfer within sorbent).
+</p>
+<h4>Important parameters and options</h4>
+<p>
+Main parameters and options of the model (e.g., description of most important flags).
+</p>
+<h4>Dynamics</h4>
+<p>
+Describe which states and dynamics are present in the model
+and which parameters may be used to influence them.
+This need not be added in partial classes.
+</p>
+<h4>Validation</h4>
+<p>
+Describe whether the validation was done using
+analytical validation, comparative model validation
+or empirical validation.
+</p>
+<h4>References</h4>
+<p>
+xxx
+</p>
+</html>"));
+end TestH2O_Silicagel123_Schawe_SPL;
diff --git a/SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/Tester/package.order b/SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/Tester/package.order
index 6886c8f..aad7d9a 100644
--- a/SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/Tester/package.order
+++ b/SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/Tester/package.order
@@ -1,3 +1,4 @@
 TestH2O_AQSOAZ02_Goldsworthy
 TestH2O_Silicagel123_Schawe
+TestH2O_Silicagel123_Schawe_SPL
 TestH2O_Zeolite5A_Wang
diff --git a/SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/package.order b/SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/package.order
index 6bb7f00..b53b360 100644
--- a/SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/package.order
+++ b/SorpLib/Media/WorkingPair/SingleComponent/Modelica_VLE/package.order
@@ -1,4 +1,5 @@
 H2O_AQSOAZ02_Goldsworthy
 H2O_Silicagel123_Schawe
+H2O_Silicagel123_Schawe_SPL
 H2O_Zeolite5A_Wang
 Tester
diff --git a/SorpLib/Media/WorkingPair/SingleComponent/ParameterizedModels/H2O_Silicagel123_Schawe.mo b/SorpLib/Media/WorkingPair/SingleComponent/ParameterizedModels/H2O_Silicagel123_Schawe.mo
index 4bc6289..e5d319b 100644
--- a/SorpLib/Media/WorkingPair/SingleComponent/ParameterizedModels/H2O_Silicagel123_Schawe.mo
+++ b/SorpLib/Media/WorkingPair/SingleComponent/ParameterizedModels/H2O_Silicagel123_Schawe.mo
@@ -1,6 +1,6 @@
 within SorpLib.Media.WorkingPair.SingleComponent.ParameterizedModels;
 partial model H2O_Silicagel123_Schawe
-  "H2O / AQSOA Z02, published by Schawe (1991)"
+  "H2O / Silica gel 123, published by Schawe (1991)"
   extends BaseClasses.PartialSingleWPair_Volumetric(
     final M_adsorpt = 0.018015267,
     final c={5.072313e-4,1.305531e5,-8.492403e4,4.128962e-6},
diff --git a/SorpLib/Media/WorkingPair/SingleComponent/ParameterizedModels/H2O_Silicagel123_Schawe_SPL.mo b/SorpLib/Media/WorkingPair/SingleComponent/ParameterizedModels/H2O_Silicagel123_Schawe_SPL.mo
new file mode 100644
index 0000000..389bf92
--- /dev/null
+++ b/SorpLib/Media/WorkingPair/SingleComponent/ParameterizedModels/H2O_Silicagel123_Schawe_SPL.mo
@@ -0,0 +1,71 @@
+within SorpLib.Media.WorkingPair.SingleComponent.ParameterizedModels;
+partial model H2O_Silicagel123_Schawe_SPL
+  "H2O / Silica gel 123, published by Schawe (1991), calculated with SorpPropLib"
+  extends BaseClasses.PartialSingleWPair_SorpPropLib(
+    final M_adsorpt = 0.018015267,
+    path_db= "D:/Engelpracht/01-Modelica/01-Bib/SorpPropLib/Resources/Data/sorpproplib.json",
+    final name_sorbent = "silica gel pellet",
+    final name_sorbent_sub_type = "123",
+    final name_refrigerant = "Water",
+    final func_isotherm = "DubininArctan1",
+    final func_isotherm_ID = 1,
+    final func_vapor_pressure = "VaporPressure_EoS1",
+    final func_vapor_pressure_ID = 1,
+    final func_saturated_liquid_density = "SaturatedLiquidDensity_EoS1",
+    final func_saturated_liquid_density_ID = 1);
+
+  //
+  // Annotations
+  //
+  annotation (Documentation(revisions="<html>
+<ul>
+  <li>
+  August 19, 2021, by Mirko Engelpracht:<br/>
+  Revision after restructering of the library.
+  </li>
+  <li>
+  November 17, 2017, by Uwe Bau:<br/>
+  Tidy up implementation and enhance documentation for publication of library.
+  </li>
+</ul>
+</html>", info="<html>
+<p>
+This model provides the equilibrium data for the working pair Silica gel Grace 123 / Water as measured by Schawe (1999).
+</p>
+<h4>Main equations</h4>
+<p>
+Most important equations (e.g., mass and energy balances).
+</p>
+<h4>Assumptions and limitations</h4>
+<p>
+Main assumptions and limitations (e.g., ideal mixture).
+</p>
+<h4>Typical use</h4>
+<p>
+Typical use of model (e.g., to calculate mass transfer within sorbent).
+</p>
+<h4>Important parameters and options</h4>
+<p>
+Main parameters and options of the model (e.g., description of most important flags).
+</p>
+<h4>Dynamics</h4>
+<p>
+Describe which states and dynamics are present in the model
+and which parameters may be used to influence them.
+This need not be added in partial classes.
+</p>
+<h4>Validation</h4>
+<p>
+Describe whether the validation was done using
+analytical validation, comparative model validation
+or empirical validation.
+</p>
+<h4>References</h4>
+<p>
+  <ul>
+    <li>Dubinin, M.M. Adsorption in micropores. J. Colloid Interface Sci., 1967, 23(4), 487-499.</li>
+    <li>Schawe, D. Theoretical and Experimental Investigations of an Adsorption Heat Pump with Heat Transfer between two Adsorbers. PhD Thesis. Stuttgart, 1999. </li>
+  </ul>
+</p>
+</html>"));
+end H2O_Silicagel123_Schawe_SPL;
diff --git a/SorpLib/Media/WorkingPair/SingleComponent/ParameterizedModels/package.order b/SorpLib/Media/WorkingPair/SingleComponent/ParameterizedModels/package.order
index cb748dc..19c432d 100644
--- a/SorpLib/Media/WorkingPair/SingleComponent/ParameterizedModels/package.order
+++ b/SorpLib/Media/WorkingPair/SingleComponent/ParameterizedModels/package.order
@@ -3,6 +3,7 @@ CO2_Zeolite5A_Wang
 CO2_Zeolite13X_Dantas
 H2O_AQSOAZ02_Goldsworthy
 H2O_Silicagel123_Schawe
+H2O_Silicagel123_Schawe_SPL
 H2O_Zeolite5A_Wang
 N2_ActivatedCarbon_Dantas
 N2_Zeolite13X_Dantas
-- 
GitLab