def run(dt, alpha, generator=pyLBM.generator.CythonGenerator, ode_solver=pyLBM.generator.basic): # parameters Tf = 1 la = 1. # data Nt = int(Tf / dt) dx = la * dt xmin, xmax = 0., 2 * dx dico = { 'box': { 'x': [xmin, xmax], }, 'space_step': dx, 'scheme_velocity': la, 'generator': generator, 'ode_solver': ode_solver, 'schemes': [ { 'velocities': [ 0, ], 'conserved_moments': u, 'polynomials': [ 1, ], 'relaxation_parameters': [ 0, ], 'equilibrium': [ u, ], 'source_terms': { u: -alpha * u }, 'init': { u: 1. }, }, ], } sol = pyLBM.Simulation(dico) #print(sol.scheme.generator.code) fnum = np.empty((Nt, )) tnum = np.empty((Nt, )) fnum[0] = sol.m[u][1] tnum[0] = sol.t for n in range(1, Nt): sol.one_time_step() fnum[n] = sol.m[u][1] tnum[n] = sol.t verification(dt, alpha, fnum, ode_solver) return np.linalg.norm(fnum - solution(tnum, alpha), np.inf)
def run(dx, Tf, generator=pyLBM.generator.CythonGenerator, sorder=None, withPlot=True): """ Parameters ---------- dx: double spatial step Tf: double final time generator: pyLBM generator sorder: list storage order withPlot: boolean if True plot the solution otherwise just compute the solution """ # advective velocity ux, uy, uz = .5, .2, .1 # domain of the computation xmin, xmax, ymin, ymax, zmin, zmax = 0., 1., 0., 1., 0., 1. def u0(x, y, z): xm, ym, zm = .5 * (xmin + xmax), .5 * (ymin + ymax), .5 * (zmin + zmax) return .5*np.ones((x.size, y.size, z.size)) \ + .5*(((x-xm)**2+(y-ym)**2+(z-zm)**2)<.25**2) s = 1. la = 1. d = { 'box': { 'x': [xmin, xmax], 'y': [ymin, ymax], 'z': [zmin, zmax], 'label': -1 }, 'space_step': dx, 'scheme_velocity': la, 'schemes': [ { 'velocities': list(range(1, 7)), 'conserved_moments': [u], 'polynomials': [1, LA * X, LA * Y, LA * Z, X**2 - Y**2, X**2 - Z**2], 'equilibrium': [u, ux * u, uy * u, uz * u, 0., 0.], 'relaxation_parameters': [0., s, s, s, s, s], 'init': { u: (u0, ) }, }, ], 'parameters': { LA: la }, 'generator': generator, } sol = pyLBM.Simulation(d, sorder=sorder) x, y, z = sol.domain.x, sol.domain.y, sol.domain.z im = 0 while sol.t < Tf: sol.one_time_step() if withPlot: im += 1 save(x, y, z, sol.m, im) return sol
def run(dx, Tf, generator=pyLBM.generator.CythonGenerator, sorder=None, withPlot=True): """ Parameters ---------- dx: double spatial step Tf: double final time generator: pyLBM generator sorder: list storage order withPlot: boolean if True plot the solution otherwise just compute the solution """ la = 1. rho0 = 1. Re = 2000 nu = 5. / Re s1 = 1.6 s2 = 1.2 s4 = 1.6 s9 = 1. / (3 * nu + .5) s11 = s9 s14 = 1.2 r = X**2 + Y**2 + Z**2 dico = { 'box': { 'x': [0., 2.], 'y': [0., 1.], 'z': [0., 1.], 'label': [1, 2, -1, -1, -1, -1] }, 'elements': [pyLBM.Sphere((.3, .5, .5), 0.125, 0)], 'space_step': dx, 'scheme_velocity': la, 'schemes': [{ 'velocities': list(range(7)) + list(range(19, 27)), 'conserved_moments': [mass, qx, qy, qz], 'polynomials': [ 1, r - 2, .5 * (15 * r**2 - 55 * r + 32), X, .5 * (5 * r - 13) * X, Y, .5 * (5 * r - 13) * Y, Z, .5 * (5 * r - 13) * Z, 3 * X**2 - r, Y**2 - Z**2, X * Y, Y * Z, Z * X, X * Y * Z ], 'relaxation_parameters': [0, s1, s2, 0, s4, 0, s4, 0, s4, s9, s9, s11, s11, s11, s14], 'equilibrium': [ mass, -mass + qx**2 + qy**2 + qz**2, -mass, qx, -7. / 3 * qx, qy, -7. / 3 * qy, qz, -7. / 3 * qz, 1. / 3 * (2 * qx**2 - (qy**2 + qz**2)), qy**2 - qz**2, qx * qy, qy * qz, qz * qx, 0 ], 'init': { mass: 1., qx: 0., qy: 0., qz: 0. }, }], 'boundary_conditions': { 0: { 'method': { 0: pyLBM.bc.Bouzidi_bounce_back } }, 1: { 'method': { 0: pyLBM.bc.Bouzidi_bounce_back }, 'value': bc_up }, 2: { 'method': { 0: pyLBM.bc.Neumann_x } }, }, 'parameters': { LA: la }, 'generator': generator, } sol = pyLBM.Simulation(dico, sorder=sorder) x, y, z = sol.domain.x, sol.domain.y, sol.domain.z im = 0 compt = 0 while sol.t < Tf: sol.one_time_step() compt += 1 if compt == 128 and withPlot: if mpi.COMM_WORLD.Get_rank() == 0: sol.time_info() im += 1 save(x, y, z, sol.m, im) compt = 0 return sol
def run(dx, Tf, generator=pyLBM.generator.CythonGenerator, sorder=None, withPlot=True): """ Parameters ---------- dx: double spatial step Tf: double final time generator: pyLBM generator store: list storage order withPlot: boolean if True plot the solution otherwise just compute the solution """ # parameters xmin, xmax = 0., 1. # bounds of the domain la = 1. # scheme velocity (la = dx/dt) c = 0.25 # velocity of the advection s = 1.99 # relaxation parameter # dictionary of the simulation dico = { 'box': { 'x': [xmin, xmax], 'label': -1 }, 'space_step': dx, 'scheme_velocity': LA, 'schemes': [ { 'velocities': [1, 2], 'conserved_moments': u, 'polynomials': [1, LA * X], 'relaxation_parameters': [0., s], 'equilibrium': [u, c * u], 'init': { u: (u0, (xmin, xmax)) }, }, ], 'generator': generator, 'split_pattern': ['transport', 'relaxation'], 'parameters': { LA: la }, } # simulation sol = pyLBM.Simulation(dico, sorder=sorder) # build the simulation if withPlot: # create the viewer to plot the solution viewer = pyLBM.viewer.matplotlibViewer fig = viewer.Fig() ax = fig[0] ymin, ymax = -.2, 1.2 ax.axis(xmin, xmax, ymin, ymax) x = sol.domain.x l1 = ax.plot(x, sol.m[u], width=2, color='b', label='D1Q2')[0] l2 = ax.plot(x, u0(x - c * sol.t, xmin, xmax), width=2, color='k', label='exact')[0] def update(iframe): if sol.t < Tf: # time loop sol.one_time_step() # increment the solution of one time step l1.set_data(x, sol.m[u]) l2.set_data(x, u0(x - c * sol.t, xmin, xmax)) ax.title = 'solution at t = {0:f}'.format(sol.t) ax.legend() fig.animate(update) fig.show() else: while sol.t < Tf: sol.one_time_step() return sol
def run(dt, Tf, generator=pyLBM.generator.NumpyGenerator, ode_solver=pyLBM.generator.basic, sorder=None, withPlot=True): """ Parameters ---------- dx: double spatial step Tf: double final time generator: pyLBM generator store: list storage order withPlot: boolean if True plot the solution otherwise just compute the solution """ # parameters xmin, xmax = 0., 1. # bounds of the domain la = 1. # scheme velocity (la = dx/dt) c = 0.25 # velocity of the advection mu = 1. # parameter of the source term s = 2. # relaxation parameter dx = la * dt # dictionary of the simulation dico = { 'box': { 'x': [xmin, xmax], 'label': -1 }, 'space_step': dx, 'scheme_velocity': LA, 'schemes': [ { 'velocities': [1, 2], 'conserved_moments': u, 'polynomials': [1, LA * XX], 'relaxation_parameters': [0., s], 'equilibrium': [u, C * u], 'source_terms': { u: MU * u * (1 - u) }, 'init': { u: (u0, (xmin, xmax)) }, }, ], 'generator': generator, 'ode_solver': ode_solver, 'split_pattern': [('source_term', 0.5), 'transport', 'relaxation', ('source_term', 0.5)], 'parameters': { LA: la, C: c, MU: mu, 'time': t, 'space_x': XX }, } # simulation sol = pyLBM.Simulation(dico, sorder=sorder) # build the simulation if withPlot: # create the viewer to plot the solution viewer = pyLBM.viewer.matplotlibViewer fig = viewer.Fig() ax = fig[0] ymin, ymax = -.2, 1.2 ax.axis(xmin, xmax, ymin, ymax) x = sol.domain.x l1 = ax.plot(x, sol.m[u], width=2, color='b', label='D1Q2')[0] l2 = ax.plot(x, solution(sol.t, x, xmin, xmax, c, mu), width=2, color='k', label='exact')[0] def update(iframe): if sol.t < Tf: # time loop sol.one_time_step() # increment the solution of one time step l1.set_data(x, sol.m[u]) l2.set_data(x, solution(sol.t, x, xmin, xmax, c, mu)) ax.title = 'solution at t = {0:f}'.format(sol.t) ax.legend() fig.animate(update) fig.show() else: while sol.t < Tf: sol.one_time_step() sol.time_info() return np.linalg.norm( sol.m[u] - solution(sol.t, sol.domain.x, xmin, xmax, c, mu), np.inf)
def run(dx, Tf, generator=pyLBM.generator.CythonGenerator, sorder=None, withPlot=True): """ Parameters ---------- dx: double spatial step Tf: double final time generator: pyLBM generator sorder: list storage order withPlot: boolean if True plot the solution otherwise just compute the solution """ # parameters width = 1. height = .5 xmin, xmax, ymin, ymax = 0., width, -.5 * height, .5 * height la = 1. # velocity of the scheme max_velocity = 0.1 mu = 0.00185 zeta = 1.e-5 grad_pressure = -mu * max_velocity * 8. / height**2 cte = 3. dummy = 3.0 / (la * dx) s1 = 1.0 / (0.5 + zeta * dummy) s2 = 1.0 / (0.5 + mu * dummy) velocities = list(range(1, 5)) polynomes = [1, LA * X, LA * Y, X**2 - Y**2] dico = { 'box': { 'x': [xmin, xmax], 'y': [ymin, ymax], 'label': [2, 1, 0, 0] }, 'space_step': dx, 'scheme_velocity': la, 'inittype': 'moments', 'schemes': [ { 'velocities': velocities, 'polynomials': polynomes, 'relaxation_parameters': [0., s1, s1, 1.], 'equilibrium': [p, ux, uy, 0.], 'conserved_moments': p, 'init': { p: 0. }, }, { 'velocities': velocities, 'polynomials': polynomes, 'relaxation_parameters': [0., s2, s2, 1.], 'equilibrium': [ux, ux**2 + p / cte, ux * uy, 0.], 'conserved_moments': ux, 'init': { ux: 0. }, }, { 'velocities': velocities, 'polynomials': polynomes, 'relaxation_parameters': [0., s2, s2, 1.], 'equilibrium': [uy, ux * uy, uy**2 + p / cte, 0.], 'conserved_moments': uy, 'init': { uy: 0. }, }, ], 'parameters': { LA: la }, 'boundary_conditions': { 0: { 'method': { 0: pyLBM.bc.Bouzidi_bounce_back, 1: pyLBM.bc.Bouzidi_anti_bounce_back, 2: pyLBM.bc.Bouzidi_anti_bounce_back }, }, 1: { 'method': { 0: pyLBM.bc.Bouzidi_anti_bounce_back, 1: pyLBM.bc.Neumann_x, 2: pyLBM.bc.Neumann_x }, 'value': (bc_out, (width, grad_pressure, cte)) }, 2: { 'method': { 0: pyLBM.bc.Bouzidi_anti_bounce_back, 1: pyLBM.bc.Bouzidi_anti_bounce_back, 2: pyLBM.bc.Bouzidi_anti_bounce_back }, 'value': (bc_in, (width, height, max_velocity, grad_pressure, cte)), }, }, 'generator': generator, } sol = pyLBM.Simulation(dico, sorder=sorder) while sol.t < Tf: sol.one_time_step() if withPlot: print("*" * 50) p_n = sol.m[p] ux_n = sol.m[ux] uy_n = sol.m[uy] x, y = np.meshgrid(*sol.domain.coords, sparse=True, indexing='ij') coeff = sol.domain.dx / np.sqrt(width * height) Err_p = coeff * np.linalg.norm(p_n - (x - 0.5 * width) * grad_pressure) Err_ux = coeff * np.linalg.norm(ux_n - max_velocity * (1 - 4 * y**2 / height**2)) Err_uy = coeff * np.linalg.norm(uy_n) print("Norm of the error on rho: {0:10.3e}".format(Err_p)) print("Norm of the error on qx: {0:10.3e}".format(Err_ux)) print("Norm of the error on qy: {0:10.3e}".format(Err_uy)) # init viewer viewer = pyLBM.viewer.matplotlibViewer fig = viewer.Fig() ax = fig[0] ax.image(ux_n - max_velocity * (1 - 4 * y**2 / height**2)) ax.title = "Error on ux" fig.show() return sol
def run(dx, Tf, generator=pyLBM.generator.CythonGenerator, sorder=None, withPlot=True): """ Parameters ---------- dx: double spatial step Tf: double final time generator: pyLBM generator sorder: list storage order withPlot: boolean if True plot the solution otherwise just compute the solution """ # parameters la = 1. # velocity of the scheme width = 2 height = 1 max_velocity = 0.1 rhoo = 1. mu = 0.00185 zeta = 1.e-2 xmin, xmax, ymin, ymax = 0.0, width, -0.5 * height, 0.5 * height grad_pressure = -max_velocity * 8.0 / (height)**2 * 3.0 / (la**2 * rhoo) * mu dummy = 3.0 / (la * rhoo * dx) s1 = 1.0 / (0.5 + zeta * dummy) s2 = 1.0 / (0.5 + mu * dummy) s = [0., 0., 0., s1, s1, s1, s1, s2, s2] dummy = 1. / (LA**2 * rhoo) qx2 = dummy * qx**2 qy2 = dummy * qy**2 q2 = qx2 + qy2 qxy = dummy * qx * qy dico = { 'box': { 'x': [xmin, xmax], 'y': [ymin, ymax], 'label': [2, 1, 0, 0] }, 'space_step': dx, 'scheme_velocity': la, 'schemes': [{ 'velocities': list(range(9)), 'polynomials': [ 1, LA * X, LA * Y, 3 * (X**2 + Y**2) - 4, 0.5 * (9 * (X**2 + Y**2)**2 - 21 * (X**2 + Y**2) + 8), 3 * X * (X**2 + Y**2) - 5 * X, 3 * Y * (X**2 + Y**2) - 5 * Y, X**2 - Y**2, X * Y ], 'relaxation_parameters': s, 'equilibrium': [ rho, qx, qy, -2 * rho + 3 * q2, rho - 3 * q2, -qx / LA, -qy / LA, qx2 - qy2, qxy ], 'conserved_moments': [rho, qx, qy], 'init': { rho: 1., qx: 0., qy: 0. }, }], 'parameters': { 'LA': la }, 'boundary_conditions': { 0: { 'method': { 0: pyLBM.bc.Bouzidi_bounce_back } }, 1: { 'method': { 0: pyLBM.bc.Neumann_x } }, 2: { 'method': { 0: pyLBM.bc.Bouzidi_bounce_back }, 'value': (bc_in, (width, height, max_velocity, grad_pressure)) } }, 'generator': generator, } sol = pyLBM.Simulation(dico, sorder=sorder) if withPlot: # init viewer viewer = pyLBM.viewer.matplotlibViewer fig = viewer.Fig() ax = fig[0] nt = int(sol.domain.shape_in[0] / 2) y = sol.domain.y l1 = ax.plot(y, sol.m[qx][nt], color='r', marker='+', label='LBM')[0] l2 = ax.plot(y, rhoo * max_velocity * (1. - 4. * y**2 / height**2), color='k', label='exact') ax.title = 'Velocity at t = {0:f}'.format(sol.t) ax.legend() def update(iframe): sol.one_time_step() l1.set_data(y, sol.m[qx][nt]) ax.title = 'Velocity at t = {0:f}'.format(sol.t) # run the simulation fig.animate(update, interval=1) fig.show() else: while sol.t < Tf: sol.one_time_step() return sol
def run(dx, Tf, generator=pyLBM.generator.CythonGenerator, sorder=None, withPlot=True): """ Parameters ---------- dx: double spatial step Tf: double final time generator: pyLBM generator sorder: list storage order withPlot: boolean if True plot the solution otherwise just compute the solution """ # parameters xmin, xmax = 0., 1. # bounds of the domain la = 2. # velocity of the scheme s = 1.5 # relaxation parameter hL, hR, qL, qR = 1., .25, 0.10, 0.10 ymina, ymaxa, yminb, ymaxb = 0., 1., 0., .5 dico = { 'box': { 'x': [xmin, xmax], 'label': 0 }, 'space_step': dx, 'scheme_velocity': la, 'schemes': [ { 'velocities': [1, 2], 'conserved_moments': h, 'polynomials': [1, LA * X], 'relaxation_parameters': [0, s], 'equilibrium': [h, q], 'init': { h: (Riemann_pb, (xmin, xmax, hL, hR)) }, }, { 'velocities': [1, 2], 'conserved_moments': q, 'polynomials': [1, LA * X], 'relaxation_parameters': [0, s], 'equilibrium': [q, q**2 / h + .5 * g * h**2], 'init': { q: (Riemann_pb, (xmin, xmax, qL, qR)) }, }, ], 'boundary_conditions': { 0: { 'method': { 0: pyLBM.bc.Neumann, 1: pyLBM.bc.Neumann } }, }, 'generator': generator, 'parameters': { LA: la, g: 1. }, } sol = pyLBM.Simulation(dico, sorder=sorder) if withPlot: # create the viewer to plot the solution viewer = pyLBM.viewer.matplotlibViewer fig = viewer.Fig(2, 1) ax1 = fig[0] ax1.axis(xmin, xmax, .9 * ymina, 1.1 * ymaxa) ax2 = fig[1] ax2.axis(xmin, xmax, .9 * yminb, 1.1 * ymaxb) x = sol.domain.x l1 = ax1.plot(x, sol.m[h], color='b')[0] l2 = ax2.plot(x, sol.m[q], color='r')[0] def update(iframe): if sol.t < Tf: sol.one_time_step() l1.set_data(x, sol.m[h]) l2.set_data(x, sol.m[q]) ax1.title = r'$h$ at $t = {0:f}$'.format(sol.t) ax2.title = r'$q$ at $t = {0:f}$'.format(sol.t) fig.animate(update) fig.show() else: while sol.t < Tf: sol.one_time_step() return sol
def run(dx, Tf, generator=pyLBM.generator.CythonGenerator, sorder=None, withPlot=True): """ Parameters ---------- dx: double spatial step Tf: double final time generator: pyLBM generator sorder: list storage order withPlot: boolean if True plot the solution otherwise just compute the solution """ # parameters width = 1. height = .5 xmin, xmax, ymin, ymax = 0., width, -.5*height, .5*height zmin, zmax = -2*dx, 2*dx la = 1. # velocity of the scheme max_velocity = 0.1 mu = 1.e-3 zeta = 1.e-5 grad_pressure = -mu * max_velocity * 8./height**2 cte = 10. dummy = 3.0/(la*dx) #s1 = 1.0/(0.5+zeta*dummy) #s2 = 1.0/(0.5+mu*dummy) sigma = 1./np.sqrt(12) s = 1./(.5+sigma) vs = [0., s, s, s, s, s] velocities = list(range(1, 7)) polynomes = [1, LA*X, LA*Y, LA*Z, X**2-Y**2, X**2-Z**2] def bc_in(f, m, x, y, z): m[p] = (x-0.5*width) * grad_pressure *cte m[ux] = max_velocity * (1. - 4.*y**2/height**2) def bc_out(f, m, x, y, z): m[p] = (x-0.5*width) * grad_pressure *cte dico = { 'box':{'x':[xmin, xmax], 'y':[ymin, ymax], 'z':[zmin, zmax], 'label':[1, 2, 0, 0, -1, -1]}, 'space_step':dx, 'scheme_velocity':la, 'schemes':[{ 'velocities':velocities, 'conserved_moments':p, 'polynomials':polynomes, 'relaxation_parameters':vs, 'equilibrium':[p, ux, uy, uz, 0., 0.], 'init':{p:0.}, },{ 'velocities':velocities, 'conserved_moments':ux, 'polynomials':polynomes, 'relaxation_parameters':vs, 'equilibrium':[ux, ux**2 + p/cte, ux*uy, ux*uz, 0., 0.], 'init':{ux:0.}, },{ 'velocities':velocities, 'conserved_moments':uy, 'polynomials':polynomes, 'relaxation_parameters':vs, 'equilibrium':[uy, uy*ux, uy**2 + p/cte, uy*uz, 0., 0.], 'init':{uy:0.}, },{ 'velocities':velocities, 'conserved_moments':uz, 'polynomials':polynomes, 'relaxation_parameters':vs, 'equilibrium':[uz, uz*ux, uz*uy, uz**2 + p/cte, 0., 0.], 'init':{uz:0.}, }, ], 'boundary_conditions':{ 0:{'method':{0: pyLBM.bc.Bouzidi_bounce_back, 1: pyLBM.bc.Bouzidi_anti_bounce_back, 2: pyLBM.bc.Bouzidi_anti_bounce_back, 3: pyLBM.bc.Bouzidi_anti_bounce_back, }, }, 1:{'method':{0: pyLBM.bc.Bouzidi_anti_bounce_back, 1: pyLBM.bc.Neumann_vertical, 2: pyLBM.bc.Neumann_vertical, 3: pyLBM.bc.Neumann_vertical, }, 'value':bc_out, }, 2:{'method':{0: pyLBM.bc.Bouzidi_anti_bounce_back, 1: pyLBM.bc.Bouzidi_anti_bounce_back, 2: pyLBM.bc.Bouzidi_anti_bounce_back, 3: pyLBM.bc.Bouzidi_anti_bounce_back, }, 'value':bc_in, }, }, 'parameters': {LA: la}, 'generator': generator, } sol = pyLBM.Simulation(dico, sorder=sorder) x, y, z = sol.domain.x, sol.domain.y, sol.domain.z im = 0 c = 0 while sol.t < Tf: sol.one_time_step() c += 1 if c == 16 and withPlot: im += 1 plot(x, y, z, sol.m, im) c = 0 return sol
def run(dx, Tf, generator=pyLBM.generator.CythonGenerator, sorder=None, withPlot=True): """ Parameters ---------- dx: double spatial step Tf: double final time generator: pyLBM generator sorder: list storage order withPlot: boolean if True plot the solution otherwise just compute the solution """ # parameters xmin, xmax, ymin, ymax = 0., 1., 0., 1. # bounds of the domain cx, cy = 0.2, 0.5 # velocity of the advection la = 2. # scheme velocity sigma_qx = 1. / np.sqrt(12) sigma_xy = sigma_qx s_qx = 1. / (0.5 + sigma_qx) s_xy = 1. / (0.5 + sigma_xy) s = [0., s_qx, s_qx, s_xy] # relaxation parameters dico = { 'box': { 'x': [xmin, xmax], 'y': [ymin, ymax], 'label': -1 }, 'space_step': dx, 'scheme_velocity': la, 'schemes': [ { 'velocities': list(range(1, 5)), 'conserved_moments': u, 'polynomials': [1, LA * X, LA * Y, X**2 - Y**2], 'relaxation_parameters': s, 'equilibrium': [u, cx * u, cy * u, 0], 'init': { u: (u0, (xmin, xmax, ymin, ymax)) }, }, ], 'generator': generator, 'parameters': { LA: la }, } sol = pyLBM.Simulation(dico, sorder=sorder) if withPlot: # create the viewer to plot the solution viewer = pyLBM.viewer.matplotlibViewer fig = viewer.Fig() ax = fig[0] im = ax.image(sol.m[u].transpose()) ax.title = 'solution at t = {0:f}'.format(sol.t) def update(iframe): nrep = 128 for i in range(nrep): sol.one_time_step() im.set_data(sol.m[u].transpose()) ax.title = 'solution at t = {0:f}'.format(sol.t) fig.animate(update, interval=1) fig.show() else: while sol.t < Tf: sol.one_time_step() return sol
def run(dx, Tf, generator=pyLBM.generator.CythonGenerator, sorder=None, withPlot=True): """ Parameters ---------- dx: double spatial step Tf: double final time generator: pyLBM generator sorder: list storage order withPlot: boolean if True plot the solution otherwise just compute the solution """ la = 1. rhoo = 1. mu = 1.e-4 zeta = 1.e-4 driven_velocity = 0.2 # velocity of the upper border dummy = 3.0 / dx s1 = 1.0 / (0.5 + zeta * dummy) s2 = 1.0 / (0.5 + mu * dummy) s = [0., 0., 0., s1, s1, s1, s1, s2, s2] Tf = 10. dummy = 1. / (LA**2 * rhoo) qx2 = dummy * qx**2 qy2 = dummy * qy**2 q2 = qx2 + qy2 qxy = dummy * qx * qy lid_cavity = { 'parameters': { LA: la }, 'box': { 'x': [0., 1.], 'y': [0., 1.], 'label': [0, 0, 0, 1] }, 'space_step': dx, 'scheme_velocity': LA, 'schemes': [ { 'velocities': list(range(9)), 'polynomials': [ 1, LA * X, LA * Y, 3 * (X**2 + Y**2) - 4, 0.5 * (9 * (X**2 + Y**2)**2 - 21 * (X**2 + Y**2) + 8), 3 * X * (X**2 + Y**2) - 5 * X, 3 * Y * (X**2 + Y**2) - 5 * Y, X**2 - Y**2, X * Y ], 'relaxation_parameters': s, 'equilibrium': [ rho, qx, qy, -2 * rho + 3 * q2, rho - 3 * q2, -qx / LA, -qy / LA, qx2 - qy2, qxy ], 'conserved_moments': [rho, qx, qy], 'init': { rho: 1., qx: 0., qy: 0. }, }, ], 'boundary_conditions': { 0: { 'method': { 0: pyLBM.bc.Bouzidi_bounce_back } }, 1: { 'method': { 0: pyLBM.bc.Bouzidi_bounce_back }, 'value': (bc_up, (driven_velocity, )) } }, 'generator': generator, } sol = pyLBM.Simulation(lid_cavity, sorder=sorder) if withPlot: # init viewer viewer = pyLBM.viewer.matplotlibViewer fig = viewer.Fig() ax = fig[0] image = ax.image(vorticity, (sol, ), cmap='cubehelix', clim=[0, .1]) def update(iframe): nrep = 100 for i in range(nrep): sol.one_time_step() image.set_data(vorticity(sol)) ax.title = "Solution t={0:f}".format(sol.t) # run the simulation fig.animate(update, interval=1) fig.show() else: while sol.t < Tf: sol.one_time_step() return sol
1: pyLBM.bc.Neumann, 2: pyLBM.bc.Neumann }, 'value': None }, }, 'parameters': { LA: la }, 'generator': pyLBM.generator.CythonGenerator, } N = 2 sol1 = pyLBM.Simulation(dico1) x = sol1.domain.x[0][1:-1] for k in range(N): sol1.one_time_step() sol1.f2m() rho1 = sol1.m[rho][1:-1] q1 = sol1.m[q][1:-1] E1 = sol1.m[E][1:-1] u1 = q1 / rho1 p1 = (gamma - 1.) * (E1 - .5 * rho1 * u1**2) e1 = E1 / rho1 - .5 * u1**2 sol2 = pyLBM.Simulation(dico2) for k in range(N): sol2.one_time_step() sol2.f2m()
def run(dx, Tf, generator=pyLBM.generator.NumpyGenerator, sorder=None, withPlot=True): """ Parameters ---------- dx: double spatial step Tf: double final time generator: pyLBM generator sorder: list storage order withPlot: boolean if True plot the solution otherwise just compute the solution """ # parameters gamma = 2. / 3. # exponent in the p-function xmin, xmax = 0., 1. # bounds of the domain la = 2. # velocity of the scheme s = 1.7 # relaxation parameter uaL, uaR, ubL, ubR = 1.50, 1.25, 1.50, 1.00 ymina, ymaxa, yminb, ymaxb = 1., 1.75, 1., 1.5 dico = { 'box': { 'x': [xmin, xmax], 'label': 0 }, 'space_step': dx, 'scheme_velocity': la, 'schemes': [ { 'velocities': [1, 2], 'conserved_moments': ua, 'polynomials': [1, LA * X], 'relaxation_parameters': [0, s], 'equilibrium': [ua, -ub], 'init': { ua: (Riemann_pb, (xmin, xmax, uaL, uaR)) }, }, { 'velocities': [1, 2], 'conserved_moments': ub, 'polynomials': [1, LA * X], 'relaxation_parameters': [0, s], 'equilibrium': [ub, ua**(-gamma)], 'init': { ub: (Riemann_pb, (xmin, xmax, ubL, ubR)) }, }, ], 'boundary_conditions': { 0: { 'method': { 0: pyLBM.bc.Neumann, 1: pyLBM.bc.Neumann } }, }, 'generator': generator, 'parameters': { LA: la }, } sol = pyLBM.Simulation(dico, sorder=sorder) if withPlot: # create the viewer to plot the solution viewer = pyLBM.viewer.matplotlibViewer fig = viewer.Fig(2, 1) ax1 = fig[0] ax1.axis(xmin, xmax, .9 * ymina, 1.1 * ymaxa) ax2 = fig[1] ax2.axis(xmin, xmax, .9 * yminb, 1.1 * ymaxb) x = sol.domain.x l1 = ax1.plot(x, sol.m[ua])[0] l2 = ax2.plot(x, sol.m[ub])[0] def update(iframe): if sol.t < Tf: sol.one_time_step() l1.set_data(x, sol.m[ua]) l2.set_data(x, sol.m[ub]) ax1.title = r'$u_a$ at $t = {0:f}$'.format(sol.t) ax2.title = r'$u_b$ at $t = {0:f}$'.format(sol.t) fig.animate(update) fig.show() else: while sol.t < Tf: sol.one_time_step() return sol
def run(dx, Tf, generator=pyLBM.generator.CythonGenerator, sorder=None, withPlot=True): """ Parameters ---------- dx: double spatial step Tf: double final time generator: pyLBM generator sorder: list storage order withPlot: boolean if True plot the solution otherwise just compute the solution """ # parameters xmin, xmax, ymin, ymax = 0., 1., 0., 1 rayon = 0.25 * (xmax - xmin) la = 1. # velocity of the scheme rhoo = 1. uo = 0.05 mu = 2.5e-5 #0.00185 zeta = 10 * mu dummy = 3.0 / (la * rhoo * dx) s3 = 1.0 / (0.5 + zeta * dummy) s4 = s3 s5 = s4 s6 = s4 s7 = 1.0 / (0.5 + mu * dummy) s8 = s7 s = [0., 0., 0., s3, s4, s5, s6, s7, s8] dummy = 1. / (LA**2 * rhoo) qx2 = dummy * qx**2 qy2 = dummy * qy**2 q2 = qx2 + qy2 qxy = dummy * qx * qy xc = xmin + 0.75 * (xmax - xmin) yc = ymin + 0.75 * (ymax - ymin) dico = { 'box': { 'x': [xmin, xmax], 'y': [ymin, ymax], 'label': [2, 0, 1, 0] }, 'elements': [pyLBM.Parallelogram((xmin, ymin), (xc, ymin), (xmin, yc), label=0)], 'scheme_velocity': la, 'space_step': dx, 'schemes': [{ 'velocities': list(range(9)), 'polynomials': [ 1, X, Y, 3 * (X**2 + Y**2) - 4, 0.5 * (9 * (X**2 + Y**2)**2 - 21 * (X**2 + Y**2) + 8), 3 * X * (X**2 + Y**2) - 5 * X, 3 * Y * (X**2 + Y**2) - 5 * Y, X**2 - Y**2, X * Y ], 'relaxation_parameters': s, 'equilibrium': [ rho, qx, qy, -2 * rho + 3 * q2, rho - 3 * q2, -qx, -qy, qx2 - qy2, qxy ], 'conserved_moments': [rho, qx, qy], 'init': { rho: rhoo, qx: 0., qy: 0. }, }], 'boundary_conditions': { 0: { 'method': { 0: pyLBM.bc.Bouzidi_bounce_back } }, 1: { 'method': { 0: pyLBM.bc.Neumann_y } }, 2: { 'method': { 0: pyLBM.bc.Bouzidi_bounce_back }, 'value': (bc_in, (rhoo, uo, ymin, ymax)) } }, 'generator': generator, 'parameters': { 'LA': la }, } sol = pyLBM.Simulation(dico, sorder=sorder) if withPlot: # init viewer viewer = pyLBM.viewer.matplotlibViewer fig = viewer.Fig() ax = fig[0] image = ax.image(norme_q, (sol, ), cmap='jet', clim=[0, uo**2]) ax.polygon([[xmin / dx, ymin / dx], [xmin / dx, yc / dx], [xc / dx, yc / dx], [xc / dx, ymin / dx]], 'k') def update(iframe): nrep = 64 for i in range(nrep): sol.one_time_step() image.set_data(norme_q(sol)) ax.title = "Solution t={0:f}".format(sol.t) # run the simulation fig.animate(update, interval=1) fig.show() else: while sol.t < Tf: sol.one_time_step() return sol
def run(dx, Tf, generator=pyLBM.generator.NumpyGenerator, sorder=None, withPlot=True): """ Parameters ---------- dx: double spatial step Tf: double final time generator: pyLBM generator sorder: list storage order withPlot: boolean if True plot the solution otherwise just compute the solution """ # parameters gamma = 1.4 xmin, xmax = 0., 1. la = 3. # velocity of the scheme rho_L, rho_R, p_L, p_R, u_L, u_R = 1., 1. / 8., 1., 0.1, 0., 0. q_L = rho_L * u_L q_R = rho_R * u_R E_L = rho_L * u_L**2 + p_L / (gamma - 1.) E_R = rho_R * u_R**2 + p_R / (gamma - 1.) s_rho, s_q, s_E = 1.9, 1.5, 1.4 dico = { 'box': { 'x': [xmin, xmax], 'label': 0 }, 'space_step': dx, 'scheme_velocity': la, 'schemes': [ { 'velocities': [1, 2], 'conserved_moments': rho, 'polynomials': [1, LA * X], 'relaxation_parameters': [0, s_rho], 'equilibrium': [rho, q], 'init': { rho: (Riemann_pb, (xmin, xmax, rho_L, rho_R)) }, }, { 'velocities': [1, 2], 'conserved_moments': q, 'polynomials': [1, LA * X], 'relaxation_parameters': [0, s_q], 'equilibrium': [q, (gamma - 1.) * E + 0.5 * (3. - gamma) * q**2 / rho], 'init': { q: (Riemann_pb, (xmin, xmax, q_L, q_R)) }, }, { 'velocities': [1, 2], 'conserved_moments': E, 'polynomials': [1, LA * X], 'relaxation_parameters': [0, s_E], 'equilibrium': [E, gamma * E * q / rho - 0.5 * (gamma - 1.) * q**3 / rho**2], 'init': { E: (Riemann_pb, (xmin, xmax, E_L, E_R)) }, }, ], 'boundary_conditions': { 0: { 'method': { 0: pyLBM.bc.Neumann, 1: pyLBM.bc.Neumann, 2: pyLBM.bc.Neumann }, }, }, 'parameters': { LA: la }, 'generator': generator, } sol = pyLBM.Simulation(dico, sorder=sorder) while (sol.t < Tf): sol.one_time_step() if withPlot: x = sol.domain.x rho_n = sol.m[rho] q_n = sol.m[q] E_n = sol.m[E] u = q_n / rho_n p = (gamma - 1.) * (E_n - .5 * rho_n * u**2) e = E_n / rho_n - .5 * u**2 viewer = pyLBM.viewer.matplotlibViewer fig = viewer.Fig(2, 3) fig[0, 0].plot(x, rho_n) fig[0, 0].title = 'mass' fig[0, 1].plot(x, u) fig[0, 1].title = 'velocity' fig[0, 2].plot(x, p) fig[0, 2].title = 'pressure' fig[1, 0].plot(x, E_n) fig[1, 0].title = 'energy' fig[1, 1].plot(x, q_n) fig[1, 1].title = 'momentum' fig[1, 2].plot(x, e) fig[1, 2].title = 'internal energy' fig.show() return sol
def run(dx, Tf, generator=pyLBM.generator.CythonGenerator, sorder=None, withPlot=True): """ Parameters ---------- dx: double spatial step Tf: double final time generator: pyLBM generator sorder: list storage order withPlot: boolean if True plot the solution otherwise just compute the solution """ rhoo = 1. deltarho = 1. Taille = 2. xmin, xmax, ymin, ymax = -0.5*Taille, 0.5*Taille, -0.5*Taille, 0.5*Taille # parameters la = 4 # velocity of the scheme g = 1. sigma = 1.e-4 s_0qx = 2.#1./(0.5+sigma) s_0xy = 1.5 s_1qx = 1.5 s_1xy = 1.2 s0 = [0., s_0qx, s_0qx, s_0xy] s1 = [0., s_1qx, s_1qx, s_1xy] vitesse = list(range(1,5)) polynomes = [1, LA*X, LA*Y, X**2-Y**2] def initialization_rho(x,y): return rhoo * np.ones((x.size, y.size)) + deltarho * ((x-0.5*(xmin+xmax))**2+(y-0.5*(ymin+ymax))**2 < 0.25**2) dico = { 'box':{'x':[xmin, xmax], 'y':[ymin, ymax], 'label':-1}, 'space_step':dx, 'scheme_velocity':la, 'parameters':{LA:la}, 'schemes':[ { 'velocities':vitesse, 'conserved_moments':rho, 'polynomials':polynomes, 'relaxation_parameters':s0, 'equilibrium':[rho, qx, qy, 0.], 'init':{rho:(initialization_rho,)}, }, { 'velocities':vitesse, 'conserved_moments':qx, 'polynomials':polynomes, 'relaxation_parameters':s1, 'equilibrium':[qx, qx**2/rho + 0.5*g*rho**2, qx*qy/rho, 0.], 'init':{qx:0.}, }, { 'velocities':vitesse, 'conserved_moments':qy, 'polynomials':polynomes, 'relaxation_parameters':s1, 'equilibrium':[qy, qy*qx/rho, qy**2/rho + 0.5*g*rho**2, 0.], 'init':{qy:0.}, }, ], 'generator': generator, } sol = pyLBM.Simulation(dico, sorder=sorder) if withPlot: viewer = pyLBM.viewer.matplotlibViewer fig = viewer.Fig() ax = fig[0] im = ax.image(sol.m[rho].transpose(), clim=[rhoo-.5*deltarho, rhoo+1.5*deltarho]) ax.title = 'solution at t = {0:f}'.format(sol.t) def update(iframe): for k in range(32): sol.one_time_step() # increment the solution of one time step im.set_data(sol.m[rho].transpose()) ax.title = 'solution at t = {0:f}'.format(sol.t) fig.animate(update, interval=1) fig.show() else: while sol.t < Tf: sol.one_time_step() return sol
'relaxation_parameters': [0., 1.9, 1.9], 'equilibrium': [u, 0.25 * u, LA**2 / 2 * u], 'init': { u: (Riemann_pb, (ug, ud)) }, }], 'boundary_conditions': { 0: { 'method': { 0: pyLBM.bc.Neumann, }, }, }, } sol2 = pyLBM.Simulation(dicoQ2) sol3 = pyLBM.Simulation(dicoQ3) viewer = pyLBM.viewer.matplotlibViewer fig = viewer.Fig() ax = fig[0] ymin, ymax = -.2, 1.2 ax.axis(xmin, xmax, ymin, ymax) x2 = sol2.domain.x[0][1:-1] x3 = sol3.domain.x[0][1:-1] l1 = ax.plot(x2, sol2.m[u][1:-1], width=2, color='b', label=r'$D_1Q_2$')[0] l2 = ax.plot(x3, sol3.m[u][1:-1], width=2, color='r', label=r'$D_1Q_3$')[0] def update(iframe): if sol2.t < Tf: # time loop
def test_transport(): # parameters dim = 2 # spatial dimension xmin, xmax, ymin, ymax = -0.5, 4.5, -0.5, 4.5 dx = 1. # spatial step la = 1. # velocity of the scheme Tf = 5 rhoo = 1. s = [0., 0., 0., 1., 1., 1., 1., 1., 1.] dummy = 1. / (LA**2 * rhoo) qx2 = dummy * qx**2 qy2 = dummy * qy**2 q2 = qx2 + qy2 qxy = dummy * qx * qy vitesse = list(range(9)) polynomes = [ 1, LA * X, LA * Y, 3 * (X**2 + Y**2) - 4, 0.5 * (9 * (X**2 + Y**2)**2 - 21 * (X**2 + Y**2) + 8), 3 * X * (X**2 + Y**2) - 5 * X, 3 * Y * (X**2 + Y**2) - 5 * Y, X**2 - Y**2, X * Y ] equilibre = [ rho, qx, qy, -2 * rho + 3 * q2, rho + 1.5 * q2, qx / LA, qy / LA, qx2 - qy2, qxy ] dico = { 'box': { 'x': [xmin, xmax], 'y': [ymin, ymax], 'label': [-1] * 4 }, #[0, 0, 1, 1]}, 'space_step': dx, 'scheme_velocity': la, 'inittype': 'distributions', 'schemes': [ { 'velocities': vitesse, 'polynomials': polynomes, 'relaxation_parameters': s, 'equilibrium': equilibre, 'conserved_moments': [rho, qx, qy], 'init': { 0: (init_un, ), 1: (init_un, ), 2: (init_un, ), 3: (init_un, ), 4: (init_un, ), 5: (init_un, ), 6: (init_un, ), 7: (init_un, ), 8: (init_un, ), }, }, ], #'generator': pyLBM.generator.CythonGenerator, 'boundary_conditions': { 0: { 'method': { 0: pyLBM.bc.Bouzidi_bounce_back } }, 1: { 'method': { 0: pyLBM.bc.Bouzidi_anti_bounce_back } }, }, 'parameters': { 'LA': 1. }, } sol = pyLBM.Simulation(dico) while (sol.t < Tf - 0.5 * sol.dt): #sol.m2f() sol.boundary_condition() sol.transport() #sol.f2m() sol.t += sol.dt print(sol.t) print() print(sol.F[rho][1:-1, 1:-1]) print() print(sol.F[qx][1:-1, 1:-1]) print() print(sol.F[qy][1:-1, 1:-1])