Example #1
0
def test_pickle_surface_fespaces():
    import netgen.meshing as meshing
    import netgen.csg as csg
    geo = csg.CSGeometry()
    bottom = csg.Plane(csg.Pnt(0, 0, 0), csg.Vec(0, 0, 1))
    surface = csg.SplineSurface(bottom)
    pts = [(0, 0, 0), (0, 1, 0), (1, 1, 0), (1, 0, 0)]
    geopts = [surface.AddPoint(*p) for p in pts]
    for p1, p2, bc in [(0, 1, "left"), (1, 2, "top"), (2, 3, "right"),
                       (3, 0, "bottom")]:
        surface.AddSegment(geopts[p1], geopts[p2], bc)
    geo.AddSplineSurface(surface)
    mesh = Mesh(
        geo.GenerateMesh(maxh=0.3,
                         perfstepsend=meshing.MeshingStep.MESHSURFACE))

    spaces = [
        HDivDivSurface(mesh, order=3, dirichlet=[1, 2, 3, 4]),
        FacetSurface(mesh, order=3, dirichlet=[1, 2, 3, 4]),
        HDivSurface(mesh, order=3, dirichlet=[1, 2, 3, 4])
    ]

    for space in spaces:
        with io.BytesIO() as f:
            pickler = pickle.Pickler(f)
            pickler.dump(space)
            data = f.getvalue()

        with io.BytesIO(data) as f:
            unpickler = pickle.Unpickler(f)
            space2 = unpickler.load()

        assert space.ndof == space2.ndof
Example #2
0
def test_SurfaceGetFE(quads=False):
    # 2d surface in 3d tests
    import netgen.meshing as meshing
    import netgen.csg as csg
    geo = csg.CSGeometry()
    bottom = csg.Plane(csg.Pnt(0, 0, 0), csg.Vec(0, 0, 1))
    surface = csg.SplineSurface(bottom)
    pts = [(0, 0, 0), (0, 1, 0), (1, 1, 0), (1, 0, 0)]
    geopts = [surface.AddPoint(*p) for p in pts]
    for p1, p2, bc in [(0, 1, "left"), (1, 2, "top"), (2, 3, "right"),
                       (3, 0, "bottom")]:
        surface.AddSegment(geopts[p1], geopts[p2], bc)
    geo.AddSplineSurface(surface)

    mesh = Mesh(
        geo.GenerateMesh(perfstepsend=meshing.MeshingStep.MESHSURFACE,
                         quad=quads))

    for spacename in surfacespaces.keys():
        if quads and spaces2d[spacename]["quad"]:
            for order in surfacespaces[spacename]["order"]:
                space = FESpace(type=spacename, mesh=mesh, order=order)
                for vb in surfacespaces[spacename]["vorb"]:
                    for el in space.Elements(vb):
                        assert space.GetFE(el).ndof == len(
                            space.GetDofNrs(el)), [spacename, vb, order]
    return