[0, .5, 0], [0, 0, 1], label=0 ) ], 'space_step': 0.5, 'schemes': [{'velocities': list(range(19))}] }, { 'box': { 'x': [0, 2], 'y': [0, 2], 'z': [0, 2], 'label': list(range(1, 7)) }, 'elements': [pylbm.Sphere((1, 1, 1), 0.5, label=0)], 'space_step': 0.5, 'schemes': [{'velocities': list(range(19))}] }, { 'box': { 'x': [0, 2], 'y': [0, 2], 'z': [0, 2], 'label': list(range(6)) }, 'space_step': 0.5, 'schemes': [{'velocities': list(range(19))}] } ]
# Authors: # Loic Gouarin <*****@*****.**> # Benjamin Graille <*****@*****.**> # # License: BSD 3 clause """ Example of a 3D geometry: the cube [0,1]x[0,1]x[0,1] """ import pylbm d = { 'box': { 'x': [0, 1], 'y': [0, 1], 'z': [0, 1], 'label': 0 }, 'elements': [pylbm.Sphere((.5, .5, .5), .25, label=1)], } g = pylbm.Geometry(d) g.visualize(viewlabel=True, alpha=0.25)
def run(dx, Tf, generator="cython", 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. uo = 0.1 radius = 0.125 Re = 2000 nu = rhoo*uo*2*radius/Re #tau = .5*(6*nu/la/dx + 1) #print(1./tau) s1 = 1.19 s2 = s10 = 1.4 s4 = 1.2 dummy = 3.0/(la*rhoo*dx) s9 = 1./(nu*dummy +.5) s13 = 1./(nu*dummy +.5) s16 = 1.98 #[0, s1, s2, 0, s4, 0, s4, 0, s4, s9, s10, s9, s10, s13, s13, s13, s16, s16, s16] s = [0]*4 + [s1, s9, s9, s13, s13, s13, s4, s4, s4, s16, s16, s16, s10, s10, s2] r = X**2+Y**2+Z**2 d_p = { 'geometry': { 'xmin': 0, 'xmax': 2, 'ymin': 0, 'ymax': 1, 'zmin': 0, 'zmax': 1 } } dico = { 'box': { 'x': [0., 2.], 'y': [0., 1.], 'z': [0., 1.], 'label': [0, 1, 0, 0, 0, 0] }, 'elements':[pylbm.Sphere((.3, .5+2*dx, .5+2*dx), radius, 2)], 'space_step': dx, 'scheme_velocity': la, 'schemes': [ { 'velocities': list(range(19)), 'conserved_moments': [rho, qx, qy, qz], 'polynomials': [ 1, X, Y, Z, 19*r - 30, 3*X**2 - r, Y**2-Z**2, X*Y, Y*Z, Z*X, X*(5*r - 9), Y*(5*r - 9), Z*(5*r - 9), X*(Y**2 - Z**2), Y*(Z**2 - X**2), Z*(X**2 - Y**2), (-2*X**2 + Y**2 + Z**2)*(3*r - 5), -5*Y**2 + 5*Z**2 + 3*X**2*(Y**2 - Z**2) + 3*Y**4 - 3*Z**4, -53*r + 21*r**2 + 24 ], 'relaxation_parameters': s,#[0]*4 + [1./tau]*15, 'feq': (feq, (sp.Matrix([qx, qy, qz]),)), }], 'init': { rho: rhoo, qx: rhoo*uo, qy: 0., qz: 0. }, 'boundary_conditions': { 0: {'method': {0: pylbm.bc.BouzidiBounceBack}, 'value': (bc_rect, (rhoo, uo))}, 1: {'method': {0: pylbm.bc.NeumannX}}, 2: {'method': {0: pylbm.bc.BouzidiBounceBack}}, }, 'parameters': {LA: la}, 'generator': generator, } sol = pylbm.Simulation(dico, sorder=sorder) return dt = 1./4 if withPlot: #### choice of the plotted field plot_field = plot_vorticity #### init viewer viewer = pylbm.viewer.matplotlib_viewer fig = viewer.Fig() ax = fig[0] ax.xaxis_set_visible(False) ax.yaxis_set_visible(False) field, ymin, ymax, decalh = plot_field(sol, bornes = True) image = ax.image(field, clim=[ymin, ymax], cmap="jet") def update(iframe): while sol.t < iframe * dt: sol.one_time_step() image.set_data(plot_field(sol)) ax.title = "Solution t={0:f}".format(sol.t) #### run the simulation fig.animate(update, interval=1) fig.show() else: im = 0 save(sol, im) while sol.t < Tf: im += 1 while sol.t < im * dt: sol.one_time_step() #printProgress(im, int(Tf/dt), prefix = 'Progress:', suffix = 'Complete', barLength = 50) save(sol, im) return sol
""" import pytest import pylbm ELEMENTS = [ [2, pylbm.Circle([0, 0], 1)], [2, pylbm.Ellipse([0, 0], [1, 0], [0, 1])], [2, pylbm.Triangle([-1, -1], [0, 2], [2, 0])], [2, pylbm.Parallelogram([-1, -1], [0, 2], [2, 0])], [3, pylbm.CylinderCircle([0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1])], [3, pylbm.CylinderEllipse([0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1])], [3, pylbm.CylinderTriangle([0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1])], [3, pylbm.Parallelepiped([-1, -1, -1], [2, 0, 0], [0, 2, 0], [0, 0, 2])], [3, pylbm.Ellipsoid([0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1])], [3, pylbm.Sphere([0, 0, 0], 1)], ] @pytest.fixture(params=ELEMENTS, ids=[elem[1].__class__.__name__ for elem in ELEMENTS]) def get_element(request): """get one element of the geometry""" return request.param BOX = [ (1, { 'x': [-2, 2], 'label': 3 }),
def run(dx, Tf, generator="cython", sorder=None, with_plot=True): """ Parameters ---------- dx: double spatial step Tf: double final time generator: pylbm generator sorder: list storage order with_plot: 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.BouzidiBounceBack } }, 1: { 'method': { 0: pylbm.bc.BouzidiBounceBack }, 'value': bc_up }, 2: { 'method': { 0: pylbm.bc.NeumannX } }, }, 'parameters': { LA: la }, 'generator': generator, } sol = pylbm.Simulation(dico, sorder=sorder) im = 0 compt = 0 while sol.t < Tf: sol.one_time_step() compt += 1 if compt == 128 and with_plot: im += 1 save(sol, im) compt = 0 return sol