def test_main(self): with h5py.File('Cartesian3d_random.hdf5', 'r') as data: shape = data['/shape'][...] mat = GMat.Matrix(shape[0], shape[1]) 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['/random/{0:d}/GradU'.format(i)][...] Eps = np.einsum('...ijkl,...lk->...ij', mat.I4s(), GradU) idx = mat.Find(Eps) self.assertTrue( np.allclose(mat.Stress(Eps), data['/random/{0:d}/Stress'.format(i)][...])) self.assertTrue( np.allclose( mat.Tangent(Eps)[1], data['/random/{0:d}/Tangent'.format(i)][...])) self.assertTrue( np.allclose( mat.Epsy(idx), data['/random/{0:d}/CurrentYieldLeft'.format(i)][...])) self.assertTrue( np.allclose( mat.Epsy(idx + 1), data[ '/random/{0:d}/CurrentYieldRight'.format(i)][...])) self.assertTrue( np.all( mat.Find(Eps) == data[ '/random/{0:d}/CurrentIndex'.format(i)][...]))
def test_Array2d(self): K = 12.3 G = 45.6 gamma = 0.02 epsm = 0.12 Eps = np.array([[epsm, gamma, 0.0], [gamma, epsm, 0.0], [0.0, 0.0, epsm]]) Sig_elas = np.array([[3.0 * K * epsm, 2.0 * G * gamma, 0.0], [2.0 * G * gamma, 3.0 * K * epsm, 0.0], [0.0, 0.0, 3.0 * K * epsm]]) Sig_plas = np.array([[3.0 * K * epsm, 0.0, 0.0], [0.0, 3.0 * K * epsm, 0.0], [0.0, 0.0, 3.0 * K * epsm]]) nelem = 3 nip = 2 mat = GMat.Array2d([nelem, nip]) ndim = 3 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))
def test_Elastic(self): K = 12.3 G = 45.6 gamma = 0.02 epsm = 0.12 Eps = np.array([[epsm, gamma, 0.0], [gamma, epsm, 0.0], [0.0, 0.0, epsm]]) Sig = np.array([[3.0 * K * epsm, 2.0 * G * gamma, 0.0], [2.0 * G * gamma, 3.0 * K * epsm, 0.0], [0.0, 0.0, 3.0 * K * epsm]]) self.assertTrue(np.isclose(float(GMat.Epsd(Eps)), gamma)) mat = GMat.Elastic(K, G) mat.setStrain(Eps) self.assertTrue(np.allclose(mat.Stress(), Sig))
def test_Smooth(self): K = 12.3 G = 45.6 gamma = 0.02 epsm = 0.12 Eps = np.array([[epsm, gamma, 0.0], [gamma, epsm, 0.0], [0.0, 0.0, epsm]]) Sig = np.array([[3.0 * K * epsm, 0.0, 0.0], [0.0, 3.0 * K * epsm, 0.0], [0.0, 0.0, 3.0 * K * epsm]]) self.assertTrue(np.isclose(float(GMat.Epsd(Eps)), gamma)) mat = GMat.Smooth(K, G, [0.01, 0.03, 0.10]) mat.setStrain(Eps) self.assertTrue(np.allclose(mat.Stress(), Sig)) self.assertTrue(np.isclose(mat.epsp(), 0.02)) self.assertTrue(mat.currentIndex() == 1)
with h5py.File('Cartesian3d_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