Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
lbmpy
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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
lbmpy
Commits
7b9b4e2d
Commit
7b9b4e2d
authored
Mar 2, 2022
by
Markus Holzer
Browse files
Options
Downloads
Patches
Plain Diff
Added sophistaced test
parent
95bf02bc
No related branches found
No related tags found
1 merge request
!115
Fix FreeSlip boundary condition
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lbmpy_tests/test_boundary_handling.py
+117
-1
117 additions, 1 deletion
lbmpy_tests/test_boundary_handling.py
with
117 additions
and
1 deletion
lbmpy_tests/test_boundary_handling.py
+
117
−
1
View file @
7b9b4e2d
...
...
@@ -112,6 +112,122 @@ def test_simple(target):
assert
(
all
(
dh
.
cpu_arrays
[
'
pdfs
'
][
0
,
2
:
4
,
8
]
==
5
))
@pytest.mark.parametrize
(
"
given_normal
"
,
[
True
,
False
])
def
test_free_slip
(
given_normal
):
# check if Free slip BC is applied correctly
stencil
=
LBStencil
(
Stencil
.
D2Q9
)
dh
=
create_data_handling
(
domain_size
=
(
4
,
4
),)
src1
=
dh
.
add_array
(
'
src1
'
,
values_per_cell
=
stencil
.
Q
)
dh
.
fill
(
'
src1
'
,
0.0
,
ghost_layers
=
True
)
shape
=
dh
.
gather_array
(
'
src1
'
,
ghost_layers
=
True
).
shape
num
=
0
for
x
in
range
(
shape
[
0
]):
for
y
in
range
(
shape
[
1
]):
for
direction
in
range
(
shape
[
2
]):
dh
.
cpu_arrays
[
src1
.
name
][
x
,
y
,
direction
]
=
num
num
+=
1
method
=
create_lb_method
(
lbm_config
=
LBMConfig
(
stencil
=
stencil
,
method
=
Method
.
SRT
,
relaxation_rate
=
1.8
))
bh
=
LatticeBoltzmannBoundaryHandling
(
method
,
dh
,
'
src1
'
,
name
=
"
bh1
"
)
if
given_normal
:
free_slipN
=
FreeSlip
(
stencil
=
stencil
,
normal_direction
=
(
0
,
-
1
))
free_slipS
=
FreeSlip
(
stencil
=
stencil
,
normal_direction
=
(
0
,
1
))
free_slipE
=
FreeSlip
(
stencil
=
stencil
,
normal_direction
=
(
-
1
,
0
))
free_slipW
=
FreeSlip
(
stencil
=
stencil
,
normal_direction
=
(
1
,
0
))
bh
.
set_boundary
(
free_slipN
,
slice_from_direction
(
'
N
'
,
dh
.
dim
))
bh
.
set_boundary
(
free_slipS
,
slice_from_direction
(
'
S
'
,
dh
.
dim
))
bh
.
set_boundary
(
free_slipE
,
slice_from_direction
(
'
E
'
,
dh
.
dim
))
bh
.
set_boundary
(
free_slipW
,
slice_from_direction
(
'
W
'
,
dh
.
dim
))
else
:
free_slip
=
FreeSlip
(
stencil
=
stencil
)
bh
.
set_boundary
(
free_slip
,
slice_from_direction
(
'
N
'
,
dh
.
dim
))
bh
.
set_boundary
(
free_slip
,
slice_from_direction
(
'
S
'
,
dh
.
dim
))
bh
.
set_boundary
(
free_slip
,
slice_from_direction
(
'
E
'
,
dh
.
dim
))
bh
.
set_boundary
(
free_slip
,
slice_from_direction
(
'
W
'
,
dh
.
dim
))
bh
()
mirrored_dirN
=
{
6
:
8
,
1
:
2
,
5
:
7
}
mirrored_dirS
=
{
7
:
5
,
2
:
1
,
8
:
6
}
mirrored_dirE
=
{
6
:
5
,
4
:
3
,
8
:
7
}
mirrored_dirW
=
{
5
:
6
,
3
:
4
,
7
:
8
}
# check North
assert
dh
.
cpu_arrays
[
src1
.
name
][
1
,
-
1
,
mirrored_dirN
[
6
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
1
,
-
2
,
6
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
1
,
-
1
,
mirrored_dirN
[
1
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
1
,
-
2
,
1
]
for
i
in
range
(
2
,
4
):
assert
dh
.
cpu_arrays
[
src1
.
name
][
i
,
-
1
,
mirrored_dirN
[
6
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
i
,
-
2
,
6
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
i
,
-
1
,
mirrored_dirN
[
1
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
i
,
-
2
,
1
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
i
,
-
1
,
mirrored_dirN
[
5
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
i
,
-
2
,
5
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
4
,
-
1
,
mirrored_dirN
[
1
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
4
,
-
2
,
1
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
4
,
-
1
,
mirrored_dirN
[
5
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
4
,
-
2
,
5
]
# check East
assert
dh
.
cpu_arrays
[
src1
.
name
][
-
1
,
1
,
mirrored_dirE
[
6
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
-
2
,
1
,
6
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
-
1
,
1
,
mirrored_dirE
[
4
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
-
2
,
1
,
4
]
for
i
in
range
(
2
,
4
):
assert
dh
.
cpu_arrays
[
src1
.
name
][
-
1
,
i
,
mirrored_dirE
[
6
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
-
2
,
i
,
6
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
-
1
,
i
,
mirrored_dirE
[
4
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
-
2
,
i
,
4
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
-
1
,
i
,
mirrored_dirE
[
8
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
-
2
,
i
,
8
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
-
1
,
4
,
mirrored_dirE
[
4
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
-
2
,
4
,
4
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
-
1
,
4
,
mirrored_dirE
[
8
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
-
2
,
4
,
8
]
# check South
assert
dh
.
cpu_arrays
[
src1
.
name
][
1
,
0
,
mirrored_dirS
[
8
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
1
,
1
,
8
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
1
,
0
,
mirrored_dirS
[
2
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
1
,
1
,
2
]
for
i
in
range
(
2
,
4
):
assert
dh
.
cpu_arrays
[
src1
.
name
][
i
,
0
,
mirrored_dirS
[
7
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
i
,
1
,
7
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
i
,
0
,
mirrored_dirS
[
2
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
i
,
1
,
2
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
i
,
0
,
mirrored_dirS
[
8
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
i
,
1
,
8
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
4
,
0
,
mirrored_dirS
[
2
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
4
,
1
,
2
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
4
,
0
,
mirrored_dirS
[
7
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
4
,
1
,
7
]
# check West
assert
dh
.
cpu_arrays
[
src1
.
name
][
0
,
1
,
mirrored_dirW
[
5
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
1
,
1
,
5
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
0
,
1
,
mirrored_dirW
[
3
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
1
,
1
,
3
]
for
i
in
range
(
2
,
4
):
assert
dh
.
cpu_arrays
[
src1
.
name
][
0
,
i
,
mirrored_dirW
[
5
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
1
,
i
,
5
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
0
,
i
,
mirrored_dirW
[
3
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
1
,
i
,
3
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
0
,
i
,
mirrored_dirW
[
7
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
1
,
i
,
7
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
0
,
4
,
mirrored_dirW
[
3
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
1
,
4
,
3
]
assert
dh
.
cpu_arrays
[
src1
.
name
][
0
,
4
,
mirrored_dirW
[
7
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
1
,
4
,
7
]
if
given_normal
:
# check corners --> determined by the last boundary applied there.
# SouthWest --> West
assert
dh
.
cpu_arrays
[
src1
.
name
][
0
,
0
,
mirrored_dirW
[
5
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
1
,
0
,
5
]
# NorthWest --> West
assert
dh
.
cpu_arrays
[
src1
.
name
][
0
,
-
1
,
mirrored_dirW
[
7
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
1
,
-
1
,
7
]
# NorthEast --> East
assert
dh
.
cpu_arrays
[
src1
.
name
][
-
1
,
-
1
,
mirrored_dirE
[
8
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
-
2
,
-
1
,
8
]
# SouthEast --> East
assert
dh
.
cpu_arrays
[
src1
.
name
][
-
1
,
0
,
mirrored_dirE
[
6
]]
==
dh
.
cpu_arrays
[
src1
.
name
][
-
2
,
0
,
6
]
else
:
# check corners --> this time the normals are calculated correctly in the corners
# SouthWest --> Normal = (1, 1); dir 7 --> 6
assert
dh
.
cpu_arrays
[
src1
.
name
][
0
,
0
,
6
]
==
dh
.
cpu_arrays
[
src1
.
name
][
1
,
1
,
7
]
# NorthWest --> Normal = (1, -1); dir 8 --> 5
assert
dh
.
cpu_arrays
[
src1
.
name
][
0
,
-
1
,
8
]
==
dh
.
cpu_arrays
[
src1
.
name
][
1
,
-
2
,
5
]
# NorthEast --> Normal = (-1, -1); dir 7 --> 6
assert
dh
.
cpu_arrays
[
src1
.
name
][
-
1
,
-
1
,
7
]
==
dh
.
cpu_arrays
[
src1
.
name
][
-
2
,
-
2
,
6
]
# SouthEast --> Normal = (-1, 1); dir 5 --> 8
assert
dh
.
cpu_arrays
[
src1
.
name
][
-
1
,
0
,
5
]
==
dh
.
cpu_arrays
[
src1
.
name
][
-
2
,
1
,
8
]
def
test_free_slip_index_list
():
stencil
=
LBStencil
(
Stencil
.
D2Q9
)
dh
=
create_data_handling
(
domain_size
=
(
4
,
4
),
periodicity
=
(
False
,
False
))
...
...
@@ -214,7 +330,7 @@ def test_free_slip_equivalence():
bh1
()
bh2
()
assert
np
.
array_equal
(
dh
.
cpu
_array
s
[
'
src1
'
]
,
dh
.
cpu
_array
s
[
'
src2
'
]
)
assert
np
.
array_equal
(
dh
.
gather
_array
(
'
src1
'
)
,
dh
.
gather
_array
(
'
src2
'
)
)
def
test_exotic_boundaries
():
...
...
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
sign in
to comment