Commit b8062309 authored by Shuang Chen's avatar Shuang Chen
Browse files

BHE pipe network interface update for review

parent 57f579b0
......@@ -13,12 +13,12 @@
<point id="6" x="25.0" y="50.0" z="-72.0" name="bottom_right_uppert"/>
<point id="7" x="25.0" y="0.0" z="-72.0" name="bottom_right_down"/>
<point id="8" x="0.0" y="25.0" z="-52.0" name="BHE1_BOTTOM"/>
<point id="9" x="0.0" y="25.0" z="-2.0" name="BHE1_TOP"/>
<point id="10" x="-6.0" y="25.0" z="-52.0" name="BHE2_BOTTOM"/>
<point id="11" x="-6.0" y="25.0" z="-2.0" name="BHE2_TOP"/>
<point id="12" x="0.0" y="25.0" z="-52.0" name="BHE3_BOTTOM"/>
<point id="13" x="0.0" y="25.0" z="-2.0" name="BHE3_TOP"/>
<point id="8" x="-6.0" y="25.0" z="-52.0" name="BHE1_BOTTOM"/>
<point id="9" x="-6.0" y="25.0" z="-2.0" name="BHE1_TOP"/>
<point id="10" x="0.0" y="25.0" z="-52.0" name="BHE2_BOTTOM"/>
<point id="11" x="0.0" y="25.0" z="-2.0" name="BHE2_TOP"/>
<point id="12" x="6.0" y="25.0" z="-52.0" name="BHE3_BOTTOM"/>
<point id="13" x="6.0" y="25.0" z="-2.0" name="BHE3_TOP"/>
</points>
<polylines>
<polyline id="0" name="BHE_1">
......
......@@ -226,7 +226,7 @@
<convergence_criterion>
<type>DeltaX</type>
<norm_type>NORM2</norm_type>
<reltol>1.e-5</reltol>
<reltol>1.e-6</reltol>
</convergence_criterion>
<time_discretization>
<type>BackwardEuler</type>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -15,7 +15,14 @@ import OpenGeoSys
from tespy.networks import load_network
# User setting ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# TESPy model direction
TESPy_model_dir = "./pre/tespy_nw"
# BHE names defined in the TESPy network model
bhe_names = ["BHE1", "BHE2", "BHE3"]
# parameters
# OGS model BHE inflow and outflow initial temperature
ini_bhe_inflow = 283.15 # K
ini_bhe_outflow = 283.15 # K
# refrigerant density
rho_f = 992.92 # kg/m3
# switch for special boundary conditions
......@@ -82,10 +89,21 @@ def dyn_frate(t):
# create network dataframe
def create_dataframe():
# return dataframe
# create bhe dataframe based on the heat_exchanger_simple file in the TESPy model
df_nw = read_csv(
"./pre/bhe_network.csv", delimiter=";", index_col=[0], dtype={"data_index": str}
"{}/components/heat_exchanger_simple.csv".format(TESPy_model_dir),
delimiter=";",
index_col=[0],
)
n_index = np.size(df_nw.iloc[:, 0])
for i in range(n_index):
if not df_nw.index[i] in bhe_names:
df_nw = df_nw.drop(df_nw.index[i])
df_nw["Tin_val"] = ini_bhe_inflow
df_nw["Tout_val"] = ini_bhe_outflow
df_nw["Tout_node_id"] = 0
df_nw["flowrate"] = 0
df_nw = df_nw.iloc[:, -4:]
return df_nw
......@@ -145,19 +163,13 @@ class BC(OpenGeoSys.BHENetwork):
cur_flowrate = df["flowrate"].tolist()
return (True, True, Tout_val, cur_flowrate)
else:
# read Tout_val to dataframe
# save Tout_val to dataframe
for i in range(n_BHE):
df.loc[df.index[i], "Tout_val"] = Tout_val[i]
# TESPy solver
cur_Tin_val, cur_flowrate = get_tespy_results(t)
# check norm if network achieves the converge
if_success = False
pre_Tin_val = Tin_val
norm = np.linalg.norm(
abs(np.asarray(pre_Tin_val) - np.asarray(cur_Tin_val))
)
if norm < 10e-6:
if_success = True
# if TESPy network runs successfully
if_success = True
# return to OGS
return (True, if_success, cur_Tin_val, cur_flowrate)
......@@ -167,11 +179,11 @@ class BC(OpenGeoSys.BHENetwork):
# load path of network model:
# loading the TESPy model
project_dir = os.chdir(ogs_prj_directory)
nw = load_network("./pre/tespy_nw")
nw = load_network(TESPy_model_dir)
# set if print the network iteration info
nw.set_attr(iterinfo=False)
# create bhe dataframe of the network system from bhe_network.csv
# create bhe dataframe of the network system
df = create_dataframe()
n_BHE = np.size(df.iloc[:, 0])
......@@ -191,7 +203,7 @@ for i in range(n_BHE):
if switch_dyn_frate == "on":
# import the name of inlet connection from the network csv file
inlet_name = read_csv(
"./pre/tespy_nw/connections.csv", delimiter=";", index_col=[0]
"{}/connections.csv".format(TESPy_model_dir), delimiter=";", index_col=[0]
).iloc[0, 0]
for c in nw.conns.index:
# bhe inflow conns
......@@ -203,7 +215,7 @@ if switch_dyn_frate == "on":
if switch_dyn_demand == "on":
# import the name of bus from the network csv file
bus_name = read_csv(
"./pre/tespy_nw/components/bus.csv", delimiter=";", index_col=[0]
"{}/components/bus.csv".format(TESPy_model_dir), delimiter=";", index_col=[0]
).index[0]
# instantiate BC objects referenced in OpenGeoSys
......
......@@ -15,7 +15,14 @@ import OpenGeoSys
from tespy.networks import load_network
# User setting ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# TESPy model direction
TESPy_model_dir = "./pre/tespy_nw_closedloop"
# BHE names defined in the TESPy network model
bhe_names = ["BHE1", "BHE2", "BHE3"]
# parameters
# OGS model BHE inflow and outflow initial temperature
ini_bhe_inflow = 283.15 # K
ini_bhe_outflow = 283.15 # K
# refrigerant density
rho_f = 992.92 # kg/m3
# switch for special boundary conditions
......@@ -84,10 +91,21 @@ def dyn_frate(t):
# create network dataframe
def create_dataframe():
# return dataframe
# create bhe dataframe based on the heat_exchanger_simple file in the TESPy model
df_nw = read_csv(
"./pre/bhe_network.csv", delimiter=";", index_col=[0], dtype={"data_index": str}
"{}/components/heat_exchanger_simple.csv".format(TESPy_model_dir),
delimiter=";",
index_col=[0],
)
n_index = np.size(df_nw.iloc[:, 0])
for i in range(n_index):
if not df_nw.index[i] in bhe_names:
df_nw = df_nw.drop(df_nw.index[i])
df_nw["Tin_val"] = ini_bhe_inflow
df_nw["Tout_val"] = ini_bhe_outflow
df_nw["Tout_node_id"] = 0
df_nw["flowrate"] = 0
df_nw = df_nw.iloc[:, -4:]
return df_nw
......@@ -147,20 +165,13 @@ class BC(OpenGeoSys.BHENetwork):
cur_flowrate = df["flowrate"].tolist()
return (True, True, Tout_val, cur_flowrate)
else:
# read Tout_val to dataframe
# save Tout_val to dataframe
for i in range(n_BHE):
df.loc[df.index[i], "Tout_val"] = Tout_val[i]
# TESPy solver
cur_Tin_val, cur_flowrate = get_tespy_results(t)
# check norm if network achieves the converge
if_success = False
pre_Tin_val = Tin_val
norm_dx = np.linalg.norm(
abs(np.asarray(pre_Tin_val) - np.asarray(cur_Tin_val))
)
norm_x = np.linalg.norm(np.asarray(cur_Tin_val))
if norm_dx / norm_x < 1e-6:
if_success = True
# if TESPy network runs successfully
if_success = True
# return to OGS
return (True, if_success, cur_Tin_val, cur_flowrate)
......@@ -170,12 +181,11 @@ class BC(OpenGeoSys.BHENetwork):
# load path of network model:
# loading the TESPy model
project_dir = os.getcwd()
print("Project dir is: ", project_dir)
nw = load_network("./pre/tespy_nw_closedloop")
nw = load_network(TESPy_model_dir)
# set if print the network iteration info
nw.set_attr(iterinfo=False)
# create bhe dataframe of the network system from bhe_network.csv
# create bhe dataframe of the network system
df = create_dataframe()
n_BHE = np.size(df.iloc[:, 0])
......@@ -195,7 +205,7 @@ for i in range(n_BHE):
if switch_dyn_frate == "on":
# import the name of inlet connection from the network csv file
inlet_name = read_csv(
"./pre/tespy_nw/connections.csv", delimiter=";", index_col=[0]
"{}/connections.csv".format(TESPy_model_dir), delimiter=";", index_col=[0]
).iloc[0, 0]
for c in nw.conns.index:
# bhe inflow conns
......
data_index;BHE_id;Tin_val;Tout_val;Tout_node_id;flowrate
BHE1;1;283.15;283.15;0;0
BHE2;2;283.15;283.15;0;0
BHE3;3;283.15;283.15;0;0
......@@ -179,21 +179,13 @@ The work flow of the PipeNetwork feature is illustrated in Figure 2. To explicit
Figure 2: Work flow of the model with BHEs coupled with a pipe network
### < BHE data container >
In order to use the PipeNetwork feature, the pre-built and saved TESPy network model in the above section is required. A csv file `bhe_network.csv` which containing all the OGS-TESPy transferred BHE's information needs to be created. The PipeNetwork feature will access this csv file to initialize the exchange data container between OGS and TESPy during the simulation. All BHEs have to be included in this csv file. Please take notice that all BHE names located in the data_index column have to be identical with the BHE names defined in the corresponding TESPy network model.
```bash
data_index;BHE_id;Tin_val;Tout_val;Tout_node_id;flowrate
BHE1;1;283.15;283.15;0;0
BHE2;2;283.15;283.15;0;0
BHE3;3;283.15;283.15;0;0
```
### < PipeNetwork feature interface >
The python script `bcs_tespy.py` is the data exchange interface for running the PipeNetwork feature.
It contains the main procedure of data exchange during the simulation.
Firstly several user defined input parameters should be specified.
The direction which contains the TESPy model is need to be given.
All BHE names which are defined in the TESPy model should be added into the parameter `bhe_names`.
In the script a network status controller function `network_status`, a system dynamic thermal load function `consumer_demand` and a system dynamic inlet flow rate function `dyn_frate` are optionally required to be pre-defined by the user.
The function `network_status` receives the current time step information from OGS and determines if the network is required to be shut off.
When the switch for dynamic thermal load `switch_dyn_demand` and dynamic flow rate `switch_dyn_frate` are `off`, the thermal and hydraulic boundary conditions, which were defined in the pre-constructed TESPy model, will be used throughout the simulation.
......@@ -201,7 +193,14 @@ When the switches are `on`, a user defined system thermal load curve and inlet f
```bash
# User setting ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# TESPy model direction
TESPy_model_dir = "./pre/tespy_nw"
# BHE names defined in the TESPy network model
bhe_names = ["BHE1", "BHE2", "BHE3"]
# parameters
# OGS model BHE inflow and outflow initial temperature
ini_bhe_inflow = 283.15 # K
ini_bhe_outflow = 283.15 # K
# refrigerant density
rho_f = 992.92 # kg/m3
# switch for special boundary conditions
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment