Exemplo n.º 1
0
    def test_main(self):

        with h5py.File("Cartesian2d_random.hdf5", "r") as data:

            mat = GMat.Array2d(data["/shape"][...])

            I = data["/cusp/I"][...]
            idx = data["/cusp/idx"][...]
            K = data["/cusp/K"][...]
            G = data["/cusp/G"][...]
            epsy = data["/cusp/epsy"][...]

            mat.setCusp(I, idx, K, G, epsy)

            I = data["/smooth/I"][...]
            idx = data["/smooth/idx"][...]
            K = data["/smooth/K"][...]
            G = data["/smooth/G"][...]
            epsy = data["/smooth/epsy"][...]

            mat.setSmooth(I, idx, K, G, epsy)

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

            mat.setElastic(I, idx, K, G)

            for i in range(20):

                GradU = data[f"/random/{i:d}/GradU"][...]

                Eps = np.einsum("...ijkl,...lk->...ij", mat.I4s(), GradU)
                mat.setStrain(Eps)

                self.assertTrue(
                    np.allclose(mat.Stress(),
                                data[f"/random/{i:d}/Stress"][...]))
                self.assertTrue(
                    np.allclose(mat.Tangent(),
                                data[f"/random/{i:d}/Tangent"][...]))
                self.assertTrue(
                    np.allclose(
                        mat.CurrentYieldLeft(),
                        data[f"/random/{i:d}/CurrentYieldLeft"][...],
                    ))
                self.assertTrue(
                    np.allclose(
                        mat.CurrentYieldRight(),
                        data[f"/random/{i:d}/CurrentYieldRight"][...],
                    ))
                self.assertTrue(
                    np.all(mat.CurrentIndex() ==
                           data[f"/random/{i:d}/CurrentIndex"][...]))
Exemplo n.º 2
0
    def test_Array2d(self):

        K = 12.3
        G = 45.6

        gamma = 0.02
        epsm = 0.12

        Eps = np.array([[epsm, gamma], [gamma, epsm]])

        Sig_elas = np.array([[K * epsm, G * gamma], [G * gamma, K * epsm]])

        Sig_plas = np.array([[K * epsm, 0.0], [0.0, K * epsm]])

        nelem = 3
        nip = 2
        mat = GMat.Array2d([nelem, nip])
        ndim = 2

        I = np.zeros([nelem, nip], dtype="int")
        I[0, :] = 1
        mat.setElastic(I, K, G)

        I = np.zeros([nelem, nip], dtype="int")
        I[1, :] = 1
        mat.setCusp(I, K, G, 0.01 + 0.02 * np.arange(100))

        I = np.zeros([nelem, nip], dtype="int")
        I[2, :] = 1
        mat.setSmooth(I, K, G, 0.01 + 0.02 * np.arange(100))

        eps = np.zeros((nelem, nip, ndim, ndim))
        sig = np.zeros((nelem, nip, ndim, ndim))
        epsp = np.zeros((nelem, nip))

        for e in range(nelem):
            for q in range(nip):
                fac = float((e + 1) * nip + (q + 1))
                eps[e, q, :, :] = fac * Eps
                if e == 0:
                    sig[e, q, :, :] = fac * Sig_elas
                    epsp[e, q] = 0.0
                else:
                    sig[e, q, :, :] = fac * Sig_plas
                    epsp[e, q] = fac * gamma

        mat.setStrain(eps)

        self.assertTrue(np.allclose(mat.Stress(), sig))
        self.assertTrue(np.allclose(mat.Epsp(), epsp))
Exemplo n.º 3
0
    def test_Array2d_refModel(self):

        K = 12.3
        G = 45.6

        gamma = 0.02
        epsm = 0.12

        Eps = np.array([[epsm, gamma], [gamma, epsm]])

        Sig_elas = np.array([[K * epsm, G * gamma], [G * gamma, K * epsm]])

        Sig_plas = np.array([[K * epsm, 0.0], [0.0, K * epsm]])

        nelem = 3
        nip = 2
        mat = GMat.Array2d([nelem, nip])

        I = np.zeros([nelem, nip], dtype="int")
        I[0, :] = 1
        mat.setElastic(I, K, G)

        I = np.zeros([nelem, nip], dtype="int")
        I[1, :] = 1
        mat.setCusp(I, K, G, 0.01 + 0.02 * np.arange(100))

        I = np.zeros([nelem, nip], dtype="int")
        I[2, :] = 1
        mat.setSmooth(I, K, G, 0.01 + 0.02 * np.arange(100))

        for e in range(nelem):
            for q in range(nip):
                fac = float((e + 1) * nip + (q + 1))
                if e == 0:
                    model = mat.refElastic([e, q])
                    model.setStrain(fac * Eps)
                    self.assertTrue(np.allclose(model.Stress(),
                                                fac * Sig_elas))
                elif e == 1:
                    model = mat.refCusp([e, q])
                    model.setStrain(fac * Eps)
                    self.assertTrue(np.allclose(model.Stress(),
                                                fac * Sig_plas))
                    self.assertTrue(np.allclose(model.epsp(), fac * gamma))
                elif e == 2:
                    model = mat.refSmooth([e, q])
                    model.setStrain(fac * Eps)
                    self.assertTrue(np.allclose(model.Stress(),
                                                fac * Sig_plas))
                    self.assertTrue(np.allclose(model.epsp(), fac * gamma))
Exemplo n.º 4
0
# nodal quantities
disp = np.zeros(coor.shape)
fint = np.zeros(coor.shape)
fext = np.zeros(coor.shape)
fres = np.zeros(coor.shape)

# element/material definition
# ---------------------------

# element definition
quad = GooseFEM.Element.Quad4.Quadrature(vector.AsElement(coor))
nip = quad.nip()

# material definition
mat = GMat.Array2d([nelem, nip])

iden = np.zeros(mat.shape(), dtype="int")
iden[elastic, :] = 1
mat.setElastic(iden, 10.0, 1.0)

iden = np.zeros(mat.shape(), dtype="int")
iden[plastic, :] = 1
mat.setElastic(iden, 10.0, 1.0)

# solve
# -----

# strain, stress, tangent
ue = vector.AsElement(disp)
Eps = quad.SymGradN_vector(ue)
Exemplo n.º 5
0
with h5py.File("Cartesian2d_random.hdf5", "w") as data:

    nelem = 1000
    nip = 4
    iden = 3.0 * np.random.random([nelem, nip])
    iden = np.where(iden < 1.0, 0.0, iden)
    iden = np.where((iden >= 1.0) * (iden < 2.0), 1.0, iden)
    iden = np.where(iden >= 2.0, 2.0, iden)
    iden = iden.astype(np.int)

    shape = np.array([nelem, nip], np.int)

    data["/shape"] = shape

    mat = GMat.Array2d(shape)

    I = np.where(iden == 0, 1, 0).astype(np.int)
    n = np.sum(I)
    idx = np.zeros(I.size, np.int)
    idx[np.argwhere(I.ravel() == 1).ravel()] = np.arange(n)
    idx = idx.reshape(I.shape)
    epsy = np.cumsum(np.random.random([n, 500]), 1)
    K = np.ones(n)
    G = np.ones(n)

    data["/cusp/I"] = I
    data["/cusp/idx"] = idx
    data["/cusp/K"] = K
    data["/cusp/G"] = G
    data["/cusp/epsy"] = epsy
Exemplo n.º 6
0
def ComputePerturbation(sigma_star_test):

    # mesh
    # ----

    # define mesh
    mesh = GooseFEM.Mesh.Quad4.FineLayer(13, 13)

    # mesh dimensions
    nelem = mesh.nelem()

    # mesh definitions
    coor = mesh.coor()
    conn = mesh.conn()
    dofs = mesh.dofs()

    # node sets
    nodesLft = mesh.nodesLeftOpenEdge()
    nodesRgt = mesh.nodesRightOpenEdge()
    nodesTop = mesh.nodesTopEdge()
    nodesBot = mesh.nodesBottomEdge()

    # element sets
    plastic = mesh.elementsMiddleLayer()
    elastic = np.setdiff1d(np.arange(nelem), plastic)

    # periodicity and fixed displacements DOFs
    # ----------------------------------------

    dofs[nodesRgt, :] = dofs[nodesLft, :]

    dofs = GooseFEM.Mesh.renumber(dofs)

    iip = np.concatenate(
        (dofs[nodesBot, 0], dofs[nodesBot, 1], dofs[nodesTop,
                                                    0], dofs[nodesTop, 1]))

    # simulation variables
    # --------------------

    # vector definition
    vector = GooseFEM.VectorPartitioned(conn, dofs, iip)

    # allocate system matrix
    K = GooseFEM.MatrixPartitioned(conn, dofs, iip)
    Solver = GooseFEM.MatrixPartitionedSolver()

    # nodal quantities
    disp = np.zeros(coor.shape)
    fint = np.zeros(coor.shape)
    fext = np.zeros(coor.shape)
    fres = np.zeros(coor.shape)

    # element/material definition
    # ---------------------------

    # element definition
    quad = GooseFEM.Element.Quad4.Quadrature(vector.AsElement(coor))
    nip = quad.nip()

    # material definition
    mat = GMat.Array2d([nelem, nip])

    iden = np.zeros(mat.shape(), dtype="int")
    iden[elastic, :] = 1
    mat.setElastic(iden, 10.0, 1.0)

    iden = np.zeros(mat.shape(), dtype="int")
    iden[plastic, :] = 1
    mat.setElastic(iden, 10.0, 1.0)

    # solve
    # -----

    # strain
    ue = vector.AsElement(disp)
    Eps = quad.SymGradN_vector(ue)

    # pre-stress
    trigger = plastic[int(len(plastic) / 2.0)]
    Sigstar = quad.AllocateQtensor(2, 0.0)
    for q in range(nip):
        Sigstar[trigger, q, :, :] = sigma_star_test
        Sigstar[trigger, q, :, :] = sigma_star_test

    # stress & tangent
    mat.setStrain(Eps)
    Sig = mat.Stress() - Sigstar
    C = mat.Tangent()

    # stiffness matrix
    Ke = quad.Int_gradN_dot_tensor4_dot_gradNT_dV(C)
    K.assemble(Ke)

    # residual force
    fe = quad.Int_gradN_dot_tensor2_dV(Sig)
    fint = vector.AssembleNode(fe)
    fext = vector.Copy_p(fint, fext)
    fres = fext - fint

    # solve
    disp = Solver.Solve(K, fres, disp)

    # post-process
    # ------------

    ue = vector.AsElement(disp)
    Eps = quad.SymGradN_vector(ue)

    return (
        GMat.Deviatoric(Eps[trigger, 0]),
        trigger,
        disp,
        coor,
        conn,
        vector,
        quad,
        mat,
    )