Skip to content
Snippets Groups Projects
Commit e577d829 authored by Jean-Matthieu Etancelin's avatar Jean-Matthieu Etancelin
Browse files

Add 2D demo real time rendering

parent 840062ab
No related branches found
No related tags found
No related merge requests found
__kernel void initScalar(__global float* scalar,
float4 minPos,
float4 size)
{
uint gidX = get_global_id(0);
uint gidY = get_global_id(1);
uint i;
float2 pos, center=(float2)(0.5, 0.75),center2=(float2)(0.75, 0.25),center3=(float2)(0.4, 0.4),center4=(float2)(0.6, 0.5);
for(i=gidX; i<WIDTH; i+=WGN)
{
pos = (float2)(i*size.x, gidY*size.y);
scalar[i+gidY*(WIDTH)] = ((distance(pos, center)<0.15) ? 1.0 : ((distance(pos, center2)<0.15) ? 2.0 : ((fabs(center3.x-pos.x)+fabs(center3.y-pos.y)<0.1) ? 3.0 : ((10.0*maxmag(fabs(center4.x-pos.x),fabs(center4.y-pos.y))<0.8) ? 4.0 : 0.0))));
}
}
#define PI (float)M_PI
__kernel void initVelocity(__global float* veloX,__global float* veloY,
float4 minPos,
float4 size)
{
uint gidX = get_global_id(0);
uint gidY = get_global_id(1);
uint i;
float v;
for(i=gidX; i<WIDTH; i+=WGN)
{
v = veloX[i+gidY*(WIDTH)] = -sin(i*size.x * PI)*sin(i*size.x * PI)*sin(gidY*size.y * PI * 2);
veloX[i+gidY*(WIDTH)] = v; // = Vx(x,y)
veloY[i+gidY*(WIDTH)] = -v;// = Vy(y,x) = -Vx(x,y)
}
}
__kernel void analyticVelocity(__global float* veloX,__global float* veloY,
float t,
float4 minPos,
float4 size)
{
uint gidX = get_global_id(0);
uint gidY = get_global_id(1);
uint i;
float v;
float time_term = cos(t*PI/3.0);
for(i=gidX; i<WIDTH; i+=WGN)
{
v = veloX[i+gidY*(WIDTH)] = -sin(i*size.x * PI)*sin(i*size.x * PI)*sin(gidY*size.y * PI * 2)*time_term;
veloX[i+gidY*(WIDTH)] = v; // = Vx(x,y)
veloY[i+gidY*(WIDTH)] = -v;// = Vy(y,x) = -Vx(x,y)
}
}
#!/bin/env python
import time
from parmepy.domain.box import Box
from parmepy.gpu import PARMES_REAL_GPU, PARMES_DOUBLE_GPU
from parmepy.fields.continuous import Field
from parmepy.fields.analytical import AnalyticalField
from parmepy.operator.advection import Advection
from parmepy.problem.transport import TransportProblem
from parmepy.operator.monitors.printer import Printer
from parmepy.operator.analytic import Analytic
from parmepy.gpu.QtRendering import QtOpenGLRendering
import math
import sys
def run(nb=257):
dim = 2
boxLength = [1., 1.]
boxMin = [0., 0.]
nbElem = [nb, nb]
timeStep = 0.025
finalTime = 3.
## Domain
box = Box(dim, length=boxLength, origin=boxMin)
## Fields
scal = Field(domain=box, name='Scalar')
velo = Field(domain=box, name='Velocity', isVector=True)
## Operators
advec = Advection(velo, scal,
resolutions={velo: nbElem,
scal: nbElem},
method='gpu_1k_m6prime',
src=['./demo_2D.cl'],
precision=PARMES_REAL_GPU,
)
velocity = Analytic(velo, None,
resolutions={velo: nbElem, },
method='gpu',
src=['./demo_2D.cl'],
)
render = QtOpenGLRendering(scal)
##Problem
pb = TransportProblem([velocity, advec],
monitors=[render])
## Setting solver to Problem
pb.setUp(finalTime, timeStep)
## Solve problem
pb.solve()
if __name__ == "__main__":
run(1025)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment