def taylor_green(n): mesh = UnitSquareMesh(n, n) nu = 1 / 100 U_e = ('-(cos(pi*(x[0]))*sin(pi*(x[1]))) * exp(-2.0*nu*pi*pi*t)', ' (cos(pi*(x[1]))*sin(pi*(x[0]))) * exp(-2.0*nu*pi*pi*t)') P_e = '-0.25*(cos(2*pi*(x[0])) + cos(2*pi*(x[1]))) * exp(-4.0*nu*pi*pi*t)' u_e = Expression(U_e, degree=3, t=0, nu=float(nu)) K_e = 0.5 * assemble(inner(u_e, u_e) * dx(mesh)) ###############CHORIN############### (u1, p1, time1) = chorin_method(mesh, c_d, U_e, P_e) K1 = 0.5 * assemble(inner(u1, u1) * dx(mesh)) er1 = K_e - K1 ###############IPCS############### (u2, p2, time2) = ipcs_method(mesh, c_d, U_e, P_e) K2 = 0.5 * assemble(inner(u2, u2) * dx(mesh)) er2 = K_e - K2 ###############GALERKIN############### (u3, p3, time3) = galerkin_method(mesh, c_d, U_e, P_e) K3 = 0.5 * assemble(inner(u3, u3) * dx(mesh)) er3 = K_e - K3 degrees1 = u1.vector().size() + p1.vector().size() degrees2 = u3.vector().size() + p3.vector().size() return mesh, er1, er2, er3, time1, time2, time3, degrees1, degrees2
def cylinder_flow(n): channel = Rectangle(Point(0, 0), Point(2.2, 0.41)) cylinder = Circle(Point(0.2, 0.2), 0.05) domain = channel - cylinder mesh = generate_mesh(domain, n) p_e = -0.111444953719 ###############CHORIN############### (u1, p1, time1) = chorin_method(mesh) p1_a = p1(0.45, 0.2) p1_b = p1(0.55, 0.2) p_1 = p1_b - p1_a er1 = p_e - p_1 ###############IPCS############### (u2, p2, time2) = ipcs_method(mesh) p2_a = p2(0.45, 0.2) p2_b = p2(0.55, 0.2) p_2 = p2_b - p2_a er2 = p_e - p_2 ###############GALERKIN############### (u3, p3, time3) = galerkin_method(mesh) p3_a = p3(0.45, 0.2) p3_b = p3(0.55, 0.2) p_3 = p3_b - p3_a er3 = p_e - p_3 degrees1 = u1.vector().size() + p1.vector().size() degrees2 = u3.vector().size() + p3.vector().size() return mesh, er1, er2, er3, time1, time2, time3, degrees1, degrees2
u1_a = u1(1.0, 0.5)[0] print('Tempo chorin: ', fim1 - inicio1) print('velocidade x : ', u1_a) errorChorin = 1 - (u_e - u1_a) / u_e print('error chorin: ', errorChorin) print('degrees of freedom: ', u1.vector().size() + p1.vector().size()) plot(u1) plt.savefig('VelocityChorin' + str(i) + '.png') plot(p1) plt.savefig('PressureChorin' + str(i) + '.png') inicio2 = time.time() (u2, p2) = ipcs_method(rho, n, k, u, v, nu, f, p, q, bcu, bcp, dt, V, Q, teste, u0, p0, T) fim2 = time.time() u2_a = u2(1.0, 0.5)[0] print('Tempo IPCS: ', fim2 - inicio2) print('velocidade x : ', u2_a) errorChorin = 1 - (u_e - u2_a) / u_e print('error IPCS: ', errorChorin) print('degrees of freedom: ', u2.vector().size() + p2.vector().size()) plot(u2) plt.savefig('VelocityIPCS.png') plot(p2) plt.savefig('PressureIPCS.png')
def pressure_driven(n): mesh = UnitSquareMesh(n, n) h = mesh.hmin() V = VectorFunctionSpace(mesh, 'P', 2) Q = FunctionSpace(mesh, 'P', 1) # Define Boundaries and Boundary Condictions inflow = 'near(x[0], 0)' outflow = 'near(x[0], 1)' walls = 'near(x[1], 0) || near(x[1], 1)' bcu_noslip = DirichletBC(V, Constant((0.0, 0.0)), walls) bcp_in = DirichletBC(Q, Constant(1.0), inflow) bcp_out = DirichletBC(Q, Constant(0.0), outflow) bcu = [bcu_noslip] bcp = [bcp_in, bcp_out] # Define variacional parameters u = TrialFunction(V) p = TrialFunction(Q) v = TestFunction(V) q = TestFunction(Q) # Set parameter values T = 0.5 # final time dt = 0.2*h/1. # time step CFL with 1 = max. velocity # Set parameter values T = 0.5 # final time dt = 0.2*h/1. # time step CFL with 1 = max. velocity nu = 1/8 # kinematic viscosity rho = 1 k = dt u0 = Constant((0.0, 0.0)) p0 = Constant(0.0) f = Constant((0.0, 0.0)) teste = 0 u_e = 0.44321183655 ###############CHORIN############### inicio1 = time.time() (u1,p1) = chorin_method(k, u, v, nu, f, p, q, bcu, bcp, dt, V, Q, teste, u0, p0, T) fim1 = time.time() time1 = (fim1 - inicio1) u1_a = u1(1.0,0.5)[0] er1 = u_e - u1_a ###############IPCS############### (u2,p2,time2) = ipcs_method(mesh) u2_a = u2(1.0,0.5)[0] er2 = u_e - u2_a ###############IPCS############### (u3, p3, time3) = galerkin_method(mesh) u3_a = u3(1.0,0.5)[0] er3 = u_e - u3_a degrees1 = u1.vector().size() + p1.vector().size() degrees2 = u3.vector().size() + p3.vector().size() return mesh, er1, er2, er3, time1, time2, time3, degrees1, degrees2
def driven_cavity(n): mesh = UnitSquareMesh(n, n) h = mesh.hmin() V = VectorFunctionSpace(mesh, 'P', 2) Q = FunctionSpace(mesh, 'P', 1) # Define Boundaries and Boundary Condictions upperedge = 'near(x[1], 1)' noslip = 'near(x[1], 0) || near(x[0], 1) || near(x[0], 0)' bcu_noslip = DirichletBC(V, Constant((0.0, 0.0)), noslip) bcu_top = DirichletBC(V, Constant((1.0, 0.0)), upperedge) bcu = [bcu_noslip, bcu_top] bcp = [] # Define variacional parameters u = TrialFunction(V) p = TrialFunction(Q) v = TestFunction(V) q = TestFunction(Q) # Set parameter values T = 2.5 # final time dt = 0.2 * h / 1. # time step CFL with 1 = max. velocity nu = 1 / 1000 # kinematic viscosity k = dt u0 = Constant((0.0, 0.0)) p0 = Constant(0.0) f = Constant((0.0, 0.0)) rho = 1 n = FacetNormal(mesh) teste = 0 psi_e = -0.0585236 ###############CHORIN############### inicio1 = time.time() (u1, p1) = chorin_method(k, u, v, nu, f, p, q, bcu, bcp, dt, V, Q, teste, u0, p0, T) fim1 = time.time() time1 = (fim1 - inicio1) psi1 = stream_function(u1) stream_min1 = np.array(psi1.vector()).min() er1 = psi_e - stream_min1 ###############IPCS############### inicio2 = time.time() (u2, p2) = ipcs_method(rho, n, k, u, v, nu, f, p, q, bcu, bcp, dt, V, Q, teste, u0, p0, T) fim2 = time.time() time2 = (fim2 - inicio2) psi2 = stream_function(u2) stream_min2 = np.array(psi2.vector()).min() er2 = psi_e - stream_min2 ###############IPCS############### (u3, p3, time3) = galerkin_method(mesh) psi3 = stream_function(u3) stream_min3 = np.array(psi3.vector()).min() er3 = psi_e - stream_min3 degrees1 = u1.vector().size() + p1.vector().size() degrees2 = u3.vector().size() + p3.vector().size() return mesh, er1, er2, er3, time1, time2, time3, degrees1, degrees2