pyyeti.cla.DR_Def.add¶
- DR_Def.add(*, name, labels, active='yes', drms=None, drfunc=None, drfile=None, se=None, desc=None, units='Not specified', uf_reds=None, filterval=1e-06, histlabels=None, histpv=None, histunits=None, misc=None, ignorepv=None, nondrms=None, srsQs=None, srsfrq=None, srsconv=None, srslabels=None, srsopts=None, srspv=None, srsunits=None, **kwargs)[source]¶
Adds a data recovery category.
All inputs to
add()must be named.Note
Any of the inputs can be set to self.defaults. In this case, the value for the parameter will be taken from the self.defaults dictionary (which is defined during instantiation). A ValueError is raised if self.defaults does not contain a value for the parameter.
Note
Using None for some inputs (which is default for many) will cause a default action to be taken. These are listed below as applicable after “DA:”.
- Parameters:
name (string) – Short name of data recovery category, eg: ‘SC_atm’. This typically also defines drfunc, the name of the function in drfile that is called to do data recovery; in that case, it must be a valid Python variable name.
labels (list_like or integer) – List_like of strings describing each row. Can also be an integer specifying number of rows being recovered; in this case, the list is formed internally as:
['Row 1', 'Row 2', ...]. This input is used to determine number of rows being recovered. If not a list, it is converted to a list vialist.active (string; optional) – If ‘yes’, this category will be included when the
DR_Event.add()function is called to add categories for the event simulation. Otherwise, this category will be ignored during the simulation by default. These tools only check for ‘yes’, but user written tools can make use of other settings, perhaps by monkey-patching theDR_Eventclass to replace or augment theDR_Event.add()method. As an example, for a category that calculates the fairing-to-spacecraft loss-of-clearance, you might set active to ‘no’ to unconditionally ignore this category but use ‘loc’ to include this category if a fairing is present but ignore it if not.drms (dict or None; optional) – Dictionary of data recovery matrices for this category; keys are matrix names and must match what is used in the data recovery function in drfile. In the data recovery function, these variables are accessed through
Vars[se]. For example:drms = {'scatm': scatm}means thatVars[se]['scatm']would be used in the function (see also drfunc). If se is greater than 0, each matrix, before being stored inVars[se]viaDR_Event.add(), will be multiplied by the appropriate “ULVS” matrix (seepyyeti.nastran.op2.rdnas2cam()) during event simulation. If se is 0, it is used as is and is likely added during event simulation since system modes are often needed. Note that when se is 0, using drms is equivalent to using nondrms.drfunc (string or None; optional) – A string that either defines the data recovery calculations directly (a “Type 1” drfunc) or, if it is a valid Python identifier, it is the name of the data recovery function in drfile (a “Type 2” drfunc). If it is Type 2, as a check, this routine will attempt to import the function; if not found, a warning is printed.
Assume that drfile is specified properly and the file it indicates has:
def SC_atm(sol, nas, Vars, se): return Vars[se]['atm'] @ sol.a
(The inputs to the data recovery function are defined below in the Notes section.) Further, assume that name is ‘SC_atm’. With these assumptions, we can use either a Type 1 or a Type 2 drfunc. That is, the following settings for drfunc are all functionally equivalent:
drfunc
Description
“Vars[se][‘atm’] @ sol.a”
Type 1. This defines the return statement directly (the function is defined internally, inside module
cla).‘SC_atm’
Type 2. Uses the SC_atm function in drfile.
None
Type 2. Same as ‘SC_atm’. (Takes the default action … see ‘DA’ below)
Note that, currently, if the data recovery function needs more than just the typical return statement calculation or if a PSD-specific data recovery function is needed, then drfunc must be Type 2.
DA: set to name and drfile is used.
drfile (string or ‘.’ or None; optional) – Only used if needed according to drfunc (if using a “Type 2” drfunc). If needed, drfile is the name of file that contains the data recovery function named drfunc. It can optionally also have a PSD-specific data recovery function; this must have the same name but with “_psd” appended. See notes below for example functions. drfile is imported during event simulation. If not already provided in drfile, the full path of drfile is defined to be relative to the path of the file that contains the function that called this routine. If input as ‘.’, drfile is set to the full name of the file that called this routine.
DA: if drfile is set in self.defaults, that is used; otherwise, it is set to the full name of the file that called this routine (as if drfile was input as ‘.’).
se (integer or None; optional) – The superelement number.
DA: get value from self.defaults if present; otherwise set to 0.
desc (string or None; optional) – One line description of category; eg:
desc = 'S/C Internal Accelerations'.DA: set to name.
units (string; optional) – Specifies the units.
uf_reds (4-element tuple or None; optional) – The uncertainty factors in “reds” order: [rigid, elastic, dynamic, static]. Examples:
(1, 1, 1.25, 1) - Typical; DUF = 1.25 (0, 1, 1.25, 1) - Same, but without rigid-body part (1, 1, 0, 1) - Recover static part only (1, 1, 1, 0) - Recover dynamic part only
DA: get value from self.defaults if present; otherwise set to (1, 1, 1, 1). Also, any of the four entries in the tuple can be None; these get reset to the corresponding entry from the self.defaults or, if that’s None too, 1.
filterval (scalar or 1d array_like; optional) – Response values smaller than filterval will be skipped during comparison to another set of results. If 1d array_like, length must be
len(labels)allowing for a unique filter value for each row.histlabels (list_like or None; optional) – Analogous to labels but just for the histpv rows.
DA: derive from labels according to histpv if needed; otherwise, leave it None.
histpv (1d array_like or ‘all’ or slice or None; optional) – Specifies which rows to save the response histories of. See note below about inputting partition vectors.
histunits (string or None; optional) – Units string for the histpv.
DA: set to units if histpv is not None; otherwise, leave it None.
ignorepv (1d array_like or ‘all’ or slice or None; optional) – Typically, this is left as None (default) so that all rows are compared. ignorepv specifies rows that need to be ignored during comparisons against a reference data set. If set to ‘all’, all rows will ignored … meaning no comparisons will be done for this category. See note below about inputting partition vectors.
misc (any object; optional) – Available for storing miscellaneous information for the category. It is not used within this module. This option is similar to nondrms in functionality; the differences are that the misc input will be stored with the results, and that the nondrms contents will be put in
Vars[se](making those values available in the the data recovery function).nondrms (dict or None; optional) – With one important exception, this input is used identically to drms. The exception is that the values in nondrms are not multiplied by ULVS. Therefore, nondrms can contain any variables you need for data recovery. An alternative option is to include data you need in drfile with the data recovery functions.
srsQs (scalar or 1d array_like or None; optional) – Q values for SRS calculation or None.
DA: set to self.defaults if any other srs* option is not None; otherwise, leave it None.
srsfrq (1d array_like or None; optional) – Frequency vector for SRS.
DA: get value from self.defaults if srsQs is not None (after its default action, if applicable); otherwise, leave it None.
srsconv (scalar or 1d array_like or None; optional) – Conversion factor for the SRS; scalar or vector same length as srspv.
DA: if srsQs is not None (after its default action, if applicable), either get value for srsconv from self.defaults (if possible), or set to 1.0. If srsQs is None, leave srsconv None.
srslabels (list_like or None; optional) – Analogous to labels but just for the srspv rows.
DA: derive from labels according to srspv if needed; otherwise, leave it None.
srsopts (dict or None; optional) – This dictionary can specify options for all three of these SRS calculation routines:
pyyeti.srs.srs(),pyyeti.srs.srs_frf(), andpyyeti.srs.vrs(). The “eqsine” option is special in that it enforces equivalent sine output for all three routines even if the routine does not accept “eqsine” as input. Other options are only passed if the function accepts it. For example, to specify equivalent sine for all three (“eqsine” is special, as noted), steady-state initial conditions forpyyeti.srs.srs()and scale_by_Q_only forpyyeti.srs.srs_frf(), use:dict(eqsine=True, ic='steady', scale_by_Q_only=True)DA: if srsQs is not None (after its default action, if applicable), either get value for srsopts from self.defaults (if possible), or set to
{}. If srsQs is None, leave srsopts None.srspv (1d array_like or ‘all’ or slice or None; optional) – Specifies which rows to compute SRS for. See note below about inputting partition vectors.
DA: if srsQs is not None (after its default action, if applicable), set to
slice(len(labels)); otherwise, leave it None.srsunits (string or None; optional) – Units string for the srspv.
DA: if srsQs is not None (after its default action, if applicable), set to units; otherwise, leave it None.
**kwargs (dict; optional) – All other inputs are quietly ignored.
- Returns:
None
Notes
See
DR_Deffor a discussion about how the order of data recovery is determined. In summary:DR_Event.add()determines the order ofDR_Definstances, andDR_Def.add()determines the order of data recovery categories within eachDR_Definstance.DR_Event.set_dr_order()can be used to modify the final order. That routine uses the more generalpyyeti.ytools.reorder_dict()to reorder the categories.Entering partition vectors. The histpv, srspv and ignorepv inputs are all handled similarly. They can be input as an index or boolean style partition vector, as a slice, or as “all”. If input as ‘all’, they are reset internally to
slice(len(labels)). The stored versions are either a slice or an index vector (uses 0-offset for standard Python indexing).`drfunc`, `drfile` notes. If drfunc is a valid Python identifier (called “Type 2” above), then drfile must contain the appropriate data recovery function(s) named
nameand, optionally,name_psd. For a typical data recovery category, only one data recovery function would be needed. Here are some examples:For a typical ATM:
def SC_atm(sol, nas, Vars, se): return Vars[se]['atm'] @ sol.a
For a typical mode-displacement DTM:
def SC_dtm(sol, nas, Vars, se): return Vars[se]['dtm'] @ sol.d
For a typical mode-acceleration LTM:
def SC_ltm(sol, nas, Vars, se): return (Vars[se]['ltma'] @ sol.a + Vars[se]['ltmd'] @ sol.d)
Note that those three examples could also be implemented more directly by using the following 3 “Type 1” drfunc definitions:
drfunc = "Vars[se]['atm'] @ sol.a" # ATM drfunc = "Vars[se]['dtm'] @ sol.d" # DTM drfunc = """(Vars[se]['ltma'] @ sol.a + Vars[se]['ltmd'] @ sol.d)""" # Mode-acce LTM
For a more complicated data recovery category, you’ll need to use drfile and you might also need to include a special PSD version. This function has the same name except with “_psd” tacked on. For example, to compute a time-consistent (or phase-consistent) root-sum-square (RSS), you need to provide both functions. Here is a pair of functions that recover 3 rows (for name “x_y_rss”): acceleration response in the ‘x’ and ‘y’ directions and the consistent RSS between them for the 3rd row. In this example, it is assumed the data recovery matrix has 3 rows where the 3rd row could be all zeros:
def x_y_rss(sol, nas, Vars, se): resp = Vars[se]['xyrss'] @ sol.a xr = 0 # 'x' row(s) yr = 1 # 'y' row(s) rr = 2 # rss rows resp[rr] = np.sqrt(resp[xr]**2 + resp[yr]**2) return resp def x_y_rss_psd(sol, nas, Vars, se, freq, forcepsd, drmres, case, i): # drmres is a results namespace, eg: # drmres = results['x_y_rss'] # i is psd force number resp = Vars[se]['xyrss'] @ sol.a xr = 0 # 'x' row(s) yr = 1 # 'y' row(s) rr = 2 # rss rows cla.PSD_consistent_rss( resp, xr, yr, rr, freq, forcepsd, drmres, case, i)
Ultimately, the PSD recovery function must provide the final PSD solution in
drmres[case]after the final force is analyzed (wheni == forcepsd.shape[0]-1). In the example above,PSD_consistent_rss()takes care of that job.Data recovery function inputs:
Input
Description
sol
ODE modal solution namespace with uncertainty factors applied. Typically has at least .a, .v and .d members (modal accelerations, velocities and displacements). See
pyyeti.ode.SolveUnc.tsolve().nas
The nas2cam dict:
nas = pyyeti.nastran.op2.rdnas2cam()DR
Defines data recovery for an event simulation (and is created in the simulation script via
DR = cla.DR_Event()). It is an event specific version of all combinedDR_Defobjects with all ULVS matrices applied.se
Superelement number. Used as key into DR.
etc
See
PSD_consistent_rss()for description of freq, forcepsd, etc.