(nnodes, ndof, x, y, z)
return rbm
Convert 2D or 3D coordinates into Rigid body modes.

    For use as near nullspace modes in elasticity AMG solvers.

    Parameters
    ----------
    nnodes : int
        Number of nodes
    ndof :
        Number of dofs per node
    x,y,z : array_like
        Coordinate vectors

    Returns
    -------
    rbm : array
        An array of size (nnodes*ndof) x (1 | 6) containing the 6 rigid
        body modes

    Examples
    --------
    >>> import numpy as np
    >>> from pyamg.util.utils import coord_to_rbm
    >>> a = np.array([0,1,2])
    >>> coord_to_rbm(3,6,a,a,a)
    array([[ 1.,  0.,  0.,  0.,  0., -0.],
           [ 0.,  1.,  0., -0.,  0.,  0.],
           [ 0.,  0.,  1.,  0., -0.,  0.],
           [ 0.,  0.,  0.,  1.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  1.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  1.],
           [ 1.,  0.,  0.,  0.,  1., -1.],
           [ 0.,  1.,  0., -1.,  0.,  1.],
           [ 0.,  0.,  1.,  1., -1.,  0.],
           [ 0.,  0.,  0.,  1.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  1.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  1.],
           [ 1.,  0.,  0.,  0.,  2., -2.],
           [ 0.,  1.,  0., -2.,  0.,  2.],
           [ 0.,  0.,  1.,  2., -2.,  0.],
           [ 0.,  0.,  0.,  1.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  1.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  1.]])
Convert 2D or 3D coordinates into Rigid body modes.
Convert 2D or 3D coordinates into Rigid body modes .
def coord_to_rbm(nnodes, ndof, x, y, z):
    """Convert 2D or 3D coordinates into Rigid body modes.

    For use as near nullspace modes in elasticity AMG solvers.

    Parameters
    ----------
    nnodes : int
        Number of nodes
    ndof :
        Number of dofs per node
    x,y,z : array_like
        Coordinate vectors

    Returns
    -------
    rbm : array
        An array of size (nnodes*ndof) x (1 | 6) containing the 6 rigid
        body modes

    Examples
    --------
    >>> import numpy as np
    >>> from pyamg.util.utils import coord_to_rbm
    >>> a = np.array([0,1,2])
    >>> coord_to_rbm(3,6,a,a,a)
    array([[ 1.,  0.,  0.,  0.,  0., -0.],
           [ 0.,  1.,  0., -0.,  0.,  0.],
           [ 0.,  0.,  1.,  0., -0.,  0.],
           [ 0.,  0.,  0.,  1.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  1.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  1.],
           [ 1.,  0.,  0.,  0.,  1., -1.],
           [ 0.,  1.,  0., -1.,  0.,  1.],
           [ 0.,  0.,  1.,  1., -1.,  0.],
           [ 0.,  0.,  0.,  1.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  1.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  1.],
           [ 1.,  0.,  0.,  0.,  2., -2.],
           [ 0.,  1.,  0., -2.,  0.,  2.],
           [ 0.,  0.,  1.,  2., -2.,  0.],
           [ 0.,  0.,  0.,  1.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  1.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  1.]])

    """
    # check inputs
    if ndof == 1:
        numcols = 1
    elif ndof in (3, 6):
        numcols = 6
    else:
        raise ValueError('coord_to_rbm(...) only supports 1, 3 or 6 PDEs per '
                         'spatial location,i.e. ndof = [1 | 3 | 6]. '
                         f'You have entered {ndof}.')

    if((max(x.shape) != nnodes)
       or (max(y.shape) != nnodes)
       or (max(z.shape) != nnodes)):
        raise ValueError('coord_to_rbm(...) requires coordinate vectors of equal '
                         f'length.  Length must be nnodes = {nnodes}')

    # if( (min(x.shape) != 1) or (min(y.shape) != 1) or (min(z.shape) != 1) ):
    #    raise ValueError("coord_to_rbm(...) requires coordinate vectors that are
    #    (nnodes x 1) or (1 x nnodes).")

    # preallocate rbm
    rbm = np.array(np.zeros((nnodes*ndof, numcols)))

    for node in range(nnodes):  # pylint: disable=too-many-nested-blocks
        dof = node * ndof

        if ndof == 1:
            rbm[node] = 1.0

        if ndof == 6:
            for ii in range(3, 6):  # lower half = [ 0 I ]
                for jj in range(0, 6):
                    if ii == jj:
                        rbm[dof+ii, jj] = 1.0
                    else:
                        rbm[dof+ii, jj] = 0.0

        if ndof in (3, 6):
            for ii in range(0, 3):  # upper left = [ I ]
                for jj in range(0, 3):
                    if ii == jj:
                        rbm[dof+ii, jj] = 1.0
                    else:
                        rbm[dof+ii, jj] = 0.0

            for ii in range(0, 3):  # upper right = [ Q ]
                for jj in range(3, 6):
                    if ii == (jj-3):
                        rbm[dof+ii, jj] = 0.0
                    else:
                        if (ii+jj) == 4:
                            rbm[dof+ii, jj] = z[node]
                        elif (ii+jj) == 5:
                            rbm[dof+ii, jj] = y[node]
                        elif (ii+jj) == 6:
                            rbm[dof+ii, jj] = x[node]
                        else:
                            rbm[dof+ii, jj] = 0.0

            ii = 0
            jj = 5
            rbm[dof+ii, jj] *= -1.0

            ii = 1
            jj = 3
            rbm[dof+ii, jj] *= -1.0

            ii = 2
            jj = 4
            rbm[dof+ii, jj] *= -1.0

    return rbm
def coord_to_rbm ( nnodes , ndof , x , y , z ) : # check inputs if ndof == 1 : numcols = 1 elif ndof in ( 3 , 6 ) : numcols = 6 else : raise ValueError ( 'coord_to_rbm(...) only supports 1, 3 or 6 PDEs per ' 'spatial location,i.e. ndof = [1 | 3 | 6]. ' f'You have entered {ndof}.' ) if ( ( max ( x . shape ) != nnodes ) or ( max ( y . shape ) != nnodes ) or ( max ( z . shape ) != nnodes ) ) : raise ValueError ( 'coord_to_rbm(...) requires coordinate vectors of equal ' f'length.  Length must be nnodes = {nnodes}' ) # if( (min(x.shape) != 1) or (min(y.shape) != 1) or (min(z.shape) != 1) ): #    raise ValueError("coord_to_rbm(...) requires coordinate vectors that are #    (nnodes x 1) or (1 x nnodes).") # preallocate rbm rbm = np . array ( np . zeros ( ( nnodes * ndof , numcols ) ) ) for node in range ( nnodes ) : # pylint: disable=too-many-nested-blocks dof = node * ndof if ndof == 1 : rbm [ node ] = 1.0 if ndof == 6 : for ii in range ( 3 , 6 ) : # lower half = [ 0 I ] for jj in range ( 0 , 6 ) : if ii == jj : rbm [ dof + ii , jj ] = 1.0 else : rbm [ dof + ii , jj ] = 0.0 if ndof in ( 3 , 6 ) : for ii in range ( 0 , 3 ) : # upper left = [ I ] for jj in range ( 0 , 3 ) : if ii == jj : rbm [ dof + ii , jj ] = 1.0 else : rbm [ dof + ii , jj ] = 0.0 for ii in range ( 0 , 3 ) : # upper right = [ Q ] for jj in range ( 3 , 6 ) : if ii == ( jj - 3 ) : rbm [ dof + ii , jj ] = 0.0 else : if ( ii + jj ) == 4 : rbm [ dof + ii , jj ] = z [ node ] elif ( ii + jj ) == 5 : rbm [ dof + ii , jj ] = y [ node ] elif ( ii + jj ) == 6 : rbm [ dof + ii , jj ] = x [ node ] else : rbm [ dof + ii , jj ] = 0.0 ii = 0 jj = 5 rbm [ dof + ii , jj ] *= - 1.0 ii = 1 jj = 3 rbm [ dof + ii , jj ] *= - 1.0 ii = 2 jj = 4 rbm [ dof + ii , jj ] *= - 1.0 return rbm