#define EPA2_2 //EPA2_0 using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace IStation { public class EpanetBase { const string DLLName = "epanet2.dll";//"epanet2.2.dll" //{ These are codes used by the DLL functions } public static class Const_class { public static class Const_Node { public const int EN_ELEVATION = 0; // { Mode parameters } public const int EN_BASEDEMAND = 1; public const int EN_PATTERN = 2; public const int EN_EMITTER = 3; public const int EN_INITQUAL = 4; public const int EN_SOURCEQUAL = 5; public const int EN_SOURCEPAT = 6; public const int EN_SOURCETYPE = 7; public const int EN_TANKLEVEL = 8; public const int EN_DEMAND = 9; public const int EN_HEAD = 10; public const int EN_PRESSURE = 11; public const int EN_QUALITY = 12; public const int EN_SOURCEMASS = 13; public const int EN_INITVOLUME = 14; public const int EN_MIXMODEL = 15; public const int EN_MIXZONEVOL = 16; } public static class Const_Tank { public const int EN_TANKDIAM = 17; public const int EN_MINVOLUME = 18; public const int EN_VOLCURVE = 19; public const int EN_MINLEVEL = 20; public const int EN_MAXLEVEL = 21; public const int EN_MIXFRACTION = 22; public const int EN_TANK_KBULK = 23; } public static class Const_Link { public const int EN_DIAMETER = 0; // { Link parameters } public const int EN_LENGTH = 1; public const int EN_ROUGHNESS = 2; public const int EN_MINORLOSS = 3; public const int EN_INITSTATUS = 4; public const int EN_INITSETTING = 5; public const int EN_KBULK = 6; public const int EN_KWALL = 7; public const int EN_FLOW = 8; public const int EN_VELOCITY = 9; public const int EN_HEADLOSS = 10; public const int EN_STATUS = 11; public const int EN_SETTING = 12; public const int EN_ENERGY = 13; } public static class Const_Time { public const int EN_DURATION = 0; // { Time parameters } public const int EN_HYDSTEP = 1; public const int EN_QUALSTEP = 2; public const int EN_PATTERNSTEP = 3; public const int EN_PATTERNSTART = 4; public const int EN_REPORTSTEP = 5; public const int EN_REPORTSTART = 6; public const int EN_RULESTEP = 7; public const int EN_STATISTIC = 8; public const int EN_PERIODS = 9; } public static class Const_Component { public const int EN_NODECOUNT = 0; //{ Component counts } public const int EN_TANKCOUNT = 1; public const int EN_LINKCOUNT = 2; public const int EN_PATCOUNT = 3; public const int EN_CURVECOUNT = 4; public const int EN_CONTROLCOUNT = 5; } public static class Const_Node_Type { public const int EN_JUNCTION = 0; // { Node types } public const int EN_RESERVOIR = 1; public const int EN_TANK = 2; } public static class Const_Link_types { public const int EN_CVPIPE = 0; // { Link types } public const int EN_PIPE = 1; public const int EN_PUMP = 2; public const int EN_PRV = 3; public const int EN_PSV = 4; public const int EN_PBV = 5; public const int EN_FCV = 6; public const int EN_TCV = 7; public const int EN_GPV = 8; } public static class Const_Quality_analysis_types { public const int EN_NONE = 0; // { Quality analysis types } public const int EN_CHEM = 1; public const int EN_AGE = 2; public const int EN_TRACE = 3; } public static class Const_Source_quality_types { public const int EN_CONCEN = 0; // { Source quality types } public const int EN_MASS = 1; public const int EN_SETPOINT = 2; public const int EN_FLOWPACED = 3; } public static class Const_Flow_units_types { public const int EN_CFS = 0; // { Flow units types } public const int EN_GPM = 1; public const int EN_MGD = 2; public const int EN_IMGD = 3; public const int EN_AFD = 4; public const int EN_LPS = 5; public const int EN_LPM = 6; public const int EN_MLD = 7; public const int EN_CMH = 8; public const int EN_CMD = 9; } public static class Const_Option_types { public const int EN_TRIALS = 0; // { Option types } public const int EN_ACCURACY = 1; public const int EN_TOLERANCE = 2; public const int EN_EMITEXPON = 3; public const int EN_DEMANDMULT = 4; } public static class Const_Control_types { public const int EN_LOWLEVEL = 0; //{ Control types } public const int EN_HILEVEL = 1; public const int EN_TIMER = 2; public const int EN_TIMEOFDAY = 3; } public static class Const_Time_statistic_types { public const int EN_AVERAGE = 1; // { Time statistic types } public const int EN_MINIMUM = 2; public const int EN_MAXIMUM = 3; public const int EN_RANGE = 4; } public static class Const_Tank_mixing_models { public const int EN_MIX1 = 0; // { Tank mixing models } public const int EN_MIX2 = 1; public const int EN_FIFO = 2; public const int EN_LIFO = 3; } public static class Const_Save_results_Mode { public const int EN_NOSAVE = 0; // { Save-results-to-file flag } public const int EN_SAVE = 1; public const int EN_INITFLOW = 10; // { Re-initialize flow flag } } } #region 节点 // 获取节点参数值 [DllImport(DLLName)] public static extern int ENgetnodevalue(int index, int paramcode, ref float value); // 获取节点类型 [DllImport(DLLName)] public static extern int ENgetnodetype(int index, ref int typecode); // 获取节点编号 [DllImport(DLLName)] public static extern int ENgetnodeindex(string nodeid, ref int nodeindex); // 获取节点 id [DllImport(DLLName)] public static extern int ENgetnodeid(int index, StringBuilder id); // 设置节点参数 [DllImport(DLLName)] public static extern int ENsetnodevalue(int index, int paramcode, float value); #endregion #region 管段 // 设置管段参数 [DllImport(DLLName)] public static extern int ENsetlinkvalue(int index, int paramcode, float value); // 获取管段 id [DllImport(DLLName)] public static extern int ENgetlinkid(int index, StringBuilder id); // 获取管段 id [DllImport(DLLName)] public static extern int ENgetlinkindex(string id, ref int index); // 获取管段节点 [DllImport(DLLName)] public static extern int ENgetlinknodes(int index, ref int fromnode, ref int tonode); // 获得管段参数 [DllImport(DLLName)] public static extern int ENgetlinkvalue(int index, int paramcode, ref float value); // 设置管段类型 [DllImport(DLLName)] public static extern int ENgetlinktype(int index, ref int typecode); #endregion #region 模式 // 获取模式id [DllImport(DLLName)] public static extern int ENgetpatternindex(string nodeid, ref int patternindex); // 增加新的时间模式 [DllImport(DLLName)] public static extern int ENaddpattern(string timeid); // 设置时间模式的值 [DllImport(DLLName)] public static extern int ENsetpatternvalue(int index, int period, float value); [DllImport(DLLName)] public static extern int ENsetpattern(int index, float[] values, int n); public static int ENsetpatternvalue(string timeid, int period, float value) { int patternid = 0; ENgetpatternindex(timeid, ref patternid); return ENsetpatternvalue(patternid, period, value); } #endregion #region 计算控制 //epanet 完全模拟函数 [DllImport(DLLName)] public static extern int ENepanet(string f1, string f2, string f3, IntPtr vfunc); // 关闭管网文件 [DllImport(DLLName)] public static extern int ENclose(); // 关闭水力模拟系统,释放内存 [DllImport(DLLName)] public static extern int ENcloseH(); // 关闭水质模拟系统,释放内存 [DllImport(DLLName)] public static extern int ENcloseQ(); // 调用打开管网文件 [DllImport(DLLName)] public static extern int ENopen(string f1, string f2, string f3); // 调用打开水力分析系统 [DllImport(DLLName)] public static extern int ENopenH(); // 调用打开水力分析系统 [DllImport(DLLName)] public static extern int ENopenQ(); /// /// 调用初始化水力计算系统 /// /// 0-1标志,说明分析结果是否以均匀报告时段保存到EPANETH二进制输出文件。 /// 返回错误编号,0表示无错误 [DllImport(DLLName)] public static extern int ENinitH(int saveflag); // 调用运行水力计算 [DllImport(DLLName)] public static extern int ENrunH(ref int t1); // 水力计算步长 [DllImport(DLLName)] public static extern int ENnextH(ref int tstep1); // 调用初始化水质计算系统 [DllImport(DLLName)] public static extern int ENinitQ(int saveflag); // 调用运行水力计算 [DllImport(DLLName)] public static extern int ENrunQ(ref int t1); // 水力计算步长 [DllImport(DLLName)] public static extern int ENnextQ(ref int tstep1); // 全部水力模拟 [DllImport(DLLName)] public static extern int ENsolveH(); // 全部水质模拟 [DllImport(DLLName)] public static extern int ENsolveQ(); // 生成报告 [DllImport(DLLName)] public static extern int ENsaveH(); #endregion #region 报告 // 生成报告 [DllImport(DLLName)] public static extern int ENreport(); // 重置报告 [DllImport(DLLName)] public static extern int ENresetreport(); // 重置报告 [DllImport(DLLName)] public static extern int ENsetreport(string x); #endregion #region 其他 // 获取管网元件数 [DllImport(DLLName)] public static extern int ENgetcount(int countcode, ref int count); // 获取错误信息 [DllImport(DLLName)] public static extern int ENgeterror(int errcode, StringBuilder errmsg, int nchar); // 输出文件信息 [DllImport(DLLName)] public static extern int ENsaveinpfile(string filename); // 获取简单控制状态的参数 [DllImport(DLLName)] public static extern int ENgetcontrol(int cindex, ref int ctype, ref int index, ref float setting, ref int nindex, ref float level); // 设置选项 [DllImport(DLLName)] public static extern int ENsetoption(int code, float v); // 设置水质类型 [DllImport(DLLName)] public static extern int ENsetqualtype(int qualcode, string chemname, string chemunits, string tracenode); #endregion //补充 [DllImport(DLLName)] public static extern int ENsetinistatus(string id, string value); } }