From 3d5ffa6ed49581777a6fbf385ee5c0b0cdf26f97 Mon Sep 17 00:00:00 2001 From: Lars Bilke <lars.bilke@ufz.de> Date: Thu, 18 Jan 2024 15:29:47 +0100 Subject: [PATCH] [py] ruff fixes in Tests/Data/Parabolic/T/3D_3BHEs_array. --- .../Parabolic/T/3D_3BHEs_array/bcs_tespy.py | 46 +++++++++--------- .../T/3D_3BHEs_array/bcs_tespy_closedloop.py | 47 +++++++++---------- 2 files changed, 45 insertions(+), 48 deletions(-) diff --git a/Tests/Data/Parabolic/T/3D_3BHEs_array/bcs_tespy.py b/Tests/Data/Parabolic/T/3D_3BHEs_array/bcs_tespy.py index fb824f82b09..fe224552508 100644 --- a/Tests/Data/Parabolic/T/3D_3BHEs_array/bcs_tespy.py +++ b/Tests/Data/Parabolic/T/3D_3BHEs_array/bcs_tespy.py @@ -5,19 +5,19 @@ # http://www.opengeosys.org/project/license ### -import sys - -print(sys.version) import os +import sys import numpy as np +from pandas import read_csv +from tespy.networks import load_network try: import ogs.callbacks as OpenGeoSys except ModuleNotFoundError: import OpenGeoSys -from pandas import read_csv -from tespy.networks import load_network + +print(sys.version) # User setting ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # parameters @@ -148,36 +148,34 @@ class BC(OpenGeoSys.BHENetwork): df.loc[:, "flowrate"] = 0 cur_flowrate = df["flowrate"].tolist() return (True, True, Tout_val, cur_flowrate) - else: - # read 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 - # return to OGS - return (True, if_success, cur_Tin_val, cur_flowrate) + + # read 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 + # return to OGS + return (True, if_success, cur_Tin_val, cur_flowrate) # main # initialize the tespy model of the bhe network # load path of network model: # loading the TESPy model -if ogs_prj_directory != "": - os.chdir(ogs_prj_directory) +if ogs_prj_directory != "": # noqa: F821 + os.chdir(ogs_prj_directory) # noqa: F821 nw = load_network("./pre/tespy_nw") # set if print the network iteration info nw.set_attr(iterinfo=False) # create bhe dataframe of the network system from bhe_network.csv -df = create_dataframe() +df = create_dataframe() # noqa: PD901 n_BHE = np.size(df.iloc[:, 0]) # create local variables of the components label and connections label in diff --git a/Tests/Data/Parabolic/T/3D_3BHEs_array/bcs_tespy_closedloop.py b/Tests/Data/Parabolic/T/3D_3BHEs_array/bcs_tespy_closedloop.py index 630700f288a..56aa85fa05d 100644 --- a/Tests/Data/Parabolic/T/3D_3BHEs_array/bcs_tespy_closedloop.py +++ b/Tests/Data/Parabolic/T/3D_3BHEs_array/bcs_tespy_closedloop.py @@ -6,18 +6,19 @@ ### import sys - -print(sys.version) -import os +from pathlib import Path import numpy as np +from pandas import read_csv +from tespy.networks import load_network try: import ogs.callbacks as OpenGeoSys except ModuleNotFoundError: import OpenGeoSys -from pandas import read_csv -from tespy.networks import load_network + + +print(sys.version) # User setting ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # parameters @@ -151,37 +152,35 @@ class BC(OpenGeoSys.BHENetwork): df.loc[:, "flowrate"] = 0 cur_flowrate = df["flowrate"].tolist() return (True, True, Tout_val, cur_flowrate) - else: - # read 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 - # return to OGS - return (True, if_success, cur_Tin_val, cur_flowrate) + + # read 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 + # return to OGS + return (True, if_success, cur_Tin_val, cur_flowrate) # main # initialize the tespy model of the bhe network # load path of network model: # loading the TESPy model -project_dir = os.getcwd() +project_dir = Path.cwd() print("Project dir is: ", project_dir) nw = load_network("./pre/tespy_nw_closedloop") # set if print the network iteration info nw.set_attr(iterinfo=False) # create bhe dataframe of the network system from bhe_network.csv -df = create_dataframe() +df = create_dataframe() # noqa: PD901 n_BHE = np.size(df.iloc[:, 0]) # create local variables of the components label and connections label in -- GitLab