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

Fix parsing #25

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions foamlib/_dictionaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@
else:
numpy = True

from pyparsing import Group, Keyword, Opt, ZeroOrMore, Literal, Forward, common
from pyparsing import (
Forward,
Group,
Keyword,
Literal,
OneOrMore,
Opt,
Word,
ZeroOrMore,
common,
identchars,
identbodychars,
)

FoamDimensionSet = namedtuple(
"FoamDimensionSet",
Expand Down Expand Up @@ -66,6 +78,9 @@ def __post_init__(self) -> None:

_YES = Keyword("yes").set_parse_action(lambda s, loc, tks: True)
_NO = Keyword("no").set_parse_action(lambda s, loc, tks: False)
_WORDS = OneOrMore(Word(identchars, identbodychars + "(),")).set_parse_action(
lambda s, loc, tks: " ".join(tks)
)
_VALUE = Forward()
_LIST = Opt(
Literal("List") + Literal("<") + common.identifier + Literal(">")
Expand All @@ -91,14 +106,7 @@ def __post_init__(self) -> None:
)

_VALUE << (
_FIELD
| _LIST
| _DIMENSIONED
| _DIMENSIONS
| common.number
| _YES
| _NO
| common.identifier
_FIELD | _LIST | _DIMENSIONED | _DIMENSIONS | common.number | _YES | _NO | _WORDS
)


Expand Down
8 changes: 8 additions & 0 deletions tests/test_dictionaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,11 @@ def test_internal_field(pitz: FoamCase) -> None:
assert u == pytest.approx(u_arr)

pitz.run()


def test_fv_schemes(pitz: FoamCase) -> None:
div_schemes = pitz.fv_schemes["divSchemes"]
assert isinstance(div_schemes, FoamDictionary)
scheme = div_schemes["div(phi,U)"]
assert isinstance(scheme, str)
assert scheme == "bounded Gauss linearUpwind grad(U)"
Loading