예제 #1
0
    def test_transform_data(self):
        import numpy as nm
        from sfepy.mechanics.tensors import transform_data

        ok = True

        coors = nm.eye(3)

        data = nm.eye(3)
        expected = nm.zeros((3, 3))
        expected[[0, 1, 2], [0, 0, 2]] = 1.0

        out = transform_data(data, coors)

        _ok = nm.allclose(out, expected, rtol=0.0, atol=1e-14)
        self.report('vectors in cylindrical coordinates: %s' % _ok)
        ok = ok and _ok

        data = nm.zeros((3, 6))
        data[:, :3] = [[1, 2, 3]]
        expected = data.copy()
        expected[1, [0, 1]] = expected[1, [1, 0]]

        out = transform_data(data, coors)

        _ok = nm.allclose(out, expected, rtol=0.0, atol=1e-14)
        self.report('sym. tensors in cylindrical coordinates: %s' % _ok)
        ok = ok and _ok

        return ok
예제 #2
0
    def test_transform_data(self):
        import numpy as nm
        from sfepy.mechanics.tensors import transform_data

        ok = True

        coors = nm.eye(3)

        data = nm.eye(3)
        expected = nm.zeros((3, 3))
        expected[[0, 1, 2], [0, 0, 2]] = 1.0

        out = transform_data(data, coors)

        _ok = nm.allclose(out, expected, rtol=0.0, atol=1e-14)
        self.report('vectors in cylindrical coordinates: %s' % _ok)
        ok = ok and _ok

        data = nm.zeros((3, 6))
        data[:, :3] = [[1, 2, 3]]
        expected = data.copy()
        expected[1, [0, 1]] = expected[1, [1, 0]]

        out = transform_data(data, coors)

        _ok = nm.allclose(out, expected, rtol=0.0, atol=1e-14)
        self.report('sym. tensors in cylindrical coordinates: %s' % _ok)
        ok = ok and _ok

        return ok
예제 #3
0
    def test_transform_data4(self):
        import numpy as nm
        import sfepy.mechanics.tensors as tn

        ok = True

        if not hasattr(nm, 'einsum'):
            self.report('no numpy.einsum(), skipping!')
            return ok

        expected = nm.zeros((6, 6), dtype=nm.float64)
        expected[0, 0] = expected[1, 1] = 1.0

        phi = nm.deg2rad(30.)
        dr, v1, v2, om1, om2 = get_ortho_d(phi, phi + nm.deg2rad(90.))

        # Rotate coordinate system by phi.
        mtx = tn.make_axis_rotation_matrix([0., 0., 1.], phi)
        do = tn.transform_data(dr[None, ...], mtx=mtx[None, ...])

        _ok = nm.allclose(do, expected, rtol=0.0, atol=1e-14)
        self.report('sym. 4th-th order tensor rotation: %s' % _ok)
        ok = ok and _ok

        dt, vt1, vt2, omt1, omt2 = get_ortho_d(0, nm.deg2rad(90.))

        expected1 = nm.zeros((3, 3), dtype=nm.float64)
        expected1[0, 0] = 1.0

        expected2 = nm.zeros((3, 3), dtype=nm.float64)
        expected2[1, 1] = 1.0

        omr1 = nm.einsum('pq,ip,jq->ij', om1, mtx, mtx)
        omr2 = nm.einsum('pq,ip,jq->ij', om2, mtx, mtx)

        ii = tn.get_sym_indices(3)
        jj = tn.get_full_indices(3)

        o1 = om1.flat[ii]
        o2 = om2.flat[ii]

        omr12 = tn.transform_data(o1[None,...], mtx=mtx[None, ...])[0, jj]
        omr22 = tn.transform_data(o2[None,...], mtx=mtx[None, ...])[0, jj]

        _ok1 = nm.allclose(omr1, expected1, rtol=0.0, atol=1e-14)
        _ok2 = nm.allclose(omr12, expected1, rtol=0.0, atol=1e-14)
        self.report('einsum-transform_data compatibility 1: %s %s'
                    % (_ok1, _ok2))
        ok = ok and _ok1 and _ok2

        _ok1 = nm.allclose(omr2, expected2, rtol=0.0, atol=1e-14)
        _ok2 = nm.allclose(omr22, expected2, rtol=0.0, atol=1e-14)
        self.report('einsum-transform_data compatibility 2: %s %s'
                    % (_ok1, _ok2))
        ok = ok and _ok1 and _ok2

        return ok
예제 #4
0
    def test_transform_data4(self):
        import numpy as nm
        import sfepy.mechanics.tensors as tn

        ok = True

        if not hasattr(nm, 'einsum'):
            self.report('no numpy.einsum(), skipping!')
            return ok

        expected = nm.zeros((6, 6), dtype=nm.float64)
        expected[0, 0] = expected[1, 1] = 1.0

        phi = nm.deg2rad(30.)
        dr, v1, v2, om1, om2 = get_ortho_d(phi, phi + nm.deg2rad(90.))

        # Rotate coordinate system by phi.
        mtx = tn.make_axis_rotation_matrix([0., 0., 1.], phi)
        do = tn.transform_data(dr[None, ...], mtx=mtx[None, ...])

        _ok = nm.allclose(do, expected, rtol=0.0, atol=1e-14)
        self.report('sym. 4th-th order tensor rotation: %s' % _ok)
        ok = ok and _ok

        dt, vt1, vt2, omt1, omt2 = get_ortho_d(0, nm.deg2rad(90.))

        expected1 = nm.zeros((3, 3), dtype=nm.float64)
        expected1[0, 0] = 1.0

        expected2 = nm.zeros((3, 3), dtype=nm.float64)
        expected2[1, 1] = 1.0

        omr1 = nm.einsum('pq,ip,jq->ij', om1, mtx, mtx)
        omr2 = nm.einsum('pq,ip,jq->ij', om2, mtx, mtx)

        ii = tn.get_sym_indices(3)
        jj = tn.get_full_indices(3)

        o1 = om1.flat[ii]
        o2 = om2.flat[ii]

        omr12 = tn.transform_data(o1[None,...], mtx=mtx[None, ...])[0, jj]
        omr22 = tn.transform_data(o2[None,...], mtx=mtx[None, ...])[0, jj]

        _ok1 = nm.allclose(omr1, expected1, rtol=0.0, atol=1e-14)
        _ok2 = nm.allclose(omr12, expected1, rtol=0.0, atol=1e-14)
        self.report('einsum-transform_data compatibility 1: %s %s'
                    % (_ok1, _ok2))
        ok = ok and _ok1 and _ok2

        _ok1 = nm.allclose(omr2, expected2, rtol=0.0, atol=1e-14)
        _ok2 = nm.allclose(omr22, expected2, rtol=0.0, atol=1e-14)
        self.report('einsum-transform_data compatibility 2: %s %s'
                    % (_ok1, _ok2))
        ok = ok and _ok1 and _ok2

        return ok
def make_mesh(dims, shape, transform=None):
    """
    Generate a 2D rectangle mesh in 3D space, and optionally apply a coordinate
    transform.
    """
    _mesh = gen_block_mesh(dims, shape, [0, 0], name='shell10x', verbose=False)

    coors = nm.c_[_mesh.coors, nm.zeros(_mesh.n_nod, dtype=nm.float64)]
    coors = nm.ascontiguousarray(coors)

    conns = [_mesh.get_conn(_mesh.descs[0])]

    mesh = Mesh.from_data(_mesh.name, coors, _mesh.cmesh.vertex_groups, conns,
                          [_mesh.cmesh.cell_groups], _mesh.descs)

    if transform == 'bend':
        bbox = mesh.get_bounding_box()
        x0, x1 = bbox[:, 0]

        angles = 0.5 *  nm.pi * (coors[:, 0] - x0) / (x1 - x0)
        mtx = make_axis_rotation_matrix([0, -1, 0], angles[:, None, None])

        coors = mesh.coors.copy()
        coors[:, 0] = 0
        coors[:, 2] = (x1 - x0)

        mesh.coors[:] = transform_data(coors, mtx=mtx)
        mesh.coors[:, 0] -= 0.5 * (x1 - x0)

    elif transform == 'twist':
        bbox = mesh.get_bounding_box()
        x0, x1 = bbox[:, 0]

        angles = 0.5 *  nm.pi * (coors[:, 0] - x0) / (x1 - x0)
        mtx = make_axis_rotation_matrix([-1, 0, 0], angles[:, None, None])

        mesh.coors[:] = transform_data(mesh.coors, mtx=mtx)

    return mesh
def make_mesh(dims, shape, transform=None):
    """
    Generate a 2D rectangle mesh in 3D space, and optionally apply a coordinate
    transform.
    """
    _mesh = gen_block_mesh(dims, shape, [0, 0], name='shell10x', verbose=False)

    coors = nm.c_[_mesh.coors, nm.zeros(_mesh.n_nod, dtype=nm.float64)]
    coors = nm.ascontiguousarray(coors)

    conns = [_mesh.get_conn(_mesh.descs[0])]

    mesh = Mesh.from_data(_mesh.name, coors, _mesh.cmesh.vertex_groups, conns,
                          [_mesh.cmesh.cell_groups], _mesh.descs)

    if transform == 'bend':
        bbox = mesh.get_bounding_box()
        x0, x1 = bbox[:, 0]

        angles = 0.5 *  nm.pi * (coors[:, 0] - x0) / (x1 - x0)
        mtx = make_axis_rotation_matrix([0, -1, 0], angles[:, None, None])

        coors = mesh.coors.copy()
        coors[:, 0] = 0
        coors[:, 2] = (x1 - x0)

        mesh.coors[:] = transform_data(coors, mtx=mtx)
        mesh.coors[:, 0] -= 0.5 * (x1 - x0)

    elif transform == 'twist':
        bbox = mesh.get_bounding_box()
        x0, x1 = bbox[:, 0]

        angles = 0.5 *  nm.pi * (coors[:, 0] - x0) / (x1 - x0)
        mtx = make_axis_rotation_matrix([-1, 0, 0], angles[:, None, None])

        mesh.coors[:] = transform_data(mesh.coors, mtx=mtx)

    return mesh
예제 #7
0
    def eval_function(out, a1, a2, h0, mtx_c, c33, mtx_b, mtx_t, geo,
                      term_mode, fmode):

        if term_mode == 'strain':
            out_qp = membranes.get_green_strain_sym3d(mtx_c, c33)

        elif term_mode == 'stress':
            n_el, n_qp, dm, _ = mtx_c.shape
            dim = dm + 1
            sym = dim2sym(dim)
            out_qp = nm.zeros((n_el, n_qp, sym, 1), dtype=mtx_c.dtype)

            stress = eval_membrane_mooney_rivlin(a1, a2, mtx_c, c33, 0)
            out_qp[..., 0:2, 0] = stress[..., 0:2, 0]
            out_qp[..., 3, 0] = stress[..., 2, 0]

        status = geo.integrate(out, out_qp, fmode)
        out[:, 0, :, 0] = transform_data(out.squeeze(), mtx=mtx_t)

        return status
예제 #8
0
    def eval_function(out, a1, a2, h0, mtx_c, c33, mtx_b, mtx_t, geo,
                      term_mode, fmode):

        if term_mode == 'strain':
            out_qp = membranes.get_green_strain_sym3d(mtx_c, c33)

        elif term_mode == 'stress':
            n_el, n_qp, dm, _ = mtx_c.shape
            dim = dm + 1
            sym = dim2sym(dim)
            out_qp = nm.zeros((n_el, n_qp, sym, 1), dtype=mtx_c.dtype)

            stress = eval_membrane_mooney_rivlin(a1, a2, mtx_c, c33, 0)
            out_qp[..., 0:2, 0] = stress[..., 0:2, 0]
            out_qp[..., 3, 0] = stress[..., 2, 0]

        status = geo.integrate(out, out_qp, fmode)
        out[:, 0, :, 0] = transform_data(out.squeeze(), mtx=mtx_t)

        return status