HEC-RAS模型
===
## 简介
HEC-RAS模型可以说是一个支持河流水动力学计算的综合软件包。由美国陆军工程兵团水文工程中心(US Army Crops of Engineers Hydrologic Engineering Center)组织开发并持续发展维护,第一个版本发布于1995年7月,现在已迭代至6.2,由最初的只支持一维计算到现在可以支持二维计算。目前主要由陆军工程兵团、联邦公路管理局(Federal Highway Administration)、Tampa Bay Water(非盈利组织)、南佛罗里达水资源管理局(South Florida Water Management District)等资助。这里有很多我们中国学者参与研发。
## 适用场景
- 河流一维稳态流水面线计算
- 河流一、二维非稳态流、泥沙输移模拟
- 河流一维水质模拟(目前版本水质因子包括:藻类、溶解氧、碳质生化需氧量CBOD、溶解性正硫酸盐、溶解性有机硫酸盐、溶解性硝酸铵、溶解性亚硝酸氮、溶解性硝酸盐氮、溶解性有机氮)
## 软件下载
### 运行程序
- 官网链接:[官网](https://www.hec.usace.army.mil/software/hec-ras/download.aspx)
- 社区链接:[HEC-RAS 6.2 安装包及说明文档](http://toolsbox.org.cn/download/hecras/HEC-RAS_62_Setup.exe)
### 开发库
#### HEC-RAS模型接口开发项目
```
git clone https://gitee.com/hydrojip/sypcloud_public.git
```
#### HEC模型二进制文件解析库HEC-DSS
- 官网链接(.net版本当前支持.net 4.7.2):[HEC-DSS](https://github.com/HydrologicEngineeringCenter/hec-dss)
- 社区提供基于当前最新版本改编译为<font color="red">.net 4.5.2</font>的AnyCPU编译版本:[HEC-DSS库文件下载](http://toolsbox.org.cn/download/hecras/hecdss.zip)
## 应用指南
更新中...
## 开发指南
### 时间控制闸门开口 time control gate opening
```
Gate Openings= 10 # hec-ras 5.0.5 版本测试 开口时间序列最大只能是10,
```
可通过修改时间间隔来使得闸门控制时间序列长度与模拟时间长度保持一致
```
Gate Time Interval=1HOUR
```
### 水位边界存储时,提前将数据的小数位进行截取,可以截取到两位小数点(对水位来说,两位以上没有意义),否则可能引起数据格式超限,导致模型识别不了边界条件
```
Stage Hydrograph=70
 1.07764 0.866460.6677020.3695650.2453420.0217391-0.0652174 0.344720.804348     1.5
 1.69876 1.64907 1.48758  1.16460.8913040.5062110.2577640.0838509-0.052795-0.0776398
0.506211 1.10248 1.36335 1.51242  1.3882 1.189440.8788820.5931680.3695650.145963
-0.003105590.319876 1.00311 1.78571 2.60559  3.2764 3.06522 2.49379 1.99689 1.41304
 1.015530.7670810.5062110.3198760.506211 1.21429 1.71118 1.88509 1.66149 1.22671
0.8416150.5062110.2950310.09627330.05900620.07142860.493789 1.22671 1.51242 1.76087
 1.66149 1.43789 1.177020.9409940.6801240.5186340.282609 0.183230.09627330.754658
```
应改为
```
Stage Hydrograph=70
    1.08    0.87    0.67    0.37    0.25    0.02   -0.07    0.34     0.8     1.5
     1.7    1.65    1.49    1.16    0.89    0.51    0.26    0.08   -0.05   -0.08
    0.51     1.1    1.36    1.51    1.39    1.19    0.88    0.59    0.37    0.15
       0    0.32       1    1.79    2.61    3.28    3.07    2.49       2    1.41
    1.02    0.77    0.51    0.32    0.51    1.21    1.71    1.89    1.66    1.23
    0.84    0.51     0.3     0.1    0.06    0.07    0.49    1.23    1.51    1.76
    1.66    1.44    1.18    0.94    0.68    0.52    0.28    0.18     0.1    0.75
```
### HEC-RAS模型结果二进制文件(DSS文件)解析
参见上面HEC-RAS模型接口开发项目工程

- Part A,rivername reachname
- Part C
    - LOCATION-ELEV 水位
    - LOCATION-FLOW 流量
    - LOCATION-VEL  流速
- 更新中...
### 接口功能介绍
#### 模型空间拓扑(河网、断面)、参数及边界信息解析
指定HEC-RAS模型文件夹和工程名称,实现对模型边界、参数等配置文件的识别;实现对模型空间拓扑(河网、断面数据)的识别;模拟时间、边界时间序列数据的识别。
识别出的信息存储在抽象的模型<font color=red>通用</font>数据模型对象中。
- 模拟时间数据对象
```c#
/// <summary>
/// 模型计算开始时间
/// </summary>
[DataMember]
public DateTime StartTime { get; set; }
/// <summary>
/// 模型计算结束时间
/// </summary>
[DataMember]
public DateTime EndTime { get; set; }
/// <summary>
/// 预报时刻
/// </summary>
[DataMember]
public DateTime ForecastingTime { get; set; }
```
- 边界数据对象示例
```json=
{
        "WaterLever": 0,
        "Flow": 0,
        "DomainType": 0,
        "HDType": 2,
        "WQType": 0,
        "RRType": 0,
        "Location": null,
        "Location2": null,
        "NodeID": 0,
        "ElementID": 0,
        "Value": [
          {
            "DT": "2022-04-01T00:00:00",
            "Data": 0.1
          },
          {
            "DT": "2022-04-01T01:00:00",
            "Data": 0.1
          },         
        ],
        "RiverName": null,
        "Chainage": 0,
        "EndChainage": 0,
        "Pollutants": [
          "Water Temperature",
          "NH3N",
          "TP",
          "COD"
        ],
        "Concetration": [
          [],
          [
            {
              "DT": "2022-04-01T00:00:00",
              "Data": 0.87
            },
            {
              "DT": "2022-04-05T00:00:00",
              "Data": 0.87
            }
          ],          
        ],
        "ObsConcetration": [
          [
            {
              "DT": "2022-04-01T00:00:00",
              "Data": 0
            },
            {
              "DT": "2022-04-05T00:00:00",
              "Data": 0
            }
          ],          
        ],
        "IntConcetration": null,
        "Location3": {
          "riverName": "yellow",
          "reachName": "yellow",
          "station": "31430.88",
          "station2": null
        },
        "IntervalStr": "1HOUR",
        "StuctureBnd": null,
        "BndDescription": 0,
        "Boundarykey": null,
        "IsConstant": false,
        "IsAdConstant": false,
        "IsTimeseriers": false,
        "ConstantValue": 0,
        "AdConstantValue": null,
        "Tsfile": null,
        "Depth": 0
      }
```
- 河网、断面数据对象示例,识别河网的空间坐标并转换为经纬度、识别断面起点距及高程数据,并计算出横断面平面布置坐标,同时追踪出上下游河道代码。
```json
{
            "UpRvr": null,
            "DnRvr": [
              "rivercode"
            ],
            "XSectoin": [
              {
                "Station": 0,
                "Data": [
                  {
                    "X": 0,
                    "Y": 11.279,
                    "Z": 0,
                    "Attribute": 0
                  },
                  {
                    "X": 2.602,
                    "Y": 8.833,
                    "Z": 0,
                    "Attribute": 0
                  },                  
                ],
                "Points": [
                  {
                    "X": 113.82124811188008,
                    "Y": 22.73713926396902,
                    "Z": 0,
                    "Attribute": 0
                  },
                  {
                    "X": 113.82122506452923,
                    "Y": 22.737129550438965,
                    "Z": 0,
                    "Attribute": 0
                  },                  
                ],
                "BranchTopoIdChainageTb": null,
                "VerticalProfile": null
              },],
            "RvrMdCode": "wanfenghe&wanfenghe",
            "TopoID": null,
            "Name": null,
            "RvrName": "wanfenghe",
            "RchName": "wanfenghe",
            "StChainage": 0,
            "EdChainage": 1,
            "Points": [
              {
                "X": 113.82227772408609,
                "Y": 22.708300308199295,
                "Z": 0,
                "Attribute": 0
              },
              {
                "X": 113.82305343158593,
                "Y": 22.709056021342377,
                "Z": 0,
                "Attribute": 0
              },              
            ]
          }
```

#### 通过河网通用地理数据生成HEC-RAS模型河网文件(*.g**)
```c#
public void WriteGeoFile(HEC_DM hecModel, string geoFile)
{
...
}
```
#### 导入ZDM断面数据
```c#
public void ImportHdm2Gemetry(string hdmfodler, string geometryFile, int tag)
{
...
}
```
#### 合并两个河网数据
```c#
public void MergeGeometry(HEC_DM hecModel, HEC_DM hecModel2, string geoFile)
{
...
}
```
#### 将边界通用数据对象保存或修改到HEC-RAS模型水动力边界文件
```c#
public void SetBoundary(List<Boundary> boundaryList)
{
...
}
```
#### 将边界通用数据对象保存或修改到HEC-RAS模型水质边界文件
```c#
public void SetWqBoundary(List<Boundary> boundaryList)
{
...
}
```
#### 将模拟时间通用数据对象保存或修改到HEC-RAS模型Plan文件
```c#
public void SetSimulationTime(ModelTime modeltime)
{
...
}
```
#### 启动模型计算并返回计算日志
```c#
public bool RunModel(string controlfile)
{
...
}
```
#### 将HEC-RAS模型结果解析到一维水动力水质结果通用数据对象
按河网模型差分计算河段输出结果,附加时段统计值,水质类别计算等。
```c#
public List<RiverSegModelResults> GetResults(DateTime startTime, DateTime endTime, string Projection, int centralLgtd)
{
...
}
```
> <font color="red">点击下面 **阅读原文** 查看文中链接</font>
###### tags: `博客` `模型软件学习`