src.pydasa.dimensional.model#
Module for Matrix to perform Dimensional Analysis in PyDASA.
This module provides the Matrix class which implements matrix-based dimensional analysis following the Buckingham Pi theorem methodology.
- Classes:
Matrix: Represents a dimensional matrix for performing dimensional analysis, including methods for matrix creation, solving, and coefficient generation.
- IMPORTANT: Based on the theory from:
Gorter, Dimensionalanalyse: Eine Theoririe der physikalischen Dimensionen mit Anwendungen
Attributes#
Classes#
Matrix for Dimensional Analysis in PyDASA. Manages the dimensional matrix for performing analysis using the Buckingham Pi theorem methodology. |
Module Contents#
- class src.pydasa.dimensional.model.Matrix#
Bases:
pydasa.core.basic.FoundationMatrix for Dimensional Analysis in PyDASA. Manages the dimensional matrix for performing analysis using the Buckingham Pi theorem methodology.
- Parameters:
Foundation – Foundation class for validation of symbols and frameworks.
- # Core Identification
- # FDU Schema Management
- # Variable Management
- # Variable Statistics
- # Matrix Representations
- _dim_mtx#
Dimensional matrix (FDUs × Variables).
- Type:
Optional[NDArray[np.float64]]
- _dim_mtx_trans#
Transposed dimensional matrix.
- Type:
Optional[NDArray[np.float64]]
- _sym_mtx#
SymPy matrix for symbolic computation.
- Type:
Optional[sp.Matrix]
- _rref_mtx#
Row-Reduced Echelon Form matrix.
- Type:
Optional[NDArray[np.float64]]
- # Analysis Results
- _coefficients#
Dimensionless Pi coefficients.
- Type:
Dict[str, Coefficient]
- _schema: pydasa.dimensional.vaschy.Schema#
Dimensional domain managing Fundamental Dimensional Units (FDUs).
- _variables: Dict[str, pydasa.elements.parameter.Variable]#
Dictionary of all parameters/variables in the model.
Keys are variable symbols (str), values are Variable instances.
- _relevance_lt: Dict[str, pydasa.elements.parameter.Variable]#
Dictionary of relevant parameters/variables for dimensional analysis.
Filtered subset of _variables where Variable.relevant == True. Keys are variable symbols (str), values are Variable instances.
NOTE: called ‘relevant list’ by convention.
- _output: pydasa.elements.parameter.Variable | None = None#
The single output variable for the dimensional analysis.
Must be a variable with cat == “OUT”.
- _dim_mtx: numpy.typing.NDArray[numpy.float64] | None = None#
Dimensional matrix as NumPy array.
Shape: (n_fdus, n_relevant_vars) Each column represents a variable’s dimensional formula. Each row represents an FDU’s exponent across all variables.
- _dim_mtx_trans: numpy.typing.NDArray[numpy.float64] | None = None#
Transposed dimensional matrix.
Shape: (n_relevant_vars, n_fdus) Transpose of _dim_mtx for alternative operations.
- _sym_mtx: sympy.Matrix | None#
SymPy Matrix representation for symbolic computation.
Used for RREF calculation and nullspace computation. Equivalent to _dim_mtx but in SymPy format.
- _rref_mtx: numpy.typing.NDArray[numpy.float64] | None = None#
Row-Reduced Echelon Form (RREF) of the dimensional matrix.
Result of Gaussian elimination on _sym_mtx. Used to identify pivot columns and compute nullspace.
- _nullspace: List[numpy.ndarray | sympy.Matrix] = []#
List of nullspace vectors of the dimensional matrix.
Can be list of arrays or list of sympy vectors
- _pivot_cols: List[int] = []#
Indices of pivot columns in the RREF matrix.
Identifies which variables are dependent (pivot) vs. independent (free).
- _coefficients: Dict[str, pydasa.dimensional.buckingham.Coefficient]#
Dictionary of dimensionless Pi coefficients.
Keys are coefficient symbols (e.g., “Pi_{0}”), values are Coefficient instances. Generated from the nullspace of the dimensional matrix.
- _prepare_analysis()#
_prepare_analysis() Prepare the model for dimensional analysis.
Sets up relevant variables, computes model statistics, identifies the output variable, and extracts working FDUs.
- Raises:
ValueError – If variable configuration is invalid.
- Return type:
None
- _update_variable_stats()#
_update_variable_stats() Update variable statistics.
Computes the number of variables, inputs, outputs, and control variables. Validates the model constraints.
- Raises:
ValueError – If model has invalid variable counts.
- Return type:
None
- _sort_by_category(vars_lt)#
_sort_by_category() Sorts variables by category.
Sorts variables in order: IN -> OUT -> CTRL. Updates variable indices to reflect sorted order.
- _find_output_variable()#
_find_output_variable() Identifies the output variable.
Finds the first variable with cat == “OUT” in the relevant list.
- Return type:
None
- _extract_fdus()#
_extract_fdus() Extracts FDUs from relevant variables.
Scans all relevant variables’ dimension strings to find which FDUs are actually used.
- Returns:
List of unique FDU symbols used, in precedence order.
- Return type:
List[str]
- create_matrix()#
create_matrix() Builds the dimensional matrix.
Creates the dimensional matrix by arranging variable dimensions as columns. Each row represents an FDU, each column a variable.
- Raises:
ValueError – If no relevant variables exist.
ValueError – If variables have invalid or missing dimensional columns.
- Return type:
None
- solve_matrix()#
solve_matrix() Solves the dimensional matrix.
Computes the Row-Reduced Echelon Form (RREF) of the matrix, identifies pivot columns, and generates dimensionless coefficients from the nullspace.
- Raises:
ValueError – If matrix hasn’t been created yet.
- Return type:
None
- _generate_coefficients()#
_generate_coefficients() Generates dimensionless coefficients.
Creates Coefficient objects from each nullspace vector of the dimensional matrix. Each nullspace vector represents a dimensionless group (Pi coefficient).
- Return type:
None
- derive_coefficient(expr, symbol='', name='', description='', idx=-1)#
derive_coefficient() Creates a new coefficient derived from existing ones.
Combines existing dimensionless coefficients using a mathematical expression. The new coefficient is marked as “DERIVED”.
- Parameters:
expr (str) –
Mathematical expression using existing coefficients and numeric constants. Supports: , /, * (power), +, -, and numeric constants .. rubric:: Examples
”Pi_{0} * Pi_{1}” (multiplication: adds exponents)
”Pi_{0} / Pi_{1}” (division: subtracts exponents)
”Pi_{0}**(-1)” (power: multiplies exponents)
”Pi_{0} + Pi_{1}” (addition: result is dimensionless)
”Pi_{0} - Pi_{1}” (subtraction: result is dimensionless)
”2 * Pi_{0}” (constant multiplication: constant is dimensionless)
”0.5 * Pi_{1} * Pi_{0}**(-1)” (mixed expression with constant)
”1/Pi_{2}” (invert the coefficient - changes both exponents and values)
symbol (str) – Symbol representation (LaTeX or alphanumeric) for the derived coefficient. Default to “” to keep the original (e.g., Pi_{0}).
name (str, optional) – Name for the derived coefficient. Defaults to “Derived-Pi-{idx}”.
description (str, optional) – Description of the coefficient. Defaults to “Derived from: {expr}”.
idx (int, optional) – Index for the coefficient. If -1, the next available index is used.
- Returns:
The newly created derived coefficient.
- Return type:
- Raises:
ValueError – If expression is invalid or references non-existent coefficients.
ValueError – If expression creates dimensionally inconsistent result.
Example::
>>> # Create Reynolds number as ratio of two Pi groups >>> Re = model.derive_coefficient( ... expr="\Pi_{0} / \Pi_{1}", ... name="Reynolds Number", ... description="Ratio of inertial to viscous forces" ... ) >>> # Create a coefficient with constant multiplier >>> scaled = model.derive_coefficient( ... expr="2 * \Pi_{0}", ... name="Scaled Coefficient", ... description="Twice the original coefficient" ... )
- analyze()#
analyze() Performs complete dimensional analysis
Executes the full analysis workflow: 1. Prepare analysis (validate variables, identify output) 2. Create dimensional matrix 3. Solve matrix (compute RREF and nullspace) 4. Generate dimensionless coefficients
This is the main entry point for dimensional analysis.
- Return type:
None
- clear()#
clear() Resets all dimensional matrix and analysis data.
Clears all computed results while preserving the framework (_schema). Resets all attributes to the same state as __post_init__ leaves them.
NOTE: Numpy arrays don’t have .clear() method, so we reassign. Lists have .clear() method.
- Return type:
None
- property variables: Dict[str, pydasa.elements.parameter.Variable]#
variables Get the dictionary of variables.
- property schema: pydasa.dimensional.vaschy.Schema#
schema Get the dimensional schema.
- Returns:
Current dimensional schema.
- Return type:
- property relevance_lt: Dict[str, pydasa.elements.parameter.Variable]#
relevance_lt Get dictionary of relevant variables.
- property alias: str#
alias Get the Python variable alias.
- Returns:
Python variable name alias.
- Return type:
- property coefficients: Dict[str, pydasa.dimensional.buckingham.Coefficient]#
coefficients Get dictionary of dimensionless coefficients.
- Returns:
Dictionary of dimensionless coefficients.
- Return type:
Dict[str, Coefficient]
- property output: pydasa.elements.parameter.Variable | None#
output Get the output variable.
- Returns:
The output variable, or None if not set.
- Return type:
Optional[Variable]
- property dim_mtx: numpy.typing.NDArray[numpy.float64] | None#
dim_mtx Get the dimensional matrix.
- Returns:
Dimensional matrix, or None.
- Return type:
Optional[NDArray[np.float64]]
- property rref_mtx: numpy.typing.NDArray[numpy.float64] | None#
rref_mtx Get the RREF matrix.
- Returns:
RREF matrix, or None.
- Return type:
Optional[NDArray[np.float64]]
- property pivot_cols: List[int]#
pivot_cols Get pivot column indices.
- Returns:
Pivot column list.
- Return type:
List[int]