Scaling functionality
- class stagpyviz.Scaling(name: str, factor: float, unit: str | Unit | None = None)
Class representing a scaling factor for a physical field, including its name, value and unit. The class provides methods to convert between dimensional and adimensional values, as well as to convert between different units of the same field using the python package pint for unit conversions.
- Parameters:
name (str) – Name of the physical field being scaled (e.g.
"temperature","length", etc.)factor (float) – Scaling factor for the physical field
unit (str|pint.Unit|None) – Base unit of the physical field (optional), see pint documentation for supported units. If not provided, the unit will be set to None.
- Example:
from stagpyviz.scaling import Scaling p_scaling = Scaling(name="pressure", factor=1e5, unit="Pa") # Convert a non-dimensional pressure field to dimensional p_dim = p_scaling.dim(p_non_dim) # Convert a dimensional pressure field to non-dimensional p_non_dim = p_scaling.a_dim(p_dim) # Convert a dimensional pressure field from Pa to GPa p_gpa = p_scaling.to(p_dim, "GPa") # Convert a dimensional pressure field from GPa to its base units (Pa) p_pa = p_scaling.to_base(p_gpa, "GPa")
- Methods:
- a_dim(field: ndarray) ndarray
Scale a dimensional field to non-dimensional using the scaling factor.
- Parameters:
field (numpy.ndarray) – Dimensional field to be scaled to non-dimensional
- Returns:
Non-dimensional field obtained by scaling the input dimensional field
- Return type:
numpy.ndarray
- dim(field: ndarray) ndarray
Scale a non-dimensional field to dimensional using the scaling factor.
- Parameters:
field (numpy.ndarray) – Non-dimensional field to be scaled to dimensional
- Returns:
Dimensional field obtained by scaling the input non-dimensional field
- Return type:
numpy.ndarray
- to(field: ndarray, unit: str | Unit) ndarray
Convert a dimensional field from its base unit (the unit associated with the scaling factor) to a different unit using the pint package for unit conversions.
Warning
Units must be compatible for conversion, i.e. they must represent the same physical quantity (e.g.
"K"and"degC"are compatible, but"K"and"m"are not).- Parameters:
field (numpy.ndarray) – Dimensional field in its base unit to be converted to another unit
unit (str|pint.Unit) – Target unit for the conversion
- Returns:
Field converted to the target unit
- Return type:
numpy.ndarray
- to_base(field: ndarray, unit: str | Unit) ndarray
Convert a dimensional field from a given unit to the base unit of the scaling factor using the pint package for unit conversions.
Warning
Units must be compatible for conversion, i.e. they must represent the same physical quantity (e.g.
"K"and"degC"are compatible, but"K"and"m"are not).- Parameters:
field (numpy.ndarray) – Dimensional field to be converted to the base unit
unit (str|pint.Unit) – Unit of the input field
- Returns:
Field converted to the base unit of the scaling factor
- Return type:
numpy.ndarray
- stagpyviz.scaling_factors(**kwargs) dict[str, Scaling]
Function to create a dictionary of Scaling instances for different physical fields, based on the provided keyword arguments. The function calculates the scaling factors for temperature, length, diffusivity, expansion, gravity, density, time, velocity, heat source, viscosity and pressure based on the provided values and / or the Rayleigh number (Ra).
- Parameters:
kwargs –
Keyword arguments to specify the scaling factors for different fields. The following keyword arguments are supported (other quantities are derived from these):
Ra: Rayleigh number (default:1e7)temperature_factor: Scaling factor for temperature (default:2700.0K)temperature_unit: Unit for temperature (default:"K")length_factor: Scaling factor for length (default:2.89e6m)length_unit: Unit for length (default:"m")diffusivity_factor: Scaling factor for diffusivity (default:1e-6m^2/s)diffusivity_unit: Unit for diffusivity (default:"m**2/s")expansion_factor: Scaling factor for thermal expansion coefficient (default:3e-51/K)expansion_unit: Unit for thermal expansion coefficient (default:"1/K")gravity_factor: Scaling factor for gravity (default:9.81m/s^2)gravity_unit: Unit for gravity (default:"m/s**2")density_factor: Scaling factor for density (default:3300.0kg/m^3)density_unit: Unit for density (default:"kg/m**3")viscosity_factor: Scaling factor for viscosity (default: calculated fromRaif not provided)viscosity_unit: Unit for viscosity (default: calculated fromRaif not provided)
- Returns:
Dictionary of Scaling instances for different physical fields.
- Return type:
dict[str, Scaling]
Available fields in the returned dictionary:
"temperature": Scaling for temperature"length": Scaling for length"diffusivity": Scaling for diffusivity"expansion": Scaling for thermal expansion coefficient"gravity": Scaling for gravity"density": Scaling for density"time": Scaling for time (derived from length and diffusivity)"velocity": Scaling for velocity (derived from length and time)"heat_source": Scaling for heat source (derived from temperature and time)"viscosity": Scaling for viscosity (derived from Ra if not provided)"pressure": Scaling for pressure (derived from viscosity and time)"strain_rate": Scaling for strain rate (derived from time)"area": Scaling for area (derived from length)"volume": Scaling for volume (derived from length)