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
35c029a0
Commit
35c029a0
authored
Jun 15, 2020
by
Markus Holzer
Browse files
removed depricated as_matrix function
parent
0238f763
Changes
2
Hide whitespace changes
Inline
Side-by-side
pystencils/fd/derivation.py
View file @
35c029a0
...
...
@@ -172,18 +172,6 @@ class FiniteDifferenceStencilDerivation:
f
=
field_access
return
sum
(
f
.
get_shifted
(
*
offset
)
*
weight
for
offset
,
weight
in
zip
(
self
.
stencil
,
self
.
weights
))
def
as_matrix
(
self
):
warnings
.
warn
(
"as_matrix is deprecated and may be removed in the near future."
"Please use as_array instead which will return an MutableDenseNDimArray."
"as_array therefore can also work in 3 dimensions"
,
category
=
DeprecationWarning
)
dim
=
len
(
self
.
stencil
[
0
])
assert
dim
==
2
max_offset
=
max
(
max
(
abs
(
e
)
for
e
in
direction
)
for
direction
in
self
.
stencil
)
result
=
sp
.
Matrix
(
2
*
max_offset
+
1
,
2
*
max_offset
+
1
,
lambda
i
,
j
:
0
)
for
direction
,
weight
in
zip
(
self
.
stencil
,
self
.
weights
):
result
[
max_offset
-
direction
[
1
],
max_offset
+
direction
[
0
]]
=
weight
return
result
def
__array__
(
self
):
return
np
.
array
(
self
.
as_array
().
tolist
())
...
...
pystencils_tests/test_fd_derivation.ipynb
View file @
35c029a0
...
...
@@ -35,17 +35,17 @@
Finite difference stencil of accuracy 2, isotropic error: False
%% Cell type:code id: tags:
```
python
standard_2d_00
.
get_stencil
().
as_
matrix
()
standard_2d_00
.
get_stencil
().
as_
array
()
```
%%%% Output: execute_result

$
$
\left[\begin{matrix}0 & 0 & 0\\1 & -2 & 1\\0 & 0 & 0\end{matrix}\right]$
$

$
\displaystyle
\left[\begin{matrix}0 & 0 & 0\\1 & -2 & 1\\0 & 0 & 0\end{matrix}\right]$
⎡0 0 0⎤
⎢ ⎥
⎢1 -2 1⎥
⎢ ⎥
⎣0 0 0⎦
...
...
@@ -72,17 +72,17 @@
Finite difference stencil of accuracy 2, isotropic error: True
%% Cell type:code id: tags:
```
python
isotropic_2d_00_res
.
as_
matrix
()
isotropic_2d_00_res
.
as_
array
()
```
%%%% Output: execute_result

$
$
\left[\begin{matrix}\frac{1}{12} & - \frac{1}{6} & \frac{1}{12}\\\frac{5}{6} & - \frac{5}{3} & \frac{5}{6}\\\frac{1}{12} & - \frac{1}{6} & \frac{1}{12}\end{matrix}\right]$
$

$
\displaystyle
\left[\begin{matrix}\frac{1}{12} & - \frac{1}{6} & \frac{1}{12}\\\frac{5}{6} & - \frac{5}{3} & \frac{5}{6}\\\frac{1}{12} & - \frac{1}{6} & \frac{1}{12}\end{matrix}\right]$
⎡1/12 -1/6 1/12⎤
⎢ ⎥
⎢5/6 -5/3 5/6 ⎥
⎢ ⎥
⎣1/12 -1/6 1/12⎦
...
...
@@ -94,28 +94,28 @@
isotropic_2d_00_res
.
visualize
()
```
%%%% Output: display_data


%% Cell type:code id: tags:
```
python
expected_result
=
sp
.
Matrix
([[
1
,
-
2
,
1
],
[
10
,
-
20
,
10
],
[
1
,
-
2
,
1
]])
/
12
assert
expected_result
==
isotropic_2d_00_res
.
as_
matrix
()
assert
expected_result
[:]
==
isotropic_2d_00_res
.
as_
array
()[:]
```
%% Cell type:code id: tags:
```
python
type
(
isotropic_2d_00_res
.
as_
matrix
())
type
(
isotropic_2d_00_res
.
as_
array
())
```
%%%% Output: execute_result
sympy.
matrices.dense
.MutableDense
Matrix
sympy.
tensor.array.dense_ndim_array
.MutableDense
NDimArray
%% Cell type:code id: tags:
```
python
type
(
expected_result
)
...
...
@@ -132,29 +132,29 @@
%% Cell type:code id: tags:
```
python
isotropic_2d_11
=
FiniteDifferenceStencilDerivation
((
1
,
1
),
stencil
)
isotropic_2d_11_res
=
isotropic_2d_11
.
get_stencil
(
isotropic
=
True
)
iso_laplacian
=
isotropic_2d_00_res
.
as_
matrix
()
+
isotropic_2d_11_res
.
as_
matrix
()
iso_laplacian
=
isotropic_2d_00_res
.
as_
array
()
+
isotropic_2d_11_res
.
as_
array
()
iso_laplacian
```
%%%% Output: execute_result

$
$
\left[\begin{matrix}\frac{1}{6} & \frac{2}{3} & \frac{1}{6}\\\frac{2}{3} & - \frac{10}{3} & \frac{2}{3}\\\frac{1}{6} & \frac{2}{3} & \frac{1}{6}\end{matrix}\right]$
$

$
\displaystyle
\left[\begin{matrix}\frac{1}{6} & \frac{2}{3} & \frac{1}{6}\\\frac{2}{3} & - \frac{10}{3} & \frac{2}{3}\\\frac{1}{6} & \frac{2}{3} & \frac{1}{6}\end{matrix}\right]$
⎡1/6 2/3 1/6⎤
⎢ ⎥
⎢2/3 -10/3 2/3⎥
⎢ ⎥
⎣1/6 2/3 1/6⎦
%% Cell type:code id: tags:
```
python
expected_result
=
sp
.
Matrix
([[
1
,
4
,
1
],
[
4
,
-
20
,
4
],
[
1
,
4
,
1
]])
/
6
assert
iso_laplacian
==
expected_result
assert
iso_laplacian
[:]
==
expected_result
[:]
```
%% Cell type:markdown id: tags:
# stencils for staggered fields
...
...
@@ -233,21 +233,15 @@
d
.
visualize
()
```
%%%% Output: display_data


%% Cell type:code id: tags:
```
python
v3
=
ps
.
fields
(
"v(3): [3D]"
)
for
i
in
range
(
*
v3
.
index_shape
):
assert
FiniteDifferenceStaggeredStencilDerivation
(
"E"
,
3
,
(
0
,)).
apply
(
v3
.
center_vector
[
i
])
==
\
v3
[
1
,
0
,
0
](
i
)
-
v3
[
0
,
0
,
0
](
i
)
```
%% Cell type:code id: tags:
```
python
```
...
...
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