From 78b1a003097ec39d0aad49f3560526901e91f124 Mon Sep 17 00:00:00 2001
From: ChaofanChen <chaofan.chen@ufz.de>
Date: Mon, 6 Jan 2020 17:26:59 +0100
Subject: [PATCH] [1P] added BHE COP boundary condition.

---
 .../BHE/CreateFlowAndTemperatureControl.cpp   | 26 +++++++++++++++++++
 .../BHE/FlowAndTemperatureControl.h           | 21 ++++++++++++++-
 Tests/Data/Parabolic/T/BHE_1P/BHE_1P.prj      |  8 +++++-
 3 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/ProcessLib/HeatTransportBHE/BHE/CreateFlowAndTemperatureControl.cpp b/ProcessLib/HeatTransportBHE/BHE/CreateFlowAndTemperatureControl.cpp
index 25fb12fc7cf..52c311c2344 100644
--- a/ProcessLib/HeatTransportBHE/BHE/CreateFlowAndTemperatureControl.cpp
+++ b/ProcessLib/HeatTransportBHE/BHE/CreateFlowAndTemperatureControl.cpp
@@ -86,6 +86,32 @@ FlowAndTemperatureControl createFlowAndTemperatureControl(
                                       refrigerant.specific_heat_capacity,
                                       refrigerant.density};
     }
+
+    if (type == "BuildingPowerCurveConstantFlow")
+    {
+        auto const& power_curve = *BaseLib::getOrError(
+            curves,
+            //! \ogs_file_param{prj__processes__process__HEAT_TRANSPORT_BHE__borehole_heat_exchangers__borehole_heat_exchanger__flow_and_temperature_control__PowerCurveConstantFlow__power_curve}
+            config.getConfigParameter<std::string>("power_curve"),
+            "Required power curve not found.");
+
+        auto const& COP_heating_curve = *BaseLib::getOrError(
+            curves,
+            //! \ogs_file_param{prj__processes__process__HEAT_TRANSPORT_BHE__borehole_heat_exchangers__borehole_heat_exchanger__flow_and_temperature_control__PowerCurveConstantFlow__power_curve}
+            config.getConfigParameter<std::string>("cop_heating_curve"),
+            "Required power curve not found.");
+
+        //        std::vector<> power_curves;
+
+        //        power_curves.emplace_back(power_curve, COP_heating_curve);
+
+        //! \ogs_file_param{prj__processes__process__HEAT_TRANSPORT_BHE__borehole_heat_exchangers__borehole_heat_exchanger__flow_and_temperature_control__PowerCurveConstantFlow__flow_rate}
+        auto const flow_rate = config.getConfigParameter<double>("flow_rate");
+
+        return BuildingPowerCurveConstantFlow{
+            power_curve, flow_rate, refrigerant.specific_heat_capacity,
+            refrigerant.density};
+    }
     OGS_FATAL("FlowAndTemperatureControl type '%s' is not implemented.",
               type.c_str());
 }
diff --git a/ProcessLib/HeatTransportBHE/BHE/FlowAndTemperatureControl.h b/ProcessLib/HeatTransportBHE/BHE/FlowAndTemperatureControl.h
index e7d50bdb785..56609a6bb35 100644
--- a/ProcessLib/HeatTransportBHE/BHE/FlowAndTemperatureControl.h
+++ b/ProcessLib/HeatTransportBHE/BHE/FlowAndTemperatureControl.h
@@ -81,10 +81,29 @@ struct PowerCurveConstantFlow
     double density;
 };
 
+struct BuildingPowerCurveConstantFlow
+{
+    FlowAndTemperature operator()(double const T_out, double const time) const
+    {
+        double const power = power_curve.getValue(time);
+        if (power == 0)
+        {
+            return {0.0, T_out};
+        }
+        return {flow_rate, power / flow_rate / heat_capacity / density + T_out};
+    }
+    MathLib::PiecewiseLinearInterpolation const& power_curve;
+
+    double flow_rate;
+    double heat_capacity;
+    double density;
+};
+
 using FlowAndTemperatureControl = std::variant<TemperatureCurveConstantFlow,
                                                FixedPowerConstantFlow,
                                                FixedPowerFlowCurve,
-                                               PowerCurveConstantFlow>;
+                                               PowerCurveConstantFlow,
+                                               BuildingPowerCurveConstantFlow>;
 }  // namespace BHE
 }  // namespace HeatTransportBHE
 }  // namespace ProcessLib
diff --git a/Tests/Data/Parabolic/T/BHE_1P/BHE_1P.prj b/Tests/Data/Parabolic/T/BHE_1P/BHE_1P.prj
index 1dd2d67629f..d0adf480735 100644
--- a/Tests/Data/Parabolic/T/BHE_1P/BHE_1P.prj
+++ b/Tests/Data/Parabolic/T/BHE_1P/BHE_1P.prj
@@ -15,9 +15,10 @@
                 <borehole_heat_exchanger>
                     <type>1P</type>
                     <flow_and_temperature_control>
-                        <type>PowerCurveConstantFlow</type>
+                        <type>BuildingPowerCurveConstantFlow</type>
                         <flow_rate>0.00833</flow_rate>
                         <power_curve>power_curve</power_curve>
+                        <cop_heating_curve>COP_heating_curve</cop_heating_curve>
                     </flow_and_temperature_control>
                     <borehole>
                         <length>50.0</length>
@@ -231,5 +232,10 @@
             <coords>0 3600</coords>
             <values>-5000 -5000</values>
         </curve>
+        <curve>
+            <name>COP_heating_curve</name>
+            <coords>-5.0 25</coords>
+            <values>3.5 6.0</values>
+        </curve>
     </curves>
 </OpenGeoSysProject>
-- 
GitLab