using AStation.Epanet.Enums;
using System.Runtime.InteropServices;
using System.Text;
namespace AStation.Epanet
{
///
/// AStation.Epanet 程序员工具包(EPANET2.2.DLL)中的函数声明。
/// 这些是构成 DLL 的外部函数。
///
public class EpanetMethods
{
/// 文件名称 ("epanet2.2.dll").
private const string EPANETDLL = "epanet2.2.dll";
/// Epanet dll 调用约定
private const CallingConvention CONVENTION = CallingConvention.StdCall;
/// Epanet dll 方法的字符串字符集
private const CharSet CHARSET = CharSet.Ansi;
/// Epanet dll 的字符串类型
private const UnmanagedType STRING = UnmanagedType.LPStr;
// private const int MAXFNAME = 259;
/// Epanet dll id 字符串(Node.Id、Link.Id 等)的最大字符数
public const int MAXID = 31;
/// Epanet dll 错误字符串的最大字符数,*.inp 文件中的行数。
public const int MAXMSG = 79;
/// Delegate for progress callback.
/// 从 AStation.Epanet dll 传递的状态信息。
[UnmanagedFunctionPointer(CONVENTION)]
public delegate void ViewProgCallback([MarshalAs(STRING)] string message);
#region 打开和关闭 AStation.Epanet 系统的功能
/// 执行完整的EPANETH模拟
/// 输入文件名
/// 输出报告文件名
/// 可选二进制输出文件名
///
/// Pointer to a user-supplied function () which accepts
/// a character string as its argument; see note below.
///
/// 错误代码
///
///
/// The argument is a pointer to a callback
/// function that takes a character string (char *) as its only parameter.
/// The function would reside in and be used by the calling
/// program to display the progress messages that AStation.Epanet generates
/// as it carries out its computations. If this feature is not
/// needed then the argument should be null.
///
///
/// ENepanet is a stand-alone function and does not interact with
/// any of the other functions in the toolkit.
///
///
/// If there is no need to save AStation.Epanet's binary output file
/// then can be an empty string ("").
///
///
/// The vfunc function pointer allows the calling program
/// to display a progress message generated by AStation.Epanet during its
/// computations.
///
///
/// A typical function for a console application might look as follows:
///
/// static void WriteConsole(string s) {
/// System.Console.WriteLine(s);
/// }
///
/// and somewhere in the calling program the following declarations would appear:
///
/// Pviewprog vfunc = WriteConsole;
/// ENepanet(f1, f2, f3, vfunc);
///
/// If such a function is not desired then this argument should be null.
///
///
/// is used mainly to link the AStation.Epanet engine to third-party
/// user interfaces that build network input files and display the results of a
/// network analysis.
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true, CharSet = CHARSET,
BestFitMapping = false, ThrowOnUnmappableChar = true)]
public static extern ErrorCode ENepanet(
[MarshalAs(STRING)] string f1,
[MarshalAs(STRING)] string f2,
[MarshalAs(STRING), Optional, DefaultParameterValue("")] string f3,
[Optional, DefaultParameterValue(null)] ViewProgCallback pviewprog);
/// 打开工具箱,为了分析特定配水系统
/// 输入文件名
/// 输出报告文件名
/// 可选二进制输出文件名
/// 错误代码
///
/// If there is no need to save AStation.Epanet's binary Output file
/// then can be an empty string ("").
/// must be called before any of the other
/// toolkit functions (except ) are used.
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true, CharSet = CHARSET,
BestFitMapping = false, ThrowOnUnmappableChar = true), PreserveSig]
public static extern ErrorCode ENopen(
[MarshalAs(STRING)] string f1,
[MarshalAs(STRING)] string f2,
[MarshalAs(STRING), Optional, DefaultParameterValue("")] string f3);
/// 将所有当前管网输入数据写入到文件,利用EPANETH输入文件的格式
/// 数据保存的文件名
/// 错误代码
///
/// The data saved reflect any changes made by calls to
/// the ENsetxxx family of functions since AStation.Epanet
/// data was first loaded using .
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true, CharSet = CHARSET,
BestFitMapping = false, ThrowOnUnmappableChar = true)]
public static extern ErrorCode ENsaveinpfile([MarshalAs(STRING)] string filename);
/// 关闭工具箱系统(包括所有正在处理的文件)
/// 错误代码
///
/// must be called when all processing has been completed,
/// even if an error condition was encountered.
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENclose();
#endregion
#region 运行水力分析的功能
///
/// 执行一次完整的水力模拟,所有时段的结果写入二进制水力文件
///
/// 错误代码
///
/// 利用产生独立完整的水力结果,或者作为水质分析的输入。为了将水力结果写入
/// 报告文件,其后也调入到和。
/// 不要使用 , , , , 和
/// 连接到。
///
///
///
/// ENopen("net1.inp", "net1.rpt", "");
/// ENsolveH();
/// ENsolveQ();
/// ENreport();
/// ENclose();
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENsolveH();
///
/// 将水力模拟结果从二进制水力文件转换到二进制输出文件,其中结果仅仅以均匀时间间隔进行报告
///
/// 错误代码
///
///
/// 仅在水力分析后执行,并在均匀报告间隔的结果需要转换为EPANETH的二进制
/// 输出文件时使用。这种情况,利用将输出报告写入EPANETH报告文件。
///
///
/// 在EPANETH输入文件([TIMES]节)或者通过利用函数,可以设置报告时间。
///
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENsaveH();
/// 打开水力分析系统
/// 错误代码
///
///
/// 在第一次执行水力分析之前调用,
/// 利用 - - 系列。
/// 在调用,以关闭水力分析系统之前,可以进行多次分析。
///
///
/// 如果用于运行完整的水力分析,不要调用该函数。
///
///
///
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENopenH();
/// 在执行水力分析之前,初始化蓄水池水位、管段状态和设置,以及模拟钟表时间
///
/// 0-1标志,说明水力结果是否保存到水力文件
///
/// 错误代码
///
///
/// 利用和.执行水力分析之前,应调用。
/// 调用之前,必须已经调用。
/// 如果整个水力分析调用了,将不再调用。
///
///
/// 如果将进行随后的水质运行,saveflag 设置为1,利用产生报告,
/// 或者利用保存二进制水力文件。
///
///
///
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENinitH(int saveflag);
/// 执行简单时段水力分析,检索当前模拟钟表时间
///
/// 当前模拟钟表时间,以秒计 (no need to supply a value for ).
///
/// 错误代码
///
///
/// 利用结合在do ..while循环中,为了分析延时模拟中每一时段的水力特性。
/// 该过程自动更新模拟钟表时间,因此将t处理为只读变量。
///
///
/// 在执行 – 循环以前,必须调用。
/// 对于该函数使用的例子,参见。
///
///
///
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENrunH(out int t);
///
/// 确定延时模拟下一次水力时间发生前的时间长度
///
///
/// 时间(以秒计),直到下一次水力时间发生;或者为0,如果在模拟时段的末端。
///
/// 错误代码
///
///
/// 该函数与一起使用,执行延时水力分析(见以下例子)
///
///
/// tstep的数值,应处理为只读变量。作为以下较小值自动计算:
///
/// - 时间间隔,直到下一水力时间步长开始;
/// - 时间间隔,直到下一报告时间步长开始;
/// - 时间间隔,直到下一需水量发生改变开始;
/// - 时间间隔,直到水池注满或者排空;
/// - 时间间隔,直到规则控制停止;
///
///
///
///
///
/// int t, tstep;
///
/// ENopenH();
/// ENinitH(0);
///
/// do {
/// ENrunH(out t);
/// /* Retrieve hydraulic results for time t */
/// ENnextH(out tstep);
/// } while (tstep > 0);
///
/// ENcloseH();
///
///
///
///
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENnextH(out int tstep);
/// 关闭水力分析系统,释放所有分配内存
/// 错误代码
///
/// 在利用 - - 执行所有水力分析之后,调用。
/// 如果使用 ,不要调用该函数。
///
///
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENcloseH();
/// 将当前二进制水力文件的内容保存到一个文件
/// 水力结果应被保存的文件名
/// 错误代码
///
///
/// 将该函数用于将当前水力结果集保存到一个文件,便于后处理或者以后时间使用,通过调用函数
///
///
/// 水力文件包含了节点需水量和水头,以及管段流量,状态和设置,对于所有水力时间步长,甚至中间数值。
///
///
/// 调用该函数之前,水力结果必须产生和保存,通过调用
/// 或者 - - 序列,
/// 具有的保存标志参数设置为1(true)。
///
///
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true, CharSet = CHARSET,
BestFitMapping = false, ThrowOnUnmappableChar = true)]
public static extern ErrorCode ENsavehydfile([MarshalAs(STRING)] string fileName);
/// 将指定文件的内容作为当前二进制水力文件
/// 含了当前管网水力分析结果的文件名
/// 错误代码
///
///
/// 调用该函数,拒绝原先保存的水力分析结果集。
/// 这些结果被检查,为了查看是否它们匹配一下参数,相关于当前被分析的管网:节点总数、水池和水库总数、管段总数、水泵总数、阀门总数和模拟历时。
///
///
/// 当水力分析系统仍旧开启时,不能够调用该函数(即已经被调用,但是 还没有)。
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true, CharSet = CHARSET,
BestFitMapping = false, ThrowOnUnmappableChar = true)]
public static extern ErrorCode ENusehydfile([MarshalAs(STRING)] string fileName);
#endregion
#region 运行水质分析的功能
///
/// 执行完整的水质模拟,结果具有均匀报告间隔,写入EPANETH二进制输出文件
///
/// 错误代码
///
/// 在调用之前,必须已经执行水力分析,并保存到二进制水力文件。
/// 为了将水力和水质结果写入报告文件,后面跟着调用。
/// 不能够将, , , 和,与一起使用。
///
///
///
/// ENopen("net1.inp", "net1.rpt", "");
/// ENsolveH();
/// ENsolveQ();
/// ENreport();
/// ENclose();
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENsolveQ();
/// 打开水质分析系统
/// 错误代码
///
///
/// 调用之前,首先执行水质分析,依次利用 - - (or )。
/// 为了关闭水质分析系统调用之前,可以进行多重水质分析。
///
/// 如果利用进行完整水质分析,不要调用该函数。
///
///
///
///
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENopenQ();
/// 在执行水质分析之前,初始化水质和模拟钟表时间
///
/// 0-1标志,说明分析结果是否以均匀报告时段保存到EPANETH二进制输出文件。
///
/// 错误代码
///
///
/// 在利用联合或者执行水质分析之前,调用。
///
///
/// 必须在调用之前调用。
/// 如果调用执行完整水质分析,不需调用。
///
///
/// 如果希望利用产生报告,或者希望将计算结果保存为二进制输出文件,设置 saveflag为1。
///
///
///
///
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENinitQ(int saveFlag);
///
/// 在下一时段水质分析的开始,使水力和水质分析结果可用,其中时段的开始返回为.
///
///
/// 当前模拟钟表时间,以秒计 (no need to supply a value for ).
///
/// 错误代码
///
///
/// 在do...while循环中利用和,为了访问延时模拟每一水力时段开始时的水质结果。
/// 或者在do...while循环中将它与一起使用,为了访问每一水质时间步长开始时的结果。
/// 怎样编制这种循环的例子,参见每一函数说明。
///
///
/// 在执行 - (or )循环之前,必须调用。
///
///
/// 模拟的当前时刻由保存在水力分析中的信息确定,然后进行水质分析。它为只读变量。
///
///
///
///
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENrunQ(out int t);
/// 水质模拟前进到下一水力时段的开始
///
/// 时刻(以秒计),直到下一水力事件发生;或者为零,如果在模拟时段的末端
///
/// 错误代码
///
///
/// 该函数用在do...while循环中,利用执行延时水质分析。
/// 允许在模拟的每一水力时段访问水质结果。
/// 水质演算和反应以更小的时间步长,在内部执行。
/// 利用代替该函数,如果需要访问每一水质事件步长后的结果。
///
///
/// 的值是根据水质分析之前的水力分析所保存的信息确定的。将其视为只读变量。
///
///
///
///
/// int t, tstep;
/// ENsolveH(); /* Generate and save hydraulics */
/// ENopenQ();
/// ENinitQ(false);
///
/// do {
/// ENrunQ(out t);
/// /* Monitor results at time t, which */
/// /* begins a new hydraulic time period */
/// ENnextQ(out tstep);
/// } while (tstep > 0);
///
/// ENcloseQ();
///
///
///
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENnextQ(out int tstep);
///
/// 水质模拟前进一个水质时间步长。保留整个模拟中的时间范围在中
///
/// 保留在整个模拟历时中的秒。 机翻:总模拟时间的剩余秒数
/// 错误代码
///
///
/// 该函数用在的do...while循环中,执行延时水质模拟。
/// 允许访问模拟每一水质时间步长的水质结果,而不是像的每一水力时段的开始。
///
///
/// 使用参数,确定何时不再需要调用,因为达到模拟时段的末尾(即当tleft = 0 时)。
///
///
/// 将 处理为只读变量(不需要赋值)。
///
///
///
///
/// int t, tleft;
///
/// ENsolveH(); /* Generate & save hydraulics */
/// ENopenQ();
/// ENinitQ(false);
///
/// do {
/// ENrunQ(out t);
/// /* Monitor results at time t */
/// ENstepQ(out tleft);
/// } while (tleft > 0);
///
/// ENcloseQ();
///
///
///
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENstepQ(out int tleft);
/// 关闭水质分析系统,释放所有分配的内存
/// 错误代码
///
/// 在利用 - -
/// (or ) 系列函数调用执行所有水质分析之后,调用。
/// 如果使用了,将不需要调用该函数。
///
///
///
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENcloseQ();
#endregion
#region 生成输出报告的功能
/// 将一行文本写入报告文件
/// 文本
/// 错误代码
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true, CharSet = CHARSET,
BestFitMapping = false, ThrowOnUnmappableChar = true)]
public static extern ErrorCode ENwriteline([MarshalAs(STRING)] string line);
/// 将模拟结果的格式化文本报告写入到报告文件
/// 错误代码
///
///
/// 调用之前,必须已经进行了完整的水力分析或者完整的水力水质分析,结果保存在文件中。
/// 在前者情况中,也必须首先调用,为了将结果从水力文件转换到输出文件。
///
///
/// 报告的格式受到EPANETH输入文件[REPORT]节的命令所控制,或者通过与 函数一起公布的类似命令。
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENreport();
/// 将报告选项重置为默认值
/// 错误代码
///
///
/// 清除任何出现在EPANETH输入文件[REPORT]节中的报告格式命令,或者利用函数所公布的
///
/// 调用该函数后,默认报告选项生效。
///
/// 这些为:
///
/// - 没有状态报告
/// - 没有能量报告
/// - 没有节点报告
/// - 没有管段报告
/// - 节点变量报告为2位小数位
/// - 管段变量报告为两位小数位 (摩擦因子为3位)
/// - 报告的节点变量为标高、水头、压强和水质
/// - 报告的管段变量为流量、流速和水头损失
///
///
///
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENresetreport();
/// 公布报告格式命令,格式命令与EPANETH输入文件的[REPORT]节中使用的相同
/// 报告格式命令文本
/// 错误代码
///
///
/// 调用,明确原来报告格式命令,出现在输入文件中,或者通过调用 或者 公布
///
///
/// 模拟的格式结果可以写入到报告文件,利用函数
///
///
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true, CharSet = CHARSET,
BestFitMapping = false, ThrowOnUnmappableChar = true)]
public static extern ErrorCode ENsetreport([MarshalAs(STRING)] string command);
#endregion
#region 检索network信息的功能
///
/// 读取分配给最近一次 更新源代码的编号。
/// 该编号由常量 CODEVERSION 设置的,从 20001 开始, 每更新一次增加 1.
///
/// Version number of the source code.
/// 错误代码 (should always be 0).
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENgetversion(out int v);
///
/// 检索简单控制语句的参数。
/// 控制的索引在以及剩余的参数返回控制参数。
///
///
/// 控制语句索引 (控制是从1开始的索引,次序为输入到EPENETH输入文件的[CONTROLS]节中)
///
/// 控制类型代码
/// 控制管段的索引
/// 控制设置数值
/// 控制节点的索引
/// Index of controlling node (0 for
/// or control).
///
///
/// 对于基于时间控制的控制行为(以秒计)的控制水位或者水位控制的压力或者控制时间的数值
///
/// 错误代码
///
///
/// Controls are indexed starting from 1 in the order in which they were
/// entered into the [CONTROLS] section of the AStation.Epanet input file.
///
///
/// 对于管道,设置为0,意味着管道被关闭;为1意味着它是开启的。
/// 对于水泵,设置包含了水泵转速,为0,意味着水泵被关闭,为1意味着处于常规转速。
/// 对于阀门,设置是指阀门的压力、流量或者损失系数值,取决于阀门类型
///
///
/// 对于计时器或者钟表时间控制,nindex参数等于0
///
///
/// See for an example of using this function.
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENgetcontrol(
int cindex,
out ControlType ctype,
out int lindex,
out float setting,
out int nindex,
out float level);
/// 检索指定类型的管网组件数量
/// 组件编号
/// 管网中countcode组件的数量
/// 错误代码
///
///
/// 管网中连接节点的数量等于节点总数减去水池和水库总数。
///
///
/// 对于在输入文件描述的组件,工具箱内没有设施添加或者删除功能。
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENgetcount(CountType code, out int count);
/// 检索特定分析选项的数值
/// 选项编号
/// 选项值
/// 错误代码
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENgetoption(MiscOption code, out float value);
/// 检索指定分析时间参数的数值
/// 时间参数编号
/// 参数值
/// 错误代码
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENgettimeparam(TimeParameter code, out int value);
/// 检索表明使用单位的代码数,为了表达所有流量
/// 流量范围代码号的数值
/// 错误代码
///
///
/// 在EPANETH输入文件的[OPTIONS]节指定流量单位。
///
///
/// 流量单位取升或者立方米,说明所有其它量将采用公制单位;否则使用美制单位。(见计量单位)。
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENgetflowunits(out FlowUnitsType code);
/// 检索特定时间模式的索引
/// 模式ID
/// 模式索引
/// 错误代码
/// 模式索引是从1开始的连续整数
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true, CharSet = CHARSET,
BestFitMapping = false, ThrowOnUnmappableChar = true)]
public static extern ErrorCode ENgetpatternindex([MarshalAs(STRING)] string id, out int index);
/// 检索特定时间模式的ID标签
/// 模式索引
/// 模式ID
/// 错误代码
///
/// must be able to hold characters.
/// 模式索引是从1开始的连续整数
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENgetpatternid(int index, [MarshalAs(STRING)] StringBuilder id);
/// 检索特定时间模式中的时段总数
/// 模式索引
/// 模式中时段总数
/// 错误代码
/// 模式索引是从1开始的连续整数
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENgetpatternlen(int index, out int len);
/// 检索时间模式中特定时段的乘子
/// 模式索引
/// 时间模式范围内的时段
/// 时段的乘子
/// 错误代码
/// 模式索引和时段是从1开始的连续整数
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENgetpatternvalue(int index, int period, out float value);
/// 检索调用水质分析的类型
/// 水质分析代码
/// 源头跟踪分子中跟踪的节点索引
/// 错误代码
///
/// 当qualcode不为EN_TRACE时,tracenode的数值将为0
/// The value will be 0 when
/// is not .
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENgetqualtype(out QualType qualcode, out int tracenode);
/// 检索与特定错误或者警告代码相关的信息文本
/// 错误或者警告代码
/// 对应于errcode的错误或者警告信息的文本
/// errmsg 的最大长度 (should be characters).
/// 错误代码
/// 错误信息字符串的长度至少应为 个字符.
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true, BestFitMapping = false,
ThrowOnUnmappableChar = true)]
public static extern ErrorCode ENgeterror(ErrorCode err, [MarshalAs(STRING), Out] StringBuilder errmsg, int n);
#endregion
#region 检索node数据的功能
/// 检索具有指定ID的节点索引
/// 节点ID
/// 节点索引
/// 错误代码
/// 节点索引是从1开始的连续整数
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true, CharSet = CHARSET,
BestFitMapping = false, ThrowOnUnmappableChar = true)]
public static extern ErrorCode ENgetnodeindex([MarshalAs(STRING)] string id, out int index);
///
/// 检索具有指定索引的ID标签
///
/// 节点索引
/// 节点ID
/// 错误代码
///
/// must be able to hold characters.
/// 节点索引是从1开始的连续整数
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true, BestFitMapping = false,
ThrowOnUnmappableChar = true)]
public static extern ErrorCode ENgetnodeid(int index, [MarshalAs(STRING), Out] StringBuilder id);
///
/// 检索指定节点的节点类型编号
///
/// 节点索引
/// 节点类型编号
/// 错误代码
/// 节点索引是从1开始的连续整数
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENgetnodetype(int index, out NodeType code);
///
/// 检索特定管段参数值
///
/// 节点索引
/// 节点参数代号
/// 参数值
/// 错误代码
///
///
/// 节点索引是从1开始的连续整数
///
///
/// 返回值的单位取决于在 AStation.Epanet 输入文件中用于流量的单位。
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENgetnodevalue(int index, NodeValue code, out float value);
#endregion
#region 检索link数据的功能
///
/// 检索具有特定ID的管段索引
///
/// 管段ID
/// 管段索引
/// 错误代码
/// 管段索引是从1开始的连续整数
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true, CharSet = CHARSET,
BestFitMapping = false, ThrowOnUnmappableChar = true)]
public static extern ErrorCode ENgetlinkindex([MarshalAs(STRING)] string id, out int index);
/// 检索具有特定指标的管段的ID标签
/// 管段索引
/// 管段ID
/// 错误代码
///
/// must be able to hold characters.
/// 管段索引是从1开始的连续整数
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true, BestFitMapping = false,
ThrowOnUnmappableChar = true)]
public static extern ErrorCode ENgetlinkid(int index, [MarshalAs(STRING), Out] StringBuilder id);
/// 检索特定管段的类型编号
/// 管段索引
/// 管段类型代号
/// 错误代码
/// 管段索引是从1开始的连续整数
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENgetlinktype(int index, out LinkType code);
///
/// 检索指定管段端点节点的索引
///
/// 管段索引
/// 管段起始节点索引
/// 管段终止节点索引
/// 错误代码
///
/// 节点和管段索引是从1开始的连续整数
///
/// 管段起始和终止节点定义在EPANETH输入文件中。
/// 没有考虑管段的实际流向。
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENgetlinknodes(int index, out int fnode, out int tnode);
///
/// 检索指定管段参数值
///
/// 管段索引
/// 管段参数代号
/// 参数值
/// 错误代码
///
/// 管段索引是从1开始的连续整数
///
/// EN_DIAMETER 0 直径
/// EN_LENGTH 1 长度
/// EN_ROUGHNESS 2 粗糙系数
/// EN_MINORLOSS 3 局部损失系数
/// EN_INITSTATUS 4 初始管段状态 (0 = 关闭, 1 = 开启)
/// EN_INITSETTING 5 初始管道粗糙度初始水泵转速初始阀门设置
/// EN_KBULK 6 主流反应系数
/// EN_KWALL 7 管壁反应系数
/// EN_FLOW 8 流量
/// EN_VELOCITY 9 流速
/// EN_HEADLOSS 10 水头损失
/// EN_STATUS 11 实际管段状态 (0 = 关闭, 1 = 开启)
/// EN_SETTING 12 管道粗糙系数实际水泵转速实际阀门设置
/// EN_ENERGY 13 消耗能量,以千瓦计
/// (参数8 - 13 (EN_FLOW到EN_ENERGY)为计算值。其他为设计参数)
///
///
/// 如果从指定管段起始节点流向指定终止节点,流量为正;否则为负。
/// 返回的数值单位,取决于EPANETH输入文件中流量使用的单位。
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENgetlinkvalue(int index, LinkValue code, out float value);
#endregion
#region 更改network数据的功能
/// 设置特定简单控制语句的参数
///
/// 控制索引是从1开始的,顺序中它们被输入,在EPANETH的输入文件的[CONTROLS]节。
///
/// 控制类型代码
/// 被控制管段的索引
/// 控制设置的数值
/// 控制节点的索引
/// index of controlling node (0 for
/// or control)
///
///
/// 对于水位控制的控制水位或者压力的数值,或者控制行为的时间(以秒计),对于基于时间的控制
///
/// 错误代码
///
///
/// 对于管道, setting为0,意味着管道关闭,为1意味着它是开启的。
/// 对于水泵, setting包含了水泵转速,为0意味着水泵关闭,为1意味着在常规转速下开启。
/// 对于阀门, setting指阀门压力、流量或者损失系数,取决于阀门类型。
///
///
/// 对于计时器或者钟表时间控制,设置 参数为0
///
///
/// 对于水位控制,如果控制节点 为水池,那么level参数应为高于池底的水位(而不是标高)。否则level应为连接节点压力。
///
///
/// 为除去关于特定管段的控制,设置参数为0。函数中其它参数的数值将被忽略。
///
///
///
/// 本例将ENgetcontrol and ENsetcontrol用于改变节点的低水位设置,控制管段,具有索引 thelink 到新的数值newlevel。
/// This example uses and
/// to change the low level setting on the node that controls a link with
/// index thelink to a new value newlevel.
///
/// int numctrls, lindex, nindex, thelink = 1;
/// float setting, level, newlevel = 1f;
/// ControlType ctype;
///
/// ENgetcount(CountType.Control, out numctrls);
///
/// for (int i = 1; i <= numctrls; i++) {
/// ENgetcontrol(i, out ctype, out lindex, out setting, out nindex, out level);
/// if (ctype == ControlType.Lowlevel && lindex == thelink) {
/// ENsetcontrol(i, ctype, lindex, setting, nindex, newlevel);
/// break;
/// }
/// }
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENsetcontrol(
int cindex,
ControlType ctype,
int lindex,
float setting,
int nindex,
float level);
///
/// 设置特定节点的参数值
///
/// 节点索引
/// 节点参数代码
/// parameter value
/// 错误代码
///
/// 节点索引是从1开始的连续整数
///
/// 提供的数值单位取决于在 AStation.Epanet 输入文件中用于流量的单位。
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENsetnodevalue(int index, NodeValue code, float v);
///
/// 设置指定管段的参数值
///
/// 管段索引
/// 节点参数代码
/// parameter value
/// 错误代码
///
/// 管段索引是从1开始的连续整数
///
/// 数值单位取决于在EPANETH输入文件中使用的流量范围(参见计量单位)
///
///
///
/// ps(pdf):对于存在的管段状态或者设置,在模拟开始之前,利用EN_INITSTATUS和 EN_INITSETTING设置设计数值。
/// 在模拟执行的同时,利用EN_STATUS和EN_SETTING 改变这些数值(在ENrunH - ENnextH循环范围内)。
///
/// ps(英文翻译):使用 和
/// 设置link状态或设置的设计值,这些值在仿真开始前就已存在。 使用 和
/// 可以在运行仿真时(在 - 循环内)更改这些值。
///
/// Use and
/// to set the design value for a link's status or setting that exists prior to the
/// start of a simulation. Use and
/// to change these values while a simulation
/// is being run (within the - loop).
///
///
///
/// 如果控制阀具有明确的状态,设置为或者。
/// 需要再次启用,在模拟过程中必须采用参数提供虚拟的阀门设置数值。
/// 对于管道或者用于改变粗糙系数。
///
///
/// For pipes, either
/// or can be used to change roughness.
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENsetlinkvalue(int index, LinkValue code, float v);
///
/// 添加一个新的时间模式,附加到现有模式的末尾
///
/// 新模式的 ID 名称
/// 错误代码
///
/// ID 标签应包含不超过 31 个字符
/// 新模式将包含一个时间段,其乘数系数为 1
///
/// 使用 函数,首先用 函数获取模式的索引,然后用一组特定的乘数填充模式。
///
///
///
///
/// string patId = "NewPattern";
/// float[] patFactors = new[] {0.8f, 1.1f, 1.4f, 1.1f, 0.8f, 0.7f};
/// int patIndex;
/// ENaddpattern(patId);
/// ENgetpatternindex(patId, out patIndex);
/// ENsetpattern(patIndex, patFactors, 6);
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true, CharSet = CHARSET,
BestFitMapping = false, ThrowOnUnmappableChar = true)]
public static extern ErrorCode ENsetpattern([MarshalAs(STRING)] string id);
///
/// 设置指定时间模式的所有乘子
///
/// 时间模式索引
/// 整个模式的乘子
/// 模式中因子总数
/// 错误代码
///
/// 模式索引是从1开始的连续整数
///
/// Factors点到基于零的数组,包含了nfactors的元素
///
///
/// 使用该函数重新定义(和重新设置尺寸)时间模式;利用,修改模式指定时段的模式因子。
///
///
///
///
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENsetpattern(
int index,
[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.R4, SizeParamIndex = 2), In] float[] f,
int n);
///
/// 设置时间模式内特定时段的乘子因子
///
/// 时间模式索引
/// 时间模式内的时段
/// 时段的乘子因子
/// 错误代码
///
/// 模式索引是从1开始的连续整数
///
/// 利用 重新设置时间模式内的所有因子.
///
///
///
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENsetpatternvalue(int index, int period, float value);
/// 设置时间参数值
/// 时间参数代码
/// 时间参数值,以秒计
/// 错误代码
///
/// Do not change time parameters after calling in a
/// hydraulic analysis or in a water quality analysis.
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENsettimeparam(TimeParameter code, int value);
/// 设置特定分析选项的数值
/// 选项编号
/// 选项值
/// 错误代码
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENsetoption(MiscOption code, float v);
/// 设置水力状态报告的水平
/// 状态报告的水平
/// 错误代码
///
///
/// 当水力模拟逐渐展开时,状态报告将管网元素的水力状态变化写入到报告文件
/// 具有三种水平的报告:
///
/// - 无状态报告
/// - 常规报告
/// - 完整状态报告
///
///
///
/// 完整状态报告包含了求解系统水力方程组,在模拟的每一时间步长的收敛信息。主要用于调试目的。
///
///
/// 如果将在应用程序中执行许多次水力分析,建议状态报告关闭( = )。
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true)]
public static extern ErrorCode ENsetstatusreport(StatusLevel statuslevel);
/// 设置被调用水质分析的类型
/// 水质分析代码
/// 被分析化学成分名称
/// 化学成分计量单位
/// 源头跟踪分析中被跟踪节点的ID
/// 错误代码
///
///
/// 如果不进行化学成分分析,化学成分名称和单位可以为空字符串。如果不进行源头跟踪分析,跟踪节点保留名称。
///
///
/// 注意跟踪节点通过ID指定而不是索引。
///
///
///
[DllImport(EPANETDLL, CallingConvention = CONVENTION, ExactSpelling = true, CharSet = CHARSET,
BestFitMapping = false, ThrowOnUnmappableChar = true)]
public static extern ErrorCode ENsetqualtype(
QualType qualcode,
[MarshalAs(STRING), Optional, DefaultParameterValue("")] string chemname,
[MarshalAs(STRING), Optional, DefaultParameterValue("")] string chemunits,
[MarshalAs(STRING), Optional, DefaultParameterValue("")] string tracenode);
#endregion
}
}