pyyeti.nastran.n2p.addgrid

pyyeti.nastran.n2p.addgrid(uset, gid, nasset, coordin, xyz, coordout, coordref=None)[source]

Add a grid or grids to a USET table.

Parameters:
  • uset (pandas DataFrame or None) – None or a DataFrame as output by pyyeti.nastran.op2.OP2.rdn2cop2(). If a DataFrame, this routine will use pandas.concat() to return a new, expanded DataFrame that includes the new grids.

  • gid (integer or list_like of integers) – Grid id(s), all must be unique.

  • nasset (string or list_like of strings; lower case) – The set(s) to put the grid in (eg “m”); each string must either be one of these letters: m, s, o, q, r, c, b, e, or it can be a 6-character string of set letters, one for each dof.

    The sets (and supersets) currently accounted for are:

    Sets              Supersets
    
     m  -------------------------------------\
     s  ------------------------------\       > g --\
     o  -----------------------\       > n --/       \
     q  ----------------\       > f --/       \       \
     r  ---------\       > a --/       \       \       > p
     c  --\       > t --/       \       > fe    > ne  /
     b  ---> l --/               > d   /       /     /
     e  ------------------------/-----/-------/-----/
    

    See mkusetmask() for more information on sets.

  • coordin (integer or 4x3 matrix; or list_like of those items) – If integer(s), specifies id(s) of the input coordinate system which is defined in uset (or coordref). If a 4x3 matrix(es), defines the input coordinate system (see below). Note: ID 0 is the basic coordinate system and is always available.

  • xyz (1d or 2d array_like) –

    Each row defines grid location(s) in coordin coordinates:

    rectangular:  [X, Y, Z]
    cylindrical:  [R, Theta, Z]
    spherical:    [R, Theta, Phi]
    - angles are specified in degrees
    
  • coordout (integer or 4x3 matrix) – Same format as coordin. Defines the output coordinate system of the grid (see description below for more information).

  • coordref (dictionary or None; optional) – If None, this input is ignored. Otherwise, it is a read/write dictionary (which can be empty) with the keys being the coordinate system id and the values being the 5x3 matrix:

    [cid  type 0]  # output coord. sys. id and type
    [xo   yo  zo]  # origin of coord. system
    [     T     ]  # 3x3 transformation to basic
    Note that T is for the coordinate system, not a grid
    (unless type = 1 which means rectangular)
    

    For example, to create a coordref with coordinate system 104, you can do this:

    coordref = {}
    addgrid(None, 1, "b", 0, [0, 0, 0], crd104, coordref)
    
Returns:

uset (pandas DataFrame) – Updated version of the input uset. Order of grids is as input.

Notes

When defining multiple grid entries, it is most efficient to use the list_like inputs as opposed to calling addgrid() for each grid. When using the list_like inputs, each entry must be compatible (singleton items are compatible with list_like items).

This routine updates the coordref dictionary (if it is a dictionary) for future reference.

To define a coordinate system, coordin or coordout must be 4x3 size matrices containing the same information that would be on a CORD2R, CORD2C, or CORD2S entry:

[ cid type reference_id ]
[ Ax   Ay   Az          ]
[ Bx   By   Bz          ]
[ Cx   Cy   Cz          ]

where ‘cid’ is the id of the new coordinate system (must be unique), ‘type’ is defined as:

1 - rectangular
2 - cylindrical
3 - spherical

and the locations of A, B, and C are given in the coordinate system indicated by ‘reference_id’.

In the demo below, a single call to this routine is used both for simplicity and efficiency. The other way to do this is to call this routine for each node; in that case, the uset DataFrame is expanded each call (meaning a new DataFrame is created for every successive node). For example, the less efficient method is this:

uset = None
uset = nastran.addgrid(uset, 100, 'b', 0, [5, 10, 15], 0)
uset = nastran.addgrid(uset, 200, 'b', cylcoord,
                       [32, 90, 10], cylcoord)

And the more efficient method (as done below) is this:

uset = nastran.addgrid(
    None, [100, 200], 'b', [0, cylcoord],
    [[5, 10, 15], [32, 90, 10]], [0, cylcoord])
Raises:

ValueError – If the grid id gid is already in uset or if a referenced coordinate system is not found in uset or coordref.

Examples

>>> import numpy as np
>>> import pandas as pd
>>> from pyyeti import nastran
>>> # node 100 in basic is @ [5, 10, 15]
>>> # node 200 in cylindrical coordinate system is @
>>> # [r, th, z] = [32, 90, 10]
>>> cylcoord = np.array([[1, 2, 0], [0, 0, 0], [1, 0, 0],
...                     [0, 1, 0]])
>>> uset = nastran.addgrid(
...     None, [100, 200], 'b', [0, cylcoord],
...     [[5, 10, 15], [32, 90, 10]], [0, cylcoord])
>>> pd.options.display.float_format = lambda x: f'{x:.1f}'
>>> uset
          nasset    x    y    z
id  dof...
100 1    2097154  5.0 10.0 15.0
    2    2097154  0.0  1.0  0.0
    3    2097154  0.0  0.0  0.0
    4    2097154  1.0  0.0  0.0
    5    2097154  0.0  1.0  0.0
    6    2097154  0.0  0.0  1.0
200 1    2097154 10.0  0.0 32.0
    2    2097154  1.0  2.0  0.0
    3    2097154  0.0  0.0  0.0
    4    2097154  0.0  0.0  1.0
    5    2097154  1.0  0.0  0.0
    6    2097154  0.0  1.0  0.0
>>> pd.options.display.float_format = None