Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jonas Plewinski
pystencils
Commits
ce39e21f
Commit
ce39e21f
authored
Nov 22, 2018
by
Stephan Seitz
Committed by
Martin Bauer
Dec 07, 2018
Browse files
Add assignment.assignmetn_from_stencil
parent
e617c781
Changes
1
Hide whitespace changes
Inline
Side-by-side
assignment.py
View file @
ce39e21f
...
...
@@ -6,8 +6,9 @@ try:
from
sympy.codegen.ast
import
Assignment
except
ImportError
:
Assignment
=
None
import
numpy
as
np
__all__
=
[
'Assignment'
]
__all__
=
[
'Assignment'
,
'assignment_from_stencil'
]
def
print_assignment_latex
(
printer
,
expr
):
...
...
@@ -48,3 +49,17 @@ else:
__str__
=
assignment_str
_print_Assignment
=
print_assignment_latex
def
assignment_from_stencil
(
stencil_array
,
input_field
,
output_field
,
normalization_factor
=
None
):
stencil_array
=
np
.
array
(
stencil_array
)
rhs
=
0
offset
=
tuple
(
s
//
2
for
s
in
stencil_array
.
shape
)
for
index
,
factor
in
np
.
ndenumerate
(
stencil_array
):
rhs
+=
factor
*
input_field
[
tuple
(
i
-
o
for
i
,
o
in
zip
(
index
,
offset
))]
if
normalization_factor
:
rhs
*=
normalization_factor
return
Assignment
(
output_field
.
center
(),
rhs
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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