Skip to content

Commit

Permalink
Added property to display the expressions of the PDE class
Browse files Browse the repository at this point in the history
  • Loading branch information
david-zwicker committed May 21, 2020
1 parent a4e562e commit ab64ca2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
TODO
====
* Add the JOSS citation so people can copy it conveniently
* Count the number of compilations and store it in the info field of the simulation
- raise a warning when this number became too large in a simulation?
* Think about interface for changing boundary values in numba
Expand Down
6 changes: 6 additions & 0 deletions pde/pdes/pde.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ def __init__(self,
'operators_detected': self.operators}
self._cache: Dict[str, Any] = {}


@property
def expressions(self) -> Dict[str, str]:
""" show the expressions of the PDE """
return {k: v.expression for k, v in self._rhs_expr.items()}


def _prepare(self, state: FieldBase) -> None:
""" prepare the expression by setting internal variables in the cache
Expand Down
4 changes: 3 additions & 1 deletion pde/pdes/tests/test_pde.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ def test_pde_wrong_input():

grid = UnitGrid([4])
eq = PDE({'u': 1})
assert eq.expressions == {'u': '1.0'}
with pytest.raises(ValueError):
eq.evolution_rate(FieldCollection.scalar_random_uniform(2, grid))

eq = PDE({'u': 1, 'v': 2})
assert eq.expressions == {'u': '1.0', 'v': '2.0'}
with pytest.raises(ValueError):
eq.evolution_rate(ScalarField.random_uniform(grid))



def test_pde_scalar():
Expand Down

0 comments on commit ab64ca2

Please sign in to comment.