144 lines
8.0 KiB
HTML
144 lines
8.0 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
|
<meta name="generator" content="Doxygen 1.8.16"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>EPANET: Chlorine Dosage Example</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="search/searchdata.js"></script>
|
|
<script type="text/javascript" src="search/search.js"></script>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
<td id="projectalign" style="padding-left: 0.5em;">
|
|
<div id="projectname">EPANET
|
|
 <span id="projectnumber">2.2.0</span>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.8.16 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|
/* @license-end */
|
|
</script>
|
|
<script type="text/javascript" src="menudata.js"></script>
|
|
<script type="text/javascript" src="menu.js"></script>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
$(function() {
|
|
initMenu('',true,false,'search.php','Search');
|
|
$(document).ready(function() { init_search(); });
|
|
});
|
|
/* @license-end */</script>
|
|
<div id="main-nav"></div>
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
</div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="javascript:void(0)" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
<div id="nav-path" class="navpath">
|
|
<ul>
|
|
<li class="navelem"><a class="el" href="_toolkit_examples.html">Examples</a></li> </ul>
|
|
</div>
|
|
</div><!-- top -->
|
|
<div class="PageDoc"><div class="header">
|
|
<div class="headertitle">
|
|
<div class="title">Chlorine Dosage Example </div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<div class="textblock"><p>This example illustrates how the Toolkit could be used to determine the lowest dose of chlorine applied at the entrance to a distribution system needed to ensure that a minimum residual is met throughout the system. We assume that the EPANET input file contains the proper set of kinetic coefficients that describe the rate at which chlorine will decay in the system being studied. In the example code, the ID label of the source node is contained in <code>SourceID</code>, the minimum residual target is given by <code>Ctarget</code>, and the target is only checked after a start-up duration of 5 days (432,000 seconds). To keep the code more readable, no error checking is made on the results returned from the Toolkit function calls.</p>
|
|
<div class="fragment"><div class="line"><span class="preprocessor">#include "epanet2_2.h"</span></div>
|
|
<div class="line"> </div>
|
|
<div class="line"><span class="keywordtype">double</span> cl2dose(<span class="keywordtype">char</span> *SourceID, <span class="keywordtype">double</span> Ctarget)</div>
|
|
<div class="line">{</div>
|
|
<div class="line"> <span class="keywordtype">int</span> i, nnodes, sourceindex, violation;</div>
|
|
<div class="line"> <span class="keywordtype">double</span> c, csource;</div>
|
|
<div class="line"> <span class="keywordtype">long</span> t, tstep;</div>
|
|
<div class="line"> EN_Project ph;</div>
|
|
<div class="line"> </div>
|
|
<div class="line"> <span class="comment">// Open the toolkit & obtain a hydraulic solution</span></div>
|
|
<div class="line"> EN_createproject(&ph);</div>
|
|
<div class="line"> EN_open(ph, <span class="stringliteral">"example3.inp"</span>, <span class="stringliteral">"example3.rpt"</span>, <span class="stringliteral">""</span>);</div>
|
|
<div class="line"> EN_solveH(ph);</div>
|
|
<div class="line"> </div>
|
|
<div class="line"> <span class="comment">// Get the number of nodes and the source node's index</span></div>
|
|
<div class="line"> EN_getcount(ph, EN_NODECOUNT, &nnodes);</div>
|
|
<div class="line"> EN_getnodeindex(ph, SourceID, &sourceindex);</div>
|
|
<div class="line"> </div>
|
|
<div class="line"> <span class="comment">// Setup the system to analyze for chlorine</span></div>
|
|
<div class="line"> <span class="comment">// (in case it was not done in the input file)</span></div>
|
|
<div class="line"> EN_setqualtype(ph, EN_CHEM, <span class="stringliteral">"Chlorine"</span>, <span class="stringliteral">"mg/L"</span>, <span class="stringliteral">""</span>);</div>
|
|
<div class="line"> </div>
|
|
<div class="line"> <span class="comment">// Open the water quality solver</span></div>
|
|
<div class="line"> EN_openQ(ph);</div>
|
|
<div class="line"> </div>
|
|
<div class="line"> <span class="comment">// Begin the search for the source concentration</span></div>
|
|
<div class="line"> csource = 0.0;</div>
|
|
<div class="line"> <span class="keywordflow">do</span> {</div>
|
|
<div class="line"> </div>
|
|
<div class="line"> <span class="comment">// Update source concentration to next level</span></div>
|
|
<div class="line"> csource = csource + 0.1;</div>
|
|
<div class="line"> EN_setnodevalue(ph, sourceindex, EN_SOURCEQUAL, csource);</div>
|
|
<div class="line"> </div>
|
|
<div class="line"> <span class="comment">// Run WQ simulation checking for target violations</span></div>
|
|
<div class="line"> violation = 0;</div>
|
|
<div class="line"> EN_initQ(ph, 0);</div>
|
|
<div class="line"> <span class="keywordflow">do</span> {</div>
|
|
<div class="line"> EN_runQ(ph, &t);</div>
|
|
<div class="line"> <span class="keywordflow">if</span> (t > 432000) {</div>
|
|
<div class="line"> <span class="keywordflow">for</span> (i=1; i<=nnodes; i++) {</div>
|
|
<div class="line"> EN_getnodevalue(ph, i, EN_QUALITY, &c);</div>
|
|
<div class="line"> <span class="keywordflow">if</span> (c < Ctarget) {</div>
|
|
<div class="line"> violation = 1;</div>
|
|
<div class="line"> <span class="keywordflow">break</span>;</div>
|
|
<div class="line"> }</div>
|
|
<div class="line"> }</div>
|
|
<div class="line"> }</div>
|
|
<div class="line"> EN_nextQ(ph, &tstep);</div>
|
|
<div class="line"> </div>
|
|
<div class="line"> <span class="comment">// End WQ run if violation found</span></div>
|
|
<div class="line"> } <span class="keywordflow">while</span> (!violation && tstep > 0);</div>
|
|
<div class="line"> </div>
|
|
<div class="line"> <span class="comment">// Continue search if violation found</span></div>
|
|
<div class="line"> } <span class="keywordflow">while</span> (violation && csource <= 4.0);</div>
|
|
<div class="line"> </div>
|
|
<div class="line"> <span class="comment">// Close up the WQ solver and delete the project</span></div>
|
|
<div class="line"> EN_closeQ(ph);</div>
|
|
<div class="line"> EN_deleteproject(ph);</div>
|
|
<div class="line"> <span class="keywordflow">return</span> csource;</div>
|
|
<div class="line">}</div>
|
|
</div><!-- fragment --> </div></div><!-- contents -->
|
|
</div><!-- PageDoc -->
|
|
<!-- start footer part -->
|
|
<hr class="footer"/><address class="footer"><small>
|
|
Generated by  <a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/>
|
|
</a> 1.8.16
|
|
</small></address>
|
|
</body>
|
|
</html>
|