Exemplo n.º 1
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
Exemplo n.º 3
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))
Exemplo n.º 4
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))
Exemplo n.º 5
0
.. 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))

Exemplo n.º 6
0
# 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))
M.translate((1.0, 0.0))
M.refine()

# define elements and bases
e1 = ElementTriP2()
e = ElementVectorH1(e1)
Exemplo n.º 7
0
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)
A = asm(laplace, basis)

boundary_dofs = basis.get_dofs(mesh.boundaries)
interior_dofs = basis.complement_dofs(boundary_dofs)
Exemplo n.º 8
0
evaluated by interpolation.

"""

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

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, 'circle')
geom.add_physical(circle.plane_surface, 'disk')
m = from_meshio(generate_mesh(geom, dim=2))

basis = InteriorBasis(m, ElementTriP2())

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

x = solve(*condense(A, b, D=basis.find_dofs()))

area = sum(b)
k = b @ x / area**2
k1, = basis.interpolator(x)(np.zeros((2, 1))) / area

if __name__ == '__main__':
Exemplo n.º 9
0
@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"]),
}
M = skfem.asm(vector_mass, basis["u"])
L = {"u": skfem.asm(vector_laplace, basis["u"]), "p": skfem.asm(laplace, basis["p"])}
B = -skfem.asm(divergence, basis["u"], basis["p"])
P = B.T + skfem.asm(
    port_pressure,
Exemplo n.º 10
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))
Exemplo n.º 11
0
from skfem import *
from skfem.models.poisson import laplace, unit_load
from skfem.importers import from_meshio

import numpy as np

from pygmsh import generate_mesh
from pygmsh.built_in import Geometry

geom = Geometry()
geom.add_physical(geom.add_circle([0.] * 3, 1., .5**3).plane_surface, 'disk')
m = from_meshio(generate_mesh(geom, dim=2))

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))

area = sum(b)
k = b @ x / area**2
k1, = basis.interpolator(x)(np.zeros((2, 1))) / area

if __name__ == '__main__':
    print('area = {:.4f} (exact = {:.4f})'.format(area, np.pi))
    print('k = {:.5f} (exact = 1/8/pi = {:.5f})'.format(k, 1/np.pi/8))