using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HStation.RevitDev.RevitDataExport { public enum NodeValueType { 标高 = 0, // { Mode parameters } 基本需水量 = 1, 需水量模式 = 2, 扩散器系数 = 3, 初始物质浓度 = 4, 输入物质浓度 = 5, 浓度模式 = 6, 水源类型 = 7, 水池水位 = 8, 需水量 = 9, 绝对压力 = 10, 自由压力 = 11, 物质浓度 = 12, 物质扩散浓度 = 13, 初始容积 = 14, 多物质混合模型 = 15, 多物质混合容积 = 16, } public enum LinkValueType { 管径 = 0, // { Link parameters } 管长 = 1, 海森威廉系数 = 2, 局部水头损失 = 3, 初始状态 = 4, 初始设置 = 5, 水体反应系数 = 6, 管壁反应系数 = 7, 流量 = 8, 流速 = 9, 水损 = 10, 状态 = 11, 设置 = 12, 功率 = 13, } public class Epanet2 { 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 } } public static class Const_statuslevel { public const int EN_NONE = 0; public const int EN_NORMAL = 0; public const int EN_FULL = 0; } } static int ProjectCount = 0; public void Dispose() { Epanet2.ProjectCount--; } int projectID; public int GetProjectID() { return projectID; } public Epanet2() { this.projectID = ProjectCount; Epanet2.ProjectCount++; } // 获取节点参数值 public int getnodevalue(int index, int paramcode, ref float value) { return EpanetBase2_2.ENgetnodevalue22(projectID, index, paramcode, ref value); } // 获取节点类型 public float getvalue(string ID, int paramcode) { int err = 0; int index = 0; err = getnodeindex(ID, ref index); float value = 0; if (index > 0) { err = getnodevalue(index, paramcode, ref value); } else { err = getlinkindex(ID, ref index); err = getlinkvalue(index, paramcode, ref value); } return value; } public float getvalue(string ID, int paramcode, bool isNode) { int err = 0; int index = 0; float value = 0; if (isNode) { err = getnodeindex(ID, ref index); if (index > 0) err = getnodevalue(index, paramcode, ref value); } else { err = getlinkindex(ID, ref index); if (index > 0) err = getlinkvalue(index, paramcode, ref value); } return value; } public int setvalue(string ID, int paramcode, double value, bool isNode) { int err = 0; int index = 0; if (isNode) { err = getnodeindex(ID, ref index); if (index > 0) err = setnodevalue(index, paramcode, (float)value); } else { err = getlinkindex(ID, ref index); if (index > 0) err = setlinkvalue(index, paramcode, (float)value); } return err; } public int getnodetype(int index, ref int typecode) { return EpanetBase2_2.ENgetnodetype22(projectID, index, ref typecode); } // 获取节点编号 public int getnodeindex(string nodeid, ref int nodeindex) { return EpanetBase2_2.ENgetnodeindex22(projectID, nodeid, ref nodeindex); } // 获取节点 id public int getnodeid(int index, StringBuilder id) { return EpanetBase2_2.ENgetnodeid22(projectID, index, id); } public int getnodecomment(int index, StringBuilder id) { return EpanetBase2_2.ENgetnodecomment22(projectID, index, id); } public int addnode(string id, int nodeType, ref int index) { return EpanetBase2_2.ENaddnode22(projectID, id, nodeType, ref index); } public int getcoord(int index, ref double x, ref double y) { return EpanetBase2_2.ENgetcoord22(projectID, index, ref x, ref y); } public int setcoord(int index, double x, double y) { return EpanetBase2_2.ENsetcoord22(projectID, index, x, y); } // 设置节点参数 public int setnodevalue(int index, int paramcode, float value) { return EpanetBase2_2.ENsetnodevalue22(projectID, index, paramcode, value); } #region 管段 // 设置管段参数 public int setlinkvalue(int index, int paramcode, float value) { return EpanetBase2_2.ENsetlinkvalue22(projectID, index, paramcode, value); } // 获取管段 id public int getlinkid(int index, StringBuilder id) { return EpanetBase2_2.ENgetlinkid22(projectID, index, id); } public int getlinkcomment(int index, StringBuilder id) { return EpanetBase2_2.ENgetlinkcomment22(projectID, index, id); } // 获取管段 id public int getlinkindex(string id, ref int index) { return EpanetBase2_2.ENgetlinkindex22(projectID, id, ref index); } // 获取管段节点 public int getlinknodes(int index, ref int fromnode, ref int tonode) { return EpanetBase2_2.ENgetlinknodes22(projectID, index, ref fromnode, ref tonode); } // 获得管段参数 public int getlinkvalue(int index, int paramcode, ref float value) { return EpanetBase2_2.ENgetlinkvalue22(projectID, index, paramcode, ref value); } // 设置管段类型 public int getlinktype(int index, ref int typecode) { return EpanetBase2_2.ENgetlinktype22(projectID, index, ref typecode); } // 增加管线 public int addlink(string id, int linkType, string fromNode, string toNode, ref int index) { return EpanetBase2_2.ENaddlink22(projectID, id, linkType, fromNode, toNode, ref index); } #endregion #region 模式 // 获取模式id public int getpatternindex(string patternID, ref int patternindex) { return EpanetBase2_2.ENgetpatternindex22(projectID, patternID, ref patternindex); } // 增加新的时间模式 public int addpattern(string patternID) { return EpanetBase2_2.ENaddpattern22(projectID, patternID); } // 设置时间模式的值 public int setpatternvalue(int index, int period, float value) { return EpanetBase2_2.ENsetpatternvalue22(projectID, index, period, value); } public int setpatternvalue_ex(string patternID, int period, float value) { return EpanetBase2_2.ENsetpatternvalue_ex(projectID, patternID, period, value); } public int setpattern(int index, float[] values, int n) { return EpanetBase2_2.ENsetpattern22(projectID, index, values, n); } /// /// 加强版添加模式,如果模式名称不存在,则自动新增模式;新增完后,自定绑定节点 /// /// /// /// /// /// public int setpatternvalue_ex(string nodeID, string patternID, double[] values) { return EpanetBase2_2.ENsetpatternvalue_ex(projectID, nodeID, patternID, values); } public int setcurve(int index, float[] Xvalues, float[] Yvalues, int n) { return EpanetBase2_2.ENsetcurve22(projectID, index, Xvalues, Yvalues, n); } #endregion #region 计算控制 //epanet 完全模拟函数 public int epanet(string f1, string f2, string f3, IntPtr vfunc) { return EpanetBase2_2.ENepanet22(projectID, f1, f2, f3, vfunc); } // 关闭管网文件 public int close() { return EpanetBase2_2.ENclose22(projectID); ProjectCount--; } // 关闭水力模拟系统,释放内存 public int closeH() { return EpanetBase2_2.ENcloseH22(projectID); } // 关闭水质模拟系统,释放内存 public int closeQ() { return EpanetBase2_2.ENcloseQ22(projectID); } // 调用打开管网文件 public int open(string f1, string f2, string f3) { return EpanetBase2_2.ENopen22(projectID, f1, f2, f3); } // 调用打开水力分析系统 public int openH() { return EpanetBase2_2.ENopenH22(projectID); } // 调用打开水力分析系统 public int openQ() { return EpanetBase2_2.ENopenQ22(projectID); } /// /// 调用初始化水力计算系统 /// /// 0-1标志,说明分析结果是否以均匀报告时段保存到EPANETH二进制输出文件。 /// 返回错误编号,0表示无错误 public int initH(int saveflag) { return EpanetBase2_2.ENinitH22(projectID, saveflag); } // 调用运行水力计算 public int runH(ref int t1) { return EpanetBase2_2.ENrunH22(projectID, ref t1); } // 水力计算步长 public int nextH(ref int tstep1) { return EpanetBase2_2.ENnextH22(projectID, ref tstep1); } // 调用初始化水质计算系统 public int initQ(int saveflag) { return EpanetBase2_2.ENinitQ22(projectID, saveflag); } // 调用运行水力计算 public int runQ(ref int t1) { return EpanetBase2_2.ENrunQ22(projectID, ref t1); } // 水力计算步长 public int nextQ(ref int tstep1) { return EpanetBase2_2.ENnextQ22(projectID, ref tstep1); } // 全部水力模拟 public int solveH() { return EpanetBase2_2.ENsolveH22(projectID); } // 全部水质模拟 public int solveQ() { return EpanetBase2_2.ENsolveQ22(projectID); } // 生成报告 public int saveH() { return EpanetBase2_2.ENsaveH22(projectID); } #endregion #region 报告 // 生成报告 public int report() { return EpanetBase2_2.ENreport22(projectID); } // 重置报告 public int resetreport() { return EpanetBase2_2.ENresetreport22(projectID); } // 重置报告 public int setreport(string x) { return EpanetBase2_2.ENsetreport22(projectID, x); } #endregion #region 其他 // 获取管网元件数 public int getcount(int countcode, ref int count) { return EpanetBase2_2.ENgetcount22(projectID, countcode, ref count); } // 获取错误信息 public string geterror() { //return EpanetBase2_2.ENgetErrorMsg22(projectID, errmsg, nchar); var nchar = 10000; //int code = 200; StringBuilder errmsg = new StringBuilder(); //为errmsg分配内存 errmsg.Capacity = nchar; var err = EpanetBase2_2.ENgetErrorMsg22(projectID, errmsg, nchar); string str = errmsg?.ToString(); if (string.IsNullOrEmpty(str)) return null; var errlines = str.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); //拼接errlines return "epaneterror:" + string.Join("\n", errlines); } // 输出文件信息 public int saveinpfile(string filename) { return EpanetBase2_2.ENsaveinpfile22(projectID, filename); } // 获取简单控制状态的参数 public int getcontrol(int cindex, ref int ctype, ref int index, ref float setting, ref int nindex, ref float level) { return EpanetBase2_2.ENgetcontrol22(projectID, cindex, ref ctype, ref index, ref setting, ref nindex, ref level); } // 设置选项 public int setoption(int code, float v) { return EpanetBase2_2.ENsetoption22(projectID, code, v); } public int setstatusreport(int code) { return EpanetBase2_2.ENsetstatusreport22(projectID, code); } public float getoption(int code) { float v = 0; EpanetBase2_2.ENgetoption22(projectID, code, ref v); return v; } // 设置选项 public int gettimeparam(int code, ref int v) { return EpanetBase2_2.ENgettimeparam22(projectID, code, ref v); } // 设置水质类型 public int setqualtype(int qualcode, string chemname, string chemunits, string tracenode) { return EpanetBase2_2.ENsetqualtype22(projectID, qualcode, chemname, chemunits, tracenode); } #endregion //补充 public int setinistatus(string id, string value) { return EpanetBase2_2.ENsetinistatus22(projectID, id, value); } //补充 public int setprojectreport(int value) { return EpanetBase2_2.ENsetprojectreport22(projectID, value); } public int getbasedemand(int nodeIndex, int demandIndex, out List baseDemand) { return EpanetBase2_2.ENgetbasedemand22(projectID, nodeIndex, demandIndex, out baseDemand); } //补充 public int getdemandpattern(int nodeIndex, int demandIndex, out List patIndex) { return EpanetBase2_2.ENgetdemandpattern22(projectID, nodeIndex, demandIndex, out patIndex); } public int getTotalDemand(int p, out double value) { return EpanetBase2_2.ENgetTotalDemand22(projectID, p, out value); } } }