Compare commits
No files matched your search
@@ -19,6 +19,8 @@ tmp
|
||||
*.pdf
|
||||
*.odt
|
||||
|
||||
!doc/**/*.pdf
|
||||
|
||||
doc/dev/images/auto_*
|
||||
doc/dev/documentation.*
|
||||
!doc/dev/*.org
|
||||
|
||||
@@ -26,6 +26,23 @@ stages:
|
||||
# DOWNLOADS #
|
||||
#############
|
||||
|
||||
variables:
|
||||
MAGE_VERSION: "v8.3.3"
|
||||
|
||||
dl-mage-doc:
|
||||
stage: downloads
|
||||
tags:
|
||||
- linux
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == 'ci-test' || $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_TAG
|
||||
script:
|
||||
- mkdir -p doc
|
||||
- cd doc
|
||||
- curl -L -o mage8.pdf https://gitlab.irstea.fr/jean-baptiste.faure/mage/-/releases/$MAGE_VERSION/downloads/documents/Mage-8_Documentation.pdf
|
||||
artifacts:
|
||||
paths:
|
||||
- doc/mage8.pdf
|
||||
|
||||
dl-mage-linux:
|
||||
stage: downloads
|
||||
tags:
|
||||
@@ -33,7 +50,7 @@ dl-mage-linux:
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == 'ci-test' || $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_TAG
|
||||
script:
|
||||
- curl -L -o mage.tgz https://gitlab.irstea.fr/jean-baptiste.faure/mage/-/releases/v8.3.0/downloads/packages/mage_linux.tgz
|
||||
- curl -L -o mage.tgz https://gitlab.irstea.fr/jean-baptiste.faure/mage/-/releases/$MAGE_VERSION/downloads/packages/mage_linux.tgz
|
||||
- mkdir -p mage-linux
|
||||
- cd mage-linux
|
||||
- tar xvf ../mage.tgz
|
||||
@@ -41,7 +58,8 @@ dl-mage-linux:
|
||||
paths:
|
||||
- mage-linux/mage
|
||||
- mage-linux/mage_extraire
|
||||
- mage-linux/mailleurPF
|
||||
- mage-linux/mailleurTT
|
||||
- mage-linux/libbief.so
|
||||
|
||||
dl-mage-windows:
|
||||
stage: downloads
|
||||
@@ -50,7 +68,7 @@ dl-mage-windows:
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == 'ci-test' || $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_TAG
|
||||
script:
|
||||
- curl -L -o mage.tgz https://gitlab.irstea.fr/jean-baptiste.faure/mage/-/releases/v8.3.0/downloads/packages/mage_windows.tgz
|
||||
- curl -L -o mage.tgz https://gitlab.irstea.fr/jean-baptiste.faure/mage/-/releases/$MAGE_VERSION/downloads/packages/mage_windows.tgz
|
||||
- mkdir -p mage-windows
|
||||
- cd mage-windows
|
||||
- tar xvf ../mage.tgz
|
||||
@@ -58,7 +76,8 @@ dl-mage-windows:
|
||||
paths:
|
||||
- mage-windows/mage.exe
|
||||
- mage-windows/mage_extraire.exe
|
||||
- mage-windows/mailleurPF.exe
|
||||
- mage-windows/mailleurTT.exe
|
||||
- mage-windows/libbief.dll
|
||||
|
||||
#############
|
||||
# CONFIGURE #
|
||||
@@ -146,6 +165,24 @@ build-users-doc:
|
||||
- doc/users/images/
|
||||
allow_failure: true
|
||||
|
||||
|
||||
build-td:
|
||||
stage: build
|
||||
tags:
|
||||
- linux
|
||||
needs:
|
||||
- job: set-version
|
||||
artifacts: true
|
||||
script:
|
||||
- cd ./doc/users/Tuto1/
|
||||
- ./build.sh
|
||||
artifacts:
|
||||
paths:
|
||||
- doc/users/Tuto1/step-by-step.pdf
|
||||
- doc/users/Tuto1/pas-a-pas.pdf
|
||||
- doc/users/Tuto1/data/
|
||||
allow_failure: true
|
||||
|
||||
build-developers-doc:
|
||||
stage: build
|
||||
tags:
|
||||
@@ -186,6 +223,8 @@ build-linux:
|
||||
needs:
|
||||
- job: dl-mage-linux
|
||||
artifacts: true
|
||||
- job: dl-mage-doc
|
||||
artifacts: true
|
||||
- job: set-version
|
||||
artifacts: true
|
||||
- job: build-lang
|
||||
@@ -194,6 +233,8 @@ build-linux:
|
||||
artifacts: true
|
||||
- job: build-users-doc
|
||||
artifacts: true
|
||||
- job: build-td
|
||||
artifacts: true
|
||||
script:
|
||||
- mkdir -p linux
|
||||
- cd linux
|
||||
@@ -237,13 +278,25 @@ build-linux:
|
||||
- mkdir -p pamhyr/doc/
|
||||
- mkdir -p pamhyr/doc/images/
|
||||
- mkdir -p pamhyr/doc/html/
|
||||
- cp ../doc/users/documentation.pdf pamhyr/doc/Pamhyr2-users.pdf
|
||||
- cp ../doc/users/documentation.html pamhyr/doc/Pamhyr2-users.html
|
||||
# - cp ../doc/users/documentation.pdf pamhyr/doc/Pamhyr2-users.pdf
|
||||
# - cp ../doc/users/documentation.html pamhyr/doc/Pamhyr2-users.html
|
||||
- cp ../doc/mage8.pdf pamhyr/doc/mage8.pdf
|
||||
- cp ../doc/dev/documentation.pdf pamhyr/doc/Pamhyr2-dev.pdf
|
||||
- cp ../doc/dev/documentation.html pamhyr/doc/Pamhyr2-dev.html
|
||||
#- cp ../doc/users/images/* pamhyr/doc/images
|
||||
- cp ../doc/dev/images/* pamhyr/doc/images
|
||||
- cp ../doc/images/* pamhyr/doc/images
|
||||
- cp -r ../doc/dev/images/* pamhyr/doc/images
|
||||
- cp -r ../doc/images/* pamhyr/doc/images
|
||||
# Copy Tuto
|
||||
- mkdir -p pamhyr/doc/Tuto1/
|
||||
- mkdir -p pamhyr/doc/Tuto1/data
|
||||
- cp ../doc/users/Tuto1/Hogneau_Engees2022.pdf pamhyr/doc/Tuto1/Hogneau_Engees2022.pdf
|
||||
- cp ../doc/users/Tuto1/step-by-step.pdf pamhyr/doc/Tuto1/Tuto1-en.pdf
|
||||
- cp ../doc/users/Tuto1/pas-a-pas.pdf pamhyr/doc/Tuto1/Tuto1-fr.pdf
|
||||
- cp ../doc/users/Tuto1/*.pamhyr pamhyr/doc/Tuto1/
|
||||
- cp ../doc/users/Tuto1/data/* pamhyr/doc/Tuto1/data/
|
||||
# Copy TP charriage
|
||||
- mkdir -p pamhyr/doc/TP_charriage/
|
||||
- cp ../doc/users/TP_charriage/* pamhyr/doc/TP_charriage
|
||||
# Create running script
|
||||
- echo "#!/bin/sh" > pamhyr/Pamhyr2
|
||||
- echo "./pamhyr/pamhyr $@" >> pamhyr/Pamhyr2
|
||||
@@ -261,6 +314,8 @@ build-windows:
|
||||
needs:
|
||||
- job: dl-mage-windows
|
||||
artifacts: true
|
||||
- job: dl-mage-doc
|
||||
artifacts: true
|
||||
- job: set-version
|
||||
artifacts: true
|
||||
- job: build-lang
|
||||
@@ -269,6 +324,8 @@ build-windows:
|
||||
artifacts: true
|
||||
- job: build-users-doc
|
||||
artifacts: true
|
||||
- job: build-td
|
||||
artifacts: true
|
||||
script:
|
||||
- mkdir windows
|
||||
- cd windows
|
||||
|
||||
@@ -10,35 +10,50 @@ modelling of rivers.
|
||||
+ Define boundary conditions
|
||||
+ Define lateral contribution
|
||||
+ Edit river friction
|
||||
+ Add reservoirs
|
||||
+ Add hydraulic structures
|
||||
+ Generate initial conditions
|
||||
+ Edit river sedimentary layers
|
||||
+ Save the study in a unique file
|
||||
+ Run Mage 8 on a study and visualize results
|
||||
|
||||
Let see the
|
||||
[documentation](https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/wikis/home)
|
||||
for more details.
|
||||
|
||||
## Install
|
||||
|
||||
### GNU/Linux
|
||||
|
||||
Downloads [last
|
||||
Downloads the [last
|
||||
realease](https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/releases/permalink/latest)
|
||||
GNU/Linux binary archive.
|
||||
|
||||
```shell
|
||||
tar xf pamhyr-gnulinux-amd64.tar.xz
|
||||
tar xf pamhyr-gnulinux.tar.xz
|
||||
cd pamhyr
|
||||
./pamhyr
|
||||
./Pamhyr2
|
||||
```
|
||||
|
||||
### Windows
|
||||
|
||||
Downloads [last
|
||||
Downloads the [last
|
||||
realease](https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/releases/permalink/latest)
|
||||
Windows installer.
|
||||
Windows installer or ZIP archive.
|
||||
|
||||
### From source code
|
||||
|
||||
```shell
|
||||
# Get source code
|
||||
# Get mage
|
||||
mkdir mage
|
||||
cd mage
|
||||
|
||||
curl -L -o mage.tgz https://gitlab.irstea.fr/jean-baptiste.faure/mage/-/releases/v8.3.2/downloads/packages/mage_linux.tgz
|
||||
tar xf mage.tgz
|
||||
|
||||
cd ..
|
||||
|
||||
# Get Pamhyr2 source code
|
||||
git clone https://gitlab.irstea.fr/theophile.terraz/pamhyr/
|
||||
cd pamhyr
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 40 KiB |
|
After Width: | Height: | Size: 43 KiB |
|
After Width: | Height: | Size: 87 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 45 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 49 KiB |
|
After Width: | Height: | Size: 134 KiB |
|
After Width: | Height: | Size: 131 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 40 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 107 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 45 KiB |
|
After Width: | Height: | Size: 17 KiB |
@@ -0,0 +1,4 @@
|
||||
#! /bin/sh
|
||||
|
||||
pdflatex -no-shell-escape step-by-step.tex
|
||||
pdflatex -no-shell-escape pas-a-pas.tex
|
||||
|
Before Width: | Height: | Size: 69 KiB |
|
Before Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
|
After Width: | Height: | Size: 70 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 115 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 37 KiB |
@@ -0,0 +1,299 @@
|
||||
%% LyX 2.0.2 created this file. For more info, see http://www.lyx.org/.
|
||||
%% Do not edit unless you really know what you are doing.
|
||||
\documentclass[12pt,french]{article}
|
||||
\usepackage[T1]{fontenc}
|
||||
\usepackage[latin9]{inputenc}
|
||||
\usepackage{geometry}
|
||||
\geometry{verbose,tmargin=2cm,bmargin=2cm,lmargin=2cm,rmargin=2cm,headheight=2cm,headsep=2cm,footskip=2cm}
|
||||
\usepackage{textcomp}
|
||||
\usepackage{graphicx}
|
||||
\usepackage{hyperref}
|
||||
|
||||
\makeatletter
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
|
||||
\newcommand{\noun}[1]{\textsc{#1}}
|
||||
%% Because html converters don't know tabularnewline
|
||||
\providecommand{\tabularnewline}{\\}
|
||||
|
||||
\makeatother
|
||||
|
||||
\usepackage{babel}
|
||||
\addto\extrasfrench{%
|
||||
\providecommand{\og}{\leavevmode\flqq~}%
|
||||
\providecommand{\fg}{\ifdim\lastskip>\z@\unskip\fi~\frqq}%
|
||||
}
|
||||
|
||||
\begin{document}
|
||||
\includegraphics[width=5cm]{img/Logo-INRAE_Transparent.png}
|
||||
|
||||
~
|
||||
|
||||
~
|
||||
|
||||
~
|
||||
|
||||
\begin{center}
|
||||
|
||||
Tutoriel pour Pamhyr2
|
||||
|
||||
Janvier 2024
|
||||
|
||||
\par\end{center}
|
||||
|
||||
~
|
||||
|
||||
~
|
||||
|
||||
\begin{center}
|
||||
|
||||
\textbf{\LARGE Modélisation 1D de la rivière } \\
|
||||
\textbf{\LARGE Hogneau (Nord, France) avec Pamhyr2}
|
||||
|
||||
\par\end{center}{\LARGE \par}
|
||||
|
||||
~
|
||||
|
||||
~
|
||||
|
||||
\begin{center}
|
||||
{\large INRAE Lyon-Grenoble Auvergne-Rhône-Alpes}
|
||||
\par\end{center}{\large \par}
|
||||
|
||||
\begin{center}
|
||||
|
||||
RiverLy, Hydraulique des rivières
|
||||
|
||||
\par\end{center}
|
||||
|
||||
~
|
||||
|
||||
~
|
||||
|
||||
~
|
||||
|
||||
~
|
||||
|
||||
~
|
||||
|
||||
~
|
||||
|
||||
\begin{center}
|
||||
\begin{tabular}{lll}
|
||||
Autors : & Pierre-Antoine Rouby & pierre-antoine.rouby@inrae.fr\tabularnewline
|
||||
& Théophile TERRAZ & theophile.terraz@inrae.fr\tabularnewline
|
||||
& Lionel Pénard & lionel.penard@inrae.fr\tabularnewline
|
||||
|
||||
\end{tabular}
|
||||
\par\end{center}
|
||||
|
||||
~
|
||||
|
||||
\pagebreak{}
|
||||
|
||||
\begin{center}
|
||||
\tableofcontents{}
|
||||
\par\end{center}
|
||||
|
||||
~
|
||||
|
||||
\pagebreak{}
|
||||
|
||||
% \section{Introduction}
|
||||
%
|
||||
% TODO
|
||||
%
|
||||
% \pagebreak{}
|
||||
|
||||
|
||||
\section{Installer Pamhyr2}
|
||||
|
||||
Pamhyr2 peut être téléchargé ici : \url{https://gitlab.irstea.fr/theophile.terraz/pamhyr}.
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{img/dl.png}
|
||||
\par\end{center}
|
||||
|
||||
|
||||
Utilisez le bouton de téléchargement GNU Linux ou Windows en fonction de votre système. Sous Windows, lancez le programme d'installation. Sous Linux, décompressez l'archive et lancez Pamhyr2.
|
||||
|
||||
|
||||
\section{Créer une première étude}
|
||||
|
||||
Dans la fenêtre principale, cliquez sur \texttt{[Fichier] => [Nouvelle étude]} pour créer une nouvelle étude. Choisissez un nom, par exemple Hogneau, et validez
|
||||
|
||||
Cliquez sur \texttt{[Réseau] => [Editer le réseau]} pour créer les biefs de votre rivière. Dans cette fenêtre, vous devez définir un graphe orienté qui représente les biefs de votre réseau fluvial : les arêtes sont les biefs et les n½uds sont soit des conditions limites amont, soit des conditions limites aval, soit des jonctions entre biefs.
|
||||
Appuyez sur le bouton \includegraphics[width=0.5cm]{img/gtk_add.png} pour entrer dans le mode \textit{Ajout}. Créez deux n½uds en cliquant dans la zone grise de la fenêtre, et créez un lien en cliquant à nouveau sur chaque n½ud. Appuyez à nouveau sur \includegraphics[width=0.5cm]{img/gtk_add.png} pour quitter le mode \textit{Ajout}. Vous avez créé votre premier bief, avec un n½ud amont et un n½ud aval. Dans la partie inférieure de la fenêtre \textit{Editer le réseau hydrographique}, vous pouvez renommer les n½uds et les biefs. Comme le bief que vous avez créé est automatiquement sélectionné, toutes les étapes suivantes s'appliqueront à ce bief. La fenêtre doit se présenter comme suit :
|
||||
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{img/network.png}
|
||||
\par\end{center}
|
||||
|
||||
|
||||
Fermer la fenêtre \textit{Editer le réseau}.
|
||||
|
||||
|
||||
\section{Editer la géometrie de la rivière}
|
||||
|
||||
Cliquez sur \texttt{[Géometrie] => [Editer la géometrie]} pour définir la géométrie du bief sélectionné. Cliquez sur le bouton \texttt{[Importer]} et sélectionnez le fichier \texttt{Data/Bief\_1.st}. Vous devriez voir :
|
||||
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{img/Geo.png}
|
||||
\par\end{center}
|
||||
|
||||
|
||||
Le panneau de gauche contient une liste de toutes les sections en travers avec leur nom et leur abscisse longitudinale (PK). Dans le graphique en haut à gauche, vous pouvez voir la vue de dessus de la rivière, dans le panneau en haut à droite, la coupe longitudinale de la rivière et dans le graphique en bas, vous pouvez voir la section en travers sélectionnée (bleu) ainsi que la suivante (pointillés violets) et la précédente (pointillés noirs). Vous pouvez vous déplacer dans la liste des sections en cliquant dans le tableau ou à l'aide de l'ascenseur situé entre le tableau et les graphiques.
|
||||
|
||||
Vous pouvez éditer la section en travers sélectionnée en cliquant sur l'icône \includegraphics[width=0.5cm]{"img/edit.png"}.
|
||||
|
||||
Sélectionnez la section en travers nommée \textit{PontRD101m} et ouvrez la fenêtre d'édition. Vous devriez voir :
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{img/editsect.png}
|
||||
\par\end{center}
|
||||
|
||||
|
||||
Sur le panneau de gauche se trouve la liste de tous les points de la section, avec leurs coordonnées, leur nom et leur abscisse transversale. La coordonnée Z du point le plus haut est inscrite en bleu et celle du point le plus bas en rouge. Les points peuvent avoir un nom. Si un point portant le même nom existe dans toutes les sections d'un bief, il forme une ligne longitudinale (ou ligne directrice). Par exemple, nous avons ici \textit{rg} et \textit{rd} qui représentent la rive gauche et la rive droite du lit mineur.
|
||||
|
||||
Sur le graphique figure une projection de la section en travers. Vous pouvez utiliser \texttt{[ctrl + clic]} pour sélectionner un point dans le tracé et \texttt{[maj + clic]} pour sélectionner une ligne d'eau et visualiser des données géométriques utiles. Vous pouvez fermer la fenêtre d'édition de la section en travers et la fenêtre d'édition de la géométrie.
|
||||
|
||||
\section{Editer les conditions aux limites}
|
||||
|
||||
Dans la fenêtre principale, cliquez sur \texttt{[Hydraulique] => [Conditions aux limites et apports ponctuels]} :
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{img/boundary.png}
|
||||
\par\end{center}
|
||||
|
||||
|
||||
Utilisez le bouton \textit{ajouter} en haut à gauche de la fenêtre pour ajouter une condition limite pour le liquide.
|
||||
Sur la nouvelle ligne, on peut cliquer pour sélectionner la ligne entière, et double-cliquer pour sélectionner la cellule.
|
||||
Sélectionnez la cellule \textit{Type} pour donner un nom à la condition limite. Ici, nous définirons le débit mesuré lors de la crue de février 2002. Vous pouvez nommer cette condition limite "crue2002".
|
||||
Sélectionner la cellule \textit{Type} et utiliser la combo box pour mettre une loi Q(t).
|
||||
Sélectionnez la cellule \textit{Noeud} et attribuez cette condition au noeud amont.
|
||||
Les noms des noeuds sont rappelés dans le réseau du panneau de droite.
|
||||
Sélectionnez maintenant la ligne entière et cliquez sur le bouton d'édition \includegraphics[width=0.5cm]{"img/edit.png"}. Vous avez ouvert la fenêtre \textit{Éditer les conditions aux limites}.
|
||||
Dans un éditeur de texte, ouvrez le fichier \texttt{Données/Fevrier\_2002.txt}. Copiez le contenu du fichier (par exemple avec \textit{ctrl+a} puis \textit{ctrl+c}) et collez-le dans le panneau gauche de la fenêtre \textit{Éditer les conditions aux limites} avec \textit{ctrl+v}. Vous pouvez maintenant voir la courbe de débit :
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{img/fev2002.png}
|
||||
\par\end{center}
|
||||
|
||||
|
||||
Fermer cette fenêtre. Revenir sur la fenêtre \textit{Conditions aux limites}. Ajouter une nouvelle ligne, lui donner un nom, lui donner le type \textit{Z(T)} et l'associer au noeud aval du réseau. Ouvrez la fenêtre \textit{Éditer les conditions aux limites} (\includegraphics[width=0.5cm]{"img/edit.png"}). Ajoutez deux lignes. Dans la première, entrez le temps : 0.00.00 et Z : 15.000.
|
||||
Dans la seconde, saisissez le temps : 1.00.00 et Z : 15.000. Cela crée une côte constante de l'eau en aval. Pour le calcul, Mage extrapolera continuellement l'élévation de l'eau.
|
||||
Vous pouvez fermer les fenêtres \textit{Éditer les conditions aux limites} et \textit{Conditions aux limites}.
|
||||
|
||||
\section{Créer les conditions initiales}
|
||||
|
||||
Dans la fenêtre principale, cliquez sur \texttt{[Hydraulique] => [Conditions initiales]}.
|
||||
Si vous ne connaissez pas les conditions initiales de la côte de l'eau et du débit de la rivière, vous pouvez utiliser les boutons \texttt{[Générer une hauteur minimale]} ou \texttt{[Générer un débit constant]} pour laisser Pamhyr2 estimer une condition initiale à l'aide de la formule de Manning-Strickler.
|
||||
Cliquez sur \texttt{[Générer à partir du débit]} et saisissez un débit de $4 m^3$ dans la fenêtre contextuelle pour générer une condition initiale de hauteur d'eau basée sur la formule de Manning-Strickler et un débit uniforme de $4 m^3$. Vous devriez voir :
|
||||
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{img/ic.png}
|
||||
\par\end{center}
|
||||
|
||||
|
||||
Fermer la fenêtre \textit{Conditions initiales}
|
||||
|
||||
|
||||
\section{Editer les coefficients de frottement}
|
||||
|
||||
Dans la fenêtre principale, cliquez sur \texttt{[Hydraulique] => [Editer les frottements]}.
|
||||
Vous devez d'abord définir des jeux de coefficients de Strickler. Cliquez sur \includegraphics[width=0.5cm]{"img/edit.png"} pour ouvrir la fenêtre \textit{Strickler}. Vous pouvez y créer des couples de coefficients de Strickler, le premier pour le lit mineur, le second pour le lit moyen. Cliquez quatre fois sur \textit{add} pour créer quatre nouveaux couples. Donnez-leur les valeurs suivantes :
|
||||
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{img/K.png}
|
||||
\par\end{center}
|
||||
|
||||
|
||||
Fermez la fenêtre \textit{Strickler}. Dans la fenêtre \textit{Editer les frottements}, ajoutez quatre lignes avec le bouton \includegraphics[width=0.5cm]{img/gtk_add.png} pour créer quatre zones de frottement. Chaque zone est définie par un PK \textit{début} et de \textit{fin} PK et un couple \textit{begin} et \textit{end} couple de Strickler. Les couples de coefficients de Strickler à l'intérieur d'une zone sont interpolés à partir des couples \textit{begin} et \textit{end}. Dans notre cas, nous utiliserons des coefficients constants par zone. Définissez les zones comme suit :
|
||||
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{img/frictions.png}
|
||||
\par\end{center}
|
||||
|
||||
|
||||
La zone sélectionnée est surlignée en bleu. Fermez la fenêtre \textit{Editer les frottements}.
|
||||
|
||||
|
||||
\section{Modélisation des ouvrages hydrauliques}
|
||||
|
||||
Parfois, il peut y avoir des sections en travers dans lesquelles les équations de Saint-Venant ne peuvent pas être utilisées pour modéliser l'écoulement de l'eau. Dans ce cas, nous devons définir une autre loi pour relier la côte de l'eau et le débit. C'est le cas, par exemple, au niveau des ponts lorsque la hauteur d'eau est trop élevée, ce qui entraîne un écoulement en charge. Pamhyr2 permet de définir différents ouvrages hydrauliques avec des lois paramétrables. Dans notre cas, on doit représenter un seuil et deux ponts comme ouvrages hydrauliques.
|
||||
Dans la fenêtre principale, cliquez sur \texttt{[Hydraulique] => [Ouvrages hydrauliques]} pour ouvrir la fenêtre des ouvrages hydrauliques. Cliquez trois fois sur le bouton \includegraphics[width=0.5cm]{img/gtk_add.png} pour créer trois ouvrages hydrauliques. Chaque structure peut avoir un nom et doit avoir une portée et un PK. Définissez-les comme suit :
|
||||
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{img/hs.png}
|
||||
\par\end{center}
|
||||
|
||||
|
||||
Sélectionnez le seuil aval et cliquez sur \includegraphics[width=0.5cm]{"img/edit.png"} pour modifier les lois de cette ouvrage. Les ouvrages hydrauliques sont composés d'ouvrages hydrauliques élémentaires. Vous pouvez combiner les lois de plusieurs ouvrages hydrauliques élémentaires pour créer votre ouvrage. Pour ce seuil, nous n'avons besoin que d'un ouvrage hydraulique élémentaire de type déversoir. Cliquez sur \includegraphics[width=0.5cm]{img/gtk_add.png} pour ajouter un nouvel ouvrage hydraulique élémentaire, donnez-lui le type \textit{seuil} et configurez-le comme suit :
|
||||
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{img/seuil.png}
|
||||
\par\end{center}
|
||||
|
||||
|
||||
Retournez à la fenêtre \textit{Ouvrages hydrauliques}.
|
||||
|
||||
Sélectionnez le pont RS101 et cliquez sur \includegraphics[width=0.5cm]{"img/edit.png"} pour éditer les lois de cet ouvrage. Un pont peut être modélisé comme une combinaison d'un orifice pour l'écoulement sous le pont et d'un déversoir pour l'écoulement au-dessus du pont. Créez deux ouvrages hydrauliques élémentaires et définissez-les comme suit :
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{img/seuilRS101.png}
|
||||
|
||||
\includegraphics[width=15cm]{img/orificeRS101.png}
|
||||
\par\end{center}
|
||||
|
||||
|
||||
Revenez à la fenêtre \textit{Ouvrages hydrauliques} et appliquez la même procédure pour le pont de Thivencelle :
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{img/orificeThivencelle.png}
|
||||
|
||||
\includegraphics[width=15cm]{img/seuilThivencelle.png}
|
||||
\par\end{center}
|
||||
|
||||
|
||||
Vous pouvez maintenant fermer les fenêtres \textit{Ouvrages hydrauliques}.
|
||||
|
||||
\section{Paramètres du solveur}
|
||||
|
||||
Dans la fenêtre principale, cliquez sur \texttt{[Exécuter] => [Parameters numériques des solveurs]}.
|
||||
Dans la fenêtre \textit{Paramètres du solveur}, sélectionnez l'onglet \textit{Mage v8}. Réglez les paramètres du solveur comme suit :
|
||||
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{img/param.png}
|
||||
\par\end{center}
|
||||
|
||||
|
||||
Fermer la fenêtre \textit{Paramètres du solveur}.
|
||||
|
||||
\section{Lancer la simulation}
|
||||
|
||||
Dans la fenêtre principale, cliquez sur \texttt{[Exécuter] => [Lancer le solveur]}.
|
||||
Sélectionnez \textit{Defaut-Mage - (Mage8)} et cliquez sur le bouton \textit{Exécuter}.
|
||||
Deux fenêtres s'ouvrent : la fenêtre \textit{check list} et la fenêtre \textit{Log du solveur}.
|
||||
La fenêtre \textit{Check list} donne quelques indications sur la validité de votre modèle, et la fenêtre \textit{Log du solveur} affiche les résultats du solveur.
|
||||
À partir de la fenêtre \textit{Log du solveur}, vous pouvez réexécuter le calcul, et vous pouvez cliquer sur le bouton \textit{Résultats} pour ouvrir la fenêtre \textit{Résultats}.
|
||||
|
||||
\section{Visualiser les résultats}
|
||||
|
||||
il est aussi possible d'ouvrir la fenêtre \textit{Résultats} si vous avez fermé la fenêtre \textit{Log du solveur}, en cliquant sur \texttt{[Résultats] => [Visualiser les derniers résultats]} à partir de la fenêtre principale. Le panneau supérieur vous permet de sélectionner le bief, le panneau inférieur gauche vous permet de sélectionner une section en travers dans ce bief. Les trois diagrammes sur la droite montrent le bief et la section en travers de la même manière que dans la fenêtre \textit{Géométrie}. Vous pouvez utiliser le curseur du bas pour visualiser la côte de l'eau à différents pas de temps.
|
||||
Pour visualiser le débit, passez à l'onglet \textit{Hydrogramme}.
|
||||
Pour créer des tracés 2D personnalisés, cliquez sur le bouton \includegraphics[width=0.5cm]{img/gtk_add.png} en haut à gauche de la fenêtre. Sélectionnez les valeurs que vous voulez sur les axes $X$ et $Y$ et cliquez sur \textit{OK}.
|
||||
Vous pouvez maintenant voir un nouvel onglet avec le tracé 2D personnalisé dans le panneau droit de la fenêtre \textit{Results}.
|
||||
|
||||
|
||||
|
||||
\pagebreak{}
|
||||
\end{document}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
}
|
||||
|
||||
\begin{document}
|
||||
\includegraphics[width=5cm]{Logo-INRAE_Transparent.png}
|
||||
\includegraphics[width=5cm]{img/Logo-INRAE_Transparent.png}
|
||||
|
||||
~
|
||||
|
||||
@@ -58,7 +58,7 @@ using Pamhyr2
|
||||
\par\end{center}{\large \par}
|
||||
|
||||
\begin{center}
|
||||
Riverly, river hydraulics
|
||||
RiverLy, river hydraulics
|
||||
\par\end{center}
|
||||
|
||||
~
|
||||
@@ -75,8 +75,9 @@ Riverly, river hydraulics
|
||||
|
||||
\begin{center}
|
||||
\begin{tabular}{lll}
|
||||
Autors : & Pierre-Antoine Rouby & pierre-antoine.rouby@inrae.fr\tabularnewline
|
||||
& Théophile TERRAZ & theophile.terraz@inrae.fr\tabularnewline
|
||||
Authors : & Pierre-Antoine Rouby & pierre-antoine.rouby@inrae.fr\tabularnewline
|
||||
& Théophile Terraz & theophile.terraz@inrae.fr\tabularnewline
|
||||
& Lionel Pénard & lionel.penard@inrae.fr\tabularnewline
|
||||
\end{tabular}
|
||||
\par\end{center}
|
||||
|
||||
@@ -92,17 +93,17 @@ Autors : & Pierre-Antoine Rouby & pierre-antoine.rouby@inrae.fr\tabularnewline
|
||||
|
||||
\pagebreak{}
|
||||
|
||||
\section{Introduction}
|
||||
|
||||
TODO
|
||||
|
||||
\pagebreak{}
|
||||
% \section{Introduction}
|
||||
%
|
||||
% TODO
|
||||
%
|
||||
% \pagebreak{}
|
||||
|
||||
\section{Install Pamhyr2}
|
||||
|
||||
Pamhyr2 can be downloaded from \url{https://gitlab.irstea.fr/theophile.terraz/pamhyr}.
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{dl.png}
|
||||
\includegraphics[width=15cm]{img/dl.png}
|
||||
\par\end{center}
|
||||
|
||||
Use the GNU Linux or the Windows download button depending on your system. On windows, launch the installer. On Linux, unpack the archive and launch Pamhyr2.
|
||||
@@ -113,10 +114,10 @@ Use the GNU Linux or the Windows download button depending on your system. On wi
|
||||
On the main windows, click on \texttt{[Files] => [New Study]} to create a new study.
|
||||
|
||||
Click on \texttt{[River Network] => [Edit River Network]} to create the reaches of your river. In this window, you must define an oriented graph that represents the reaches of your river network: the edges are the reaches and the nodes are either upstream boundary conditions, downstream boundary conditions or junctions.
|
||||
Press the \includegraphics[width=0.5cm]{gtk_add.png} to enter the \textit{add} mode. Create two nodes by clicking in the grey zone of the window, and create a link by clicking again on each node. press \includegraphics[width=0.5cm]{gtk_add.png} again to exit the \textit{add} mode. You created your first reach, with an upstream node and a downstream node. In the lower part of the \textit{Edit River Network} window you can rename the nodes and the reaches. As the reach you created is automaticaly selected, all the next steps will apply to this reach. The window should look like that:
|
||||
Press the \includegraphics[width=0.5cm]{img/gtk_add.png} to enter the \textit{add} mode. Create two nodes by clicking in the grey zone of the window, and create a link by clicking again on each node. press \includegraphics[width=0.5cm]{img/gtk_add.png} again to exit the \textit{add} mode. You created your first reach, with an upstream node and a downstream node. In the lower part of the \textit{Edit River Network} window you can rename the nodes and the reaches. As the reach you created is automaticaly selected, all the next steps will apply to this reach. The window should look like that:
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{network.png}
|
||||
\includegraphics[width=15cm]{img/network.png}
|
||||
\par\end{center}
|
||||
|
||||
Close the \textit{Edit River Network} window.
|
||||
@@ -127,29 +128,29 @@ Close the \textit{Edit River Network} window.
|
||||
Click on \texttt{[Geometry] => [Edit Geometry]} to define the geometry of the selected bief. Click on the \texttt{[Import]} button and select the file \texttt{Data/Bief\_1.st}. You should see:
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{Geo.png}
|
||||
\includegraphics[width=15cm]{img/Geo.png}
|
||||
\par\end{center}
|
||||
|
||||
On the left panel is a list of all the cross sections with their name and longitudinal abscisa. In the top left plot you can see the top view of the river, on the top right panel the longitudinal cross-section of the river and in the bottom plot you can see the selected cross-section (blue) along with the next one (dashed purple) and previous one (dashed black). You can move in the section list using the slider at the very right of the window.
|
||||
|
||||
You can edit the selected cross section by clicking on the \includegraphics[width=0.5cm]{"../../../src/View/ui/ressources/edit.png"} icon.
|
||||
You can edit the selected cross section by clicking on the \includegraphics[width=0.5cm]{"img/edit.png"} icon.
|
||||
|
||||
select the cross section named \textit{PontRD101m} and open the edition window. You should see:
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{editsect.png}
|
||||
\includegraphics[width=15cm]{img/editsect.png}
|
||||
\par\end{center}
|
||||
|
||||
On the left panel is the list of all the points of the section, with their coordinates, their name and their transversal absisa. The Z coordinate of the highest point is written in blue and the lowest in red. Points can have a name. If a point with the same name exists in every section in a reach, it forms a longitudinal line. For example, here we have \textit{rg} and \textit{rd} which represent the left bank and the right bank of the main chanel.
|
||||
|
||||
On the plot is a projection of the cross section. You can use \texttt{[ctrl + click]} to select a point in the plot and \texttt{[shift + click]} to select a water line and fisualize usefull geometric data. You can close the cross section edition window and the geometry edition window.
|
||||
On the plot is a projection of the cross section. You can use \texttt{[ctrl + click]} to select a point in the plot and \texttt{[shift + click]} to select a water line and visualize usefull geometric data. You can close the cross section edition window and the geometry edition window.
|
||||
|
||||
\section{Edit the boundary conditions}
|
||||
|
||||
From the main window, click on \texttt{[Hydraulics] => [Boundary conditions and punctual contributions]}.You should see:
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{boundary.png}
|
||||
\includegraphics[width=15cm]{img/boundary.png}
|
||||
\par\end{center}
|
||||
|
||||
Use the \textit{add} button on the top left of the window to add a liquid boundary condition.
|
||||
@@ -158,25 +159,25 @@ From the main window, click on \texttt{[Hydraulics] => [Boundary conditions and
|
||||
Select the \textit{Type} cell and use the combo box to put a Q(t) law.
|
||||
Select the \textit{Node} cell and atribute this condition to the upstream node.
|
||||
Names of the nodes are recalled in network in the right panel.
|
||||
Now select the whole line and click on the edit button \includegraphics[width=0.5cm]{"../../../src/View/ui/ressources/edit.png"}. You opened the \textit{Edit Boundary Conditions} window.
|
||||
Now select the whole line and click on the edit button \includegraphics[width=0.5cm]{"img/edit.png"}. You opened the \textit{Edit Boundary Conditions} window.
|
||||
On a text editor, open the \texttt{Data/Fevrier\_2002.txt} file. Copy the content of the file (for example with \textit{ctrl+a ctrl+c}) and paste it in the left panel of the \textit{Edit Boundary Conditions} window with \textit{ctrl+v}. You can now see the flow discharge curve:
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{fev2002.png}
|
||||
\includegraphics[width=15cm]{img/fev2002.png}
|
||||
\par\end{center}
|
||||
|
||||
Close this window. Go back on the \textit{Boundary Conditions} window. Add a new line, give it a name, give it the textit{Z(T)} type and associate it to the downstream node of the network. Open the \textit{Edit Boundary Conditions} window (\includegraphics[width=0.5cm]{"../../../src/View/ui/ressources/edit.png"}). Add two lines. In the first one, enter time: 0.00.00 and Z: 15.000.
|
||||
Close this window. Go back on the \textit{Boundary Conditions} window. Add a new line, give it a name, give it the textit{Z(T)} type and associate it to the downstream node of the network. Open the \textit{Edit Boundary Conditions} window (\includegraphics[width=0.5cm]{"img/edit.png"}). Add two lines. In the first one, enter time: 0.00.00 and Z: 15.000.
|
||||
On the second one, time: 1.00.00 and Z: 15.000. It creates a constant downstream water elevation. For the computaion, Mage will extrapolate continuously the water elevation, that's why we only need to define one hour.
|
||||
You can close the the \textit{Edit Boundary Conditions} and the \textit{Boundary Conditions} window.
|
||||
|
||||
\section{Create initial conditions}
|
||||
|
||||
From the main window, click on \texttt{[Hydraulics] => [Initial conditions]}.
|
||||
If you don't know the initial conditions in water elevation and flow discharge of the river, you can use \texttt{[Generate minimal height]} or \texttt{[Generate constant discharge]} buttons to let Pamhyr2 estimate an initial condition using the Manning-Strickler formula.
|
||||
Click on \texttt{[Generate minimal height]} and enter a discharge of $4 m^2$ in the pop-up window to generate an initial water height condition based on the Manning-Strickler formula and a uniform discharge of $4 m^2$. You should see:
|
||||
If you don't know the initial conditions in water elevation and flow discharge of the river, you can use \texttt{[Generate minimal height]} or \texttt{[Generate from discharge]} buttons to let Pamhyr2 estimate an initial condition using the Manning-Strickler formula.
|
||||
Click on \texttt{[Generate from discharge]} and enter a discharge of $4 m^3$ in the pop-up window to generate an initial water height condition based on the Manning-Strickler formula and a uniform discharge of $4 m^3$. You should see:
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{ic.png}
|
||||
\includegraphics[width=15cm]{img/ic.png}
|
||||
\par\end{center}
|
||||
|
||||
Close the \textit{Initial conditions} window.
|
||||
@@ -185,16 +186,16 @@ Close the \textit{Initial conditions} window.
|
||||
\section{Edit friction coefficients}
|
||||
|
||||
From the main window, click on \texttt{[Hydraulics] => [Edit friction]}.
|
||||
You fist have to define sets of Strickler coefficients. Click on \includegraphics[width=0.5cm]{"../../../src/View/ui/ressources/edit.png"} to open the \textit{Strickler} window. Here you can create couples of Strickler coefficients, the first one for the minor bed, the second one for the medium bed. Click on \textit{add} four times to create four new couple. Give them the folowing values:
|
||||
You fist have to define sets of Strickler coefficients. Click on \includegraphics[width=0.5cm]{"img/edit.png"} to open the \textit{Strickler} window. Here you can create couples of Strickler coefficients, the first one for the minor bed, the second one for the medium bed. Click on \textit{add} four times to create four new couple. Give them the folowing values:
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{K.png}
|
||||
\includegraphics[width=15cm]{img/K.png}
|
||||
\par\end{center}
|
||||
|
||||
Close the \textit{Strickler} window. On the \textit{Edit friction} window, add four lines with the button \includegraphics[width=0.5cm]{gtk_add.png} to create four friction zones. Each zone is defined by a \textit{begin} and \textit{end} PK and a \textit{begin} and \textit{end} Strickler couple. The strickler coefficient couples inside a zone are interpolated from the \textit{begin} and \textit{end} couples. In our case, we will use constant coefficients per zone. Set the zones as follow:
|
||||
Close the \textit{Strickler} window. On the \textit{Edit friction} window, add four lines with the button \includegraphics[width=0.5cm]{img/gtk_add.png} to create four friction zones. Each zone is defined by a \textit{begin} and \textit{end} KP and a \textit{begin} and \textit{end} Strickler couple. The strickler coefficient couples inside a zone are interpolated from the \textit{begin} and \textit{end} couples. In our case, we will use constant coefficients per zone. Set the zones as follow:
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{frictions.png}
|
||||
\includegraphics[width=15cm]{img/frictions.png}
|
||||
\par\end{center}
|
||||
|
||||
The selected zone is highlighted in blue. Close the \textit{Edit friction} window.
|
||||
@@ -203,34 +204,34 @@ The selected zone is highlighted in blue. Close the \textit{Edit friction} windo
|
||||
\section{Model hydraulic structures}
|
||||
|
||||
Sometimes there can be cross-sections in which Shallow water equations can not be used to model the water flow. In that case, we have to define an other law to link the water elevation and the flow discharge. This is the case, for example, under bridges when the water elevation is too high, leading to a flow in charge. Pamhyr2 enables to define various hydraulic structures with laws that can be parametrized. In our case, a weir and two bridges have to be represented as hydraulic structures.
|
||||
From the main window, click on \texttt{[Hydraulics] => [Hydraulic structures]} to open the hydraulic structures window. Click tree times on the \includegraphics[width=0.5cm]{gtk_add.png} button to create three hydraulic structures. Each structure can have a name and must have a reach and a kp. Set them as follow:
|
||||
From the main window, click on \texttt{[Hydraulics] => [Hydraulic structures]} to open the hydraulic structures window. Click tree times on the \includegraphics[width=0.5cm]{img/gtk_add.png} button to create three hydraulic structures. Each structure can have a name and must have a reach and a KP. Set them as follow:
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{hs.png}
|
||||
\includegraphics[width=15cm]{img/hs.png}
|
||||
\par\end{center}
|
||||
|
||||
Select the downstream weir and click on \includegraphics[width=0.5cm]{"../../../src/View/ui/ressources/edit.png"} to edit the laws of this structure. Hydraulic structures are composed of basic hydraulic structures. You can combine the laws of several basic hydraulic structures to setup your structure. For this weir, we only need a weir basic hydraulic structure. Click on \includegraphics[width=0.5cm]{gtk_add.png} to add a new basic hydraulic structure, give it the \textit{weir} type and set it up as folow:
|
||||
Select the downstream weir and click on \includegraphics[width=0.5cm]{"img/edit.png"} to edit the laws of this structure. Hydraulic structures are composed of basic hydraulic structures. You can combine the laws of several basic hydraulic structures to setup your structure. For this weir, we only need a weir basic hydraulic structure. Click on \includegraphics[width=0.5cm]{img/gtk_add.png} to add a new basic hydraulic structure, give it the \textit{weir} type and set it up as folow:
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{seuil.png}
|
||||
\includegraphics[width=15cm]{img/seuil.png}
|
||||
\par\end{center}
|
||||
|
||||
Go back to the \textit{hydraulic structures} window.
|
||||
|
||||
Select the RS101 bridge and click on \includegraphics[width=0.5cm]{"../../../src/View/ui/ressources/edit.png"} to edit the laws of this structure. A bridge can be modeled as a combination of an orifice for the flow under the bridge and a weir for the flow over the bridge. Create two basic hydraulic structures and set them as folow:
|
||||
Select the RS101 bridge and click on \includegraphics[width=0.5cm]{"img/edit.png"} to edit the laws of this structure. A bridge can be modeled as a combination of an orifice for the flow under the bridge and a weir for the flow over the bridge. Create two basic hydraulic structures and set them as folow:
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{seuilRS101.png}
|
||||
\includegraphics[width=15cm]{img/seuilRS101.png}
|
||||
|
||||
\includegraphics[width=15cm]{orificeRS101.png}
|
||||
\includegraphics[width=15cm]{img/orificeRS101.png}
|
||||
\par\end{center}
|
||||
|
||||
Go back to the \textit{hydraulic structures} window and aply the same procedure for the Thivencelle bridge:
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{orificeThivencelle.png}
|
||||
\includegraphics[width=15cm]{img/orificeThivencelle.png}
|
||||
|
||||
\includegraphics[width=15cm]{seuilThivencelle.png}
|
||||
\includegraphics[width=15cm]{img/seuilThivencelle.png}
|
||||
\par\end{center}
|
||||
|
||||
You can now close the \textit{hydraulic structures} windows.
|
||||
@@ -241,7 +242,7 @@ From the main window, click on \texttt{[Execute] => [Numerical parameters for so
|
||||
In the window \textit{solver parameters} select the \textit{Mage v8} tab. Set the solver parameters as follow:
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=15cm]{param.png}
|
||||
\includegraphics[width=15cm]{img/param.png}
|
||||
\par\end{center}
|
||||
|
||||
Close the \textit{solver parameters} window.
|
||||
@@ -256,9 +257,9 @@ From the \textit{Solver log} window you can re-run the computation, and from the
|
||||
|
||||
\section{Visualize the results}
|
||||
|
||||
If you closed the textit{Solver log} window, you can click on \texttt{[Results] => [Visualize last results]} from the main window to open the \textit{Results} window. The top lets panel let you select your reach, the bottom left panel lets you select a cross-section in that reach. the tree plots on the right show the reach and the cross-section the same way than in the \textit{Geometry} window. You can use the bottom slider to visualize the water elevation at different timesteps.
|
||||
If you closed the \textit{Solver log} window, you can click on \texttt{[Results] => [Visualize last results]} from the main window to open the \textit{Results} window. The top lets panel let you select your reach, the bottom left panel lets you select a cross-section in that reach. the three plots on the right show the reach and the cross-section the same way than in the \textit{Geometry} window. You can use the bottom slider to visualize the water elevation at different timesteps.
|
||||
To visualize the flow discharge, switch to the \textit{Hydrograph} tab.
|
||||
To create custom 2D plots, click on the \includegraphics[width=0.5cm]{gtk_add.png} button on the top left of the window. Select the values you want on the $X$ and $Y$ axis and click on \textit{OK}.
|
||||
To create custom 2D plots, click on the \includegraphics[width=0.5cm]{img/gtk_add.png} button on the top left of the window. Select the values you want on the $X$ and $Y$ axis and click on \textit{OK}.
|
||||
You can now see a new tab with the custom 2D plot in the right panel of the \textit{Results} window.
|
||||
|
||||
|
||||
|
||||
@@ -42,7 +42,8 @@ rem MAGE
|
||||
mkdir pamhyr\mage
|
||||
copy /y ..\mage-windows\mage.exe pamhyr\mage\
|
||||
copy /y ..\mage-windows\mage_extraire.exe pamhyr\mage\
|
||||
copy /y ..\mage-windows\mailleurPF.exe pamhyr\mage\
|
||||
copy /y ..\mage-windows\mailleurTT.exe pamhyr\mage\
|
||||
copy /y ..\mage-windows\libbief.dll pamhyr\mage\
|
||||
|
||||
rem Copy tests_cases
|
||||
mkdir pamhyr\tests_cases
|
||||
@@ -52,10 +53,24 @@ copy /y ..\tests_cases\Saar\Saar.pamhyr pamhyr\tests_cases\Saar\
|
||||
rem Documentations
|
||||
mkdir pamhyr\doc
|
||||
mkdir pamhyr\doc\images
|
||||
copy /y ..\doc\users\documentation.pdf pamhyr\doc\Pamhyr2-users.pdf
|
||||
rem copy /y ..\doc\users\documentation.pdf pamhyr\doc\Pamhyr2-users.pdf
|
||||
copy /y ..\doc\dev\documentation.pdf pamhyr\doc\Pamhyr2-dev.pdf
|
||||
copy /y ..\doc\users\documentation.html pamhyr\doc\Pamhyr2-users.html
|
||||
copy /y ..\doc\mage8.pdf pamhyr\doc\mage8.pdf
|
||||
rem copy /y ..\doc\users\documentation.html pamhyr\doc\Pamhyr2-users.html
|
||||
copy /y ..\doc\dev\documentation.html pamhyr\doc\Pamhyr2-dev.html
|
||||
copy /y ..\doc\users\images\* pamhyr\doc\images
|
||||
copy /y ..\doc\dev\images\* pamhyr\doc\images
|
||||
copy /y ..\doc\images\* pamhyr\doc\images
|
||||
|
||||
rem Tuto
|
||||
mkdir pamhyr\doc\Tuto1\
|
||||
mkdir pamhyr\doc\Tuto1\data
|
||||
copy /y ..\doc\users\Tuto1\Hogneau_Engees2022.pdf pamhyr\doc\Tuto1\Hogneau_Engees2022.pdf
|
||||
copy /y ..\doc\users\Tuto1\step-by-step.pdf pamhyr\doc\Tuto1\Tuto1-en.pdf
|
||||
copy /y ..\doc\users\Tuto1\pas-a-pas.pdf pamhyr\doc\Tuto1\Tuto1-fr.pdf
|
||||
copy /y ..\doc\users\Tuto1\*.pamhyr pamhyr\doc\Tuto1\
|
||||
copy /y ..\doc\users\Tuto1\data\* pamhyr\doc\Tuto1\data\
|
||||
|
||||
rem TP charriage
|
||||
mkdir pamhyr\doc\TP_charriage
|
||||
copy /y ..\doc\users\TP_charriage\ pamhyr\doc\TP_charriage
|
||||
@@ -24,6 +24,7 @@ from tools import flatten, timer
|
||||
from PyQt5.QtCore import QCoreApplication
|
||||
|
||||
from Checker.Checker import AbstractModelChecker, STATUS
|
||||
from Checker.Study import StudyGeometryChecker
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
@@ -195,3 +196,51 @@ class MageNetworkGraphChecker(AbstractModelChecker):
|
||||
self._summary = summary
|
||||
self._status = status
|
||||
return True
|
||||
|
||||
|
||||
class MageGeometryGuideLineChecker(StudyGeometryChecker):
|
||||
def __init__(self):
|
||||
super(MageGeometryGuideLineChecker, self).__init__()
|
||||
|
||||
self._name = _translate("Checker", "Mage geometry guide line checker")
|
||||
self._description = _translate(
|
||||
"Checker",
|
||||
"Check if exists geometry guide line is correctly defined \
|
||||
for each reaches of the study"
|
||||
)
|
||||
self._reachs = []
|
||||
|
||||
def run(self, study):
|
||||
ok = super(MageGeometryGuideLineChecker, self).run(study)
|
||||
|
||||
if not ok:
|
||||
return ok
|
||||
|
||||
river = study.river
|
||||
edges = river.enable_edges()
|
||||
|
||||
gls = []
|
||||
|
||||
for edge in edges:
|
||||
comp, incomp = edge.reach.compute_guidelines()
|
||||
if len(incomp) != 0:
|
||||
self._status = STATUS.WARNING
|
||||
self._summary = "incomplete_guideline"
|
||||
return False
|
||||
|
||||
gls.append(comp)
|
||||
|
||||
profiles = edge.reach.profiles
|
||||
for profile in profiles:
|
||||
if not profile.has_standard_named_points():
|
||||
self._status = STATUS.WARNING
|
||||
self._summary = "no_standard_guileline_defined"
|
||||
return False
|
||||
|
||||
for gl in gls[1:]:
|
||||
if len(gls[0].symmetric_difference(gl)) != 0:
|
||||
self._status = STATUS.WARNING
|
||||
self._summary = "no_all_reaches_do_not_have_same_defined"
|
||||
return False
|
||||
|
||||
return ok
|
||||
@@ -82,15 +82,15 @@ class StudyGeometryChecker(AbstractModelChecker):
|
||||
self._summary = "no_river_found"
|
||||
return False
|
||||
|
||||
edges = list(filter(lambda e: e.is_enable(), river.edges()))
|
||||
edges = river.enable_edges()
|
||||
if len(edges) == 0:
|
||||
self._status = STATUS.ERROR
|
||||
self._summary = "no_reach_defined"
|
||||
return False
|
||||
|
||||
for edge in edges:
|
||||
if edge.is_enable() and len(edge.reach.profiles) < 3:
|
||||
summary = f"no_geometry_defined"
|
||||
if len(edge.reach.profiles) < 2:
|
||||
summary = "no_geometry_defined"
|
||||
status = STATUS.ERROR
|
||||
ok = False
|
||||
self._reachs.append(edge)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
# AMeshingTool.py -- Pamhyr
|
||||
# Copyright (C) 2023 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 -*-
|
||||
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
|
||||
|
||||
class AMeshingTool(object):
|
||||
def __init__(self):
|
||||
super(AMeshingTool, self).__init__()
|
||||
|
||||
def meshing(self, reach, **kwargs):
|
||||
raise NotImplementedMethodeError(self, self.meshing)
|
||||
@@ -0,0 +1,324 @@
|
||||
# Mage.py -- Pamhyr
|
||||
# Copyright (C) 2023 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 tempfile
|
||||
|
||||
from ctypes import (
|
||||
cdll,
|
||||
byref, Structure,
|
||||
c_char_p, c_wchar_p,
|
||||
create_string_buffer,
|
||||
POINTER, c_void_p,
|
||||
c_int, c_double, c_bool
|
||||
)
|
||||
from PyQt5.QtCore import QProcess
|
||||
|
||||
from tools import logger_color_red, logger_color_reset
|
||||
from Meshing.AMeshingTool import AMeshingTool
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class MeshingWithMage(AMeshingTool):
|
||||
def __init__(self):
|
||||
super(MeshingWithMage, self).__init__()
|
||||
|
||||
self._init_bief_lib()
|
||||
|
||||
def _init_bief_lib(self):
|
||||
self._bief_lib = cdll.LoadLibrary(self._lib_path())
|
||||
|
||||
self._init_c_init_bief_from_geo_file()
|
||||
self._init_c_get_nb_sections()
|
||||
self._init_c_get_nb_points_section()
|
||||
self._init_c_set_bief_name()
|
||||
self._init_c_st_to_m_compl()
|
||||
self._init_c_interpolate_profils_pas_transversal()
|
||||
self._init_c_purge()
|
||||
self._init_c_output_bief()
|
||||
|
||||
@classmethod
|
||||
def _lib_path(cls):
|
||||
ext = "so" if os.name == "posix" else "dll"
|
||||
|
||||
return os.path.abspath(
|
||||
os.path.join(
|
||||
os.path.dirname(__file__),
|
||||
"..", "..", "..", "mage", f"libbief.{ext}"
|
||||
)
|
||||
)
|
||||
|
||||
def _init_c_init_bief_from_geo_file(self):
|
||||
self._c_init_bief_from_geo_file = getattr(
|
||||
self._bief_lib, 'c_init_bief_from_geo_file'
|
||||
)
|
||||
self._c_init_bief_from_geo_file.argtypes = [
|
||||
c_char_p, POINTER(c_int), POINTER(c_int)
|
||||
]
|
||||
self._c_init_bief_from_geo_file.restype = None
|
||||
|
||||
def _init_c_get_nb_sections(self):
|
||||
self._c_get_nb_sections = getattr(self._bief_lib, 'c_get_nb_sections')
|
||||
self._c_get_nb_sections.argtypes = [POINTER(c_int)]
|
||||
self._c_get_nb_sections.restype = None
|
||||
|
||||
def _init_c_get_nb_points_section(self):
|
||||
self._c_get_nb_points_section = getattr(
|
||||
self._bief_lib, 'c_get_nb_points_section'
|
||||
)
|
||||
self._c_get_nb_points_section.argtypes = [
|
||||
POINTER(c_int), POINTER(c_int)
|
||||
]
|
||||
self._c_get_nb_points_section.restype = None
|
||||
|
||||
def _init_c_set_bief_name(self):
|
||||
self._c_set_bief_name = getattr(self._bief_lib, 'c_set_bief_name')
|
||||
self._c_set_bief_name.argtypes = [c_char_p]
|
||||
self._c_set_bief_name.restype = None
|
||||
|
||||
def _init_c_st_to_m_compl(self):
|
||||
self._c_st_to_m_compl = getattr(self._bief_lib, 'c_st_to_m_compl')
|
||||
self._c_st_to_m_compl.argtypes = [POINTER(c_int), c_char_p, c_char_p]
|
||||
self._c_st_to_m_compl.restype = None
|
||||
|
||||
def _init_c_interpolate_profils_pas_transversal(self):
|
||||
self._c_interpolate_profils_pas_transversal = getattr(
|
||||
self._bief_lib, 'c_interpolate_profils_pas_transversal'
|
||||
)
|
||||
self._c_interpolate_profils_pas_transversal.argtypes = [
|
||||
POINTER(c_int), POINTER(c_int),
|
||||
c_char_p, c_char_p,
|
||||
POINTER(c_double), POINTER(c_bool),
|
||||
POINTER(c_int), POINTER(c_bool)
|
||||
]
|
||||
self._c_interpolate_profils_pas_transversal.restype = None
|
||||
|
||||
def _init_c_purge(self):
|
||||
self._c_purge = getattr(self._bief_lib, 'c_purge')
|
||||
self._c_purge.argtypes = None
|
||||
self._c_purge.restype = None
|
||||
|
||||
def _init_c_output_bief(self):
|
||||
self._c_output_bief = getattr(self._bief_lib, 'c_output_bief')
|
||||
self._c_output_bief.argtypes = [c_char_p]
|
||||
self._c_output_bief.restype = None
|
||||
|
||||
#####################
|
||||
# Binding functions #
|
||||
#####################
|
||||
|
||||
def init_bief_from_geo_file(self, name, with_charriage, with_water):
|
||||
cname = create_string_buffer(name.encode())
|
||||
self._c_init_bief_from_geo_file(
|
||||
cname,
|
||||
byref(c_int(with_charriage)),
|
||||
byref(c_int(with_water))
|
||||
)
|
||||
|
||||
def get_nb_sections(self):
|
||||
nb_sections = c_int(0)
|
||||
self._c_get_nb_sections(byref(nb_sections))
|
||||
return nb_sections.value
|
||||
|
||||
def get_nb_points_section(self, section):
|
||||
nb_points = c_int(0)
|
||||
self._c_get_nb_points_section(
|
||||
byref(c_int(section)), byref(nb_points)
|
||||
)
|
||||
return nb_points.value
|
||||
|
||||
def set_bief_name(self, name):
|
||||
cname = create_string_buffer(name.encode())
|
||||
self._c_set_bief_name(cname)
|
||||
|
||||
def st_to_m_compl(self, npoints, tag1=' ', tag2=' '):
|
||||
cnpoints = c_int(npoints)
|
||||
ctag1 = create_string_buffer(tag1.encode())
|
||||
ctag2 = create_string_buffer(tag2.encode())
|
||||
|
||||
self._c_st_to_m_compl(byref(cnpoints), ctag1, ctag2)
|
||||
|
||||
def interpolate_profils_pas_transversal(self, limite1, limite2,
|
||||
directrice1, directrice2,
|
||||
pas, lplan=False,
|
||||
lm=3, lineaire=False):
|
||||
climite1 = c_int(limite1)
|
||||
climite2 = c_int(limite2)
|
||||
cpas = c_double(pas)
|
||||
clplan = c_bool(lplan)
|
||||
clm = c_int(lm)
|
||||
clineaire = c_bool(lineaire)
|
||||
cdirectrice1 = create_string_buffer(directrice1.encode())
|
||||
cdirectrice2 = create_string_buffer(directrice2.encode())
|
||||
|
||||
self._c_interpolate_profils_pas_transversal(
|
||||
byref(climite1), byref(climite2),
|
||||
cdirectrice1, cdirectrice2,
|
||||
byref(cpas), byref(clplan),
|
||||
byref(clm), byref(clineaire)
|
||||
)
|
||||
|
||||
def output_bief(self, name):
|
||||
cname = create_string_buffer(name.encode())
|
||||
self._c_output_bief(cname)
|
||||
|
||||
###########
|
||||
# Meshing #
|
||||
###########
|
||||
|
||||
def meshing(self, reach, step: float = 50):
|
||||
if reach is None or len(reach.profiles) == 0:
|
||||
return reach
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
st_file = self.export_reach_to_st(reach, tmp)
|
||||
m_file = st_file.rsplit(".ST", 1)[0] + ".M"
|
||||
|
||||
self.load_st_file(st_file)
|
||||
|
||||
ns, npts_max = self.get_reach_stat()
|
||||
|
||||
gl = reach.compute_guidelines()
|
||||
|
||||
# we make sure that the lines are in the left-to-right order
|
||||
guide_list = [
|
||||
x.name
|
||||
for x in reach.profiles[0].named_points()
|
||||
if x.name in gl[0]
|
||||
]
|
||||
|
||||
self.complete_cross_section(guide_list)
|
||||
self.interpolate_cross_section(ns, step)
|
||||
self.purge()
|
||||
|
||||
self.export_to_m(m_file)
|
||||
|
||||
self.import_m_file(reach, m_file)
|
||||
return reach
|
||||
|
||||
def export_reach_to_st(self, reach, tmp):
|
||||
tmp_st = os.path.join(tmp, "meshing.ST")
|
||||
|
||||
logger.debug(f"meshing: Export ST to {tmp_st}")
|
||||
|
||||
reach.export_reach(tmp_st)
|
||||
return tmp_st
|
||||
|
||||
def load_st_file(self, st):
|
||||
self.init_bief_from_geo_file(st, 0, 0)
|
||||
self.set_bief_name("tmp")
|
||||
|
||||
def get_reach_stat(self):
|
||||
ns = self.get_nb_sections()
|
||||
npts_max = max(
|
||||
map(
|
||||
lambda i: self.get_nb_points_section(i),
|
||||
range(1, ns)
|
||||
)
|
||||
)
|
||||
|
||||
return ns, npts_max
|
||||
|
||||
def complete_cross_section(self, gl=[]):
|
||||
gl1 = ["un"] + gl
|
||||
gl2 = gl + ["np"]
|
||||
|
||||
for gls in zip(gl1, gl2):
|
||||
self.st_to_m_compl(0, gls[0], gls[1])
|
||||
|
||||
def interpolate_cross_section(self, ns, step: float):
|
||||
self.interpolate_profils_pas_transversal(
|
||||
1, ns,
|
||||
'un', 'np',
|
||||
step
|
||||
)
|
||||
|
||||
def purge(self):
|
||||
self._c_purge()
|
||||
|
||||
def export_to_m(self, m):
|
||||
self.output_bief(m)
|
||||
|
||||
def import_m_file(self, reach, m):
|
||||
reach.purge()
|
||||
|
||||
logger.debug(f"meshing: Import geometry from {m}")
|
||||
reach.import_geometry(m)
|
||||
|
||||
|
||||
class MeshingWithMageMailleurTT(AMeshingTool):
|
||||
def __init__(self):
|
||||
super(MeshingWithMageMailleurTT, self).__init__()
|
||||
|
||||
@classmethod
|
||||
def _exe_path(cls):
|
||||
ext = "" if os.name == "posix" else ".exe"
|
||||
|
||||
return os.path.abspath(
|
||||
os.path.join(
|
||||
os.path.dirname(__file__),
|
||||
"..", "..", "..", "mage", f"mailleurTT{ext}"
|
||||
)
|
||||
)
|
||||
|
||||
###########
|
||||
# Meshing #
|
||||
###########
|
||||
|
||||
def meshing(self, reach, step: float = 50):
|
||||
if reach is None or len(reach.profiles) == 0:
|
||||
return reach
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
logger.debug(f"temp file: {tmp}")
|
||||
st_file = self.export_reach_to_st(reach, tmp)
|
||||
m_file = st_file.rsplit(".ST", 1)[0] + ".M"
|
||||
|
||||
proc = QProcess()
|
||||
proc.setWorkingDirectory(tmp)
|
||||
|
||||
logger.debug(f"! mailleurTT {st_file} {m_file} {str(step)}")
|
||||
proc.start(
|
||||
self._exe_path(), [st_file, m_file, str(step)]
|
||||
)
|
||||
proc.waitForFinished()
|
||||
|
||||
errors = proc.readAllStandardError()
|
||||
if len(errors) != 0:
|
||||
logger.error(
|
||||
f"{logger_color_red()}{errors}{logger_color_reset()}"
|
||||
)
|
||||
else:
|
||||
self.import_m_file(reach, m_file)
|
||||
return reach
|
||||
|
||||
def export_reach_to_st(self, reach, tmp):
|
||||
tmp_st = os.path.join(tmp, "meshing.ST")
|
||||
|
||||
logger.debug(f"meshing: Export ST to {tmp_st}")
|
||||
|
||||
reach.export_reach(tmp_st)
|
||||
return tmp_st
|
||||
|
||||
def import_m_file(self, reach, m):
|
||||
reach.purge()
|
||||
|
||||
logger.debug(f"meshing: Import geometry from {m}")
|
||||
reach.import_geometry(m)
|
||||
@@ -0,0 +1,17 @@
|
||||
# __init__.py -- Pamhyr
|
||||
# Copyright (C) 2023 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 -*-
|
||||
@@ -0,0 +1,37 @@
|
||||
# test_Model.py -- Pamhyr
|
||||
# Copyright (C) 2023 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 unittest
|
||||
import warnings
|
||||
import tempfile
|
||||
|
||||
from Model.Saved import SavedStatus
|
||||
from Model.Study import Study
|
||||
from Model.River import River
|
||||
|
||||
from Meshing.Mage import MeshingWithMage
|
||||
|
||||
mage_mesher = os.path.exists(MeshingWithMage._lib_path())
|
||||
|
||||
|
||||
class MeshingTestCase(unittest.TestCase):
|
||||
@unittest.skipIf(not mage_mesher, "libbief is not available")
|
||||
def test_create_meshingtool_mage(self):
|
||||
mesher = MeshingWithMage()
|
||||
self.assertNotEqual(mesher, None)
|
||||
@@ -179,3 +179,38 @@ class ClipboardFormatError(ExeceptionWithMessageBox):
|
||||
|
||||
def message(self):
|
||||
return self.msg
|
||||
|
||||
|
||||
class ExternFileMissingError(ExeceptionWithMessageBox):
|
||||
def __init__(self, module="mage", filename="libbief", path="??/libbief.so",
|
||||
src_except=None):
|
||||
super(ExternFileMissingError, self).__init__(
|
||||
title=_translate(
|
||||
"Exception", "External file dependence is missing"
|
||||
)
|
||||
)
|
||||
|
||||
self.msg = _translate(
|
||||
"Exception",
|
||||
"'@file' is missing for module @module:\n'@path'"
|
||||
)
|
||||
self.msg = self.msg.replace("@file", filename)
|
||||
self.msg = self.msg.replace("@module", module)
|
||||
self.msg = self.msg.replace("@path", path)
|
||||
|
||||
if src_except is not None:
|
||||
self.msg = self.msg + "\n\n" + f"Exception: {src_except}"
|
||||
|
||||
self.alert()
|
||||
|
||||
def __str__(self):
|
||||
return self.msg
|
||||
|
||||
def header(self):
|
||||
return _translate("Exception", "External file dependence is missing")
|
||||
|
||||
def short_message(self):
|
||||
return _translate("Exception", "External file dependence is missing")
|
||||
|
||||
def message(self):
|
||||
return self.msg
|
||||
@@ -77,8 +77,15 @@ class Friction(SQLSubModel):
|
||||
for row in table:
|
||||
ind = row[0]
|
||||
# Get stricklers
|
||||
bs = next(filter(lambda s: s.id == row[3], stricklers))
|
||||
es = next(filter(lambda s: s.id == row[4], stricklers))
|
||||
if int(row[3]) == -1:
|
||||
bs = None
|
||||
else:
|
||||
bs = next(filter(lambda s: s.id == row[3], stricklers))
|
||||
|
||||
if int(row[4]) == -1:
|
||||
es = None
|
||||
else:
|
||||
es = next(filter(lambda s: s.id == row[4], stricklers))
|
||||
|
||||
# Create friction
|
||||
sec = cls(status=status)
|
||||
@@ -94,6 +101,15 @@ class Friction(SQLSubModel):
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
ind = data["ind"]
|
||||
|
||||
b_s_id = -1
|
||||
e_s_id = -1
|
||||
|
||||
if self._begin_strickler is not None:
|
||||
b_s_id = self._begin_strickler.id
|
||||
if self._end_strickler is not None:
|
||||
e_s_id = self._end_strickler.id
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"friction(ind, begin_kp, end_kp, " +
|
||||
@@ -101,7 +117,7 @@ class Friction(SQLSubModel):
|
||||
"VALUES (" +
|
||||
f"{ind}, {self._begin_kp}, {self._end_kp}, " +
|
||||
f"{self._edge.id}, " +
|
||||
f"{self._begin_strickler.id}, {self._end_strickler.id}" +
|
||||
f"{b_s_id}, {e_s_id}" +
|
||||
")"
|
||||
)
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from math import dist, sqrt, acos
|
||||
from math import dist
|
||||
import numpy as np
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
@@ -204,55 +204,3 @@ class PointXYZ(Point, SQLSubModel):
|
||||
Euclidean distance between the two points
|
||||
"""
|
||||
return dist((p1.x, p1.y, p1.z), (p2.x, p2.y, p2.z))
|
||||
|
||||
@staticmethod
|
||||
def angle(p1, p2, p3):
|
||||
"""angle p1 p2 p3.
|
||||
|
||||
Args:
|
||||
p1: A XYZ Point
|
||||
p2: A XYZ Point
|
||||
p3: A XYZ Point
|
||||
|
||||
Returns:
|
||||
angle p1 p2 p3
|
||||
"""
|
||||
a = PointXYZ.distance(p1, p2)
|
||||
b = PointXYZ.distance(p2, p3)
|
||||
c = PointXYZ.distance(p1, p3)
|
||||
return acos((a**2 + b**2 - c**2) / (2 * a * b))
|
||||
|
||||
|
||||
@staticmethod
|
||||
def triangle_height(p1, p2, p3):
|
||||
"""triangle p1 p2 p3 height starting at p2.
|
||||
|
||||
Args:
|
||||
p1: A XYZ Point
|
||||
p2: A XYZ Point
|
||||
p3: A XYZ Point
|
||||
|
||||
Returns:
|
||||
triangle height starting at p2
|
||||
"""
|
||||
a = PointXYZ.distance(p1, p2)
|
||||
b = PointXYZ.distance(p2, p3)
|
||||
c = PointXYZ.distance(p1, p3)
|
||||
h2 = a**2 - ((c**2 - b**2 + a**2) / 2*c)**2
|
||||
return sqrt(h2)
|
||||
|
||||
@staticmethod
|
||||
def triangle_area(p1, p2, p3):
|
||||
"""triangle p1 p2 p3 area.
|
||||
|
||||
Args:
|
||||
p1: A XYZ Point
|
||||
p2: A XYZ Point
|
||||
p3: A XYZ Point
|
||||
|
||||
Returns:
|
||||
triangle height starting at p2
|
||||
"""
|
||||
h = PointXYZ.triangle_height(p1, p2, p3)
|
||||
d = PointXYZ.distance(p1, p3)
|
||||
return h*d/2
|
||||
@@ -214,20 +214,6 @@ class Profile(object):
|
||||
self.points.insert(index, point)
|
||||
self._status.modified()
|
||||
|
||||
|
||||
def add_point(self, point:Point):
|
||||
"""append point at end of profile.
|
||||
|
||||
Args:
|
||||
point: The point.
|
||||
|
||||
Returns:
|
||||
Nothing.
|
||||
"""
|
||||
self._points.append(point)
|
||||
self._status.modified()
|
||||
|
||||
|
||||
def delete_i(self, indexes: list):
|
||||
self._points = list(
|
||||
map(
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import logging
|
||||
import numpy as np
|
||||
from typing import List
|
||||
from functools import reduce
|
||||
|
||||
from tools import timer
|
||||
|
||||
@@ -212,11 +213,21 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
return profile
|
||||
|
||||
def point_from_data(self, header, data):
|
||||
def float_format(s: str):
|
||||
return float(
|
||||
s.replace(",", ".")
|
||||
)
|
||||
|
||||
point = None
|
||||
try:
|
||||
if len(header) == 0:
|
||||
x = float_format(data[0])
|
||||
y = float_format(data[1])
|
||||
z = float_format(data[2])
|
||||
name = data[3] if len(data) == 4 else ""
|
||||
|
||||
point = PointXYZ(
|
||||
*data, profile=self, status=self._status
|
||||
x, y, z, name, profile=self, status=self._status
|
||||
)
|
||||
else:
|
||||
valid_header = {'name', 'x', 'y', 'z'}
|
||||
@@ -309,7 +320,23 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
)
|
||||
except Exception as e:
|
||||
logger.debug(f"{e}")
|
||||
raise IndexError(f"Invalid point name: {name}")
|
||||
raise IndexError(
|
||||
f"Invalid point name: {name} " +
|
||||
f"for profile ({self.id}) kp = {self.kp}"
|
||||
)
|
||||
|
||||
def has_standard_named_points(self):
|
||||
l, r = reduce(
|
||||
lambda acc, n: (
|
||||
(acc[0] | (n == "rg")),
|
||||
(acc[1] | (n == "rd"))
|
||||
),
|
||||
map(lambda p: p.name.lower().strip(),
|
||||
self.points),
|
||||
(False, False)
|
||||
)
|
||||
|
||||
return l & r
|
||||
|
||||
def add(self):
|
||||
"""Add a new PointXYZ to profile.
|
||||
@@ -440,80 +467,13 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||
|
||||
return list(map(lambda s: s - constant, station))
|
||||
|
||||
@timer
|
||||
def length(self) -> list:
|
||||
l = []
|
||||
x = self.x()
|
||||
y = self.y()
|
||||
z = self.z()
|
||||
for i in range(len(self.points)-1):
|
||||
dx = x[i+1] - x[i]
|
||||
dy = y[i+1] - y[i]
|
||||
dz = z[i+1] - z[i]
|
||||
l.append( np.sqrt(dx*dx + dy*dy + dz*dz) )
|
||||
|
||||
return l
|
||||
|
||||
|
||||
@timer
|
||||
def cumul_length(self) -> list:
|
||||
lcum = []
|
||||
lc = 0.0
|
||||
l = self.length()
|
||||
for i in l:
|
||||
lc = lc + i
|
||||
lcum.append(lc)
|
||||
|
||||
return lcum
|
||||
|
||||
@timer
|
||||
def purge1(self, np) -> list:
|
||||
|
||||
points = self.points
|
||||
if (self.number_points <= np): return points
|
||||
while len(points) > np:
|
||||
x1 = [point.x() for point in points]
|
||||
y1 = [point.y() for point in points]
|
||||
z1 = [point.z() for point in points]
|
||||
l = [(x*x+y*y+z*z) for (x,y,z) in zip(x1,y1,z1)]
|
||||
l2 = [(x + y) for (x, y) in zip(l[:-1], l[1:])]
|
||||
imin = np.argmin(l2)+1
|
||||
points.pop(imin)
|
||||
|
||||
return points
|
||||
|
||||
@timer
|
||||
def purge2(self, np) -> list:
|
||||
|
||||
points = self.points
|
||||
if (self.number_points <= np): return points
|
||||
while len(points) > np:
|
||||
l2 = []
|
||||
for i in range(len(points)-2):
|
||||
l2.append(PointXYZ.angle(points(i),points(i+1),points(i+2)))
|
||||
imax = np.argmax(l2)+1
|
||||
points.pop(imax)
|
||||
|
||||
return points
|
||||
|
||||
@timer
|
||||
def purge3(self, np) -> list:
|
||||
|
||||
points = self.points
|
||||
if (self.number_points <= np): return points
|
||||
while len(points) > np:
|
||||
l2 = []
|
||||
for i in range(len(points)-2):
|
||||
l2.append(PointXYZ.triangle_area(points(i),points(i+1),points(i+2)))
|
||||
imin = np.argmin(l2)+1
|
||||
points.pop(imin)
|
||||
|
||||
return points
|
||||
|
||||
|
||||
def width_approximation(self):
|
||||
rg = self.get_point_by_name("rg")
|
||||
rd = self.get_point_by_name("rd")
|
||||
if self.has_standard_named_points():
|
||||
rg = self.get_point_by_name("rg")
|
||||
rd = self.get_point_by_name("rd")
|
||||
else:
|
||||
rg = self.points[0]
|
||||
rd = self.points[-1]
|
||||
|
||||
return abs(rg.dist(rd))
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ from copy import deepcopy
|
||||
from operator import itemgetter
|
||||
from functools import reduce
|
||||
|
||||
from tools import flatten, timer, trace
|
||||
from tools import flatten, timer, trace, logger_exception
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
|
||||
@@ -247,6 +247,11 @@ class Reach(SQLSubModel):
|
||||
self._update_profile_numbers()
|
||||
self._status.modified()
|
||||
|
||||
def purge(self):
|
||||
self._profiles = []
|
||||
self._update_profile_numbers()
|
||||
self._status.modified()
|
||||
|
||||
def move_up_profile(self, index: int):
|
||||
if index < len(self.profiles):
|
||||
next = index - 1
|
||||
@@ -264,13 +269,37 @@ class Reach(SQLSubModel):
|
||||
self._status.modified()
|
||||
|
||||
def get_x(self):
|
||||
return [profile.x() for profile in self.profiles]
|
||||
return list(
|
||||
map(
|
||||
lambda profile: profile.x(),
|
||||
filter(
|
||||
lambda profile: len(profile) > 0,
|
||||
self.profiles
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def get_y(self):
|
||||
return [profile.y() for profile in self.profiles]
|
||||
return list(
|
||||
map(
|
||||
lambda profile: profile.y(),
|
||||
filter(
|
||||
lambda profile: len(profile) > 0,
|
||||
self.profiles
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def get_z(self):
|
||||
return [profile.z() for profile in self.profiles]
|
||||
return list(
|
||||
map(
|
||||
lambda profile: profile.z(),
|
||||
filter(
|
||||
lambda profile: len(profile) > 0,
|
||||
self.profiles
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def get_z_min(self):
|
||||
"""List of z min for each profile
|
||||
@@ -278,7 +307,15 @@ class Reach(SQLSubModel):
|
||||
Returns:
|
||||
List of z min for each profile
|
||||
"""
|
||||
return [profile.z_min() for profile in self.profiles]
|
||||
return list(
|
||||
map(
|
||||
lambda profile: profile.z_min(),
|
||||
filter(
|
||||
lambda profile: len(profile) > 0,
|
||||
self.profiles
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def get_z_max(self):
|
||||
"""List of z max for each profile
|
||||
@@ -286,7 +323,15 @@ class Reach(SQLSubModel):
|
||||
Returns:
|
||||
List of z max for each profile
|
||||
"""
|
||||
return [profile.z_max() for profile in self.profiles]
|
||||
return list(
|
||||
map(
|
||||
lambda profile: profile.z_max(),
|
||||
filter(
|
||||
lambda profile: len(profile) > 0,
|
||||
self.profiles
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def get_kp(self):
|
||||
"""List of profiles kp
|
||||
@@ -296,11 +341,28 @@ class Reach(SQLSubModel):
|
||||
"""
|
||||
return [profile.kp for profile in self.profiles]
|
||||
|
||||
def get_kp_complete_profiles(self):
|
||||
return list(
|
||||
map(
|
||||
lambda profile: profile.kp,
|
||||
filter(
|
||||
lambda profile: len(profile) > 0,
|
||||
self.profiles
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def get_kp_min(self):
|
||||
return min(self.get_kp())
|
||||
if len(self.get_kp()) > 0:
|
||||
return min(self.get_kp())
|
||||
else:
|
||||
return 0.0
|
||||
|
||||
def get_kp_max(self):
|
||||
return max(self.get_kp())
|
||||
if len(self.get_kp()) > 0:
|
||||
return max(self.get_kp())
|
||||
else:
|
||||
return 0.0
|
||||
|
||||
# Sediment Layers
|
||||
|
||||
@@ -369,7 +431,7 @@ class Reach(SQLSubModel):
|
||||
Returns:
|
||||
Tuple of complete and incomplete guidelines name.
|
||||
"""
|
||||
# Get all point contains into a guideline
|
||||
# Get all point contained into a guideline
|
||||
named_points = [profile.named_points() for profile in self.profiles]
|
||||
points_name = list(
|
||||
map(
|
||||
@@ -482,8 +544,7 @@ class Reach(SQLSubModel):
|
||||
Returns:
|
||||
Nothing.
|
||||
"""
|
||||
list_profile = []
|
||||
list_header = []
|
||||
imported_profiles = []
|
||||
|
||||
try:
|
||||
list_profile, list_header = self.read_file_st(str(file_path_name))
|
||||
@@ -500,9 +561,8 @@ class Reach(SQLSubModel):
|
||||
**d, reach=self, status=self._status
|
||||
)
|
||||
prof.import_points(profile)
|
||||
self.profiles.append(prof)
|
||||
self._update_profile_numbers()
|
||||
|
||||
imported_profiles.append(prof)
|
||||
self._status.modified()
|
||||
except FileNotFoundError as e:
|
||||
logger.error(e)
|
||||
@@ -510,6 +570,11 @@ class Reach(SQLSubModel):
|
||||
except FileFormatError as e:
|
||||
logger.error(e)
|
||||
e.alert()
|
||||
finally:
|
||||
self.profiles = imported_profiles + self.profiles
|
||||
|
||||
self._update_profile_numbers()
|
||||
return imported_profiles
|
||||
|
||||
@timer
|
||||
def read_file_st(self, filename):
|
||||
@@ -525,6 +590,8 @@ class Reach(SQLSubModel):
|
||||
list_header = []
|
||||
stop_code = "999.999"
|
||||
|
||||
logger.debug(f"Import geometry from {filename}")
|
||||
|
||||
with open(filename, encoding="utf-8") as file_st:
|
||||
for line in file_st:
|
||||
if not (line.startswith("#") or line.startswith("*")):
|
||||
@@ -563,281 +630,31 @@ class Reach(SQLSubModel):
|
||||
|
||||
# TODO: Move this function to model reach
|
||||
def export_reach(self, filename):
|
||||
with open(f"{filename}", "w") as file_st:
|
||||
for index in range(len(self.profiles)):
|
||||
profile = self.profiles[index]
|
||||
with open(f"{filename}", "w") as st:
|
||||
cnt = 0
|
||||
for profile in self.profiles:
|
||||
num = f"{cnt:>6}"
|
||||
c1 = f"{profile.code1:>6}"
|
||||
c2 = f"{profile.code2:>6}"
|
||||
t = f"{len(profile.points):>6}"
|
||||
kp = f"{profile.kp:>12f}"[0:12]
|
||||
pname = profile.name
|
||||
if profile.name == "":
|
||||
pname = f"p{profile.id:>3}".replace(" ", "0")
|
||||
|
||||
for v in profile.header:
|
||||
file_st.write(f"{v:>6}")
|
||||
file_st.write("\n")
|
||||
st.write(f"{num}{c1}{c2}{t} {kp} {pname}\n")
|
||||
|
||||
for point in self._data.profile[index_pro].points:
|
||||
for i in [point.x, point.y, point.z, point.name]:
|
||||
file_st.write(f"{i:>13.4f}")
|
||||
file_st.write("\n")
|
||||
for point in profile.points:
|
||||
x = f"{point.x:<12.4f}"[0:12]
|
||||
y = f"{point.y:<12.4f}"[0:12]
|
||||
z = f"{point.z:<12.4f}"[0:12]
|
||||
n = f"{point.name:<3}"
|
||||
|
||||
file_st.write(" 999.9990 999.9990 999.9990")
|
||||
file_st.write("\n")
|
||||
st.write(f"{x} {y} {z} {n}\n")
|
||||
|
||||
# Interpolate
|
||||
|
||||
@timer
|
||||
def interpolate_step(self, lim: list, guideline1: str, guideline2: str, step: float, longmi: int, linear: bool):
|
||||
"""interpolate with a given step between profile lim[0] and profile lim[1]
|
||||
Args:
|
||||
lim: index of profiles for interpolation
|
||||
guideline1: first guideline for distance
|
||||
guideline2: second guideline for distance
|
||||
step: interpolation step
|
||||
longmi: 1 if distance computed on min(dist(guideline1),dist(guideline2))
|
||||
2 if distance computed on max(dist(guideline1),dist(guideline2))
|
||||
else: distance computed on (dist(guideline1)+dist(guideline2))/2
|
||||
linear: true if linear interpolation, false if spline interpolation
|
||||
|
||||
Returns:
|
||||
List of profiles including old profiles and interpolated profiles.
|
||||
"""
|
||||
if len(lim) != 2:
|
||||
print('TODO: CRITICAL ERROR!') # error for now, only one interval
|
||||
if lim[0] < 0 or lim[0] >= lim[1] or lim[1] >= self.number_profiles:
|
||||
print('TODO: CRITICAL ERROR!')
|
||||
if lim[1] < 0 or lim[0] > lim[1]:
|
||||
print('TODO: CRITICAL ERROR!')
|
||||
comp, inconmp = self.compute_guidelines()
|
||||
if not guideline1 in comp:
|
||||
print('TODO: CRITICAL ERROR!')
|
||||
if not guideline2 in comp:
|
||||
print('TODO: CRITICAL ERROR!')
|
||||
|
||||
nbsti = [] # number of profiles to add between self._profile[i] and self._profile[i+1]
|
||||
for i in range(lim[0]):
|
||||
nbsti.append(0)
|
||||
for i in range(lim[0],lim[1]-1):
|
||||
points = self.profile(i).points
|
||||
point11 = next(filter(lambda p: p.name == guideline1, points))
|
||||
point12 = next(filter(lambda p: p.name == guideline2, points))
|
||||
points = self.profile(i+1).points
|
||||
point21 = next(filter(lambda p: p.name == guideline1, points))
|
||||
point22 = next(filter(lambda p: p.name == guideline2, points))
|
||||
d1 = point11.dist(point21)
|
||||
d2 = point12.dist(point22) # warning: 3D distance
|
||||
|
||||
if (longmi == 1):
|
||||
d = max(d1, d2)
|
||||
elif (longmi == 2):
|
||||
d = min(d1, d2)
|
||||
else:
|
||||
d = 0.5*(d1 + d2)
|
||||
|
||||
nbsti[i] = nint(d / pas) - 1
|
||||
if(nbsti[i] < 0): nbsti[i] = 0
|
||||
|
||||
for i in range(lim[1]-1,self.number_profiles-1):
|
||||
nbsti.append(0)
|
||||
|
||||
return self.interpolate_nprof(nbsti, lineaire)
|
||||
|
||||
@timer
|
||||
def interpolate_nprof(self, nbsti: List[int], linear: bool):
|
||||
"""add nbsti[i] profiles between self._profile[i] and self._profile[i+1]
|
||||
|
||||
Args:
|
||||
nbsti: number of profiles to add between self._profile[i] and self._profile[i+1]
|
||||
linear: true if linear interpolation, false if spline interpolation
|
||||
|
||||
Returns:
|
||||
List of profiles including old profiles and interpolated profiles.
|
||||
"""
|
||||
|
||||
if(lineaire):
|
||||
return self.interpolate_linear(nbsti)
|
||||
else:
|
||||
# we might add the spline interpolation later
|
||||
print('TODO: CRITICAL ERROR!')
|
||||
|
||||
@timer
|
||||
def interpolate_linear(self, nbsti: List[int]):
|
||||
"""add nbsti[i] profiles between self._profile[i] and self._profile[i+1]
|
||||
|
||||
Args:
|
||||
nbsti: number of profiles to add between self._profile[i] and self._profile[i+1]
|
||||
|
||||
Returns:
|
||||
List of profiles including old profiles and interpolated profiles.
|
||||
"""
|
||||
if len(nbsti) != self.number_profiles()-1:
|
||||
print('TODO: CRITICAL ERROR!') # error for now, only one interval
|
||||
sections_out = []
|
||||
kps = self.get_kp()
|
||||
for isect_in in range(len(nbsti)):
|
||||
sections_out.append(self.profiles(isect_in))
|
||||
dkp = kps[isect_in + 1] - kps[isect_in]
|
||||
sect_in1 = self.profiles(isect_in)
|
||||
sect_in2 = self.profiles(isect_in+1)
|
||||
for isect_loc in range(nbsti[isect_in]):
|
||||
# RATIO entre les deux sections initiales
|
||||
d=float(isect_loc)/float(nbsti(isect_in)+1)
|
||||
x1 = sect_in1.x()
|
||||
y1 = sect_in1.y()
|
||||
z1 = sect_in1.z()
|
||||
x2 = sect_in2.x()
|
||||
y2 = sect_in2.y()
|
||||
z2 = sect_in2.z()
|
||||
tags = sect_in1.names()
|
||||
section_out.append(ProfileXYZ(kp = kps[isect_in] + d*dkp,
|
||||
reach = self))
|
||||
for i in range(len(x1)): # can do better...
|
||||
# add the points to the created section
|
||||
sections_out[-1].add_point(PointXYZ(x = x1[i] + d*(x2[i] - x1[i]),
|
||||
y = y1[i] + d*(y2[i] - y1[i]),
|
||||
z = z1[i] + d*(z2[i] - z1[i]),
|
||||
name = tags[i]))
|
||||
# don't forget the last one:
|
||||
sections_out.append(self.profiles[self.number_profiles-1])
|
||||
return sections_out
|
||||
|
||||
@timer
|
||||
def st_to_m(self):
|
||||
"""convert a ST bief to a M bief (same number of points on every section)
|
||||
|
||||
Args:
|
||||
nbsti: number of profiles to add between self._profile[i] and self._profile[i+1]
|
||||
|
||||
Returns:
|
||||
List of profiles including old profiles and interpolated profiles.
|
||||
"""
|
||||
isectmax = 0
|
||||
npoint_max = 0
|
||||
new_profiles = []
|
||||
np = []
|
||||
nprof = len(self.number_profiles)
|
||||
# find the profile with more points
|
||||
for isect in range(nprof):
|
||||
new_profiles.append(self.profile(isect))
|
||||
points = new_profiles[isect].points
|
||||
np.append(len(points))
|
||||
if(npoint_max < len(points)):
|
||||
npoint_max = len(points)
|
||||
isectmax = isect
|
||||
|
||||
# let's go ! up from isectmax
|
||||
for isect in range(isectmax+1,nprof):
|
||||
# TODO case new_profiles[isect].length() = 0.0
|
||||
# TODO case new_profiles[isect-1].length() = 0.0
|
||||
l = new_profiles[isect-1].length() # length of each segment
|
||||
lcum = new_profiles[isect-1].cumul_length() # lcum[-1] is length
|
||||
alpha = [i/lcum[-1] for i in lcum]
|
||||
l = new_profiles[isect].length()
|
||||
lcum = new_profiles[isect].cumul_length()
|
||||
beta = [i/lcum[-1] for i in lcum]
|
||||
for i in range(np[isect], npoints_max):
|
||||
beta.append(1.0)
|
||||
|
||||
|
||||
|
||||
for k in range(np[isect]): # boucle sur les points à rajouter
|
||||
trouve = False
|
||||
for j0 in range(np[isect]-1):
|
||||
if(trouve):break
|
||||
undeplus=True
|
||||
for j1 in range(j0, np[isect]-1):
|
||||
if(undeplus):
|
||||
if(beta[j1].le.alpha[j1]):
|
||||
undeplus=False
|
||||
break
|
||||
|
||||
if (undeplus):
|
||||
if (j0 == np[isect]-2):
|
||||
trouve=True
|
||||
else:
|
||||
j1=j0+1
|
||||
if (beta[j0]-alpha[j0] > alpha[j1]-beta[j0]): # beta(j0) > (alpha(j1)+alpha(j2))/2
|
||||
trouve = True
|
||||
|
||||
|
||||
if (trouve):
|
||||
# on rajoute un point
|
||||
ratio=(alpha[j0]-beta[j0-1])/(beta[j0]-beta[j0-1])
|
||||
if (ratio < 0.0):
|
||||
# on double le point a gauche
|
||||
new_profiles[isect].insert_point(j0,new_profiles[isect].points[j0])
|
||||
beta[j0]=beta[j0-1]
|
||||
new_profiles[isect].points[j0+1].name('')
|
||||
else:
|
||||
p = PointXYZ(x = (1.0-ratio)*new_profiles[isect].points[j0].x + ratio*new_profiles[isect].points[j0].x,
|
||||
y = (1.0-ratio)*new_profiles[isect].points[j0].y + ratio*new_profiles[isect].points[j0].y,
|
||||
z = (1.0-ratio)*new_profiles[isect].points[j0].z + ratio*new_profiles[isect].points[j0].z
|
||||
)
|
||||
new_profiles[isect].insert_point(j0,p)
|
||||
|
||||
n = len(new_profiles[isect].points)
|
||||
if n <= npoint_max: # we add the missing points at the end of the profile
|
||||
for k in range(n,npoints_max): new_profiles[isect].add_point(new_profiles[isect].points[-1])
|
||||
|
||||
|
||||
# let's go ! down from isectmax
|
||||
for isect in range(isectmax-1,-1,-1):
|
||||
# TODO case new_profiles[isect].length() = 0.0
|
||||
# TODO case new_profiles[isect-1].length() = 0.0
|
||||
l = new_profiles[isect+1].length() # length of each segment
|
||||
lcum = new_profiles[isect+1].cumul_length() # lcum[-1] is length
|
||||
alpha = [i/lcum[-1] for i in lcum]
|
||||
l = new_profiles[isect].length()
|
||||
lcum = new_profiles[isect].cumul_length()
|
||||
beta = [i/lcum[-1] for i in lcum]
|
||||
for i in range(np[isect], npoints_max):
|
||||
beta.append(1.0)
|
||||
|
||||
|
||||
|
||||
for k in range(np[isect]): # boucle sur les points à rajouter
|
||||
trouve = False
|
||||
for j0 in range(np[isect]-1):
|
||||
if(trouve):break
|
||||
undeplus=True
|
||||
for j1 in range(j0, np[isect]-1):
|
||||
if(undeplus):
|
||||
if(beta[j1].le.alpha[j1]):
|
||||
undeplus=False
|
||||
break
|
||||
|
||||
if (undeplus):
|
||||
if (j0 == np[isect]-2):
|
||||
trouve=True
|
||||
else:
|
||||
j1=j0+1
|
||||
if (beta[j0]-alpha[j0] > alpha[j1]-beta[j0]): # beta(j0) > (alpha(j1)+alpha(j2))/2
|
||||
trouve = True
|
||||
|
||||
|
||||
if (trouve):
|
||||
# on rajoute un point
|
||||
ratio=(alpha[j0]-beta[j0-1])/(beta[j0]-beta[j0-1])
|
||||
if (ratio < 0.0):
|
||||
# on double le point a gauche
|
||||
new_profiles[isect].insert_point(j0,new_profiles[isect].points[j0])
|
||||
new_profiles[isect].points[j0+1].name('')
|
||||
beta[j0]=beta[j0-1]
|
||||
else:
|
||||
p = PointXYZ(x = (1.0-ratio)*new_profiles[isect].points[j0].x + ratio*new_profiles[isect].points[j0].x,
|
||||
y = (1.0-ratio)*new_profiles[isect].points[j0].y + ratio*new_profiles[isect].points[j0].y,
|
||||
z = (1.0-ratio)*new_profiles[isect].points[j0].z + ratio*new_profiles[isect].points[j0].z,
|
||||
)
|
||||
new_profiles[isect].insert_point(j0,p)
|
||||
|
||||
n = len(new_profiles[isect].points)
|
||||
if n <= npoint_max: # we add the missing points at the end of the profile
|
||||
for k in range(n,npoints_max): new_profiles[isect].add_point(new_profiles[isect].points[-1])
|
||||
|
||||
@timer
|
||||
def purge(self, np: int) -> list:
|
||||
profiles = []
|
||||
for profile in self.profiles():
|
||||
points = profile.purge2(np)
|
||||
profiles.append(ProfileXYZ())
|
||||
profiles[-1].import_points(points)
|
||||
|
||||
return profiles
|
||||
st.write(" 999.9990 999.9990 999.9990")
|
||||
st.write("\n")
|
||||
cnt += 1
|
||||
|
||||
def get_incline(self):
|
||||
first = self.profile(0)
|
||||
@@ -931,10 +748,14 @@ class Reach(SQLSubModel):
|
||||
logger.debug(f"+{incline_acc}")
|
||||
logger.debug(f"-{incline_set}")
|
||||
|
||||
return (
|
||||
reduce(
|
||||
lambda acc, x: acc + x,
|
||||
incline_set,
|
||||
0.0
|
||||
) / (len(incline_set))
|
||||
)
|
||||
try:
|
||||
return (
|
||||
reduce(
|
||||
lambda acc, x: acc + x,
|
||||
incline_set,
|
||||
0.0
|
||||
) / (len(incline_set))
|
||||
)
|
||||
except Exception as e:
|
||||
logger_exception(e)
|
||||
return 0
|
||||
@@ -37,145 +37,145 @@ class NotDefined(BasicHS):
|
||||
self._data = []
|
||||
|
||||
|
||||
class SeuilDeversoir(BasicHS):
|
||||
class DischargeWeir(BasicHS):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None):
|
||||
super(SeuilDeversoir, self).__init__(
|
||||
super(DischargeWeir, self).__init__(
|
||||
id=id, name=name,
|
||||
status=status
|
||||
)
|
||||
|
||||
self._type = "S1"
|
||||
self._data = [
|
||||
BHSValue("Largeur", float, 1.0, status=status),
|
||||
BHSValue("Cote", float, 1.0, status=status),
|
||||
BHSValue("Coefficient de debit", float, 0.4, status=status),
|
||||
BHSValue("width", float, 1.0, status=status),
|
||||
BHSValue("elevation", float, 1.0, status=status),
|
||||
BHSValue("discharge_coefficient", float, 0.4, status=status),
|
||||
]
|
||||
|
||||
|
||||
class SeuilTrapezoidal(BasicHS):
|
||||
class TrapezoidalWeir(BasicHS):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None):
|
||||
super(SeuilTrapezoidal, self).__init__(
|
||||
super(TrapezoidalWeir, self).__init__(
|
||||
id=id, name=name,
|
||||
status=status
|
||||
)
|
||||
|
||||
self._type = "S2"
|
||||
self._data = [
|
||||
BHSValue("Largeur", float, 1.0, status=status),
|
||||
BHSValue("Cote", float, 1.0, status=status),
|
||||
BHSValue("Cote de mise en charge", float, 9999.999, status=status),
|
||||
BHSValue("Coefficient de debit", float, 0.4, status=status),
|
||||
BHSValue("Tangeante du demi angle", float, 0.0, status=status),
|
||||
BHSValue("width", float, 1.0, status=status),
|
||||
BHSValue("elevation", float, 1.0, status=status),
|
||||
BHSValue("loading_elevation", float, 9999.999, status=status),
|
||||
BHSValue("discharge_coefficient", float, 0.4, status=status),
|
||||
BHSValue("half-angle_tangent", float, 0.0, status=status),
|
||||
]
|
||||
|
||||
|
||||
class SeuilTriangulaire(BasicHS):
|
||||
class TriangularWeir(BasicHS):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None):
|
||||
super(SeuilTriangulaire, self).__init__(
|
||||
super(TriangularWeir, self).__init__(
|
||||
id=id, name=name,
|
||||
status=status
|
||||
)
|
||||
|
||||
self._type = "S3"
|
||||
self._data = [
|
||||
BHSValue("Cote", float, 1.0, status=status),
|
||||
BHSValue("Cote de mise en charge", float, 9999.999, status=status),
|
||||
BHSValue("Coefficient de debit", float, 0.4, status=status),
|
||||
BHSValue("Tangeante du demi angle", float, 0.0, status=status),
|
||||
BHSValue("elevation", float, 1.0, status=status),
|
||||
BHSValue("loading_elevation", float, 9999.999, status=status),
|
||||
BHSValue("discharge_coefficient", float, 0.4, status=status),
|
||||
BHSValue("half-angle_tangent", float, 0.0, status=status),
|
||||
]
|
||||
|
||||
|
||||
class OrificeRectangulaire(BasicHS):
|
||||
class RectangularOrifice(BasicHS):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None):
|
||||
super(OrificeRectangulaire, self).__init__(
|
||||
super(RectangularOrifice, self).__init__(
|
||||
id=id, name=name,
|
||||
status=status
|
||||
)
|
||||
|
||||
self._type = "OR"
|
||||
self._data = [
|
||||
BHSValue("Largeur", float, 0.0, status=status),
|
||||
BHSValue("Cote", float, 0.0, status=status),
|
||||
BHSValue("Cote de mise en charge", float, 9999.999,
|
||||
BHSValue("width", float, 0.0, status=status),
|
||||
BHSValue("elevation", float, 0.0, status=status),
|
||||
BHSValue("loading_elevation", float, 9999.999,
|
||||
status=status),
|
||||
BHSValue("Coefficient de debit", float, 0.4, status=status),
|
||||
BHSValue("Cote de mise en charge maximale", float, 9999.999,
|
||||
BHSValue("discharge_coefficient", float, 0.4, status=status),
|
||||
BHSValue("maximal_loading_elevation", float, 9999.999,
|
||||
status=status),
|
||||
]
|
||||
|
||||
|
||||
class OrificeCirculaire(BasicHS):
|
||||
class CircularOrifice(BasicHS):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None):
|
||||
super(OrificeCirculaire, self).__init__(
|
||||
super(CircularOrifice, self).__init__(
|
||||
id=id, name=name,
|
||||
status=status
|
||||
)
|
||||
|
||||
self._type = "OC"
|
||||
self._data = [
|
||||
BHSValue("Diametre", float, 0.0, status=status),
|
||||
BHSValue("Cote", float, 0.0, status=status),
|
||||
BHSValue("hauteur envasement", float, 0.0, status=status),
|
||||
BHSValue("Coefficient de debit", float, 0.4, status=status),
|
||||
BHSValue("diameter", float, 0.0, status=status),
|
||||
BHSValue("elevation", float, 0.0, status=status),
|
||||
BHSValue("siltation_height", float, 0.0, status=status),
|
||||
BHSValue("discharge_coefficient", float, 0.4, status=status),
|
||||
]
|
||||
|
||||
|
||||
# class OrificeVoute(BasicHS):
|
||||
# def __init__(self, id: int = -1, name: str = "",
|
||||
# status=None):
|
||||
# super(OrificeVoute, self).__init__(
|
||||
# id=id, name=name,
|
||||
# status=status
|
||||
# )
|
||||
|
||||
# self._type = "OV"
|
||||
# self._data = [
|
||||
# BHSValue("Cote", float, 1.0, status=status),
|
||||
# BHSValue("Largeur", float, 1.0, status=status),
|
||||
# BHSValue("Haut de la voute", float, 0.0, status=status),
|
||||
# BHSValue("Bas de la voute", float, 0.0, status=status),
|
||||
# BHSValue("Coefficient de debit", float, 0.4, status=status),
|
||||
# ]
|
||||
|
||||
|
||||
class VanneRectangulaire(BasicHS):
|
||||
class VaultedOrifice(BasicHS):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None):
|
||||
super(VanneRectangulaire, self).__init__(
|
||||
super(VaultedOrifice, self).__init__(
|
||||
id=id, name=name,
|
||||
status=status
|
||||
)
|
||||
|
||||
self._type = "OV"
|
||||
self._data = [
|
||||
BHSValue("elevation", float, 1.0, status=status),
|
||||
BHSValue("width", float, 1.0, status=status),
|
||||
BHSValue("top_of_the_vault", float, 0.0, status=status),
|
||||
BHSValue("bottom_of_the_vault", float, 0.0, status=status),
|
||||
BHSValue("discharge_coefficient", float, 0.4, status=status),
|
||||
]
|
||||
|
||||
|
||||
class RectangularGate(BasicHS):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None):
|
||||
super(RectangularGate, self).__init__(
|
||||
id=id, name=name,
|
||||
status=status
|
||||
)
|
||||
|
||||
self._type = "V1"
|
||||
self._data = [
|
||||
BHSValue("Largeur", float, 1.0, status=status),
|
||||
BHSValue("Cote", float, 0.0, status=status),
|
||||
BHSValue("Coefficient de debit", float, 0.4, status=status),
|
||||
BHSValue("Ouverture", float, 1.0, status=status),
|
||||
BHSValue("Ouverture maximale", float, 1.0, status=status),
|
||||
BHSValue("width", float, 1.0, status=status),
|
||||
BHSValue("elevation", float, 0.0, status=status),
|
||||
BHSValue("discharge coefficient", float, 0.4, status=status),
|
||||
BHSValue("opening", float, 1.0, status=status),
|
||||
BHSValue("maximal_opening", float, 1.0, status=status),
|
||||
]
|
||||
|
||||
|
||||
class VanneRectangulaireSimplifiee(BasicHS):
|
||||
class SimplifiedRectangularGate(BasicHS):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None):
|
||||
super(VanneRectangulaireSimplifiee, self).__init__(
|
||||
super(SimplifiedRectangularGate, self).__init__(
|
||||
id=id, name=name,
|
||||
status=status
|
||||
)
|
||||
|
||||
self._type = "V2"
|
||||
self._data = [
|
||||
BHSValue("Largeur", float, 1.0, status=status),
|
||||
BHSValue("Cote", float, 0.0, status=status),
|
||||
BHSValue("Coefficient de debit", float, 0.4, status=status),
|
||||
BHSValue("Ouverture", float, 1.0, status=status),
|
||||
BHSValue("Ouverture maximale", float, 1.0, status=status),
|
||||
BHSValue("width", float, 1.0, status=status),
|
||||
BHSValue("elevation", float, 0.0, status=status),
|
||||
BHSValue("discharge coefficient", float, 0.4, status=status),
|
||||
BHSValue("opening", float, 1.0, status=status),
|
||||
BHSValue("maximal_opening", float, 1.0, status=status),
|
||||
]
|
||||
|
||||
|
||||
@@ -189,9 +189,29 @@ class Borda(BasicHS):
|
||||
|
||||
self._type = "BO"
|
||||
self._data = [
|
||||
BHSValue("Pas espace", float, 0.1, status=status),
|
||||
BHSValue("Seuil", float, 0.15, status=status),
|
||||
BHSValue("Coefficient", float, 0.4, status=status),
|
||||
BHSValue("step_space", float, 0.1, status=status),
|
||||
BHSValue("weir", float, 0.15, status=status),
|
||||
BHSValue("coefficient", float, 0.4, status=status),
|
||||
]
|
||||
|
||||
|
||||
class CheckValve(BasicHS):
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None):
|
||||
super(CheckValve, self).__init__(
|
||||
id=id, name=name,
|
||||
status=status
|
||||
)
|
||||
|
||||
self._type = "CV"
|
||||
self._data = [
|
||||
BHSValue("width", float, 0.0, status=status),
|
||||
BHSValue("elevation", float, 0.0, status=status),
|
||||
BHSValue("loading_elevation", float, 9999.999,
|
||||
status=status),
|
||||
BHSValue("discharge_coefficient", float, 0.4, status=status),
|
||||
BHSValue("maximal_loading_elevation", float, 9999.999,
|
||||
status=status),
|
||||
]
|
||||
|
||||
|
||||
@@ -205,24 +225,25 @@ class UserDefined(BasicHS):
|
||||
|
||||
self._type = "UD"
|
||||
self._data = [
|
||||
BHSValue("Parameter 1", float, 0.0, status=status),
|
||||
BHSValue("Parameter 2", float, 0.0, status=status),
|
||||
BHSValue("Parameter 3", float, 0.0, status=status),
|
||||
BHSValue("Parameter 4", float, 0.0, status=status),
|
||||
BHSValue("Parameter 5", float, 0.0, status=status),
|
||||
BHSValue("parameter_1", float, 0.0, status=status),
|
||||
BHSValue("parameter_2", float, 0.0, status=status),
|
||||
BHSValue("parameter_3", float, 0.0, status=status),
|
||||
BHSValue("parameter_4", float, 0.0, status=status),
|
||||
BHSValue("parameter_5", float, 0.0, status=status),
|
||||
]
|
||||
|
||||
|
||||
BHS_types = {
|
||||
"ND": NotDefined,
|
||||
"S1": SeuilDeversoir,
|
||||
"S2": SeuilTrapezoidal,
|
||||
"S3": SeuilTriangulaire,
|
||||
"OR": OrificeRectangulaire,
|
||||
"OC": OrificeCirculaire,
|
||||
# "OV": OrificeVoute,
|
||||
"V1": VanneRectangulaire,
|
||||
"V2": VanneRectangulaireSimplifiee,
|
||||
"S1": DischargeWeir,
|
||||
"S2": TrapezoidalWeir,
|
||||
"S3": TriangularWeir,
|
||||
"OR": RectangularOrifice,
|
||||
"OC": CircularOrifice,
|
||||
# "OV": VaultedOrifice,
|
||||
"V1": RectangularGate,
|
||||
"V2": SimplifiedRectangularGate,
|
||||
"BO": Borda,
|
||||
"CV": CheckValve,
|
||||
"UD": UserDefined
|
||||
}
|
||||
@@ -200,6 +200,9 @@ class HydraulicStructure(SQLSubModel):
|
||||
|
||||
@input_kp.setter
|
||||
def input_kp(self, input_kp):
|
||||
if input_kp is not None:
|
||||
input_kp = float(input_kp)
|
||||
|
||||
self._input_kp = input_kp
|
||||
self._status.modified()
|
||||
|
||||
|
||||
@@ -48,10 +48,14 @@ class Graph(object):
|
||||
|
||||
def enable_edges(self):
|
||||
return list(
|
||||
filter(
|
||||
lambda e: e.is_enable(),
|
||||
self._edges
|
||||
)
|
||||
self._enable_edges()
|
||||
)
|
||||
|
||||
def _enable_edges(self):
|
||||
"""Return a generator"""
|
||||
return filter(
|
||||
lambda e: e.is_enable(),
|
||||
self._edges
|
||||
)
|
||||
|
||||
def edges_names(self):
|
||||
@@ -138,8 +142,20 @@ class Graph(object):
|
||||
self._nodes
|
||||
)
|
||||
)
|
||||
self._remove_associated_edge(node_name)
|
||||
self._status.modified()
|
||||
|
||||
def _remove_associated_edge(self, node_name: str):
|
||||
edges = list(
|
||||
filter(
|
||||
lambda e: (e.node1.name == node_name or
|
||||
e.node2.name == node_name),
|
||||
self._edges,
|
||||
)
|
||||
)
|
||||
for edge in edges:
|
||||
self.remove_edge(edge.name)
|
||||
|
||||
def create_node(self, x: float = 0.0, y: float = 0.0):
|
||||
node = self._create_node(x, y)
|
||||
return node
|
||||
@@ -186,14 +202,14 @@ class Graph(object):
|
||||
def is_upstream_node(self, node):
|
||||
return reduce(
|
||||
lambda acc, e: (acc and (e.node2 != node or not e.enable)),
|
||||
self._edges,
|
||||
self._enable_edges(),
|
||||
True
|
||||
)
|
||||
|
||||
def is_downstream_node(self, node):
|
||||
return reduce(
|
||||
lambda acc, e: (acc and (e.node1 != node or not e.enable)),
|
||||
self._edges,
|
||||
self._enable_edges(),
|
||||
True
|
||||
)
|
||||
|
||||
@@ -203,10 +219,9 @@ class Graph(object):
|
||||
acc or (
|
||||
(e.node1 == node or
|
||||
e.node2 == node)
|
||||
and e._enable
|
||||
)
|
||||
),
|
||||
self._edges,
|
||||
self._enable_edges(),
|
||||
False
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# __init__.py -- Pamhyr
|
||||
# Copyright (C) 2023 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 -*-
|
||||
@@ -0,0 +1,182 @@
|
||||
# test_Network.py -- Pamhyr
|
||||
# Copyright (C) 2023 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 unittest
|
||||
import tempfile
|
||||
|
||||
from Model.Saved import SavedStatus
|
||||
|
||||
from Model.Network.Graph import Graph
|
||||
from Model.Network.Edge import Edge
|
||||
from Model.Network.Node import Node
|
||||
|
||||
|
||||
def new_graph():
|
||||
status = SavedStatus()
|
||||
g = Graph(status=status)
|
||||
|
||||
return g
|
||||
|
||||
|
||||
class GraphTestCase(unittest.TestCase):
|
||||
def test_graph_0(self):
|
||||
g = new_graph()
|
||||
|
||||
self.assertEqual(g.nodes_counts(), 0)
|
||||
self.assertEqual(g.edges_counts(), 0)
|
||||
|
||||
def test_graph_1(self):
|
||||
g = new_graph()
|
||||
|
||||
n0 = g.add_node()
|
||||
n1 = g.add_node()
|
||||
|
||||
e0 = g.add_edge(n0, n1)
|
||||
|
||||
self.assertEqual(g.nodes_counts(), 2)
|
||||
self.assertEqual(g.edges_counts(), 1)
|
||||
|
||||
def test_graph_2(self):
|
||||
g = new_graph()
|
||||
|
||||
n0 = g.add_node()
|
||||
n1 = g.add_node()
|
||||
|
||||
e0 = g.add_edge(n0, n1)
|
||||
|
||||
g.remove_edge(e0.name)
|
||||
|
||||
self.assertEqual(g.nodes_counts(), 2)
|
||||
self.assertEqual(g.edges_counts(), 0)
|
||||
|
||||
def test_graph_3(self):
|
||||
g = new_graph()
|
||||
|
||||
n0 = g.add_node()
|
||||
n1 = g.add_node()
|
||||
|
||||
e0 = g.add_edge(n0, n1)
|
||||
|
||||
g.remove_node(n0.name)
|
||||
|
||||
self.assertEqual(g.nodes_counts(), 1)
|
||||
self.assertEqual(g.edges_counts(), 0)
|
||||
|
||||
def test_graph_4(self):
|
||||
g = new_graph()
|
||||
|
||||
n0 = g.add_node()
|
||||
n1 = g.add_node()
|
||||
n2 = g.add_node()
|
||||
|
||||
e0 = g.add_edge(n0, n1)
|
||||
e1 = g.add_edge(n1, n2)
|
||||
|
||||
g.remove_node(n1.name)
|
||||
|
||||
self.assertEqual(g.nodes_counts(), 2)
|
||||
self.assertEqual(g.edges_counts(), 0)
|
||||
|
||||
def test_graph_upstream_0(self):
|
||||
g = new_graph()
|
||||
|
||||
n0 = g.add_node()
|
||||
n1 = g.add_node()
|
||||
n2 = g.add_node()
|
||||
|
||||
e0 = g.add_edge(n0, n1)
|
||||
e1 = g.add_edge(n1, n2)
|
||||
|
||||
self.assertEqual(g.is_upstream_node(n0), True)
|
||||
self.assertEqual(g.is_upstream_node(n1), False)
|
||||
self.assertEqual(g.is_upstream_node(n2), False)
|
||||
|
||||
def test_graph_upstream_1(self):
|
||||
g = new_graph()
|
||||
|
||||
n0 = g.add_node()
|
||||
n1 = g.add_node()
|
||||
n2 = g.add_node()
|
||||
|
||||
e0 = g.add_edge(n0, n1)
|
||||
e1 = g.add_edge(n2, n1)
|
||||
|
||||
self.assertEqual(g.is_upstream_node(n0), True)
|
||||
self.assertEqual(g.is_upstream_node(n1), False)
|
||||
self.assertEqual(g.is_upstream_node(n2), True)
|
||||
|
||||
def test_graph_upstream_disable(self):
|
||||
g = new_graph()
|
||||
|
||||
n0 = g.add_node()
|
||||
n1 = g.add_node()
|
||||
n2 = g.add_node()
|
||||
|
||||
e0 = g.add_edge(n0, n1)
|
||||
e1 = g.add_edge(n1, n2)
|
||||
|
||||
e0.disable()
|
||||
|
||||
# self.assertEqual(g.is_upstream_node(n0), False)
|
||||
self.assertEqual(g.is_upstream_node(n1), True)
|
||||
self.assertEqual(g.is_upstream_node(n2), False)
|
||||
|
||||
def test_graph_downstream_0(self):
|
||||
g = new_graph()
|
||||
|
||||
n0 = g.add_node()
|
||||
n1 = g.add_node()
|
||||
n2 = g.add_node()
|
||||
|
||||
e0 = g.add_edge(n0, n1)
|
||||
e1 = g.add_edge(n1, n2)
|
||||
|
||||
self.assertEqual(g.is_downstream_node(n0), False)
|
||||
self.assertEqual(g.is_downstream_node(n1), False)
|
||||
self.assertEqual(g.is_downstream_node(n2), True)
|
||||
|
||||
def test_graph_downstream_1(self):
|
||||
g = new_graph()
|
||||
|
||||
n0 = g.add_node()
|
||||
n1 = g.add_node()
|
||||
n2 = g.add_node()
|
||||
|
||||
e0 = g.add_edge(n0, n1)
|
||||
e1 = g.add_edge(n2, n1)
|
||||
|
||||
self.assertEqual(g.is_downstream_node(n0), False)
|
||||
self.assertEqual(g.is_downstream_node(n1), True)
|
||||
self.assertEqual(g.is_downstream_node(n2), False)
|
||||
|
||||
def test_graph_downstream_disable(self):
|
||||
g = new_graph()
|
||||
|
||||
n0 = g.add_node()
|
||||
n1 = g.add_node()
|
||||
n2 = g.add_node()
|
||||
|
||||
e0 = g.add_edge(n0, n1)
|
||||
e1 = g.add_edge(n1, n2)
|
||||
|
||||
e1.disable()
|
||||
|
||||
self.assertEqual(g.is_downstream_node(n0), False)
|
||||
self.assertEqual(g.is_downstream_node(n1), True)
|
||||
# self.assertEqual(g.is_downstream_node(n2), False)
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from tools import flatten
|
||||
from tools import flatten, logger_exception
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
|
||||
@@ -326,6 +326,8 @@ class River(Graph, SQLSubModel):
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
self._db_save_delete_artefact(execute, data)
|
||||
|
||||
objs = (self._nodes + self._edges)
|
||||
objs.append(self._boundary_condition)
|
||||
objs.append(self._initial_conditions)
|
||||
@@ -341,6 +343,35 @@ class River(Graph, SQLSubModel):
|
||||
self._save_submodel(execute, objs, data)
|
||||
return True
|
||||
|
||||
def _db_save_delete_artefact(self, execute, data=None):
|
||||
self._db_save_delete_artefact_where_not_id(
|
||||
execute, data,
|
||||
"river_node", self._nodes
|
||||
)
|
||||
self._db_save_delete_artefact_where_not_id(
|
||||
execute, data,
|
||||
"river_reach", self._edges
|
||||
|
||||
)
|
||||
|
||||
def _db_save_delete_artefact_where_not_id(self, execute, data,
|
||||
table: str, els: list):
|
||||
if len(els) == 0:
|
||||
return
|
||||
|
||||
try:
|
||||
execute(
|
||||
f"DELETE FROM {table} " +
|
||||
"WHERE " +
|
||||
" OR ".join(
|
||||
map(
|
||||
lambda n: f"( id <> {n.id} )", els
|
||||
)
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
logger_exception(e)
|
||||
|
||||
@property
|
||||
def boundary_condition(self):
|
||||
return self._boundary_condition
|
||||
|
||||
@@ -225,7 +225,8 @@ class Study(SQLModel):
|
||||
|
||||
if self._update_submodel(version[0]):
|
||||
self.execute(
|
||||
f"UPDATE info SET value='{self._version}' WHERE key='version'")
|
||||
f"UPDATE info SET value='{self._version}' WHERE key='version'"
|
||||
)
|
||||
return True
|
||||
|
||||
logger.info("TODO: update failed")
|
||||
|
||||
@@ -135,6 +135,10 @@ def init_c_output_bief(bief_lib):
|
||||
c_output_bief.argtypes = [c_char_p]
|
||||
c_output_bief.restype = None
|
||||
|
||||
#####################
|
||||
# Binding functions #
|
||||
#####################
|
||||
|
||||
|
||||
def init_bief_from_geo_file(name, with_charriage, with_water):
|
||||
logger.info("! call init_bief_from_geo_file:")
|
||||
@@ -145,10 +149,6 @@ def init_bief_from_geo_file(name, with_charriage, with_water):
|
||||
byref(c_int(with_water))
|
||||
)
|
||||
|
||||
#####################
|
||||
# Binding functions #
|
||||
#####################
|
||||
|
||||
|
||||
def get_nb_sections():
|
||||
nb_sections = c_int(0)
|
||||
@@ -266,7 +266,7 @@ class MageMesh(AScript):
|
||||
)
|
||||
|
||||
# Transform
|
||||
st_to_m_compl(npts_max, 'rg', 'rd')
|
||||
st_to_m_compl(0, ' ', ' ')
|
||||
interpolate_profils_pas_transversal(
|
||||
1, ns,
|
||||
'un', 'np',
|
||||
@@ -275,6 +275,9 @@ class MageMesh(AScript):
|
||||
update_pk("un")
|
||||
|
||||
# Save
|
||||
if os.path.isfile(f"{file_name}.M"):
|
||||
os.remove(f"{file_name}.M")
|
||||
|
||||
logger.info(f"Saved meshing geometry to {file_name}.M")
|
||||
output_bief(f"{file_name}.M")
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ class CommandLineSolver(AbstractSolver):
|
||||
"""
|
||||
cmd = cmd.replace("@install_dir", self._install_dir())
|
||||
cmd = cmd.replace("@path", "\"" + path + "\"")
|
||||
cmd = cmd.replace("@input", self.input_param())
|
||||
cmd = cmd.replace("@input", self.input_param().replace(" ", "_"))
|
||||
cmd = cmd.replace("@output", self.output_param())
|
||||
cmd = cmd.replace("@dir", self._process.workingDirectory())
|
||||
cmd = cmd.replace("@args", " ".join(self.cmd_args(study)))
|
||||
|
||||
@@ -23,7 +23,9 @@ import numpy as np
|
||||
from tools import timer, trace
|
||||
|
||||
from Solver.CommandLine import CommandLineSolver
|
||||
from Checker.Mage import MageNetworkGraphChecker
|
||||
from Checker.Mage import (
|
||||
MageNetworkGraphChecker, MageGeometryGuideLineChecker,
|
||||
)
|
||||
|
||||
from Model.Results.Results import Results
|
||||
from Model.Results.River.River import River, Reach, Profile
|
||||
@@ -36,7 +38,14 @@ def mage_file_open(filepath, mode):
|
||||
|
||||
if "w" in mode:
|
||||
# Write header
|
||||
f.write("* This file is generated by PAMHYR, please don't modify\n")
|
||||
comment = "*"
|
||||
if ".ST" in filepath:
|
||||
comment = "#"
|
||||
|
||||
f.write(
|
||||
f"{comment} " +
|
||||
"This file is generated by PAMHYR, please don't modify\n"
|
||||
)
|
||||
|
||||
return f
|
||||
|
||||
@@ -90,7 +99,9 @@ class Mage(CommandLineSolver):
|
||||
def checkers(cls):
|
||||
lst = [
|
||||
MageNetworkGraphChecker(connectivity=True),
|
||||
MageNetworkGraphChecker(connectivity=False)
|
||||
MageNetworkGraphChecker(connectivity=False),
|
||||
MageGeometryGuideLineChecker(),
|
||||
|
||||
]
|
||||
|
||||
return lst
|
||||
@@ -240,6 +251,9 @@ class Mage(CommandLineSolver):
|
||||
files.append(f"{name}.{t}")
|
||||
|
||||
for bound in bounds:
|
||||
if bound.node is None:
|
||||
continue
|
||||
|
||||
name = f"{bound.node.id:3}".replace(" ", "x")
|
||||
f.write(f"* {bound.node.name} ({name}) {bound.bctype}\n")
|
||||
f.write(f"${name}\n")
|
||||
@@ -347,6 +361,9 @@ class Mage(CommandLineSolver):
|
||||
frictions = edge.frictions
|
||||
|
||||
for friction in frictions.frictions:
|
||||
if friction.begin_strickler is None:
|
||||
continue
|
||||
|
||||
num = f"{id:>3}"
|
||||
bkp = f"{friction.begin_kp:>10.3f}"
|
||||
ekp = f"{friction.end_kp:>10.3f}"
|
||||
@@ -422,6 +439,9 @@ class Mage(CommandLineSolver):
|
||||
files.append(f"{name}.CAS")
|
||||
|
||||
for reservoir in reservoirs:
|
||||
if reservoir.node is None:
|
||||
continue
|
||||
|
||||
reservoir.sort()
|
||||
node = reservoir.node
|
||||
name = f"{node.id:3}".replace(" ", "x")
|
||||
@@ -445,6 +465,7 @@ class Mage(CommandLineSolver):
|
||||
"ND": "*",
|
||||
"S1": "D", "S2": "T", "S3": "T",
|
||||
"OR": "O", "OC": "B", "OV": "F",
|
||||
"CV": "O", # CheckValve
|
||||
"V1": "V", "V2": "W",
|
||||
"BO": "A",
|
||||
"UD": "X",
|
||||
@@ -462,12 +483,15 @@ class Mage(CommandLineSolver):
|
||||
files.append(f"{name}.SIN")
|
||||
|
||||
for hs in hydraulic_structures:
|
||||
if hs.input_reach is None:
|
||||
continue
|
||||
|
||||
if not hs.input_reach.is_enable():
|
||||
continue
|
||||
|
||||
f.write(
|
||||
'* ouvrage au pk ' +
|
||||
f"{hs.input_kp:>12.1f}" + ' ' +
|
||||
f"{float(hs.input_kp):>12.1f}" + ' ' +
|
||||
hs.name + '\n'
|
||||
)
|
||||
|
||||
@@ -480,10 +504,16 @@ class Mage(CommandLineSolver):
|
||||
]
|
||||
)
|
||||
|
||||
name = bhs.name
|
||||
if name == "":
|
||||
name = f"HS_{bhs.id:>3}".replace(" ", "0")
|
||||
else:
|
||||
name = name.replace(" ", "_")
|
||||
|
||||
f.write(
|
||||
f"{sin_dict[bhs._type]} " +
|
||||
f"{reach_id} {hs.input_kp:>12.3f} {param_str} " +
|
||||
f"{bhs.name}\n"
|
||||
f"{reach_id} {float(hs.input_kp):>12.3f} " +
|
||||
f"{param_str} {name}\n"
|
||||
)
|
||||
|
||||
return files
|
||||
@@ -501,7 +531,7 @@ class Mage(CommandLineSolver):
|
||||
return res
|
||||
|
||||
def _export_SIN_parameters_5(self, bhs):
|
||||
# S2, OR, V1, V2, UD
|
||||
# S2, OR, V1, V2, UD, CV
|
||||
return [
|
||||
bhs._data[0].value,
|
||||
bhs._data[1].value,
|
||||
@@ -546,6 +576,42 @@ class Mage(CommandLineSolver):
|
||||
|
||||
return res
|
||||
|
||||
@timer
|
||||
def _export_VAR(self, study, repertory, qlog, name="0"):
|
||||
files = []
|
||||
|
||||
hydraulic_structures = study.river.hydraulic_structures.lst
|
||||
if len(hydraulic_structures) == 0:
|
||||
return files
|
||||
|
||||
if qlog is not None:
|
||||
qlog.put("Export VAR file")
|
||||
|
||||
with mage_file_open(os.path.join(repertory, f"{name}.VAR"), "w+") as f:
|
||||
files.append(f"{name}.VAR")
|
||||
|
||||
for hs in hydraulic_structures:
|
||||
if hs.input_reach is None:
|
||||
continue
|
||||
|
||||
if not hs.input_reach.is_enable():
|
||||
continue
|
||||
|
||||
for bhs in hs.basic_structures:
|
||||
logger.info(bhs._type)
|
||||
if bhs._type != "CV":
|
||||
continue
|
||||
|
||||
name = bhs.name
|
||||
if name == "":
|
||||
name = f"HS_{bhs.id:>3}".replace(" ", "0")
|
||||
|
||||
f.write(
|
||||
f"${name} clapet"
|
||||
)
|
||||
|
||||
return files
|
||||
|
||||
@timer
|
||||
def _export_DEV(self, study, repertory, qlog, name="0"):
|
||||
files = []
|
||||
@@ -819,6 +885,7 @@ class Mage8(Mage):
|
||||
files = files + self._export_RUG(study, repertory, qlog, name=name)
|
||||
files = files + self._export_INI(study, repertory, qlog, name=name)
|
||||
files = files + self._export_SIN(study, repertory, qlog, name=name)
|
||||
files = files + self._export_VAR(study, repertory, qlog, name=name)
|
||||
files = files + self._export_CAS(study, repertory, qlog, name=name)
|
||||
files = files + self._export_DEV(study, repertory, qlog, name=name)
|
||||
self._export_REP(study, repertory, files, qlog, name=name)
|
||||
@@ -951,10 +1018,8 @@ class Mage8(Mage):
|
||||
# Set data for profile RI
|
||||
reach.set(ri, timestamp, key, d)
|
||||
if key == "Z":
|
||||
profile = study.river\
|
||||
.current_reach()\
|
||||
.reach.profile(ri)
|
||||
ptX, ptY = profile.get_water_limits(d)
|
||||
profile = reach.profile(ri)
|
||||
ptX, ptY = profile.geometry.get_water_limits(d)
|
||||
reach.set(ri, timestamp, "ptX", ptX)
|
||||
reach.set(ri, timestamp, "ptY", ptY)
|
||||
|
||||
@@ -1135,9 +1200,10 @@ class Mage8(Mage):
|
||||
logger.info(f"read_gra: ... end with {len(ts)} timestamp read")
|
||||
|
||||
@timer
|
||||
def results(self, study, repertory, qlog=None):
|
||||
def results(self, study, repertory, qlog=None, name=None):
|
||||
self._study = study
|
||||
name = study.name.replace(" ", "_")
|
||||
if name is None:
|
||||
name = study.name.replace(" ", "_")
|
||||
|
||||
results = super(Mage8, self).results(study, repertory, qlog, name=name)
|
||||
self.read_gra(study, repertory, results, qlog, name=name)
|
||||
|
||||
@@ -119,9 +119,9 @@ class ConfigureWindow(PamhyrDialog):
|
||||
)
|
||||
|
||||
def setup_data(self):
|
||||
# Meshing_Tool
|
||||
self.set_line_edit_text("lineEdit_meshing_tool",
|
||||
self._config.meshing_tool)
|
||||
# # Meshing_Tool
|
||||
# self.set_line_edit_text("lineEdit_meshing_tool",
|
||||
# self._config.meshing_tool)
|
||||
|
||||
# Const
|
||||
self.set_line_edit_text("lineEdit_segment", str(self._config.segment))
|
||||
@@ -168,12 +168,12 @@ class ConfigureWindow(PamhyrDialog):
|
||||
"lineEdit_backup_path", f[0]
|
||||
)
|
||||
),
|
||||
"pushButton_meshing_tool": lambda: self.file_dialog(
|
||||
select_file=True,
|
||||
callback=lambda f: self.set_line_edit_text(
|
||||
"lineEdit_meshing_tool", f[0]
|
||||
)
|
||||
),
|
||||
# "pushButton_meshing_tool": lambda: self.file_dialog(
|
||||
# select_file=True,
|
||||
# callback=lambda f: self.set_line_edit_text(
|
||||
# "lineEdit_meshing_tool", f[0]
|
||||
# )
|
||||
# ),
|
||||
}
|
||||
|
||||
for button in buttons:
|
||||
@@ -183,9 +183,9 @@ class ConfigureWindow(PamhyrDialog):
|
||||
# Solvers
|
||||
self._config.solvers = self.solver_table_model._data.copy()
|
||||
|
||||
# Meshing_Tool
|
||||
self._config.meshing_tool = self.get_line_edit_text(
|
||||
"lineEdit_meshing_tool")
|
||||
# # Meshing_Tool
|
||||
# self._config.meshing_tool = self.get_line_edit_text(
|
||||
# "lineEdit_meshing_tool")
|
||||
|
||||
# Const
|
||||
self._config.segment = self.get_line_edit_text("lineEdit_segment")
|
||||
|
||||
@@ -63,13 +63,19 @@ class PlotAC(PamhyrPlot):
|
||||
if self.data.number_profiles == 0:
|
||||
return
|
||||
|
||||
np = len(self.data.profiles)
|
||||
if np < 2:
|
||||
return
|
||||
|
||||
selected_profile = 0
|
||||
|
||||
station = self.data.profile(selected_profile).get_station()
|
||||
station_plus_1 = self.data.profile(selected_profile + 1).get_station()
|
||||
elevation = self.data.profile(selected_profile).z()
|
||||
elevation_i_plus_1 = self.data.profile(selected_profile + 1).z()
|
||||
gl = self.data.profile(selected_profile).names()
|
||||
|
||||
station_plus_1 = self.data.profile(selected_profile + 1).get_station()
|
||||
elevation_i_plus_1 = self.data.profile(selected_profile + 1).z()
|
||||
|
||||
self.canvas.axes.set_xlabel(
|
||||
_translate("MainWindow_reach", "Transverse abscissa (m)"),
|
||||
color='black', fontsize=10
|
||||
@@ -108,7 +114,7 @@ class PlotAC(PamhyrPlot):
|
||||
lcomplete = list(self.complete_gl)
|
||||
lincomplete = list(self.incomplete_gl)
|
||||
|
||||
line_2d = [line_2D for line_2D in self.plot_xy.line_gl]
|
||||
line_2d = self.plot_xy.line_gl
|
||||
self.color_complete_gl = self.get_line_gl_colors(line_2d)
|
||||
self.color_incomplete_gl = 2 * ["#000000"]
|
||||
|
||||
@@ -185,11 +191,11 @@ class PlotAC(PamhyrPlot):
|
||||
self.canvas.figure.tight_layout()
|
||||
|
||||
label_before_plot_selected = _translate(
|
||||
"MainWindow_reach", "Profil précédent")
|
||||
"MainWindow_reach", "Previous cross-section")
|
||||
label_plot_selected = _translate(
|
||||
"MainWindow_reach", "Profil sélectionné")
|
||||
"MainWindow_reach", "Cross-section")
|
||||
label_after_plot_selected = _translate(
|
||||
"MainWindow_reach", "Profil suivant")
|
||||
"MainWindow_reach", "Next cross-section")
|
||||
color_before_plot_selected = "k" # 'grey'
|
||||
color_plot_selected = 'b'
|
||||
color_after_plot_selected = 'm'
|
||||
@@ -213,7 +219,7 @@ class PlotAC(PamhyrPlot):
|
||||
lcomplete = list(self.complete_gl)
|
||||
lincomplete = list(self.incomplete_gl)
|
||||
|
||||
line_2d = [line_2D for line_2D in self.plot_xy.line_gl]
|
||||
line_2d = self.plot_xy.line_gl
|
||||
self.color_complete_gl = self.get_line_gl_colors(line_2d)
|
||||
self.color_incomplete_gl = 2 * ["#000000"]
|
||||
|
||||
@@ -242,12 +248,15 @@ class PlotAC(PamhyrPlot):
|
||||
x_gl_complete.append(station[i])
|
||||
y_gl_complete.append(elevation[i])
|
||||
color_scat_complete_gl.append(
|
||||
self.color_complete_gl[lcomplete.index(txt)])
|
||||
self.color_complete_gl[lcomplete.index(txt)]
|
||||
)
|
||||
elif txt.strip() in self.incomplete_gl:
|
||||
annotate = self.canvas.axes.annotate(
|
||||
txt, (station[i], elevation[i]
|
||||
), horizontalalignment='left',
|
||||
verticalalignment='top', annotation_clip=True, fontsize=11,
|
||||
txt,
|
||||
(station[i], elevation[i]),
|
||||
horizontalalignment='left',
|
||||
verticalalignment='top',
|
||||
annotation_clip=True, fontsize=11,
|
||||
color=self.color_incomplete_gl[
|
||||
lincomplete.index(txt)
|
||||
],
|
||||
@@ -327,6 +336,10 @@ class PlotAC(PamhyrPlot):
|
||||
self.draw()
|
||||
return
|
||||
|
||||
line_2d = self.plot_xy.line_gl
|
||||
self.color_complete_gl = self.get_line_gl_colors(line_2d)
|
||||
self.color_incomplete_gl = 2 * ["#000000"]
|
||||
|
||||
if ind is not None:
|
||||
before = ind - 1
|
||||
after = ind + 1
|
||||
|
||||
@@ -59,7 +59,18 @@ class PlotKPZ(PamhyrPlot):
|
||||
if self.data is None:
|
||||
return
|
||||
|
||||
if self.data.number_profiles == 0:
|
||||
if len(self.data.profiles) == 0:
|
||||
return
|
||||
|
||||
profiles_defined = any(
|
||||
filter(
|
||||
lambda profile: len(profile) > 0,
|
||||
self.data.profiles
|
||||
)
|
||||
)
|
||||
|
||||
if not profiles_defined:
|
||||
self._init = False
|
||||
return
|
||||
|
||||
self.canvas.axes.set_xlabel(
|
||||
@@ -71,13 +82,13 @@ class PlotKPZ(PamhyrPlot):
|
||||
color='black', fontsize=10
|
||||
)
|
||||
|
||||
kp = self.data.get_kp()
|
||||
kp = self.data.get_kp_complete_profiles()
|
||||
z_min = self.data.get_z_min()
|
||||
z_max = self.data.get_z_max()
|
||||
|
||||
self.canvas.axes.set_xlim(
|
||||
left=min(kp), right=max(kp)
|
||||
)
|
||||
# self.canvas.axes.set_xlim(
|
||||
# left=min(kp), right=max(kp)
|
||||
# )
|
||||
|
||||
self.line_kp_zmin_zmax = self.canvas.axes.vlines(
|
||||
x=kp,
|
||||
@@ -142,7 +153,7 @@ class PlotKPZ(PamhyrPlot):
|
||||
)
|
||||
self.after_plot_selected.set_visible(False)
|
||||
|
||||
kp = self.data.get_kp()
|
||||
kp = self.data.get_kp_complete_profiles()
|
||||
self.line_kp_zgl = []
|
||||
for z in self.data.get_guidelines_z():
|
||||
# Is incomplete guideline?
|
||||
@@ -183,41 +194,47 @@ class PlotKPZ(PamhyrPlot):
|
||||
self.after_plot_selected.set_visible(False)
|
||||
|
||||
if 0 <= before < self.data.number_profiles:
|
||||
kp_i = self.data.profile(before).kp
|
||||
z_min_i = self.data.profile(before).z_min()
|
||||
z_max_i = self.data.profile(before).z_max()
|
||||
profile = self.data.profile(before)
|
||||
if len(profile) > 0:
|
||||
kp_i = profile.kp
|
||||
z_min_i = profile.z_min()
|
||||
z_max_i = profile.z_max()
|
||||
|
||||
self.before_plot_selected.set_data(
|
||||
(kp_i, kp_i),
|
||||
(z_min_i, z_max_i)
|
||||
)
|
||||
self.before_plot_selected.set_visible(True)
|
||||
self.before_plot_selected.set_data(
|
||||
(kp_i, kp_i),
|
||||
(z_min_i, z_max_i)
|
||||
)
|
||||
self.before_plot_selected.set_visible(True)
|
||||
|
||||
if 0 <= ind < self.data.number_profiles:
|
||||
kp_i = self.data.profile(ind).kp
|
||||
z_min_i = self.data.profile(ind).z_min()
|
||||
z_max_i = self.data.profile(ind).z_max()
|
||||
profile = self.data.profile(ind)
|
||||
if len(profile) > 0:
|
||||
kp_i = profile.kp
|
||||
z_min_i = profile.z_min()
|
||||
z_max_i = profile.z_max()
|
||||
|
||||
self.plot_selected.set_data(
|
||||
(kp_i, kp_i),
|
||||
(z_min_i, z_max_i)
|
||||
)
|
||||
self.plot_selected.set_visible(True)
|
||||
self.plot_selected.set_data(
|
||||
(kp_i, kp_i),
|
||||
(z_min_i, z_max_i)
|
||||
)
|
||||
self.plot_selected.set_visible(True)
|
||||
|
||||
if 0 <= after < self.data.number_profiles:
|
||||
kp_i = self.data.profile(after).kp
|
||||
z_min_i = self.data.profile(after).z_min()
|
||||
z_max_i = self.data.profile(after).z_max()
|
||||
profile = self.data.profile(after)
|
||||
if len(profile) > 0:
|
||||
kp_i = profile.kp
|
||||
z_min_i = profile.z_min()
|
||||
z_max_i = profile.z_max()
|
||||
|
||||
self.after_plot_selected.set_data(
|
||||
(kp_i, kp_i),
|
||||
(z_min_i, z_max_i)
|
||||
)
|
||||
self.after_plot_selected.set_visible(True)
|
||||
self.after_plot_selected.set_data(
|
||||
(kp_i, kp_i),
|
||||
(z_min_i, z_max_i)
|
||||
)
|
||||
self.after_plot_selected.set_visible(True)
|
||||
|
||||
self.canvas.figure.canvas.draw_idle()
|
||||
else:
|
||||
kp = self.data.get_kp()
|
||||
kp = self.data.get_kp_complete_profiles()
|
||||
z_min = self.data.get_z_min()
|
||||
z_max = self.data.get_z_max()
|
||||
|
||||
@@ -239,5 +256,5 @@ class PlotKPZ(PamhyrPlot):
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to update graphic KPZ: {e}")
|
||||
|
||||
self.canvas.axes.autoscale_view(True, True, True)
|
||||
self.canvas.figure.canvas.draw_idle()
|
||||
self.canvas.axes.autoscale_view(True, True, True)
|
||||
self.canvas.figure.canvas.draw_idle()
|
||||
@@ -73,10 +73,10 @@ class PlotXY(PamhyrPlot):
|
||||
)
|
||||
self.canvas.axes.axis("equal")
|
||||
|
||||
kp = self.data.get_kp()
|
||||
self.canvas.axes.set_xlim(
|
||||
left=min(kp), right=max(kp)
|
||||
)
|
||||
kp = self.data.get_kp_complete_profiles()
|
||||
# self.canvas.axes.set_xlim(
|
||||
# left=min(kp), right=max(kp)
|
||||
# )
|
||||
|
||||
# Draw line for each profile
|
||||
self.line_xy = [
|
||||
@@ -149,8 +149,15 @@ class PlotXY(PamhyrPlot):
|
||||
return
|
||||
|
||||
self.data.compute_guidelines()
|
||||
x_complete = self.data.get_guidelines_x()
|
||||
y_complete = self.data.get_guidelines_y()
|
||||
x_complete = list(self.data.get_guidelines_x())
|
||||
y_complete = list(self.data.get_guidelines_y())
|
||||
|
||||
# self.line_gl = [
|
||||
# self.canvas.axes.plot(
|
||||
# x, y,
|
||||
# )
|
||||
# for x, y in zip(x_complete, y_complete)
|
||||
# ]
|
||||
|
||||
for i in range(self.data.number_profiles):
|
||||
if i < len(self.line_xy):
|
||||
|
||||
@@ -235,8 +235,8 @@ class ProfileWindow(PamhyrWindow):
|
||||
|
||||
if len(header) != 0:
|
||||
header.append("profile")
|
||||
for row in data:
|
||||
row.append(self._profile)
|
||||
# for row in data:
|
||||
# row.append(self._profile)
|
||||
|
||||
row = self.index_selected_row()
|
||||
self._tablemodel.paste(row, header, data)
|
||||
|
||||
@@ -59,7 +59,7 @@ class GeometryReachTableModel(PamhyrTableModel):
|
||||
return f"{kp:.4f}"
|
||||
|
||||
if role == Qt.DisplayRole and index.column() == 2:
|
||||
return self._data.profile(index.row()).profile_type
|
||||
return str(self._data.profile(index.row()).nb_points)
|
||||
|
||||
if role == Qt.TextAlignmentRole:
|
||||
return Qt.AlignHCenter | Qt.AlignVCenter
|
||||
@@ -185,6 +185,19 @@ class GeometryReachTableModel(PamhyrTableModel):
|
||||
self.endMoveRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def import_geometry(self, row, filename):
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
self._undo.push(
|
||||
ImportCommand(
|
||||
self._data, row,
|
||||
filename
|
||||
)
|
||||
)
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def duplicate(self, rows, profiles):
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
@@ -221,3 +234,15 @@ class GeometryReachTableModel(PamhyrTableModel):
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def meshing(self, mesher, step):
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
self._undo.push(
|
||||
MeshingCommand(
|
||||
self._data, mesher, step
|
||||
)
|
||||
)
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
self.layoutChanged.emit()
|
||||
@@ -45,4 +45,5 @@ class GeometryTranslate(PamhyrTranslate):
|
||||
self._sub_dict["table_headers"] = {
|
||||
"name": _translate("Geometry", "Name"),
|
||||
"kp": _translate("Geometry", "KP"),
|
||||
"poins": _translate("Geometry", "Points"),
|
||||
}
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from copy import deepcopy
|
||||
from tools import trace, timer
|
||||
|
||||
@@ -25,6 +27,10 @@ from PyQt5.QtWidgets import (
|
||||
|
||||
from Model.Geometry import Reach
|
||||
|
||||
from Meshing.Mage import MeshingWithMage
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class SetDataCommand(QUndoCommand):
|
||||
def __init__(self, reach, index, old_value, new_value):
|
||||
@@ -187,3 +193,56 @@ class DuplicateCommand(QUndoCommand):
|
||||
def redo(self):
|
||||
for profile in self._profiles:
|
||||
self._reach.insert_profile(self._rows[0], profile)
|
||||
|
||||
|
||||
class ImportCommand(QUndoCommand):
|
||||
def __init__(self, reach, row, filename):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._reach = reach
|
||||
self._row = row
|
||||
self._filename = filename
|
||||
self._profiles = None
|
||||
|
||||
def undo(self):
|
||||
self._reach.delete_profiles(self._profiles)
|
||||
|
||||
def redo(self):
|
||||
if self._profiles is None:
|
||||
self._profiles = self._reach.import_geometry(self._filename)
|
||||
self._profiles.reverse()
|
||||
else:
|
||||
for profile in self._profiles:
|
||||
self._reach.insert_profile(self._row, profile)
|
||||
|
||||
|
||||
class MeshingCommand(QUndoCommand):
|
||||
def __init__(self, reach, mesher, step):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._reach = reach
|
||||
self._step = step
|
||||
self._mesher = mesher
|
||||
|
||||
self._profiles = reach.profiles.copy()
|
||||
self._profiles.reverse()
|
||||
|
||||
self._new_profiles = None
|
||||
|
||||
def undo(self):
|
||||
self._reach.purge()
|
||||
|
||||
for profile in self._profiles:
|
||||
self._reach.insert_profile(0, profile)
|
||||
|
||||
def redo(self):
|
||||
if self._new_profiles is None:
|
||||
self._mesher.meshing(self._reach)
|
||||
|
||||
self._new_profiles = self._reach.profiles.copy()
|
||||
self._new_profiles.reverse()
|
||||
else:
|
||||
self._reach.purge()
|
||||
|
||||
for profile in self._new_profiles:
|
||||
self._reach.insert_profile(0, profile)
|
||||
@@ -17,12 +17,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
import time
|
||||
import pathlib
|
||||
import logging
|
||||
|
||||
from copy import deepcopy
|
||||
from tools import timer, trace
|
||||
from tools import timer, trace, logger_exception
|
||||
|
||||
from PyQt5 import QtWidgets
|
||||
from PyQt5.QtGui import (
|
||||
@@ -39,10 +40,16 @@ from PyQt5.QtWidgets import (
|
||||
QLabel, QAbstractItemView,
|
||||
)
|
||||
|
||||
from Model.Except import ExternFileMissingError
|
||||
|
||||
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
|
||||
from View.Tools.Plot.PamhyrCanvas import MplCanvas
|
||||
|
||||
from Meshing.Mage import (
|
||||
MeshingWithMage, MeshingWithMageMailleurTT
|
||||
)
|
||||
|
||||
from View.Geometry.Table import GeometryReachTableModel
|
||||
from View.Geometry.PlotXY import PlotXY
|
||||
from View.Geometry.PlotAC import PlotAC
|
||||
@@ -52,6 +59,8 @@ from View.Geometry.Profile.Window import ProfileWindow
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class GeometryWindow(PamhyrWindow):
|
||||
_pamhyr_ui = "GeometryReach"
|
||||
@@ -76,7 +85,7 @@ class GeometryWindow(PamhyrWindow):
|
||||
# Add reach to hash computation data
|
||||
self._hash_data.append(self._reach)
|
||||
|
||||
self._tablemodel = None
|
||||
self._table = None
|
||||
self._profile_window = []
|
||||
|
||||
self.setup_table()
|
||||
@@ -89,14 +98,14 @@ class GeometryWindow(PamhyrWindow):
|
||||
table_headers = self._trad.get_dict("table_headers")
|
||||
|
||||
table = self.find(QTableView, "tableView")
|
||||
self._tablemodel = GeometryReachTableModel(
|
||||
self._table = GeometryReachTableModel(
|
||||
table_view=table,
|
||||
table_headers=table_headers,
|
||||
editable_headers=["name", "kp"],
|
||||
data=self._reach,
|
||||
undo=self._undo_stack
|
||||
)
|
||||
table.setModel(self._tablemodel)
|
||||
table.setModel(self._table)
|
||||
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||
table.setAlternatingRowColors(True)
|
||||
@@ -160,7 +169,7 @@ class GeometryWindow(PamhyrWindow):
|
||||
def setup_connections(self):
|
||||
actions = {
|
||||
"action_import": self.import_from_file,
|
||||
# "action_export": self.export_to_file,
|
||||
"action_export": self.export_to_file,
|
||||
"action_sort_asc": self.sort_ascending,
|
||||
"action_sort_des": self.sort_descending,
|
||||
"action_up": self.move_up,
|
||||
@@ -168,6 +177,7 @@ class GeometryWindow(PamhyrWindow):
|
||||
"action_add": self.add,
|
||||
"action_delete": self.delete,
|
||||
"action_edit": self.edit_profile,
|
||||
"action_meshing": self.edit_meshing,
|
||||
}
|
||||
|
||||
for action in actions:
|
||||
@@ -186,6 +196,17 @@ class GeometryWindow(PamhyrWindow):
|
||||
.selectionChanged\
|
||||
.connect(self.select_current_profile)
|
||||
|
||||
self._table.layoutChanged.connect(self.update)
|
||||
|
||||
def update(self):
|
||||
self.update_profile_windows()
|
||||
self.plot_xy()
|
||||
self.plot_kpc()
|
||||
self.plot_ac()
|
||||
|
||||
self.select_current_profile()
|
||||
self.changed_slider_value()
|
||||
|
||||
def import_from_file(self):
|
||||
options = QFileDialog.Options()
|
||||
settings = QSettings(QSettings.IniFormat,
|
||||
@@ -208,13 +229,7 @@ class GeometryWindow(PamhyrWindow):
|
||||
|
||||
if filename != "":
|
||||
size = os.stat(filename).st_size
|
||||
self._reach.import_geometry(filename)
|
||||
self._tablemodel.layoutChanged.emit()
|
||||
|
||||
self.update_profile_windows()
|
||||
self.plot_xy()
|
||||
self.plot_kpc()
|
||||
self.plot_ac()
|
||||
self._table.import_geometry(0, filename)
|
||||
|
||||
def edit_profile(self):
|
||||
self.tableView.model().blockSignals(True)
|
||||
@@ -243,6 +258,25 @@ class GeometryWindow(PamhyrWindow):
|
||||
|
||||
self.tableView.model().blockSignals(False)
|
||||
|
||||
def edit_meshing(self):
|
||||
try:
|
||||
self._edit_meshing()
|
||||
except Exception:
|
||||
return
|
||||
|
||||
def _edit_meshing(self):
|
||||
try:
|
||||
mesher = MeshingWithMageMailleurTT()
|
||||
self._table.meshing(mesher, -1)
|
||||
except Exception as e:
|
||||
logger_exception(e)
|
||||
raise ExternFileMissingError(
|
||||
module="mage",
|
||||
filename="libbief",
|
||||
path=MeshingWithMage._lib_path(),
|
||||
src_except=e
|
||||
)
|
||||
|
||||
pyqtSlot(bool)
|
||||
|
||||
def changed_profile_slot(self, status):
|
||||
@@ -355,9 +389,9 @@ class GeometryWindow(PamhyrWindow):
|
||||
def changed_slider_value(self):
|
||||
self.tableView.model().blockSignals(True)
|
||||
|
||||
if self._tablemodel.rowCount() != 0:
|
||||
if self._table.rowCount() != 0:
|
||||
slider = self.find(QSlider, "verticalSlider")
|
||||
slider.setMaximum(self._tablemodel.rowCount() - 1)
|
||||
slider.setMaximum(self._table.rowCount() - 1)
|
||||
|
||||
slider_value = slider.value()
|
||||
kp = self._reach.profile(slider_value).kp
|
||||
@@ -371,20 +405,20 @@ class GeometryWindow(PamhyrWindow):
|
||||
|
||||
def increment_value_slider(self):
|
||||
slider = self.find(QSlider, "verticalSlider")
|
||||
if 0 <= slider.value() < self._tablemodel.rowCount() - 1:
|
||||
if 0 <= slider.value() < self._table.rowCount() - 1:
|
||||
slider.setValue(slider.value() + 1)
|
||||
|
||||
def decrement_value_slider(self):
|
||||
slider = self.find(QSlider, "verticalSlider")
|
||||
if 0 < slider.value() < self._tablemodel.rowCount():
|
||||
if 0 < slider.value() < self._table.rowCount():
|
||||
slider.setValue(slider.value() - 1)
|
||||
|
||||
def add(self):
|
||||
if len(self.tableView.selectedIndexes()) == 0:
|
||||
self._tablemodel.add(self._tablemodel.rowCount())
|
||||
self._table.add(self._table.rowCount())
|
||||
else:
|
||||
row = self.index_selected_row()
|
||||
self._tablemodel.add(row + 1)
|
||||
self._table.add(row + 1)
|
||||
|
||||
def delete(self):
|
||||
rows = sorted(
|
||||
@@ -396,13 +430,7 @@ class GeometryWindow(PamhyrWindow):
|
||||
)
|
||||
|
||||
if len(rows) > 0:
|
||||
self._tablemodel.delete(rows)
|
||||
|
||||
self.update_plot_xy()
|
||||
self.select_current_profile()
|
||||
|
||||
self.plot_kpc()
|
||||
self.changed_slider_value()
|
||||
self._table.delete(rows)
|
||||
|
||||
def index_selected_row(self):
|
||||
return self.tableView\
|
||||
@@ -411,24 +439,24 @@ class GeometryWindow(PamhyrWindow):
|
||||
.row()
|
||||
|
||||
def sort_ascending(self):
|
||||
self._tablemodel.sort_profiles(False)
|
||||
self._table.sort_profiles(False)
|
||||
self.select_current_profile()
|
||||
self.changed_slider_value()
|
||||
|
||||
def sort_descending(self):
|
||||
self._tablemodel.sort_profiles(True)
|
||||
self._table.sort_profiles(True)
|
||||
|
||||
self.select_current_profile()
|
||||
self.changed_slider_value()
|
||||
|
||||
def move_up(self):
|
||||
row = self.index_selected_row()
|
||||
self._tablemodel.move_up(row)
|
||||
self._table.move_up(row)
|
||||
self.select_current_profile()
|
||||
|
||||
def move_down(self):
|
||||
row = self.index_selected_row()
|
||||
self._tablemodel.move_down(row)
|
||||
self._table.move_down(row)
|
||||
self.select_current_profile()
|
||||
|
||||
def duplicate(self):
|
||||
@@ -446,7 +474,7 @@ class GeometryWindow(PamhyrWindow):
|
||||
if len(profiles) == 0:
|
||||
return
|
||||
|
||||
self._tablemodel.duplicate(rows, profiles)
|
||||
self._table.duplicate(rows, profiles)
|
||||
self.select_current_profile()
|
||||
|
||||
def _copy(self):
|
||||
@@ -468,50 +496,113 @@ class GeometryWindow(PamhyrWindow):
|
||||
def _paste(self):
|
||||
header, data = self.parseClipboardTable()
|
||||
|
||||
if len(data) == 0:
|
||||
if len(data) + len(header) == 0:
|
||||
return
|
||||
|
||||
# if len(header) != 0:
|
||||
# header.append("reach")
|
||||
# header.append("status")
|
||||
|
||||
for row in data:
|
||||
row.append(self._reach)
|
||||
row.append(self._study.river._status)
|
||||
# HACK: The CVS module detect the first line to csv header in
|
||||
# some particular case... To avoid this we append to data list
|
||||
# the "headers". /!\ This hack must failed if a real header
|
||||
# exists (a better solution is welcome).
|
||||
logger.debug(
|
||||
"Geometry: Paste: " +
|
||||
f"header = {header}, " +
|
||||
f"data = {data}"
|
||||
)
|
||||
if len(header) != 0:
|
||||
data = [header] + data
|
||||
|
||||
row = self.index_selected_row()
|
||||
# self._tablemodel.paste(row, header, data)
|
||||
self._tablemodel.paste(row, [], data)
|
||||
self.select_current_profile()
|
||||
try:
|
||||
for row in data:
|
||||
row.append(self._reach)
|
||||
row.append(self._study.river._status)
|
||||
|
||||
row = self.index_selected_row()
|
||||
# self._table.paste(row, header, data)
|
||||
self._table.paste(row, [], data)
|
||||
self.select_current_profile()
|
||||
except Exception as e:
|
||||
logger_exception(e)
|
||||
|
||||
def _undo(self):
|
||||
self._tablemodel.undo()
|
||||
self._table.undo()
|
||||
self.select_current_profile()
|
||||
self.update_plot_xy()
|
||||
self.update_plot_kpc()
|
||||
# self.update_plot_ac()
|
||||
# self.update_plot_xy()
|
||||
# self.update_plot_kpc()
|
||||
|
||||
def _redo(self):
|
||||
self._tablemodel.redo()
|
||||
self._table.redo()
|
||||
self.select_current_profile()
|
||||
self.update_plot_xy()
|
||||
self.update_plot_kpc()
|
||||
# self.update_plot_ac()
|
||||
# self.update_plot_xy()
|
||||
# self.update_plot_kpc()
|
||||
|
||||
def export_to_file(self):
|
||||
settings = QSettings(
|
||||
QSettings.IniFormat,
|
||||
QSettings.UserScope, 'MyOrg'
|
||||
)
|
||||
|
||||
if self._study.filename != "" or self._study.filename is not None:
|
||||
default_directory = os.path.basename(self._study.filename)
|
||||
current_dir = settings.value(
|
||||
'current_directory',
|
||||
default_directory,
|
||||
type=str
|
||||
)
|
||||
|
||||
options = QFileDialog.Options()
|
||||
DEFAULT_DIRECTORY = '/home/'
|
||||
settings = QSettings(QSettings.IniFormat,
|
||||
QSettings.UserScope, 'MyOrg', )
|
||||
current_dir = settings.value(
|
||||
'current_directory', DEFAULT_DIRECTORY, type=str)
|
||||
options |= QFileDialog.DontUseNativeDialog
|
||||
|
||||
filename, filters = QFileDialog.getSaveFileName(
|
||||
self,
|
||||
filter=self._trad["file_st"] + ";; " + self._trad["file_all"],
|
||||
filter=(
|
||||
self._trad["file_st"] + ";; " +
|
||||
self._trad["file_all"]
|
||||
),
|
||||
options=options
|
||||
)
|
||||
|
||||
current_dir = os.path.split(filename)[0] or DEFAULT_DIRECTORY
|
||||
|
||||
if filename != '':
|
||||
self._tablemodel.export_reach(filename)
|
||||
self._export_to_file_st(filename)
|
||||
|
||||
def _export_to_file_st(self, filename):
|
||||
with open(filename, "w+") as f:
|
||||
f.write("# Exported from Pamhyr2\n")
|
||||
self._export_to_file_st_reach(f, self._reach)
|
||||
|
||||
def _export_to_file_st_reach(self, wfile, reach):
|
||||
pid = 0
|
||||
for profile in reach.profiles:
|
||||
self._export_to_file_st_profile(wfile, profile, pid)
|
||||
pid += 1
|
||||
|
||||
def _export_to_file_st_profile(self, wfile, profile, pid):
|
||||
num = f"{pid:>6}"
|
||||
c1 = f"{profile.code1:>6}"
|
||||
c2 = f"{profile.code2:>6}"
|
||||
t = f"{len(profile.points):>6}"
|
||||
kp = f"{profile.kp:>12f}"[0:12]
|
||||
pname = profile.name
|
||||
if profile.name == "":
|
||||
pname = f"p{profile.id:>3}".replace(" ", "0")
|
||||
name = f"{pname:<19}"
|
||||
|
||||
wfile.write(f"{num}{c1}{c2}{t} {kp} {pname}\n")
|
||||
|
||||
for point in profile.points:
|
||||
self._export_to_file_st_point(wfile, point)
|
||||
|
||||
wfile.write(f" 999.9990 999.9990 999.9990\n")
|
||||
|
||||
def _export_to_file_st_point(self, wfile, point):
|
||||
x = f"{point.x:<12.4f}"[0:12]
|
||||
y = f"{point.y:<12.4f}"[0:12]
|
||||
z = f"{point.z:<12.4f}"[0:12]
|
||||
n = f"{point.name:<3}"
|
||||
|
||||
wfile.write(f"{x} {y} {z} {n}\n")
|
||||
@@ -136,7 +136,9 @@ class TableModel(PamhyrTableModel):
|
||||
)
|
||||
)
|
||||
elif self._headers[column] == "type":
|
||||
if self._question_set_type():
|
||||
old_type = self._data.basic_structure(row).type
|
||||
|
||||
if old_type == "ND" or self._question_set_type():
|
||||
key = next(
|
||||
k for k, v in self._long_types.items()
|
||||
if v == value
|
||||
@@ -239,7 +241,7 @@ class ParametersTableModel(PamhyrTableModel):
|
||||
hs = self._data.basic_structure(self._hs_index)
|
||||
|
||||
if self._headers[column] == "name":
|
||||
return hs.parameters[row].name
|
||||
return self._trad[hs.parameters[row].name]
|
||||
elif self._headers[column] == "value":
|
||||
return str(hs.parameters[row].value)
|
||||
|
||||
|
||||
@@ -38,42 +38,118 @@ class BasicHydraulicStructuresTranslate(PamhyrTranslate):
|
||||
hydraulic structure values?"
|
||||
)
|
||||
|
||||
# BHSValues translation
|
||||
|
||||
self._dict['width'] = _translate(
|
||||
"BasicHydraulicStructures", "Width"
|
||||
)
|
||||
self._dict['height'] = _translate(
|
||||
"BasicHydraulicStructures", "Height"
|
||||
)
|
||||
self._dict['elevation'] = _translate(
|
||||
"BasicHydraulicStructures", "Elevation"
|
||||
)
|
||||
self._dict['diameter'] = _translate(
|
||||
"BasicHydraulicStructures", "Diameter"
|
||||
)
|
||||
self._dict['discharge_coefficient'] = _translate(
|
||||
"BasicHydraulicStructures", "Discharge coefficient"
|
||||
)
|
||||
self._dict['loading_elevation'] = _translate(
|
||||
"BasicHydraulicStructures", "Loading elevation"
|
||||
)
|
||||
self._dict['half-angle_tangent'] = _translate(
|
||||
"BasicHydraulicStructures", "Half-angle tangent"
|
||||
)
|
||||
self._dict['maximal_loading_elevation'] = _translate(
|
||||
"BasicHydraulicStructures", "Maximal loading elevation"
|
||||
)
|
||||
self._dict['siltation_height'] = _translate(
|
||||
"BasicHydraulicStructures", "Siltation height"
|
||||
)
|
||||
self._dict['top_of_the_vault'] = _translate(
|
||||
"BasicHydraulicStructures", "Top of the vault"
|
||||
)
|
||||
self._dict['bottom_of_the_vault'] = _translate(
|
||||
"BasicHydraulicStructures", "Bottom of the vault"
|
||||
)
|
||||
self._dict['opening'] = _translate(
|
||||
"BasicHydraulicStructures", "Opening"
|
||||
)
|
||||
self._dict['maximal_opening'] = _translate(
|
||||
"BasicHydraulicStructures", "Maximal opening"
|
||||
)
|
||||
self._dict['step_space'] = _translate(
|
||||
"BasicHydraulicStructures", "Step space"
|
||||
)
|
||||
self._dict['weir'] = _translate(
|
||||
"BasicHydraulicStructures", "Weir"
|
||||
)
|
||||
self._dict['coefficient'] = _translate(
|
||||
"BasicHydraulicStructures", "Coefficient"
|
||||
)
|
||||
|
||||
# Dummy parameters
|
||||
|
||||
self._dict['parameter_1'] = _translate(
|
||||
"BasicHydraulicStructures", "Parameter 1"
|
||||
)
|
||||
self._dict['parameter_2'] = _translate(
|
||||
"BasicHydraulicStructures", "Parameter 2"
|
||||
)
|
||||
self._dict['parameter_3'] = _translate(
|
||||
"BasicHydraulicStructures", "Parameter 3"
|
||||
)
|
||||
self._dict['parameter_4'] = _translate(
|
||||
"BasicHydraulicStructures", "Parameter 4"
|
||||
)
|
||||
self._dict['parameter_5'] = _translate(
|
||||
"BasicHydraulicStructures", "Parameter 5"
|
||||
)
|
||||
|
||||
# BHS types long names
|
||||
|
||||
self._sub_dict["long_types"] = {
|
||||
"ND": _translate(
|
||||
"BasicHydraulicStructures", "Not defined"
|
||||
),
|
||||
"S1": _translate(
|
||||
"BasicHydraulicStructures", "Seuil déversoir"
|
||||
"BasicHydraulicStructures", "Discharge weir"
|
||||
),
|
||||
"S2": _translate(
|
||||
"BasicHydraulicStructures", "Seuil trapezoidal"
|
||||
"BasicHydraulicStructures", "Trapezoidal weir"
|
||||
),
|
||||
"S3": _translate(
|
||||
"BasicHydraulicStructures", "Seuil triangulaire"
|
||||
"BasicHydraulicStructures", "Triangular weir"
|
||||
),
|
||||
"OR": _translate(
|
||||
"BasicHydraulicStructures", "Orifice rectangulaire"
|
||||
"BasicHydraulicStructures", "Rectangular orifice"
|
||||
),
|
||||
"OC": _translate(
|
||||
"BasicHydraulicStructures", "Orifice circulaire"
|
||||
"BasicHydraulicStructures", "Circular orifice"
|
||||
),
|
||||
"OV": _translate(
|
||||
"BasicHydraulicStructures", "Orifice voute"
|
||||
"BasicHydraulicStructures", "Vaulted orifice"
|
||||
),
|
||||
"V1": _translate(
|
||||
"BasicHydraulicStructures", "Vanne rectangulaire"
|
||||
"BasicHydraulicStructures", "Rectangular gate"
|
||||
),
|
||||
"V2": _translate(
|
||||
"BasicHydraulicStructures", "Vanne rectangulaire simplifiée"
|
||||
"BasicHydraulicStructures", "Simplified rectangular gate"
|
||||
),
|
||||
"BO": _translate(
|
||||
"BasicHydraulicStructures", "Perte de charge à la Borda"
|
||||
"BasicHydraulicStructures", "Borda-type head loss"
|
||||
),
|
||||
"CV": _translate(
|
||||
"BasicHydraulicStructures", "Check valve"
|
||||
),
|
||||
"UD": _translate(
|
||||
"BasicHydraulicStructures", "User defined"
|
||||
),
|
||||
}
|
||||
|
||||
# Tables
|
||||
|
||||
self._sub_dict["table_headers"] = {
|
||||
"name": _translate("BasicHydraulicStructures", "Name"),
|
||||
"type": _translate("BasicHydraulicStructures", "Type"),
|
||||
|
||||