#define EPA2_2 //EPA2_0
#if !TYPES_H
#define TYPES_H
#endif
//C++ TO C# CONVERTER WARNING: The following #include directive was ignored:
//#include "hash.h"
//
//-------------------------------------------
// Definition of 4-byte integers & reals
//-------------------------------------------
//
//
//----------------------------------------------
// Various constants
//----------------------------------------------
//
#define CODEVERSION
#define MAGICNUMBER
#define ENGINE_VERSION
#define EOFMARK
#define MAXTITLE
#define TITLELEN
#define MAXID
#define MAXMSG
#define MAXLINE
#define MAXFNAME
#define MAXTOKS
#define TRUE
#define FALSE
#define FULL
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define BIG 1.E10
#define BIG
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define TINY 1.E-6
#define TINY
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define MISSING -1.E10
#define MISSING
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define DIFFUS 1.3E-8
#define DIFFUS
// @ 20 deg C (sq ft/sec)
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define VISCOS 1.1E-5
#define VISCOS
// @ 20 deg C (sq ft/sec)
#define MINPDIFF
#define SEPSTR
#if M_PI
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define PI M_PI
#define PI
#else
#define PI
#endif
//
//----------------------------------------------
// Flow units conversion factors
//----------------------------------------------
//
#define GPMperCFS
#define AFDperCFS
#define MGDperCFS
#define IMGDperCFS
#define LPSperCFS
#define LPMperCFS
#define CMHperCFS
#define CMDperCFS
#define MLDperCFS
#define M3perFT3
#define LperFT3
#define MperFT
#define PSIperFT
#define KPAperPSI
#define KWperHP
#define SECperDAY
//
//---------------------------------------------------------------------
// Macros to test for successful allocation of memory and to free it
//---------------------------------------------------------------------
//
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define MEMCHECK(x) (((x) == NULL) ? 101 : 0 )
#define MEMCHECK
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define FREE(x) do { free(x); (x) = NULL; } while(0)
#define FREE
//
//---------------------------------------------------------------------
// Conversion macros to be used in place of functions
//---------------------------------------------------------------------
//
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define INT(x) ((int)(x))
#define INT
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define FRAC(x) ((x)-(int)(x))
#define FRAC
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define ABS(x) (((x)<0) ? -(x) : (x))
#define ABS
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define MIN(x,y) (((x)<=(y)) ? (x) : (y))
#define MIN
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define MAX(x,y) (((x)>=(y)) ? (x) : (y))
#define MAX
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define ROUND(x) (((x)>=0) ? (int)((x)+.5) : (int)((x)-.5))
#define ROUND
// round-off of x
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define MOD(x,y) ((x)%(y))
#define MOD
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define SQR(x) ((x)*(x))
#define SQR
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define SGN(x) (((x)<0) ? (-1) : (1))
#define SGN
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define UCHAR(x) (((x) >= 'a' && (x) <= 'z') ? ((x)&~32) : (x))
#define UCHAR
// uppercase char of x
//
//------------------------------------------------------
// Macro to evaluate function x with error checking
// (Fatal errors are numbered higher than 100)
//------------------------------------------------------
//
//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define ERRCODE(x) (errcode = ((errcode>100) ? (errcode) : (x)))
#define ERRCODE
//
//----------------------------------------------
// Enumerated Data Types
//----------------------------------------------
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Eptools
{
public enum ObjectType : int
{
NODE,
LINK,
TIMEPAT,
CURVE,
CONTROL,
RULE
}
public enum NodeType : int
{
JUNCTION,
RESERVOIR,
TANK
}
public enum LinkType : int
{
CVPIPE, // pipe with check valve
PIPE, // pipe
PUMP, // pump
PRV, // pressure reducing valve
PSV, // pressure sustaining valve
PBV, // pressure breaker valve
FCV, // flow control valve
TCV, // throttle control valve
GPV // general purpose valve
}
public enum HydFiletype : int
{
USE, // use hydraulics file from previous run
SAVE, // save hydraulics file after current run
SCRATCH // use temporary hydraulics file
}
public enum QualType : int
{
NONE, // no quality analysis
CHEM, // analyze a chemical
AGE, // analyze water age
TRACE // trace % of flow from a source
}
public enum CurveType : int
{
VOLUME_CURVE, // volume curve
PUMP_CURVE, // pump curve
EFFIC_CURVE, // efficiency curve
HLOSS_CURVE, // head loss curve
GENERIC_CURVE // generic curve
}
public enum PumpType : int
{
CONST_HP, // constant horsepower
POWER_FUNC, // power function
CUSTOM, // user-defined custom curve
NOCURVE
}
public enum SourceType : int
{
CONCEN, // inflow concentration
MASS, // mass inflow booster
SETPOINT, // setpoint booster
FLOWPACED // flow paced booster
}
public enum ControlType : int
{
LOWLEVEL, // act when grade below set level
HILEVEL, // act when grade above set level
TIMER, // act when set time reached
TIMEOFDAY // act when time of day occurs
}
public enum StatusType : int
{
XHEAD, // pump cannot deliver head (closed)
TEMPCLOSED, // temporarily closed
CLOSED, // closed
OPEN, // open
ACTIVE, // valve active (partially open)
XFLOW, // pump exceeds maximum flow
XFCV, // FCV cannot supply flow
XPRESSURE, // valve cannot supply pressure
FILLING, // tank filling
EMPTYING, // tank emptying
OVERFLOWING // tank overflowing
}
public enum HeadLossType : int
{
HW, // Hazen-Williams
DW, // Darcy-Weisbach
CM // Chezy-Manning
}
public enum UnitsType : int
{
US, // US
SI // SI (metric)
}
public enum FlowUnitsType : int
{
CFS, // cubic feet per second
GPM, // gallons per minute
MGD, // million gallons per day
IMGD, // imperial million gal. per day
AFD, // acre-feet per day
LPS, // liters per second
LPM, // liters per minute
MLD, // megaliters per day
CMH, // cubic meters per hour
CMD // cubic meters per day
}
public enum PressureUnitsType : int
{
PSI, // pounds per square inch
KPA, // kiloPascals
METERS // meters
}
public enum RangeType : int
{
LOW, // lower limit
HI, // upper limit
PREC // precision
}
public enum MixType : int
{
MIX1, // complete mix model
MIX2, // 2-compartment model
FIFO, // first in, first out model
LIFO // last in, first out model
}
public enum StatisticType : int
{
SERIES, // point time series
AVG, // time-averages
MIN, // minimum values
MAX, // maximum values
RANGE // max - min values
}
public enum FieldType : int
{
ELEV = 0, // nodal elevation
DEMAND, // nodal demand flow
HEAD, // nodal hydraulic head
PRESSURE, // nodal pressure
QUALITY, // nodal water quality
LENGTH, // link length
DIAM, // link diameter
FLOW, // link flow rate
VELOCITY, // link flow velocity
HEADLOSS, // link head loss
LINKQUAL, // avg. water quality in link
STATUS, // link status
SETTING, // pump/valve setting
REACTRATE, // avg. reaction rate in link
FRICTION, // link friction factor
POWER, // pump power output
TIME, // simulation time
VOLUME, // tank volume
CLOCKTIME, // simulation time of day
FILLTIME, // time to fill a tank
DRAINTIME, // time to drain a tank
MAXVAR // total number of variable fields
}
public enum SectionType : int
{
_TITLE,
_JUNCTIONS,
_RESERVOIRS,
_TANKS,
_PIPES,
_PUMPS,
_VALVES,
_CONTROLS,
_RULES,
_DEMANDS,
_SOURCES,
_EMITTERS,
_PATTERNS,
_CURVES,
_QUALITY,
_STATUS,
_ROUGHNESS,
_ENERGY,
_REACTIONS,
_MIXING,
_REPORT,
_TIMES,
_OPTIONS,
_COORDS,
_VERTICES,
_LABELS,
_BACKDROP,
_TAGS,
_END
}
public enum HdrType : int
{
STATHDR, // hydraulic status header
ENERHDR, // energy usage header
NODEHDR, // node results header
LINKHDR // link results header
}
public enum FlowDirection : int
{
NEGATIVE = -1, // flow in reverse of pre-assigned direction
ZERO_FLOW = 0, // zero flow
POSITIVE = 1 // flow in pre-assigned direction
}
public enum DemandModelType : int
{
DDA, // demand driven analysis
PDA // pressure driven analysis
}
//
//------------------------------------------------------
// Fundamental Data Structures
//------------------------------------------------------
//
[StructLayout(LayoutKind.Sequential)]
public struct IDstring // Holds component ID label
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXID + 1)]
public string ID;//= new string(new char[EpanetBaseMul.MAXID + 1]);
}
[StructLayout(LayoutKind.Sequential)]
public struct Spattern // Time Pattern Object
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXID + 1)]
public string ID;//= new string(new char[EpanetBaseMul.MAXID + 1]); // pattern ID
public string Comment; // pattern comment
public int Length; // pattern length
public double F; // pattern factors
}
[StructLayout(LayoutKind.Sequential)]
public struct Scurve // Curve Object
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXID + 1)]
public string ID;//= new string(new char[EpanetBaseMul.MAXID + 1]); // curve ID
public string Comment; // curve comment
public CurveType Type;//= new CurveType(); // curve type
public int Npts; // number of points
public int Capacity; // size of X & Y arrays
public double X; // x-values
public double Y; // y-values
}
[StructLayout(LayoutKind.Sequential)]
unsafe public struct Sdemand // Demand List Item
{
public double Base; // baseline demand
public int Pat; // pattern index
public string Name; // demand category name
public Sdemand *next; // next demand list item
}
[StructLayout(LayoutKind.Sequential)]
public struct Senergy // Energy Usage Object
{
public double TimeOnLine; // hours pump is online
public double Efficiency; // total time wtd. efficiency
public double KwHrsPerFlow; // total kw-hrs per unit of flow
public double KwHrs; // total kw-hrs consumed
public double MaxKwatts; // max. kw consumed
public double TotalCost; // total pumping cost
}
[StructLayout(LayoutKind.Sequential)]
public struct Ssource // Water Quality Source Object
{
public double C0; // base concentration/mass
public int Pat; // pattern index
public double Smass; // actual mass flow rate
public SourceType Type;//= new SourceType(); // type of source
}
[StructLayout(LayoutKind.Sequential)]
public struct Svertices // Coordinates of a link's vertices
{
public double X; // array of x-coordinates
public double Y; // array of y-coordinates
public int Npts; // number of vertex points
public int Capacity; // capacity of coordinate arrays
}
[StructLayout(LayoutKind.Sequential)]
public struct Snode // Node Object
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXID + 1)]
public string ID;//= new string(new char[EpanetBaseMul.MAXID + 1]); // node ID
public double X; // x-coordinate
public double Y; // y-coordinate
public double El; // elevation
public Sdemand D; // demand pointer
public Ssource S; // source pointer
public double C0; // initial quality
public double Ke; // emitter coeff.
public int Rpt; // reporting flag
public int ResultIndex; // saved result index
public NodeType Type;//= new NodeType(); // node type
public string Comment; // node comment
}
[StructLayout(LayoutKind.Sequential)]
public struct Slink // Link Object
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXID + 1)]
public string ID;//= new string(new char[EpanetBaseMul.MAXID + 1]); // link ID
public int N1; // start node index
public int N2; // end node index
public double Diam; // diameter
public double Len; // length
public double Kc; // roughness
public double Km; // minor loss coeff.
public double Kb; // bulk react. coeff.
public double Kw; // wall react. coef.
public double R; // flow resistance
public double Rc; // reaction coeff.
public LinkType Type;//= new LinkType(); // link type
public StatusType Status;//= new StatusType(); // initial status
public Svertices Vertices; // internal vertex coordinates
public int Rpt; // reporting flag
public int ResultIndex; // saved result index
public string Comment; // link comment
}
[StructLayout(LayoutKind.Sequential)]
public struct Stank // Tank Object
{
public int Node; // node index of tank
public double A; // tank area
public double Hmin; // minimum water elev
public double Hmax; // maximum water elev
public double H0; // initial water elev
public double Vmin; // minimum volume
public double Vmax; // maximum volume
public double V0; // initial volume
public double Kb; // bulk reaction coeff.
public double V; // tank volume
public double C; // concentration
public int Pat; // fixed grade time pattern
public int Vcurve; // volume v. elev. curve index
public MixType MixModel;// = new MixType(); // type of mixing model
public double V1max; // mixing compartment size
public int CanOverflow; // tank can overflow or not
public Stank(int Node, double A, double Hmin, double Hmax, double H0, double Vmin, double Vmax, double V0, double Kb, double V, double C, int Pat, int Vcurve, double V1max, int CanOverflow)
{
this.Node = Node;
this.A = A;
this.Hmin = Hmin;
this.Hmax = Hmax;
this.H0 = H0;
this.Vmin = Vmin;
this.Vmax = Vmax;
this.V0 = V0;
this.Kb = Kb;
this.V = V;
this.C = C;
this.Pat = Pat;
this.Vcurve = Vcurve;
MixModel = new MixType();
this.V1max = V1max;
this.CanOverflow = CanOverflow;
}
}
[StructLayout(LayoutKind.Sequential)]
public struct Spump // Pump Object
{
public int Link; // link index of pump
public int Ptype; // pump curve type
public double Q0; // initial flow
public double Qmax; // maximum flow
public double Hmax; // maximum head
public double H0; // shutoff head
public double R; // flow coeffic.
public double N; // flow exponent
public int Hcurve; // head v. flow curve index
public int Ecurve; // effic. v. flow curve index
public int Upat; // utilization pattern index
public int Epat; // energy cost pattern index
public double Ecost; // unit energy cost
public Senergy Energy;//= new Senergy(); // energy usage statistics
public Spump(int Link, int Ptype, double Q0, double Qmax, double Hmax, double H0, double R, double N, int Hcurve, int Ecurve, int Upat, int Epat, double Ecost)
{
this.Link = Link;
this.Ptype = Ptype;
this.Q0 = Q0;
this.Qmax = Qmax;
this.Hmax = Hmax;
this.H0 = H0;
this.R = R;
this.N = N;
this.Hcurve = Hcurve;
this.Ecurve = Ecurve;
this.Upat = Upat;
this.Epat = Epat;
this.Ecost = Ecost;
Energy= new Senergy();
}
}
[StructLayout(LayoutKind.Sequential)]
public struct Svalve // Valve Object
{
public int Link; // link index of valve
}
[StructLayout(LayoutKind.Sequential)]
public struct Scontrol // Control Statement
{
public int Link; // link index
public int Node; // control node index
public int Time; // control time
public double Grade; // control grade
public double Setting; // new link setting
public StatusType Status;// = new StatusType(); // new link status
public ControlType Type;// = new ControlType(); // control type
public Scontrol(int Link, int Node, int Time, double Grade, double Setting)
{
this.Link = Link;
this.Node = Node;
this.Time = Time;
this.Grade = Grade;
this.Setting = Setting;
Status = new StatusType();
Type= new ControlType();
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SField // Field Object of Report Table
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXID + 1)]
public string Name;//= new string(new char[EpanetBaseMul.MAXID + 1]); // name of reported variable
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXID + 1)]
public string Units;//= new string(new char[EpanetBaseMul.MAXID + 1]); // units of reported variable
public int Enabled; // enabled if in table
public int Precision; // number of decimal places
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public double[] RptLim;//= new double[2]; // lower/upper report limits
public SField( int Enabled, int Precision)
{
Name = new string(new char[EpanetBaseMul.MAXID + 1]);
Units = new string(new char[EpanetBaseMul.MAXID + 1]);
this.Enabled = Enabled;
this.Precision = Precision;
RptLim = new double[2]; // lower/upper report limits
}
}
[StructLayout(LayoutKind.Sequential)]
unsafe public struct Sadjlist // Node Adjacency List Item
{
public int node; // index of connecting node
public int link; // index of connecting link
public Sadjlist *next; // next item in list
}
[StructLayout(LayoutKind.Sequential)]
unsafe public struct Sseg // Pipe Segment List Item
{
public double v; // segment volume
public double c; // segment water quality
public Sseg *prev; // previous segment in list
}
[StructLayout(LayoutKind.Sequential)]
unsafe public struct s_Premise // Rule Premise Clause
{
public int logop; // logical operator (IF, AND, OR)
public int @object; // NODE or LINK
public int index; // object's index
public int variable; // pressure, flow, etc.
public int relop; // relational operator (=, >, <, etc.)
public int status; // variable's status (OPEN, CLOSED)
public double @value; // variable's value
public s_Premise *next; // next premise clause
}
[StructLayout(LayoutKind.Sequential)]
unsafe public struct s_Action // Rule Action Clause
{
public int link; // link index
public int status; // link's status
public double setting; // link's setting
public s_Action *next;
}
[StructLayout(LayoutKind.Sequential)]
unsafe public struct Srule // Control Rule Structure
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXID + 1)]
public string label;//= new string(new char[EpanetBaseMul.MAXID + 1]); // rule label
public double priority; // priority level
public s_Premise *Premises; // list of premises
public s_Action *ThenActions; // list of THEN actions
public s_Action *ElseActions; // list of ELSE actions
}
[StructLayout(LayoutKind.Sequential)]
unsafe public struct s_ActionItem // Action List Item
{
public int ruleIndex; // index of rule action belongs to
public s_Action *action; // an action clause
public s_ActionItem *next; // next action on the list
}
[StructLayout(LayoutKind.Sequential)]
public struct SmassBalance // Mass Balance Components
{
public double initial; // initial mass in system
public double inflow; // mass inflow to system
public double outflow; // mass outflow from system
public double reacted; // mass reacted in system
public double final; // final mass in system
public double ratio; // ratio of mass added to mass lost
}
//
//------------------------------------------------------
// Wrapper Data Structures
//------------------------------------------------------
//
// Input File Parser Wrapper
[StructLayout(LayoutKind.Sequential)]
unsafe public struct Parser
{
public FILE InFile; // Input file handle
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXID + 1)]
public string DefPatID;//= new string(new char[EpanetBaseMul.MAXID + 1]); // Full line comment
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXFNAME + 1)]
public string InpFname;//= new string(new char[EpanetBaseMul.MAXFNAME + 1]);
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXTOKS + 1)]
public string[] Tok;//= new string[EpanetBaseMul.MAXTOKS];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXMSG + 1)]
public string Comment;// = new string(new char[EpanetBaseMul.MAXMSG + 1]);
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXMSG + 1)]
public string LineComment;// = new string(new char[EpanetBaseMul.MAXMSG + 1]);
public int MaxNodes; // Default demand pattern
public int MaxLinks;
public int MaxJuncs;
public int MaxPipes;
public int MaxTanks;
public int MaxPumps;
public int MaxValves;
public int MaxControls;
public int MaxRules;
public int MaxPats;
public int MaxCurves;
public int Ntokens;
public int Ntitle;
public int ErrTok;
public int Unitsflag;
public int Flowflag;
public int Pressflag;
public int DefPat;
public Spattern *PrevPat; // Previous pattern processed
public Scurve *PrevCurve; // Previous curve processed
public double X; // Temporary array for curve data
}
// Time Step Wrapper
[StructLayout(LayoutKind.Sequential)]
public struct Times
{
public int Tstart; // Duration of simulation
public int Hstep;
public int Pstep;
public int Pstart;
public int Rstep;
public int Rstart;
public int Rtime;
public int Htime;
public int Hydstep;
public int Qstep;
public int Qtime;
public int Rulestep;
public int Dur;
}
[StructLayout(LayoutKind.Sequential)]
unsafe public struct FILE
{
public IntPtr *_Placeholder;
}
// Reporting Wrapper
[StructLayout(LayoutKind.Sequential)]
public struct Report
{
public FILE RptFile; // Report file handle
public int Nperiods; // File write error flag
public int PageSize;
public int Rptflag;
public int Tstatflag;
public int Summaryflag;
public int Messageflag;
public int Statflag;
public int Energyflag;
public int Nodeflag;
public int Linkflag;
public int Fprinterr;
public int LineNum; // Current page number
public int PageNum;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 13)]
public string Atime;//= new string(new char[13]); // Current date & time
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXFNAME + 1)]
public string Rpt1Fname;// = new string(new char[EpanetBaseMul.MAXFNAME + 1]);
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXFNAME + 1)]
public string Rpt2Fname;//= new string(new char[EpanetBaseMul.MAXFNAME + 1]);
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 26)]
public string DateStamp;//= new string(new char[26]);
public SField[] Field;//= new SField[(int)EpanetBaseMul.MAXVAR]; // Output reporting fields
}
// Output File Wrapper
[StructLayout(LayoutKind.Sequential)]
public struct Outfile
{
public string HydFname;//= new string(new char[EpanetBaseMul.MAXFNAME + 1]); // Binary output file name
public string OutFname;//= new string(new char[EpanetBaseMul.MAXFNAME + 1]);
public int Outflag; // General purpose save flag
public int Hydflag;
public int SaveHflag;
public int SaveQflag;
public int Saveflag;
public int HydOffset; // 2nd output file byte offset
public int OutOffset1;
public int OutOffset2;
public FILE OutFile; // Temporary file handle
public FILE HydFile;
public FILE TmpOutFile;
}
// Rule-Based Controls Wrapper
[StructLayout(LayoutKind.Sequential)]
public struct Rules
{
public s_ActionItem ActionList; // Linked list of action items
public int RuleState; // State of rule interpreter
public int Errcode; // Rule parser error code
public int Time1; // Start of rule evaluation time interval
public s_Premise LastPremise; // Previous premise clause
public s_Action LastThenAction; // Previous THEN action
public s_Action LastElseAction; // Previous ELSE action
}
// Sparse Matrix Wrapper
[StructLayout(LayoutKind.Sequential)]
public struct Smatrix
{
public double Aii; // Array used by linear eqn. solver
public double Aij;
public double F;
public double temp;
public int Ncoeffs; // Array used by linear eqn. solver
public int Order;
public int Row;
public int Ndx;
public int XLNZ;
public int NZSUB;
public int LNZ;
public int Degree;
public int link;
public int first;
}
// Hydraulics Solver Wrapper
[StructLayout(LayoutKind.Sequential)]
public struct Hydraul
{
public double NodeHead; // Inflow - outflow at each node
public double NodeDemand;
public double DemandFlow;
public double EmitterFlow;
public double LinkFlow;
public double LinkSetting;
public double Htol;
public double Qtol;
public double RQtol;
public double Hexp;
public double Qexp;
public double Pexp;
public double Pmin;
public double Preq;
public double Dmult;
public double Hacc;
public double FlowChangeLimit;
public double HeadErrorLimit;
public double DampLimit;
public double Viscos;
public double SpGrav;
public double Epump;
public double Dsystem;
public double Ecost;
public double Dcost;
public double Emax;
public double RelativeError;
public double MaxHeadError;
public double MaxFlowChange;
public double DemandReduction;
public double RelaxFactor;
public double P;
public double Y;
public double Xflow;
public int Epat; // Number of pressure deficient nodes
public int DemandModel;
public int Formflag;
public int Iterations;
public int MaxIter;
public int ExtraIter;
public int CheckFreq;
public int MaxCheck;
public int OpenHflag;
public int Haltflag;
public int DeficientNodes;
public StatusType LinkStatus; // Previous link/tank status
public StatusType OldStatus;
public Smatrix smatrix;//= new Smatrix(); // Sparse matrix storage
}
// Forward declaration of the Mempool structure defined in mempool.h
//C++ TO C# CONVERTER NOTE: C# has no need of forward class declarations:
//struct Mempool;
// Water Quality Solver Wrapper
[StructLayout(LayoutKind.Sequential)]
unsafe public struct MemBlock
{
public MemBlock *next; // Next block
public string block; // block + block size
public string free;
public string end;
}
[StructLayout(LayoutKind.Sequential)]
public struct Mempool
{
public MemBlock first;
public MemBlock current;
}
[StructLayout(LayoutKind.Sequential)]
public struct Quality
{
public int Qualflag; // Topologically sorted node indexes
public int OpenQflag;
public int Reactflag;
public int OutOfMemory;
public int TraceNode;
public int SortedNodes;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXID + 1)]
public string ChemName;//= new string(new char[EpanetBaseMul.MAXID + 1]); // Units of chemical
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXID + 1)]
public string ChemUnits;//= new string(new char[EpanetBaseMul.MAXID + 1]);
public double Ctol; // Pipe reaction rate coeffs.
public double Diffus;
public double Wbulk;
public double Wwall;
public double Wtank;
public double Wsource;
public double Rfactor;
public double Sc;
public double Bucf;
public double Tucf;
public double BulkOrder;
public double WallOrder;
public double TankOrder;
public double Kbulk;
public double Kwall;
public double Climit;
public double SourceQual;
public double NodeQual;
public double PipeRateCoeff;
public Mempool SegPool; // Memory pool for water quality segments
public Sseg FreeSeg; // Last (upstream) segment in each pipe
public Sseg[] FirstSeg;
public Sseg[] LastSeg;
public FlowDirection FlowDir; // Flow direction for each pipe
public SmassBalance MassBalance;//= new SmassBalance(); // Mass balance components
}
[StructLayout(LayoutKind.Sequential)]
unsafe public struct HashTable
{
public string key;
public int data;
public HashTable *next;
}
// Pipe Network Wrapper
[StructLayout(LayoutKind.Sequential)]
unsafe public struct Network
{
public int Nnodes; // Number of data curves
public int Ntanks;
public int Njuncs;
public int Nlinks;
public int Npipes;
public int Npumps;
public int Nvalves;
public int Ncontrols;
public int Nrules;
public int Npats;
public int Ncurves;
public Snode *Node; // Node array
public Slink *Link; // Link array
public Stank *Tank; // Tank array
public Spump *Pump; // Pump array
public Svalve *Valve; // Valve array
public Spattern *Pattern; // Time pattern array
public Scurve *Curve; // Data curve array
public Scontrol *Control; // Simple controls array
public Srule *Rule; // Rule-based controls array
public HashTable *NodeHashTable; // Hash table for Link ID names
public HashTable *LinkHashTable;
public Sadjlist *Adjlist;// = new Sadjlist(); // Node adjacency lists
}
// Overall Project Wrapper
[StructLayout(LayoutKind.Sequential)]
public struct Project
{
public Network network;// = new Network(); // Pipe network wrapper
public Parser parser;// = new Parser(); // Input file parser wrapper
public Times times;// = new Times(); // Time step wrapper
public Report report;// = new Report(); // Reporting wrapper
public Outfile outfile;// = new Outfile(); // Output file wrapper
public Rules rules;// = new Rules(); // Rule-based controls wrapper
public Hydraul hydraul;// = new Hydraul(); // Hydraulics solver wrapper
public Quality quality;// = new Quality(); // Water quality solver wrapper
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXVAR)]
public double[] Ucf;// = new double[(int)EpanetBaseMul.MAXVAR]; // Unit conversion factors
public int Openflag; // Warning flag
public int Warnflag;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXMSG + 1)]
public string Msg;//= new string(new char[EpanetBaseMul.MAXMSG + 1]); // Temporary statistic file name
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXTITLE)]
public string[] Title;//= new string[EpanetBaseMul.MAXTITLE];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXFNAME + 1)]
public string MapFname;//= new string(new char[EpanetBaseMul.MAXFNAME + 1]);
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXFNAME + 1)]
public string TmpHydFname;//= new string(new char[EpanetBaseMul.MAXFNAME + 1]);
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXFNAME + 1)]
public string TmpOutFname;//= new string(new char[EpanetBaseMul.MAXFNAME + 1]);
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EpanetBaseMul.MAXFNAME + 1)]
public string TmpStatFname;//= new string(new char[EpanetBaseMul.MAXFNAME + 1]);
public delegate void viewprogDelegate(sbyte NamelessParameter); // Pointer to progress viewing function
public viewprogDelegate viewprog;
}
public class EpanetBaseMul
{
public const int MAXTITLE = 3;// Max. # title lines
public const int TITLELEN = 79;// Max. # characters in a title line
public const int MAXID = 31;// Max. # characters in ID name
public const int MAXMSG = 255;// Max. # characters in message text
public const int MAXLINE = 1024;// Max. # characters read from input line
public const int MAXFNAME = 259;// Max. # characters in file name
public const int MAXTOKS = 40;// Max. items per line of input
public const int TRUE = 1;
public const int FALSE = 0;
public const int FULL = 2;
public const int MAXVAR = 21;
//public const int BIG =1.0E10 ;
//public const double TINY = 1.0E-6;
//public const double MISSING =-1.0E10 ;// Missing value indicator
//public const double DIFFUS =1.3E-8 ;// Diffusivity of chlorine
// // @ 20 deg C (sq ft/sec)
//public const double VISCOS =1.10E-5 ;// Kinematic viscosity of water
// // @ 20 deg C (sq ft/sec)
//public const double MINPDIFF =0.1 ;// PDA min. pressure difference (psi or m)
//public const string SEPSTR = " \t\n\r";// Token separator characters
const string DLLName = "epanet2.2.dll";
//{ These are codes used by the DLL functions }
#region 节点
// 获取节点参数值
[DllImport(DLLName)]
public static extern int EN_getnodevalue(ref Project p, int index, int paramcode, ref float value);
// 获取节点类型
[DllImport(DLLName)]
public static extern int EN_getnodetype(ref Project p, int index, ref int typecode);
// 获取节点编号
[DllImport(DLLName)]
public static extern int EN_getnodeindex(ref Project p, string nodeid, ref int nodeindex);
// 获取节点 id
[DllImport(DLLName)]
public static extern int EN_getnodeid(ref Project p, int index, StringBuilder id);
// 设置节点参数
[DllImport(DLLName)]
public static extern int EN_setnodevalue(ref Project p, int index, int paramcode, float value);
#endregion
#region 管段
// 设置管段参数
[DllImport(DLLName)]
public static extern int EN_setlinkvalue(ref Project p, int index, int paramcode, float value);
// 获取管段 id
[DllImport(DLLName)]
public static extern int EN_getlinkid(ref Project p, int index, StringBuilder id);
// 获取管段 id
[DllImport(DLLName)]
public static extern int EN_getlinkindex(ref Project p, string id, ref int index);
// 获取管段节点
[DllImport(DLLName)]
public static extern int EN_getlinknodes(ref Project p, int index, ref int fromnode, ref int tonode);
// 获得管段参数
[DllImport(DLLName)]
public static extern int EN_getlinkvalue(ref Project p, int index, int paramcode, ref float value);
// 设置管段类型
[DllImport(DLLName)]
public static extern int EN_getlinktype(ref Project p, int index, ref int typecode);
#endregion
#region 模式
// 获取模式id
[DllImport(DLLName)]
public static extern int EN_getpatternindex(ref Project p, string nodeid, ref int patternindex);
// 增加新的时间模式
[DllImport(DLLName)]
public static extern int EN_addpattern(ref Project p, string timeid);
// 设置时间模式的值
[DllImport(DLLName)]
public static extern int EN_setpatternvalue(ref Project p, int index, int period, float value);
[DllImport(DLLName)]
public static extern int EN_setpattern(ref Project p, int index, float[] values, int n);
public static int EN_setpatternvalue(ref Project p, string timeid, int period, float value)
{
int patternid = 0;
EN_getpatternindex(ref p, timeid, ref patternid);
return EN_setpatternvalue(ref p, patternid, period, value);
}
#endregion
#region 计算控制
//epanet 完全模拟函数
[DllImport(DLLName)]
public static extern int EN_epanet(ref Project p, string f1, string f2, string f3, IntPtr vfunc);
// 关闭管网文件
[DllImport(DLLName)]
public static extern int EN_close(ref Project p);
// 关闭水力模拟系统,释放内存
[DllImport(DLLName)]
public static extern int EN_closeH(ref Project p);
// 关闭水质模拟系统,释放内存
[DllImport(DLLName)]
public static extern int EN_closeQ(ref Project p);
// 调用打开管网文件
[DllImport(DLLName)]
public static extern int EN_open(ref Project p, string f1, string f2, string f3);
// 调用打开水力分析系统
[DllImport(DLLName)]
public static extern int EN_openH(ref Project p);
// 调用打开水力分析系统
[DllImport(DLLName)]
public static extern int EN_openQ(ref Project p);
///
/// 调用初始化水力计算系统
///
/// 0-1标志,说明分析结果是否以均匀报告时段保存到EPANETH二进制输出文件。
/// 返回错误编号,0表示无错误
[DllImport(DLLName)]
public static extern int EN_initH(ref Project p, int saveflag);
// 调用运行水力计算
[DllImport(DLLName)]
public static extern int EN_runH(ref Project p, ref int t1);
// 水力计算步长
[DllImport(DLLName)]
public static extern int EN_nextH(ref Project p, ref int tstep1);
// 调用初始化水质计算系统
[DllImport(DLLName)]
public static extern int EN_initQ(ref Project p, int saveflag);
// 调用运行水力计算
[DllImport(DLLName)]
public static extern int EN_runQ(ref Project p, ref int t1);
// 水力计算步长
[DllImport(DLLName)]
public static extern int EN_nextQ(ref Project p, ref int tstep1);
// 全部水力模拟
[DllImport(DLLName)]
public static extern int EN_solveH(ref Project p);
// 全部水质模拟
[DllImport(DLLName)]
public static extern int EN_solveQ(ref Project p);
// 生成报告
[DllImport(DLLName)]
public static extern int EN_saveH(ref Project p);
#endregion
#region 报告
// 生成报告
[DllImport(DLLName)]
public static extern int EN_report(ref Project p);
// 重置报告
[DllImport(DLLName)]
public static extern int EN_resetreport(ref Project p);
// 重置报告
[DllImport(DLLName)]
public static extern int EN_setreport(ref Project p, string x);
#endregion
#region 其他
// 获取管网元件数
[DllImport(DLLName)]
public static extern int EN_getcount(ref Project p, int countcode, ref int count);
// 获取错误信息
[DllImport(DLLName)]
public static extern int EN_geterror(ref Project p, int errcode, StringBuilder errmsg, int nchar);
// 输出文件信息
[DllImport(DLLName)]
public static extern int EN_saveinpfile(ref Project p, string filename);
// 获取简单控制状态的参数
[DllImport(DLLName)]
public static extern int EN_getcontrol(ref Project p, int cindex, ref int ctype, ref int index, ref
float setting, ref int nindex, ref float level);
// 设置选项
[DllImport(DLLName)]
public static extern int EN_setoption(ref Project p, int code, float v);
// 设置水质类型
[DllImport(DLLName)]
public static extern int EN_setqualtype(ref Project p, int qualcode, string chemname,
string chemunits, string tracenode);
#endregion
//补充
[DllImport(DLLName)]
public static extern int EN_setinistatus(string id, string value);
}
}