def func1(x): _asp_declare('double', 'A_0star') _asp_declare('double', 'b1star') A_0star = 5 b1star = 2 return x[2] - (b1star / A_0star) * (x[0] - sqrt(A_0star))
def func2(x): _asp_declare('double', 'rho') _asp_declare('double', 'c1star') rho = 1050 c1star = 2 return x[1] - (x[2] - 2) / (rho * c1star)
def func2(x): _asp_declare('double', 'A_0star') _asp_declare('double', 'b1star') A_0star = 1 b1star = 2 return x[2] - (b1star / A_0star) * x[0]
def func0(x): _asp_declare('double', 'A_0star') _asp_declare('double', 'b1star') A_0star = 5 b1star = 2 return x[0] - 4 * pow(x[0], 2) - (x[0] - 1)
def func1(x): _asp_declare('double', 'rho') _asp_declare('double', 'c1star') rho = 1050 c1star = 0.001 return x[2] - x[1] * rho * c1star
def func0(x): _asp_declare('double', 'u_inflow') u_inflow = 0 return x[1] - u_inflow
def func1(x): _asp_declare('double', 'rho') _asp_declare('double', 'b1_1') _asp_declare('double', 'b1_2') _asp_declare('double', 'b1_3') _asp_declare('double', 'A_0_1') _asp_declare('double', 'A_0_2') _asp_declare('double', 'A_0_3') rho = 1 b1_1 = 2 b1_2 = 3 b1_3 = 4 A_0_1 = 5 A_0_2 = 6 A_0_3 = 7 return (b1_1 / A_0_1 * x[0] - b1_2 / A_0_2 * x[1] * .5 * rho * (pow(x[3], 2) - pow(x[4], 2)))
def func5(x): _asp_declare('double', 'rho') _asp_declare('double', 'b1_1') _asp_declare('double', 'b1_2') _asp_declare('double', 'b1_3') _asp_declare('double', 'A_0_1') _asp_declare('double', 'A_0_2') _asp_declare('double', 'A_0_3') rho = 1 b1_1 = 2 b1_2 = 3 b1_3 = 4 A_0_1 = 5 A_0_2 = 6 A_0_3 = 7 return x[5] + pow(4 * x[2], 2) * b1_3 / (2 * rho * A_0_3)
def kernel(self, in_grid, out_grid): # must declare the variables before using them. #should eventually analyze code statically and automatically do this. _asp_declare('double', 'delt') _asp_declare('double', 'delx') _asp_declare('double', 'Ainitstar') _asp_declare('double', 'betastar') _asp_declare('double', 'rho') _asp_declare('double', 'c') _asp_declare('double', 'cstar') delt = 1.0 delx = 2.0 Ainitstar = 3.0 betastar = 4.0 rho = 5.0 c = 6.0 cstar = 7.0 # declare the temporary uL/uR values _asp_declare('double', 'uL_A') _asp_declare('double', 'uL_u') _asp_declare('double', 'uL_p') _asp_declare('double', 'uR_A') _asp_declare('double', 'uR_u') _asp_declare('double', 'uR_p') # lambda1=U(:,2)+c; # lambda2=U(:,2)-c; for x in out_grid.interior_points(): for y in in_grid.neighbors(x, 1): # Strategy: calculate all uL,uR values, and use them to # calculate the uI output values # uL(2,n) = U(1,n) + B(1,1)*U(1,n).*(.5*(1-(U(1,2)+c)*delt./delx(1))) # Shift the point over by 1 since the output interface line has # a ghost depth of 2. # FIXME: ASP doesn't like this...yet. # y = tuple(i - 1 for i in y) uL_A = (in_grid[y].A + in_grid[y].A * (0.5 * (1 - in_grid[y].A + c) * delt / delx)) uL_u = (in_grid[y].u + in_grid[y].u * (0.5 * (1 - in_grid[y].u + c) * delt / delx)) uL_p = (in_grid[y].p + in_grid[y].p * (0.5 * (1 - in_grid[y].p + c) * delt / delx)) # uR(1,n) = U(1,n) - B(1,1)*U(1,n).*(.5*(1+(U(1,2)-c)*delt./delx(1))) uR_A = (in_grid[y].A + in_grid[y].A * (0.5 * (1 + in_grid[y].A - c) * delt / delx)) uR_u = (in_grid[y].u + in_grid[y].u * (0.5 * (1 + in_grid[y].u - c) * delt / delx)) uR_p = (in_grid[y].p + in_grid[y].p * (0.5 * (1 + in_grid[y].p - c) * delt / delx)) # uI(:,1)=(uI(:,3).*Ainitstar./betastar+Ainitstar.^.5).^2; out_grid[x].A = pow(out_grid[x].p * Ainitstar / betastar + sqrt(Ainitstar), 2) # uI(:,2)=(1./(2*rho*cstar)).*(uL(:,3)-uR(:,3))+0.5*(uL(:,2)+uR(:,2)); out_grid[x].u = (1.0 / (2 * rho * cstar) * (uL_p - uR_p) + 0.5 * (uL_u + uR_p)) # uI(:,3)=.5*(uL(:,3)+uR(:,3))+.5*rho*cstar.*(uL(:,2)-uR(:,2)); out_grid[x].p = (0.5 * (uL_p + uR_p) + 0.5 * rho * cstar * (uL_u - uR_u))