This commit is contained in:
André R. Brodtkorb 2018-11-11 15:12:56 +01:00
parent e98ae0a979
commit dcb849b705
3 changed files with 35 additions and 16 deletions

View File

@ -69,6 +69,10 @@ class HLL2 (Simulator.BaseSimulator):
self.theta = np.float32(theta)
self.order = np.int32(order)
self.boundary_conditions = boundary_conditions.asCodedInt()
#This kernel is dimensionally split, and therefore only second order every other
#dimsplit timestep. Therefore, step always runs two substeps
self.dt = 2*self.dt
#Get kernels
self.kernel = context.get_prepared_kernel("cuda/SWE2D_HLL2.cu", "HLL2Kernel", \
@ -95,14 +99,15 @@ class HLL2 (Simulator.BaseSimulator):
def step(self, dt):
if (self.order == 1):
self.substepDimsplit(dt, substep=(self.nt % 2))
self.substepDimsplit(0.5*dt, 0)
self.substepDimsplit(0.5*dt, 1)
elif (self.order == 2):
self.substepDimsplit(dt, substep=0)
self.substepDimsplit(dt, substep=1)
self.substepDimsplit(0.5*dt, 0)
self.substepDimsplit(0.5*dt, 1)
else:
raise(NotImplementedError("Order {:d} is not implemented".format(self.order)))
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, \

View File

@ -82,10 +82,10 @@ class BoundaryCondition(object):
Helper function which packs four boundary conditions into one integer
"""
bc = 0
bc = bc | (self.north & 0x000F) << 24
bc = bc | (self.south & 0x000F) << 16
bc = bc | (self.east & 0x000F) << 8
bc = bc | (self.west & 0x000F)
bc = bc | (self.north & 0x0000000F) << 24
bc = bc | (self.south & 0x0000000F) << 16
bc = bc | (self.east & 0x0000000F) << 8
bc = bc | (self.west & 0x0000000F)
#for t in types:
# print("{0:s}, {1:d}, {1:032b}, {1:08b}".format(t, types[t]))
@ -153,11 +153,11 @@ class BaseSimulator(object):
self.t = 0.0
self.nt = 0
def __str__(self):
return "{:s} [{:d}x{:d}]".format(self.__class__.__name__, self.nx, self.ny)
def simulate(self, t_end):
"""
Function which simulates t_end seconds using the step function
@ -233,7 +233,7 @@ def stepOrderToCodedInt(step, order):
"""
Helper function which packs the step and order into a single integer
"""
step_order = (step << 16) ^ (order & 0x00ff)
step_order = (step << 16) | (order & 0x0000ffff)
#print("Step: {0:032b}".format(step))
#print("Order: {0:032b}".format(order))
#print("Mix: {0:032b}".format(step_order))

View File

@ -114,15 +114,15 @@ enum BoundaryCondition {
};
inline __device__ BoundaryCondition getBCNorth(int bc_) {
return static_cast<BoundaryCondition>(bc_ & 0x000F);
return static_cast<BoundaryCondition>(bc_ & 0x0000000F);
}
inline __device__ BoundaryCondition getBCSouth(int bc_) {
return static_cast<BoundaryCondition>((bc_ >> 8) & 0x000F);
return static_cast<BoundaryCondition>((bc_ >> 8) & 0x0000000F);
}
inline __device__ BoundaryCondition getBCEast(int bc_) {
return static_cast<BoundaryCondition>((bc_ >> 16) & 0x000F);
return static_cast<BoundaryCondition>((bc_ >> 16) & 0x0000000F);
}
inline __device__ BoundaryCondition getBCWest(int bc_) {
@ -260,12 +260,26 @@ inline __device__ void writeBlock(float* ptr_, int pitch_,
float* const row = (float*) ((char*) ptr_ + pitch_*tj);
//Handle runge-kutta timestepping here
row[ti] = shmem[ty][tx];
/**
* SSPRK2
* u^1 = u^n + dt*f(u^n)
* u^n+1 = 1/2*u^n + 1/2*(u^1 + dt*f(u^1))
*
* SSPRK3
* u^1 = u^n + dt*f(u^n)
* u^2 = 3/4 * u^n + 1/4 * (u^1 + dt*f(u^1))
* u^n+1 = 1/3 * u^n + 2/3 * (u^2 + dt*f(u^2))
*/
/*
if (rk_order_ == 2 && rk_step_ == 1) {
row[ti] = 0.5f*(row[ti] + shmem[ty][tx]);
}
else {
row[ti] = shmem[ty][tx];
}
}*/
}
}