Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
patapon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
David Coulette
patapon
Commits
d54bcd0b
Commit
d54bcd0b
authored
Nov 19, 2017
by
ph
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add transport solver
parent
4e01a62a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
41 deletions
+68
-41
transport_cl.py
transport_cl.py
+28
-8
transport_kernels.cl
transport_kernels.cl
+40
-33
No files found.
transport_cl.py
View file @
d54bcd0b
...
@@ -19,6 +19,9 @@ ny = 50
...
@@ -19,6 +19,9 @@ ny = 50
Lx
=
1.
Lx
=
1.
Ly
=
1.
Ly
=
1.
# number of animation frames
nbplots
=
10
dx
=
Lx
/
nx
dx
=
Lx
/
nx
dy
=
Ly
/
ny
dy
=
Ly
/
ny
...
@@ -28,13 +31,19 @@ vel = np.array([1., 1.])
...
@@ -28,13 +31,19 @@ vel = np.array([1., 1.])
vmax
=
np
.
sqrt
(
vel
[
0
]
**
2
+
vel
[
1
]
**
2
)
vmax
=
np
.
sqrt
(
vel
[
0
]
**
2
+
vel
[
1
]
**
2
)
# time stepping
# time stepping
Tmax
=
1
Tmax
=
0.5
/
vmax
cfl
=
0.8
cfl
=
0.8
iterplot
=
5000
dt
=
cfl
*
(
dx
*
dy
)
/
(
2
*
dx
+
2
*
dy
)
/
vmax
dt
=
cfl
*
(
dx
*
dy
)
/
(
2
*
dx
+
2
*
dy
)
/
vmax
itermax
=
int
(
np
.
floor
(
Tmax
/
dt
))
iterplot
=
int
(
itermax
/
nbplots
)
print
(
"itermax="
,
itermax
,
" iterplot="
,
iterplot
,
"tmax="
,
itermax
*
dt
)
#exit()
def
fluxnum
(
wL
,
wR
,
vnorm
):
def
fluxnum
(
wL
,
wR
,
vnorm
):
vdotn
=
vel
[
0
]
*
vnorm
[
0
]
+
vel
[
1
]
*
vnorm
[
1
]
vdotn
=
vel
[
0
]
*
vnorm
[
0
]
+
vel
[
1
]
*
vnorm
[
1
]
vnp
=
0
vnp
=
0
...
@@ -61,7 +70,7 @@ def solve_python(wn):
...
@@ -61,7 +70,7 @@ def solve_python(wn):
wn
[
i
,
j
]
=
exact_sol
(
xy
,
t
)
wn
[
i
,
j
]
=
exact_sol
(
xy
,
t
)
#print("i j", xy,wn[i,j])
#print("i j", xy,wn[i,j])
wnp1
=
np
.
zeros
((
nx
,
ny
))
wnp1
=
np
.
zeros
((
nx
,
ny
)
,
dtype
=
'float32'
)
np
.
copyto
(
wnp1
,
wn
)
np
.
copyto
(
wnp1
,
wn
)
iter
=
0
iter
=
0
while
t
<
Tmax
:
while
t
<
Tmax
:
...
@@ -128,17 +137,20 @@ while t < Tmax:
...
@@ -128,17 +137,20 @@ while t < Tmax:
t
=
t
+
dt
t
=
t
+
dt
iter
=
iter
+
1
iter
=
iter
+
1
prg
.
time_step
(
queue
,
(
nx
*
ny
,
),
(
32
,
),
wn_gpu
,
wnp1_gpu
).
wait
()
prg
.
time_step
(
queue
,
(
nx
*
ny
,
),
(
32
,
),
wn_gpu
,
wnp1_gpu
).
wait
()
# exchange buffer references for avoiding a copy
wn_gpu
,
wnp1_gpu
=
wnp1_gpu
,
wn_gpu
wn_gpu
,
wnp1_gpu
=
wnp1_gpu
,
wn_gpu
print
(
"iter="
,
iter
,
" t="
,
t
)
print
(
"iter="
,
iter
,
" t="
,
t
)
if
iter
%
iterplot
==
0
:
if
iter
%
iterplot
==
0
:
cl
.
enqueue_copy
(
queue
,
wn_cpu
,
wn_gpu
).
wait
()
cl
.
enqueue_copy
(
queue
,
wn_cpu
,
wn_gpu
).
wait
()
wplot
=
np
.
reshape
(
wn_cpu
,
(
nx
,
ny
))
wplot
=
np
.
reshape
(
wn_cpu
,
(
nx
,
ny
))
plt
.
clf
()
plt
.
clf
()
plt
.
imshow
(
wplot
)
plt
.
imshow
(
wplot
,
vmin
=
0
,
vmax
=
1
)
plt
.
colorbar
()
plt
.
pause
(
0.01
)
plt
.
pause
(
0.01
)
if
iter
%
2
!=
0
:
# in case of an odd number of iterations, perform a last exchange
wn_gpu
,
wnp1_gpu
=
wnp1_gpu
,
wn_gpu
#if iter % 2 != 0:
# wn_gpu, wnp1_gpu = wnp1_gpu, wn_gpu
# prg.K2(queue, (taille, ), None, y_gpu).wait()
# prg.K2(queue, (taille, ), None, y_gpu).wait()
...
@@ -149,14 +161,22 @@ cl.enqueue_copy(queue, wn_cpu, wn_gpu).wait()
...
@@ -149,14 +161,22 @@ cl.enqueue_copy(queue, wn_cpu, wn_gpu).wait()
wplot
=
np
.
reshape
(
wn_cpu
,(
nx
,
ny
))
wplot
=
np
.
reshape
(
wn_cpu
,(
nx
,
ny
))
plt
.
clf
()
plt
.
clf
()
plt
.
imshow
(
wplot
)
plt
.
imshow
(
wplot
,
vmin
=
0
,
vmax
=
1
)
plt
.
colorbar
()
plt
.
show
()
plt
.
show
()
wplot_gpu
=
wplot
.
copy
()
solve_python
(
wplot
)
solve_python
(
wplot
)
plt
.
clf
()
plt
.
clf
()
plt
.
imshow
(
wplot
[
1
:
nx
-
1
,
1
:
ny
-
1
])
plt
.
imshow
(
wplot
,
vmin
=
0
,
vmax
=
1
)
plt
.
colorbar
()
plt
.
show
()
plt
.
show
()
plt
.
clf
()
plt
.
imshow
(
wplot
-
wplot_gpu
)
plt
.
colorbar
()
plt
.
show
()
transport_kernels.cl
View file @
d54bcd0b
...
@@ -58,6 +58,9 @@ __kernel void init_sol(__global float *wn){
...
@@ -58,6 +58,9 @@ __kernel void init_sol(__global float *wn){
for
(
int
iv
=
0
; iv < _M; iv++){
for
(
int
iv
=
0
; iv < _M; iv++){
int
imem
=
i
+
j
*
_NX
+
iv
*
ngrid
;
int
imem
=
i
+
j
*
_NX
+
iv
*
ngrid
;
wn[imem]
=
wnow[iv]
;
wn[imem]
=
wnow[iv]
;
//
boundary
values
if
(
i
==
0
|
| i == _NX - 1 || j == 0 |
|
j
==
_NY
-
1
)
wn[imem]
=
_WBORD
;
}
}
}
}
...
@@ -72,6 +75,7 @@ __kernel void time_step(__global float *wn, __global float *wnp1){
...
@@ -72,6 +75,7 @@ __kernel void time_step(__global float *wn, __global float *wnp1){
int
i
=
id
%
_NX
;
int
i
=
id
%
_NX
;
int
j
=
id
/
_NX
;
int
j
=
id
/
_NX
;
int
ngrid
=
_NX
*
_NY
;
int
ngrid
=
_NX
*
_NY
;
float
wnow[_M]
;
float
wnow[_M]
;
...
@@ -84,6 +88,7 @@ __kernel void time_step(__global float *wn, __global float *wnp1){
...
@@ -84,6 +88,7 @@ __kernel void time_step(__global float *wn, __global float *wnp1){
wnext[iv]
=
wnow[iv]
;
wnext[iv]
=
wnow[iv]
;
}
}
if
(
i
>
0
&&
i
<
_NX
-
1
&&
j
>
0
&&
j
<
_NY
-
1
)
{
float
flux[_M]
;
float
flux[_M]
;
//
loop
on
all
directions:
//
loop
on
all
directions:
...
@@ -100,12 +105,12 @@ __kernel void time_step(__global float *wn, __global float *wnp1){
...
@@ -100,12 +105,12 @@ __kernel void time_step(__global float *wn, __global float *wnp1){
//
load
neighbour
values
if
accessible
//
load
neighbour
values
if
accessible
float
wR[_M]
;
float
wR[_M]
;
for
(
int
iv
=
0
; iv < _M; iv++) wR[iv] = _WBORD;
for
(
int
iv
=
0
; iv < _M; iv++) wR[iv] = _WBORD;
if
((
iR
>=
0
)
&&
(
iR
<=
_NX
-
1
)
&&
(
jR
>=
0
)
&&
(
jR
<=
_NY
-
1
))
{
//
if
((
iR
>=
0
)
&&
(
iR
<=
_NX
-
1
)
&&
(
jR
>=
0
)
&&
(
jR
<=
_NY
-
1
))
{
for
(
int
iv
=
0
; iv < _M; iv++){
for
(
int
iv
=
0
; iv < _M; iv++){
int
imem
=
iv
*
ngrid
+
iR
+
jR
*
_NX
;
int
imem
=
iv
*
ngrid
+
iR
+
jR
*
_NX
;
wR[iv]
=
wn[imem]
;
wR[iv]
=
wn[imem]
;
}
}
}
//
}
fluxnum
(
wnow,
wR,
vn,
flux
)
;
fluxnum
(
wnow,
wR,
vn,
flux
)
;
//
time
evolution
//
time
evolution
...
@@ -116,6 +121,7 @@ __kernel void time_step(__global float *wn, __global float *wnp1){
...
@@ -116,6 +121,7 @@ __kernel void time_step(__global float *wn, __global float *wnp1){
}
}
}
//
copy
wnext
into
global
memory
//
copy
wnext
into
global
memory
for
(
int
iv
=
0
; iv < _M; iv++){
for
(
int
iv
=
0
; iv < _M; iv++){
...
@@ -124,4 +130,5 @@ __kernel void time_step(__global float *wn, __global float *wnp1){
...
@@ -124,4 +130,5 @@ __kernel void time_step(__global float *wn, __global float *wnp1){
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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