From 39220ac58ca2e5c5cc617146d58381e405b06e7f Mon Sep 17 00:00:00 2001
From: ChaofanChen <chaofan.chen@ufz.de>
Date: Wed, 4 Mar 2020 19:01:12 +0100
Subject: [PATCH] [BHE] add function to return BHE BC nodes and components.

---
 .../HeatTransportBHE/BHE/BHECommonCoaxial.cpp | 20 ++++++++++++
 .../HeatTransportBHE/BHE/BHECommonCoaxial.h   | 12 +++++++
 ProcessLib/HeatTransportBHE/BHE/BHE_1P.cpp    | 20 ++++++++++++
 ProcessLib/HeatTransportBHE/BHE/BHE_1P.h      | 12 +++++++
 ProcessLib/HeatTransportBHE/BHE/BHE_1U.cpp    | 21 +++++++++++++
 ProcessLib/HeatTransportBHE/BHE/BHE_1U.h      | 11 +++++++
 ProcessLib/HeatTransportBHE/BHE/BHE_2U.cpp    | 21 +++++++++++++
 ProcessLib/HeatTransportBHE/BHE/BHE_2U.h      | 12 +++++++
 .../HeatTransportBHEProcess.cpp               | 31 +++++++++++++------
 9 files changed, 150 insertions(+), 10 deletions(-)

diff --git a/ProcessLib/HeatTransportBHE/BHE/BHECommonCoaxial.cpp b/ProcessLib/HeatTransportBHE/BHE/BHECommonCoaxial.cpp
index eb2e2c5e00e..15090b71e66 100644
--- a/ProcessLib/HeatTransportBHE/BHE/BHECommonCoaxial.cpp
+++ b/ProcessLib/HeatTransportBHE/BHE/BHECommonCoaxial.cpp
@@ -131,6 +131,26 @@ BHECommonCoaxial::calcThermalResistances(double const Nu_inner_pipe,
     return getThermalResistances(R_gs, R_ff, R_fg);
 }
 
+std::array<std::pair<std::size_t /*node_id*/, int /*component*/>, 2>
+BHECommonCoaxial::getBHEInflowDirichletBCNodesAndComponents(
+    std::size_t const top_node_id,
+    std::size_t const /*bottom_node_id*/,
+    int const in_component_id) const
+{
+    return {std::make_pair(top_node_id, in_component_id),
+            std::make_pair(top_node_id, in_component_id + 1)};
+}
+
+std::optional<
+    std::array<std::pair<std::size_t /*node_id*/, int /*component*/>, 2>>
+BHECommonCoaxial::getBHEBottomDirichletBCNodesAndComponents(
+    std::size_t const bottom_node_id, int const in_component_id,
+    int const out_component_id) const
+{
+    return {{std::make_pair(bottom_node_id, in_component_id),
+             std::make_pair(bottom_node_id, out_component_id)}};
+}
+
 void BHECommonCoaxial::updateHeatTransferCoefficients(double const flow_rate)
 {
     auto const tm_flow_properties_annulus =
diff --git a/ProcessLib/HeatTransportBHE/BHE/BHECommonCoaxial.h b/ProcessLib/HeatTransportBHE/BHE/BHECommonCoaxial.h
index 1d1d30ac5d8..efb715f7a9a 100644
--- a/ProcessLib/HeatTransportBHE/BHE/BHECommonCoaxial.h
+++ b/ProcessLib/HeatTransportBHE/BHE/BHECommonCoaxial.h
@@ -48,6 +48,18 @@ public:
     static constexpr std::pair<int, int> inflow_outflow_bc_component_ids[] = {
         {0, 1}};
 
+    std::array<std::pair<std::size_t /*node_id*/, int /*component*/>, 2>
+    getBHEInflowDirichletBCNodesAndComponents(
+        std::size_t const top_node_id,
+        std::size_t const /*bottom_node_id*/,
+        int const in_component_id) const;
+
+    std::optional<
+        std::array<std::pair<std::size_t /*node_id*/, int /*component*/>, 2>>
+    getBHEBottomDirichletBCNodesAndComponents(std::size_t const bottom_node_id,
+                                              int const in_component_id,
+                                              int const out_component_id) const;
+
     std::array<double, number_of_unknowns> pipeHeatConductions() const;
 
     std::array<Eigen::Vector3d, number_of_unknowns> pipeAdvectionVectors(
diff --git a/ProcessLib/HeatTransportBHE/BHE/BHE_1P.cpp b/ProcessLib/HeatTransportBHE/BHE/BHE_1P.cpp
index c9dd0544ce2..436a4c73f59 100644
--- a/ProcessLib/HeatTransportBHE/BHE/BHE_1P.cpp
+++ b/ProcessLib/HeatTransportBHE/BHE/BHE_1P.cpp
@@ -147,6 +147,26 @@ std::array<double, BHE_1P::number_of_unknowns> BHE_1P::calcThermalResistances(
     return {{R_fg, R_gs}};
 }
 
+std::array<std::pair<std::size_t /*node_id*/, int /*component*/>, 2>
+BHE_1P::getBHEInflowDirichletBCNodesAndComponents(
+    std::size_t const top_node_id,
+    std::size_t const bottom_node_id,
+    int const in_component_id) const
+{
+    return {std::make_pair(top_node_id, in_component_id),
+            std::make_pair(bottom_node_id, in_component_id)};
+}
+
+std::optional<
+    std::array<std::pair<std::size_t /*node_id*/, int /*component*/>, 2>>
+BHE_1P::getBHEBottomDirichletBCNodesAndComponents(
+    std::size_t const /*bottom_node_id*/,
+    int const /*in_component_id*/,
+    int const /*out_component_id*/) const
+{
+    return {};
+}
+
 std::array<double, BHE_1P::number_of_unknowns> BHE_1P::crossSectionAreas() const
 {
     return {{_pipe.single_pipe.area(),
diff --git a/ProcessLib/HeatTransportBHE/BHE/BHE_1P.h b/ProcessLib/HeatTransportBHE/BHE/BHE_1P.h
index cebe65cfbe9..b14896c1c47 100644
--- a/ProcessLib/HeatTransportBHE/BHE/BHE_1P.h
+++ b/ProcessLib/HeatTransportBHE/BHE/BHE_1P.h
@@ -111,6 +111,18 @@ public:
     static constexpr std::pair<int, int> inflow_outflow_bc_component_ids[] = {
         {0, 1}};
 
+    std::array<std::pair<std::size_t /*node_id*/, int /*component*/>, 2>
+    getBHEInflowDirichletBCNodesAndComponents(std::size_t const top_node_id,
+                                              std::size_t const bottom_node_id,
+                                              int const in_component_id) const;
+
+    std::optional<
+        std::array<std::pair<std::size_t /*node_id*/, int /*component*/>, 2>>
+    getBHEBottomDirichletBCNodesAndComponents(
+        std::size_t const /*bottom_node_id*/,
+        int const /*in_component_id*/,
+        int const /*out_component_id*/) const;
+
 public:
     std::array<double, number_of_unknowns> crossSectionAreas() const;
 
diff --git a/ProcessLib/HeatTransportBHE/BHE/BHE_1U.cpp b/ProcessLib/HeatTransportBHE/BHE/BHE_1U.cpp
index 603c7afb045..38e0f829ccc 100644
--- a/ProcessLib/HeatTransportBHE/BHE/BHE_1U.cpp
+++ b/ProcessLib/HeatTransportBHE/BHE/BHE_1U.cpp
@@ -228,6 +228,27 @@ std::array<double, BHE_1U::number_of_unknowns> BHE_1U::calcThermalResistances(
     // -------------------------------------------------------------------------
 }
 
+std::array<std::pair<std::size_t /*node_id*/, int /*component*/>, 2>
+BHE_1U::getBHEInflowDirichletBCNodesAndComponents(
+    std::size_t const top_node_id,
+    std::size_t const /*bottom_node_id*/,
+    int const in_component_id) const
+{
+    return {std::make_pair(top_node_id, in_component_id),
+            std::make_pair(top_node_id, in_component_id + 1)};
+}
+
+std::optional<
+    std::array<std::pair<std::size_t /*node_id*/, int /*component*/>, 2>>
+BHE_1U::getBHEBottomDirichletBCNodesAndComponents(
+    std::size_t const bottom_node_id,
+    int const in_component_id,
+    int const out_component_id) const
+{
+    return {{std::make_pair(bottom_node_id, in_component_id),
+             std::make_pair(bottom_node_id, out_component_id)}};
+}
+
 std::array<double, BHE_1U::number_of_unknowns> BHE_1U::crossSectionAreas() const
 {
     return {{_pipes.inlet.area(), _pipes.outlet.area(),
diff --git a/ProcessLib/HeatTransportBHE/BHE/BHE_1U.h b/ProcessLib/HeatTransportBHE/BHE/BHE_1U.h
index f9d06541738..a699fb256b6 100644
--- a/ProcessLib/HeatTransportBHE/BHE/BHE_1U.h
+++ b/ProcessLib/HeatTransportBHE/BHE/BHE_1U.h
@@ -138,6 +138,17 @@ public:
     static constexpr std::pair<int, int> inflow_outflow_bc_component_ids[] = {
         {0, 1}};
 
+    std::array<std::pair<std::size_t /*node_id*/, int /*component*/>, 2>
+    getBHEInflowDirichletBCNodesAndComponents(
+        std::size_t const top_node_id,
+        std::size_t const /*bottom_node_id*/,
+        int const in_component_id) const;
+    std::optional<
+        std::array<std::pair<std::size_t /*node_id*/, int /*component*/>, 2>>
+    getBHEBottomDirichletBCNodesAndComponents(std::size_t const bottom_node_id,
+                                              int const in_component_id,
+                                              int const out_component_id) const;
+
 public:
     std::array<double, number_of_unknowns> crossSectionAreas() const;
 
diff --git a/ProcessLib/HeatTransportBHE/BHE/BHE_2U.cpp b/ProcessLib/HeatTransportBHE/BHE/BHE_2U.cpp
index 4f70cf7c734..75a862340f5 100644
--- a/ProcessLib/HeatTransportBHE/BHE/BHE_2U.cpp
+++ b/ProcessLib/HeatTransportBHE/BHE/BHE_2U.cpp
@@ -258,6 +258,27 @@ std::array<double, BHE_2U::number_of_unknowns> BHE_2U::calcThermalResistances(
     // -------------------------------------------------------------------------
 }
 
+std::array<std::pair<std::size_t /*node_id*/, int /*component*/>, 2>
+BHE_2U::getBHEInflowDirichletBCNodesAndComponents(
+    std::size_t const top_node_id,
+    std::size_t const /*bottom_node_id*/,
+    int const in_component_id) const
+{
+    return {std::make_pair(top_node_id, in_component_id),
+            std::make_pair(top_node_id, in_component_id + 2)};
+}
+
+std::optional<
+    std::array<std::pair<std::size_t /*node_id*/, int /*component*/>, 2>>
+BHE_2U::getBHEBottomDirichletBCNodesAndComponents(
+    std::size_t const bottom_node_id,
+    int const in_component_id,
+    int const out_component_id) const
+{
+    return {{std::make_pair(bottom_node_id, in_component_id),
+             std::make_pair(bottom_node_id, out_component_id)}};
+}
+
 std::array<double, BHE_2U::number_of_unknowns> BHE_2U::crossSectionAreas() const
 {
     return {{
diff --git a/ProcessLib/HeatTransportBHE/BHE/BHE_2U.h b/ProcessLib/HeatTransportBHE/BHE/BHE_2U.h
index 466068806a3..0b0b22756a6 100644
--- a/ProcessLib/HeatTransportBHE/BHE/BHE_2U.h
+++ b/ProcessLib/HeatTransportBHE/BHE/BHE_2U.h
@@ -200,6 +200,18 @@ public:
     static constexpr std::pair<int, int> inflow_outflow_bc_component_ids[] = {
         {0, 2}, {1, 3}};
 
+    std::array<std::pair<std::size_t /*node_id*/, int /*component*/>, 2>
+    getBHEInflowDirichletBCNodesAndComponents(
+        std::size_t const top_node_id,
+        std::size_t const /*bottom_node_id*/,
+        int const in_component_id) const;
+
+    std::optional<
+        std::array<std::pair<std::size_t /*node_id*/, int /*component*/>, 2>>
+    getBHEBottomDirichletBCNodesAndComponents(std::size_t const bottom_node_id,
+                                              int const in_component_id,
+                                              int const out_component_id) const;
+
 public:
     std::array<double, number_of_unknowns> crossSectionAreas() const;
 
diff --git a/ProcessLib/HeatTransportBHE/HeatTransportBHEProcess.cpp b/ProcessLib/HeatTransportBHE/HeatTransportBHEProcess.cpp
index 261cf474be4..cf4ca0df634 100644
--- a/ProcessLib/HeatTransportBHE/HeatTransportBHEProcess.cpp
+++ b/ProcessLib/HeatTransportBHE/HeatTransportBHEProcess.cpp
@@ -367,20 +367,31 @@ void HeatTransportBHEProcess::createBHEBoundaryConditionTopBottom(
                     bcs.addBoundaryCondition(
                         createBHEInflowDirichletBoundaryCondition(
                             get_global_bhe_bc_indices(
-                                {{{bc_top_node_id, in_out_component_id.first},
-                                  {bc_top_node_id,
-                                   in_out_component_id.second}}}),
+                                bhe.getBHEInflowDirichletBCNodesAndComponents(
+                                    bc_top_node_id, bc_bottom_node_id,
+                                    in_out_component_id.first)),
                             [&bhe](double const T, double const t) {
                                 return bhe.updateFlowRateAndTemperature(T, t);
                             }));
                 }
-                // Bottom, outflow, all cases
-                bcs.addBoundaryCondition(
-                    createBHEBottomDirichletBoundaryCondition(
-                        get_global_bhe_bc_indices(
-                            {{{bc_bottom_node_id, in_out_component_id.first},
-                              {bc_bottom_node_id,
-                               in_out_component_id.second}}})));
+
+                auto const bottom_nodes_and_components =
+                    bhe.getBHEBottomDirichletBCNodesAndComponents(
+                        bc_bottom_node_id,
+                        in_out_component_id.first,
+                        in_out_component_id.second);
+
+                if (bottom_nodes_and_components)
+                {
+                    // Bottom, outflow, all cases
+                    bcs.addBoundaryCondition(
+                        createBHEBottomDirichletBoundaryCondition(
+                            get_global_bhe_bc_indices(
+                                {{{bc_bottom_node_id, in_out_component_id.first},
+                                  {bc_bottom_node_id,
+                                   in_out_component_id.second}}})));
+                }
+
             }
         };
         visit(createBCs, _process_data._vec_BHE_property[bhe_i]);
-- 
GitLab