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

Incorrect number of pipes in network representation #790

Open
zannads opened this issue May 23, 2024 · 0 comments
Open

Incorrect number of pipes in network representation #790

zannads opened this issue May 23, 2024 · 0 comments

Comments

@zannads
Copy link
Contributor

zannads commented May 23, 2024

The library doesn't decrease the number of pipes (net.Npipes) when a pipe is removed from the network.
See this example:

#include <iostream>
#include <string>

#include "epanet2_2.h"
#include "types.h"

int main() {
    int errcode=0;
    EN_Project ph=NULL;
    int errco = EN_createproject(&ph);
    if (errco > 100) return 1;
    
    errco = EN_open(ph, "Net1.inp", "Net1.rpt", "");
    if (errco > 100) return 2;
    
    // Print number of links and pipes
    int nlinks=0;
    errco = EN_getcount(ph, EN_LINKCOUNT, &nlinks);
    if (errco > 100) return 1;
    std::cout << "Number of links: " << nlinks << std::endl;
    std::cout << "Number of pipes: " << ph->network.Npipes << std::endl;

    std::cout << "Adding a pipe..." <<std::endl;
    int index=0;
    errco = EN_addlink(ph, "newDupLink", EN_PIPE, "12", "13", &index);
    if (errco > 100) return 2;
    errco = EN_setpipedata(ph, index, 5280, 12, 130, 0);
    if (errcode > 100 ) return 2;

    errco = EN_getcount(ph, EN_LINKCOUNT, &nlinks);
    if (errco > 100) return 2;
    std::cout << "Number of links: " << nlinks << std::endl;
    std::cout << "Number of pipes: " << ph->network.Npipes << std::endl;

    std::cout << "Removing the pipe..." <<std::endl;
    errco = EN_getlinkindex(ph, "newDupLink", &index);
    if (errco > 100) return 3;
    errco = EN_deletelink(ph, index, EN_UNCONDITIONAL);

    errco = EN_getcount(ph, EN_LINKCOUNT, &nlinks);
    if (errco > 100) return 3;
    std::cout << "Number of links: " << nlinks << std::endl;
    std::cout << "Number of pipes: " << ph->network.Npipes << std::endl;

    // Close 
    EN_close(ph);
   
    return 0;
}

This is not a critical bug as the variable Npipes can not be retrieved (you can only get the number of links and net.Nlinks is correctly decreased) and is actually never used. Unless types.h is included and one specifically accesses p->network.Npipes it is not possible to see this error.
However, if in the future we allow to retrieve the number of pipes or this variable will be used for some reasons, this would become a critical bug.

zannads added a commit to zannads/EPANET that referenced this issue May 23, 2024
The pipe counter was not decreased if the element was a pipe.
LRossman added a commit that referenced this issue May 29, 2024
Fix Issue #790 - incorrect number of pipes
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

No branches or pull requests

1 participant