utils Package
This is the pyNastran.utils.rst file.
dev
Module
- defines:
- fnames = get_files_of_type(dirname, extension=’.txt’,
max_size=100., limit_file=’no_dig.txt’)
msg = list_print(lst, float_fmt=’%-4.2f’)
- pyNastran.utils.dev.get_files_of_type(dirname: str, extension: str = '.txt', max_size: float = 100.0, limit_file: str = 'no_dig.txt', skip_folder_file: str = 'skip_folder.txt') list[str] [source]
Gets the list of all the files with a given extension in the specified directory
- Parameters:
- dirnamestr
the directory name
- extensionstr; default=’.txt’
list of filetypes to get
- max_sizefloat; default=100.0
size in MB for max file size
- limit_filestr; default=no_dig.txt
the presence of this file indicates no folder digging should be done on this folder
- skip_filestr; skip_folder.txt
the presence of this file indicates the folder should be skipped should be done on this folder
- Returns:
- fileslist[str]
list of all the files with a given extension in the specified directory
- pyNastran.utils.dev.list_print(lst: list[Any], float_fmt: str = '%-4.2f') str [source]
Prints a list or numpy array in an abbreviated format. Supported element types: None, string, numbers. Useful for debugging.
- Parameters:
- lstlist / numpy array
the value to print
- Returns:
- msgstr
the clean string representation of the object
#:mod:gui_io Module #——————– # #.. inheritance-diagram:: pyNastran.utils.gui_io # #.. automodule:: pyNastran.utils.gui_io # :members: # :undoc-members: # :show-inheritance:
mathematics
Module
- Various mathematical functions are defined in this file. This includes:
gauss(n)
get_abs_index(data, axis=1)
get_abs_max(min_values, max_values)
get_max_index(data, axis=1)
get_min_index(data, axis=1)
integrate_positive_unit_line(x, y, min_value=0.)
integrate_unit_line(x, y)
is_float_ranged(a, x, b)
is_list_ranged(a, List, b)
list_print(list_a, tol=1e-8, float_fmt=’%-3.2g’, zero_fmt=’ 0’)
print_annotated_matrix(A, row_names=None, col_names=None, tol=1e-8)
print_matrix(A, tol=1e-8)
reduce_matrix(matrix_a, nids)
roundup(value, round_increment=100)
solve_tridag(A, D)
unique2d(a)
All beams are LineProperty objects. Multi-segment beams are IntegratedLineProperty objects.
- pyNastran.utils.mathematics.Area(a, b)
- pyNastran.utils.mathematics.gauss(n: int) tuple[Any, Any] [source]
A quadrature rule: an approximation of the definite integral of a function. Currently implementation supports up to 5 quadrature points.
Function returns following values depending on n (number of points):
n = 1:
f$ 0 f$ –> f$ 2 f$
n = 2:
f$ pm 1/sqrt{3} f$ –> f$ 1 f$
n = 3
f$ 0 f$ –> f$ 8/9 f$
f$ pmsqrt{3/5} f$ –> f$ 5/9 f$
n = 4:
f$ pmsqrt{left( 3 - 2sqrt{6/5} right)/7} f$ –> f$ (18+sqrt{30})/36 f$
f$ pmsqrt{left( 3 + 2sqrt{6/5} right)/7} f$ –> f$ (18-sqrt{30})/36 f$
n = 5:
f$ 0 f$ –> f$ 128/225 f$
f$ pmfrac{1}{3}sqrt{5-2sqrt{10/7}} f$ –> f$ (322+13sqrt{70})/900 f$
f$ pmfrac{1}{3}sqrt{5+2sqrt{10/7}} f$ –> f$ (322-13sqrt{70})/900 f$
- Parameters:
n – Number of quadrature points
- Returns lists:
points and corresponding weights, sorted by points value
- pyNastran.utils.mathematics.get_abs_index(data: ndarray, axis: int = 1) tuple[ndarray, ndarray] [source]
Gets the maximum absolute value of a 2D matrix along an axis
Examples
>>> data = [ [4.0, 2.2, 3.0, 5.0, 2.2] # subcase 1 [4.1, 2.1, 3.1, 5.1, 2.1], # subcase 2 ] >>> max_values, index = get_min_index(data, axis=1) >>> out [4.1, 2.2, 3.1, 5.1, 2.2]
>>> index [1, 0, 1, 1, 0]
- pyNastran.utils.mathematics.get_abs_max(min_values: ndarray, max_values: ndarray, dtype: str = 'float32') ndarray [source]
Get return the value with the greatest magnitude, preserving sign.
- pyNastran.utils.mathematics.get_max_index(data: ndarray, axis: int = 1) tuple[ndarray, ndarray] [source]
Gets the maximum values of a 2D matrix along an axis
Examples
>>> data = [ [4.0, 2.2, 3.0, 5.0, 2.2] # subcase 1 [4.1, 2.1, 3.1, 5.1, 2.1], # subcase 2 ] >>> max_values, index = get_max_index(data, axis=1) >>> out [4.1, 2.2, 3.1, 5.1, 2.2]
>>> index [1, 0, 1, 1, 0]
- pyNastran.utils.mathematics.get_min_index(data: ndarray, axis: int = 1) tuple[ndarray, ndarray] [source]
Gets the minimum values of a 2D matrix along an axis
Examples
>>> data = [ [4.0, 2.2, 3.0, 5.0, 2.2] # subcase 1 [4.1, 2.1, 3.1, 5.1, 2.1], # subcase 2 ] >>> min_values, index = get_min_index(data, axis=1) >>> out [4.0, 2.1, 3.0, 5.0, 2.1]
>>> index [0, 1, 0, 0, 1]
- pyNastran.utils.mathematics.integrate_positive_unit_line(x, y, min_value: float = 0.0) float [source]
Integrates a line of length 1.0 by linear interpolation
- Parameters:
- xlist[float]
the independent variable
- ylist[float]
the dependent variable
- min_valuefloat; default=0.0
???
- Returns:
- integrated_valuefloat
the area under the curve
- pyNastran.utils.mathematics.integrate_unit_line(x: list[float], y: list[float]) float [source]
Integrates a line of length 1.0 by linear interpolation
- Parameters:
- xlist[float]
the independent variable
- ylist[float]
the dependent variable
- Returns:
- integrated_valuefloat
the area under the curve
- pyNastran.utils.mathematics.is_float_ranged(a: float, x: list[float], b: float) bool [source]
Returns true if a<= x <= b or a-x < 0 < b-x.
- Parameters:
- afloat
the lower bound value (inclusive)
- xlist[float, …]
the search values
- b: float
the upper bound value (inclusive)
- Returns:
- is_rangedbool
True/False
- pyNastran.utils.mathematics.is_list_ranged(a: float, alist: list[float], b: float) bool [source]
Returns true if a<= x <= b or a-x < 0 < b-x
- Parameters:
- afloat
the lower bound value (inclusive)
- xlist[float, …]
the search values
- b: float
the upper bound value (inclusive)
- Returns:
- is_rangedbool
True/False
- pyNastran.utils.mathematics.list_print(list_a, tol: float = 1e-08, float_fmt: str = '%-3.2g', zero_fmt: str = ' 0') str [source]
prints a list / numpy array in a readable format
- pyNastran.utils.mathematics.print_annotated_matrix(A: ndarray, row_names=None, col_names=None, tol: ndarray = 1e-08)[source]
Takes a list/dictionary and annotates the row number with that value indicies go from 0 to N
- pyNastran.utils.mathematics.print_matrix(A: ndarray, tol: float = 1e-08)[source]
prints a 2d matrix in a readable format
- pyNastran.utils.mathematics.reduce_matrix(matrix_a: ndarray, nids: list[int]) ndarray [source]
takes a list of ids and removes those rows and cols
- pyNastran.utils.mathematics.roundup(value: int, round_increment: int = 100) int [source]
Rounds up to the next N.
- Parameters:
- valueint
the value to round up
- round_incrementint
the increment to round by
- .. python
>>> 100 = roundup(10) >>> 200 = roundup(105) >>> 300 = roundup(200) >>> 1000 = roundup(200, 1000) >>> 2000 = roundup(1000, 1000) >>> 2000 = roundup(1001, 1000)
- .. note :: this function is used to ensure that renumbering is more
obvious when testing
nastran_utils
Module
- pyNastran.utils.nastran_utils.run_nastran(bdf_filename: str, nastran_cmd: str = 'nastran', keywords: str | list[str] | dict[str, str] | None = None, run: bool = True, run_in_bdf_dir: bool = True, cleanup: bool = False) tuple[int | None, list[str]] [source]
Call a nastran subprocess with the given filename
- Parameters:
- bdf_filenamestring
Filename of the Nastran .bdf file
- keywordsstr/dict/list of strings, optional
Default keywords are ‘scr=yes’, ‘bat=no’, ‘old=no’, and ‘news=no’
- runbool; default=True
let’s you disable actually running Nastran to test out code/get the call arguments
- run_in_local_dirbool; default=True
True : output (e.g., *.f06) will go to the current working directory (default) False : outputs (e.g., *.f06) will go to the input BDF directory
- cleanupbool; default=False
- Returns:
- return_codeint
the nastran flag
- cmd_argslist[str]
the nastran commands that go into subprocess
numpy_utils
Module
Interface to various numpy utilities
__init__
Module
- defines:
deprecated(old_name, new_name, deprecated_version, levels=None)
print_bad_path(path)
object_attributes(obj, mode=’public’, keys_to_skip=None)
object_methods(obj, mode=’public’, keys_to_skip=None)
- pyNastran.utils.__init__.check_path(filename: str | PurePath, name: str = 'file') None [source]
checks that the file exists
- pyNastran.utils.__init__.int_version(name: str, version: str) list[int] [source]
splits the version into a tuple of integers
- pyNastran.utils.__init__.ipython_info() str | None [source]
determines if iPython/Jupyter notebook is running
- pyNastran.utils.__init__.is_binary_file(filename: str | PurePath) bool [source]
Return true if the given filename is binary.
- Parameters:
- filenamestr
the filename to test
- Returns:
- binary_flagbool
True if filename is a binary file (contains null byte) and False otherwise.
- raises:
IOError if the file cannot be opened. ..
- Based on the idea (.. seealso:: http://bytes.com/topic/python/answers/21222-determine-file-type-binary-text)
- that file is binary if it contains null.
Warning
this may not work for unicode. ..
- pyNastran.utils.__init__.is_file_obj(filename: str | PurePath) bool [source]
does this object behave like a file object?
- pyNastran.utils.__init__.object_attributes(obj: Any, mode: str = 'public', keys_to_skip: list[str] | None = None, filter_properties: bool = False) list[str] [source]
List the names of attributes of a class as strings. Returns public attributes as default.
- Parameters:
- objinstance
the object for checking
- modestr
defines what kind of attributes will be listed * ‘public’ - names that do not begin with underscore * ‘private’ - names that begin with single underscore * ‘both’ - private and public * ‘all’ - all attributes that are defined for the object
- keys_to_skiplist[str]; default=None -> []
names to not consider to avoid deprecation warnings
- filter_properties: bool: default=False
filters the @property objects
- Returns:
- attribute_nameslist[str]
sorted list of the names of attributes of a given type or None if the mode is wrong
- pyNastran.utils.__init__.object_methods(obj: Any, mode: str = 'public', keys_to_skip: list[str] | None = None) list[str] [source]
List the names of methods of a class as strings. Returns public methods as default.
- Parameters:
- objinstance
the object for checking
- modestr
defines what kind of methods will be listed * “public” - names that do not begin with underscore * “private” - names that begin with single underscore * “both” - private and public * “all” - all methods that are defined for the object
- keys_to_skiplist[str]; default=None -> []
names to not consider to avoid deprecation warnings
- Returns:
- methodlist[str]
sorted list of the names of methods of a given type or None if the mode is wrong
- pyNastran.utils.__init__.object_stats(obj: Any, mode: str = 'public', keys_to_skip: list[str] | None = None, filter_properties: bool = False) str [source]
Prints out an easy to read summary of the object
- pyNastran.utils.__init__.print_bad_path(path: str | PurePath) str [source]
Prints information about the existence (access possibility) of the parts of the given path. Useful for debugging when the path to a given file is wrong.
- Parameters:
- pathstr
path to check
- Returns:
- msgstr
string with information whether access to parts of the path is possible
- pyNastran.utils.__init__.remove_files(filenames: list[str | PurePath]) None [source]
remvoes a series of files; quietly continues if the file can’t be removed
atmosphere
Moduleatm_density()
atm_dynamic_pressure()
atm_dynamic_viscosity_mu()
atm_equivalent_airspeed()
atm_kinematic_viscosity_nu()
atm_mach()
atm_pressure()
atm_speed_of_sound()
atm_temperature()
atm_unit_reynolds_number()
atm_velocity()
get_alt_for_density()
get_alt_for_eas_with_constant_mach()
get_alt_for_mach_eas()
get_alt_for_pressure()
get_alt_for_q_with_constant_mach()
make_flfacts_alt_sweep_constant_mach()
make_flfacts_alt_sweep_constant_tas()
make_flfacts_eas_sweep_constant_alt()
make_flfacts_eas_sweep_constant_mach()
make_flfacts_mach_sweep_constant_alt()
make_flfacts_tas_sweep_constant_alt()
sutherland_viscoscity()
dict_to_h5py
Module