Commit c3e2d2d5 authored by coulette's avatar coulette

up small tests

parent 7c266d3e
......@@ -191,7 +191,7 @@ if __name__ == '__main__':
# gpu solve
wplot_gpu = solve_ocl(**vars(args))
#print(np.sum(wplot_gpu[:, _ivplot, :, :],axis=0))
print(np.sum(wplot_gpu[:, _ivplot, :, :],axis=0))
plt.clf()
#plt.imshow(np.sum(wplot_gpu[:, _ivplot, :, :],axis=0), vmin=0, vmax=1)
......
......@@ -19,7 +19,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%%bash\n",
......@@ -29,7 +31,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%env XAUTHORITY=/tmp/x11-auth-file\n",
......@@ -63,7 +67,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%env PYOPENCL_CTX=0:1"
......@@ -80,6 +86,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"scrolled": false
},
"outputs": [],
......@@ -111,7 +118,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"Tmax = 0.1\n",
......@@ -130,7 +139,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%env PYOPENCL_CTX=0:4\n",
......@@ -140,7 +151,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"print(\"GPU [s]: {:f}\".format(result_gpu.best))\n",
......@@ -164,7 +177,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
"version": "3.6.3"
}
},
"nbformat": 4,
......
#define _NC _nc_
#define _NVS _nvs_
#define _NV _nv_
#define _NX _nx_
#define _NY _ny_
#define _DX _dx_
#define _DY _dy_
#define _VMAX _vmax_
#define _T _t_
#define real _real_
#define _NGRID (_NX * _NY)
__constant real vi[_NV][2]= _vi_;
__constant real v0[2] = {1.0_F, 0.0_F};
inline int get_memindex(int ix, int iy, int iv){
int index = 0;
index = iv * (_NGRID) + _NX * iy + ix;
return index;
}
inline int get_ivindex(int ivloc,int ivar){
int index = 0;
index = ivar * _NVS + ivloc;
return index;
}
void flux_phy( real w[_NC], real flux[_NC][2]){
for (int k = 0; k < _NC; k++){
flux[k][0] = v0[0] * w[k];
flux[k][1] = v0[1] * w[k];
}
}
void feq_D2Q4( real w[_NC], real f[_NV]){
real flux[_NC][2];
flux_phy(w,flux);
for (int k = 0; k < _NC ; k++){
for (int ivloc = 0; ivloc < _NVS ; ivloc++){
int iv = get_ivindex(ivloc,k);
f[iv] = 0.25_F * w[k] + (vi[ivloc][0] * flux[k][0] + vi[ivloc][1] * flux[k][1]) / (2.0 * _VMAX);
}
}
}
void analytical_sol(real t,real xin[2],real w[_NC]){
real x[2] = {xin[0] - 0.5_F - v0[0] * t, xin[1] - 0.5_F - v0[1] * t};
for (int k = 0; k < _NC; k++){
w[k] = exp (-100.0_F * (x[0] * x[0] + x[1] * x[1]));
}
}
__kernel void exact_sol(__global real *fn){
int id = get_global_id(0);
int i = id % _NX;
int j = id / _NX;
real x[2] = { i * _DX , j * _DY };
real w[_NC];
analytical_sol(_T,x,w);
real fnow[_NV];
feq_D2Q4(w,fnow);
for (int iv = 0; iv < _NV; iv++){
int imem = get_memindex(i,j,iv);
fn[imem] = fnow[iv];
}
}
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function
import pyopencl as cl
import numpy as np
#import matplotlib.pyplot as plt
import time
#define _NC _nc_
#define _NVS _nvs_
#define _NV _nv_
#define _NX _nx_
#define _NY _ny_
#define _RELCOEFF _relcoeff_
#define _VMAX _vmax_
#define real _real_
#define _NGRID (_NX * _NY)
#define _COMPRELCOEFF (1._F - _RELCOEFF)
__constant real vi[_NV][2]= _vi_;
__constant real v0[2] = {1.0_F, 0.0_F};
inline int get_memindex(int ix, int iy, int iv){
int index = 0;
index = iv * (_NGRID) + _NX * iy + ix;
return index;
}
inline int get_ivindex(int ivloc,int ivar){
int index = 0;
index = ivar * _NVS + ivloc;
return index;
}
void flux_phy( real w[_NC], real flux[_NC][2]){
for (int k = 0; k < _NC; k++){
flux[k][0] = v0[0] * w[k];
flux[k][1] = v0[1] * w[k];
}
}
void micro_to_macro( real f[_NV],real w[_NC]){
for (int k = 0; k < _NC; k++){
w[k] = 0._F;
for (int ivloc = 0; ivloc < _NVS; ivloc++){
w[k] += f[ k * _NVS + ivloc];
}
}
}
void feq_D2Q4( real w[_NC], real f[_NV]){
real flux[_NC][2];
flux_phy(w,flux);
for (int k = 0; k < _NC ; k++){
for (int ivloc = 0; ivloc < _NVS ; ivloc++){
int iv = get_ivindex(ivloc,k);
f[iv] = 0.25_F * w[k] + (vi[ivloc][0] * flux[k][0] + vi[ivloc][1] * flux[k][1]) / (2.0 * _VMAX);
}
}
}
__kernel void relax_bgk(__global real *fn, __global real *fnp1){
int id = get_global_id(0);
int i = id % _NX;
int j = id / _NX;
// get f
real fnow[_NV];
for (int iv = 0; iv < _NV; iv++){
int imem = get_memindex(i,j,iv);
fnow[iv] = fn[imem];
}
real wnow[_NC];
real feq[_NV];
feq_D2Q4(wnow,feq);
for (int iv = 0; iv < _NV ; iv++){
fnow[iv] = _RELCOEFF * feq[iv] + _COMPRELCOEFF * fnow[iv];
}
for (int iv = 0; iv < _NV; iv++){
int imem = get_memindex(i,j,iv);
fnp1[imem] = fnow[iv];
}
}
This diff is collapsed.
#define _NC _nc_
#define _NVS _nvs_
#define _NV _nv_
#define _NX _nx_
#define _NY _ny_
#define _DX _dx_
#define _DY _dy_
#define _INTERP_D _interp_d_
#define _NGRID (_NX*_NY)
#define _NSTENCIL (2 * _INTERP_D +2)
#define real _real_
__constant int offset[_NVS][2] = _offset_;
__constant real locshift[_NVS][2] = _locshift_;
__constant real lag_coeffs_x[_NVS][_NSTENCIL] = _lag_coeffs_x_;
__constant real lag_coeffs_y[_NVS][_NSTENCIL] = _lag_coeffs_y_;
inline int get_memindex(int ix, int iy, int iv){
int index = 0;
index = iv * (_NGRID) + _NX * iy + ix;
return index;
}
inline int get_ivindex(int ivloc,int ivar){
int index = 0;
index = ivar * _NVS + ivloc;
return index;
}
__kernel void init_sol(__global real *fn){
int id = get_global_id(0);
//int size = get_global_size(0);
int i = id % _NX;
int j = id / _NX;
real xy[2] = {i * _DX + _DX / 2 - 0.5_F, j * _DY + _DY / 2 - 0.5_F};
for(int ik = 0; ik < _NV; ik++){
int imem = get_memindex(i,j,ik);
fn[imem] = exp (-20.0_F * (xy[0] * xy[0] + xy[1] * xy[1]));
}
}
__kernel void transport_xO1(__global real *fn, __global real *fnp1){
int id = get_global_id(0);
int i = id % _NX;
int j = id / _NX;
real fnow[_NV];
for (int ivloc = 0; ivloc < _NVS; ivloc++){
real fshift2 = locshift[ivloc][0];
real fshift1 = 1._F-fshift2;
int iorig1 = (i - offset[ivloc][0] + _NX) % _NX;
int iorig2 = (iorig1 + 1 + _NX) % _NX;
for (int ivar = 0; ivar < _NC; ivar++){
int iv = get_ivindex(ivloc,ivar);
int imem1 = get_memindex(iorig1,j,iv);
int imem2 = get_memindex(iorig2,j,iv);
//int imem = get_memindex(i,j,iv);
fnow[iv] = fshift1 * fn[imem1] + fshift2 * fn[imem2];
//fnow[iv] = fn[imem1];
}
} // end iv
for (int iv = 0; iv < _NV; iv++){
int imem = get_memindex(i,j,iv);
fnp1[imem] = fnow[iv];
}
}
__kernel void transport_yO1(__global real *fn, __global real *fnp1){
int id = get_global_id(0);
int i = id % _NX;
int j = id / _NX;
real fnow[_NV];
for (int ivloc = 0; ivloc < _NVS; ivloc++){
real fshift2 = locshift[ivloc][1];
real fshift1 = 1._F-fshift2;
int jorig1 = (j - offset[ivloc][1] + _NY) % _NY;
int jorig2 = (jorig1 + 1 + _NY) % _NY;
for (int ivar = 0; ivar < _NC; ivar++){
int iv = get_ivindex(ivloc,ivar);
int imem1 = get_memindex(i,jorig1,iv);
int imem2 = get_memindex(i,jorig2,iv);
fnow[iv] = fshift1 * fn[imem1] + fshift2 * fn[imem2];
}
} // end iv
for (int iv = 0; iv < _NV; iv++){
int imem = get_memindex(i,j,iv);
fnp1[imem] = fnow[iv];
}
}
__kernel void transport_xlag(__global real *fn, __global real *fnp1){
int id = get_global_id(0);
int i = id % _NX;
int j = id / _NX;
real fnow[_NV];
for (int ivloc = 0; ivloc < _NVS; ivloc++){
int iorig[_NSTENCIL];
for (int isten = 0; isten < _NSTENCIL; isten++){
iorig[isten] = (i +isten -_INTERP_D -1 - offset[ivloc][0] + _NX) % _NX;
}
for (int ivar = 0; ivar < _NC; ivar++){
int iv = get_ivindex(ivloc,ivar);
fnow[iv] = 0._F;
for (int isten = 0; isten <_NSTENCIL; isten++){
int imem = get_memindex(iorig[isten],j,iv);
fnow[iv] += fn[imem] * lag_coeffs_x[ivloc][isten];
}
}
} // end iv
for (int iv = 0; iv < _NV; iv++){
int imem = get_memindex(i,j,iv);
fnp1[imem] = fnow[iv];
}
}
__kernel void transport_ylag(__global real *fn, __global real *fnp1){
int id = get_global_id(0);
int i = id % _NX;
int j = id / _NX;
real fnow[_NV];
for (int ivloc = 0; ivloc < _NVS; ivloc++){
int iorig[_NSTENCIL];
for (int isten = 0; isten < _NSTENCIL; isten++){
iorig[isten] = (j +isten -_INTERP_D -1 - offset[ivloc][1] + _NX) % _NX;
}
for (int ivar = 0; ivar < _NC; ivar++){
int iv = get_ivindex(ivloc,ivar);
fnow[iv] = 0._F;
for (int isten = 0; isten <_NSTENCIL; isten++){
int imem = get_memindex(i,iorig[isten],iv);
fnow[iv] += fn[imem] * lag_coeffs_y[ivloc][isten];
}
}
} // end iv
for (int iv = 0; iv < _NV; iv++){
int imem = get_memindex(i,j,iv);
fnp1[imem] = fnow[iv];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment