From 2f5bc5a0dce6261696ac1adfca4b82985445de82 Mon Sep 17 00:00:00 2001 From: shuangchen <gechenshuang88@gmail.com> Date: Wed, 19 Aug 2020 14:29:34 +0200 Subject: [PATCH] [BHE/network] merged the hydraulic and thermal functions in OGS-TESPy interface --- ...BHEInflowPythonBoundaryConditionModule.cpp | 23 +++------ ...thonBoundaryConditionPythonSideInterface.h | 49 ++++++------------- .../HeatTransportBHEProcess.cpp | 42 +++++----------- 3 files changed, 31 insertions(+), 83 deletions(-) diff --git a/ProcessLib/BoundaryCondition/Python/BHEInflowPythonBoundaryConditionModule.cpp b/ProcessLib/BoundaryCondition/Python/BHEInflowPythonBoundaryConditionModule.cpp index 3d536d8ce27..a3a49dcd200 100644 --- a/ProcessLib/BoundaryCondition/Python/BHEInflowPythonBoundaryConditionModule.cpp +++ b/ProcessLib/BoundaryCondition/Python/BHEInflowPythonBoundaryConditionModule.cpp @@ -37,24 +37,16 @@ public: initializeDataContainer); } - std::tuple<bool, bool, std::vector<double>> tespyThermalSolver( + std::tuple<bool, bool, std::vector<double>, std::vector<double>> + tespySolver( double t, std::vector<double> const& Tin_val, std::vector<double> const& Tout_val) const override { - using Ret = std::tuple<bool, bool, std::vector<double>>; + using Ret = std::tuple<bool, bool, std::vector<double>, std::vector<double>>; PYBIND11_OVERLOAD(Ret, BHEInflowPythonBoundaryConditionPythonSideInterface, - tespyThermalSolver, t, Tin_val, Tout_val); - } - - std::tuple<bool, std::vector<double>> tespyHydroSolver( - double t) const override - { - using Ret = std::tuple<bool, std::vector<double>>; - PYBIND11_OVERLOAD(Ret, - BHEInflowPythonBoundaryConditionPythonSideInterface, - tespyHydroSolver, t); + tespySolver, t, Tin_val, Tout_val); } }; @@ -71,12 +63,9 @@ void bheInflowpythonBindBoundaryCondition(pybind11::module& m) pybc.def("initializeDataContainer", &BHEInflowPythonBoundaryConditionPythonSideInterface:: initializeDataContainer); - pybc.def("tespyThermalSolver", + pybc.def("tespySolver", &BHEInflowPythonBoundaryConditionPythonSideInterface:: - tespyThermalSolver); - pybc.def( - "tespyHydroSolver", - &BHEInflowPythonBoundaryConditionPythonSideInterface::tespyHydroSolver); + tespySolver); } } // namespace ProcessLib diff --git a/ProcessLib/BoundaryCondition/Python/BHEInflowPythonBoundaryConditionPythonSideInterface.h b/ProcessLib/BoundaryCondition/Python/BHEInflowPythonBoundaryConditionPythonSideInterface.h index 66e6a6ad875..f80bc01926f 100644 --- a/ProcessLib/BoundaryCondition/Python/BHEInflowPythonBoundaryConditionPythonSideInterface.h +++ b/ProcessLib/BoundaryCondition/Python/BHEInflowPythonBoundaryConditionPythonSideInterface.h @@ -41,35 +41,23 @@ public: } /*! - * transfer BHE network dataframe to TESPy and get Tin from TESPy + * transfer BHE network dataframe to TESPy and get Tin and flow rate from TESPy * * \return a tuple (if use tespyThermalSolver, if convergence achieved - * in tespy, BHE Tin and Tout value from TESPy) + * in tespy, BHE Tin value, BHE flow rate from TESPy) * indicating if tespyThermalSolver shall be used at that position, if - * themal convergence has been achieved in the tespy and the new - * inflow temperature of all BHEs. + * themal convergence has been achieved in the tespy, the new + * inflow temperature and flow rate for all BHEs. */ - virtual std::tuple<bool, bool, std::vector<double>> tespyThermalSolver( + virtual std::tuple<bool, bool, std::vector<double>, std::vector<double>> + tespySolver( double /*t*/, std::vector<double> const& /*Tin_val*/, std::vector<double> const& /*Tout_val*/) const { - _overridden_tespyThermal = false; - return std::tuple<bool, bool, std::vector<double>>{false, false, {}}; - } - - /*! - * call Tespy hydraulic solver to get flow velocity in each pipe - * - * \return a tuple (if use tespyHydroSolver, f_velocity) indicating if - * tespyHydroSolver shall be used at that position and the flow velocity - * in each pipe of all BHEs. - */ - virtual std::tuple<bool, std::vector<double>> tespyHydroSolver( - double /*t*/) const - { - _overridden_tespyHydro = false; - return std::tuple<bool, std::vector<double>>{false, {}}; + _overridden_tespy = false; + return std::tuple<bool, bool, std::vector<double>, std::vector<double>>{ + false, false, {}, {}}; } //! Tells if initializeDataContainer() has been overridden in the derived @@ -79,17 +67,11 @@ public: //! once. bool isOverriddenEssential() const { return _overridden_essential; } - //! Tells if tespyThermalSolver() has been overridden in the derived class - //! in Python. - //! - //! \pre tespyThermalSolver() must already have been called once. - bool isOverriddenTespyThermal() const { return _overridden_tespyThermal; } - - //! Tells if tespyHydroSolver() has been overridden in the derived class + //! Tells if tespySolver() has been overridden in the derived class //! in Python. //! - //! \pre tespyHydroSolver() must already have been called once. - bool isOverriddenTespyHydro() const { return _overridden_tespyHydro; } + //! \pre tespySolver() must already have been called once. + bool isOverriddenTespy() const { return _overridden_tespy; } // BHE network dataframe container std::tuple<double, @@ -105,11 +87,8 @@ private: //! Tells if initializeDataContainer() has been overridden in the derived //! class in Python. mutable bool _overridden_essential = true; - //! Tells if tespyThermalSolver() has been overridden in the derived class + //! Tells if tespySolver() has been overridden in the derived class //! in Python. - mutable bool _overridden_tespyThermal = true; - //! Tells if tespyHydroSolver() has been overridden in the derived class in - //! Python. - mutable bool _overridden_tespyHydro = true; + mutable bool _overridden_tespy = true; }; } // namespace ProcessLib diff --git a/ProcessLib/HeatTransportBHE/HeatTransportBHEProcess.cpp b/ProcessLib/HeatTransportBHE/HeatTransportBHEProcess.cpp index 556721f6b53..426fecc356b 100644 --- a/ProcessLib/HeatTransportBHE/HeatTransportBHEProcess.cpp +++ b/ProcessLib/HeatTransportBHE/HeatTransportBHEProcess.cpp @@ -208,57 +208,37 @@ NumLib::IterationResult HeatTransportBHEProcess::postIterationConcreteProcess( return NumLib::IterationResult::SUCCESS; // Here the task is to get current time flowrate and flow temperature from - // TESPy + // TESPy and determine whether it converges. auto const Tout_nodes_id = std::get<3>(_process_data.py_bc_object->dataframe_network); const std::size_t n_bc_nodes = Tout_nodes_id.size(); - // update flowrate in network if network exist a dynamic flowrate in time - auto const cur_time = - std::get<0>(_process_data.py_bc_object->dataframe_network); - if (std::get<0>(_process_data.py_bc_object->tespyHydroSolver(cur_time))) - { - // calculate the current flowrate in each BHE from TESPy - auto const cur_flowrate = - std::get<1>(_process_data.py_bc_object->tespyHydroSolver(cur_time)); - for (std::size_t i = 0; i < n_bc_nodes; i++) - std::get<4>(_process_data.py_bc_object->dataframe_network)[i] = - cur_flowrate[i]; - if (!_process_data.py_bc_object->isOverriddenTespyHydro()) - { - DBUG( - "Method `tespyHydroSolver' not overridden in Python " - "script."); - } - } - - // get the outflow temperature, - // transfer it to TESPy and to get inflow temperature, - // and determine whether it converges. for (std::size_t i = 0; i < n_bc_nodes; i++) { // read the T_out and store them in dataframe std::get<2>(_process_data.py_bc_object->dataframe_network)[i] = x[Tout_nodes_id[i]]; } - // Tout transfer to Python - auto const tespy_result = _process_data.py_bc_object->tespyThermalSolver( + // Transfer Tin and Tout to TESPy and return the results + auto const tespy_result = _process_data.py_bc_object->tespySolver( std::get<0>(_process_data.py_bc_object->dataframe_network), std::get<1>(_process_data.py_bc_object->dataframe_network), std::get<2>(_process_data.py_bc_object->dataframe_network)); - if (!_process_data.py_bc_object->isOverriddenTespyThermal()) + if (!_process_data.py_bc_object->isOverriddenTespy()) { DBUG( - "Method `tespyThermalSolver' not overridden in Python " + "Method `tespySolver' not overridden in Python " "script."); } - auto const cur_Tin = std::get<2>(tespy_result); - // update the T_in + // update the Tin and flow rate for (std::size_t i = 0; i < n_bc_nodes; i++) + { std::get<1>(_process_data.py_bc_object->dataframe_network)[i] = - cur_Tin[i]; - + std::get<2>(tespy_result)[i]; + std::get<4>(_process_data.py_bc_object->dataframe_network)[i] = + std::get<3>(tespy_result)[i]; + } auto const tespy_has_converged = std::get<1>(tespy_result); if (tespy_has_converged == true) return NumLib::IterationResult::SUCCESS; -- GitLab