Ejemplo n.º 1
0
def createScene(root):
        from math import pi
        geom = Geometry()
        
        # Draw a cross.
        poly = geom.add_polygon([
            [ 0.1,  0.5, 0.0],
            [-0.1,  0.1, 0.0],
            [-0.5,  0.0, 0.0],
            [-0.1, -0.1, 0.0],
            [ 0.0, -0.5, 0.0],
            [ 0.1, -0.1, 0.0],
            [ 0.5,  0.0, 0.0],
            [ 0.1,  0.1, 0.0]
            ],
            lcar=0.05
            )
        axis = [0, 0, 1]

        geom.extrude(
            poly,
            translation_axis=axis,
            rotation_axis=axis,
            point_on_axis=[0, 0, 0],
            angle=2.0 / 6.0 * pi
            )

        filename = meshAndSaveToFile(geom, directory="data/meshes/autogen/")
        root.addObject("MeshVTKLoader", name="loader", filename=filename)
        root.addObject("TetrahedronSetTopologyContainer", name="container", src="@loader")

        root.addObject("MechanicalObject", name="dofs", position="@loader.position")
        root.addObject("TetrahedronFEMForceField", name="forcefield")
Ejemplo n.º 2
0
    def make_geom(length: float, lcar: float) -> Geometry:
        # Barkley et al (2002, figure 3 a - c)
        geom = Geometry()

        points = []
        for point in [[0, -1, 0],
                      [length, -1, 0],
                      [length, 1, 0],
                      [-1, 1, 0],
                      [-1, 0, 0],
                      [0, 0, 0]]:
            points.append(geom.add_point(point, lcar))

        lines = []
        for termini in zip(points,
                           islice(cycle(points), 1, None)):
            lines.append(geom.add_line(*termini))

        for k, label in [([1], 'outlet'),
                         ([2], 'ceiling'),
                         ([3], 'inlet'),
                         ([0, 4, 5], 'floor')]:
            geom.add_physical(list(np.array(lines)[k]), label)

        geom.add_physical(
            geom.add_plane_surface(geom.add_line_loop(lines)), 'domain')

        return geom
    def geometry(self) -> Geometry:
        geom = Geometry()
        cylinder = geom.add_circle([*self.centre, 0.0], self.radius, lcar=self.lcar)
        channel = geom.add_rectangle(
            0.0, self.length, 0.0, self.height, 0, holes=[cylinder], lcar=self.lcar
        )
        geom.add_physical(channel.surface, "domain")
        geom.add_physical(channel.lines[1], "outlet")
        geom.add_physical(channel.lines[3], "inlet")

        return geom
Ejemplo n.º 4
0
def make_mesh(a: float,         # radius of wire
              b: float,         # radius of insulation
              dx: Optional[float] = None) -> MeshTri:

    dx = a / 2 ** 3 if dx is None else dx

    origin = np.zeros(3)
    geom = Geometry()
    wire = geom.add_circle(origin, a, dx, make_surface=True)
    geom.add_physical(wire.plane_surface, 'wire')
    insulation = geom.add_circle(origin, b, dx, holes=[wire.line_loop])
    geom.add_physical(insulation.plane_surface, 'insulation')
    geom.add_physical(insulation.line_loop.lines, 'convection')

    return from_meshio(generate_mesh(geom, dim=2))
Ejemplo n.º 5
0
def make_mesh(
        halfheight: float,  # mm
        length: float,
        thickness: float) -> MeshTri:
    geom = Geometry()
    points = []
    lines = []

    lcar = halfheight / 2**2

    for xy in [(0., halfheight), (0., -halfheight), (length, -halfheight),
               (length, halfheight), (0., -halfheight - thickness),
               (length, -halfheight - thickness)]:
        points.append(geom.add_point([*xy, 0.], lcar))

    lines.append(geom.add_line(*points[:2]))
    geom.add_physical(lines[-1], 'fluid-inlet')

    lines.append(geom.add_line(*points[1:3]))

    lines.append(geom.add_line(*points[2:4]))
    geom.add_physical(lines[-1], 'fluid-outlet')

    lines.append(geom.add_line(points[3], points[0]))

    geom.add_physical(geom.add_plane_surface(geom.add_line_loop(lines)),
                      'fluid')

    lines.append(geom.add_line(points[1], points[4]))
    geom.add_physical(lines[-1], 'solid-inlet')

    lines.append(geom.add_line(*points[4:6]))
    geom.add_physical(lines[-1], 'heated')

    lines.append(geom.add_line(points[5], points[2]))
    geom.add_physical(lines[-1], 'solid-outlet')

    geom.add_physical(
        geom.add_plane_surface(geom.add_line_loop([*lines[-3:], -lines[1]])),
        'solid')

    return from_meshio(generate_mesh(geom, dim=2))
Ejemplo n.º 6
0
polynomial solution with circular stream-lines:

.. math::
    \psi = \left(1 - (x^2+y^2)/a^2\right)^2 / 64.

"""
from skfem import *
from skfem.io import from_meshio
from skfem.models.poisson import unit_load

import numpy as np

from pygmsh import generate_mesh
from pygmsh.built_in import Geometry

geom = Geometry()
circle = geom.add_circle([0.] * 3, 1., .5**3)
geom.add_physical(circle.line_loop.lines, 'perimeter')
geom.add_physical(circle.plane_surface, 'disk')
mesh = from_meshio(generate_mesh(geom, dim=2))

element = ElementTriMorley()
mapping = MappingAffine(mesh)
ib = InteriorBasis(mesh, element, mapping, 2)


@BilinearForm
def biharmonic(u, v, w):
    from skfem.helpers import ddot, dd

    return ddot(dd(u), dd(v))
Ejemplo n.º 7
0
    lame_parameters, linear_stress
from skfem.models.helpers import dot, ddot,\
    prod, sym_grad
import numpy as np
from skfem.io import from_meshio
from skfem.io.json import from_file, to_file
from pathlib import Path

# create meshes
mesh_file = Path(__file__).with_name("ex04_mesh.json")
try:
    m = from_file(mesh_file)
except FileNotFoundError:
    from pygmsh import generate_mesh
    from pygmsh.built_in import Geometry
    geom = Geometry()
    points = []
    lines = []
    points.append(geom.add_point([0., 0., 0.], .1))
    points.append(geom.add_point([0., 1., 0.], .1))
    points.append(geom.add_point([0., -1., 0.], .1))
    lines.append(geom.add_circle_arc(points[2], points[0], points[1]))
    geom.add_physical(lines[-1], 'contact')
    lines.append(geom.add_line(points[1], points[2]))
    geom.add_physical(lines[-1], 'dirichlet')
    geom.add_physical(geom.add_plane_surface(geom.add_line_loop(lines)),
                      'domain')
    m = from_meshio(generate_mesh(geom, dim=2))
    to_file(m, mesh_file)

M = MeshLine(np.linspace(0, 1, 6)) * MeshLine(np.linspace(-1, 1, 10))
Ejemplo n.º 8
0
problem, the maximum of the solution (normalized by the area) is the
'Boussinesq k'-factor'; by symmetry, this occurs for squares (k' ≐
0.07363) and circles (k' = 1/π/4) at the centre and so can be
evaluated by interpolation.

"""

from skfem import *
from skfem.models.poisson import laplace, unit_load

import numpy as np

from pygmsh import generate_mesh
from pygmsh.built_in import Geometry

geom = Geometry()
geom.add_physical_surface(geom.add_circle([0.] * 3, 1., .5**3).plane_surface,
                          'disk')
points, cells = generate_mesh(geom)[:2]
m = MeshTri(points[:, :2].T, cells['triangle'].T)

basis = InteriorBasis(m, ElementTriP2())

A = asm(laplace, basis)
b = asm(unit_load, basis)

D = basis.get_dofs().all()
I = basis.complement_dofs(D)

x = 0*b
x[I] = solve(*condense(A, b, I=I))
Ejemplo n.º 9
0
from skfem import *
from skfem.models.poisson import laplace, mass
from skfem.importers import from_meshio

import numpy as np

from pygmsh import generate_mesh
from pygmsh.built_in import Geometry

geom = Geometry()
points = []
lines = []
radii = [1., 2.]
lcar = .1
points.append(geom.add_point([0.] * 3, lcar))  # centre
for x in radii:
    points.append(geom.add_point([x, 0., 0.], lcar))
for y in reversed(radii):
    points.append(geom.add_point([0., y, 0.], lcar))
lines.append(geom.add_line(*points[1:3]))
geom.add_physical(lines[-1], 'ground')
lines.append(geom.add_circle_arc(points[2], points[0], points[3]))
lines.append(geom.add_line(points[3], points[4]))
geom.add_physical(lines[-1], 'positive')
lines.append(geom.add_circle_arc(points[4], points[0], points[1]))
geom.add_physical(geom.add_plane_surface(geom.add_line_loop(lines)), 'domain')

mesh = from_meshio(generate_mesh(geom, dim=2))

elements = ElementTriP2()
basis = InteriorBasis(mesh, elements)
Ejemplo n.º 10
0
        u_j u_{i,j} v_i.

    """
    return sum(np.einsum("j...,ij...->i...", w["wind"], w["wind"].grad) * v)


@skfem.BilinearForm
def port_pressure(u, v, w):
    """v is the P2 velocity test-function, u a P1 pressure"""
    return sum(v * (u * w.n))


radius = 0.05
height = 0.41

geom = Geometry()
cylinder = geom.add_circle([0.2, 0.2, 0.0], radius, lcar=radius / 2)
channel = geom.add_rectangle(
    0.0, 2.2, 0.0, height, 0, holes=[cylinder], lcar=radius / 2
)
geom.add_physical(channel.surface, "domain")
geom.add_physical(channel.lines[1], "outlet")
geom.add_physical(channel.lines[3], "inlet")

mesh = from_meshio(generate_mesh(geom, dim=2))

element = {"u": skfem.ElementVectorH1(skfem.ElementTriP2()), "p": skfem.ElementTriP1()}
basis = {
    **{v: skfem.InteriorBasis(mesh, e, intorder=4) for v, e in element.items()},
    "inlet": skfem.FacetBasis(mesh, element["u"], facets=mesh.boundaries["inlet"]),
}
Ejemplo n.º 11
0
def make_mesh() -> MeshTri:
    # dimensions for RG316 coaxial cable
    inner_conductor_diameter = 0.50e-3
    inner_insulator_diameter = 1.52e-3
    outer_conductor_diameter = 1.98e-3
    outer_insulator_diameter = 2.48e-3

    # characteristic length for mesh generation
    lcar = 0.1e-3

    geom = Geometry()

    inner_conductor = geom.add_circle(
        (0, 0, 0), inner_conductor_diameter/2,
        lcar=lcar)
    geom.add_physical(
        inner_conductor.plane_surface, label='inner_conductor')
    geom.add_physical(
        inner_conductor.line_loop.lines, label='inner_conductor_outer_surface')

    inner_insulator = geom.add_circle(
        (0, 0, 0), inner_insulator_diameter/2,
        lcar=lcar, holes=[inner_conductor.line_loop])
    geom.add_physical(
        inner_insulator.plane_surface, label='inner_insulator')
    geom.add_physical(
        inner_insulator.line_loop.lines, label='outer_conductor_inner_surface')

    outer_conductor = geom.add_circle(
        (0, 0, 0), outer_conductor_diameter/2,
        lcar=lcar, holes=[inner_insulator.line_loop])
    geom.add_physical(
        outer_conductor.plane_surface, label='outer_conductor')
    geom.add_physical(
        outer_conductor.line_loop.lines, label='outer_conductor_outer_surface')

    outer_insulator = geom.add_circle(
        (0, 0, 0), outer_insulator_diameter/2,
        lcar=lcar, holes=[outer_conductor.line_loop])
    geom.add_physical(
        outer_insulator.plane_surface, label='outer_insulator')
    geom.add_physical(
        outer_insulator.line_loop.lines, label='boundary')

    return from_meshio(generate_mesh(geom, dim=2))