Solver: Mage: Split ST export function.

setup.py
Pierre-Antoine Rouby 2023-10-27 11:31:20 +02:00
parent 66f6d3505b
commit 4355be1a9c
1 changed files with 76 additions and 57 deletions

View File

@ -125,7 +125,6 @@ class Mage(CommandLineSolver):
qlog.put("Export ST file")
os.makedirs(os.path.join(repertory, "net"), exist_ok=True)
gra_file = f"{name}.GRA"
# Write header
edges = study.river.edges()
@ -149,7 +148,25 @@ class Mage(CommandLineSolver):
cnt_num = 1
for profile in edge.reach.profiles:
num = f"{cnt_num:>6}"
self._export_ST_profile_header(
f, files, profile, cnt_num
)
cnt_num += 1
# Points
for point in profile.points:
self._export_ST_point_line(
f, files, point
)
# Profile last line
f.write(f" 999.9990 999.9990 999.9990\n")
return files
def _export_ST_profile_header(self, wfile, files,
profile, cnt):
num = f"{cnt:>6}"
c1 = f"{profile.code1:>6}"
c2 = f"{profile.code2:>6}"
t = f"{len(profile.points):>6}"
@ -165,7 +182,7 @@ class Mage(CommandLineSolver):
sediment = ""
if profile.sl is not None:
if not any(filter(lambda f: ".GRA" in f, files)):
files.append(gra_file)
files.append(self._gra_file)
# Number of layers
nl = len(profile.sl)
@ -180,11 +197,9 @@ class Mage(CommandLineSolver):
)
# Profile header line
f.write(f"{num}{c1}{c2}{t} {kp} {name} {sediment}\n")
cnt_num += 1
wfile.write(f"{num}{c1}{c2}{t} {kp} {name} {sediment}\n")
# Points
for point in profile.points:
def _export_ST_point_line(self, wfile, files, point):
x = f"{point.x:<12f}"[0:12]
y = f"{point.y:<12f}"[0:12]
z = f"{point.z:<12f}"[0:12]
@ -208,12 +223,7 @@ class Mage(CommandLineSolver):
)
# Point line
f.write(f"{x} {y} {z} {n} {sediment}\n")
# Profile last line
f.write(f" 999.9990 999.9990 999.9990\n")
return files
wfile.write(f"{x} {y} {z} {n} {sediment}\n")
@timer
def _export_BC(self, t, bounds, repertory, qlog, name="0"):
@ -429,6 +439,10 @@ class Mage(CommandLineSolver):
self._study = study
name = study.name.replace(" ", "_")
# Define GRA file name
self._gra_file = f"{name}.GRA"
self._bin_file = f"{name}.BIN"
self._export_ST(study, repertory, qlog, name=name)
return True
@ -622,6 +636,11 @@ class Mage8(Mage):
self._study = study
name = study.name.replace(" ", "_")
# Define GRA file name
self._gra_file = f"{name}.GRA"
self._bin_file = f"{name}.BIN"
# Generate files
files = []
files = self._export_ST(study, repertory, qlog, name=name)