Module: basicUtilities

Basic utility functions and constants, not depending on numpy or other python modules.

  • Author: Johannes Gerstmayr

  • Date: 2020-03-10 (created)

  • Notes:
    Additional constants are defined:
    pi = 3.1415926535897932
    sqrt2 = 2**0.5
    g=9.81
    eye2D (2x2 diagonal matrix)
    eye3D (3x3 diagonal matrix)
    Two variables ‘gaussIntegrationPoints’ and ‘gaussIntegrationWeights’ define integration points and weights for function GaussIntegrate(…)

Function: ClearWorkspace

ClearWorkspace()

  • function description:
    clear all workspace variables except for system variables with ‘_’ at beginning,
    ‘func’ or ‘module’ in name; it also deletes all items in exudyn.sys and exudyn.variables,
    EXCEPT from exudyn.sys[‘renderState’] for pertaining the previous view of the renderer
  • notes:
    Use this function with CARE! In Spyder, it is certainly safer to add the preference Run\(\ra\)‘remove all variables before execution’. It is recommended to call ClearWorkspace() at the very beginning of your models, to avoid that variables still exist from previous computations which may destroy repeatability of results
  • example:
import exudyn as exu
import exudyn.utilities
#clear workspace at the very beginning, before loading other modules and potentially destroying unwanted things ...
ClearWorkspace()       #cleanup
#now continue with other code
from exudyn.itemInterface import *
SC = exu.SystemContainer()
mbs = SC.AddSystem()
...

Relevant Examples (Ex) and TestModels (TM) with weblink to github:


Function: SmartRound2String

SmartRound2String(x, prec = 3)

  • function description:
    round to max number of digits; may give more digits if this is shorter; using in general the format() with ‘.g’ option, but keeping decimal point and using exponent where necessary

Function: DiagonalMatrix

DiagonalMatrix(rowsColumns, value = 1)

  • function description:
    create a diagonal or identity matrix; used for interface.py, avoiding the need for numpy
  • input:
    rowsColumns: provides the number of rows and columns
    value: initialization value for diagonal terms
  • output:
    list of lists representing a matrix

Function: NormL2

NormL2(vector)

  • function description:
    compute L2 norm for vectors without switching to numpy or math module
  • input:
    vector as list or in numpy format
  • output:
    L2-norm of vector

Relevant Examples (Ex) and TestModels (TM) with weblink to github:


Function: VSum

VSum(vector)

  • function description:
    compute sum of all values of vector
  • input:
    vector as list or in numpy format
  • output:
    sum of all components of vector

Relevant Examples (Ex) and TestModels (TM) with weblink to github:


Function: VAdd

VAdd(v0, v1)

  • function description:
    add two vectors instead using numpy
  • input:
    vectors v0 and v1 as list or in numpy format
  • output:
    component-wise sum of v0 and v1

Relevant Examples (Ex) and TestModels (TM) with weblink to github:


Function: VSub

VSub(v0, v1)

  • function description:
    subtract two vectors instead using numpy: result = v0-v1
  • input:
    vectors v0 and v1 as list or in numpy format
  • output:
    component-wise difference of v0 and v1

Relevant Examples (Ex) and TestModels (TM) with weblink to github:


Function: VMult

VMult(v0, v1)

  • function description:
    scalar multiplication of two vectors instead using numpy: result = v0’ * v1
  • input:
    vectors v0 and v1 as list or in numpy format
  • output:
    sum of all component wise products: c0[0]*v1[0] + v0[1]*v1[0] + …

Function: ScalarMult

ScalarMult(scalar, v)

  • function description:
    multiplication vectors with scalar: result = scalar * v
  • input:
    value *scalar* and vector *v* as list or in numpy format
  • output:
    scalar multiplication of all components of v: [scalar*v[0], scalar*v[1], …]

Relevant Examples (Ex) and TestModels (TM) with weblink to github:


Function: Normalize

Normalize(v)

  • function description:
    take a 3D vector and return a normalized 3D vector (L2Norm=1)
  • input:
    vector v as list or in numpy format
  • output:
    vector v multiplied with scalar such that L2-norm of vector is 1

Relevant Examples (Ex) and TestModels (TM) with weblink to github:


Function: Vec2Tilde

Vec2Tilde(v)

  • function description:
    apply tilde operator (skew) to 3D-vector and return skew matrix
  • input:
    3D vector v as list or in numpy format
  • output:
    matrix as list of lists with the skew-symmetric matrix from v:
    \(\left[\!\! \begin{array}{ccc} 0 & -v[2] & v[1] \\ v[2] & 0 & -v[0] \\ -v[1] & v[0] & 0 \end{array} \!\!\right]\)

Relevant Examples (Ex) and TestModels (TM) with weblink to github:


Function: Tilde2Vec

Tilde2Vec(m)

  • function description:
    take skew symmetric matrix and return vector (inverse of Skew(…))
  • input:
    list of lists containing a skew-symmetric matrix (3x3)
  • output:
    list containing the vector v (inverse function of Vec2Tilde(…))

Function: GaussIntegrate

GaussIntegrate(functionOfX, integrationOrder, a, b)

  • function description:
    compute numerical integration of functionOfX in interval [a,b] using Gaussian integration
  • input:
    functionOfX: scalar, vector or matrix-valued function with scalar argument (X or other variable)
    integrationOrder: odd number in {1,3,5,7,9}; currently maximum order is 9
    a: integration range start
    b: integration range end
  • output:
    (scalar or vectorized) integral value

Function: LobattoIntegrate

LobattoIntegrate(functionOfX, integrationOrder, a, b)

  • function description:
    compute numerical integration of functionOfX in interval [a,b] using Lobatto integration
  • input:
    functionOfX: scalar, vector or matrix-valued function with scalar argument (X or other variable)
    integrationOrder: odd number in {1,3,5}; currently maximum order is 5
    a: integration range start
    b: integration range end
  • output:
    (scalar or vectorized) integral value