mirror of
https://github.com/smyalygames/FiniteVolumeGPU.git
synced 2026-01-14 15:48:43 +01:00
Implemented variable timestep
This commit is contained in:
@@ -29,6 +29,7 @@ from GPUSimulators import Simulator, Common
|
||||
from GPUSimulators.Simulator import BaseSimulator, BoundaryCondition
|
||||
import numpy as np
|
||||
|
||||
from pycuda import gpuarray
|
||||
|
||||
|
||||
|
||||
@@ -57,6 +58,7 @@ class KP07 (Simulator.BaseSimulator):
|
||||
dx, dy, dt,
|
||||
g,
|
||||
theta=1.3,
|
||||
cfl_scale=0.9,
|
||||
order=2,
|
||||
boundary_conditions=BoundaryCondition(),
|
||||
block_width=16, block_height=16):
|
||||
@@ -67,7 +69,8 @@ class KP07 (Simulator.BaseSimulator):
|
||||
dx, dy, dt,
|
||||
block_width, block_height);
|
||||
self.g = np.float32(g)
|
||||
self.theta = np.float32(theta)
|
||||
self.theta = np.float32(theta)
|
||||
self.cfl_scale = cfl_scale
|
||||
self.order = np.int32(order)
|
||||
self.boundary_conditions = boundary_conditions.asCodedInt()
|
||||
|
||||
@@ -83,7 +86,7 @@ class KP07 (Simulator.BaseSimulator):
|
||||
},
|
||||
jit_compile_args={})
|
||||
self.kernel = module.get_function("KP07Kernel")
|
||||
self.kernel.prepare("iifffffiiPiPiPiPiPiPi")
|
||||
self.kernel.prepare("iifffffiiPiPiPiPiPiPiP")
|
||||
|
||||
#Create data by uploading to device
|
||||
self.u0 = Common.ArakawaA2D(self.stream,
|
||||
@@ -94,6 +97,8 @@ class KP07 (Simulator.BaseSimulator):
|
||||
nx, ny,
|
||||
2, 2,
|
||||
[None, None, None])
|
||||
self.cfl_data = gpuarray.GPUArray(self.grid_size, dtype=np.float32)
|
||||
self.cfl_data.fill(self.dt, stream=self.stream)
|
||||
|
||||
|
||||
def step(self, dt):
|
||||
@@ -121,9 +126,18 @@ class KP07 (Simulator.BaseSimulator):
|
||||
self.u0[2].data.gpudata, self.u0[2].data.strides[0],
|
||||
self.u1[0].data.gpudata, self.u1[0].data.strides[0],
|
||||
self.u1[1].data.gpudata, self.u1[1].data.strides[0],
|
||||
self.u1[2].data.gpudata, self.u1[2].data.strides[0])
|
||||
self.u1[2].data.gpudata, self.u1[2].data.strides[0],
|
||||
self.cfl_data.gpudata)
|
||||
self.u0, self.u1 = self.u1, self.u0
|
||||
|
||||
|
||||
def download(self):
|
||||
return self.u0.download(self.stream)
|
||||
return self.u0.download(self.stream)
|
||||
|
||||
def check(self):
|
||||
self.u0.check()
|
||||
self.u1.check()
|
||||
|
||||
def computeDt(self):
|
||||
max_dt = gpuarray.min(self.cfl_data, stream=self.stream).get();
|
||||
return max_dt*0.5**self.order*self.cfl_scale
|
||||
Reference in New Issue
Block a user