[bc.apply(A1, b1) for bc in bcu] solve(A1, u1.vector(), b1, "bicgstab", "default") # Pressure correction b2 = assemble(L2) [bc.apply(A2, b2) for bc in bcp] [bc.apply(p1.vector()) for bc in bcp] solve(A2, p1.vector(), b2, "bicgstab", prec) # Velocity correction b3 = assemble(L3) [bc.apply(A3, b3) for bc in bcu] solve(A3, u1.vector(), b3, "bicgstab", "default") # Move to next time step u0.assign(u1) t += dt # Plot solution plot( u1, mode='mesh and arrows', text="Velocity of fluid", cmap='jet', scale=0.3, # unit conversion factor scalarbar=False, interactive=False) pb.print() plot()
def awefem(mesh, t, source_loc=None): # Function space V = FunctionSpace(mesh, "Lagrange", 1) # Boundary condition bc = DirichletBC(V, Constant(0), "on_boundary") # Trial and test functions u = TrialFunction(V) v = TestFunction(V) # Discretization c = 6 dt = t[1] - t[0] u0 = Function(V) # u0 = uN-1 u1 = Function(V) # u1 = uN1 # Variational formulation F = (u - 2 * u1 + u0) * v * dx + (dt * c) ** 2 * dot( grad(u + 2 * u1 + u0) / 4, grad(v) ) * dx a, L = lhs(F), rhs(F) # Solver A, b = assemble_system(a, L) solver = LUSolver(A, "mumps") solver.parameters["symmetric"] = True bc.apply(A, b) # Solution u = Function(V) # uN+1 # Source if source_loc is None: mesh_center = np.mean(mesh.coordinates(), axis=0) source_loc = Point(mesh_center) else: source_loc = Point(source_loc) # Time stepping printc('\bomb Hit F1 to interrupt.', c='yellow') pb = ProgressBar(0, len(t)) for i, t_ in enumerate(t[1:]): pb.print() b = assemble(L) delta = PointSource(V, source_loc, ricker_source(t_) * dt**2) delta.apply(b) solver.solve(u.vector(), b) u0.assign(u1) u1.assign(u) if t_>0.03: plot(u, warpZfactor=20, # set elevation along z vmin=.0, # sets a minimum to the color scale vmax=0.003, cmap='rainbow', # the color map style alpha=1, # transparency of the mesh lw=0.1, # linewidth of mesh scalarbar=None, #lighting='plastic', #elevation=-.3, interactive=0) # continue execution interactive()
# Read velocity from file timeseries_w.retrieve(w.vector(), t) # Solve variational problem for time step solve(F == 0, u) _u_1, _u_2, _u_3 = u.split() # Update previous solution u_n.assign(u) # Plot solution plot(_u_3, at=0, # draw on renderer nr.0 shape=(2,1), # two rows, one column size='fullscreen', cmap='bone', scalarbar=False, axes=0, zoom=2, interactive=False) plot(_u_2, at=1, cmap='bone', zoom=2, scalarbar=False, interactive=False) pb.print(t) plot()