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
e2cab929
Commit
e2cab929
authored
Apr 21, 2017
by
Martin Bauer
Browse files
lbmpy: Fix bug when using non-standard field layout in scenarios
parent
8065a9d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
field.py
View file @
e2cab929
...
...
@@ -114,13 +114,13 @@ class Field(object):
@
staticmethod
def
createFixedSize
(
fieldName
,
shape
,
indexDimensions
=
0
,
dtype
=
np
.
float64
,
layout
=
'numpy'
):
"""
Creates a field with fixed sizes i.e. can be called only wit
y
arrays of the same size and layout
Creates a field with fixed sizes i.e. can be called only wit
h
arrays of the same size and layout
:param fieldName: symbolic name for the field
:param shape: overall shape of the array
:param indexDimensions: how many of the trailing dimensions are interpreted as index (as opposed to spatial)
:param dtype: numpy data type of the array the kernel is called with later
:param layout:
see createGeneric
:param layout:
full layout of array, not only spatial dimensions
"""
spatialDimensions
=
len
(
shape
)
-
indexDimensions
assert
spatialDimensions
>=
1
...
...
@@ -140,7 +140,10 @@ class Field(object):
shape
+=
(
1
,)
strides
+=
(
1
,)
return
Field
(
fieldName
,
dtype
,
layout
[:
spatialDimensions
],
shape
,
strides
)
spatialLayout
=
list
(
layout
)
for
i
in
range
(
spatialDimensions
,
len
(
layout
)):
spatialLayout
.
remove
(
i
)
return
Field
(
fieldName
,
dtype
,
tuple
(
spatialLayout
),
shape
,
strides
)
def
__init__
(
self
,
fieldName
,
dtype
,
layout
,
shape
,
strides
):
"""Do not use directly. Use static create* methods"""
...
...
slicing.py
View file @
e2cab929
import
sympy
as
sp
import
numpy
as
np
from
pystencils.field
import
createNumpyArrayWithLayout
,
getLayoutOfArray
class
SliceMaker
(
object
):
...
...
@@ -95,11 +96,14 @@ def removeGhostLayers(arr, indexDimensions=0, ghostLayers=1):
return
arr
[
indexing
]
def
addGhostLayers
(
arr
,
indexDimensions
=
0
,
ghostLayers
=
1
):
def
addGhostLayers
(
arr
,
indexDimensions
=
0
,
ghostLayers
=
1
,
layout
=
None
):
dimensions
=
len
(
arr
.
shape
)
spatialDimensions
=
dimensions
-
indexDimensions
newShape
=
[
e
+
2
*
ghostLayers
for
e
in
arr
.
shape
[:
spatialDimensions
]]
+
list
(
arr
.
shape
[
spatialDimensions
:])
result
=
np
.
zeros
(
newShape
)
if
layout
is
None
:
layout
=
getLayoutOfArray
(
arr
)
result
=
createNumpyArrayWithLayout
(
newShape
,
layout
)
result
.
fill
(
0.0
)
indexing
=
[
slice
(
ghostLayers
,
-
ghostLayers
,
None
),
]
*
spatialDimensions
indexing
+=
[
slice
(
None
,
None
,
None
)]
*
indexDimensions
result
[
indexing
]
=
arr
...
...
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