|
|
@@ -0,0 +1,329 @@
|
|
|
+package com.shkpr.epanet.code;
|
|
|
+
|
|
|
+import com.sun.jna.Library;
|
|
|
+import com.sun.jna.Pointer;
|
|
|
+import com.sun.jna.ptr.IntByReference;
|
|
|
+import com.sun.jna.ptr.PointerByReference;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 本地库
|
|
|
+ *
|
|
|
+ * @author 欧阳劲驰
|
|
|
+ * @since 1.0.0
|
|
|
+ */
|
|
|
+public interface EpanetLibrary extends Library {
|
|
|
+ /*===================================================================
|
|
|
+ Project Functions
|
|
|
+ ===================================================================*/
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creates an EPANET project.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle that is passed into all other API functions.
|
|
|
+ * @return an error code.
|
|
|
+ * <p>
|
|
|
+ * EN_createproject must be called before any other API functions are used.
|
|
|
+ */
|
|
|
+ int EN_createproject(PointerByReference ph);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Deletes a currently opened EPANET project.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle which is returned as NULL.
|
|
|
+ * @return an error code.
|
|
|
+ * <p>
|
|
|
+ * EN_deleteproject should be called after all network analysis has been completed.
|
|
|
+ */
|
|
|
+ int EN_deleteproject(PointerByReference ph);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Runs a complete EPANET simulation.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @param inpFile the name of an existing EPANET-formatted input file.
|
|
|
+ * @param rptFile the name of a report file to be created (or "" if not needed)
|
|
|
+ * @param outFile the name of a binary output file to be created (or "" if not needed)
|
|
|
+ * @param pviewprog a callback function that takes a character string (char *) as its only parameter.
|
|
|
+ * @return an error code
|
|
|
+ * <p>
|
|
|
+ * The callback function should reside in and be used by the calling code to display
|
|
|
+ * the progress messages that EPANET generates as it carries out its computations.
|
|
|
+ */
|
|
|
+ int EN_runproject(Pointer ph, String inpFile, String rptFile, String outFile, Object pviewprog);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Initializes an EPANET project.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @param rptFile the name of a report file to be created (or "" if not needed).
|
|
|
+ * @param outFile the name of a binary output file to be created (or "" if not needed).
|
|
|
+ * @param unitsType the choice of flow units (see EN_FlowUnits).
|
|
|
+ * @param headLossType the choice of head loss formula (see EN_HeadLossType).
|
|
|
+ * @return an error code.
|
|
|
+ * <p>
|
|
|
+ * This function should be called immediately after EN_createproject if an EPANET-formatted input
|
|
|
+ * file will not be used to supply network data.
|
|
|
+ */
|
|
|
+ int EN_init(Pointer ph, String rptFile, String outFile, int unitsType, int headLossType);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Reads an EPANET input file with no errors allowed.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @param inpFile the name of an existing EPANET-formatted input file.
|
|
|
+ * @param rptFile the name of a report file to be created (or "" if not needed).
|
|
|
+ * @param outFile the name of a binary output file to be created (or "" if not needed).
|
|
|
+ * @return an error code.
|
|
|
+ * <p>
|
|
|
+ * This function should be called immediately after EN_createproject if an EPANET-formatted
|
|
|
+ * input file will be used to supply network data.
|
|
|
+ */
|
|
|
+ int EN_open(Pointer ph, String inpFile, String rptFile, String outFile);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves the title lines of the project
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @param out_line1 first title line
|
|
|
+ * @param out_line2 second title line
|
|
|
+ * @param out_line3 third title line
|
|
|
+ * @return an error code
|
|
|
+ */
|
|
|
+ int EN_gettitle(Pointer ph, byte[] out_line1, byte[] out_line2, byte[] out_line3);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Sets the title lines of the project
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @param line1 first title line
|
|
|
+ * @param line2 second title line
|
|
|
+ * @param line3 third title line
|
|
|
+ * @return an error code
|
|
|
+ */
|
|
|
+ int EN_settitle(Pointer ph, String line1, String line2, String line3);
|
|
|
+
|
|
|
+ /*===================================================================
|
|
|
+ Hydraulic Analysis Functions
|
|
|
+ ===================================================================*/
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Runs a complete hydraulic simulation with results for all time periods
|
|
|
+ * written to a temporary hydraulics file.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @return an error code.
|
|
|
+ * <p>
|
|
|
+ * Use EN_solveH to generate a complete hydraulic solution which can stand alone
|
|
|
+ * or be used as input to a water quality analysis.
|
|
|
+ */
|
|
|
+ int EN_solveH(Pointer ph);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Uses a previously saved binary hydraulics file to supply a project's hydraulics.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @param filename the name of the binary file containing hydraulic results.
|
|
|
+ * @return an error code.
|
|
|
+ * <p>
|
|
|
+ * Call this function to re-use a set of hydraulic analysis results saved previously.
|
|
|
+ */
|
|
|
+ int EN_usehydfile(Pointer ph, String filename);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Opens a project's hydraulic solver.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @return an error code.
|
|
|
+ * <p>
|
|
|
+ * Call EN_openH prior to running the first hydraulic analysis.
|
|
|
+ */
|
|
|
+ int EN_openH(Pointer ph);
|
|
|
+
|
|
|
+ /*===================================================================
|
|
|
+ Water Quality Analysis Functions
|
|
|
+ ===================================================================*/
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Runs a complete water quality simulation with results at uniform
|
|
|
+ * reporting intervals written to the project's binary output file.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @return an error code.
|
|
|
+ * <p>
|
|
|
+ * A hydraulic analysis must have been run and saved to a hydraulics file before
|
|
|
+ * calling EN_solveQ.
|
|
|
+ */
|
|
|
+ int EN_solveQ(Pointer ph);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Opens a project's water quality solver.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @return an error code.
|
|
|
+ * <p>
|
|
|
+ * Call EN_openQ prior to running the first water quality analysis.
|
|
|
+ */
|
|
|
+ int EN_openQ(Pointer ph);
|
|
|
+
|
|
|
+ /*===================================================================
|
|
|
+ Reporting Functions
|
|
|
+ ===================================================================*/
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Sets a user-supplied callback function for reporting
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @param callback a function pointer used for reporting.
|
|
|
+ * @return an error code.
|
|
|
+ * <p>
|
|
|
+ * The callback function replaces the project's report file as
|
|
|
+ * the destination for all output written by EN_writeline.
|
|
|
+ */
|
|
|
+ int EN_setreportcallback(Pointer ph, Object callback);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Writes a line of text to a project's report file.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @param line a text string to write.
|
|
|
+ * @return an error code.
|
|
|
+ */
|
|
|
+ int EN_writeline(Pointer ph, String line);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Writes simulation results in a tabular format to a project's report file.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @return an error code
|
|
|
+ * <p>
|
|
|
+ * Either a full hydraulic analysis or full hydraulic and water quality analysis must
|
|
|
+ * have been run, with results saved to file, before EN_report is called.
|
|
|
+ */
|
|
|
+ int EN_report(Pointer ph);
|
|
|
+
|
|
|
+ /*===================================================================
|
|
|
+ Node Functions
|
|
|
+ ===================================================================*/
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Adds a new node to a project.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @param id the ID name of the node to be added.
|
|
|
+ * @param nodeType the type of node being added (see EN_NodeType)
|
|
|
+ * @param out_index the index of the newly added node
|
|
|
+ * @return an error code.
|
|
|
+ * <p>
|
|
|
+ * When a new node is created all of its properties are set to 0.
|
|
|
+ */
|
|
|
+ int EN_addnode(Pointer ph, String id, int nodeType, IntByReference out_index);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Gets the index of a node given its ID name.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @param id a node ID name.
|
|
|
+ * @param out_index the node's index (starting from 1).
|
|
|
+ * @return an error code
|
|
|
+ */
|
|
|
+ int EN_getnodeindex(Pointer ph, String id, IntByReference out_index);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Gets the ID name of a node given its index.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @param index a node's index (starting from 1).
|
|
|
+ * @param out_id the node's ID name.
|
|
|
+ * @return an error code
|
|
|
+ */
|
|
|
+ int EN_getnodeid(Pointer ph, int index, byte[] out_id);
|
|
|
+
|
|
|
+ /*===================================================================
|
|
|
+ Link Functions
|
|
|
+ ===================================================================*/
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Adds a new link to a project.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @param id the ID name of the link to be added.
|
|
|
+ * @param linkType The type of link being added (see EN_LinkType)
|
|
|
+ * @param fromNode The ID name of the link's starting node.
|
|
|
+ * @param toNode The ID name of the link's ending node.
|
|
|
+ * @param out_index the index of the newly added link.
|
|
|
+ * @return an error code.
|
|
|
+ */
|
|
|
+ int EN_addlink(Pointer ph, String id, int linkType, String fromNode, String toNode, IntByReference out_index);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Gets the index of a link given its ID name.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @param id a link's ID name.
|
|
|
+ * @param out_index the link's index (starting from 1).
|
|
|
+ * @return an error code.
|
|
|
+ */
|
|
|
+ int EN_getlinkindex(Pointer ph, String id, IntByReference out_index);
|
|
|
+
|
|
|
+ /*===================================================================
|
|
|
+ Time Pattern Functions
|
|
|
+ ===================================================================*/
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Adds a new time pattern to a project.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @param id the ID name of the pattern to add.
|
|
|
+ * @return an error code.
|
|
|
+ * <p>
|
|
|
+ * The new pattern contains a single time period whose factor is 1.0.
|
|
|
+ */
|
|
|
+ int EN_addpattern(Pointer ph, String id);
|
|
|
+
|
|
|
+ /*===================================================================
|
|
|
+ Data Curve Functions
|
|
|
+ ===================================================================*/
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Adds a new data curve to a project.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @param id The ID name of the curve to be added.
|
|
|
+ * @return an error code.
|
|
|
+ * <p>
|
|
|
+ * The new curve contains a single data point (1.0, 1.0).
|
|
|
+ */
|
|
|
+ int EN_addcurve(Pointer ph, String id);
|
|
|
+
|
|
|
+ /*===================================================================
|
|
|
+ Simple Controls Functions
|
|
|
+ ===================================================================*/
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Adds a new simple control to a project.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @param type the type of control to add (see EN_ControlType).
|
|
|
+ * @param linkIndex the index of a link to control (starting from 1).
|
|
|
+ * @param setting control setting applied to the link.
|
|
|
+ * @param nodeIndex index of the node used to control the link
|
|
|
+ * @param level action level that triggers the control.
|
|
|
+ * @param out_index index of the new control.
|
|
|
+ * @return an error code.
|
|
|
+ */
|
|
|
+ int EN_addcontrol(Pointer ph, int type, int linkIndex, double setting,
|
|
|
+ int nodeIndex, double level, IntByReference out_index);
|
|
|
+
|
|
|
+ /*===================================================================
|
|
|
+ Rule-Based Controls Functions
|
|
|
+ ===================================================================*/
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Adds a new rule-based control to a project.
|
|
|
+ *
|
|
|
+ * @param ph an EPANET project handle.
|
|
|
+ * @param rule text of the rule following the format used in an EPANET input file.
|
|
|
+ * @return an error code.
|
|
|
+ */
|
|
|
+ int EN_addrule(Pointer ph, String rule);
|
|
|
+}
|