Пример #1
0
def make_geom(length: float = 35.,
              lcar: float = 1.) -> 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_line(list(np.array(lines)[k]), label)

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

    return geom
Пример #2
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_surface(wire.plane_surface, 'wire')
    insulation = geom.add_circle(origin, b, dx, holes=[wire.line_loop])
    geom.add_physical_surface(insulation.plane_surface, 'insulation')
    geom.add_physical_line(insulation.line_loop.lines, 'convection')

    return MeshTri.from_meshio(meshio.Mesh(*generate_mesh(geom)))
Пример #3
0
'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))

area = sum(b)
Пример #4
0
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_line(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_line(lines[-1], 'positive')
lines.append(geom.add_circle_arc(points[4], points[0], points[1]))
geom.add_physical_surface(geom.add_plane_surface(geom.add_line_loop(lines)),
                          'domain')

mesh = MeshTri.from_meshio(
    meshio.Mesh(*generate_mesh(geom, prune_vertices=False)))

elements = ElementTriP2()
basis = InteriorBasis(mesh, elements)
A = asm(laplace, basis)

boundary_dofs = basis.get_dofs(mesh.boundaries)
interior_dofs = basis.complement_dofs(boundary_dofs)

u = np.zeros(basis.N)
u[boundary_dofs['positive'].all()] = 1.
u[interior_dofs] = solve(*condense(A, 0. * u, u, interior_dofs))
Пример #5
0
from skfem import *

import numpy as np

import meshio
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_line(circle.line_loop.lines, 'perimeter')
geom.add_physical_surface(circle.plane_surface, 'disk')
mesh = MeshTri.from_meshio(meshio.Mesh(*generate_mesh(geom)))

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

@bilinear_form
def biharmonic(u, du, ddu, v, dv, ddv, w):

    def shear(ddw):
        return np.array([[ddw[0][0], ddw[0][1]],
                         [ddw[1][0], ddw[1][1]]])

    def ddot(T1, T2):
        return T1[0, 0]*T2[0, 0] +\
               T1[0, 1]*T2[0, 1] +\
               T1[1, 0]*T2[1, 0] +\
               T1[1, 1]*T2[1, 1]