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

EN_setLinkValue #42

Open
sandcastler opened this issue Dec 1, 2018 · 7 comments
Open

EN_setLinkValue #42

sandcastler opened this issue Dec 1, 2018 · 7 comments

Comments

@sandcastler
Copy link

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.?

@LRossman
Copy link
Collaborator

LRossman commented Dec 1, 2018

@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;

@sandcastler
Copy link
Author

sandcastler commented Dec 1, 2018

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

@LRossman
Copy link
Collaborator

LRossman commented Dec 1, 2018

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

@sandcastler
Copy link
Author

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
Copy link
Author

sandcastler commented Dec 2, 2018

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...

@LRossman LRossman reopened this Dec 2, 2018
@LRossman
Copy link
Collaborator

LRossman commented Dec 2, 2018

@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.

@sandcastler
Copy link
Author

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

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

2 participants