diff --git a/src/Solver/RubarBE.py b/src/Solver/RubarBE.py new file mode 100644 index 0000000000000000000000000000000000000000..a6df9d3377eacc6db852e15a9ea01e34977bd2a9 --- /dev/null +++ b/src/Solver/RubarBE.py @@ -0,0 +1,197 @@ +# RubarBE.py -- Pamhyr +# Copyright (C) 2024 INRAE +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +# -*- coding: utf-8 -*- + +import os +import logging +import numpy as np + +from tools import timer, trace, old_pamhyr_date_to_timestamp + +from Solver.CommandLine import CommandLineSolver + +from Model.Results.Results import Results +from Model.Results.River.River import River, Reach, Profile + +logger = logging.getLogger() + +class RubarBE(CommandLineSolver): + _type = "rubarbe" + + def __init__(self, name): + super(RubarBE, self).__init__(name) + + self._type = "rubarbe" + + self._cmd_input = "" + self._cmd_solver = "@path @input -o @output" + self._cmd_output = "" + + @classmethod + def default_parameters(cls): + lst = super(RubarBE, cls).default_parameters() + + lst += [ + ("rubarbe_cfl", "0.50000E+00"), + ("rubarbe_condam", "1"), + ("rubarbe_condav", "3"), + ("rubarbe_regime", "0"), + ("rubarbe_iodev", "n"), + ("rubarbe_iodebord", ""), + ("rubarbe_iostockage", ""), + ("rubarbe_iopdt", "y"), + ("rubarbe_iovis", "n"), + ("rubarbe_rep", "n"), + ("rubarbe_tinit", "000:00:00:00"), + ("rubarbe_tmax", "999:99:99:00"), + ("rubarbe_tiopdt", "000:00:00:00"), + ("rubarbe_dt", "3000.0"), + ("rubarbe_ts", "999:99:99:00"), + ("rubarbe_dtsauv", "999:99:99:00"), + ("rubarbe_psave", "999:99:99:00"), + ("rubarbe_fdeb1", "1"), + ("rubarbe_fdeb2", "10"), + ("rubarbe_fdeb3", "100"), + ("rubarbe_tf_1", "y"), + ("rubarbe_tf_2", "y"), + ("rubarbe_tf_3", "y"), + ("rubarbe_tf_4", "y"), + ("rubarbe_tf_5", "y"), + ("rubarbe_tf_6", "n"), + ("rubarbe_trased", "y"), + ("rubarbe_optfpc", "0"), + ("rubarbe_ros", "2650.0"), + ("rubarbe_dm", "0.1"), + ("rubarbe_segma", "1.0"), + ] + + return lst + + @classmethod + def checkers(cls): + lst = [ + ] + + return lst + + ########## + # Export # + ########## + + def cmd_args(self, study): + lst = super(RubarBE, self).cmd_args(study) + + return lst + + def input_param(self): + name = self._study.name + return f"{name}.REP" + + def output_param(self): + name = self._study.name + return f"{name}.BIN" + + def log_file(self): + name = self._study.name + return f"{name}.TRA" + + def _export_donnee(self, study, repertory, files, qlog, name="0"): + if qlog is not None: + qlog.put("Export DONNEE file") + + with open( + os.path.join( + repertory, f"donnee.{name}" + ), "w+" + ) as f: + params = study.river.get_params(self.type).parameters + it = iter(params) + + line = 0 + while line < 29: + lh, value = next(it) + + if value != "": + # Value format + if value.count(':') == 3: + value = old_pamhyr_date_to_timestamp(value) + value = f"{value:>12.5e}".upper() + + if value.count('.') == 1: + value = f"{value:>12.5e}".upper() + + if value == "y" or value == "n": + value = "O" if value == "y" else "N" + + # Write value + f.write(f"{lh:<50}{value}") + + # Add values of 'rubarbe_iodebord' and + # 'rubarbe_iostockage' + if lh == "rubarbe_iodev": + _, v2 = next(it) + _, v3 = next(it) + + f.write(f"{v2}{v3}") + + # New line + f.write(f"\n") + + line += 1 + + def _export_geomac_i(self, study, repertory, files, qlog, name="0"): + if qlog is not None: + qlog.put("Export GEOMAC-i file") + + with open( + os.path.join( + repertory, f"geomac-i.{name}" + ), "w+" + ) as f: + for edge in study.river.enable_edges(): + reach = edge.reach + n_profiles = len(reach) + time = 0.0 + + f.write(f"{n_profiles:>5} {time:>11.3f}\n") + + ind = 1 + for profile in reach.profiles: + kp = profile.get_kp() + n_points = len(profile) + + f.write(f"{ind:>4} {kp:>11.3f} {n_points:>4}\n") + + for point in profile.points: + label = point.name.lower() + if label[0] == "r": + label = label[1].upper() + + y = point.y + z = point.z + dcs = 0.001 + scs = 1.0 + tmcs = 0.0 + + f.write( + f"{label[0]} {y:>11.5f}" + + f"{z:>13.5f}{dcs:>15.10f}" + + f"{scs:>15.10f}{tmcs:>15.5f}" + + "\n" + ) + + ind += 1