コード例 #1
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))
コード例 #2
0
ファイル: ex35.py プロジェクト: xanderyin/scikit-fem
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))
コード例 #3
0
    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
コード例 #4
0
ファイル: ex20.py プロジェクト: ahojukka5/scikit-fem
.. 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))
コード例 #5
0
ファイル: ex12.py プロジェクト: zhucer2003/scikit-fem
'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))
コード例 #6
0
    """
    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"]),
}
M = skfem.asm(vector_mass, basis["u"])
コード例 #7
0
ファイル: ex12.py プロジェクト: ForeverDavid/scikit-fem
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)
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))