Beispiel #1
0
    def test_d_factor(self):
        nd = differentiate(
            lambda s: self.model.hist_factor(s, self.L, self.T, self.fixed),
            self.strength)
        d = self.model.d_hist_factor(self.strength, self.L, self.T, self.fixed)

        self.assertTrue(np.isclose(nd, d))
 def test_damage_damage(self):
     act = self.model.d_damage_rate_d_damage(self.shear, self.sliprate,
                                             self.normal, self.damage)
     res = differentiate(
         lambda d: self.model.damage_rate(self.shear, self.sliprate, self.
                                          normal, d), self.damage)
     self.assertAlmostEqual(act, res)
Beispiel #3
0
 def test_dshear(self):
   for i in range(self.lattice.ngroup):
     for j in range(self.lattice.nslip(i)):
       rs = lambda S: np.einsum('ij,ij',
             np.dot(self.QM,np.dot(np.outer(self.lattice.slip_directions[i][j].data,
               self.lattice.slip_planes[i][j].data), self.QM.T)), S)
       num = tensors.Symmetric(differentiate(rs, self.S)[0])
    def test_damage_slip(self):
        act = self.model.d_damage_rate_d_slip(self.shear, self.sliprate,
                                              self.normal, self.damage)

        dfn = lambda s: self.model.damage_rate(self.shear, list(s), self.
                                               normal, self.damage)
        res = differentiate(dfn, np.array(self.sliprate))[0]

        self.assertTrue(np.allclose(act, res))
Beispiel #5
0
 def test_d_sslip_d_strength(self):
     for g in range(self.L.ngroup):
         for i in range(self.L.nslip(g)):
             nd = differentiate(
                 lambda s: self.model.scalar_sslip(g, i, self.tau, s, self.T
                                                   ), self.strength)
             d = self.model.scalar_d_sslip_dstrength(
                 g, i, self.tau, self.strength, self.T)
             self.assertTrue(np.isclose(nd, d))
Beispiel #6
0
    def drive(self, model):
        d_n = np.zeros((6, ))
        w_n = np.zeros((3, ))
        s_n = np.zeros((6, ))
        h_n = model.init_store()
        t_n = 0.0
        u_n = 0.0
        p_n = 0.0

        for i in range(self.nsteps):
            t_np1 = t_n + self.dt
            d_np1 = d_n + self.Ddir * self.dt
            w_np1 = w_n + self.Wdir * self.dt

            s_np1, h_np1, A_np1, B_np1, u_np1, p_np1 = model.update_ld_inc(
                d_np1, d_n, w_np1, w_n, self.T, self.T, t_np1, t_n, s_n, h_n,
                u_n, p_n)

            A_num = common.differentiate(
                lambda d: model.
                update_ld_inc(d, d_n, w_np1, w_n, self.T, self.T, t_np1, t_n,
                              s_n, h_n, u_n, p_n)[0], d_np1)

            # This is somewhat iffy
            print(A_np1)
            print(A_num)
            self.assertTrue(np.allclose(A_np1, A_num, rtol=1.0e-3))

            B_num = common.differentiate(
                lambda w: model.
                update_ld_inc(d_np1, d_n, w, w_n, self.T, self.T, t_np1, t_n,
                              s_n, h_n, u_n, p_n)[0], w_np1)

            # Again, why the loose tolerance?
            self.assertTrue(np.allclose(B_np1, B_num, rtol=1.0e-3))

            s_n = np.copy(s_np1)
            h_n = np.copy(h_np1)
            d_n = np.copy(d_np1)
            w_n = np.copy(w_np1)
            t_n = t_np1
            u_n = u_np1
            p_n = p_np1
Beispiel #7
0
    def test_slip_tau(self):
        for g in range(self.L.ngroup):
            for i in range(self.L.nslip(g)):
                rs = self.L.shear(g, i, self.Q, self.S)
                nd = differentiate(
                    lambda t: self.model.sslip(g, i, t, self.strength_values,
                                               self.T), rs)
                d = self.model.d_sslip_dtau(g, i, rs, self.strength_values,
                                            self.T)

                self.assertTrue(np.isclose(d, nd, rtol=1e-4))
Beispiel #8
0
    def test_jacobian(self):
        fn = lambda x: self.model.RJ(x, self.ts)[0]
        Jn = common.differentiate(fn, self.x)

        R, J = self.model.RJ(self.x, self.ts)

        print(J)
        print(Jn)

        print((J - Jn))

        self.assertTrue(np.allclose(J, Jn, rtol=1.0e-4))
Beispiel #9
0
    def test_slip_strength(self):
        for g in range(self.L.ngroup):
            for i in range(self.L.nslip(g)):
                rs = self.L.shear(g, i, self.Q, self.S)

                nd = differentiate(
                    lambda s: self.model.sslip(g, i, rs, s, self.T),
                    np.array(self.strength_values))
                d = self.model.d_sslip_dstrength(g, i, rs,
                                                 self.strength_values, self.T)

                self.assertTrue(np.allclose(nd, d))
 def test_map_normal(self):
     for v in self.vals:
         exact = self.function.d_map_d_normal(v, self.n)
         num = differentiate(lambda x: self.function.map(v, x), self.n)
         self.assertAlmostEqual(exact, num)
 def test_map_damage(self):
     for v in self.vals:
         exact = self.function.d_map_d_damage(v, self.n)
         num = differentiate(lambda x: self.function.map(x, self.n), v)
         self.assertAlmostEqual(exact, num)