mirror of
https://github.com/smyalygames/FiniteVolumeGPU.git
synced 2026-01-14 15:48:43 +01:00
Fixed order again
This commit is contained in:
@@ -46,71 +46,65 @@ class WAF (Simulator.BaseSimulator):
|
||||
dt: Size of each timestep (90 s)
|
||||
g: Gravitational accelleration (9.81 m/s^2)
|
||||
"""
|
||||
def __init__(self, \
|
||||
context, \
|
||||
h0, hu0, hv0, \
|
||||
nx, ny, \
|
||||
dx, dy, dt, \
|
||||
g, \
|
||||
order=2, \
|
||||
boundary_conditions=BoundaryCondition(), \
|
||||
def __init__(self,
|
||||
context,
|
||||
h0, hu0, hv0,
|
||||
nx, ny,
|
||||
dx, dy, dt,
|
||||
g,
|
||||
boundary_conditions=BoundaryCondition(),
|
||||
block_width=16, block_height=16):
|
||||
|
||||
# Call super constructor
|
||||
super().__init__(context, \
|
||||
nx, ny, \
|
||||
dx, dy, dt, \
|
||||
super().__init__(context,
|
||||
nx, ny,
|
||||
dx, dy, dt*2,
|
||||
block_width, block_height);
|
||||
self.g = np.float32(g)
|
||||
self.order = np.int32(order)
|
||||
self.boundary_conditions = boundary_conditions.asCodedInt()
|
||||
|
||||
#Get kernels
|
||||
self.kernel = context.get_prepared_kernel("cuda/SWE2D_WAF.cu", "WAFKernel", \
|
||||
"iiffffiiPiPiPiPiPiPi", \
|
||||
module = context.get_module("cuda/SWE2D_WAF.cu",
|
||||
defines={
|
||||
'BLOCK_WIDTH': self.block_size[0],
|
||||
'BLOCK_HEIGHT': self.block_size[1]
|
||||
}, \
|
||||
},
|
||||
compile_args={
|
||||
'no_extern_c': True,
|
||||
'options': ["--use_fast_math"],
|
||||
}, \
|
||||
},
|
||||
jit_compile_args={})
|
||||
self.kernel = module.get_function("WAFKernel")
|
||||
self.kernel.prepare("iiffffiiPiPiPiPiPiPi")
|
||||
|
||||
#Create data by uploading to device
|
||||
self.u0 = Common.ArakawaA2D(self.stream, \
|
||||
nx, ny, \
|
||||
2, 2, \
|
||||
self.u0 = Common.ArakawaA2D(self.stream,
|
||||
nx, ny,
|
||||
2, 2,
|
||||
[h0, hu0, hv0])
|
||||
self.u1 = Common.ArakawaA2D(self.stream, \
|
||||
nx, ny, \
|
||||
2, 2, \
|
||||
self.u1 = Common.ArakawaA2D(self.stream,
|
||||
nx, ny,
|
||||
2, 2,
|
||||
[None, None, None])
|
||||
|
||||
def step(self, dt):
|
||||
if (self.order == 1):
|
||||
self.substepDimsplit(dt, substep=(self.nt % 2))
|
||||
elif (self.order == 2):
|
||||
self.substepDimsplit(dt, substep=0)
|
||||
self.substepDimsplit(dt, substep=1)
|
||||
else:
|
||||
raise(NotImplementedError("Order {:d} is not implemented".format(self.order)))
|
||||
self.substepDimsplit(dt*0.5, substep=0)
|
||||
self.substepDimsplit(dt*0.5, substep=1)
|
||||
self.t += dt
|
||||
self.nt += 1
|
||||
self.nt += 2
|
||||
|
||||
def substepDimsplit(self, dt, substep):
|
||||
self.kernel.prepared_async_call(self.grid_size, self.block_size, self.stream, \
|
||||
self.nx, self.ny, \
|
||||
self.dx, self.dy, dt, \
|
||||
self.g, \
|
||||
Simulator.stepOrderToCodedInt(step=substep, order=self.order), \
|
||||
self.boundary_conditions, \
|
||||
self.u0[0].data.gpudata, self.u0[0].data.strides[0], \
|
||||
self.u0[1].data.gpudata, self.u0[1].data.strides[0], \
|
||||
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.kernel.prepared_async_call(self.grid_size, self.block_size, self.stream,
|
||||
self.nx, self.ny,
|
||||
self.dx, self.dy, dt,
|
||||
self.g,
|
||||
substep,
|
||||
self.boundary_conditions,
|
||||
self.u0[0].data.gpudata, self.u0[0].data.strides[0],
|
||||
self.u0[1].data.gpudata, self.u0[1].data.strides[0],
|
||||
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.u0, self.u1 = self.u1, self.u0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user