Example #1
0
def get_random_triangle(p1 = [0.3,0.3], p2 = [0.7,0.3], p3 = [0.5,0.7], var = 0.3):
    
    start = (np.random.rand(2)-0.5) * var + p1
    end1 = (np.random.rand(2)-0.5) * var + p2
    v1 = end1 - start
    end2 = (np.random.rand(2)-0.5) * var + p3
    v2 = end2 - start
    obs = pylbm.Triangle(start,v1,v2,label=2)
    return obs
Example #2
0
    def test_domain_with_triangle(self):
        fname = 'triangle.npz'
        dom2d = copy.deepcopy(self.dom2d)
        dom2d['elements'] = [
            pylbm.Triangle([0.23, 0.73], [0.5, 0], [0., .5], label=10)
        ]
        dom = pylbm.Domain(dom2d)

        check_from_file(dom, fname)
Example #3
0
    def test_domain_with_fluid_triangle(self):
        fname = 'fluid_triangle.npz'
        dom2d = copy.deepcopy(self.dom2d)
        dom2d['elements'] = [
            pylbm.Parallelogram([0., 0.], [1., 0], [0., 2.], label=20),
            pylbm.Triangle([0.23, 0.73], [0.5, 0], [0., .5],
                           label=10,
                           isfluid=True)
        ]
        dom = pylbm.Domain(dom2d)

        check_from_file(dom, fname)
Example #4
0
    def get_dictionary(self):
        def init_rho(x, y):
            return self.rho_in

        def init_ux(x, y):
            return self.ux_in

        def init_uy(x, y):
            return self.uy_in

        def init_p(x, y):
            return self.p_in

        def init_qx(x, y):
            return init_rho(x, y) * init_ux(x, y)

        def init_qy(x, y):
            return init_rho(x, y) * init_uy(x, y)

        def init_E(x, y):
            return .5 * init_rho(x, y) * (init_ux(x, y)**2 + init_uy(
                x, y)) + init_p(x, y) / (self.gamma - 1)

        BC_labels = [1, 1, 4, 1]

        angle = self.angle_degre * np.pi / 180
        posx = self.xmin + (self.xmax - self.xmin) * self.distance_relative
        tri_p1 = [posx, self.ymin]
        tri_p2 = [self.xmax, (self.xmax - posx) * np.tan(angle)]
        tri_p3 = [self.xmax, self.ymin]

        return {
            'box': {
                'x': [self.xmin, self.xmax],
                'y': [self.ymin, self.ymax],
                'label': BC_labels
            },
            'elements': [
                pylbm.Triangle((tri_p1[0], tri_p1[1]), (tri_p2[0], tri_p2[1]),
                               (tri_p3[0], tri_p3[1]),
                               label=2)
            ],
            'init': {
                self.equation.rho: init_rho,
                self.equation.qx: init_qx,
                self.equation.qy: init_qy,
                self.equation.E: init_E,
            },
            'parameters': {
                self.equation.gamma: self.gamma
            }
        }
Example #5
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
# Authors:
#     Loic Gouarin <*****@*****.**>
#     Benjamin Graille <*****@*****.**>
#
# License: BSD 3 clause
"""
Example of a 2D geometry: the square [0,1]x[0,1] with a triangular hole
"""
import pylbm
d = {
    'box': {
        'x': [0, 1],
        'y': [0, 1],
        'label': 0
    },
    'elements': [pylbm.Triangle((0., 0.), (0., .5), (.5, 0.), label=1)],
}
g = pylbm.Geometry(d)
g.visualize(viewlabel=True)