-
Notifications
You must be signed in to change notification settings - Fork 28
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
Fix handling of flow direction for dynamic flow rates #101
Changes from 3 commits
c37fac5
971aaa5
c2c3481
0ecc576
5fd603c
df438f5
140136d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,7 @@ bool ConvectionDispersionOperatorBase::configure(UnitOpIdx unitOpIdx, IParameter | |
{ | ||
readScalarParameterOrArray(_velocity, paramProvider, "VELOCITY", 1); | ||
} | ||
_dir = 1; | ||
|
||
readScalarParameterOrArray(_colDispersion, paramProvider, "COL_DISPERSION", 1); | ||
if (paramProvider.exists("COL_DISPERSION_MULTIPLEX")) | ||
|
@@ -185,29 +186,25 @@ bool ConvectionDispersionOperatorBase::configure(UnitOpIdx unitOpIdx, IParameter | |
*/ | ||
bool ConvectionDispersionOperatorBase::notifyDiscontinuousSectionTransition(double t, unsigned int secIdx) | ||
{ | ||
double prevVelocity = static_cast<double>(_curVelocity); | ||
|
||
// If we don't have cross section area, velocity is given by parameter | ||
double dir_old = _dir; | ||
if (_crossSection <= 0.0) | ||
_curVelocity = getSectionDependentScalar(_velocity, secIdx); | ||
{ | ||
double dir_new = static_cast<double>(getSectionDependentScalar(_velocity, secIdx)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to change this value, so make it |
||
_dir = (dir_new >= 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will result in _dir = (dir_new >= 0.0) ? 1 : -1; This occurs some more times in the remaining code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see my mistake. Can you please elaborate on the syntax of your suggestion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This a = 2 if b == 3 else 6 which would translate to int a = (b == 3) ? 2 : 6; So it's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's what I expected but I really was not sure about the operator. Thanks for explaining! |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also need to set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you're right, but I'm also a bit confused. ^^
Do you mean inside the However, a bit up, you also write:
With that you simply meant that it was wrong to put the statement that overwrites If so, doesn't this mean, I can combine both branches with a simple OR ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, sorry. I meant the
else if (!_velocity.empty())
{
// ...
const double dirNew = static_cast<double>(getSectionDependentScalar(_velocity, secIdx));
_dir = (dirNew >= 0.0) ? 1 : -1;
if (dirOld * _dir < 0.0)
_curVelocity *= -1.0;
} |
||
else if (!_velocity.empty()) | ||
{ | ||
if (secIdx > 0) | ||
{ | ||
const double dir = static_cast<double>(getSectionDependentScalar(_velocity, secIdx - 1)); | ||
if (dir < 0.0) | ||
prevVelocity *= -1.0; | ||
} | ||
|
||
// We have both cross section area and interstitial flow rate | ||
// _curVelocity has already been set to the network flow rate in setFlowRates() | ||
// the direction of the flow (i.e., sign of _curVelocity) is given by _velocity | ||
const double dir = static_cast<double>(getSectionDependentScalar(_velocity, secIdx)); | ||
if (dir < 0.0) | ||
_curVelocity *= -1.0; | ||
double dir_new = static_cast<double>(getSectionDependentScalar(_velocity, secIdx)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to change this value, so make it |
||
_dir = (dir_new >= 0); | ||
} | ||
if (dir_old * _dir < 0.0) | ||
_curVelocity *= -1.0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this working or should we do this instead: _curVelocity = abs(_curVelocity) * _dir; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it works; it only changes the sign of the velocity iff dir_old != _dir; but I don't mind changing it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're probably right. When a discontinuous section transition occurs, the However, the flipping must occur only in the |
||
|
||
return (prevVelocity * static_cast<double>(_curVelocity) < 0.0); | ||
return (dir_old * _dir < 0.0); | ||
} | ||
|
||
/** | ||
|
@@ -221,7 +218,7 @@ void ConvectionDispersionOperatorBase::setFlowRates(const active& in, const acti | |
{ | ||
// If we have cross section area, interstitial velocity is given by network flow rates | ||
if (_crossSection > 0.0) | ||
_curVelocity = in / (_crossSection * colPorosity); | ||
_curVelocity = _dir * in / (_crossSection * colPorosity); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -850,6 +850,8 @@ bool TwoDimensionalConvectionDispersionOperator::configure(UnitOpIdx unitOpIdx, | |
else | ||
registerParam2DArray(parameters, _velocity, [=](bool multi, unsigned int sec, unsigned int compartment) { return makeParamId(hashString("VELOCITY"), unitOpIdx, CompIndep, compartment, BoundStateIndep, ReactionIndep, multi ? sec : SectionIndep); }, _nRad); | ||
|
||
std::vector<int> _dir(_nRad, 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This creates a local variable that shadows the member variable with the same name. _dir = std::vector<int>(_nRad, 1); You should also initialize the vector in the constructor with size There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah yes, I was a bit confused there... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry, can you tell me where would that be? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Around line 656 in SomeClass::SomeClass() : _var1(value), _var2(ctorArg1, ctorArg2) { /* ... /* } The part between My suggestion is to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks; How do you decide what to initialize? E.g. Also, should I resize it like other radially dependent parameter vectors are? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to It would be consistent to also initialize the other vectors with size |
||
|
||
_axialDispersionMode = readAndRegisterMultiplexParam(paramProvider, parameters, _axialDispersion, "COL_DISPERSION", _nComp, _nRad, unitOpIdx); | ||
_radialDispersionMode = readAndRegisterMultiplexParam(paramProvider, parameters, _radialDispersion, "COL_DISPERSION_RADIAL", _nComp, _nRad, unitOpIdx); | ||
|
||
|
@@ -872,30 +874,22 @@ bool TwoDimensionalConvectionDispersionOperator::configure(UnitOpIdx unitOpIdx, | |
bool TwoDimensionalConvectionDispersionOperator::notifyDiscontinuousSectionTransition(double t, unsigned int secIdx) | ||
{ | ||
bool hasChanged = false; | ||
std::vector<int> dir_old = _dir; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can avoid this local (and memory allocating) variable. See below for a suggestion. |
||
|
||
if (!_velocity.empty()) | ||
{ | ||
// _curVelocity has already been set to the network flow rate in setFlowRates() | ||
// the direction of the flow (i.e., sign of _curVelocity) is given by _velocity | ||
|
||
active const* const dirs = getSectionDependentSlice(_velocity, _nRad, secIdx); | ||
if (secIdx > 0) | ||
{ | ||
active const* const dirsPrev = getSectionDependentSlice(_velocity, _nRad, secIdx - 1); | ||
for (unsigned int i = 0; i < _nRad; ++i) | ||
{ | ||
if (dirs[i] * dirsPrev[i] < 0.0) | ||
{ | ||
hasChanged = true; | ||
break; | ||
} | ||
} | ||
} | ||
active const* const dir_new = getSectionDependentSlice(_velocity, _nRad, secIdx); | ||
|
||
for (unsigned int i = 0; i < _nRad; ++i) | ||
{ | ||
if (dirs[i] < 0.0) | ||
_dir[i] = (dir_new[i] > 0); | ||
if (_dir[i] * dir_old[i] < 0.0) | ||
{ | ||
hasChanged = true; | ||
_curVelocity[i] *= -1.0; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doing it this way allows to get rid of the local const int newDir = (dir_new[i] >= 0.0) ? 1 : -1;
if (_dir[i] * newDir < 0)
{
hasChanged = true;
_curVelocity[i] *= -1.0;
}
_dir[i] = newDir; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
here you mean |
||
} | ||
} | ||
|
||
|
@@ -915,7 +909,7 @@ bool TwoDimensionalConvectionDispersionOperator::notifyDiscontinuousSectionTrans | |
*/ | ||
void TwoDimensionalConvectionDispersionOperator::setFlowRates(int compartment, const active& in, const active& out) CADET_NOEXCEPT | ||
{ | ||
_curVelocity[compartment] = in / (_crossSections[compartment] * _colPorosities[compartment]); | ||
_curVelocity[compartment] = _dir[compartment] * in / (_crossSections[compartment] * _colPorosities[compartment]); | ||
} | ||
|
||
void TwoDimensionalConvectionDispersionOperator::setFlowRates(active const* in, active const* out) CADET_NOEXCEPT | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_dir
is anint
now: