epanet-dev icon indicating copy to clipboard operation
epanet-dev copied to clipboard

EN_setLinkValue

Open sandcastler opened this issue 6 years ago • 7 comments

I'm reviewing the code and am 'new' at C++ (though I feel pretty good in VBA/ModL). I noticed that API to set system parameters (EN_setLinkValuie, EN_setControl, EN_setOption, EN_setTimeParam, EN_XXXX, ect...) is not currently developed. If I were to develop some of these, if I understand correctly, I'd want to add to datamanager.cpp; for example, to setLinkValue, I'd take getLinkValue and essentially reverse the method so that the value is set, and not retrieved. so the function would have the same format but essentially switch value and the link parameter variable?

int DataManager::setLinkValue(int index, int param, double value, Network* nw)

and for the switch case:

{ case EN_DIAMETER: link->diameter * nw->ucf(Units::DIAMETER)=value ; break;

is it that simple or am I'm missing something.?

sandcastler avatar Dec 01 '18 20:12 sandcastler

@sandcastler yes, pretty much so. Except that a pipe's diameter also affects its resistance coefficient and minor loss factor which are used in the hydraulic solver to compute head loss as a function of flow. So for this particular property the code would look as follows:

    {
    case EN_DIAMETER:
        link->diameter = value / nw->ucf(Units::DIAMETER);
        // ... diameter affects the loss factor & resistance
        link->setLossFactor();
        link->setResistance(nw);
        return 0;

LRossman avatar Dec 01 '18 21:12 LRossman

Thanks @LRossman for the quick respsonse;

SO I'm testing this out, It actually gives an error in the error list "expression must be modifiable lvalue". So my solution is to create 'setDiameter' and other function for each in the appropriate location. So for diameter, since its a link specific property (valves/pipes/ect..) I added

void Link::setDiameter(double value)
{
	diameter = value;
}

and then in the switch case

	case EN_DIAMETER:
	       link->setDiameter(value);
               link->setLossFactor();
               link->setResistance(nw);
         break;

I assume this is how all properties would need to be set, correct? Good call on the others (loss factor and resistance) I"ll be sure to include those as well.

EDIT: it seems this is appropriate for Length and Diameter thus far. Don't get an lvalue error for roughness. But with the change in roughness, like diameter, I assume setlossfactor and setResistance will need to be recalculated.

Edit 2: I don't see a setlossfactor or equivalent function

sandcastler avatar Dec 01 '18 21:12 sandcastler

I should have mentioned that I've already added most of the missing API functions (including EN_setLinkValue) to my local version of the code. I was waiting to finish up some additional stuff before committing it. The code snippet I posted above came from my updated version and it compiled OK. These are the API functions that I haven't written yet:

EN_getCurveLen
EN_getCurveXvalues
EN_getCurveYvalues
EN_getError
EN_getControl
EN_setControl

LRossman avatar Dec 01 '18 22:12 LRossman

Thanks. I see what my mistake was orginally. Like I mentioned, ramping into understanding syntax and this project is a great one (In my Opinion) to get started. I'm familiar with 2.0 toolkit so I have a good understanding of what things should do. Thanks again!

sandcastler avatar Dec 02 '18 01:12 sandcastler

OK @LRossman ; So you've created link.setLossFactor in link and then a the same for each (valve, pipe) where it actually updates the minorlossfactor due to change in diameter. So if I'm to repeat what you've already done on your local version, I'd need to do that.

Actrually, it looks to be just a ratio, based off diameter to adjust the existing lossfactor...

sandcastler avatar Dec 02 '18 02:12 sandcastler

@sandcastler here's what the setLossFactor function looks like:

void Pipe::setLossFactor()
{
    lossFactor = 0.02517 * lossCoeff / pow(diameter, 4);
}

with the same function also appearing in valve.cpp.

I will push my updated version to the dev branch shortly so that we can all be better synchronized.

LRossman avatar Dec 02 '18 03:12 LRossman

Yep, that is what I have for the lossFactor as well. Thanks for the update.

sandcastler avatar Dec 03 '18 00:12 sandcastler