Exemplo n.º 1
0
def create_mesh():
    global python_major_version, pygmsh_major_version, meshio_major_version

    # version info
    python_major_version = sys.version_info[0]
    python_minor_version = sys.version_info[1]
    print("Python version: ", "{}.{}".format(python_major_version,
                                             python_minor_version))

    # meshio version
    version = meshio.__version__
    meshio_major_version = int(version.split(".")[0])
    print("meshio version: ", version)

    # pygmsh version
    version = pygmsh.__version__
    pygmsh_major_version = int(version.split(".")[0])
    print("pygmsh version: ", version)

    # Gmsh version
    if pygmsh_major_version >= 7:
        # pygmsh version >= 7.x
        version = pygmsh.__gmsh_version__
    else:
        # pygmsh version 6.x
        version = pygmsh.get_gmsh_major_version()
    print("Gmsh version  : ", version, " module version ", gmsh.__version__)

    # creates a simple 3D mesh
    mesh_3D()
def create_mesh():
    # version info
    print("pygmsh version: ", pygmsh.__version__)

    version = pygmsh.get_gmsh_major_version()
    print("Gmsh version  : ", version)

    # creates a simple 3D mesh
    mesh_3D()
Exemplo n.º 3
0
def _test_demo(demo):
    import sys
    sys._called_from_test = True

    def nop(*args, **kwargs):
        pass

    try:
        from matplotlib import pyplot
        pyplot.show = nop
    except ImportError:
        pass
    try:
        import dolfin
        dolfin.plot = nop
    except ImportError:
        pass

    # reset default RandomState
    import pymor.tools.random
    pymor.tools.random._default_random_state = None

    result = None
    try:
        result = demo()
    except QtMissing:
        pytest.xfail("Qt missing")
    except GmshError as ge:
        # this error is ok if gmsh isn't installed at all, or in the wrong version
        try:
            import pygmsh
            gmsh_major = pygmsh.get_gmsh_major_version()
            if gmsh_major != 2:
                pytest.xfail(
                    f'GMSH installed in incompatible major {gmsh_major}')
            else:
                raise ge
        except (ImportError, FileNotFoundError):
            pytest.xfail(f'GMSH not intalled')
        else:
            raise ge
    finally:
        stop_gui_processes()
        from pymor.parallel.default import _cleanup
        _cleanup()

    return result
Exemplo n.º 4
0
Arquivo: demos.py Projeto: pymor/pymor
def _test_demo(demo):
    import sys
    sys._called_from_test = True

    def nop(*args, **kwargs):
        pass

    try:
        from matplotlib import pyplot
        pyplot.show = nop
    except ImportError:
        pass
    try:
        import dolfin
        dolfin.plot = nop
    except ImportError:
        pass

    # reset default RandomState
    import pymor.tools.random
    pymor.tools.random._default_random_state = None

    result = None
    try:
        result = demo()
    except QtMissing:
        pytest.xfail("Qt missing")
    except GmshError as ge:
        # this error is ok if gmsh isn't installed at all, or in the wrong version
        try:
            import pygmsh
            gmsh_major = pygmsh.get_gmsh_major_version()
            if gmsh_major != 2:
                pytest.xfail(f'GMSH installed in incompatible major {gmsh_major}')
            else:
                raise ge
        except (ImportError, FileNotFoundError):
            pytest.xfail(f'GMSH not intalled')
        else:
            raise ge
    finally:
        stop_gui_processes()
        from pymor.parallel.default import _cleanup
        _cleanup()

    return result
Exemplo n.º 5
0
def test():
    geom = pygmsh.built_in.Geometry()

    lcar = 0.1
    p1 = geom.add_point([0.0, 0.0, 0.0], lcar)
    p2 = geom.add_point([1.0, 0.0, 0.0], lcar)
    p3 = geom.add_point([1.0, 0.5, 0.0], lcar)
    p4 = geom.add_point([1.0, 1.0, 0.0], lcar)
    s1 = geom.add_bspline([p1, p2, p3, p4])

    p2 = geom.add_point([0.0, 1.0, 0.0], lcar)
    p3 = geom.add_point([0.5, 1.0, 0.0], lcar)
    s2 = geom.add_bspline([p4, p3, p2, p1])

    ll = geom.add_line_loop([s1, s2])
    geom.add_plane_surface(ll)

    ref = 0.9156598733673261 if pygmsh.get_gmsh_major_version() < 4 else 0.75
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Exemplo n.º 6
0
def test():
    geom = pygmsh.built_in.Geometry()

    lcar = 0.1
    p1 = geom.add_point([0.0, 0.0, 0.0], lcar)
    p2 = geom.add_point([1.0, 0.0, 0.0], lcar)
    p3 = geom.add_point([1.0, 0.5, 0.0], lcar)
    p4 = geom.add_point([1.0, 1.0, 0.0], lcar)
    s1 = geom.add_bspline([p1, p2, p3, p4])

    p2 = geom.add_point([0.0, 1.0, 0.0], lcar)
    p3 = geom.add_point([0.5, 1.0, 0.0], lcar)
    s2 = geom.add_bspline([p4, p3, p2, p1])

    ll = geom.add_line_loop([s1, s2])
    geom.add_plane_surface(ll)

    ref = 0.9156598733673261 if pygmsh.get_gmsh_major_version() < 4 else 0.75
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh
Exemplo n.º 7
0
import pytest
from helpers import compute_volume

import pygmsh


@pytest.mark.skipif(pygmsh.get_gmsh_major_version() < 3, reason="requires Gmsh >= 3")
def test():
    geom = pygmsh.opencascade.Geometry()

    geom.add_wedge([0.0, 0.0, 0.0], [1.0, 1.0, 1.0], top_extent=0.4, char_length=0.1)

    ref = 0.7
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh


if __name__ == "__main__":
    import meshio

    meshio.write("opencascade_wedge.vtu", test())
Exemplo n.º 8
0
# -*- coding: utf-8 -*-
import pytest

import pygmsh

from helpers import compute_volume


@pytest.mark.skipif(pygmsh.get_gmsh_major_version() < 3,
                    reason="requires Gmsh >= 3")
def test_union():
    geom = pygmsh.opencascade.Geometry(characteristic_length_min=0.1,
                                       characteristic_length_max=0.1)

    rectangle = geom.add_rectangle([-1.0, -1.0, 0.0], 2.0, 2.0)
    disk_w = geom.add_disk([-1.0, 0.0, 0.0], 0.5)
    disk_e = geom.add_disk([+1.0, 0.0, 0.0], 0.5)
    geom.boolean_union([rectangle, disk_w, disk_e])

    ref = 4.780361
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh


@pytest.mark.skipif(pygmsh.get_gmsh_major_version() < 3,
                    reason="requires Gmsh >= 3")
def test_intersection():
    geom = pygmsh.opencascade.Geometry(characteristic_length_min=0.1,
                                       characteristic_length_max=0.1)
Exemplo n.º 9
0
# -*- coding: utf-8 -*-
import pytest

import pygmsh

from helpers import compute_volume


@pytest.mark.skipif(pygmsh.get_gmsh_major_version() < 3, reason="requires Gmsh >= 3")
def test():
    geom = pygmsh.opencascade.Geometry(
        characteristic_length_min=2.0, characteristic_length_max=2.0
    )

    rect1 = geom.add_rectangle([10.0, 0.0, 0.0], 20.0, 40.0, corner_radius=5.0)
    rect2 = geom.add_rectangle([0.0, 10.0, 0.0], 40.0, 20.0, corner_radius=5.0)
    disk1 = geom.add_disk([14.5, 35.0, 0.0], 1.85)
    disk2 = geom.add_disk([25.5, 5.0, 0.0], 1.85)

    rect3 = geom.add_rectangle([10.0, 30.0, 0.0], 10.0, 1.0)
    rect4 = geom.add_rectangle([20.0, 9.0, 0.0], 10.0, 1.0)

    r1 = geom.add_rectangle([9.0, 0.0, 0.0], 21.0, 20.5, corner_radius=8.0)
    r2 = geom.add_rectangle([10.0, 00.0, 0.0], 20.0, 19.5, corner_radius=7.0)
    diff1 = geom.boolean_difference([r1], [r2])
    r22 = geom.add_rectangle([9.0, 10.0, 0.0], 11.0, 11.0)
    inter1 = geom.boolean_intersection([diff1, r22])

    r3 = geom.add_rectangle([10.0, 19.5, 0.0], 21.0, 21.0, corner_radius=8.0)
    r4 = geom.add_rectangle([10.0, 20.5, 0.0], 20.0, 20.0, corner_radius=7.0)
    diff2 = geom.boolean_difference([r3], [r4])
Exemplo n.º 10
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from math import pi
import pytest

import pygmsh

from helpers import compute_volume


@pytest.mark.skipif(
    pygmsh.get_gmsh_major_version() < 3,
    reason='requires Gmsh >= 3'
    )
def test():
    geom = pygmsh.opencascade.Geometry()

    geom.add_torus([0.0, 0.0, 0.0], 1.0, 0.3, 1.25*pi, char_length=0.1)

    ref = 1.09994740709
    points, cells, _, _, _ = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(points, cells) - ref) < 1.0e-2 * ref
    return points, cells


if __name__ == '__main__':
    import meshio
    meshio.write('opencascade_torus.vtu', *test())