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

tankmix2: Stagnant zone volume incorrectly zeroed when there's no net flow #820

Closed
endearqb opened this issue Dec 14, 2024 · 1 comment
Closed

Comments

@endearqb
Copy link

Issue #1: Stagnant zone volume incorrectly zeroed when there's no net flow

Current Behavior:
When there is no net flow (inflow = outflow), vt = 0, and mixzone->v = vmz, the code incorrectly sets stagzone->v = 0 even when the stagnant zone contains water (stagzone->v > 0).

Expected Behavior:
When there is no net flow, the stagnant zone volume should remain unchanged if no water is being transferred between zones (vt = 0).

Code Location:
In tankmix2() function, the else branch of volume update section:

else
{
    mixzone->v += vnet;
    mixzone->v = MIN(mixzone->v, vmz);
    mixzone->v = MAX(0.0, mixzone->v);
    stagzone->v = 0.0;  // This line incorrectly zeros the stagnant zone
}

Issue #2: Mixing zone volume calculation incorrect during partial stagnant zone emptying

Current Behavior:
When water is transferred from the stagnant zone to mixing zone but net outflow is larger (vt > 0 && vt < -vnet), the code sets mixzone->v = vmz, maintaining maximum volume despite net water loss.

Expected Behavior:
The mixing zone volume should account for both the water received from stagnant zone and net outflow:
mixzone->v = vmz + vt + vnet

Code Location:
In tankmix2() function:

if (vt > 0.0)
{
    mixzone->v = vmz;  // Should consider both transfer volume and net flow
    if (vnet > 0.0) stagzone->v += vt;
    else            stagzone->v = MAX(0.0, ((stagzone->v) - vt));
}

Proposed Fix:

if (vt > 0.0)
{
    if (vnet > 0.0)
    {   
        stagzone->v += vt;
        mixzone->v = vmz;
    }
    else
    {
        stagzone->v = MAX(0.0, ((stagzone->v) - vt));
        mixzone->v = vmz + vt + vnet; // fix the issue 2
    }
}
else
{
    mixzone->v += vnet;
    mixzone->v = MIN(mixzone->v, vmz);
    mixzone->v = MAX(0.0, mixzone->v);
    if (vmz - mixzone->v >0.0) stagzone->v = 0.0; // fix the issue 1
}
@LRossman
Copy link
Collaborator

The fix has been applied in PR #821 .

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