src.pydasa.dimensional.vaschy ============================= .. py:module:: src.pydasa.dimensional.vaschy .. autoapi-nested-parse:: Module framework.py =========================================== Module for **Schema** to manage Fundamental Dimensional Units (FDUs) for Dimensional Analysis in *PyDASA*. This module provides the Schema class which manages dimensional frameworks, FDU precedence, and regex patterns for dimensional expression validation. Classes: **Schema**: Manages dimensional frameworks and FDUs, providing methods for validation, *IMPORTANT:* Based on the theory from: # H.Gorter, *Dimensionalanalyse: Eine Theoririe der physikalischen Dimensionen mit Anwendungen* Classes ------- .. autoapisummary:: src.pydasa.dimensional.vaschy.Schema Module Contents --------------- .. py:class:: Schema Bases: :py:obj:`pydasa.core.basic.Foundation` **Schema** Manages dimensional frameworks and FDUs for *PyDASA*. Maintains a collection of Dimensions with their precedence, provides regex patterns for dimensional expressions, and manages the dimensional framework context. :param Foundation: Foundation class for validation of symbols and frameworks. .. attribute:: _fdu_lt List of Fundamental Dimensional Units in precedence order. :type: List[Dimension] .. attribute:: _fdu_map Dictionary mapping FDU symbols to Dimension objects. :type: Dict[str, Dimension] .. attribute:: _fdu_regex Regex pattern for matching dimensional expressions (e.g., 'M/L*T^-2' to 'M^1*L^-1*T^-2'). :type: str .. attribute:: _fdu_pow_regex Regex pattern for matching dimensions with exponents. (e.g., 'M*L^-1*T^-2' to 'M^(1)*L^(-1)*T^(-2)'). :type: str .. attribute:: _fdu_no_pow_regex Regex pattern for matching dimensions without exponents. (e.g., 'M*L*T' to 'M^(1)*L^(1)*T^(1)'). :type: str .. attribute:: _fdu_sym_regex Regex pattern for matching FDUs in symbolic expressions. (e.g., 'M^(1)*L^(-1)*T^(-2)' to 'L**(-1)*M**(1)*T**(-2)'). :type: str .. py:attribute:: _fdu_lt :type: List[pydasa.dimensional.fundamental.Dimension] :value: [] Internal storage for fundamental dimension objects. Always a List[Dimension] after __post_init__. .. py:attribute:: _fdu_map :type: Dict[str, pydasa.dimensional.fundamental.Dimension] Dictionary mapping FDU symbols to Dimension objects in *PyDASA*. procesess (e.g., Mass [M], Length [L], Time [T]). Purpose: - Defines the default dimensional framework used in *PyDASA*. - Used to initialize entities without a specified framework. - Basis for dimensional analysis precedence list in *PyDASA*. - Validates parameter and variable dimensions in *PyDASA*. - Default is the Physical FDUs framework. - Can be customized for specific applications or domains. .. py:attribute:: _fdu_symbols :type: List[str] :value: [] List of FDU symbols in the framework for the dimensional matrix (e.g., 'M*L^-1*T^-2'). Purpose: - Defines the row order in the dimensional matrix. - Validates parameter and variable dimensions in *PyDASA*. .. py:attribute:: _fdu_regex :type: str :value: '' Regex pattern for matching dimensional expressions. Default/Working regex pattern to match FDUs in *PyDASA* (e.g., 'M*L^-1*T^-2' to 'M^(1)*L^(-1)*T^(-2)'). .. py:attribute:: _fdu_pow_regex :type: str :value: '\\-?\\d+' Regex pattern for matching FDUs with exponents (e.g., 'M*L^-1*T^-2' to 'M^(1)*L^(-1)*T^(-2)') .. py:attribute:: _fdu_no_pow_regex :type: str :value: '' Regex pattern for matching dimensions without exponents. Default/Working regex to match FDUs without exponents (e.g., 'T*D' instead of 'T^2*D^-1'). .. py:attribute:: _fdu_sym_regex :type: str :value: '' Regex pattern for matching FDUs in symbolic expressions. Default/Working regex to match FDU symbols in *PyDASA* (e.g., 'T^(1)*D^(-1)' to 'D**(-1)*T**(2)'). .. py:method:: _setup_fdus() *_setup_fdus()* Initializes FDUs based on the selected framework. Creates and adds standard FDUs for the selected framework (PHYSICAL, COMPUTATION, SOFTWARE) or validates custom FDUs. :raises ValueError: If framework is not supported. :raises ValueError: If custom framework FDUs are not provided. :raises ValueError: If custom framework FDUs are not properly formatted. :raises ValueError: If custom framework FDUs contain invalid types. .. py:method:: _convert_fdu_lt() *_convert_fdu_lt()* Converts and validates the provided FDUs list/dict into Dimension objects. :raises TypeError: If elements in the list are not all Dimension or dict. :raises TypeError: If values in the dict are not all dict objects. :raises TypeError: If _fdu_lt is not a list or dict. .. py:method:: _setup_default_framework() *_setup_default_framework()* Returns the default FDU precedence list for the specified framework. :returns: Default FDUs precedence list based on the framework map. :rtype: List[str] .. py:method:: _validate_fdu_precedence() *_validate_fdu_precedence()* Ensures FDUs have valid and unique precedence values. :raises ValueError: If FDU precedence values are duplicated. .. py:method:: _update_fdu_map() *_update_fdu_map()* Updates the FDU symbol to object mapping. .. py:method:: _update_fdu_symbols() *_update_fdu_symbols()* Updates the list of FDU symbols in precedence order. .. py:method:: _setup_regex() *_setup_regex()* Sets up regex patterns for dimensional validation. Generates regex patterns for: - validating dimensional expressions. - parsing exponents. - completing expressions with exponent. - handling symbolic expressions. .. py:method:: _validate_fdu_lt(value) *_validate_fdu_lt()* Custom validator for fdu_lt property. :param value: List of FDUs to validate. :type value: List[Dimension] :raises ValueError: If list is empty or contains non-Dimension objects. .. py:property:: fdu_lt :type: List[pydasa.dimensional.fundamental.Dimension] *fdu_lt* Get the list of FDUs in precedence order. :returns: List of FDUs. :rtype: List[Dimension] .. py:property:: fdu_symbols :type: List[str] *fdu_symbols* Get the list of FDU symbols in precedence order. :returns: List of FDU symbols. :rtype: List[str] .. py:property:: size :type: int *size* Get the number of FDUs in the framework. :returns: Number of FDUs. :rtype: int .. py:property:: fdu_regex :type: str *fdu_regex* Get the FDU regex pattern. :returns: Regex pattern for validating dimensional expressions. :rtype: str .. py:property:: fdu_pow_regex :type: str *fdu_pow_regex* Get the FDU powered regex pattern. :returns: Regex pattern for matching dimensions with exponents. :rtype: str .. py:property:: fdu_no_pow_regex :type: str *fdu_no_pow_regex* Get the FDU no-power regex pattern. :returns: Regex pattern for matching dimensions without exponents. :rtype: str .. py:property:: fdu_sym_regex :type: str *fdu_sym_regex* Get the FDU symbol regex pattern. :returns: Regex pattern for matching FDUs in symbolic expressions. :rtype: str .. py:method:: get_fdu(symbol) *get_fdu()* Get an FDU by its symbol. :param symbol: FDU symbol. :type symbol: str :returns: FDU object if found, None otherwise. :rtype: Optional[Dimension] .. py:method:: has_fdu(symbol) *has_fdu()* Check if an FDU with the given symbol exists. :param symbol: FDU symbol. :type symbol: str :returns: True if the FDU exists, False otherwise. :rtype: bool .. py:method:: add_fdu(fdu) *add_fdu()* Add an FDU to the framework. :param fdu: FDU to add. :type fdu: Dimension :raises ValueError: If an FDU with the same symbol already exists. :raises ValueError: If the FDU framework does not match the current framework. .. py:method:: remove_fdu(sym) *remove_fdu()* Remove an FDU from the framework. :param sym: Symbol of the FDU to remove. :type sym: str :returns: removed FDU object. :rtype: Dimension .. py:method:: reset() .. py:method:: to_dict() *to_dict()* Convert framework to dictionary representation. :returns: Dictionary representation of the framework. :rtype: Dict[str, Any] .. py:method:: from_dict(data) :classmethod: *from_dict()* Create framework from dictionary representation. :param data: Dictionary representation of the framework. :type data: Dict[str, Any] :returns: New DimScheme instance. :rtype: DimScheme