Commit 97c161fc authored by Youcef Aouad's avatar Youcef Aouad
Browse files

correct names nodes reaches

No related merge requests found
Pipeline #59718 passed with stages
in 1 minute
Showing with 68 additions and 2 deletions
+68 -2
...@@ -40,6 +40,8 @@ from Checker.Adists import ( ...@@ -40,6 +40,8 @@ from Checker.Adists import (
AdistsOutputRKChecker, AdistsOutputRKChecker,
) )
from itertools import chain
logger = logging.getLogger() logger = logging.getLogger()
def adists_file_open(filepath, mode): def adists_file_open(filepath, mode):
...@@ -173,6 +175,67 @@ class AdisTS(CommandLineSolver): ...@@ -173,6 +175,67 @@ class AdisTS(CommandLineSolver):
name = "" name = ""
return f"{name}" return f"{name}"
_alph = list(
map(
chr,
chain(
range(48, 58), # 0..9
range(65, 91), # A..Z
range(97, 123) # a..z
)
)
)
_l_alph = len(_alph)
_nodes_cnt = 0
_nodes_names = {}
_nodes_views = set()
def get_reach_name(self, reach):
return f"Reach_{reach.id:>3}".replace(" ", "0")
def get_node_name(self, node):
"""Generate a 3 char name for node
Args:
node: The node
Returns:
A 3 char name string
"""
n = node.id
##print("node name id: ", n)
##if n in self._nodes_names:
##return self._nodes_names[n]
name = ""
checked_new = False
while not checked_new:
self._nodes_cnt += 1
nc = self._nodes_cnt
name = "".join(
map(
lambda i: self._alph[i % self._l_alph],
[
int(nc / (self._l_alph * self._l_alph)),
int(nc / self._l_alph),
nc
]
)
)
checked_new = name not in self._nodes_views
self._nodes_views.add(name)
self._nodes_names[n] = name
return name
################################# #################################
# Adis-TS in weak coupling mode # # Adis-TS in weak coupling mode #
################################# #################################
...@@ -252,7 +315,8 @@ class AdisTSwc(AdisTS): ...@@ -252,7 +315,8 @@ class AdisTSwc(AdisTS):
with adists_file_open(os.path.join(repertory, f"{POL_name}.ALD"), "w+") as f: with adists_file_open(os.path.join(repertory, f"{POL_name}.ALD"), "w+") as f:
for LC in POL_LC: for LC in POL_LC:
reach_name = next(filter(lambda edge: edge.id == LC.edge, study.river.edges())).name reach = next(filter(lambda edge: edge.id == LC.edge, study.river.edges())) #.name
reach_name = self.get_reach_name(self, reach)
f.write(f"${reach_name} {LC.begin_rk} {LC.end_rk}\n") f.write(f"${reach_name} {LC.begin_rk} {LC.end_rk}\n")
f.write(f"*temps |débit massique (kg/s)\n") f.write(f"*temps |débit massique (kg/s)\n")
f.write(f"*---------++++++++++\n") f.write(f"*---------++++++++++\n")
...@@ -270,7 +334,9 @@ class AdisTSwc(AdisTS): ...@@ -270,7 +334,9 @@ class AdisTSwc(AdisTS):
with adists_file_open(os.path.join(repertory, f"{POL_name}.CDT"), "w+") as f: with adists_file_open(os.path.join(repertory, f"{POL_name}.CDT"), "w+") as f:
for BC in POL_BC: for BC in POL_BC:
node_name = next(filter(lambda x: x.id == BC.node, study.river._nodes)).name node = next(filter(lambda x: x.id == BC.node, study.river._nodes)) #.name
print("node name in BC:", node, node.name)
node_name = self.get_node_name(node)
f.write(f"${node_name}\n") f.write(f"${node_name}\n")
if BC.type == "Concentration": if BC.type == "Concentration":
......
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