def test_historic(self):
        """
        A simple historic run.
        Thanks to prrng this test can be run on any platform, but also from any API (Python or C++).
        """

        # Define a geometry

        N = 3**2
        h = np.pi
        L = h * float(N)

        mesh = GooseFEM.Mesh.Quad4.Regular(N, 11, h)

        coor = mesh.coor()
        conn = mesh.conn()
        dofs = mesh.dofs()
        elem = mesh.elementgrid()

        height = [1.5 * h, 3.5 * h, 5.5 * h, 7.5 * h, 9.5 * h]
        active = [[False, False], [False, False], [True, False], [False, False], [True, False]]
        layers = [
            elem[:3, :].ravel(),
            elem[3, :].ravel(),
            elem[4:7, :].ravel(),
            elem[7, :].ravel(),
            elem[8:, :].ravel(),
        ]
        layers = [np.sort(i) for i in layers]
        is_plastic = [False, True, False, True, False]

        left = mesh.nodesLeftOpenEdge()
        right = mesh.nodesRightOpenEdge()
        dofs[left] = dofs[right]

        mesh.nodesTopEdge()
        mesh.nodesBottomEdge()

        nelas = sum(i.size for i, p in zip(layers, is_plastic) if not p)
        nplas = sum(i.size for i, p in zip(layers, is_plastic) if p)

        c = 1.0
        G = 1.0
        K = 10.0 * G
        rho = G / c**2.0
        qL = 2.0 * np.pi / L
        qh = 2.0 * np.pi / h
        alpha = np.sqrt(2.0) * qL * c * rho
        dt = 1.0 / (c * qh) / 10.0

        generators = prrng.pcg32_array(np.arange(nplas), np.zeros(nplas))
        epsy = np.hstack((generators.random([1]), generators.weibull([1000], k=2.0)))
        epsy *= 1.0e-3
        epsy += 1.0e-5
        epsy = np.cumsum(epsy, 1)

        system = FrictionQPotFEM.UniformMultiLayerLeverDrive2d.System(
            coor=coor,
            conn=conn,
            dofs=dofs,
            iip=dofs[mesh.nodesBottomEdge(), :].ravel(),
            elem=layers,
            node=[np.unique(conn[i, :]) for i in layers],
            layer_is_plastic=is_plastic,
            elastic_K=FrictionQPotFEM.moduli_toquad(K * np.ones(nelas)),
            elastic_G=FrictionQPotFEM.moduli_toquad(G * np.ones(nelas)),
            plastic_K=FrictionQPotFEM.moduli_toquad(K * np.ones(nplas)),
            plastic_G=FrictionQPotFEM.moduli_toquad(G * np.ones(nplas)),
            plastic_epsy=FrictionQPotFEM.epsy_initelastic_toquad(epsy),
            dt=dt,
            rho=rho,
            alpha=alpha,
            eta=0,
            drive_is_active=active,
            k_drive=1e-3,
            H=12 * h,
            hi=height,
        )

        # Drive

        system.initEventDriven(0.1, active)

        nstep = 20
        collect_Eps = np.zeros(nstep)
        collect_Sig = np.zeros(nstep)
        collect_Sig_plastic = np.zeros(nstep)
        dV = system.quad.AsTensor(2, system.dV)

        for step in range(nstep):

            if step % 2 == 0:
                system.eventDrivenStep(deps=1e-5, kick=True, iterative=True, yield_element=False)
                ret = system.minimise()
                self.assertTrue(ret == 0)
            else:
                system.eventDrivenStep(deps=1e-5, kick=False, iterative=True, yield_element=False)

            Epsbar = np.average(system.Eps(), weights=dV, axis=(0, 1))
            Sigbar = np.average(system.Sig(), weights=dV, axis=(0, 1))
            collect_Eps[step] = GMat.Epsd(Epsbar)
            collect_Sig[step] = GMat.Sigd(Sigbar)
            collect_Sig_plastic[step] = GMat.Sigd(np.mean(system.plastic.Sig, axis=(0, 1)))

        with h5py.File(os.path.splitext(__file__)[0] + ".h5") as file:
            self.assertTrue(np.allclose(collect_Eps, file["Eps"][...]))
            self.assertTrue(np.allclose(collect_Sig, file["Sig"][...]))
            self.assertTrue(np.allclose(collect_Sig_plastic, file["Sig_plastic"][...]))
            self.assertTrue(np.allclose(system.u, file["u_last"][...]))
    def test_historic(self):
        """
        A simple historic run.
        Thanks to prrng this test can be run on any platform, but also from any API (Python or C++).
        """

        # Define a geometry

        N = 3**2
        h = np.pi
        L = h * float(N)

        mesh = GooseFEM.Mesh.Quad4.FineLayer(N, N, h)

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

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

        left = mesh.nodesLeftOpenEdge()
        right = mesh.nodesRightOpenEdge()
        dofs[left] = dofs[right]

        top = mesh.nodesTopEdge()
        bottom = mesh.nodesBottomEdge()
        iip = np.concatenate((dofs[bottom].ravel(), dofs[top].ravel()))

        c = 1.0
        G = 1.0
        K = 10.0 * G
        rho = G / c**2.0
        qL = 2.0 * np.pi / L
        qh = 2.0 * np.pi / h
        alpha = np.sqrt(2.0) * qL * c * rho
        dt = 1.0 / (c * qh) / 10.0

        generators = prrng.pcg32_array(np.arange(N), np.zeros(N))
        epsy = np.hstack(
            (generators.random([1]), generators.weibull([1000], k=2.0)))
        epsy *= 1.0e-3
        epsy += 1.0e-5
        epsy = np.cumsum(epsy, 1)

        # Initialise system

        system = FrictionQPotFEM.Generic2d.System(
            coor=coor,
            conn=conn,
            dofs=dofs,
            iip=iip,
            elastic_elem=elastic,
            elastic_K=FrictionQPotFEM.moduli_toquad(K * np.ones(elastic.size)),
            elastic_G=FrictionQPotFEM.moduli_toquad(G * np.ones(elastic.size)),
            plastic_elem=plastic,
            plastic_K=FrictionQPotFEM.moduli_toquad(K * np.ones(plastic.size)),
            plastic_G=FrictionQPotFEM.moduli_toquad(G * np.ones(plastic.size)),
            plastic_epsy=FrictionQPotFEM.epsy_initelastic_toquad(epsy),
            dt=dt,
            rho=rho,
            alpha=alpha,
            eta=0,
        )

        # Run

        dF = np.zeros((1001, 2, 2))
        dF[1:, 0, 1] = 0.004 / 1000.0

        collect_Eps = np.zeros(dF.shape[0])
        collect_Sig = np.zeros(dF.shape[0])
        collect_Sig_plastic = np.zeros(dF.shape[0])
        dV = system.quad.AsTensor(2, system.dV)

        for step in range(dF.shape[0]):

            u = system.u

            for i in range(mesh.nnode):
                for j in range(mesh.ndim):
                    for k in range(mesh.ndim):
                        u[i, j] += dF[step, j, k] * (coor[i, k] - coor[0, k])

            system.u = u
            ret = system.minimise(nmargin=5)
            self.assertTrue(ret == 0)

            Epsbar = np.average(system.Eps(), weights=dV, axis=(0, 1))
            Sigbar = np.average(system.Sig(), weights=dV, axis=(0, 1))
            collect_Eps[step] = GMat.Epsd(Epsbar)
            collect_Sig[step] = GMat.Sigd(Sigbar)
            collect_Sig_plastic[step] = GMat.Sigd(
                np.mean(system.plastic.Sig, axis=(0, 1)))

        with h5py.File(os.path.splitext(__file__)[0] + ".h5") as file:
            self.assertTrue(np.allclose(collect_Eps, file["Eps"][...]))
            self.assertTrue(np.allclose(collect_Sig, file["Sig"][...]))
            self.assertTrue(
                np.allclose(collect_Sig_plastic, file["Sig_plastic"][...]))
            self.assertTrue(np.allclose(system.u, file["u_last"][...]))
Beispiel #3
0
import os

import FrictionQPotSpringBlock.Line1d as model
import matplotlib.pyplot as plt
import numpy as np
import prrng
import tqdm

N = 1000

initstate = np.arange(N)
initseq = np.zeros(N)
generators = prrng.pcg32_array(initstate, initseq)

y = 2.0 * generators.random([20000])
y = np.cumsum(y, 1)
y -= 50.0

xdelta = 1e-3

system = model.System(N, y)

system.set_dt(0.1)
system.set_eta(2.0 * np.sqrt(3.0) / 10.0)
system.set_m(1.0)
system.set_mu(1.0)
system.set_k_neighbours(1.0)
system.set_k_frame(1.0 / N)

ninc = 1000
ret = np.empty([2, ninc])