Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stanet converter 2.0 #618

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/pandapipes/converter/stanet/preparing_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,19 @@ def get_net_params(net, stored_data):
net_params = dict()
net_data = stored_data["net_parameters"]
net_params['medium'] = net_data.at[0, "MEDI"]
net_params["rho"] = net_data.at[0, "RHON"]
net_params["cp"] = net_data.at[0, "CG"]
net_params["eta"] = net_data.at[0, "ETA"] * 1e-6
net_params["t_sutherland"] = net_data.at[0, "TS"]
net_params["t0_sutherland"] = net_data.at[0, "T0"]
net_params["rho"] = float(net_data.at[0, "RHON"])
net_params["cp"] = float(net_data.at[0, "CG"])
net_params["eta"] = float(net_data.at[0, "ETA"]) * 1e-6
net_params["t_sutherland"] = float(net_data.at[0, "TS"])
net_params["t0_sutherland"] = float(net_data.at[0, "T0"])
net_params["calculate_temp"] = str(net_data.at[0, "TEMPCALC"]) == "J"
pp_calc_mode = "all" if net_params["calculate_temp"] else "hydraulics"
pandapipes.set_user_pf_options(net, mode=pp_calc_mode)
net_params["medium_temp_C"] = net_data.at[0, "TEMP"]
net_params["medium_temp_K"] = net_data.at[0, "TEMP"] + 273.15
net_params["medium_temp_C"] = float(net_data.at[0, "TEMP"])
net_params["medium_temp_K"] = float(net_data.at[0, "TEMP"]) + 273.15
net_params["calculation_results_valid"] = not bool(net_data.at[0, "CALCDIRTY"])
net_params["household_results_valid"] = not bool(net_data.at[0, "HCALCDIRTY"])
net_params["comp_factor"] = net_data.at[0, "KPAR"]
net_params["comp_factor"] = float(net_data.at[0, "KPAR"])
net_params["friction_model"] = int(net_data.at[0, "LAM"])
net_params["max_iterations"] = int(net_data.at[0, "IMAX"])
net_params["compress_model"] = compressibility_models[int(net_data.at[0, "KFAKT"])]
Expand All @@ -207,7 +207,7 @@ def get_net_params(net, stored_data):
logger.warning("The compressibility model %s is not implemented in pandapipes, which might "
"lead to wrong results." % net_params["compress_model"])

pandapipes.set_user_pf_options(net, ambient_temperature=net_data.at[0, "AIRTEMP"] + 273.15)
pandapipes.set_user_pf_options(net, ambient_temperature=float(net_data.at[0, "AIRTEMP"]) + 273.15)
state = 'liquid' if net_params['medium'] == 'W' else 'gas'
fluid = pandapipes.create_constant_fluid(
'STANET_fluid', state, density=net_params["rho"], viscosity=net_params["eta"],
Expand Down Expand Up @@ -272,9 +272,9 @@ def adapt_pipe_data(stored_data, pipe_data, coord_names, use_clients):
for client_num, indices in client_types_ind.items():
node_name = CLIENT_TYPES_OF_NODES[client_num]
node_data = stored_data[node_name]
node_geo = node_data.loc[:, ["XRECHTS", "YHOCH"]]
node_geo.index = node_data.RECNO.values
node_cols = ["CLIENTNO", "CLIENT2NO"] if use_clients else ["ANFNR", "ENDNR"]
node_geo = node_data.loc[:, ["XRECHTS", "YHOCH"]].astype(float)
node_geo.index = node_data.STANETID.values if use_clients else node_data.RECNO.values
node_cols = ["CLIENTID", "CLIENT2ID"] if use_clients else ["ANFNR", "ENDNR"]

# the following code is just a check whether pipe and node geodata fit together
# in case of deviations, the pipe geodata is adapted on the basis of the node geodata
Expand Down Expand Up @@ -312,13 +312,15 @@ def get_pipe_geo(stored_data, modus):
coord_names = ["XRA", "XRB", "YHA", "YHB"] if modus == "main" \
else ["XRECHTS", "XRECHTS2", "YHOCH", "YHOCH2"]
inflexion_points = "inflexion_points" if modus == "main" else "house_inflexion_points"

pipe_data = stored_data[pipe_table_name]
pipe_data[coord_names] = pipe_data[coord_names].astype(float)

adapt_pipe_data(stored_data, pipe_data, coord_names, modus != "main")

pipe_geo_data = pipe_data.loc[:, coord_names + ["RECNO"]]
if inflexion_points in stored_data:
columns = ['XRECHTS', 'YHOCH']
stored_data[inflexion_points][columns] = stored_data[inflexion_points][columns].astype(float)
used_cols, sort_cols = ["XRECHTS", "YHOCH", "SNUM", "KNICKNO"], ["SNUM", "KNICKNO"]
ipt = stored_data["{}".format(inflexion_points)].loc[:, used_cols].sort_values(sort_cols)
# make lists of all x- and y-values of the inflexion points grouped by the pipe index
Expand Down
44 changes: 30 additions & 14 deletions src/pandapipes/converter/stanet/table_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import pandas as pd

import pandapipes
from pandapipes.properties import get_fluid
from pandapipes.constants import NORMAL_TEMPERATURE
from pandapipes.component_models.component_toolbox import vrange
from pandapipes.converter.stanet.valve_pipe_component import create_valve_pipe_from_parameters

Expand Down Expand Up @@ -74,7 +76,7 @@ def create_junctions_from_nodes(net, stored_data, net_params, index_mapping, add
add_info["stanet_layer"] = node_table.LAYER.values.astype(str)
temperatures = pd.Series(net_params["medium_temp_K"], index=node_table.index, dtype=np.float64)
eg_ind = ((node_table.FSTATUS == '?') & (node_table.DSTATUS == '!')).values
eg_temps = node_table.loc[eg_ind, "TMESS"].values + 273.15
eg_temps = node_table.loc[eg_ind, "TMESS"].values.astype(float) + 273.15
if net_params["calculate_temp"]:
temperatures.loc[eg_ind] = eg_temps
else:
Expand All @@ -91,7 +93,7 @@ def create_junctions_from_nodes(net, stored_data, net_params, index_mapping, add
stanet_active=node_table.ISACTIVE.values.astype(np.bool_),
stanet_system=CLIENT_TYPES_OF_PIPES[MAIN_PIPE_TYPE], **add_info)
for eg_junc, p_bar, t_k in zip(junction_indices[eg_ind], eg_press, eg_temps):
pandapipes.create_ext_grid(net, eg_junc, p_bar, t_k, type="pt",
pandapipes.create_ext_grid(net, eg_junc, float(p_bar), float(t_k), type="pt",
stanet_system=CLIENT_TYPES_OF_PIPES[MAIN_PIPE_TYPE])
index_mapping["nodes"] = dict(zip(stanet_nrs, junction_indices))

Expand Down Expand Up @@ -137,6 +139,7 @@ def create_valve_and_pipe(net, stored_data, index_mapping, net_params, stanet_li
add_info = dict()
if add_layers:
add_info["stanet_layer"] = str(row.LAYER)
add_info["construction_year"] = int(row.BAUJAHR) if 'BAUJAHR' in row else np.nan
if stanet_like_valves:
create_valve_pipe_from_parameters(
net, node_mapping[from_stanet_nr], node_mapping[to_stanet_nr],
Expand Down Expand Up @@ -246,9 +249,9 @@ def create_slider_valves(net, stored_data, index_mapping, add_layers,
if any(slider_valves.DM == 0):
logger.warning(f"{sum(slider_valves.DM == 0)} sliders have an inner diameter of 0 m! "
f"The diameter will be set to 1 m.")
slider_valves.DM[slider_valves.DM == 0] = 1e3
slider_valves.loc[slider_valves.DM == 0, 'DM'] = 1e3
pandapipes.create_valves(
net, from_junctions, to_junctions, slider_valves.DM.values / 1000,
net, from_junctions, to_junctions, slider_valves.DM.values.astype(float) / 1000,
opened=slider_valves.TYP.astype(np.int32).replace(opened_types).values,
loss_coefficient=slider_valves.ZETA.values, name=slider_valves.STANETID.values,
type="slider_valve_" + valve_system,
Expand Down Expand Up @@ -321,6 +324,7 @@ def create_control_components(net, stored_data, index_mapping, net_params, add_l
"""
if "controllers" not in stored_data:
return
fluid = get_fluid(net)
logger.info("Creating control components.")
control_table = stored_data["controllers"]
node_mapping = index_mapping["nodes"]
Expand All @@ -342,15 +346,24 @@ def create_control_components(net, stored_data, index_mapping, net_params, add_l
logger.warning("There is an error in the control table! Please check the columns 'OFFEN',"
" 'ZU' and 'AKTIV', which should only contain 'J' or 'N'.")

control_active = (control_table.AKTIV.values == "J").astype(np.bool_)
if consider_controlled:
control_active &= ~fully_open
in_service = control_table.ISACTIVE.values.astype(np.bool_)
in_service = (control_table.AKTIV.values != "N").astype(np.bool_)
in_service &= control_table.ISACTIVE.values.astype(np.bool_)
if consider_controlled:
in_service &= ~(control_table.ZU.values == "J")

control_active = np.ones(len(control_table), dtype=bool)
if consider_controlled:
control_active &= ~fully_open

#todo: after implementing a new pressure controller RTYP should replace RSTATUS
is_nan = pd.isnull(control_table.RTYP.values)
is_pc_stat = control_table.RSTATUS.values[is_nan] == "P"
is_fc_stat = control_table.RSTATUS.values[is_nan] == "Q"
is_pc = control_table.RTYP.values == "P"
is_fc = control_table.RTYP.values == "Q"
is_pc[is_nan] |= is_pc_stat
is_fc[is_nan] |= is_fc_stat

if not np.all(is_pc | is_fc):
raise UserWarning("There are controllers of types %s that cannot be converted!" \
% set(control_table.RTYP.values[~is_pc & ~is_fc]))
Expand All @@ -377,8 +390,8 @@ def create_control_components(net, stored_data, index_mapping, net_params, add_l
stanet_is_closed=fully_closed[is_pc],
stanet_flow_kgps=flow[is_pc],
stanet_active=control_table.ISACTIVE.values[is_pc].astype(np.bool_),
**add_info
)
max_mdot_kg_per_s=control_table.QSOLL.values[is_pc].astype(float) / 3600 * fluid.get_density(NORMAL_TEMPERATURE),
**add_info)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this, we need #619 to be merged? Is max_mdot_kg_per_s then always required? Can we add the column to the press_control as it it implemented currently?


drop_eg = net.ext_grid.loc[net.ext_grid.junction.isin(to_junctions[is_pc])].index
net.ext_grid.drop(drop_eg, inplace=True)
Expand Down Expand Up @@ -563,15 +576,15 @@ def create_pipes_from_connections(net, stored_data, connection_table, index_mapp
pipe_data.loc[pipe_nums, "ANFNR"].values[previous_different])
con_to = np.insert(cons.RECNO.values, next_different_num + 1,
pipe_data.loc[pipe_nums, "ENDNR"].values[next_different])
vm_from = np.insert(cons.VMB.values, next_different_num, cons.VMA.values[next_different_num])
vm_to = np.insert(cons.VMA.values, next_different_num, cons.VMB.values[next_different_num])
vm_from = np.insert(cons.VMB.values.astype(float), next_different_num, cons.VMA.values[next_different_num].astype(float),)
vm_to = np.insert(cons.VMA.values.astype(float), next_different_num, cons.VMB.values[next_different_num].astype(float),)
vm = (vm_from + vm_to) / 2

pipe_sections = pd.DataFrame({
"SNUM": pipe_numbers, "rel_length": rel_lengths, "start_pos": start_pos, "end_pos": end_pos,
"from_type": type_from, "to_type": type_to, "from_node": con_from, "to_node": con_to,
"full_geo": pipe_geodata.loc[pipe_numbers], "vm": vm,
"length": rel_lengths * pipe_data.RORL.loc[pipe_numbers].values,
"length": rel_lengths * pipe_data.RORL.loc[pipe_numbers].values.astype(float),
"aux": np.ones(len(pipe_numbers), dtype=np.int32)
})
pipe_sections["section_no"] = pipe_sections.groupby("SNUM").aux.cumsum()
Expand All @@ -591,6 +604,7 @@ def create_geodata_sections(row):
add_info = dict()
if add_layers:
add_info["stanet_layer"] = pipes.LAYER.values.astype(str)
add_info["construction_year"] = pipes.BAUJAHR.values.astype(np.int32) if 'BAUJAHR' in pipes else np.nan
# TODO: v_stanet might have to be extended by house connections VMA and VMB
text_k = 293
if "TU" in pipes.columns:
Expand All @@ -600,7 +614,7 @@ def create_geodata_sections(row):
alpha = pipes.WDZAHL.values.astype(np.float64)
pandapipes.create_pipes_from_parameters(
net, pipe_sections.fj.values, pipe_sections.tj.values, pipe_sections.length.values / 1000,
pipes.DM.values / 1000, pipes.RAU.values, pipes.ZETA.values, type="main_pipe",
pipes.DM.values.astype(float) / 1000, pipes.RAU.values.astype(float), pipes.ZETA.values.astype(float), type="main_pipe",
stanet_std_type=pipes.ROHRTYP.values, in_service=pipes.ISACTIVE.values, text_k=text_k,
alpha_w_per_m2k=alpha,
name=["pipe_%s_%s_%s" % (nf, nt, sec) for nf, nt, sec in zip(
Expand Down Expand Up @@ -723,6 +737,7 @@ def create_pipes_from_remaining_pipe_table(net, stored_data, connection_table, i
add_info = dict()
if add_layers:
add_info["stanet_layer"] = p_tbl.LAYER.values.astype(str)
add_info["construction_year"] = p_tbl.BAUJAHR.values.astype(np.int32) if 'BAUJAHR' in p_tbl else np.nan
text_k = 293
if "TU" in p_tbl.columns:
text_k = p_tbl.TU.values.astype(np.float64) + 273.15
Expand Down Expand Up @@ -1044,6 +1059,7 @@ def create_geodata_sections(row):
add_info = dict()
if add_layers:
add_info["stanet_layer"] = hp_data.LAYER.values.astype(str)
add_info["construction_year"] = hp_data.BAUJAHR.values.astype(np.int32) if 'BAUJAHR' in hp_data else np.nan
# TODO: v_stanet might have to be extended by house connections VMA and VMB
text_k = 293
if "TU" in hp_data.columns:
Expand Down
Loading