Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
pystencils
Commits
dcc76a01
Commit
dcc76a01
authored
5 years ago
by
Michael Kuron
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/master' into staggered_kernel
parents
fcdfc127
8ca8b2ee
No related branches found
No related tags found
1 merge request
!93
Reimplement create_staggered_kernel
Pipeline
#20073
failed
5 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pystencils/field.py
+21
-5
21 additions, 5 deletions
pystencils/field.py
pystencils_tests/test_field.py
+7
-0
7 additions, 0 deletions
pystencils_tests/test_field.py
with
28 additions
and
5 deletions
pystencils/field.py
+
21
−
5
View file @
dcc76a01
...
@@ -426,13 +426,15 @@ class Field(AbstractField):
...
@@ -426,13 +426,15 @@ class Field(AbstractField):
index_shape
=
self
.
index_shape
index_shape
=
self
.
index_shape
if
len
(
index_shape
)
==
0
:
if
len
(
index_shape
)
==
0
:
return
sp
.
Matrix
([
self
.
center
])
return
sp
.
Matrix
([
self
.
center
])
if
len
(
index_shape
)
==
1
:
el
if
len
(
index_shape
)
==
1
:
return
sp
.
Matrix
([
self
(
i
)
for
i
in
range
(
index_shape
[
0
])])
return
sp
.
Matrix
([
self
(
i
)
for
i
in
range
(
index_shape
[
0
])])
elif
len
(
index_shape
)
==
2
:
elif
len
(
index_shape
)
==
2
:
def
cb
(
*
args
):
return
sp
.
Matrix
([[
self
(
i
,
j
)
for
j
in
range
(
index_shape
[
1
])]
for
i
in
range
(
index_shape
[
0
])])
r
=
self
.
__call__
(
*
args
)
elif
len
(
index_shape
)
==
3
:
return
r
return
sp
.
Matrix
([[[
self
(
i
,
j
,
k
)
for
k
in
range
(
index_shape
[
2
])]
return
sp
.
Matrix
(
*
index_shape
,
cb
)
for
j
in
range
(
index_shape
[
1
])]
for
i
in
range
(
index_shape
[
0
])])
else
:
raise
NotImplementedError
(
"
center_vector is not implemented for more than 3 index dimensions
"
)
@property
@property
def
center
(
self
):
def
center
(
self
):
...
@@ -534,6 +536,20 @@ class Field(AbstractField):
...
@@ -534,6 +536,20 @@ class Field(AbstractField):
return
prefactor
*
Field
.
Access
(
self
,
offset
,
(
idx
,
*
index
))
return
prefactor
*
Field
.
Access
(
self
,
offset
,
(
idx
,
*
index
))
def
staggered_vector_access
(
self
,
offset
):
"""
Like staggered_access, but returns the entire vector/tensor stored at offset.
"""
assert
FieldType
.
is_staggered
(
self
)
if
self
.
index_dimensions
==
1
:
return
sp
.
Matrix
([
self
.
staggered_access
(
offset
)])
elif
self
.
index_dimensions
==
2
:
return
sp
.
Matrix
([
self
.
staggered_access
(
offset
,
i
)
for
i
in
range
(
self
.
index_shape
[
1
])])
elif
self
.
index_dimensions
==
3
:
return
sp
.
Matrix
([[
self
.
staggered_access
(
offset
,
(
i
,
k
))
for
k
in
range
(
self
.
index_shape
[
2
])]
for
i
in
range
(
self
.
index_shape
[
1
])])
else
:
raise
NotImplementedError
(
"
staggered_vector_access is not implemented for more than 3 index dimensions
"
)
@property
@property
def
staggered_stencil
(
self
):
def
staggered_stencil
(
self
):
assert
FieldType
.
is_staggered
(
self
)
assert
FieldType
.
is_staggered
(
self
)
...
...
This diff is collapsed.
Click to expand it.
pystencils_tests/test_field.py
+
7
−
0
View file @
dcc76a01
...
@@ -28,6 +28,9 @@ def test_field_basic():
...
@@ -28,6 +28,9 @@ def test_field_basic():
assert
neighbor
.
offsets
==
(
-
1
,
1
)
assert
neighbor
.
offsets
==
(
-
1
,
1
)
assert
'
_
'
in
neighbor
.
_latex
(
'
dummy
'
)
assert
'
_
'
in
neighbor
.
_latex
(
'
dummy
'
)
f
=
Field
.
create_fixed_size
(
'
f
'
,
(
8
,
8
,
2
,
2
,
2
),
index_dimensions
=
3
)
assert
f
.
center_vector
==
sp
.
Matrix
([[[
f
(
i
,
j
,
k
)
for
k
in
range
(
2
)]
for
j
in
range
(
2
)]
for
i
in
range
(
2
)])
f
=
Field
.
create_generic
(
'
f
'
,
spatial_dimensions
=
5
,
index_dimensions
=
2
)
f
=
Field
.
create_generic
(
'
f
'
,
spatial_dimensions
=
5
,
index_dimensions
=
2
)
field_access
=
f
[
1
,
-
1
,
2
,
-
3
,
0
](
1
,
0
)
field_access
=
f
[
1
,
-
1
,
2
,
-
3
,
0
](
1
,
0
)
assert
field_access
.
offsets
==
(
1
,
-
1
,
2
,
-
3
,
0
)
assert
field_access
.
offsets
==
(
1
,
-
1
,
2
,
-
3
,
0
)
...
@@ -139,12 +142,16 @@ def test_staggered():
...
@@ -139,12 +142,16 @@ def test_staggered():
assert
j1
[
0
,
2
](
1
)
==
j1
.
staggered_access
((
0
,
sp
.
Rational
(
3
,
2
)))
assert
j1
[
0
,
2
](
1
)
==
j1
.
staggered_access
((
0
,
sp
.
Rational
(
3
,
2
)))
assert
j1
[
0
,
1
](
1
)
==
j1
.
staggered_access
(
"
N
"
)
assert
j1
[
0
,
1
](
1
)
==
j1
.
staggered_access
(
"
N
"
)
assert
j1
[
0
,
0
](
1
)
==
j1
.
staggered_access
(
"
S
"
)
assert
j1
[
0
,
0
](
1
)
==
j1
.
staggered_access
(
"
S
"
)
assert
j1
.
staggered_vector_access
(
"
N
"
)
==
sp
.
Matrix
([
j1
.
staggered_access
(
"
N
"
)])
assert
j2
[
0
,
1
](
1
,
1
)
==
j2
.
staggered_access
((
0
,
sp
.
Rational
(
1
,
2
)),
1
)
assert
j2
[
0
,
1
](
1
,
1
)
==
j2
.
staggered_access
((
0
,
sp
.
Rational
(
1
,
2
)),
1
)
assert
j2
[
0
,
1
](
1
,
1
)
==
j2
.
staggered_access
(
"
N
"
,
1
)
assert
j2
[
0
,
1
](
1
,
1
)
==
j2
.
staggered_access
(
"
N
"
,
1
)
assert
j2
.
staggered_vector_access
(
"
N
"
)
==
sp
.
Matrix
([
j2
.
staggered_access
(
"
N
"
,
0
),
j2
.
staggered_access
(
"
N
"
,
1
)])
assert
j3
[
0
,
1
](
1
,
1
,
1
)
==
j3
.
staggered_access
((
0
,
sp
.
Rational
(
1
,
2
)),
(
1
,
1
))
assert
j3
[
0
,
1
](
1
,
1
,
1
)
==
j3
.
staggered_access
((
0
,
sp
.
Rational
(
1
,
2
)),
(
1
,
1
))
assert
j3
[
0
,
1
](
1
,
1
,
1
)
==
j3
.
staggered_access
(
"
N
"
,
(
1
,
1
))
assert
j3
[
0
,
1
](
1
,
1
,
1
)
==
j3
.
staggered_access
(
"
N
"
,
(
1
,
1
))
assert
j3
.
staggered_vector_access
(
"
N
"
)
==
sp
.
Matrix
([[
j3
.
staggered_access
(
"
N
"
,
(
i
,
j
))
for
j
in
range
(
2
)]
for
i
in
range
(
2
)])
# D2Q9
# D2Q9
k
=
ps
.
fields
(
'
k(4) : double[2D]
'
,
field_type
=
FieldType
.
STAGGERED
)
k
=
ps
.
fields
(
'
k(4) : double[2D]
'
,
field_type
=
FieldType
.
STAGGERED
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment