Beispiel #1
0
def test_pickling():
    # some simple checks for pickle
    mesh = MeshQuad()
    elem = ElementQuad1()
    mapping = MappingIsoparametric(mesh, elem)
    basis = CellBasis(mesh, elem, mapping)

    pickled_mesh = pickle.dumps(mesh)
    pickled_elem = pickle.dumps(elem)
    pickled_mapping = pickle.dumps(mapping)
    pickled_basis = pickle.dumps(basis)

    mesh1 = pickle.loads(pickled_mesh)
    elem1 = pickle.loads(pickled_elem)
    mapping1 = pickle.loads(pickled_mapping)
    basis1 = pickle.loads(pickled_basis)

    assert_almost_equal(
        laplace.assemble(basis).toarray(),
        laplace.assemble(basis1).toarray(),
    )
    assert_almost_equal(
        mesh.doflocs,
        mesh1.doflocs,
    )
    assert_almost_equal(
        mapping.J(0, 0, np.array([[.3], [.3]])),
        mapping1.J(0, 0, np.array([[.3], [.3]])),
    )
    assert_almost_equal(
        elem.doflocs,
        elem1.doflocs,
    )
Beispiel #2
0
    def __init__(self, doflocs, t, **kwargs):

        warnings.warn("MeshQuad2 is an experimental feature and "
                      "not governed by the semantic versioning. "
                      "Several features of MeshQuad are still "
                      "missing.")

        if t.shape[0] == 9:
            dofs, ix = np.unique(t[:4], return_inverse=True)
            super(MeshQuad2, self).__init__(
                doflocs[:, dofs],
                np.arange(len(dofs), dtype=np.int)[ix].reshape(t[:4].shape),
                **kwargs)
        else:
            # fallback for refinterp
            super(MeshQuad2, self).__init__(doflocs, t, **kwargs)
        from skfem.element import ElementQuad1, ElementQuad2
        from skfem.assembly import InteriorBasis
        from skfem.mapping import MappingIsoparametric
        self._elem = ElementQuad2()
        self._basis = InteriorBasis(self, self._elem,
                                    MappingIsoparametric(self, ElementQuad1()))
        self._mesh = MeshQuad.from_basis(self._basis)
        if t.shape[0] == 9:
            self._mesh.p = doflocs
            self._mesh.t = t
Beispiel #3
0
 def _mapping(self):
     """Return a default reference mapping for the mesh."""
     from skfem.mapping import MappingAffine, MappingIsoparametric
     if not hasattr(self, '_cached_mapping'):
         if self.affine:
             self._cached_mapping = MappingAffine(self)
         else:
             self._cached_mapping = MappingIsoparametric(
                 self,
                 self.elem(),
                 self.bndelem,
             )
     return self._cached_mapping
Beispiel #4
0
 def mapping(self):
     return MappingIsoparametric(self, ElementQuad1(), ElementLineP1())
Beispiel #5
0
 def _mapping(self):
     from skfem.mapping import MappingIsoparametric
     from skfem.element import ElementQuad1, ElementLineP1
     return MappingIsoparametric(self, ElementQuad1(), ElementLineP1())
Beispiel #6
0
 def _mapping(self):
     from skfem.mapping import MappingIsoparametric
     return MappingIsoparametric(self._mesh, self._elem)