コード例 #1
0
 def mapping(self):
     return MappingIsoparametric(self, ElementQuad1(), ElementLineP1())
コード例 #2
0
ファイル: mesh_quad.py プロジェクト: zhang9song/scikit-fem
 def mapping(self):
     from skfem.mapping import MappingIsoparametric
     from skfem.element import ElementQuad1, ElementLineP1
     return MappingIsoparametric(self, ElementQuad1(), ElementLineP1())
コード例 #3
0
class TestDerivatives(TestCase):
    """Test values of derivatives."""

    elems = [
        ElementLineP0(),
        ElementLineP1(),
        ElementLineP2(),
        ElementLineMini(),
        ElementTriP0(),
        ElementTriP1(),
        ElementTriP2(),
        ElementTriP3(),
        ElementTriP4(),
        ElementTriMini(),
        ElementQuad0(),
        ElementQuad1(),
        ElementQuad2(),
        ElementQuadS2(),
        ElementTetP0(),
        ElementTetP1(),
        ElementTetP2(),
        ElementTetMini(),
        ElementHex1(),
        ElementHexS2(),
        ElementHex2(),
        ElementTriCR(),
        ElementTriCCR(),
        ElementTetCR(),
        ElementTetCCR(),
        ElementWedge1(),
    ]

    def runTest(self):
        for elem in self.elems:
            eps = 1e-6
            for base in [0., .3, .6, .9]:
                if elem.dim == 1:
                    y = np.array([[base, base + eps]])
                elif elem.dim == 2:
                    y = np.array([[base, base + eps, base, base],
                                  [base, base, base, base + eps]])
                elif elem.dim == 3:
                    y = np.array([[base, base + eps, base, base, base, base],
                                  [base, base, base, base + eps, base, base],
                                  [base, base, base, base, base, base + eps]])
                i = 0
                while True:
                    try:
                        out = elem.lbasis(y, i)
                    except ValueError:
                        break
                    diff = (out[0][1] - out[0][0]) / eps
                    errmsg = 'x-derivative for {}th bfun failed for {}'
                    self.assertAlmostEqual(diff,
                                           out[1][0][0],
                                           delta=1e-3,
                                           msg=errmsg.format(i, elem))
                    if elem.dim > 1:
                        diff = (out[0][3] - out[0][2]) / eps
                        errmsg = 'y-derivative for {}th bfun failed for {}'
                        self.assertAlmostEqual(diff,
                                               out[1][1][3],
                                               delta=1e-3,
                                               msg=errmsg.format(i, elem))
                    if elem.dim == 3:
                        diff = (out[0][5] - out[0][4]) / eps
                        errmsg = 'z-derivative for {}th bfun failed for {}'
                        self.assertAlmostEqual(diff,
                                               out[1][2][4],
                                               delta=1e-3,
                                               msg=errmsg.format(i, elem))
                    i += 1
コード例 #4
0
    element_type = ElementLineP2
    nrefs = 5


class TestIncompatibleMeshElement(TestCase):
    def runTest(self):

        with self.assertRaises(ValueError):
            m = MeshTri()
            e = ElementTetP2()
            basis = InteriorBasis(m, e)


@pytest.mark.parametrize("mtype,e1,e2", [
    (MeshTri, ElementTriP1(), ElementLineP0()),
    (MeshTri, ElementTriP1(), ElementLineP1()),
    (MeshTri, ElementTriP2(), ElementLineP1()),
    (MeshTri, ElementTriP2(), ElementLineP2()),
    (MeshTri, ElementTriP2(), None),
    (MeshQuad, ElementQuad1(), ElementLineP0()),
    (MeshQuad, ElementQuad1(), ElementLineP1()),
    (MeshQuad, ElementQuad2(), ElementLineP2()),
    (MeshTet, ElementTetP1(), ElementTriP0()),
    (MeshTet, ElementTetP2(), ElementTriP2()),
    (MeshHex, ElementHex1(), ElementQuad0()),
    (MeshHex, ElementHex1(), ElementQuad1()),
    (MeshHex, ElementHex2(), ElementQuad2()),
])
def test_trace(mtype, e1, e2):

    m = mtype().refined(3)
コード例 #5
0
ファイル: test_convergence.py プロジェクト: mfkiwl/scikit-fem
 def create_basis(self, m):
     e = ElementLineP1()
     return InteriorBasis(m, e)
コード例 #6
0
        ElementQuad1(),
    ),
    (
        MeshQuad().refined(2),
        MeshQuad1DG,
        ElementQuad2(),
    ),
    (
        MeshTri().refined(2),
        MeshTri1DG,
        ElementTriP2(),
    ),
    (
        MeshLine().refined(5),
        MeshLine1DG,
        ElementLineP1(),
    ),
    (
        MeshHex().refined(3),
        MeshHex1DG,
        ElementHex1(),
    ),
    (
        MeshLine().refined(),
        MeshLine1DG,
        ElementLinePp(5),
    ),
])
def test_periodic_loading(m, mdgtype, e):
    def _sort(ix):
        # sort index arrays so that ix[0] matches