diff --git a/src/Solver/Mage.py b/src/Solver/Mage.py index d4792b7fdbe64d223015fc9c0d7f1279b38c6f6e..38c600d2c63f496ca9aaaec3112b38c584452850 100644 --- a/src/Solver/Mage.py +++ b/src/Solver/Mage.py @@ -54,7 +54,9 @@ class Mage(AbstractSolver): ########## @timer - def _export_ST(self, study, repertory, qlog = None): + def _export_ST(self, study, repertory, qlog): + files = [] + if qlog is not None: qlog.put("Export ST file") @@ -63,6 +65,7 @@ class Mage(AbstractSolver): name = f"Reach_{edge.id}" with open(os.path.join(repertory, f"{name}.ST"), "w+") as f: + files.append(f"{name}.ST") f.write("* This file is generate by PAMHYR, please don't modify\n") for profile in edge.reach.profiles: @@ -87,7 +90,11 @@ class Mage(AbstractSolver): f.write("* END OF FILE") - def _export_BC(self, bound, repertory, qlog = None): + return files + + def _export_BC(self, bound, repertory, qlog): + files = [] + t = "XX" if bound.bctype == "ZD": t = "AVA" @@ -100,6 +107,8 @@ class Mage(AbstractSolver): qlog.put(f"Export {t} file") with open(os.path.join(repertory, f"0.{t}"), "w+") as f: + files.append(f"0.{t}") + f.write("* This file is generate by PAMHYR, please don't modify\n") name = f"{bound.node.id:3}".replace(" ", "x") @@ -113,22 +122,29 @@ class Mage(AbstractSolver): f.write("* END OF FILE") + return files @timer - def _export_bound_cond(self, study, repertory, qlog = None): - # Write header + def _export_bound_cond(self, study, repertory, qlog): + files = [] lst = study.river.boundary_condition + for tab in ["liquid", "solid", "suspenssion"]: for bound in lst.get_tab(tab): - self._export_BC(bound, repertory, qlog) + files = files + self._export_BC(bound, repertory, qlog) + + return files @timer - def _export_RUG(self, study, repertory, qlog = None): + def _export_RUG(self, study, repertory, qlog): + files = [] + if qlog is not None: qlog.put("Export RUG file") # Write header - with open(os.path.join(repertory, f"0.RUG"), "w+") as f: + with open(os.path.join(repertory, "0.RUG"), "w+") as f: + files.append("0.RUG") f.write("* This file is generate by PAMHYR, please don't modify\n") id = 1 @@ -153,6 +169,28 @@ class Mage(AbstractSolver): f.write("* END OF FILE") + return files + + def _export_REP(self, study, repertory, files, qlog): + if qlog is not None: + qlog.put("Export REP file") + + # Write header + with open(os.path.join(repertory, f"0.REP"), "w+") as f: + f.write("confirmation=non\n") + f.write("* This file is generate by PAMHYR, please don't modify\n") + + edges = study.river.edges() + for file in files: + EXT = file.split('.')[1] + + f.write(f"{EXT} {file}\n") + + f.write("* OUTPUT\n") + f.write(f"TRA 0.TRA\n") + f.write(f"BIN 0.BIN\n") + f.write("* END OF FILE") + @timer def export(self, study, repertory, qlog = None): self._export_ST(study, repertory, qlog) @@ -202,10 +240,14 @@ class Mage8(Mage): @timer def _export_PAR(self, study, repertory, qlog = None): + files = [] + if qlog is not None: qlog.put("Export PAR file") with open(os.path.join(repertory, "0.PAR"), "w+") as f: + files.append("0.PAR") + f.write("* This file is generate by PAMHYR, please don't modify\n") params = study.river.get_params(self.type).parameters @@ -219,12 +261,18 @@ class Mage8(Mage): f.write("* END OF FILE") + return files + @timer def _export_NET(self, study, repertory, qlog = None): + files = [] + if qlog is not None: qlog.put("Export NET file") with open(os.path.join(repertory, "0.NET"), "w+") as f: + files.append("0.NET") + f.write("* This file is generate by PAMHYR, please don't modify\n") edges = study.river.edges() @@ -235,18 +283,23 @@ class Mage8(Mage): n1 = f"{e.node1.id:3}".replace(" ", "x") n2 = f"{e.node2.id:3}".replace(" ", "x") - files = name + ".ST" + file = name + ".ST" - f.write(f"{name} {n1} {n2} {files}\n") + f.write(f"{name} {n1} {n2} {file}\n") f.write("* END OF FILE") + return files + @timer def export(self, study, repertory, qlog = None): - self._export_PAR(study, repertory, qlog) - self._export_NET(study, repertory, qlog) - self._export_ST(study, repertory, qlog) - self._export_bound_cond(study, repertory, qlog) - self._export_RUG(study, repertory, qlog) + files = [] + + files = files + self._export_PAR(study, repertory, qlog) + files = files + self._export_NET(study, repertory, qlog) + files = files + self._export_ST(study, repertory, qlog) + files = files + self._export_bound_cond(study, repertory, qlog) + files = files + self._export_RUG(study, repertory, qlog) + self._export_REP(study, repertory, files, qlog) return True