utils Package¶
This is the pyNastran.utils.rst file.
#: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)[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, axis=1)[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, max_values, dtype='float32')[source]¶ Get return the value with the greatest magnitude, preserving sign.
-
pyNastran.utils.mathematics.
get_max_index
(data, axis=1)[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, axis=1)[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=0.0)[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, y)[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, x, b)[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, List, b)[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=1e-08, float_fmt='%-3.2g', zero_fmt=' 0')[source]¶ prints a list / numpy array in a readable format
-
pyNastran.utils.mathematics.
print_annotated_matrix
(A, row_names=None, col_names=None, tol=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, tol=1e-08)[source]¶ prints a 2d matrix in a readable format
-
pyNastran.utils.mathematics.
reduce_matrix
(matrix_a, nids)[source]¶ takes a list of ids and removes those rows and cols
-
pyNastran.utils.mathematics.
roundup
(value, round_increment=100)[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: Union[str, List[str], Dict[str, str], None] = None, run: bool = True, run_in_bdf_dir: bool = True) → Tuple[Optional[int], 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
- 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__.
b
(string: str) → bytes[source]¶ reimplementation of six.b(…) to work in Python 2
-
pyNastran.utils.__init__.
check_path
(filename: str, 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
() → Optional[str][source]¶ determines if iPython/Jupyter notebook is running
-
pyNastran.utils.__init__.
is_binary_file
(filename: Union[str, pathlib.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) → bool[source]¶ does this object behave like a file object?
-
pyNastran.utils.__init__.
object_attributes
(obj: Any, mode: str = 'public', keys_to_skip: Optional[List[str]] = 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: Optional[List[str]] = 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: Optional[List[str]] = 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) → 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