Example #1
0
#!/usr/bin/env python
"""
    Mesh extrusion from 1D over 2D to a 3D hex mesh
"""

import math
import numpy as np
import pygimli as pg
from pygimli.meshtools import polytools as plc
# from pygimli.viewer import *
# import pygimli.meshtools as mt

c1 = plc.createCircle(pos=(-5.0, 0.0),
                      radius=0.1,
                      segments=5,
                      start=math.pi,
                      end=2 * math.pi,
                      isClosed=False)
c2 = plc.createCircle(pos=(5.0, 0.0),
                      radius=0.1,
                      segments=5,
                      start=math.pi,
                      end=2 * math.pi,
                      isClosed=False)

left = plc.createLine(start=(-20, 0.0), end=(-5.1, 0.0), segments=10)
left.node(8).setMarker(1)
mid = plc.createLine(start=(-4.9, 0.0), end=(4.9, 0.0), segments=20)
right = plc.createLine(start=(5.1, 0.0), end=(20, 0.0), segments=10)
left.node(2).setMarker(1)
#!/usr/bin/env python

"""
    Mesh extrusion from 1D over 2D to a 3D hex mesh
"""

import pygimli as pg
from pygimli.viewer import *
from pygimli.meshtools import *

import math
from pygimli.meshtools import polytools as plc

c1 = plc.createCircle(pos=(-5.0, 0.0), radius=0.1, segments=5,
                      start=math.pi, end=2*math.pi, isClosed=False)
c2 = plc.createCircle(pos=( 5.0, 0.0), radius=0.1, segments=5,
                      start=math.pi, end=2*math.pi, isClosed=False)

left = plc.createLine(start=(-20, 0.0), end=(-5.1, 0.0), segments=10)
left.node(8).setMarker(1)
mid = plc.createLine(start=(-4.9, 0.0), end=(4.9, 0.0), segments=20)
right= plc.createLine(start=(5.1, 0.0), end=(20, 0.0), segments=10)
left.node(2).setMarker(1)

border = mergePLC([left, c1, mid, c2, right])

depth = 20
nz = 15
newNodes = []
y = pg.increasingRange(0.2, depth, nz)
surface = pg.createMesh2D(border, y, 0, 0, False)
    cell counts and thus longer computation times.
"""

import matplotlib.pyplot as plt
import numpy as np

import pygimli as pg
from pygimli.meshtools import polytools as plc
from pygimli.meshtools import quality

################################################################################
# We start by creating a mesh with a refined object inside.

world = plc.createWorld(start=[-10, 0], end=[10, -10], marker=1,
                        worldMarker=False)
c1 = plc.createCircle(pos=[0.0, -5.0], radius=3.0, area=.3)

################################################################################
# When calling the :func:`pg.meshtools.createMesh` function, a quality parameter
# can be forwarded to Triangle, which prescribes the minimum angle allowed in
# the final mesh. We can asses its effectiveness by creating different meshes
# and plotting the resulting quality. For this purpose, we define a showQuality
# function, which also plots a histogram of the mesh qualities.


def showQuality(mesh, qualities):
    fig, axes = plt.subplots(1, 2)
    axes[1].hist(qualities, color="grey")
    pg.show(mesh, qualities, ax=axes[0], cMin=0.5, cMax=1, hold=True,
            logScale=False, label="Mesh quality", cmap="RdYlGn", showMesh=True)
    s = "Min: %.2f, Mean: %.2f, Max: %.2f" % (
    cell counts and thus longer computation times.
"""

import matplotlib.pyplot as plt
import pygimli as pg
from pygimli.meshtools import polytools as plc
from pygimli.meshtools import quality

################################################################################
# We start by creating a mesh with a refined object inside.

world = plc.createWorld(start=[-10, 0],
                        end=[10, -10],
                        marker=1,
                        worldMarker=False)
c1 = plc.createCircle(pos=[0.0, -5.0], radius=3.0, area=.3)

################################################################################
# When calling the :func:`pg.meshtools.createMesh` function, a quality parameter
# can be forwarded to Triangle, which prescribes the minimum angle allowed in
# the final mesh. We can asses its effectiveness by creating different meshes
# and plotting the resulting quality.

for q in 10, 20, 30:
    m = pg.meshtools.createMesh([world, c1], quality=q)
    quality(m, show=True)

################################################################################
# Note that there is a decreasing number of problematic triangles (marked in
# red). However, the number of cells is increased siginficantly to achieve this.
Example #5
0
def maillage_SWMS2D_EL(geometry):
    """Définition du maillage triangulaire pour SWMS_2D"""

    xmin = geometry.xmin
    xmax = geometry.xmax
    emin = geometry.emin
    emax = geometry.emax
    dtrou = geometry.dtrou
    etrou = geometry.etrou
    r = geometry.r
    dx = geometry.dx
    zaff = geometry.zaff
    eaff = geometry.eaff
    #waff=geometry.waff

    assert dtrou + zaff < emax

    #xtrou_reg = np.arange(xmin, r + dx, dx, 'float')
    #    xtrou_reg = np.arange(xmin, r + zaff, dx, 'float')
    #etrou_reg = np.arange(etrou, emax +dx, dx, 'float')
    #efin_reg = np.arange(eaff, etrou+dx, dx, 'float')

    #A présent on crée une zone grâce à un polygone

    poly = pg.Mesh(2)  # empty 2d mesh
    #nStart = poly.createNode(0.0, 0.0, 0.0) # On crée un noeud de départ, on travaille en 2D donc le dernier terme vaut 0.0

    #nA = nStart # noeud de départ
    xreg = [xmin, xmin, xmin + r, xmin + r, xmax, xmax, xmin + r]
    zreg = [emin, etrou, etrou, emax, emax, emin, emin]
    nStart = poly.createNode(
        xreg[0], zreg[0], 0.0
    )  # On crée un noeud de départ, on travaille en 2D donc le dernier terme vaut 0.0

    nA = nStart  # noeud de départ
    for xx, zz in zip(
            xreg[1::], zreg[1::]
    ):  # On démarre de 1 et on se balade sur l'axe des x en créant un noeud à chaque fois
        nB = poly.createNode(xx, zz, 0.0)
        poly.createEdge(
            nA, nB
        )  # On définit un côté entre le noeud précédemment créé et le nouveau
        nA = nB  # On remplace le noeud de départ par le noeud nouvellement créé
    poly.createEdge(nA, nStart)

    #=============================================================================
    c1 = plc.createCircle(pos=[xmin + r / 2, etrou + 1],
                          radius=20,
                          area=geometry.area * 0.3)
    mesh1 = pg.meshtools.createMesh(c1,
                                    quality=geometry.quality,
                                    area=geometry.area,
                                    smooth=geometry.smooth)
    #pg.show(mesh1, markers=True, showMesh=True)

    for ii in range(mesh1.nodeCount()):
        if (mesh1.node(ii)[1] > etrou):
            if (mesh1.node(ii)[0] > xmin + r):
                poly.createNode(mesh1.node(ii)[0], mesh1.node(ii)[1], 0)

        elif (mesh1.node(ii)[1] < etrou):
            if (mesh1.node(ii)[0] > xmin):
                poly.createNode(mesh1.node(ii)[0], mesh1.node(ii)[1], 0)

#=============================================================================

    mesh = pg.meshtools.createMesh(poly,
                                   quality=geometry.quality,
                                   area=geometry.area,
                                   smooth=geometry.smooth)

    pg_pos = mesh.positions()
    mesh_pos = np.array(
        (np.array(pg.x(pg_pos)), np.array(pg.y(pg_pos)), np.array(pg.z(pg_pos))
         )).T  #On crée une matrice contenant la position des noeuds
    mesh_cells = np.zeros(
        (mesh.cellCount(),
         3))  #Matrice vide de la taille du nombre de cellules
    for i, cell in enumerate(
            mesh.cells()):  #On rentre les cellules das une matrice
        mesh_cells[i] = cell.ids()

    return mesh, pg_pos, mesh_pos, mesh_cells