Updated to python 3, and took a look at WAF

This commit is contained in:
André R. Brodtkorb 2018-07-20 16:02:41 +02:00
parent c5dc865c48
commit e5200cd200
14 changed files with 140 additions and 134 deletions

File diff suppressed because one or more lines are too long

View File

@ -25,7 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#Import packages we need #Import packages we need
import numpy as np import numpy as np
import pyopencl as cl #OpenCL in Python import pyopencl as cl #OpenCL in Python
import Common from SWESimulators import Common
@ -103,6 +103,8 @@ class CDKLM16:
) )
def __str__(self):
return "Chertok, Dudzinski, Kurganov, Lukacova-Medvidova"
""" """

View File

@ -27,7 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#Import packages we need #Import packages we need
import numpy as np import numpy as np
import pyopencl as cl #OpenCL in Python import pyopencl as cl #OpenCL in Python
import Common from SWESimulators import Common
@ -109,6 +109,8 @@ class CTCS:
) )
def __str__(self):
return "Centered in time, centered in space"
""" """

View File

@ -26,7 +26,8 @@ def get_kernel(cl_ctx, kernel_filename, block_width, block_height):
return '"' + s.replace(" ", "\\ ") + '"' return '"' + s.replace(" ", "\\ ") + '"'
elif ('NVIDIA' in platform_name): elif ('NVIDIA' in platform_name):
#NVIDIA doesn't like double quoted paths... #NVIDIA doesn't like double quoted paths...
return "'" + s + "'" #return "'" + s + "'"
return s
module_path = os.path.dirname(os.path.realpath(__file__)) module_path = os.path.dirname(os.path.realpath(__file__))
module_path_escaped = shellquote(module_path) module_path_escaped = shellquote(module_path)
@ -96,7 +97,7 @@ class OpenCLArray2D:
@staticmethod @staticmethod
def convert_to_float32(data): def convert_to_float32(data):
if (not np.issubdtype(data.dtype, np.float32) or np.isfortran(data)): if (not np.issubdtype(data.dtype, np.float32) or np.isfortran(data)):
print "Converting H0" #print("Converting H0")
return data.astype(np.float32, order='C') return data.astype(np.float32, order='C')
else: else:
return data return data

View File

@ -103,7 +103,7 @@ class CTCSNetCDFWriter:
def __exit__(self, exc_type, exc_value, traceback): def __exit__(self, exc_type, exc_value, traceback):
print "Closing '" + self.ncfile.filepath() + "'" #print("Closing '" + self.ncfile.filepath() + "'")
self.ncfile.close() self.ncfile.close()

View File

@ -25,7 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#Import packages we need #Import packages we need
import numpy as np import numpy as np
import pyopencl as cl #OpenCL in Python import pyopencl as cl #OpenCL in Python
import Common from SWESimulators import Common
@ -111,6 +111,8 @@ class FBL:
) )
def __str__(self):
return "Forward Backward Linear"
""" """

View File

@ -23,7 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#Import packages we need #Import packages we need
import numpy as np import numpy as np
import pyopencl as cl #OpenCL in Python import pyopencl as cl #OpenCL in Python
import Common from SWESimulators import Common
@ -93,6 +93,8 @@ class FORCE:
) )
def __str__(self):
return "First order centered"
""" """

View File

@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#Import packages we need #Import packages we need
import numpy as np import numpy as np
import pyopencl as cl #OpenCL in Python import pyopencl as cl #OpenCL in Python
import Common from SWESimulators import Common
@ -89,6 +89,8 @@ class HLL:
) )
def __str__(self):
return "Harten-Lax-van Leer"
""" """

View File

@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#Import packages we need #Import packages we need
import numpy as np import numpy as np
import pyopencl as cl #OpenCL in Python import pyopencl as cl #OpenCL in Python
import Common from SWESimulators import Common
@ -92,6 +92,8 @@ class HLL2:
) )
def __str__(self):
return "Harten-Lax-van Leer contact discontinuity"
""" """

View File

@ -27,7 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#Import packages we need #Import packages we need
import numpy as np import numpy as np
import pyopencl as cl #OpenCL in Python import pyopencl as cl #OpenCL in Python
import Common from SWESimulators import Common
@ -111,6 +111,8 @@ class KP07:
def __str__(self):
return "Kurganov-Petrova"
""" """
Function which steps n timesteps Function which steps n timesteps

View File

@ -27,7 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#Import packages we need #Import packages we need
import numpy as np import numpy as np
import pyopencl as cl #OpenCL in Python import pyopencl as cl #OpenCL in Python
import Common from SWESimulators import Common
@ -93,6 +93,8 @@ class KP07_dimsplit:
) )
def __str__(self):
return "Kurganov-Petrova dimensionally split"
""" """

View File

@ -23,7 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#Import packages we need #Import packages we need
import numpy as np import numpy as np
import pyopencl as cl #OpenCL in Python import pyopencl as cl #OpenCL in Python
import Common from SWESimulators import Common
@ -94,6 +94,8 @@ class LxF:
def __str__(self):
return "Lax Friedrichs"
""" """
Function which steps n timesteps Function which steps n timesteps

View File

@ -23,7 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#Import packages we need #Import packages we need
import numpy as np import numpy as np
import pyopencl as cl #OpenCL in Python import pyopencl as cl #OpenCL in Python
import Common from SWESimulators import Common

View File

@ -749,7 +749,7 @@ float WAF_minbee(float r_, float c_) {
if (r_ <= 0.0f) { if (r_ <= 0.0f) {
return 1.0f; return 1.0f;
} }
else if (r_ <= 1.0f) { else if (r_ >= 0.0f && r_ <= 1.0f) {
return 1.0f - (1.0f - fabs(c_))*r_; return 1.0f - (1.0f - fabs(c_))*r_;
} }
else { else {
@ -833,17 +833,13 @@ float3 WAF_1D_flux(const float3 Q_l2, const float3 Q_l1, const float3 Q_r1, cons
const float c_3 = S_r * dt_ / dx_; const float c_3 = S_r * dt_ / dx_;
// Compute the "upwind change" vectors for the i-3/2 and i+3/2 interfaces // Compute the "upwind change" vectors for the i-3/2 and i+3/2 interfaces
// We use h for the tangential direction, and v for the normal direction const float rh_m = fmin(fmax( (h_l - h_l2) / (h_r - h_l), -1.0f ), 1.0f);
const float dh = h_r - h_l; const float rh_p = fmin(fmax( (h_r2 - h_r) / (h_r - h_l), -1.0f ), 1.0f);
const float rh_m = (h_l - h_l2) / dh;
const float rh_p = (h_r2 - h_r) / dh;
const float dv = v_r - v_l; const float rv_m = fmin(fmax( (v_l - v_l2) / (v_r - v_l), -1.0f ), 1.0f);
const float rv_m = (v_l - v_l2) / dv; const float rv_p = fmin(fmax( (v_r2 - v_r) / (v_r - v_l), -1.0f ), 1.0f);
const float rv_p = (v_r2 - v_r) / dv;
// Compute the r parameters for the flux limiter // Compute the r parameters for the flux limiter
// Note that you use h for h and hu, and v for hv component/equation
const float rh_1 = (c_1 > 0.0f) ? rh_m : rh_p; const float rh_1 = (c_1 > 0.0f) ? rh_m : rh_p;
const float rv_1 = (c_1 > 0.0f) ? rv_m : rv_p; const float rv_1 = (c_1 > 0.0f) ? rv_m : rv_p;
@ -854,9 +850,10 @@ float3 WAF_1D_flux(const float3 Q_l2, const float3 Q_l1, const float3 Q_r1, cons
const float rv_3 = (c_3 > 0.0f) ? rv_m : rv_p; const float rv_3 = (c_3 > 0.0f) ? rv_m : rv_p;
// Compute the limiter // Compute the limiter
const float A_1 = sign(c_1)*WAF_minbee(rh_1, c_1); // We use h for the nonlinear waves, and v for the middle shear wave
const float A_2 = sign(c_2)*WAF_minbee(rv_2, c_2); const float A_1 = c_1;//sign(c_1)*WAF_minbee(rh_1, c_1);
const float A_3 = sign(c_3)*WAF_minbee(rh_3, c_3); const float A_2 = c_2;//sign(c_2)*WAF_minbee(rv_2, c_2); //Middle shear wave
const float A_3 = c_3;//sign(c_3)*WAF_minbee(rh_3, c_3);
//Average the fluxes //Average the fluxes
const float3 flux = 0.5f*( F_1 + F_4 ) const float3 flux = 0.5f*( F_1 + F_4 )