-
Notifications
You must be signed in to change notification settings - Fork 161
Add a per-fluid equation-of-state selector #1700
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
Open
fahnab666
wants to merge
14
commits into
MFlowCode:master
Choose a base branch
from
fahnab666:feature/eos-selector-v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
172bfa7
Add per-fluid EOS selector with a stable EOS enumeration
fahnab666 7ee3cd3
Document the non-chemistry ideal-gas route in the eos selector note
fahnab666 dad4505
Merge branch 'master' into feature/eos-selector-v2
fahnab666 ff17a03
Address review: document the eos enum manual exception, derive rather
fahnab666 0e8230f
Place eos_* constants above the auto-gen include and flag the silent …
fahnab666 1a7222f
Tighten the eos auto-gen note and complete the physical_parameters dr…
fahnab666 d401bba
Clamp s_check_eos fluid loop to num_fluids_max to avoid out-of-bounds…
fahnab666 c9252fd
Trim the eos enum to the implemented backends and check every fluid_p…
sbryngelson b3efac1
Add tests for the eos selector
sbryngelson 73e2150
Merge master into feature/eos-selector-v2
sbryngelson 53df8da
Merge branch 'master' into feature/eos-selector-v2
fahnab666 8f96104
Merge branch 'MFlowCode:master' into feature/eos-selector-v2
fahnab666 87da967
Merge branch 'master' into feature/eos-selector-v2
sbryngelson ddd3da4
Merge branch 'master' into feature/eos-selector-v2
fahnab666 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| """ | ||
| Tests for the per-fluid equation-of-state selector, fluid_pp(i)%eos. | ||
|
|
||
| Covers the enum itself (Fortran/Python agreement), the readable-name to integer | ||
| resolution done by Case, and the check_eos constraints in case_validator. | ||
| """ | ||
|
|
||
| import unittest | ||
|
|
||
| from ..case import Case | ||
| from ..case_validator import CaseConstraintError, CaseValidator | ||
| from ..common import MFCException | ||
| from ..params.definitions import _EOS_NAMES | ||
| from ..params.namelist_parser import get_fortran_constants | ||
| from .negative_tests import BASE_CASE | ||
|
|
||
|
|
||
| def _eos_errors(overrides): | ||
| """Validate BASE_CASE plus overrides, returning only the eos-related messages.""" | ||
| params = dict(BASE_CASE) | ||
| params.update(overrides) | ||
| try: | ||
| CaseValidator(Case(params).params).validate("pre_process") | ||
| except CaseConstraintError as exc: | ||
| return [line for line in str(exc).splitlines() if "%eos" in line] | ||
| return [] | ||
|
|
||
|
|
||
| class TestEosEnum(unittest.TestCase): | ||
| """The enum is hand-written in m_constants.fpp and restated in definitions.py.""" | ||
|
|
||
| def test_fortran_and_python_enums_agree(self): | ||
| """_EOS_NAMES must match the eos_* parameters in m_constants.fpp. | ||
|
|
||
| generate_constants_fpp skips compound registry keys, so these constants are | ||
| hand-written on the Fortran side and nothing else forces the two to agree. | ||
| """ | ||
| fortran = {name[len("eos_") :]: value for name, value in get_fortran_constants().items() if name.startswith("eos_")} | ||
| self.assertEqual(fortran, _EOS_NAMES) | ||
|
|
||
| def test_only_implemented_backends_are_exposed(self): | ||
| """Reserved values must not appear until they have a backend and a check_eos branch.""" | ||
| self.assertEqual(set(_EOS_NAMES), {"stiffened_gas", "ideal_gas_mixture"}) | ||
|
|
||
|
|
||
| class TestEosNameResolution(unittest.TestCase): | ||
| """Case converts the readable name in a case file to the integer the namelist carries.""" | ||
|
|
||
| def test_name_resolves_to_integer(self): | ||
| case = Case({"fluid_pp(1)%eos": "stiffened_gas"}) | ||
| self.assertEqual(case.params["fluid_pp(1)%eos"], _EOS_NAMES["stiffened_gas"]) | ||
|
|
||
| def test_integer_passes_through(self): | ||
| case = Case({"fluid_pp(1)%eos": _EOS_NAMES["ideal_gas_mixture"]}) | ||
| self.assertEqual(case.params["fluid_pp(1)%eos"], _EOS_NAMES["ideal_gas_mixture"]) | ||
|
|
||
| def test_unknown_name_rejected(self): | ||
| with self.assertRaises(MFCException) as ctx: | ||
| Case({"fluid_pp(1)%eos": "jwl"}) | ||
| self.assertIn("stiffened_gas", str(ctx.exception)) | ||
|
|
||
| def test_resolution_applies_to_every_fluid_slot(self): | ||
| """CONSTRAINTS is registered per slot, so slot 10 must resolve like slot 1.""" | ||
| case = Case({"fluid_pp(10)%eos": "stiffened_gas"}) | ||
| self.assertEqual(case.params["fluid_pp(10)%eos"], _EOS_NAMES["stiffened_gas"]) | ||
|
|
||
|
|
||
| class TestCheckEos(unittest.TestCase): | ||
| """check_eos constraints, on a non-chemistry build (BASE_CASE sets no chemistry).""" | ||
|
|
||
| def test_base_case_has_no_eos_errors(self): | ||
| self.assertEqual(_eos_errors({}), []) | ||
|
|
||
| def test_stiffened_gas_accepted(self): | ||
| self.assertEqual(_eos_errors({"fluid_pp(1)%eos": "stiffened_gas"}), []) | ||
|
|
||
| def test_ideal_gas_mixture_requires_chemistry(self): | ||
| errors = _eos_errors({"fluid_pp(1)%eos": "ideal_gas_mixture"}) | ||
| self.assertTrue(errors) | ||
| self.assertIn("requires a chemistry build", " ".join(errors)) | ||
|
|
||
| def test_value_outside_enum_rejected(self): | ||
| """The choices constraint covers integers the enum does not define.""" | ||
| errors = _eos_errors({"fluid_pp(1)%eos": 99}) | ||
| self.assertTrue(errors) | ||
|
|
||
| def test_unused_slot_is_validated(self): | ||
| """Slots above num_fluids are default-assigned and broadcast, so they are checked too. | ||
|
|
||
| BASE_CASE sets num_fluids = 1; fluid_pp(3) is an unused slot whose value still | ||
| reaches every rank through the fluid_pp member-loop broadcast. | ||
| """ | ||
| errors = _eos_errors({"fluid_pp(3)%eos": "ideal_gas_mixture"}) | ||
| self.assertTrue(errors) | ||
| self.assertIn("fluid_pp(3)%eos", " ".join(errors)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.