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

Make test_mass_flow_controller more robust #1043

Merged
merged 2 commits into from
May 19, 2021

Conversation

speth
Copy link
Member

@speth speth commented May 17, 2021

This is an alternative to #1035 and #1039.

As I noted in #1033, this test is (deliberately) somewhat rough on the ODE solver. We are providing a mass flow rate function that's a square wave, so it has detect that it's not resolving something at the point where the square wave switches and (repeatedly) reduce the timestep.

This change modifies the test so that the imposed mass flow rate is at least continuous, if not smooth (we still want the ODE solver to have something to chew on). I ran the GH Actions for this 4 times and haven't seen a failure yet, so I think this may be a more reliable solution than getting into a fight with OpenBLAS.

Changes proposed in this pull request

  • Replace square wave mass flow rate with triangle wave in test_mass_flow_controller

If applicable, fill in the issue number this pull request is fixing

Closes #1033

If applicable, provide an example illustrating new features this pull request is introducing

Checklist

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • Style & formatting of contributed code follows contributing guidelines
  • The pull request is ready for review

ischoegl
ischoegl previously approved these changes May 17, 2021
Copy link
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that changing the test is ultimately better than fighting some compiler-specific symptoms.

@@ -443,7 +443,8 @@ def test_mass_flow_controller(self):
reservoir = ct.Reservoir(gas2)

mfc = ct.MassFlowController(reservoir, self.r1)
mfc.mass_flow_rate = lambda t: 0.1 if 0.2 <= t < 1.2 else 0.0
# Triangular pulse with area = 0.1
Copy link
Member

@ischoegl ischoegl May 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I usually would type it like this also, I believe Cantera uses white spaces left and right of * (on line 447 below what is marked here).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. It doesn't fit on one line anymore, but 🤷 .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could get it to fit on a line by reversing the check of the time and returning zero first. Then you could dedent the calculation line

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see now that I'm looking on a computer. Ignore this comment 😂

ischoegl
ischoegl previously approved these changes May 17, 2021
@ischoegl
Copy link
Member

I’m still tagging @bryanwweber so he gets a chance to respond

Copy link
Member

@bryanwweber bryanwweber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Can you add a docstring to the test including the discussion from #1033? Then we don't need to have this conversation again 😊

@speth
Copy link
Member Author

speth commented May 18, 2021

What part of that discussion? I don't think there's much that really belongs in the code, as it becomes an exercise in explaining what isn't there. Perhaps some of what I wrote in my last comment belongs in the commit message.

@bryanwweber
Copy link
Member

I think adding a note that the function is intentionally discontinuous in the slope to stretch the integrator is worthwhile. Basically, a note about the point of the test, why does it exist in this way. Since the implemented function choice is a little arbitrary, someone in the future may come along and wonder why it's not a smoother function. I agree that a justification for the change from square to triangle belongs in the commit message, though.

speth added 2 commits May 19, 2021 09:13
…oller

Use a triangular pulse in the mass flow rate instead of a square wave
so that the function is continuous (but not necessarily smooth). This
still shows that CVODES is able to appropriately reduce the step size
around such a feature in the input function, but seems to be give
results that are more consistent across different systems / library
versions.

Fixes Cantera#1033.
Copy link
Member

@bryanwweber bryanwweber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @speth!

@@ -443,7 +443,8 @@ def test_mass_flow_controller(self):
reservoir = ct.Reservoir(gas2)

mfc = ct.MassFlowController(reservoir, self.r1)
mfc.mass_flow_rate = lambda t: 0.1 if 0.2 <= t < 1.2 else 0.0
# Triangular pulse with area = 0.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see now that I'm looking on a computer. Ignore this comment 😂

@speth
Copy link
Member Author

speth commented May 19, 2021

Well, I guess all of these minor edits have gotten us several additional CI runs, so it's pretty clear that this is fixed, at least for the current version of OpenBLAS.

@speth speth merged commit 33a2e87 into Cantera:main May 19, 2021
@speth speth deleted the debug-mfc-reactor-test-v3 branch May 19, 2021 14:23
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

Successfully merging this pull request may close these issues.

Sporadic failures of CI in test_mass_flow_controller
3 participants