Commit 7c97bb74 by Markus Holzer

### Added test cases for fd derivation

parent a3f37cbd
 ... @@ -228,7 +228,9 @@ def diff_terms(expr): ... @@ -228,7 +228,9 @@ def diff_terms(expr): Example: Example: >>> x, y = sp.symbols("x, y") >>> x, y = sp.symbols("x, y") >>> diff_terms( diff(x, 0, 0) ) >>> diff_terms( diff(x, 0, 0) ) {Diff(Diff(x, 0, -1), 0, -1)} >>> diff_terms( diff(x, 0, 0) + y ) {Diff(Diff(x, 0, -1), 0, -1)} {Diff(Diff(x, 0, -1), 0, -1)} """ """ result = set() result = set() ... ...
 import pytest import sympy as sp from pystencils.utils import LinearEquationSystem def test_linear_equation_system(): unknowns = sp.symbols("x_:3") x, y, z = unknowns m = LinearEquationSystem(unknowns) m.add_equation(x + y - 2) m.add_equation(x - y - 1) assert m.solution_structure() == 'multiple' m.set_unknown_zero(2) assert m.solution_structure() == 'single' solution = m.solution() assert solution[unknowns[2]] == 0 assert solution[unknowns[1]] == sp.Rational(1, 2) assert solution[unknowns[0]] == sp.Rational(3, 2) m.set_unknown_zero(0) assert m.solution_structure() == 'none' # special case where less rows than unknowns, but no solution m = LinearEquationSystem(unknowns) m.add_equation(x - 3) m.add_equation(x - 4) assert m.solution_structure() == 'none' m.add_equation(y - 4) assert m.solution_structure() == 'none' with pytest.raises(ValueError) as e: m.add_equation(x**2 - 1) assert 'Not a linear equation' in str(e.value)
 import sympy as sp from pystencils import fields from pystencils.fd import Diff, diff, collect_diffs from pystencils.fd.derivative import replace_generic_laplacian def test_fs(): f = sp.Symbol("f", commutative=False) a = Diff(Diff(Diff(f, 1), 0), 0) assert a.is_commutative is False print(str(a)) assert diff(f) == f x, y = sp.symbols("x, y") collected_terms = collect_diffs(diff(x, 0, 0)) assert collected_terms == Diff(Diff(x, 0, -1), 0, -1) src = fields("src : double[2D]") expr = sp.Add(Diff(Diff(src[0, 0])), 10) expected = Diff(Diff(src[0, 0], 0, -1), 0, -1) + Diff(Diff(src[0, 0], 1, -1), 1, -1) + 10 result = replace_generic_laplacian(expr, 3) assert result == expected \ No newline at end of file
 import pytest import sympy as sp import sympy as sp from pystencils.utils import LinearEquationSystem from pystencils.utils import LinearEquationSystem from pystencils.utils import DotDict from pystencils.utils import DotDict def test_LinearEquationSystem(): def test_linear_equation_system(): unknowns = sp.symbols("x_:3") x, y, z = unknowns m = LinearEquationSystem(unknowns) m.add_equation(x + y - 2) m.add_equation(x - y - 1) assert m.solution_structure() == 'multiple' m.set_unknown_zero(2) assert m.solution_structure() == 'single' solution = m.solution() assert solution[unknowns[2]] == 0 assert solution[unknowns[1]] == sp.Rational(1, 2) assert solution[unknowns[0]] == sp.Rational(3, 2) m.set_unknown_zero(0) assert m.solution_structure() == 'none' # special case where less rows than unknowns, but no solution m = LinearEquationSystem(unknowns) m.add_equation(x - 3) m.add_equation(x - 4) assert m.solution_structure() == 'none' m.add_equation(y - 4) assert m.solution_structure() == 'none' with pytest.raises(ValueError) as e: m.add_equation(x**2 - 1) assert 'Not a linear equation' in str(e.value) x, y, z = sp.symbols("x, y, z") x, y, z = sp.symbols("x, y, z") les = LinearEquationSystem([x, y, z]) les = LinearEquationSystem([x, y, z]) les.add_equation(1 * x + 2 * y - 1 * z + 4) les.add_equation(1 * x + 2 * y - 1 * z + 4) ... @@ -37,7 +66,7 @@ def test_LinearEquationSystem(): ... @@ -37,7 +66,7 @@ def test_LinearEquationSystem(): assert les.solution_structure() == 'none' assert les.solution_structure() == 'none' def test_DotDict(): def test_dot_dict(): d = {'a': {'c': 7}, 'b': 6} d = {'a': {'c': 7}, 'b': 6} t = DotDict(d) t = DotDict(d) assert t.a.c == 7 assert t.a.c == 7 ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment