Repository: oemof/tespy

Issue:
The Ref class imposes negative value for delta
... which is unintuitive.

Discussion:

Patch:
diff --git a/docs/whats_new.rst b/docs/whats_new.rst
index f03b829f..7f5718e0 100644
--- a/docs/whats_new.rst
+++ b/docs/whats_new.rst
@@ -3,6 +3,7 @@ What's New
 
 Discover noteable new features and improvements in each release
 
+.. include::  whats_new/v0-7-2.rst
 .. include::  whats_new/v0-7-1.rst
 .. include::  whats_new/v0-7-0.rst
 .. include::  whats_new/v0-6-3.rst
diff --git a/docs/whats_new/v0-7-2.rst b/docs/whats_new/v0-7-2.rst
new file mode 100644
index 00000000..ca1c1c59
--- /dev/null
+++ b/docs/whats_new/v0-7-2.rst
@@ -0,0 +1,12 @@
+v0.7.2 - Under development
+++++++++++++++++++++++++++
+
+Bug Fixes
+#########
+- The `delta` value of the :py:class:`tespy.connections.connection.Ref` class
+  was oriented with the wrong sign. A positive delta lead to a negative value.
+  Fixed in (`PR #459 <https://github.com/oemof/tespy/pull/459>`__).
+
+Contributors
+############
+- Francesco Witte (`@fwitte <https://github.com/fwitte>`__)
diff --git a/pyproject.toml b/pyproject.toml
index 7f9b42ce..eb184e99 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -47,7 +47,7 @@ classifiers = [
 ]
 requires-python = ">=3.9"
 dependencies = [
-    "CoolProp>=6.6,<7",
+    "CoolProp>=6.4,<7",
     "jinja2",
     "matplotlib>=3.2.1,<4",
     "numpy>=1.13.3,<2",
diff --git a/src/tespy/connections/connection.py b/src/tespy/connections/connection.py
index ceb64a66..459bcd14 100644
--- a/src/tespy/connections/connection.py
+++ b/src/tespy/connections/connection.py
@@ -726,7 +726,7 @@ class Connection:
         ref = self.get_attr(f"{variable}_ref").ref
         self.residual[k] = (
             self.get_attr(variable).val_SI
-            - ref.obj.get_attr(variable).val_SI * ref.factor + ref.delta_SI
+            - (ref.obj.get_attr(variable).val_SI * ref.factor + ref.delta_SI)
         )
 
     def primary_ref_deriv(self, k, **kwargs):
@@ -761,7 +761,7 @@ class Connection:
     def T_ref_func(self, k, **kwargs):
         ref = self.T_ref.ref
         self.residual[k] = (
-            self.calc_T() - ref.obj.calc_T() * ref.factor + ref.delta_SI
+            self.calc_T() - (ref.obj.calc_T() * ref.factor + ref.delta_SI)
         )
 
     def T_ref_deriv(self, k, **kwargs):
@@ -810,7 +810,7 @@ class Connection:
         ref = self.v_ref.ref
         self.residual[k] = (
             self.calc_vol(T0=self.T.val_SI) * self.m.val_SI
-            - ref.obj.calc_vol(T0=ref.obj.T.val_SI) * ref.obj.m.val_SI * ref.factor + ref.delta_SI
+            - (ref.obj.calc_vol(T0=ref.obj.T.val_SI) * ref.obj.m.val_SI * ref.factor + ref.delta_SI)
         )
 
     def v_ref_deriv(self, k, **kwargs):
diff --git a/src/tespy/tools/fluid_properties/wrappers.py b/src/tespy/tools/fluid_properties/wrappers.py
index 565c98bf..bc2f84df 100644
--- a/src/tespy/tools/fluid_properties/wrappers.py
+++ b/src/tespy/tools/fluid_properties/wrappers.py
@@ -191,6 +191,15 @@ class CoolPropWrapper(FluidPropertyWrapper):
         return self.AS.hmass()
 
     def h_pT(self, p, T):
+        if self.back_end == "INCOMP":
+            if T == (self._T_max + self._T_min) / 2:
+                T += ERR
+                self.AS.update(CP.PT_INPUTS, p, T)
+                h = self.AS.hmass() * 0.5
+                T -= 2 * ERR
+                self.AS.update(CP.PT_INPUTS, p, T)
+                h += self.AS.hmass() * 0.5
+                return h
         self.AS.update(CP.PT_INPUTS, p, T)
         return self.AS.hmass()
 


Test patch:
diff --git a/tests/test_connections.py b/tests/test_connections.py
index acc620a2..6d35bdf8 100644
--- a/tests/test_connections.py
+++ b/tests/test_connections.py
@@ -58,7 +58,7 @@ class TestConnections:
         c2.set_attr(v=Ref(c1, 2, 10))
         self.nw.solve('design')
 
-        v_expected = round(c1.v.val * 2 - 10, 4)
+        v_expected = round(c1.v.val * 2 + 10, 4)
         v_is = round(c2.v.val, 4)
         msg = (
             'The mass flow of the connection 2 should be equal to '
@@ -87,7 +87,7 @@ class TestConnections:
         c2.set_attr(T=Ref(c1, 1.5, -75))
         self.nw.solve('design')
 
-        T_expected = round(convert_from_SI("T", c1.T.val_SI * 1.5, c1.T.unit) + 75, 4)
+        T_expected = round(convert_from_SI("T", c1.T.val_SI * 1.5, c1.T.unit) - 75, 4)
         T_is = round(c2.T.val, 4)
         msg = (
             'The temperature of the connection 2 should be equal to '
@@ -116,7 +116,7 @@ class TestConnections:
         c2.set_attr(m=Ref(c1, 2, -0.5))
         self.nw.solve('design')
 
-        m_expected = round(convert_from_SI("m", c1.m.val_SI * 2, c1.m.unit) + 0.5, 4)
+        m_expected = round(convert_from_SI("m", c1.m.val_SI * 2, c1.m.unit) - 0.5, 4)
         m_is = round(c2.m.val, 4)
         msg = (
             'The mass flow of the connection 2 should be equal to '