Closed lbutler closed 1 month ago
Modify EN_setnodevalue()
in epanet.c as follows:
case EN_EMITTER:
if (index > nJuncs) return 0;
if (value < 0.0) return 209;
if (value > 0.0) value = pow((Ucf[FLOW] / value), hyd->Qexp) / Ucf[PRESSURE];
Node[index].Ke = value;
if (hyd->EmitterFlow[index] == 0.0) hyd->EmitterFlow[index] = 1.0; //<---- new line
break;
When using the EPANET API, setting an emitter exponent greater than 1 and subsequently changing the node's emitter flow coefficient during the simulation results in -nan errors for flow and pressure outputs. However, defining the node in the [EMITTERS] section of the INP file with any coefficients allows the simulation to run correctly without producing NaN errors.
The code I’ve been working on can be found at the following Replit: https://replit.com/@lbutler1/epanet-v22-vs-dev-Emitexpon-bug#main.c
Steps to reproduce:
I tired to look through the code but it wasn't immediately obvious what was going on, I'm sure a fresh more experienced set of eyes might be able to see what is causing this issue.
1 - Exponent 1.1 and Coeff. 2.2 when t > 7200
2 - Exponent 0.9 and Coeff. 2.2 when t > 7200
3 - Exponent 1.1 and Coeff. 2.2 when t > 7200 and Coeff defined in INP
Code and network also attached below epanet-exponent-bug.zip