def test_Array2d(self):

        K = 12.3
        G = 45.6

        gamma = 0.02

        F = np.array([
                [1.0 + gamma, 0.0, 0.0],
                [0.0, 1.0 / (1.0 + gamma), 0.0],
                [0.0, 0.0, 1.0]])

        Sig = np.array([
            [G * 2.0 * np.log(1.0 + gamma), 0.0, 0.0],
            [0.0, - G * 2.0 * np.log(1.0 + gamma), 0.0],
            [0.0, 0.0, 0.0]])

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

        I = np.ones([nelem, nip], dtype='int')
        mat.setElastic(I, K, G)

        f = np.zeros((nelem, nip, ndim, ndim))
        sig = np.zeros((nelem, nip, ndim, ndim))

        for e in range(nelem):
            for q in range(nip):
                f[e, q, :, :] = F
                sig[e, q, :, :] = Sig

        mat.setDefGrad(f)

        self.assertTrue(np.allclose(mat.Stress(), sig))
import GMatElastoPlasticFiniteStrainSimo.Cartesian3d as GMat

with h5py.File('Cartesian3d_random.hdf5', 'w') as data:

    nelem = 1000
    nip = 4
    iden = 2.0 * np.random.random([nelem, nip])
    iden = np.where(iden < 1.0, 0.0, iden)
    iden = np.where(iden >= 1.0, 1.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)
    K = np.ones(n)
    G = np.ones(n)
    tauy0 = 0.1 * np.ones(n)
    H = np.ones(n)

    data['/LinearHardening/I'] = I
    data['/LinearHardening/idx'] = idx
    data['/LinearHardening/K'] = K
    data['/LinearHardening/G'] = G
phase[1, 0, 0] = 1.
# function to convert material parameters to grid of scalars
param  = lambda M0,M1: M0*np.ones([Nx,Ny,Nz])*(1.-phase)+\
                       M1*np.ones([Nx,Ny,Nz])*    phase
# material parameters
K = param(0.833, 0.833)  # bulk      modulus
mu = param(0.386, 0.386)  # shear     modulus
H = param(0.004, 0.008)  # hardening modulus
tauy0 = param(1000., 0.003)  # initial yield stress

# --------------------------------------- C++ IMPLEMENTATION ---------------------------------------

Isoft = (1. - phase).astype(np.uint).reshape(2, 1)
Ihard = (phase).astype(np.uint).reshape(2, 1)

mat = GMat.Array2d([2, 1])
mat.setElastic(Isoft, K[0, 0, 0], mu[0, 0, 0])
mat.setLinearHardening(Ihard, K[1, 0, 0], mu[1, 0, 0], tauy0[1, 0, 0], H[1, 0,
                                                                         0])

# -------------------------------------------- LOADING ---------------------------------------------

# stress, deformation gradient, plastic strain, elastic Finger tensor
# NB "_t" signifies that it concerns the value at the previous increment
ep_t = np.zeros([Nx, Ny, Nz])
P = np.zeros([3, 3, Nx, Ny, Nz])
F = np.array(I, copy=True)
F_t = np.array(I, copy=True)
be_t = np.array(I, copy=True)

# initialize macroscopic incremental loading