Пример #1
0
    def test_domain_with_circle(self):
        fname = 'circle.npz'
        dom2d = copy.deepcopy(self.dom2d)
        dom2d['elements'] = [pylbm.Circle([0.5, 1.], .5, label=10)]
        dom = pylbm.Domain(dom2d)

        check_from_file(dom, fname)
Пример #2
0
    def test_domain_with_fluid_circle(self):
        fname = 'fluid_circle.npz'
        dom2d = copy.deepcopy(self.dom2d)
        dom2d['elements'] = [
            pylbm.Parallelogram([0., 0.], [1., 0], [0., 2.], label=20),
            pylbm.Circle([0.5, 1.], .5, label=10, isfluid=True)
        ]
        dom = pylbm.Domain(dom2d)

        check_from_file(dom, fname)
Пример #3
0
# Authors:
#     Loic Gouarin <*****@*****.**>
#     Benjamin Graille <*****@*****.**>
#
# License: BSD 3 clause
"""
Example of a 2D geometry: the square [0,1]x[0,1] with a circular hole
"""
import pylbm
d = {
    'box': {
        'x': [0, 1],
        'y': [0, 1],
        'label': 0
    },
    'elements': [pylbm.Circle((.5, .5), .125, label=1)],
}
g = pylbm.Geometry(d)
g.visualize(viewlabel=True)
Пример #4
0
 {
     'box': {'x': [0, 1], 'label': 0},
     'space_step': 0.1,
     'schemes': [{'velocities': list(range(3))}],
 },
 {
     'box': {'x': [0, 2], 'y': [0, 1], 'label': 0},
     'elements': [
         pylbm.Ellipse((0.5, 0.5), (0.25, 0.25), (0.1, -0.1), label=1)
     ],
     'space_step': 0.05,
     'schemes':[{'velocities': list(range(13))}],
 },
 {
     'box': {'x': [0, 2], 'y': [0, 1], 'label': 0},
     'elements':[pylbm.Circle((0.5, 0.5), 0.2, label=1)],
     'space_step': 0.05,
     'schemes':[{'velocities': list(range(13))}],
 },
 {
     'box': {'x': [0, 1], 'y': [0, 1], 'label': [0, 1, 2, 3]},
     'space_step': 0.1,
     'schemes':[{'velocities': list(range(9))}],
 },
 {
     'box': {'x': [0, 3], 'y': [0, 1], 'label': [0, 1, 0, 2]},
     'elements': [
         pylbm.Parallelogram((0., 0.), (.5, 0.), (0., .5), label=0)
     ],
     'space_step': 0.125,
     'schemes':[{'velocities': list(range(9))}],
Пример #5
0
# Authors:
#     Loic Gouarin <*****@*****.**>
#     Benjamin Graille <*****@*****.**>
#
# License: BSD 3 clause
"""
Example of a 2D geometry: the square [0,1]x[0,1] with a circular hole
"""
import pylbm

# pylint: disable=invalid-name

dgeom = {
    'box': {
        'x': [0, 1],
        'y': [0, 1],
        'label': 0
    },
    'elements': [pylbm.Circle((0.5, 0.5), 0.125, label=1)],
}
geom = pylbm.Geometry(dgeom)
print(geom)
geom.visualize(viewlabel=True, alpha=0.5)
Пример #6
0
# Authors:
#     Loic Gouarin <*****@*****.**>
#     Benjamin Graille <*****@*****.**>
#
# License: BSD 3 clause
"""
Example of a square in 2D with a circular hole with a D2Q13
"""
from six.moves import range
import pylbm
dico = {
    'box': {
        'x': [0, 2],
        'y': [0, 1],
        'label': 0
    },
    'elements': [pylbm.Circle((0.5, 0.5), 0.2)],
    'space_step': 0.05,
    'schemes': [{
        'velocities': list(range(13))
    }],
}
dom = pylbm.Domain(dico)
dom.visualize()
dom.visualize(view_distance=True)
Пример #7
0
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

    """
    # parameters
    xmin, xmax, ymin, ymax = 0., 2., 0., 1.
    radius = 0.125
    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)
    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': [0, 1, 0, 0]
        },
        'elements':
        [pylbm.Circle([.3, 0.5 * (ymin + ymax) + 2 * dx], radius, label=2)],
        '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: rhoo,
                    qx: rhoo * uo,
                    qy: 0.
                },
            },
        ],
        'parameters': {
            LA: la
        },
        '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
                }
            },
        },
        'generator':
        generator,
        'show_code':
        True
    }

    sol = pylbm.Simulation(dico, sorder=sorder)

    if withPlot:
        Re = rhoo * uo * 2 * radius / mu
        print("Reynolds number {0:10.3e}".format(Re))

        # init viewer
        viewer = pylbm.viewer.matplotlib_viewer
        fig = viewer.Fig()

        ax = fig[0]
        ax.ellipse([.3 / dx, 0.5 * (ymin + ymax) / dx + 2],
                   [radius / dx, radius / dx], 'r')
        image = ax.image(vorticity(sol), cmap='jet', clim=[0, .05])

        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
Пример #8
0
s_q = s_eta
s_es = s_mu
s = [0., 0., 0., s_mu, s_es, s_q, s_q, s_eta, s_eta]
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': [0, 2, 0, 0]
    },
    'elements': [pylbm.Circle([.3, 0.5 * (ymin + ymax) + dx], rayon, label=1)],
    'space_step':
    dx,
    'scheme_velocity':
    la,
    'parameters': {
        LA: la
    },
    'schemes': [
        {
            'velocities':
            list(range(9)),
            'conserved_moments': [rho, qx, qy],
            'polynomials': [
                1, LA * X, LA * Y, 3 * (X**2 + Y**2) - 4,
                (9 * (X**2 + Y**2)**2 - 21 * (X**2 + Y**2) + 8) / 2,
Пример #9
0
# Authors:
#     Loic Gouarin <*****@*****.**>
#     Benjamin Graille <*****@*****.**>
#
# License: BSD 3 clause
"""
pylbm: tests for the geometry
"""

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
Пример #10
0
# Authors:
#     Loic Gouarin <*****@*****.**>
#     Benjamin Graille <*****@*****.**>
#
# License: BSD 3 clause

"""
Example of a complex geometry in 2D
"""
import pylbm
square = pylbm.Parallelogram((.1, .1), (.8, 0), (0, .8), isfluid=False)
strip = pylbm.Parallelogram((0, .4), (1, 0), (0, .2), isfluid=True)
circle = pylbm.Circle((.5, .5), .25, isfluid=True)
inner_square = pylbm.Parallelogram((.4, .5), (.1, .1), (.1, -.1), isfluid=False)
d = {'box':{'x': [0, 1], 'y': [0, 1], 'label':0},
     'elements':[square, strip, circle, inner_square],
}
g = pylbm.Geometry(d)
g.visualize()
# rounded inner angles
g.add_elem(pylbm.Parallelogram((0.1, 0.9), (0.05, 0), (0, -0.05), isfluid=True))
g.add_elem(pylbm.Circle((0.15, 0.85), 0.05, isfluid=False))
g.add_elem(pylbm.Parallelogram((0.1, 0.1), (0.05, 0), (0, 0.05), isfluid=True))
g.add_elem(pylbm.Circle((0.15, 0.15), 0.05, isfluid=False))
g.add_elem(pylbm.Parallelogram((0.9, 0.9), (-0.05, 0), (0, -0.05), isfluid=True))
g.add_elem(pylbm.Circle((0.85, 0.85), 0.05, isfluid=False))
g.add_elem(pylbm.Parallelogram((0.9, 0.1), (-0.05, 0), (0, 0.05), isfluid=True))
g.add_elem(pylbm.Circle((0.85, 0.15), 0.05, isfluid=False))
g.visualize()
def main():
    # parameters
    xmin, xmax, ymin, ymax = 0., 2., 0., 1.
    radius = 0.125
    if h5_save:
        dx = 1. / 512  # spatial step
    else:
        dx = 1. / 128
    la = 1.  # velocity of the scheme
    rhoo = 1.
    uo = 0.05
    mu = 5.e-5
    zeta = 10 * 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': [0, 1, 0, 0]
        },
        'elements':
        [pylbm.Circle([.3, 0.5 * (ymin + ymax) + 2 * dx], radius, label=2)],
        '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: rhoo,
            qx: rhoo * uo,
            qy: 0.
        },
        'parameters': {
            LA: la
        },
        '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
                }
            },
        },
        'generator':
        "cython",
    }

    sol = pylbm.Simulation(dico)

    Re = rhoo * uo * 2 * radius / mu
    print("Reynolds number {0:10.3e}".format(Re))

    x, y = sol.domain.x, sol.domain.y

    if h5_save:
        Tf = 500.
        im = 0
        l = Tf / sol.dt / 64
        printProgress(im,
                      l,
                      prefix='Progress:',
                      suffix='Complete',
                      barLength=50)
        filename = 'Karman'
        path = './data_' + filename
        save(x, y, sol.m, im)
        while sol.t < Tf:
            for k in range(64):
                sol.one_time_step()
            im += 1
            printProgress(im,
                          l,
                          prefix='Progress:',
                          suffix='Complete',
                          barLength=50)
            save(sol.mpi_topo, x, y, sol.m, im)
    else:
        viewer = pylbm.viewer.matplotlib_viewer
        fig = viewer.Fig(figsize=(8, 6))
        ax = fig[0]
        ax.ellipse([.3 / dx, 0.5 * (ymin + ymax) / dx + 2],
                   [radius / dx, radius / dx], 'r')
        image = ax.image(vorticity(sol), cmap='cubehelix', clim=[0, .05])

        def update(iframe):
            nrep = 64
            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()
Пример #12
0
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': [0, 1, 0, 0]
    },
    'elements':
    [pylbm.Circle([.3, 0.5 * (ymin + ymax) + 2 * dx], radius, label=2)],
    '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':
def format_input(input_data):
    boundary = get_boundary(input_data)

    if input_data["Library"] == 1:
        if input_data["Problem"] == 1:

            def bc_in(f, m, x, y):
                m[qx] = input_data["Density"] * (input_data["Velocity"]/20)

            dummy = 3.0/(input_data["Velocity"]*input_data["Density"]*(1./64))
            s_mu = 1.0/(0.5+input_data["BulkViscosity"]*dummy)
            eta = input_data["Density"]*(1./20)*2*0.05/input_data["ReynoldsNumber"]
            s_q = 1.0/(0.5+eta*dummy)
            s = [0., 0., 0., s_mu, s_mu, s_q, s_q, s_q, s_q]
            dummy2 = 1./(LA**2*input_data["Density"])
            qx2 = dummy2 * qx ** 2
            qy2 = dummy2 * qy ** 2
            q2 = qx2 + qy2
            qxy = dummy2 * qx * qy

            problem_parameters = {
                'box': {'x': [boundary["x_min"], boundary["x_max"]],
                        'y': [boundary["y_min"], boundary["y_max"]],
                        'label': [0, 2, 0, 0]
                        },
                'elements': [pylbm.Circle([.3, 0.5 * (boundary["y_min"] + boundary["y_max"]) + 1./64], 0.05, label=1)],
                'space_step': 1./64,
                'scheme_velocity': input_data["Velocity"],
                'parameters': {LA: input_data["Velocity"]},
                'schemes': [
                    {
                        'velocities': list(range(9)),
                        'conserved_moments': [rho, qx, qy],
                        'polynomials': [
                            1, LA * X, LA * Y,
                               3 * (X ** 2 + Y ** 2) - 4,
                               (9 * (X ** 2 + Y ** 2) ** 2 - 21 * (X ** 2 + Y ** 2) + 8) / 2,
                               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
                        ],
                    },
                ],
                'init': {rho: input_data["Density"],
                         qx: 0.,
                         qy: 0.
                         },
                'boundary_conditions': {
                    0: {'method': {0: pylbm.bc.BouzidiBounceBack}, 'value': bc_in},
                    1: {'method': {0: pylbm.bc.BouzidiBounceBack}},
                    2: {'method': {0: pylbm.bc.NeumannX}},
                },
                'generator': 'cython',
            }

            return problem_parameters
Пример #14
0
def run(space_step,
        final_time,
        generator="cython",
        sorder=None,
        with_plot=True):
    """
    Parameters
    ----------

    space_step: double
        spatial step

    final_time: double
        final time

    generator: string
        pylbm generator

    sorder: list
        storage order

    with_plot: boolean
        if True plot the solution otherwise just compute the solution


    Returns
    -------

    sol
        <class 'pylbm.simulation.Simulation'>

    """
    # parameters
    scheme_name = 'Geier'
    xmin, xmax, ymin, ymax = 0., 2., 0., 1.  # bounds of the domain
    radius = 1. / 32  # radius of the obstacle
    la = 1.  # velocity of the scheme
    rho_o = 1.  # reference value of the mass
    u_o = 0.05  # boundary value of the velocity
    mu = 5.e-6  # bulk viscosity
    zeta = 10 * mu  # shear viscosity

    def moments_choice(scheme_name, mu, zeta):
        if scheme_name == 'dHumiere':
            dummy = 1. / rho_o
            QX2 = dummy * QX**2
            QY2 = dummy * QY**2
            Q2 = QX2 + QY2
            QXY = dummy * QX * QY
            polynomials = [
                1, X, Y, 3 * (X**2 + Y**2) - 4 * LA**2,
                0.5 * (9 * (X**2 + Y**2)**2 - 21 *
                       (X**2 + Y**2) * LA**2 + 8 * LA**4),
                3 * X * (X**2 + Y**2) - 5 * X * LA**2,
                3 * Y * (X**2 + Y**2) - 5 * Y * LA**2, X**2 - Y**2, X * Y
            ]
            equilibrium = [
                RHO, QX, QY, -2 * RHO * LA**2 + 3 * Q2, RHO * LA**2 - 3 * Q2,
                -QX * LA**2, -QY * LA**2, QX2 - QY2, QXY
            ]
            dummy = 3.0 / (la * rho_o * space_step)
            sigma_1 = dummy * zeta
            sigma_2 = dummy * mu
            s_1 = 1 / (.5 + sigma_1)
            s_2 = 1 / (.5 + sigma_2)

        if scheme_name == 'Geier':
            UX, UY = QX / RHO, QY / RHO
            RHOU2 = RHO * (UX**2 + UY**2)
            polynomials = [
                1,
                X,
                Y,
                X**2 + Y**2,
                X * Y**2,
                Y * X**2,
                X**2 * Y**2,
                X**2 - Y**2,
                X * Y,
            ]
            equilibrium = [
                RHO,
                QX,
                QY,
                RHOU2 + 2 / 3 * RHO * LA**2,
                QX * (LA**2 / 3 + UY**2),
                QY * (LA**2 / 3 + UX**2),
                RHO * (LA**2 / 3 + UX**2) * (LA**2 / 3 + UY**2),
                RHO * (UX**2 - UY**2),
                RHO * UX * UY,
            ]
            dummy = 3.0 / (la * rho_o * space_step)
            sigma_1 = dummy * (zeta - 2 * mu / 3)
            sigma_2 = dummy * mu
            s_1 = 1 / (.5 + sigma_1)
            s_2 = 1 / (.5 + sigma_2)

        if scheme_name == 'Lallemand':
            dummy = 1. / rho_o
            QX2 = dummy * QX**2
            QY2 = dummy * QY**2
            Q2 = QX2 + QY2
            QXY = dummy * QX * QY
            polynomials = [
                1,
                X,
                Y,
                X**2 + Y**2,
                X * (X**2 + Y**2),
                Y * (X**2 + Y**2),
                (X**2 + Y**2)**2,
                X**2 - Y**2,
                X * Y,
            ]
            equilibrium = [
                RHO,
                QX,
                QY,
                Q2 + 2 / 3 * LA**2 * RHO,
                4 / 3 * QX * LA**2,
                4 / 3 * QY * LA**2,
                ((21 * Q2 + 6 * RHO * LA**2) * LA**2 -
                 (6 * Q2 - 2 * RHO * LA**2)) / 9,
                QX2 - QY2,
                QXY,
            ]
            dummy = 3.0 / (la * rho_o * space_step)
            sigma_1 = dummy * zeta
            sigma_2 = dummy * mu
            s_1 = 1 / (.5 + sigma_1)
            s_2 = 1 / (.5 + sigma_2)

        s = [0., 0., 0., s_1, s_1, s_1, s_1, s_2, s_2]
        return polynomials, equilibrium, s

    polynomials, equilibrium, s = moments_choice(scheme_name, mu, zeta)

    simu_cfg = {
        'box': {
            'x': [xmin, xmax],
            'y': [ymin, ymax],
            'label': [0, 1, 0, 0]
        },
        'elements': [
            pylbm.Circle([.3, 0.5 * (ymin + ymax) + 2 * space_step],
                         radius,
                         label=2)
        ],
        'space_step':
        space_step,
        'scheme_velocity':
        la,
        'schemes': [
            {
                'velocities': list(range(9)),
                'polynomials': polynomials,
                'relaxation_parameters': s,
                'equilibrium': equilibrium,
                'conserved_moments': [RHO, QX, QY],
            },
        ],
        'parameters': {
            LA: la
        },
        'init': {
            RHO: rho_o,
            QX: rho_o * u_o,
            QY: 0.
        },
        'boundary_conditions': {
            0: {
                'method': {
                    0: pylbm.bc.BouzidiBounceBack
                },
                'value': (bc_in, (rho_o, u_o))
            },
            1: {
                'method': {
                    0: pylbm.bc.NeumannX
                }
            },
            2: {
                'method': {
                    0: pylbm.bc.BouzidiBounceBack
                }
            },
        },
        'generator':
        generator,
        'relative_velocity': [QX / RHO, QY / RHO],
        # 'show_code': True
    }

    sol = pylbm.Simulation(simu_cfg, sorder=sorder)

    if with_plot:
        Re = rho_o * u_o * 2 * radius / mu
        print("Reynolds number {0:10.3e}".format(Re))

        # init viewer
        viewer = pylbm.viewer.matplotlib_viewer
        fig = viewer.Fig()

        axe = fig[0]
        axe.grid(visible=False)
        axe.xaxis_set_visible(False)
        axe.yaxis_set_visible(False)
        axe.ellipse(
            [.3 / space_step - 1.5, 0.5 * (ymin + ymax) / space_step + .5],
            [radius / space_step, radius / space_step], 'black')
        surf = axe.SurfaceImage(vorticity(sol), cmap='jet', clim=[0, .1])

        def update(iframe):  # pylint: disable=unused-argument
            nrep = 32
            for _ in range(nrep):
                sol.one_time_step()
            surf.update(vorticity(sol))
            axe.title = "Solution t={0:f}".format(sol.t)

        # run the simulation
        fig.animate(update, interval=1)
        fig.show()
    else:
        while sol.t < final_time:
            sol.one_time_step()

    return sol
Пример #15
0
#
# License: BSD 3 clause
"""
Example of a square in 2D with a cavity
"""
import pylbm

D_DOM = {
    'box': {
        'x': [0, 1],
        'y': [0, 1],
        'label': 0
    },
    'elements': [
        pylbm.Parallelogram((0.4, 0.3), (0, 0.4), (0.2, 0), label=1),
        pylbm.Circle((0.4, 0.5), 0.2, label=3),
        pylbm.Circle((0.6, 0.5), 0.2, label=3),
        pylbm.Parallelogram((0.45, 0.3), (0, 0.4), (0.1, 0),
                            label=2,
                            isfluid=True),
    ],
    'space_step':
    0.025,
    'schemes': [{
        'velocities': list(range(9))
    }],
}
DOMAIN = pylbm.Domain(D_DOM)
print(DOMAIN)
DOMAIN.visualize(view_distance=True,
                 label=None,
Пример #16
0
#     Benjamin Graille <*****@*****.**>
#
# License: BSD 3 clause
"""
Example of a square in 2D with a circular hole
"""
import pylbm

D_DOM = {
    'box': {
        'x': [0, 2],
        'y': [0, 1],
        'label': 0
    },
    'elements': [
        pylbm.Circle((0.5, 0.5), 0.2, label=1),
    ],
    'space_step': 0.05,
    'schemes': [{
        'velocities': list(range(13))
    }],
}
DOMAIN = pylbm.Domain(D_DOM)
print(DOMAIN)
DOMAIN.visualize(scale=1.5)
DOMAIN.visualize(view_distance=True,
                 label=None,
                 view_in=True,
                 view_out=True,
                 view_bound=True)
DOMAIN.visualize(
obs_num = 0
while batch_counter < 500:

    uo = np.random.rand(1) * .2 + .05
    uo = uo[0]
    radius = np.random.rand(1) * .4 + .05
    radius = radius[0]

    first = True
    print("Obstacle number", obs_num)
    # obs = obs_gen.get_random_triangle()
    x_loc = np.random.rand(1) * 1.25 + radius + .05
    y_loc = 0.5 * (np.random.rand(1)) + radius + .05
    x_loc = x_loc[0]
    y_loc = y_loc[0]
    obs = pylbm.Circle([x_loc, y_loc], radius, label=2)

    dico = {
        'box': {
            'x': [xmin, xmax],
            'y': [ymin, ymax],
            'label': [0, 1, 0, 0]
        },
        'elements': [obs],
        'space_step':
        dx,
        'scheme_velocity':
        LA,
        'schemes': [
            {
                'velocities':