Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions docs/tools/prof_to_cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
prof_to_cross
=============
*Convert D-Flow FM legacy profile files to cross section files.*

Directly jump to [Commandline usage](#Commandline-usage).

# Background
1D cross section specification in a D-Flow FM model used to go via two or three prof* files,
the ones specified in the MDU file under `[geometry]` via `ProflocFile`, `ProfdefFile`
and optionally `ProfdefxyzFile`. They contain the location/placement and the type/geometry description, respectively.

Similar input is still needed, but now is officially supported via .ini files.
These are the ones now specified in the MDU file under `[geometry]` via `CrsLocFile` and `CrsDefFile`.

## Automatic conversion choices
prof_to_cross makes the following automatic conversion choices.
### Location
Location continues to be specified via original *x,y* coordinate, no branchId is available.

Vertical absolute placement (`ZMIN` in profile *definition* file) only has a basic conversion
(as direct `shift` in crosssection *location* file).

### Type + conveyance
The following table lists the mapping from old to new cross section types:

|Profdef TYPE|meaning|type in crsdef.ini|conveyanceType in crsdef.ini|
| :--- | :--- | :--- | :--- |
|1|`PIPE`|`circle`|N/A|
|2|`RECTAN , HYDRAD = AREA / PERIMETER`|`rectangle`|N/A|
|3|`RECTAN , HYDRAD = 1D ANALYTIC CONVEYANCE`|`rectangle`|N/A|
|4|`V-SHAPE , HYDRAD = AREA / PERIMETER`|`yz`|`lumped`|
|5|`V-SHAPE , HYDRAD = 1D ANALYTIC CONVEYANCE`|`yz`|`segmented`|
|6|`TRAPEZOID, HYDRAD = AREA / PERIMETER`|`yz`|`lumped`|
|7|`TRAPEZOID, HYDRAD = 1D ANALYTIC CONVEYANCE`|`yz`|`segmented`|
|100|`YZPROF , HYDRAD = AREA / PERIMETER`|`yz`|`lumped`|
|101|`YZPROF , HYDRAD = 1D ANALYTIC CONVEYANCE METHOD`|`yz`|`segmented`|
|200|`XYZPROF , HYDRAD = AREA / PERIMETER`|`xyz`|`lumped`|
|201|`XYZPROF , HYDRAD = 1D ANALYTIC CONVEYANCE METHOD`|`xyz`|`segmented`|

### Friction
The following table lists the mapping from old to new friction types:

|Profdef FRCTP|frictionType in crsdef.ini
| :--- | :--- |
|`0`|`Chezy`|
|`1`|`Manning`|
|`2`|`WallLawNikuradse` (a.k.a. White-Colebrook Delft3D-style)|
|`3`|`WhiteColebrook`|


# Commandline usage:
```bash
usage: python hydrolib/tools/prof_to_cross.py [-h] [--version] [--verbose] \
[--mdufile MDUFILE] \
[--proffiles [PROFFILE [PROFFILE ...]]] \
[--outfiles CRSLOCFILE CRSDEFFILE]
```

## Arguments

|short|long|default|help|
| :--- | :--- | :--- | :--- |
|`-h`|`--help`||show this help message and exit|
|`-v`|`--version`||show program's version number and exit|
||`--verbose`||also print diagnostic information|
|`-m`|`--mdufile`|`None`|automatically take profile filenames from MDUFILE|
|`-p`|`--proffiles`|`None`|2 or 3 profile files: PROFLOCFILE PROFDEFFILE [PROFDEFXYZFILE]|
|`-o`|`--outfiles` |`crsloc.ini crsdef.ini`|save cross section locations and definitions to specified filenames|

# Python usage:
```python
from hydrolib.tools import prof_to_cross

# Option 1: via MDU file:
prof_to_cross.prof_to_cross_from_mdu('FlowFM.mdu')

# Option 2: directly via profile files:
prof_to_cross.prof_to_cross('profloc.xyz', 'profdef.txt', 'profdefxyz.pliz')
```
6 changes: 6 additions & 0 deletions docs/tools/tools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Introduction to tools

HYDROLIB-core also contains utility tools built on top of the core I/O functionality.
These small tools may help with model conversion and inspection.

* **[prof_to_cross](prof_to_cross.md)** - Convert D-Flow FM legacy profdef/profloc files to cross section files.
13 changes: 13 additions & 0 deletions hydrolib/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import contextlib
Comment thread
arthurvd marked this conversation as resolved.
import os
import platform
import re
from enum import Enum, auto
Expand Down Expand Up @@ -178,6 +180,17 @@ def get_operating_system() -> OperatingSystem:
raise NotImplementedError(f"Operating system {operating_system} is not supported.")


@contextlib.contextmanager
def working_directory(path):
"""Changes working directory and returns to previous on exit."""
prev_cwd = Path.cwd()
os.chdir(path)
try:
yield
finally:
os.chdir(prev_cwd)


class PathStyle(str, Enum):
"""Path style format."""

Expand Down
1 change: 1 addition & 0 deletions hydrolib/tools/__init__ .py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading