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
Tom Harke
pystencils
Commits
fcdfc127
Commit
fcdfc127
authored
Nov 24, 2019
by
Michael Kuron
Committed by
Michael Kuron
Nov 25, 2019
Browse files
Remove unneeded ghost layers from staggered kernel
parent
6dab2755
Changes
2
Show whitespace changes
Inline
Side-by-side
pystencils/kernelcreation.py
View file @
fcdfc127
...
@@ -333,16 +333,32 @@ def create_staggered_kernel_2(assignments, **kwargs):
...
@@ -333,16 +333,32 @@ def create_staggered_kernel_2(assignments, **kwargs):
final_assignments
=
[]
final_assignments
=
[]
# find out whether any of the ghost layers is not needed
common_exclusions
=
set
([
"E"
,
"W"
,
"N"
,
"S"
,
"T"
,
"B"
][:
2
*
dim
])
for
direction
in
staggered_field
.
staggered_stencil
:
exclusions
=
set
([
"E"
,
"W"
,
"N"
,
"S"
,
"T"
,
"B"
][:
2
*
dim
])
for
elementary_direction
in
direction
:
exclusions
.
remove
(
inverse_direction_string
(
elementary_direction
))
common_exclusions
.
intersection_update
(
exclusions
)
ghost_layers
=
[[
1
,
1
]
for
d
in
range
(
dim
)]
for
direction
in
common_exclusions
:
direction
=
direction_string_to_offset
(
direction
)
for
d
,
s
in
enumerate
(
direction
):
if
s
==
1
:
ghost_layers
[
d
][
1
]
=
0
elif
s
==
-
1
:
ghost_layers
[
d
][
0
]
=
0
def
condition
(
direction
):
def
condition
(
direction
):
"""exclude those staggered points that correspond to fluxes between ghost cells"""
"""exclude those staggered points that correspond to fluxes between ghost cells"""
exclusions
=
set
([
"E"
,
"W"
,
"N"
,
"S"
])
exclusions
=
set
([
"E"
,
"W"
,
"N"
,
"S"
,
"T"
,
"B"
][:
2
*
dim
])
if
dim
==
3
:
exclusions
.
update
(
"T"
,
"B"
)
for
elementary_direction
in
direction
:
for
elementary_direction
in
direction
:
exclusions
.
remove
(
inverse_direction_string
(
elementary_direction
))
exclusions
.
remove
(
inverse_direction_string
(
elementary_direction
))
conditions
=
[]
conditions
=
[]
for
e
in
exclusions
:
for
e
in
exclusions
:
if
e
in
common_exclusions
:
continue
offset
=
direction_string_to_offset
(
e
)
offset
=
direction_string_to_offset
(
e
)
for
i
,
o
in
enumerate
(
offset
):
for
i
,
o
in
enumerate
(
offset
):
if
o
==
1
:
if
o
==
1
:
...
@@ -357,6 +373,5 @@ def create_staggered_kernel_2(assignments, **kwargs):
...
@@ -357,6 +373,5 @@ def create_staggered_kernel_2(assignments, **kwargs):
last_conditional
=
Conditional
(
condition
(
direction
),
Block
(
sp_assignments
))
last_conditional
=
Conditional
(
condition
(
direction
),
Block
(
sp_assignments
))
final_assignments
.
append
(
last_conditional
)
final_assignments
.
append
(
last_conditional
)
ghost_layers
=
[(
1
,
0
)]
*
dim
ast
=
create_kernel
(
final_assignments
,
ghost_layers
=
ghost_layers
,
**
kwargs
)
ast
=
create_kernel
(
final_assignments
,
ghost_layers
=
ghost_layers
,
**
kwargs
)
return
ast
return
ast
pystencils_tests/test_staggered_diffusion.py
View file @
fcdfc127
import
pystencils
as
ps
import
pystencils
as
ps
import
numpy
as
np
import
numpy
as
np
import
sympy
as
sp
class
TestDiffusion
:
class
TestDiffusion
:
...
@@ -20,8 +21,8 @@ class TestDiffusion:
...
@@ -20,8 +21,8 @@ class TestDiffusion:
xY_staggered
=
-
c
[
-
1
,
1
]
+
c
[
0
,
0
]
xY_staggered
=
-
c
[
-
1
,
1
]
+
c
[
0
,
0
]
jj
=
j
.
staggered_access
jj
=
j
.
staggered_access
divergence
=
-
1
*
D
/
(
1
+
n
p
.
sqrt
(
2
)
if
j
.
index_shape
[
0
]
==
4
else
1
)
*
\
divergence
=
-
1
*
D
/
(
1
+
s
p
.
sqrt
(
2
)
if
j
.
index_shape
[
0
]
==
4
else
1
)
*
\
sum
([
jj
(
d
)
/
n
p
.
linalg
.
norm
(
ps
.
stencil
.
direction_string_to_offset
(
d
))
for
d
in
j
.
staggered_stencil
sum
([
jj
(
d
)
/
s
p
.
Matrix
(
ps
.
stencil
.
direction_string_to_offset
(
d
))
.
norm
()
for
d
in
j
.
staggered_stencil
+
[
ps
.
stencil
.
inverse_direction_string
(
d
)
for
d
in
j
.
staggered_stencil
]])
+
[
ps
.
stencil
.
inverse_direction_string
(
d
)
for
d
in
j
.
staggered_stencil
]])
update
=
[
ps
.
Assignment
(
c
.
center
,
c
.
center
+
dt
*
divergence
)]
update
=
[
ps
.
Assignment
(
c
.
center
,
c
.
center
+
dt
*
divergence
)]
...
...
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