Ejemplo n.º 1
0
    def test_cube_cube_coplanar_touchface(self):
        w = mt.createCube(marker=1)
        w.scale([2.0, 2.0, 2.0])

        c = mt.createCube(marker=2)
        c.translate([1.5, 0.0, 0.0])
        w = mt.mergePLC3D([w, c])
        self.assertEqual(w.nodeCount(), 8 + 8)
        self.assertEqual(w.boundaryCount(), 6 + 5)

        c = mt.createCube(marker=3)
        c.translate([-1.5, 0.0, 0.0])
        w = mt.mergePLC3D([w, c])
        self.assertEqual(w.nodeCount(), 8 + 8 + 8)
        self.assertEqual(w.boundaryCount(), 6 + 5 + 5)

        c = mt.createCube(marker=4)
        c.translate([0.0, 1.5, 0.0])
        w = mt.mergePLC3D([w, c])
        self.assertEqual(w.nodeCount(), 8 + 8 + 8 + 8)
        self.assertEqual(w.boundaryCount(), 6 + 5 + 5 + 5)

        c = mt.createCube(marker=5)
        c.translate([0.0, 0.0, -1.5])
        w = mt.mergePLC3D([w, c])
        self.assertEqual(w.nodeCount(), 8 + 8 + 8 + 8 + 8)
        self.assertEqual(w.boundaryCount(), 6 + 5 + 5 + 5 + 5)

        pg.show(w)
        # w.exportPLC('t.poly')
        pg.show(mt.createMesh(w))
Ejemplo n.º 2
0
    def test_face_in_face(self):
        """Test subface with different marker constructed with hole marker."""
        w = mt.createCube(marker=1, boundaryMarker=1)
        b = w.boundary(2)

        pad = mt.createFacet(
            mt.createCircle(radius=0.2, segments=12, isHole=True))
        b2 = pad.boundary(0)

        # rotate to match target norm and pos
        rot = pg.core.getRotation(b2.norm(), b.norm())
        pad.transform(rot)
        pad.translate(b.center())

        # create a boundary with new marker match the hole
        w.copyBoundary(b2)

        w.createBoundary(w.nodes(
            [w.createNode(n.pos()).id() for n in b2.nodes()]),
                         marker=2)

        #print(w.boundaryMarkers())

        mesh = mt.createMesh(w)

        #pg.show(mesh)
        # w.exportPLC('pad.poly')
        # mesh.exportBoundaryVTU('b.vtu')
        np.testing.assert_array_equal(
            pg.unique(pg.sort(mesh.boundaryMarkers())), [0, 1, 2])

        # print(mesh)
        # mesh.exportBoundaryVTU('b.vtu')
        pg.show(mesh)
Ejemplo n.º 3
0
def testShowPV():
    m1 = mt.createCube()
    # pg.rc['view3D'] = 'fallback'
    # pg.show(m1)

    pg.rc['view3D'] = 'pyvista'
    #pg.show(m1, notebook=True)

    pg.show(m1)
Ejemplo n.º 4
0
    def test_cubeBasics(self):
        plc = mt.createCube()
        for i, b in enumerate(plc.boundaries()):
            b.setMarker(i + 1)

        mesh = mt.createMesh(plc)

        for marker in pg.unique(pg.sort(plc.boundaryMarkers())):
            b1 = plc.boundaries(plc.boundaryMarkers() == marker)[0]
            b2 = mesh.boundaries(mesh.boundaryMarkers() == marker)[0]

            np.testing.assert_array_equal(b1.norm(), b2.norm())
Ejemplo n.º 5
0
    def test_cube_cube_equalface(self):
        w = mt.createCube(marker=1)
        c = mt.createCube(marker=2)
        c.translate([c.xmax() - w.xmin(), 0.0])

        w = mt.mergePLC3D([w, c])
        self.assertEqual(w.nodeCount(), 8 + 4)
        self.assertEqual(w.boundaryCount(), 6 + 5)

        c = mt.createCube(marker=3)
        c.translate([0.0, w.ymax() - c.ymin(), 0.0])
        w = mt.mergePLC3D([w, c])
        self.assertEqual(w.nodeCount(), 8 + 4 + 4)
        self.assertEqual(w.boundaryCount(), 6 + 5 + 5)

        c = mt.createCube(marker=4)
        c.translate([0.0, 0.0, c.zmax() - w.zmin()])
        w = mt.mergePLC3D([c, w])
        self.assertEqual(w.nodeCount(), 8 + 4 + 4 + 4)
        self.assertEqual(w.boundaryCount(), 6 + 5 + 5 + 5)

        c = mt.createCube(marker=5)
        c.translate([0.0, w.ymax() - c.ymin(), c.zmax() - w.zmin()])
        w = mt.mergePLC3D([c, w])
        self.assertEqual(w.nodeCount(), 8 + 4 + 4 + 4 + 6)
        self.assertEqual(w.boundaryCount(), 6 + 5 + 5 + 5 + 6)

        c = mt.createCube(marker=6)
        c.translate([0.0, c.ymax() - w.ymin(), c.zmax() - w.zmin()])
        w = mt.mergePLC3D([w, c])
        self.assertEqual(w.nodeCount(), 8 + 4 + 4 + 4 + 6 + 0)
        self.assertEqual(w.boundaryCount(), 6 + 5 + 5 + 5 + 6 + 3)

        # w.exportPLC('t.poly')
        pg.show(mt.createMesh(w))
Ejemplo n.º 6
0
    def test_smallcube_in_bigcube(self):
        """
        A small cube in a bigger one, creating two subfaces.
        author: @frodo4fingers
        """
        w = mt.createCube(marker=1)
        c = mt.createCube(size=[0.5, 1.0, 1.0], marker=2)

        w = mt.mergePLC3D([w, c])
        self.assertEqual(w.nodeCount(), 8 + 8)
        self.assertEqual(w.boundaryCount(), 8)

        # will not work until edge intersection is working
        # d = mt.createCube(size=[0.8, 1.0, 1.0],
        #                   pos=[0.1, 0.0, 1.0],
        #                   marker=3)
        # w = mt.mergePLC3D([w, d])
        # self.assertEqual(w.nodeCount(), 8+8)
        # self.assertEqual(w.boundaryCount(), 8)

        # print(w)
        pg.show(w)
        pg.show(mt.createMesh(w))
Ejemplo n.º 7
0
.. math::

    \nabla \cdot(K \nabla p)=0

The sought hydraulic velocity distribution can then be calculated as the
gradient field of :math:`\mathbf{v}=-\nabla p`.
"""
# sphinx_gallery_thumbnail_number = 2

import numpy as np

import pygimli as pg
import pygimli.meshtools as mt
from pygimli.viewer.pv import drawStreamLines, drawSlice

plc = mt.createCube(size=[40, 20, 15], marker=1, boundaryMarker=0)
cube = mt.createCube(size=[15, 15, 8], marker=2, boundaryMarker=0)
geom = plc + cube

mesh = mt.createMesh(geom, area=4)

for bound in mesh.boundaries():
    x = bound.center().x()
    if x == mesh.xmin():
        bound.setMarker(1)
    elif x == mesh.xmax():
        bound.setMarker(2)

kMap = {1: 1e-4, 2: 1e-6}
kArray = pg.solver.parseMapToCellArray(list(kMap), mesh)  # dict does not work
kArray = np.column_stack([kArray] * 3)
Ejemplo n.º 8
0
import pygimli as pg
import pygimli.meshtools as mt
from pygimli.physics.ert import simulate as simulateERT

###############################################################################
# In contrast to field measurements, experimental tanks have well-defined
# spatial dimensions and need different boundary conditions (BC).
#
# As there is no current flow through the tanks boundary at all, homogeneous
# (Neumann) BC are defined for the whole boundary.
# Neumann BC are natural (intrinsic) for the finite element simulations.
# \link{tutorial:fem:bc}, so we just need to define a cube geometry including
# region markers.

plc = mt.createCube(size=[0.99, 0.5, 1.0], pos=[0.495, 0.25], boundaryMarker=1)

###############################################################################
# We first read the measuring scheme file and add the electrodes as nodes with
# the marker -99 to the geometry.

filename = pg.getExampleFile("ert/modeltank.shm")
shm = pg.DataContainerERT(filename)

for s in shm.sensors():
    plc.createNode(s, marker=-99)

###############################################################################
# There are two small problems to overcome for simulating Neumann bodies.
#
# First, we always need dipole current injection since there can be no current
Ejemplo n.º 9
0
 def test_cube_cube_same(self):
     c1 = mt.createCube()
     c2 = mt.createCube()
     m = mt.mergePLC3D([c1, c2])
     self.assertEqual(c1.nodeCount(), m.nodeCount())
     self.assertEqual(c1.boundaryCount(), m.boundaryCount())
Ejemplo n.º 10
0
           str(depthAno) + 'W' + str(widthAno) + 'H' + str(HAno) + 'L' +
           str(lengthAno) + 'S' + str(shift) + 'Noise' + str(noiseLevel))
path_Figures = MainPath + '/Sens3d/' + SimName + '/Figures/'
if not os.path.exists(path_Figures):
    os.makedirs(path_Figures)
path_Data = MainPath + '/Sens3d/' + SimName + '/Data/'
if not os.path.exists(path_Data):
    os.makedirs(path_Data)
os.chdir(MainPath + '/Sens3d/' + SimName)

# %% create model geometry

# world = mt.createWorld(start=[-width/2, -width/2, 0], end=[width/2, width/2, -depth],
#                         worldMarker=True) # ,area=10 markerPosition=[width,width]
world = mt.createCube(size=[width, width, depth],
                      pos=[width / 2, width / 2, -depth / 2],
                      marker=1,
                      area=75)  #, boundaryMarker=0)

for i, b in enumerate(world.boundaries()):
    # if worldMarker is True:
    if b.norm()[2] == 1.0:
        b.setMarker(pg.core.MARKER_BOUND_HOMOGEN_NEUMANN)
    else:
        b.setMarker(pg.core.MARKER_BOUND_MIXED)

ano = mt.createCube(size=[widthAno, lengthAno, HAno],
                    pos=[width / 2 + shift / 2, width / 2, depthAno],
                    marker=4,
                    area=0.01)
plc = mt.mergePLC([world, ano])
Ejemplo n.º 11
0
# sphinx_gallery_thumbnail_number = 2
import numpy as np
import pygimli as pg
import pygimli.meshtools as mt
from pygimli.physics import traveltime
from pygimli.viewer.pv import drawSensors

pyvista = pg.optImport("pyvista")

################################################################################
# Build mesh.

depth = 15
width = 30
plc = mt.createCube(size=[width, width, depth], pos=[0, 0, -depth / 2], area=5)

n_sensors = 8
sensors = np.zeros((n_sensors, 3))
sensors[0, 0] = 15
sensors[0, 1] = -10
sensors[1:, 0] = -15
sensors[1:, 1] = np.linspace(-15, 15, n_sensors - 1)

for pos in sensors:
    plc.createNode(pos)
mesh = mt.createMesh(plc)
mesh.createSecondaryNodes(1)

################################################################################
# Create vertical gradient model.