using IStation.Epanet.Analysis;
|
using IStation.Epanet.Enums;
|
using System.Text;
|
using Yw;
|
|
namespace IStation.Epanet
|
{
|
/// <summary>
|
/// 水力模型调度
|
/// </summary>
|
public class StationScheduleHelper
|
{
|
|
public static string Schedule(int stationId,string filePath)
|
{
|
|
|
var err = EpanetMethods.ENopen(filePath, "", "");
|
if (err != 0)
|
{
|
return $"ENopen:{new EnException(err).Message}!";
|
}
|
|
|
int tstep = 0;
|
EpanetMethods.ENopenH();
|
EpanetMethods.ENinitH(0);
|
|
do
|
{
|
const int MAXID = 31;
|
var idBuild = new StringBuilder(MAXID);
|
var jsonBuild = new StringBuilder();
|
|
EpanetMethods.ENrunH(out int t);
|
|
EpanetMethods.ENgetcount(CountType.Node, out int nodeCount);
|
EpanetMethods.ENgetcount(CountType.Link, out int linkCount);
|
|
for (int i = 1; i <= nodeCount; i++)
|
{
|
if (EpanetMethods.ENgetnodeid(i, idBuild) != 0)
|
continue;
|
jsonBuild.Clear();
|
jsonBuild.Append("{");
|
foreach (NodeValue f in Enum.GetValues(typeof(NodeValue)))
|
{
|
EpanetMethods.ENgetnodevalue(i, f, out float v);
|
jsonBuild.Append($"\"{f}\":\"{v}\",");
|
}
|
jsonBuild.Remove(jsonBuild.Length - 1, 1);
|
jsonBuild.Append("}");
|
|
EpanetMethods.ENgetnodetype(i, out NodeType type);
|
var outNode = JsonHelper.Json2Object<OutNode>(jsonBuild.ToString());
|
outNode.NodeType = type;
|
outNode.ID = idBuild.ToString();
|
outNode.Time = TimeSpan.FromSeconds(t);
|
|
output.Nodes.Add(outNode);
|
}
|
|
for (int i = 1; i <= linkCount; i++)
|
{
|
if (EpanetMethods.ENgetlinkid(i, idBuild) != 0)
|
continue;
|
|
jsonBuild.Clear();
|
jsonBuild.Append("{");
|
foreach (LinkValue f in Enum.GetValues(typeof(LinkValue)))
|
{
|
EpanetMethods.ENgetlinkvalue(i, f, out float v);
|
jsonBuild.Append($"\"{f}\":\"{v}\",");
|
}
|
jsonBuild.Remove(jsonBuild.Length - 1, 1);
|
jsonBuild.Append("}");
|
|
EpanetMethods.ENgetlinktype(i, out LinkType type);
|
var outLink = JsonHelper.Json2Object<OutLink>(jsonBuild.ToString());
|
outLink.LinkType = type;
|
outLink.ID = idBuild.ToString();
|
outLink.Time = TimeSpan.FromSeconds(t);
|
output.Links.Add(outLink);
|
}
|
|
EpanetMethods.ENnextH(out tstep);
|
|
} while (tstep > 0);
|
EpanetMethods.ENcloseH();
|
|
return string.Empty;
|
}
|
|
}
|
|
}
|