Пример #1
0
    def test_tangent(self):

        shape = [2, 3]
        Eps = np.random.random(shape + [2, 2])
        Eps = tensor.A4_ddot_B2(tensor.Array2d(shape).I4s, Eps)
        mat = GMat.Elastic2d(np.random.random(shape), np.random.random(shape))
        mat.Eps = Eps
        self.assertTrue(np.allclose(tensor.A4_ddot_B2(mat.C, mat.Eps),
                                    mat.Sig))
    G = np.random.random(n)
    mat["Elastic1d"] = {"mat": GMat.Elastic1d(K, G), "is": iden == 2}

    data["/elastic/I"] = I
    data["/elastic/idx"] = idx
    data["/elastic/K"] = K
    data["/elastic/G"] = G
    data["/elastic/epsy"] = epsy

    for m in mat:
        mat[m]["is_tensor2"] = np.zeros(shape + [2, 2], bool)
        mat[m]["is_tensor4"] = np.zeros(shape + [2, 2, 2, 2], bool)
        mat[m]["is_tensor2"] += (mat[m]["is"]).reshape(shape + [1, 1])
        mat[m]["is_tensor4"] += (mat[m]["is"]).reshape(shape + [1, 1, 1, 1])

    I4s = tensor.Array2d(shape).I4s

    for i in range(20):

        GradU = 200 * np.random.random(shape + [2, 2])

        data[f"/random/{i:d}/GradU"] = GradU
        Eps = tensor.A4_ddot_B2(I4s, GradU)

        for m in mat:
            mat[m]["mat"].Eps = Eps[mat[m]["is_tensor2"]].reshape(-1, 2, 2)
            Sig[mat[m]["is_tensor2"]] = mat[m]["mat"].Sig.reshape(-1)
            C[mat[m]["is_tensor4"]] = mat[m]["mat"].C.reshape(-1)
            if m == "Elastic1d":
                continue
            index[mat[m]["is"]] = mat[m]["mat"].i