Skip to content

Commit

Permalink
Fix parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
gerlero committed Mar 21, 2024
1 parent 2cb7404 commit 325e61d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
24 changes: 15 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,7 @@ 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 +104,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)"

0 comments on commit 325e61d

Please sign in to comment.