Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Stephan Seitz
pystencils
Commits
7c97bb74
Commit
7c97bb74
authored
Aug 10, 2020
by
Markus Holzer
Browse files
Added test cases for fd derivation
parent
a3f37cbd
Changes
4
Hide whitespace changes
Inline
Side-by-side
pystencils/fd/derivative.py
View file @
7c97bb74
...
...
@@ -228,7 +228,9 @@ def diff_terms(expr):
Example:
>>> 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)}
"""
result
=
set
()
...
...
pystencils_tests/test_fd_derivation.py
deleted
100644 → 0
View file @
a3f37cbd
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
)
pystencils_tests/test_fd_derivative.py
0 → 100644
View file @
7c97bb74
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
pystencils_tests/test_utils.py
View file @
7c97bb74
import
pytest
import
sympy
as
sp
from
pystencils.utils
import
LinearEquationSystem
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"
)
les
=
LinearEquationSystem
([
x
,
y
,
z
])
les
.
add_equation
(
1
*
x
+
2
*
y
-
1
*
z
+
4
)
...
...
@@ -37,7 +66,7 @@ def test_LinearEquationSystem():
assert
les
.
solution_structure
()
==
'none'
def
test_
D
ot
D
ict
():
def
test_
d
ot
_d
ict
():
d
=
{
'a'
:
{
'c'
:
7
},
'b'
:
6
}
t
=
DotDict
(
d
)
assert
t
.
a
.
c
==
7
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment