EPANET icon indicating copy to clipboard operation
EPANET copied to clipboard

Incorrect number of pipes in network representation

Open zannads opened this issue 1 year ago • 0 comments

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 avatar May 23 '24 07:05 zannads