Mechanics

Analysis Comparison

Feature

Static Analysis (Beam)

Dynamics (RigidBody)

Primary Goal

Deformation & Stress

Motion & Forces

Key Variable

$I$ (Inertia)

$m$ (Mass)

Governing Law

Euler-Bernoulli Theory

Newton’s Second Law ($F=ma$)

Main Output

Deflection ($delta$)

Acceleration ($a$)

Static Analysis

class mechlab.mechanics.SimplySupportedBeam(length, load, E, I)[source]

Bases: object

Simply supported beam with center point load.

Calculates reactions, maximum moment, and maximum deflection for a beam with a concentrated load at the center.

Parameters:
L

Beam length (m)

P

Point load at center (N)

E

Young’s modulus (Pa)

I

Second moment of area (m^4)

RA

Reaction at support A (N)

RB

Reaction at support B (N)

M_max

Maximum bending moment (N·m)

delta_max

Maximum deflection (m)

Example

>>> beam = SimplySupportedBeam(5, 1000, 200e9, 1e-4)
>>> beam.M_max
1250.0
results()[source]

Return analysis results as dictionary.

Returns:

Dictionary with all computed values

Return type:

dict[str, float]

class mechlab.mechanics.Beam(L, E, I)[source]

Bases: object

Cantilever beam with end load.

Calculates maximum deflection and slope.

Example

>>> beam = Beam(L=2, E=200e9, I=1e-6)
>>> beam.max_deflection(load=1000)
0.0133...
Parameters:
max_deflection(load)[source]

Calculate maximum deflection: δ = PL³/(3EI).

Parameters:

load (float)

Return type:

float

slope(x)[source]

Calculate slope at position x (simplified).

Parameters:

x (float)

Return type:

float

class mechlab.mechanics.StaticsParticle(forces)[source]

Bases: object

Represents a particle in statics.

Calculates resultant force, inclination angles, and unit vectors.

Example

>>> F1 = (10, 20, 0)
>>> F2 = (5, -10, 15)
>>> p = StaticsParticle([F1, F2])
>>> p.resultant()
Matrix([[15], [10], [15]])
Parameters:

forces (list)

resultant()[source]

Calculate and return the resultant force vector.

Return type:

MutableDenseMatrix

inclination()[source]

Calculate inclination angles of the resultant force.

Return type:

tuple

unit_vector()[source]

Calculate the unit vector of the resultant force.

Return type:

tuple

Stress Analysis

class mechlab.mechanics.StressState(sx, sy, txy, unit='MPa')[source]

Bases: object

Plane stress state (σx, σy, τxy) with optional unit conversion.

Parameters:
property unit: str | None
property sigma_x: float
property sigma_y: float
property tau_xy: float
property sx: float
property sy: float
property txy: float
principal(unit=None)[source]

Return principal stresses (σ1, σ2).

Parameters:

unit (str | None)

Return type:

tuple[float, float]

principal_stresses(unit=None)[source]

Alias for principal().

Parameters:

unit (str | None)

Return type:

tuple[float, float]

max_shear(unit=None)[source]

Return maximum shear stress (τmax).

Parameters:

unit (str | None)

Return type:

float

von_mises(unit=None)[source]

Return Von Mises equivalent stress.

Parameters:

unit (str | None)

Return type:

float

results(unit=None)[source]

Return a results dictionary in the requested unit.

Parameters:

unit (str | None)

Return type:

dict[str, float | str | None]

class mechlab.mechanics.StressTensor3D(components)[source]

Bases: object

Represents a 3D stress tensor.

The stress tensor is a symmetric 3x3 matrix:
[[σxx, τxy, τxz],

[τxy, σyy, τyz], [τxz, τyz, σzz]]

Example

>>> tensor = StressTensor3D([[100, 25, 0], [25, 50, 0], [0, 0, 0]])
>>> tensor.components
array([[100,  25,   0],
       [ 25,  50,   0],
       [  0,   0,   0]])
Parameters:

components (list[list[float]])

trace()[source]

Return the trace (sum of diagonal elements).

Return type:

float

hydrostatic()[source]

Return hydrostatic stress: σ_h = (σxx + σyy + σzz) / 3.

Return type:

float

class mechlab.mechanics.StressTransform[source]

Bases: object

Symbolic stress tensor transformation in 3D.

Uses direction cosines (l, m, n) to transform stress tensor from one coordinate system to another.

Example

>>> transform = StressTransform()
>>> result = transform.transform()  # Returns symbolic L * σ * L^T
transform()[source]

Compute transformed stress tensor: σ’ = L * σ * L^T.

Return type:

MutableDenseMatrix

class mechlab.mechanics.PrincipalStresses[source]

Bases: object

Calculate principal stresses from stress tensor.

Principal stresses are the eigenvalues of the stress tensor, representing normal stresses on planes with no shear stress.

Example

>>> tensor = [[100, 25, 0], [25, 50, 0], [0, 0, 0]]
>>> PrincipalStresses.calculate(tensor)
[110.355..., 39.644..., 0.0]
static calculate(stress_tensor)[source]

Calculate principal stresses (eigenvalues) sorted in descending order.

Parameters:

stress_tensor (list[list[float]]) – 3x3 stress tensor

Returns:

List of principal stresses [σ1, σ2, σ3] where σ1 >= σ2 >= σ3

Return type:

list[float]

Rigid Body Dynamics

class mechlab.mechanics.RigidBody(mass, position)[source]

Bases: object

Represents a point mass for dynamic calculations.

Example

>>> body = RigidBody(mass=10, position=(0, 0, 0))
>>> body.weight()
98.1
Parameters:
weight(g=9.81)[source]

Calculate weight: W = mg.

Parameters:

g (float)

Return type:

float

class mechlab.mechanics.DynamicsOfParticle(position, velocity, mass)[source]

Bases: object

Represents a particle in dynamics.

Tracks position, velocity, and mass for kinematic calculations.

Example

>>> p = DynamicsOfParticle(position=(0, 0, 0), velocity=(5, 0, 0), mass=10)
>>> p.kinetic_energy()
125.0
Parameters:
kinetic_energy()[source]

Calculate kinetic energy: KE = ½mv².

Return type:

float