Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NaN sim results when setting emitter exponent above 1 and modifying emitter coefficient using the API #795

Closed
lbutler opened this issue May 28, 2024 · 1 comment · Fixed by #797

Comments

@lbutler
Copy link
Contributor

lbutler commented May 28, 2024

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:

  1. Run as is - see error values in output
  2. Change line 20 to make exponent less than 1 - simulation returns results
  3. Update network.inp and uncomment nodes in [EMITTERS] and make exponent larger than 1 again - simulation returns results

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
image

2 - Exponent 0.9 and Coeff. 2.2 when t > 7200
image

3 - Exponent 1.1 and Coeff. 2.2 when t > 7200 and Coeff defined in INP
image

Code and network also attached below
epanet-exponent-bug.zip

@LRossman
Copy link
Collaborator

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants