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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
lbmpy
Commits
890811d8
Commit
890811d8
authored
5 years ago
by
Stephan Seitz
Browse files
Options
Downloads
Patches
Plain Diff
Execute LBM scenario with OpenCL
It compiles so it's correct I guess...
parent
d4679714
No related branches found
No related tags found
1 merge request
!13
Execute LBM scenario with OpenCL
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lbmpy/lbstep.py
+8
-5
8 additions, 5 deletions
lbmpy/lbstep.py
lbmpy/scenarios.py
+8
-2
8 additions, 2 deletions
lbmpy/scenarios.py
lbmpy_tests/test_lbstep.py
+29
-0
29 additions, 0 deletions
lbmpy_tests/test_lbstep.py
with
45 additions
and
7 deletions
lbmpy/lbstep.py
+
8
−
5
View file @
890811d8
...
@@ -18,7 +18,7 @@ from pystencils.timeloop import TimeLoop
...
@@ -18,7 +18,7 @@ from pystencils.timeloop import TimeLoop
class
LatticeBoltzmannStep
:
class
LatticeBoltzmannStep
:
def
__init__
(
self
,
domain_size
=
None
,
lbm_kernel
=
None
,
periodicity
=
False
,
def
__init__
(
self
,
domain_size
=
None
,
lbm_kernel
=
None
,
periodicity
=
False
,
kernel_params
=
MappingProxyType
({}),
data_handling
=
None
,
name
=
"
lbm
"
,
optimization
=
None
,
kernel_params
=
MappingProxyType
({}),
data_handling
=
None
,
name
=
"
lbm
"
,
optimization
=
{}
,
velocity_data_name
=
None
,
density_data_name
=
None
,
density_data_index
=
None
,
velocity_data_name
=
None
,
density_data_name
=
None
,
density_data_index
=
None
,
compute_velocity_in_every_step
=
False
,
compute_density_in_every_step
=
False
,
compute_velocity_in_every_step
=
False
,
compute_density_in_every_step
=
False
,
velocity_input_array_name
=
None
,
time_step_order
=
'
stream_collide
'
,
flag_interface
=
None
,
velocity_input_array_name
=
None
,
time_step_order
=
'
stream_collide
'
,
flag_interface
=
None
,
...
@@ -29,11 +29,15 @@ class LatticeBoltzmannStep:
...
@@ -29,11 +29,15 @@ class LatticeBoltzmannStep:
if
domain_size
is
not
None
:
if
domain_size
is
not
None
:
raise
ValueError
(
"
When passing a data_handling, the domain_size parameter can not be specified
"
)
raise
ValueError
(
"
When passing a data_handling, the domain_size parameter can not be specified
"
)
target
=
optimization
.
get
(
'
target
'
,
'
cpu
'
)
if
data_handling
is
None
:
if
data_handling
is
None
:
if
domain_size
is
None
:
if
domain_size
is
None
:
raise
ValueError
(
"
Specify either domain_size or data_handling
"
)
raise
ValueError
(
"
Specify either domain_size or data_handling
"
)
data_handling
=
create_data_handling
(
domain_size
,
default_ghost_layers
=
1
,
data_handling
=
create_data_handling
(
domain_size
,
periodicity
=
periodicity
,
parallel
=
False
)
default_ghost_layers
=
1
,
periodicity
=
periodicity
,
default_target
=
target
,
parallel
=
False
)
if
'
stencil
'
not
in
method_parameters
:
if
'
stencil
'
not
in
method_parameters
:
method_parameters
[
'
stencil
'
]
=
'
D2Q9
'
if
data_handling
.
dim
==
2
else
'
D3Q27
'
method_parameters
[
'
stencil
'
]
=
'
D2Q9
'
if
data_handling
.
dim
==
2
else
'
D3Q27
'
...
@@ -47,7 +51,6 @@ class LatticeBoltzmannStep:
...
@@ -47,7 +51,6 @@ class LatticeBoltzmannStep:
q
=
len
(
lbm_kernel
.
method
.
stencil
)
q
=
len
(
lbm_kernel
.
method
.
stencil
)
else
:
else
:
q
=
len
(
get_stencil
(
method_parameters
[
'
stencil
'
]))
q
=
len
(
get_stencil
(
method_parameters
[
'
stencil
'
]))
target
=
optimization
[
'
target
'
]
self
.
name
=
name
self
.
name
=
name
self
.
_data_handling
=
data_handling
self
.
_data_handling
=
data_handling
...
@@ -58,7 +61,7 @@ class LatticeBoltzmannStep:
...
@@ -58,7 +61,7 @@ class LatticeBoltzmannStep:
self
.
density_data_index
=
density_data_index
self
.
density_data_index
=
density_data_index
self
.
_optimization
=
optimization
self
.
_optimization
=
optimization
self
.
_gpu
=
target
==
'
gpu
'
self
.
_gpu
=
target
==
'
gpu
'
or
target
==
'
opencl
'
layout
=
optimization
[
'
field_layout
'
]
layout
=
optimization
[
'
field_layout
'
]
alignment
=
False
alignment
=
False
...
...
This diff is collapsed.
Click to expand it.
lbmpy/scenarios.py
+
8
−
2
View file @
890811d8
...
@@ -85,7 +85,13 @@ def create_lid_driven_cavity(domain_size=None, lid_velocity=0.005, lbm_kernel=No
...
@@ -85,7 +85,13 @@ def create_lid_driven_cavity(domain_size=None, lid_velocity=0.005, lbm_kernel=No
"""
"""
assert
domain_size
is
not
None
or
data_handling
is
not
None
assert
domain_size
is
not
None
or
data_handling
is
not
None
if
data_handling
is
None
:
if
data_handling
is
None
:
data_handling
=
create_data_handling
(
domain_size
,
periodicity
=
False
,
default_ghost_layers
=
1
,
parallel
=
parallel
)
optimization
=
kwargs
.
get
(
'
optimization
'
,
None
)
target
=
optimization
.
get
(
'
target
'
,
None
)
if
optimization
else
None
data_handling
=
create_data_handling
(
domain_size
,
periodicity
=
False
,
default_ghost_layers
=
1
,
parallel
=
parallel
,
default_target
=
target
)
step
=
LatticeBoltzmannStep
(
data_handling
=
data_handling
,
lbm_kernel
=
lbm_kernel
,
name
=
"
ldc
"
,
**
kwargs
)
step
=
LatticeBoltzmannStep
(
data_handling
=
data_handling
,
lbm_kernel
=
lbm_kernel
,
name
=
"
ldc
"
,
**
kwargs
)
my_ubb
=
UBB
(
velocity
=
[
lid_velocity
,
0
,
0
][:
step
.
method
.
dim
])
my_ubb
=
UBB
(
velocity
=
[
lid_velocity
,
0
,
0
][:
step
.
method
.
dim
])
...
@@ -99,7 +105,7 @@ def create_lid_driven_cavity(domain_size=None, lid_velocity=0.005, lbm_kernel=No
...
@@ -99,7 +105,7 @@ def create_lid_driven_cavity(domain_size=None, lid_velocity=0.005, lbm_kernel=No
def
create_channel
(
domain_size
=
None
,
force
=
None
,
pressure_difference
=
None
,
u_max
=
None
,
diameter_callback
=
None
,
def
create_channel
(
domain_size
=
None
,
force
=
None
,
pressure_difference
=
None
,
u_max
=
None
,
diameter_callback
=
None
,
duct
=
False
,
wall_boundary
=
NoSlip
(),
parallel
=
False
,
data_handling
=
None
,
**
kwargs
):
duct
=
False
,
wall_boundary
=
NoSlip
(),
parallel
=
False
,
data_handling
=
None
,
**
kwargs
):
"""
Create a channel scenario (2D or 3D).
"""
Create a channel scenario (2D or 3D).
The channel can be driven either by force, velocity inflow or pressure difference. Choose one and pass
The channel can be driven either by force, velocity inflow or pressure difference. Choose one and pass
exactly one of the parameters
'
force
'
,
'
pressure_difference
'
or
'
u_max
'
.
exactly one of the parameters
'
force
'
,
'
pressure_difference
'
or
'
u_max
'
.
...
...
This diff is collapsed.
Click to expand it.
lbmpy_tests/test_lbstep.py
+
29
−
0
View file @
890811d8
...
@@ -48,6 +48,35 @@ def test_data_handling_3d():
...
@@ -48,6 +48,35 @@ def test_data_handling_3d():
np
.
testing
.
assert_almost_equal
(
results
[
0
],
arr
)
np
.
testing
.
assert_almost_equal
(
results
[
0
],
arr
)
def
test_data_handling_2d_opencl
():
pytest
.
importorskip
(
'
pyopencl
'
)
import
pystencils.opencl.opencljit
pystencils
.
opencl
.
opencljit
.
init_globally
()
print
(
"
--- LDC 2D test ---
"
)
results
=
[]
for
parallel
in
[
True
,
False
]
if
parallel_available
else
[
False
]:
for
gpu
in
[
True
,
False
]
if
gpu_available
else
[
False
]:
if
parallel
and
gpu
and
not
hasattr
(
wLB
,
'
cuda
'
):
continue
print
(
"
Testing parallel: %s
\t
gpu: %s
"
%
(
parallel
,
gpu
))
opt_params
=
{
'
target
'
:
'
opencl
'
if
gpu
else
'
cpu
'
,
'
gpu_indexing_params
'
:
{
'
block_size
'
:
(
8
,
4
,
2
)}}
if
parallel
:
from
pystencils.datahandling
import
ParallelDataHandling
blocks
=
wLB
.
createUniformBlockGrid
(
blocks
=
(
2
,
3
,
1
),
cellsPerBlock
=
(
5
,
5
,
1
),
oneBlockPerProcess
=
False
)
dh
=
ParallelDataHandling
(
blocks
,
dim
=
2
)
rho
=
ldc_setup
(
data_handling
=
dh
,
optimization
=
opt_params
)
results
.
append
(
rho
)
else
:
rho
=
ldc_setup
(
domain_size
=
(
10
,
15
),
parallel
=
False
,
optimization
=
opt_params
)
results
.
append
(
rho
)
for
i
,
arr
in
enumerate
(
results
[
1
:]):
print
(
"
Testing equivalence version 0 with version %d
"
%
(
i
+
1
,))
np
.
testing
.
assert_almost_equal
(
results
[
0
],
arr
)
def
test_data_handling_2d
():
def
test_data_handling_2d
():
print
(
"
--- LDC 2D test ---
"
)
print
(
"
--- LDC 2D test ---
"
)
results
=
[]
results
=
[]
...
...
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