pyyeti.nastran.bulk.wtdmig¶
- pyyeti.nastran.bulk.wtdmig(f, dct)[source]¶
Writes Nastran DMIG cards to a file.
- Parameters:
f (string or file_like or 1 or None) – Either a name of a file, or is a file_like object as returned by
open()orio.StringIO. Input as integer 1 to write to stdout. Can also be the name of a directory or None; in these cases, a GUI is opened for file selection.dct (dictionary) – Dictionary of pandas DataFrames. The keys will be used as the names of the DMIG entries. With one exception, the column and row indices of each DataFrame are pandas MultiIndex objects with node ID in level 0 and DOF in level 1 (the names are “id” and “dof”). The exception is for form “9” matrices: the column index in that case is just the column number (starting at one for Nastran). Use an OrderedDict from the standard Python “collections” module to write the entries in a specific order.
- Returns:
None
Notes
If a DataFrame has a single level ‘columns’ attribute, the form for that matrix is 9. In that case, the ‘NCOL’ DMIG header card value is determined by maximum value in the ‘columns’ attribute.
Otherwise, if a DataFrame has a 2-level ‘columns’ attribute, the form is determined by checking the matrix shape and, if square, whether the matrix is symmetric or not. ‘NCOL’ is set to the number of columns in the matrix (but is ignored by Nastran).
The type is determined by the numpy ‘dtype’ attribute.
Currently, both ‘POLAR’ and ‘TOUT’ header card values are set to 0. That means that complex numbers are written in real/imaginary parts and the resulting precision in Nastran is automatically set.
- Raises:
ValueError – When a DataFrame row index is not 2 levels, or when a column index is not 1 or 2 levels.
Examples
Create a symmetric matrix and write DMIG to screen:
>>> import numpy as np >>> import pandas as pd >>> from pyyeti import nastran >>> a = np.array([[3.5, -1.2, -2.4], ... [-1.2, 8.8, 6.5], ... [-2.4, 6.5, 9.9]]) >>> ind = pd.MultiIndex.from_product([[100], [1, 2, 6]]) >>> k = pd.DataFrame(a, index=ind, columns=ind) >>> k 100... 1 2 6 100 1 3.5 -1.2 -2.4 2 -1.2 8.8 6.5 6 -2.4 6.5 9.9 >>> nastran.wtdmig(1, {'k': k}) DMIG K 0 6 2 0 0 3 DMIG* K 100 1 * 100 1 3.500000000D+00 * 100 2-1.200000000D+00 * 100 6-2.400000000D+00 DMIG* K 100 2 * 100 2 8.800000000D+00 * 100 6 6.500000000D+00 DMIG* K 100 6 * 100 6 9.900000000D+00
As another demo, write to a string and use
rddmig()to read back in:>>> import io >>> with io.StringIO() as sio: ... nastran.wtdmig(sio, {'k': k}) ... k2 = nastran.rddmig(sio)['k'] >>> k2 id 100... dof 1 2 6 id dof... 100 1 3.5 -1.2 -2.4 2 -1.2 8.8 6.5 6 -2.4 6.5 9.9 >>> np.all((k2 == k).values) True