Skip to content

Commit

Permalink
Pre-commit changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JingWang-CUB committed Jun 25, 2024
1 parent c1e7d07 commit ec99189
Show file tree
Hide file tree
Showing 9 changed files with 339 additions and 336 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Connections between ground coupling and distribution
connect(dis.heatPortGro,{{ coupling.network.id }}.ports[1, :])
connect(dis.heatPortGro,{{ coupling.network.id }}.ports[1, :])
{% raw %}annotation (Line(points={{70,-20},{70,-36},{104,-36},{104,28},{150,28},{150,40}},color={191,0,0}));
{% endraw %}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
from geojson_modelica_translator.model_connectors.couplings.diagram import Diagram
from geojson_modelica_translator.model_connectors.load_connectors.load_base import LoadBase
from geojson_modelica_translator.scaffold import Scaffold
from geojson_modelica_translator.utils import mbl_version
from geojson_modelica_translator.utils import convert_ft_to_m
from geojson_modelica_translator.utils import convert_ft_to_m, mbl_version

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -50,9 +49,8 @@ def __init__(self, root_dir, project_name, system_parameters, coupling_graph, ge
)

def to_modelica(self):
"""Generate modelica files for the models as well as the modelica file for
the entire district system.
"""
"""Generate modelica files for the models as well as the modelica file for the entire district system."""

# scaffold the project
self._scaffold.create()
self.district_model_filepath = Path(self._scaffold.districts_path.files_dir) / "DistrictEnergySystem.mo"
Expand Down Expand Up @@ -97,8 +95,8 @@ def to_modelica(self):
# get horizontal pipe lengths from geojson, starting from the outlet of the (first) ghe
# TODO: only check for total_length if type==ThermalConnector
# I thought this was the right syntax, but not quite: .properties[?type=ThermalConnector].total_length
# TODO: make sure the list of lengths is starting from the outlet of the ghe, convert units to meter
"lDis": str(list_of_pipe_lengths[:-1]).replace('[','{').replace(']','}'),
# TODO: make sure the list of lengths is starting from the outlet of the ghe
"lDis": str(list_of_pipe_lengths[:-1]).replace("[", "{").replace("]", "}"),
"lEnd": list_of_pipe_lengths[-1],
},
"graph": self._coupling_graph,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,39 +59,40 @@ def to_modelica(self, scaffold):
"buried_depth": self.system_parameters.get_param(
"$.district_system.fifth_generation.horizontal_piping_parameters.buried_depth"
),
"weather": self.system_parameters.get_param(
"$.weather"
),
"num_buildings": len(self.system_parameters.get_param("$.buildings"))
"weather": self.system_parameters.get_param("$.weather"),
"num_buildings": len(self.system_parameters.get_param("$.buildings")),
}

# process pipe wall thickness
if template_data["hydraulic_diameter"] and template_data["diameter_ratio"]:
template_data["pipe_wall_thickness"] = template_data["hydraulic_diameter"]/(template_data["diameter_ratio"]-2)
template_data["pipe_wall_thickness"] = template_data["hydraulic_diameter"] / (
template_data["diameter_ratio"] - 2
)
else:
template_data["pipe_wall_thickness"] = None

# get weather station name from weather file
# get weather station name from weather file
parts = template_data["weather"].split("/")[-1].split("_")
if len(parts)==4:
station_name=parts[2]
elif len(parts)==3:
station_name=parts[1]
station_name = re.sub(r'\d+', '', station_name).replace('.', ' ')
if len(parts) == 4:
station_name = parts[2]
elif len(parts) == 3:
station_name = parts[1]
station_name = re.sub(r"\d+", "", station_name).replace(".", " ")

# search for coefficients for calculating soil temperature based on station
df = pd.read_excel(Path(__file__).parent / "data" / "Soil_temp_coefficients.xlsx")
matching_rows = df[df.apply(lambda row: row.astype(str).str.contains(station_name).any(), axis=1)]
if len(matching_rows)==0:
coefs = pd.read_excel(Path(__file__).parent / "data" / "Soil_temp_coefficients.xlsx")
matching_rows = coefs[coefs.apply(lambda row: row.astype(str).str.contains(station_name).any(), axis=1)]
if len(matching_rows) == 0:
raise ValueError(
"No matching weather station has been found. Please check your weather file name format."
"(e.g., USA_NY_Buffalo-Greater.Buffalo.Intl.AP.725280_TMY3.mos)")
"(e.g., USA_NY_Buffalo-Greater.Buffalo.Intl.AP.725280_TMY3.mos)"
)
else:
template_data["surface_temp"]=matching_rows['Ts,avg, °C'].iloc[0]
template_data["first_amplitude"]=matching_rows['Ts,amplitude,1, °C'].iloc[0]
template_data["second_amplitude"]=matching_rows['Ts,amplitude,2, °C'].iloc[0]
template_data["first_phase_lag"]=matching_rows['PL1'].iloc[0]
template_data["second_phase_lag"]=matching_rows['PL2'].iloc[0]
template_data["surface_temp"] = matching_rows["Ts,avg, °C"].iloc[0]
template_data["first_amplitude"] = matching_rows["Ts,amplitude,1, °C"].iloc[0]
template_data["second_amplitude"] = matching_rows["Ts,amplitude,2, °C"].iloc[0]
template_data["first_phase_lag"] = matching_rows["PL1"].iloc[0]
template_data["second_phase_lag"] = matching_rows["PL2"].iloc[0]

# create horizontal piping package paths
b_modelica_path = ModelicaPath(self.ground_coupling_name, scaffold.networks_path.files_dir, True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ First implementation.
This model represents the supply and return lines to connect an
agent (e.g., an energy transfer station) to a one-pipe main distribution
system.
The instances of the pipe model are autosized based on the pressure drop per pipe length
The instances of the pipe model are autosized based on the pressure drop per pipe length
at nominal flow rate.
</p>
</html>"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
datDes.lDis,
{datDes.lEnd}),
rad={0.5*dis.dhDis[1] + dis.thickness + dis.dIns})
{% raw %}"Ground coupling"
{% raw %}"Ground coupling"
annotation (Placement(transformation(extent={{-10,-10},{10,10}},rotation=0,origin={150,50})));
{% endraw %}
{% endraw %}
2 changes: 1 addition & 1 deletion geojson_modelica_translator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def convert_ft_to_m(f):
:param c: float, length in ft
:return: float, length in meter
"""
return 0.3048*f
return 0.3048 * f


def linecount(filename: Path) -> int:
Expand Down
20 changes: 10 additions & 10 deletions tests/model_connectors/data/system_params_ghe_3.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@
"central_pump_parameters": {
"pump_design_head": 60000
},
"horizontal_piping_parameters": {
"hydraulic_diameter": 0.089,
"insulation_thickness": 0.2,
"insulation_conductivity": 2.3,
"diameter_ratio": 11,
"roughness": 1e-6,
"rho_cp": 2139000,
"number_of_segments": 1,
"buried_depth": 1.5
},
"horizontal_piping_parameters": {
"hydraulic_diameter": 0.089,
"insulation_thickness": 0.2,
"insulation_conductivity": 2.3,
"diameter_ratio": 11,
"roughness": 1e-06,
"rho_cp": 2139000,
"number_of_segments": 1,
"buried_depth": 1.5
},
"ghe_parameters": {
"version": "1.0",
"ghe_dir": "../../management/data/sdk_project_scraps/run/baseline_scenario/ghe_dir",
Expand Down
Loading

0 comments on commit ec99189

Please sign in to comment.