diff --git a/plots/thermodynamics/carnot_cycle.py b/plots/thermodynamics/carnot_cycle.py index 757c9d4c9..cf133e80c 100644 --- a/plots/thermodynamics/carnot_cycle.py +++ b/plots/thermodynamics/carnot_cycle.py @@ -61,7 +61,8 @@ adiabatic_law.initial_temperature: GAS_TEMPERATURE_START, adiabatic_law.initial_volume: GAS_VOLUME_ADIABATIC_START, adiabatic_law.adiabatic_index: GAS_SPECIFIC_HEATS_RATIO, - adiabatic_law.final_temperature: GAS_TEMPERATURE_END + adiabatic_law.final_temperature: GAS_TEMPERATURE_END, + ideal_gas_equation.amount_of_substance: GAS_MOLE_COUNT, }) # Use reversed adiabatic process here: looks like adiabatic expansion @@ -70,7 +71,8 @@ adiabatic_law.initial_temperature: GAS_TEMPERATURE_START, adiabatic_law.initial_volume: GAS_VOLUME_START, adiabatic_law.adiabatic_index: GAS_SPECIFIC_HEATS_RATIO, - adiabatic_law.final_temperature: GAS_TEMPERATURE_END + adiabatic_law.final_temperature: GAS_TEMPERATURE_END, + ideal_gas_equation.amount_of_substance: GAS_MOLE_COUNT, }) result_pressure_isothermal_expansion = isothermal_pressure.subs({ diff --git a/symplyphysics/docs/symbols_role.py b/symplyphysics/docs/symbols_role.py index 07380b88c..6d8441370 100644 --- a/symplyphysics/docs/symbols_role.py +++ b/symplyphysics/docs/symbols_role.py @@ -39,7 +39,7 @@ def process_string(doc: str, path: Path) -> str: last_index_to = index_to break else: - raise ValueError(f"Unknown symbol {name} in '{path}'.") + raise ValueError(f"Unknown symbol '{name}' in '{path}'.") # no substitution happened if not parts: diff --git a/symplyphysics/laws/thermodynamics/canonical_partition_function_of_classical_discrete_system.py b/symplyphysics/laws/thermodynamics/canonical_partition_function_of_classical_discrete_system.py index e1d7a0618..a764d5e39 100644 --- a/symplyphysics/laws/thermodynamics/canonical_partition_function_of_classical_discrete_system.py +++ b/symplyphysics/laws/thermodynamics/canonical_partition_function_of_classical_discrete_system.py @@ -12,41 +12,34 @@ from sympy import Eq, Idx, solve from symplyphysics import ( convert_to_float, - dimensionless, - Symbol, validate_input, validate_output, - SymbolIndexed, SumIndexed, global_index, + symbols, ) +from symplyphysics.core.symbols.symbols import clone_as_indexed -partition_function = Symbol("partition_function", dimensionless) +partition_function = symbols.partition_function """ -Partition function of the system. - -Symbol: - :code:`Z` +:symbols:`partition_function` of the system. """ -boltzmann_factor = SymbolIndexed("boltzmann_factor", dimensionless) -r""" -:doc:`Boltzmann factor ` of energy state :math:`i`. - -Symbol: - :code:`f_i` - -Latex: - :math:`f_i` +boltzmann_factor = clone_as_indexed( + symbols.boltzmann_factor, + display_symbol="f[i]", + display_latex="f_i", +) +""" +:symbols:`boltzmann_factor` of energy state :math:`i`. See :doc:`Boltzmann factor +`. """ law = Eq(partition_function, SumIndexed(boltzmann_factor[global_index], global_index)) -r""" -:code:`Z = Sum(f_i, i)` +""" +:laws:symbol:: -Latex: - .. math:: - Z = \sum_i f_i +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/change_in_entropy_of_ideal_gas_from_volume_and_temperature.py b/symplyphysics/laws/thermodynamics/change_in_entropy_of_ideal_gas_from_volume_and_temperature.py index c1d4b2f6d..299b0caf4 100644 --- a/symplyphysics/laws/thermodynamics/change_in_entropy_of_ideal_gas_from_volume_and_temperature.py +++ b/symplyphysics/laws/thermodynamics/change_in_entropy_of_ideal_gas_from_volume_and_temperature.py @@ -15,13 +15,14 @@ **Conditions:** #. The gas is ideal. + +.. + TODO refactor `mass / molar_mass` into `amount_of_substance` """ from sympy import Eq, solve, log from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, symbols, @@ -29,12 +30,9 @@ quantities, ) -entropy_change = Symbol("entropy_change", units.energy / units.temperature) +entropy_change = symbols.entropy """ -Entropy change during the transition between the two states. - -Symbol: - :code:`S` +:symbols:`entropy` change during the transition between the two states. """ mass = symbols.mass @@ -42,67 +40,47 @@ :symbols:`mass` of the gas. """ -molar_mass = Symbol("molar_mass", units.mass / units.amount_of_substance) +molar_mass = symbols.molar_mass """ -Molar mass, or molecular weight, of the gas. - -Symbol: - :code:`M` +:symbols:`molar_mass`, or molecular weight, of the gas. """ -molar_isochoric_heat_capacity = Symbol( - "molar_isochoric_heat_capacity", units.energy / (units.temperature * units.amount_of_substance)) +molar_isochoric_heat_capacity = clone_as_symbol( + symbols.molar_heat_capacity, + display_symbol="c_Vm", + display_latex="c_{V, m}", +) """ -Heat capacity at constant volume per unit amount of substance. - -Symbol: - :code:`C_V` - -Latex: - :math:`C_V` +:symbols:`molar_heat_capacity` at constant volume. """ -final_temperature = clone_as_symbol(symbols.temperature, display_symbol="T1", display_latex="T_1") +final_temperature = clone_as_symbol(symbols.temperature, subscript="1") """ :symbols:`temperature` of the final state. """ -initial_temperature = clone_as_symbol(symbols.temperature, display_symbol="T0", display_latex="T_0") +initial_temperature = clone_as_symbol(symbols.temperature, subscript="0") """ :symbols:`temperature` of the initial state. """ -final_volume = Symbol("final_volume", units.volume) +final_volume = clone_as_symbol(symbols.volume, subscript="1") """ -Volume of the final state. - -Symbol: - :code:`V1` - -Latex: - :math:`V_1` +:symbols:`volume` of the final state. """ -initial_volume = Symbol("initial_volume", units.volume) +initial_volume = clone_as_symbol(symbols.volume, subscript="0") """ -Volume of the initial state. - -Symbol: - :code:`V0` - -Latex: - :math:`V_0` +:symbols:`volume` of the initial state. """ law = Eq(entropy_change, (mass / molar_mass) * ((molar_isochoric_heat_capacity * log(final_temperature / initial_temperature)) + (quantities.molar_gas_constant * log(final_volume / initial_volume)))) -r""" -:code:`S = (m / M) * (C_V * log(T1 / T0) + R * log(V1 / V0))` +""" +:laws:symbol:: -Latex: - .. math:: - S = \frac{m}{M} \left( C_V \log \frac{T_1}{T_0} + R \log \frac{V_1}{V_0} \right) +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/chemical_potential_is_gibbs_energy_per_particle.py b/symplyphysics/laws/thermodynamics/chemical_potential_is_gibbs_energy_per_particle.py index 3d166378a..b0607b1ee 100644 --- a/symplyphysics/laws/thermodynamics/chemical_potential_is_gibbs_energy_per_particle.py +++ b/symplyphysics/laws/thermodynamics/chemical_potential_is_gibbs_energy_per_particle.py @@ -9,47 +9,32 @@ from sympy import Eq from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, + symbols, ) -chemical_potential = Symbol("chemical_potential", units.energy) +chemical_potential = symbols.chemical_potential r""" -Chemical potential of the system. - -Symbol: - :code:`mu` - -Latex: - :math:`\mu` +:symbols:`chemical_potential` of the system. """ -gibbs_energy = Symbol("gibbs_energy", units.energy) +gibbs_energy = symbols.gibbs_energy """ -Gibbs energy of the system. - -Symbol: - :code:`G` +:symbols:`gibbs_energy` of the system. """ -particle_count = Symbol("particle_count") +particle_count = symbols.particle_count """ -Number of particles in the system. - -Symbol: - :code:`N` +:symbols:`particle_count` of the system. """ law = Eq(chemical_potential, gibbs_energy / particle_count) -r""" -:code:`mu = G / N` +""" +:laws:symbol:: -Latex: - .. math:: - \mu = \frac{G}{N} +:laws:latex:: """ # TODO: derive law from the extensive property of chemical potential diff --git a/symplyphysics/laws/thermodynamics/chemical_potential_is_particle_count_derivative_of_enthalpy.py b/symplyphysics/laws/thermodynamics/chemical_potential_is_particle_count_derivative_of_enthalpy.py index 089bc830c..b3eb81243 100644 --- a/symplyphysics/laws/thermodynamics/chemical_potential_is_particle_count_derivative_of_enthalpy.py +++ b/symplyphysics/laws/thermodynamics/chemical_potential_is_particle_count_derivative_of_enthalpy.py @@ -9,69 +9,47 @@ from sympy import Eq, Derivative, Point2D from symplyphysics import ( - units, - dimensionless, Quantity, - Symbol, - Function, validate_input, validate_output, + symbols, + clone_as_function, ) from symplyphysics.core.geometry.line import two_point_function -chemical_potential = Symbol("chemical_potential", units.energy) +chemical_potential = symbols.chemical_potential r""" -Chemical potential of the system. - -Symbol: - :code:`mu` - -Latex: - :math:`\mu` +:symbols:`chemical_potential` of the system. """ -enthalpy = Function("enthalpy", units.energy) +entropy = symbols.entropy """ -Enthalpy as a function of its natural variables. - -Symbol: - :code:`H(S, p, N)` +:symbols:`entropy` of the system. """ -particle_count = Symbol("particle_count", dimensionless) +pressure = symbols.pressure """ -Number of particles in the system. - -Symbol: - :code:`N` +:symbols:`pressure` inside the system. """ -entropy = Symbol("entropy", units.energy / units.temperature) +particle_count = symbols.particle_count """ -Entropy of the system. - -Symbol: - :code:`S` +:symbols:`particle_count` of the system. """ -pressure = Symbol("pressure", units.pressure) +enthalpy = clone_as_function(symbols.enthalpy, [entropy, pressure, particle_count]) """ -Pressure inside the system. - -Symbol: - :code:`p` +:symbols:`enthalpy` as a function of its natural variables. """ law = Eq( chemical_potential, Derivative(enthalpy(entropy, pressure, particle_count), particle_count), ) -r""" -:code:`mu = Derivative(H(S, p, N), N)` +""" +:laws:symbol:: -Latex: - .. math:: - \mu = \left( \frac{\partial H}{\partial N} \right)_{S, p} +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/chemical_potential_is_particle_count_derivative_of_free_energy.py b/symplyphysics/laws/thermodynamics/chemical_potential_is_particle_count_derivative_of_free_energy.py index 4d695773c..5fb1dc8e5 100644 --- a/symplyphysics/laws/thermodynamics/chemical_potential_is_particle_count_derivative_of_free_energy.py +++ b/symplyphysics/laws/thermodynamics/chemical_potential_is_particle_count_derivative_of_free_energy.py @@ -10,77 +10,52 @@ from sympy import Eq, Derivative, Point2D from symplyphysics import ( symbols, - units, - dimensionless, Quantity, - Symbol, - Function, validate_input, validate_output, + clone_as_function, ) from symplyphysics.core.geometry.line import two_point_function -# Law: mu = (dF/dN)_(T, V) -## mu - chemical potential -## F = F(T, V, N) - [Helmholtz free energy](./helmholtz_free_energy_via_internal_energy.py) -## N - particle count -## T - temperature -## V - volume -## (d/dN)_(T, V) - derivative w.r.t. particle count at constant temperature and volume - -chemical_potential = Symbol("chemical_potential", units.energy) +chemical_potential = symbols.chemical_potential r""" -Chemical potential of the system. - -Symbol: - :code:`mu` - -Latex: - :math:`\mu` +:symbols:`chemical_potential` of the system. """ -free_energy = Function("free_energy", units.energy) +temperature = symbols.temperature """ -Helmholtz free energy of the system as a function of its natural variables. - -.. - TODO add link to definition file - -Symbol: - :code:`F` +:symbols:`temperature` of the system. """ -particle_count = Symbol("particle_count", dimensionless) +volume = symbols.volume """ -Number of particles in the system. - -Symbol: - :code:`N` +:symbols:`volume` of the system. """ -temperature = symbols.temperature +particle_count = symbols.particle_count """ -:symbols:`temperature` of the system. +:symbols:`particle_count` of the system. """ -volume = Symbol("volume", units.volume) +free_energy = clone_as_function( + symbols.helmholtz_free_energy, + [temperature, volume, particle_count], +) """ -Volume of the system. +Helmholtz free energy of the system as a function of its natural variables. -Symbol: - :code:`V` +.. + TODO add link to definition file """ law = Eq( chemical_potential, Derivative(free_energy(temperature, volume, particle_count), particle_count), ) -r""" -:code:`mu = Derivative(F(T, V, N), N)` +""" +:laws:symbol:: -Latex: - .. math:: - \mu = \left( \frac{\partial F}{\partial N} \right)_{T, V} +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/chemical_potential_is_particle_count_derivative_of_gibbs_energy.py b/symplyphysics/laws/thermodynamics/chemical_potential_is_particle_count_derivative_of_gibbs_energy.py index 8454a2a03..f5a304d36 100644 --- a/symplyphysics/laws/thermodynamics/chemical_potential_is_particle_count_derivative_of_gibbs_energy.py +++ b/symplyphysics/laws/thermodynamics/chemical_potential_is_particle_count_derivative_of_gibbs_energy.py @@ -10,66 +10,49 @@ from sympy import Eq, Derivative, Point2D from symplyphysics import ( symbols, - units, - dimensionless, Quantity, - Symbol, - Function, validate_input, validate_output, + clone_as_function, ) from symplyphysics.core.geometry.line import two_point_function -chemical_potential = Symbol("chemical_potential", units.energy) +chemical_potential = symbols.chemical_potential r""" -Chemical potential of the system. - -Symbol: - :code:`mu` - -Latex: - :math:`\mu` +:symbols:`chemical_potential` of the system. """ -gibbs_energy = Function("gibbs_energy", units.energy) +temperature = symbols.temperature """ -Gibbs energy of the system as a function of its natural variables. - -Symbol: - :code:`G(T, p, N)` +:symbols:`temperature` of the system. """ -particle_count = Symbol("particle_count", dimensionless) +pressure = symbols.pressure """ -Number of particles in the system. - -Symbol: - :code:`N` +:symbols:`pressure` inside the system. """ -temperature = symbols.temperature +particle_count = symbols.particle_count """ -:symbols:`temperature` of the system. +:symbols:`particle_count` of the system. """ -pressure = Symbol("pressure", units.pressure) +gibbs_energy = clone_as_function( + symbols.gibbs_energy, + [temperature, pressure, particle_count] +) """ -Pressure inside the system. - -Symbol: - :code:`p` +:symbols:`gibbs_energy` of the system as a function of its natural variables. """ law = Eq( chemical_potential, Derivative(gibbs_energy(temperature, pressure, particle_count), particle_count), ) -r""" -:code:`mu = Derivative(G(T, p, N), N)` +""" +:laws:symbol:: -Latex: - .. math:: - \mu = \left( \frac{\partial G}{\partial N} \right)_{T, p} +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/chemical_potential_is_particle_count_derivative_of_internal_energy.py b/symplyphysics/laws/thermodynamics/chemical_potential_is_particle_count_derivative_of_internal_energy.py index 2427f18e1..66f1f4b8b 100644 --- a/symplyphysics/laws/thermodynamics/chemical_potential_is_particle_count_derivative_of_internal_energy.py +++ b/symplyphysics/laws/thermodynamics/chemical_potential_is_particle_count_derivative_of_internal_energy.py @@ -9,69 +9,50 @@ from sympy import Eq, Derivative, Point2D from symplyphysics import ( - units, - dimensionless, Quantity, - Symbol, - Function, validate_input, validate_output, + symbols, + clone_as_function, ) from symplyphysics.core.geometry.line import two_point_function -chemical_potential = Symbol("chemical_potential", units.energy) +chemical_potential = symbols.chemical_potential r""" -Chemical potential of the system. - -Symbol: - :code:`mu` - -Latex: - :math:`\mu` +:symbols:`chemical_potential` of the system. """ -internal_energy = Function("internal_energy", units.energy) +entropy = symbols.entropy """ -Internal energy of the system as a function of its natural variables. - -Symbol: - :code:`U` +:symbols:`entropy` of the system. """ -particle_count = Symbol("particle_count", dimensionless) +volume = symbols.volume """ -Number of particles in the system. - -Symbol: - :code:`N` +:symbols:`volume` of the system. """ -entropy = Symbol("entropy", units.energy / units.temperature) +particle_count = symbols.particle_count """ -Entropy of the system. - -Symbol: - :code:`S` +:symbols:`particle_count` of the system. """ -volume = Symbol("volume", units.volume) +internal_energy = clone_as_function( + symbols.internal_energy, + [entropy, volume, particle_count], +) """ -Volume of the system. - -Symbol: - :code:`V` +:symbols:`internal_energy` of the system as a function of its natural variables. """ law = Eq( chemical_potential, Derivative(internal_energy(entropy, volume, particle_count), particle_count), ) -r""" -:code:`mu = Derivative(U(S, V, N), N)` +""" +:laws:symbol:: -Latex: - .. math:: - \mu = \left( \frac{\partial U}{\partial N} \right)_{S, V} +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/chemical_potential_of_ideal_gas.py b/symplyphysics/laws/thermodynamics/chemical_potential_of_ideal_gas.py index 78e5184a1..658e0df27 100644 --- a/symplyphysics/laws/thermodynamics/chemical_potential_of_ideal_gas.py +++ b/symplyphysics/laws/thermodynamics/chemical_potential_of_ideal_gas.py @@ -16,24 +16,16 @@ from sympy import Eq, log from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, symbols, quantities, ) -chemical_potential = Symbol("chemical_potential", units.energy) +chemical_potential = symbols.chemical_potential r""" -Chemical potential of ideal gas. - -Symbol: - :code:`mu` - -Latex: - :math:`\mu` +:symbols:`chemical_potential` of ideal gas. """ temperature = symbols.temperature @@ -41,33 +33,23 @@ :symbols:`temperature` of the gas. """ -concentration = Symbol("concentration", 1 / units.volume) +concentration = symbols.number_density """ -Concentration of the gas, or particle count per unit volume. - -Symbol: - :code:`n` +Concentration of the gas, or :symbols:`number_density`. """ -thermal_wavelength = Symbol("thermal_wavelength", units.length) -r""" -:doc:`Thermal de Broglie wavelength ` of the gas. - -Symbol: - :code:`lambda` - -Latex: - :math:`\lambda` +thermal_wavelength = symbols.thermal_wavelength +""" +:symbols:`thermal_wavelength` of the gas. Also see :doc:`Thermal de Broglie wavelength +`. """ law = Eq(chemical_potential, quantities.boltzmann_constant * temperature * log(concentration * thermal_wavelength**3)) -r""" -:code:`mu = k_B * T * log(n * lambda^3)` +""" +:laws:symbol:: -Latex: - .. math:: - \mu = k_\text{B} T \log \left( n \lambda^3 \right) +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/classical_isochoric_molar_heat_capacity_of_solids.py b/symplyphysics/laws/thermodynamics/classical_isochoric_molar_heat_capacity_of_solids.py index 061a3fd69..5c0e5f394 100644 --- a/symplyphysics/laws/thermodynamics/classical_isochoric_molar_heat_capacity_of_solids.py +++ b/symplyphysics/laws/thermodynamics/classical_isochoric_molar_heat_capacity_of_solids.py @@ -16,32 +16,27 @@ from sympy import Eq from symplyphysics import ( - units, Quantity, - Symbol, validate_output, quantities, + symbols, + clone_as_symbol, ) -isochoric_molar_heat_capacity = Symbol( - "isochoric_molar_heat_capacity", units.energy / (units.temperature * units.amount_of_substance)) -r""" -Heat capacity at constant volume per unit amount of substance. - -Symbol: - :code:`C_V` - -Latex: - :math:`C_V` +isochoric_molar_heat_capacity = clone_as_symbol( + symbols.molar_heat_capacity, + display_symbol="c_pm", + display_latex="c_{p, m}", +) +""" +:symbols:`molar_heat_capacity` at constant pressure. """ law = Eq(isochoric_molar_heat_capacity, 3 * quantities.molar_gas_constant) -r""" -:code:`C_V = 3 * R` +""" +:laws:symbol:: -Latex: - .. math:: - C_V = 3 R +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/compressibility_factor_via_intermolecular_force_potential.py b/symplyphysics/laws/thermodynamics/compressibility_factor_via_intermolecular_force_potential.py index b8fe17c62..2f6e31e49 100644 --- a/symplyphysics/laws/thermodynamics/compressibility_factor_via_intermolecular_force_potential.py +++ b/symplyphysics/laws/thermodynamics/compressibility_factor_via_intermolecular_force_potential.py @@ -1,4 +1,4 @@ -r""" +""" Compressibility factor via intermolecular force potential ========================================================= @@ -23,12 +23,11 @@ from sympy import Eq, Integral, pi, exp, S from symplyphysics import ( clone_as_symbol, + clone_as_function, symbols, units, - dimensionless, Quantity, Symbol, - Function, validate_input, validate_output, convert_to_float, @@ -37,47 +36,43 @@ from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.laws.chemistry.potential_energy_models import hard_spheres_potential -compressibility_factor = Symbol("compressibility_factor", dimensionless, positive=True) +compressibility_factor = symbols.compressibility_factor """ -:doc:`Compressibility factor ` of the gas. - -Symbol: - :code:`Z` +:symbols:`compressibility_factor` of the gas. Also see :doc:`Compressibility factor +`. """ -particle_count = Symbol("particle_count", dimensionless, integer=True, positive=True) +particle_count = clone_as_symbol( + symbols.particle_count, + integer=True, + positive=True, +) """ -Number of particles in the system. - -Symbol: - :code:`N` +:symbols:`particle_count` of the system. """ -volume = Symbol("volume", units.volume, positive=True) +volume = clone_as_symbol(symbols.volume, positive=True) """ -Volume of the system. - -Symbol: - :code:`V` +:symbols:`volume` of the system. """ -intermolecular_distance = Symbol("intermolecular_distance", units.length, positive=True) +intermolecular_distance = clone_as_symbol( + symbols.distance, + display_symbol="r", + display_latex="r", + positive=True, +) """ -Distance between gas molecules. - -Symbol: - :code:`r` +:symbols:`distance` between gas molecules. """ -intermolecular_force_potential = Function("intermolecular_force_potential", units.energy, real=True) -r""" -Intermolecular force potential as a function of intermolecular distance. - -Symbol: - :code:`phi(r)` - -Latex: - :math:`\varphi(r)` +intermolecular_force_potential = clone_as_function( + symbols.potential_energy, + [intermolecular_distance], + real=True, +) +""" +Intermolecular force potential as a function of :attr:`~intermolecular_distance`. See :symbols:`potential_energy`. """ temperature = clone_as_symbol(symbols.temperature, positive=True) @@ -91,13 +86,10 @@ (quantities.boltzmann_constant * temperature))) * intermolecular_distance**2, (intermolecular_distance, 0, S.Infinity), )) -r""" -:code:`Z = 1 + 2 * pi * (N / V) * Integral((1 - exp(-1 * phi(r) / (k_B * T))) * r^2, (r, 0, Infinity))` +""" +:laws:symbol:: -Latex: - .. math:: - Z = 1 + \frac{2 \pi N}{V} - \int \limits_0^{\infty} \left( 1 - \exp{\left( - \frac{\varphi(r)}{k_\text{B} T} \right)} \right) r^2 dr +:laws:latex:: """ # Calculate the compressibility factor for the model of hard spheres diff --git a/symplyphysics/laws/thermodynamics/diffusion_coefficient_of_spherical_brownian_particles_from_temperature_and_dynamic_viscosity.py b/symplyphysics/laws/thermodynamics/diffusion_coefficient_of_spherical_brownian_particles_from_temperature_and_dynamic_viscosity.py index 6f7d1aa32..0c2aa9b1c 100644 --- a/symplyphysics/laws/thermodynamics/diffusion_coefficient_of_spherical_brownian_particles_from_temperature_and_dynamic_viscosity.py +++ b/symplyphysics/laws/thermodynamics/diffusion_coefficient_of_spherical_brownian_particles_from_temperature_and_dynamic_viscosity.py @@ -24,16 +24,18 @@ #. Low Reynolds number, i.e. non-turbulent flow. """ -from sympy import (Eq, solve, pi) -from symplyphysics import (symbols, units, Quantity, Symbol, validate_input, validate_output, - quantities) - -diffusion_coefficient = Symbol("diffusion_coefficient", units.area / units.time) +from sympy import Eq, solve, pi +from symplyphysics import ( + symbols, + Quantity, + validate_input, + validate_output, + quantities, +) + +diffusion_coefficient = symbols.diffusion_coefficient """ -Diffusion coefficient of the particles. - -Symbol: - :code:`D` +:symbols:`diffusion_coefficient` of the particles. """ temperature = symbols.temperature @@ -41,34 +43,23 @@ :symbols:`temperature` of the system. """ -particle_radius = Symbol("particle_radius", units.length) +particle_radius = symbols.radius """ -Radius of the particles. - -Symbol: - :code:`r` +:symbols:`radius` of the particles. """ -dynamic_viscosity = Symbol("dynamic_viscosity", units.pressure * units.time) -r""" -Dynamic viscosity of the particles. - -Symbol: - :code:`eta` - -Latex: - :math:`\eta` +dynamic_viscosity = symbols.dynamic_viscosity +""" +:symbols:`dynamic_viscosity` of the particles. """ law = Eq( diffusion_coefficient, quantities.molar_gas_constant * temperature / (6 * quantities.avogadro_constant * pi * particle_radius * dynamic_viscosity)) -r""" -:code:`D = (R * T) / (6 * N_A * pi * r * eta)` +""" +:laws:symbol:: -Latex: - .. math:: - D = \frac{R T}{6 N_\text{A} \pi r \eta} +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/diffusion_flux_from_diffusion_coefficient_and_concentration_gradient.py b/symplyphysics/laws/thermodynamics/diffusion_flux_from_diffusion_coefficient_and_concentration_gradient.py index df1b6e94a..249432e0c 100644 --- a/symplyphysics/laws/thermodynamics/diffusion_flux_from_diffusion_coefficient_and_concentration_gradient.py +++ b/symplyphysics/laws/thermodynamics/diffusion_flux_from_diffusion_coefficient_and_concentration_gradient.py @@ -16,49 +16,41 @@ #. The mixture is ideal. """ -from sympy import (Eq, Derivative) -from symplyphysics import (units, Function, Quantity, Symbol, validate_input, validate_output) - -diffusion_flux = Function("diffusion_flux", units.amount_of_substance / (units.area * units.time)) +from sympy import Eq, Derivative +from symplyphysics import ( + Quantity, + validate_input, + validate_output, + symbols, + clone_as_function, +) + +position = symbols.position """ -Diffusion flux. - -Symbol: - :code:`J(x)` +:symbols:`position` of particles. """ -diffusion_coefficient = Symbol("diffusion_coefficient", units.area / units.time) +diffusion_flux = clone_as_function(symbols.diffusion_flux, [position]) """ -Diffusion coefficient. - -Symbol: - :code:`D` +:symbols:`diffusion_flux` as a function of :attr:`~position`. """ -concentration = Function("concentration", units.amount_of_substance / units.volume) +diffusion_coefficient = symbols.diffusion_coefficient """ -Concentration of particles as a function of position. - -Symbol: - :code:`n(x)` +:symbols:`diffusion_coefficient`. """ -position = Symbol("position", units.length) +concentration = clone_as_function(symbols.molar_concentration, [position]) """ -Position of particles. - -Symbol: - :code:`x` +:symbols:`molar_concentration` of particles as a function of :attr:`~position`. """ law = Eq(diffusion_flux(position), -diffusion_coefficient * Derivative(concentration(position), position)) -r""" -:code:`J(x) = -1 * D * Derivative(n(x), x)` +""" +:laws:symbol:: -Latex: - .. math:: - J(x) = - D \frac{d n}{d x} +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/dynamic_viscosity_of_gas_from_control_viscosity_and_temperature.py b/symplyphysics/laws/thermodynamics/dynamic_viscosity_of_gas_from_control_viscosity_and_temperature.py index c4c002a87..fb1b8d254 100644 --- a/symplyphysics/laws/thermodynamics/dynamic_viscosity_of_gas_from_control_viscosity_and_temperature.py +++ b/symplyphysics/laws/thermodynamics/dynamic_viscosity_of_gas_from_control_viscosity_and_temperature.py @@ -11,34 +11,33 @@ #. The gas is ideal. +**Links:** + +#. `Sutherland model `__. + .. TODO Rename file """ -from sympy import (Eq, solve) -from symplyphysics import (clone_as_symbol, symbols, units, Quantity, Symbol, validate_input, - validate_output) - -dynamic_viscosity = Symbol("dynamic_viscosity", units.pressure * units.time) -r""" -Dynamic viscosity of the gas at temperature :math:`T`. - -Symbol: - :code:`mu` - -Latex: - :math:`\mu` +from sympy import Eq, solve, Rational +from symplyphysics import ( + clone_as_symbol, + symbols, + units, + Quantity, + SymbolNew, + validate_input, + validate_output, +) + +dynamic_viscosity = symbols.dynamic_viscosity +""" +:symbols:`dynamic_viscosity` of the gas at the given :attr:`~temperature`. """ -reference_dynamic_viscosity = Symbol("reference_dynamic_viscosity", units.pressure * units.time) -r""" -Dynamic viscosity of the gas at the reference temperature :math:`T_0`. - -Symbol: - :code:`mu_0` - -Latex: - :math:`\mu_0` +reference_dynamic_viscosity = clone_as_symbol(symbols.dynamic_viscosity, subscript="0") +""" +:symbols:`dynamic_viscosity` of the gas at the :attr:`~reference_temperature`. """ temperature = symbols.temperature @@ -46,31 +45,27 @@ :symbols:`temperature` at which the viscosity value is calculated. """ -reference_temperature = clone_as_symbol(symbols.temperature, - display_symbol="T0", - display_latex="T_0") +reference_temperature = clone_as_symbol(symbols.temperature, subscript="0") """ :symbols:`temperature` at which the reference viscosity value is calculated. """ -sutherland_constant = Symbol("sutherland_constant", units.temperature) +sutherland_constant = SymbolNew("C", units.temperature) """ Sutherland constant of the gas. -Symbol: - :code:`C` +.. + NOTE probably add this to `symbols`? this constant is specific to the Sutherland model """ law = Eq( dynamic_viscosity, reference_dynamic_viscosity * ((reference_temperature + sutherland_constant) / - (temperature + sutherland_constant)) * (temperature / reference_temperature)**1.5) -r""" -:code:`mu = mu_0 * ((T0 + C) / (T + C)) * (T / T0)^(3/2)` + (temperature + sutherland_constant)) * (temperature / reference_temperature)**Rational(3, 2)) +""" +:laws:symbol:: -Latex: - .. math:: - \mu = \mu_0 \left( \frac{T_0 + C}{T + C} \right) \left( \frac{T}{T_0} \right)^{3 / 2} +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/efficiency_of_heat_engine.py b/symplyphysics/laws/thermodynamics/efficiency_of_heat_engine.py index a38d29b75..a02353ed9 100644 --- a/symplyphysics/laws/thermodynamics/efficiency_of_heat_engine.py +++ b/symplyphysics/laws/thermodynamics/efficiency_of_heat_engine.py @@ -8,55 +8,34 @@ from sympy import Eq, solve from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, - dimensionless, convert_to_float, + symbols, + clone_as_symbol, ) -heat_from_heater = Symbol("heat_from_heater", units.energy) +heat_from_heater = clone_as_symbol(symbols.heat, subscript="h") r""" -Heat transferred by the heater to the heat engine. - -Symbol: - :code:`Q_h` - -Latex: - :math:`Q_\text{h}` +:symbols:`heat` transferred by the heater to the heat engine. """ -heat_to_refrigerator = Symbol("heat_to_refrigerator", units.energy) +heat_to_refrigerator = clone_as_symbol(symbols.heat, subscript="r") r""" -Heat transferred by the heat engine to the refrigerator. - -Symbol: - :code:`Q_r` - -Latex: - :math:`Q_\text{r}` +:symbols:`heat` transferred by the heat engine to the refrigerator. """ -efficiency = Symbol("efficiency", dimensionless) -r""" -Efficiency of the heat engine. - -Symbol: - :code:`eta` - -Latex: - :math:`\eta` +efficiency = symbols.thermal_efficiency +""" +:symbols:`thermal_efficiency` of the heat engine. """ law = Eq(efficiency, 1 - heat_to_refrigerator / heat_from_heater) -r""" -:code:`eta = 1 - Q_r / Q_h` +""" +:laws:symbol:: -Latex: - .. math:: - \eta = 1 - \frac{Q_\text{r}}{Q_\text{h}} +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/enthalpy_derivative_via_volume_derivative.py b/symplyphysics/laws/thermodynamics/enthalpy_derivative_via_volume_derivative.py index 1d0058257..8c7de056e 100644 --- a/symplyphysics/laws/thermodynamics/enthalpy_derivative_via_volume_derivative.py +++ b/symplyphysics/laws/thermodynamics/enthalpy_derivative_via_volume_derivative.py @@ -14,54 +14,42 @@ from symplyphysics import ( units, Quantity, - Symbol, - Function, validate_input, validate_output, symbols, + clone_as_function, ) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.core.geometry.line import two_point_function, Point2D -enthalpy = Function("enthalpy", units.energy) -""" -Enthalpy of the system. - -Symbol: - :code:`H(T, p)` -""" - temperature = symbols.temperature """ :symbols:`temperature` of the system. """ -pressure = Symbol("pressure", units.pressure) +pressure = symbols.pressure """ -Pressure inside the system. - -Symbol: - :code:`p` +:symbols:`pressure` inside the system. """ -volume = Function("volume", units.volume) +enthalpy = clone_as_function(symbols.enthalpy, [temperature, pressure]) +""" +:symbols:`enthalpy` of the system. """ -Volume of the system. -Symbol: - :code:`V` +volume = clone_as_function(symbols.volume, [temperature, pressure]) +""" +:symbols:`volume` of the system. """ law = Eq( Derivative(enthalpy(temperature, pressure), pressure), volume(temperature, pressure) - temperature * Derivative(volume(temperature, pressure), temperature)) -r""" -:code:`Derivative(H(T, p), p) = V(T, p) - T * Derivative(V(T, p), T)` +""" +:laws:symbol:: -Latex: - .. math:: - \left( \frac{\partial H}{\partial p} \right)_T = V(T, p) - T \left( \frac{\partial V}{\partial T} \right)_p +:laws:latex:: """ # TODO: Derive from differential of enthalpy and Maxwell relation diff --git a/symplyphysics/laws/thermodynamics/enthalpy_is_internal_energy_plus_pressure_energy.py b/symplyphysics/laws/thermodynamics/enthalpy_is_internal_energy_plus_pressure_energy.py index 91ecd1452..cf1d6d21d 100644 --- a/symplyphysics/laws/thermodynamics/enthalpy_is_internal_energy_plus_pressure_energy.py +++ b/symplyphysics/laws/thermodynamics/enthalpy_is_internal_energy_plus_pressure_energy.py @@ -9,52 +9,37 @@ from sympy import Eq from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, + symbols, ) -enthalpy = Symbol("enthalpy", units.energy) +enthalpy = symbols.enthalpy """ -Enthalpy of the system. - -Symbol: - :code:`H` +:symbols:`enthalpy` of the system. """ -internal_energy = Symbol("internal_energy", units.energy) +internal_energy = symbols.internal_energy """ -Internal energy of the system. - -Symbol: - :code:`U` +:symbols:`internal_energy` of the system. """ -pressure = Symbol("pressure", units.pressure) +pressure = symbols.pressure """ -Pressure inside the system. - -Symbol: - :code:`p` +:symbols:`pressure` inside the system. """ -volume = Symbol("volume", units.volume) +volume = symbols.volume """ -Volume of the system. - -Symbol: - :code:`V` +:symbols:`volume` of the system. """ law = Eq(enthalpy, internal_energy + pressure * volume) -r""" -:code:`H = U + p * V` +""" +:laws:symbol:: -Latex - .. math:: - H = U + p V +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/enthalpy_via_gibbs_energy.py b/symplyphysics/laws/thermodynamics/enthalpy_via_gibbs_energy.py index 1a949fb51..65151ca32 100644 --- a/symplyphysics/laws/thermodynamics/enthalpy_via_gibbs_energy.py +++ b/symplyphysics/laws/thermodynamics/enthalpy_via_gibbs_energy.py @@ -14,12 +14,10 @@ from sympy import Eq, Derivative, Point2D, solve from symplyphysics import ( symbols, - units, Quantity, - Symbol, - Function, validate_input, validate_output, + clone_as_function, ) from symplyphysics.core.geometry.line import two_point_function from symplyphysics.core.expr_comparisons import expr_equals @@ -28,20 +26,9 @@ entropy_is_derivative_of_gibbs_energy as entropy_law, ) -enthalpy = Symbol("enthalpy", units.energy) +enthalpy = symbols.enthalpy """ -Enthalpy of the system. - -Symbol: - :code:`H` -""" - -gibbs_energy = Function("gibbs_energy", units.energy) -""" -Gibbs energy of the system. - -Symbol: - :code:`G(T, p)` +:symbols:`enthalpy` of the system. """ temperature = symbols.temperature @@ -49,24 +36,24 @@ :symbols:`temperature` of the system. """ -pressure = Symbol("pressure", units.pressure) +pressure = symbols.pressure +""" +:symbols:`pressure` inside the system. """ -Pressure inside the system. -Symbol: - :code:`p` +gibbs_energy = clone_as_function(symbols.gibbs_energy, [temperature, pressure]) +""" +:symbols:`gibbs_energy` of the system as a function of :attr:`~temperature` and :attr:`~pressure`. """ law = Eq( enthalpy, gibbs_energy(temperature, pressure) - temperature * Derivative(gibbs_energy(temperature, pressure), temperature)) -r""" -:code:`H = G(T, p) - T * Derivative(G(T, p), T)` +""" +:laws:symbol:: -Latex: - .. math:: - H = G(T, p) - T \left( \frac{\partial G}{\partial T} \right)_p +:laws:latex:: """ # Derive from definition of Gibbs energy and thermodynamical relations diff --git a/symplyphysics/laws/thermodynamics/entropy_derivative_via_volume_derivative.py b/symplyphysics/laws/thermodynamics/entropy_derivative_via_volume_derivative.py index 3ec15ae70..46367002e 100644 --- a/symplyphysics/laws/thermodynamics/entropy_derivative_via_volume_derivative.py +++ b/symplyphysics/laws/thermodynamics/entropy_derivative_via_volume_derivative.py @@ -23,51 +23,39 @@ symbols, units, Quantity, - Symbol, - Function, validate_input, validate_output, + clone_as_function, ) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.laws.thermodynamics import gibbs_energy_differential -entropy = Function("entropy", units.energy / units.temperature) +temperature = symbols.temperature """ -Entropy of the system as a function of temperature and pressure. - -Symbol: - :code:`S(T, p)` +:symbols:`temperature` of the system. """ -pressure = Symbol("pressure", units.pressure) +pressure = symbols.pressure """ -Pressure inside the system. - -Symbol: - :code:`p` +:symbols:`pressure` inside the system. """ -volume = Function("volume", units.volume) +entropy = clone_as_function(symbols.entropy, [temperature, pressure]) """ -Volume of the system as a function of temperature and pressure. - -Symbol: - :code:`V(T, p)` +:symbols:`entropy` of the system as a function of temperature and pressure. """ -temperature = symbols.temperature +volume = clone_as_function(symbols.volume, [temperature, pressure]) """ -:symbols:`temperature` of the system. +:symbols:`volume` of the system as a function of temperature and pressure. """ law = Eq(Derivative(entropy(temperature, pressure), pressure), -1 * Derivative(volume(temperature, pressure), temperature)) -r""" -:code:`Derivative(S(T, p), p) = -1 * Derivative(V(T, p), T)` +""" +:laws:symbol:: -Latex: - .. math:: - \left( \frac{\partial S}{\partial p} \right)_T = - \left( \frac{\partial V}{\partial T} \right)_p +:laws:latex:: """ # Derive from expression of Gibbs energy differential diff --git a/symplyphysics/laws/thermodynamics/entropy_from_statistical_weight.py b/symplyphysics/laws/thermodynamics/entropy_from_statistical_weight.py index 1e2678253..78d2e4f50 100644 --- a/symplyphysics/laws/thermodynamics/entropy_from_statistical_weight.py +++ b/symplyphysics/laws/thermodynamics/entropy_from_statistical_weight.py @@ -10,39 +10,51 @@ #. :quantity_notation:`boltzmann_constant`. """ -from sympy import Eq, solve, symbols, Function as SymFunction, dsolve, log -from symplyphysics import (units, Quantity, Symbol, validate_input, validate_output, dimensionless, - assert_equal, quantities) +from sympy import ( + Eq, + solve, + symbols as sym_symbols, + Function as SymFunction, + dsolve, + log, +) +from symplyphysics import ( + units, + Quantity, + validate_input, + validate_output, + assert_equal, + quantities, + symbols, + clone_as_symbol, + clone_as_function, +) from symplyphysics.core.expr_comparisons import expr_equals -from symplyphysics.laws.chemistry import avogadro_constant_is_particle_count_over_amount_of_substance as avogadro_law +from symplyphysics.laws.chemistry import ( + avogadro_constant_is_particle_count_over_amount_of_substance as avogadro_law, +) from symplyphysics.laws.thermodynamics import ( - change_in_entropy_of_ideal_gas_from_volume_and_temperature as entropy_change_law,) + change_in_entropy_of_ideal_gas_from_volume_and_temperature as entropy_change_law, +) from symplyphysics.laws.quantities import ( - quantity_is_molar_quantity_times_amount_of_substance as molar_qty_law,) + quantity_is_molar_quantity_times_amount_of_substance as molar_qty_law, +) -entropy = Symbol("entropy", units.energy / units.temperature) +entropy = symbols.entropy """ -Entropy of the system. - -Symbol: - :code:`S` +:symbols:`entropy` of the system. """ -statistical_weight = Symbol("statistical_weight", dimensionless) +statistical_weight = symbols.statistical_weight """ -Statistical weight of the system's state. - -Symbol: - :code:`W` +:symbols:`statistical_weight` of the system's state. """ law = Eq(entropy, quantities.boltzmann_constant * log(statistical_weight)) -r""" -:code:`S = k_B * log(W)` +""" +:laws:symbol:: -Latex: - .. math:: - S = k_\text{B} \log W +:laws:latex:: """ # Derive the law from the properties of entropy @@ -56,10 +68,10 @@ # respectively. If we join the two subsystems into one, the probability of the total system # will be `P_12`, and using their independence we have `P_12 = P_1 * P_2`. -_time = symbols("time", real=True) -_first_probability = symbols("first_probability", cls=SymFunction, positive=True)(_time) -_second_probability = symbols("second_probability", cls=SymFunction, positive=True)(_time) -_entropy = symbols("entropy", cls=SymFunction, real=True) +_time = clone_as_symbol(symbols.time, real=True) +_first_probability = sym_symbols("first_probability", cls=SymFunction, positive=True)(_time) +_second_probability = sym_symbols("second_probability", cls=SymFunction, positive=True)(_time) +_entropy = clone_as_function(symbols.entropy, real=True) # FIXME: use law for this step # According to thermodynamics, the entropy of a complex system should equal the sum of entropies @@ -96,15 +108,15 @@ # 2. Since `f(P)` is universal for all bodies, the constant is universal for all bodies as well. -_probability = symbols("probability", positive=True) -_equation_constant = symbols("equation_constant", real=True) +_probability = sym_symbols("probability", positive=True) +_equation_constant = sym_symbols("equation_constant", real=True) _entropy_eqn = Eq( _differential_property.lhs.subs(_first_probability, _probability), _equation_constant, ) -_integration_constant = symbols("integration_constant", real=True) +_integration_constant = sym_symbols("integration_constant", real=True) # Now we can integrate the above differential property and show that the integration constant is # actually zero. @@ -137,10 +149,9 @@ # Then the probability of finding one molecule in `V_0` is `V_0 / V`, and the probability # of finding all `N` particles is `(V_0 / V)**N` -_volume, _total_volume, _particle_count = symbols( - "volume total_volume particle_count", - positive=True, -) +_volume = clone_as_symbol(symbols.volume, positive=True) +_total_volume = clone_as_symbol(symbols.volume, positive=True) +_particle_count = clone_as_symbol(symbols.particle_count, positive=True) # FIXME: use law for this step _probability_via_volume = (_volume / _total_volume)**_particle_count @@ -151,10 +162,8 @@ # constant temperature and particle count. Then we can find the entropy of the two states # via the above formula. -_first_volume, _second_volume = symbols( - "first_volume second_volume", - positive=True, -) +_first_volume = clone_as_symbol(symbols.volume, positive=True) +_second_volume = clone_as_symbol(symbols.volume, positive=True) _entropy_difference_derived = (_entropy_via_volume.subs(_volume, _second_volume) - _entropy_via_volume.subs(_volume, _first_volume)).simplify() diff --git a/symplyphysics/laws/thermodynamics/entropy_is_derivative_of_free_energy.py b/symplyphysics/laws/thermodynamics/entropy_is_derivative_of_free_energy.py index a1db84073..a8f2f9f48 100644 --- a/symplyphysics/laws/thermodynamics/entropy_is_derivative_of_free_energy.py +++ b/symplyphysics/laws/thermodynamics/entropy_is_derivative_of_free_energy.py @@ -7,32 +7,18 @@ from sympy import Eq, Derivative, solve from symplyphysics import ( - units, - dimensionless, Quantity, - Symbol, - Function, validate_input, validate_output, symbols, + clone_as_function, ) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.laws.thermodynamics import free_energy_differential -entropy = Symbol("entropy", units.energy / units.temperature) +entropy = symbols.entropy """ -Entropy of the system. - -Symbol: - :code:`S` -""" - -free_energy = Function("free_energy", units.energy) -""" -Free energy of the system. - -Symbol: - :code:`F(T, V, N)` +:symbols:`entropy` of the system. """ temperature = symbols.temperature @@ -40,29 +26,30 @@ :symbols:`temperature` of the system. """ -volume = Symbol("volume", units.volume) +volume = symbols.volume """ -Volume of the system. - -Symbol: - :code:`V` +:symbols:`volume` of the system. """ -particle_count = Symbol("particle_count", dimensionless) +particle_count = symbols.particle_count +""" +:symbols:`particle_count` of the system. """ -Number of particles in the system. -Symbol: - :code:`N` +free_energy = clone_as_function( + symbols.helmholtz_free_energy, + [temperature, volume, particle_count], +) +""" +:symbols:`helmholtz_free_energy` of the system as a function of :attr:`~temperature`, +:attr:`~volume`, and :attr:`~particle_count`. """ law = Eq(entropy, -1 * Derivative(free_energy(temperature, volume, particle_count), temperature)) -r""" -:code:`S = -1 * Derivative(F(T, V, N), T)` +""" +:laws:symbol:: -Latex: - .. math:: - S = - \left( \frac{\partial F}{\partial T} \right)_{V, N} +:laws:latex:: """ # Derive from expression of free energy differential diff --git a/symplyphysics/laws/thermodynamics/entropy_is_derivative_of_gibbs_energy.py b/symplyphysics/laws/thermodynamics/entropy_is_derivative_of_gibbs_energy.py index 1a36e2481..ddb6b0d56 100644 --- a/symplyphysics/laws/thermodynamics/entropy_is_derivative_of_gibbs_energy.py +++ b/symplyphysics/laws/thermodynamics/entropy_is_derivative_of_gibbs_energy.py @@ -7,32 +7,18 @@ from sympy import Eq, Derivative, solve from symplyphysics import ( - units, - dimensionless, Quantity, - Symbol, - Function, validate_input, validate_output, symbols, + clone_as_function, ) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.laws.thermodynamics import gibbs_energy_differential -entropy = Symbol("entropy", units.energy / units.temperature) +entropy = symbols.entropy """ -Entropy of the system. - -Symbol: - :code:`S` -""" - -gibbs_energy = Function("gibbs_energy", units.energy) -""" -Gibbs energy of the system. - -Symbol: - :code:`G(T, p, N)` +:symbols:`entropy` of the system. """ temperature = symbols.temperature @@ -40,29 +26,30 @@ :symbols:`temperature` of the system. """ -pressure = Symbol("pressure", units.pressure) +pressure = symbols.pressure """ -Pressure inside the system. - -Symbol: - :code:`p` +:symbols:`pressure` inside the system. """ -particle_count = Symbol("particle_count", dimensionless) +particle_count = symbols.particle_count +""" +:symbols:`particle_count` of the system. """ -Number of particles in the system. -Symbol: - :code:`N` +gibbs_energy = clone_as_function( + symbols.gibbs_energy, + [temperature, pressure, particle_count], +) +""" +:symbols:`gibbs_energy` of the system as a function of :attr:`~temperature`, :attr:`~pressure`, +and :attr:`~particle_count`. """ law = Eq(entropy, -1 * Derivative(gibbs_energy(temperature, pressure, particle_count), temperature)) -r""" -:code:`S = -1 * Derivative(G(T, p, N), T)` +""" +:laws:symbol:: -Latex: - .. math:: - S = - \left( \frac{\partial G}{\partial T} \right)_{p, N} +:laws:latex:: """ # Derive from the expression of Gibbs energy differential diff --git a/symplyphysics/laws/thermodynamics/euler_relations/enthalpy_formula.py b/symplyphysics/laws/thermodynamics/euler_relations/enthalpy_formula.py index a81312d73..3b440dce0 100644 --- a/symplyphysics/laws/thermodynamics/euler_relations/enthalpy_formula.py +++ b/symplyphysics/laws/thermodynamics/euler_relations/enthalpy_formula.py @@ -7,23 +7,19 @@ **Notes:** -#. This formula words for a single-component system. For multi-component system replace the +#. This formula works for a single-component system. For a multi-component system replace the product of chemical potential and particle count with a sum over each type of components. """ from sympy import Eq -from symplyphysics import (units, dimensionless, Quantity, Symbol, validate_input, validate_output, - symbols) +from symplyphysics import Quantity, validate_input, validate_output, symbols from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.laws.thermodynamics import enthalpy_is_internal_energy_plus_pressure_energy as enthalpy_def from symplyphysics.laws.thermodynamics.euler_relations import internal_energy_formula -enthalpy = Symbol("enthalpy", units.energy) +enthalpy = symbols.enthalpy """ -:doc:`Enthalpy ` of the system. - -Symbol: - :code:`H` +:symbols:`enthalpy` of the system. Also see :doc:`laws.thermodynamics.enthalpy_is_internal_energy_plus_pressure_energy`. """ temperature = symbols.temperature @@ -31,41 +27,27 @@ :symbols:`temperature` of the system. """ -entropy = Symbol("entropy", units.energy / units.temperature) +entropy = symbols.entropy """ -:doc:`Entropy ` of the system. - -Symbol: - :code:`S` +:symbols:`entropy` of the system. Also see :doc:`laws.thermodynamics.entropy_change_in_reversible_process`. """ -chemical_potential = Symbol("chemical_potential", units.energy) -r""" -:doc:`Chemical potential ` -of the system. - -Symbol: - :code:`mu` - -Latex: - :math:`\mu` +chemical_potential = symbols.chemical_potential """ - -particle_count = Symbol("particle_count", dimensionless) +:symbols:`chemical_potential` of the system. Also see +:doc:`laws.thermodynamics.chemical_potential_is_particle_count_derivative_of_internal_energy`. """ -Number of particles in the system. -Symbol: - :code:`N` +particle_count = symbols.particle_count +""" +:symbols:`particle_count` of the system. """ law = Eq(enthalpy, temperature * entropy + chemical_potential * particle_count) -r""" -:code:`H = T * S + mu * N` +""" +:laws:symbol:: -Latex: - .. math:: - H = T S + \mu N +:laws:latex:: """ # Derive from enthalpy definition and internal energy Euler relation diff --git a/symplyphysics/laws/thermodynamics/euler_relations/gibbs_energy_formula.py b/symplyphysics/laws/thermodynamics/euler_relations/gibbs_energy_formula.py index 8213e06b9..a779ff30e 100644 --- a/symplyphysics/laws/thermodynamics/euler_relations/gibbs_energy_formula.py +++ b/symplyphysics/laws/thermodynamics/euler_relations/gibbs_energy_formula.py @@ -7,57 +7,36 @@ **Notes:** -#. This formula words for a single-component system. For multi-component system replace the +#. This formula works for a single-component system. For a multi-component system replace the right-hand side with a sum over each type of components. """ from sympy import Eq -from symplyphysics import ( - units, - dimensionless, - Quantity, - Symbol, - validate_input, - validate_output, -) +from symplyphysics import Quantity, validate_input, validate_output, symbols from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.laws.thermodynamics import gibbs_energy_via_enthalpy as gibbs_energy_def from symplyphysics.laws.thermodynamics.euler_relations import enthalpy_formula -gibbs_energy = Symbol("gibbs_energy", units.energy) +gibbs_energy = symbols.gibbs_energy """ -Gibbs energy of the system. - -Symbol: - :code:`G` +:symbols:`gibbs_energy` of the system. """ -chemical_potential = Symbol("chemical_potential", units.energy) -r""" -Chemical potential of the system. - -Symbol: - :code:`mu` - -Latex: - :math:`\mu` +chemical_potential = symbols.chemical_potential """ - -particle_count = Symbol("particle_count", dimensionless) +:symbols:`chemical_potential` of the system. """ -Number of particles in the system. -Symbol: - :code:`N` +particle_count = symbols.particle_count +""" +:symbols:`particle_count` of the system. """ law = Eq(gibbs_energy, chemical_potential * particle_count) -r""" -:code:`G = mu * N` +""" +:laws:symbol:: -Latex: - .. math:: - G = \mu N +:laws:latex:: """ # Derive from Gibbs energy definition and enthalpy formula diff --git a/symplyphysics/laws/thermodynamics/euler_relations/internal_energy_formula.py b/symplyphysics/laws/thermodynamics/euler_relations/internal_energy_formula.py index 046075380..9af48aa56 100644 --- a/symplyphysics/laws/thermodynamics/euler_relations/internal_energy_formula.py +++ b/symplyphysics/laws/thermodynamics/euler_relations/internal_energy_formula.py @@ -7,27 +7,16 @@ **Notes:** -#. This formula words for a single-component system. For multi-component system replace the +#. This formula works for a single-component system. For a multi-component system replace the product of chemical potential and particle count with a sum over each type of components. """ from sympy import Eq -from symplyphysics import ( - units, - dimensionless, - Quantity, - Symbol, - validate_input, - validate_output, - symbols, -) +from symplyphysics import Quantity, validate_input, validate_output, symbols -internal_energy = Symbol("internal_energy", units.energy) +internal_energy = symbols.internal_energy """ -Internal energy of the system. - -Symbol: - :code:`U` +:symbols:`internal_energy` of the system. """ temperature = symbols.temperature @@ -35,57 +24,37 @@ :symbols:`temperature` of the system. """ -entropy = Symbol("entropy", units.energy / units.temperature) +entropy = symbols.entropy """ -Entropy of the system. - -Symbol: - :code:`S` +:symbols:`entropy` of the system. """ -pressure = Symbol("pressure", units.pressure) +pressure = symbols.pressure """ -Pressure in the system. - -Symbol: - :code:`p` +:symbols:`pressure` in the system. """ -volume = Symbol("volume", units.volume) +volume = symbols.volume """ -Volume of the system. - -Symbol: - :code:`V` +:symbols:`volume` of the system. """ -chemical_potential = Symbol("chemical_potential", units.energy) -r""" -Chemical potential of the system. - -Symbol: - :code:`mu` - -Latex: - :math:`\mu` +chemical_potential = symbols.chemical_potential """ - -particle_count = Symbol("particle_count", dimensionless) +:symbols:`chemical_potential` of the system. """ -Number of particles in the system. -Symbol: - :code:`N` +particle_count = symbols.particle_count +""" +:symbols:`particle_count` of the system. """ law = Eq(internal_energy, temperature * entropy - pressure * volume + chemical_potential * particle_count) -r""" -:code:`U = T * S - p * V + mu * N` +""" +:laws:symbol:: -Latex: - .. math:: - U = T S - p V + \mu N +:laws:latex:: """ # TODO: derive from Euler's theorem and internal energy differential diff --git a/symplyphysics/laws/thermodynamics/gibbs_energy_via_enthalpy.py b/symplyphysics/laws/thermodynamics/gibbs_energy_via_enthalpy.py index a15861494..6039ccc28 100644 --- a/symplyphysics/laws/thermodynamics/gibbs_energy_via_enthalpy.py +++ b/symplyphysics/laws/thermodynamics/gibbs_energy_via_enthalpy.py @@ -8,38 +8,27 @@ conditions. """ -from sympy import (Eq, solve) +from sympy import Eq, solve from symplyphysics import ( symbols, - units, Quantity, - Symbol, validate_input, validate_output, ) -gibbs_energy = Symbol("gibbs_energy", units.energy / units.amount_of_substance) +gibbs_energy = symbols.gibbs_energy """ -Gibbs energy of the system. - -Symbol: - :code:`G` +:symbols:`gibbs_energy` of the system. """ -enthalpy = Symbol("enthalpy", units.energy / units.amount_of_substance) +enthalpy = symbols.enthalpy """ -Enthalpy of the system. - -Symbol: - :code:`H` +:symbols:`enthalpy` of the system. """ -entropy = Symbol("entropy", units.energy / units.amount_of_substance / units.temperature) +entropy = symbols.entropy """ -Entropy of the system. - -Symbol: - :code:`S` +:symbols:`entropy` of the system. """ temperature = symbols.temperature @@ -48,12 +37,10 @@ """ law = Eq(gibbs_energy, enthalpy - temperature * entropy) -r""" -:code:`G = H - T * S` +""" +:laws:symbol:: -Latex: - .. math:: - G = H - T S +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/heat_is_heat_capacity_times_temperature_change.py b/symplyphysics/laws/thermodynamics/heat_is_heat_capacity_times_temperature_change.py index 2f08466fd..5858b961f 100644 --- a/symplyphysics/laws/thermodynamics/heat_is_heat_capacity_times_temperature_change.py +++ b/symplyphysics/laws/thermodynamics/heat_is_heat_capacity_times_temperature_change.py @@ -15,40 +15,39 @@ refer to the differential definition of the heat capacity. """ -from sympy import (Eq, solve) -from symplyphysics import (clone_as_symbol, symbols, units, Quantity, Symbol, validate_input, - validate_output) +from sympy import Eq, solve +from symplyphysics import ( + clone_as_symbol, + symbols, + Quantity, + validate_input, + validate_output, +) -heat = Symbol("heat", units.energy) +heat = symbols.heat """ -Heat received or released by the body. - -Symbol: - :code:`Q` +:symbols:`heat` received or released by the body. """ -heat_capacity = Symbol("heat_capacity", units.energy / units.temperature) +heat_capacity = symbols.heat_capacity """ -Heat capacity of the body. - -Symbol: - :code:`C` +:symbols:`heat_capacity` of the body. """ -temperature_change = clone_as_symbol(symbols.temperature, - display_symbol="dT", - display_latex="\\Delta T") +temperature_change = clone_as_symbol( + symbols.temperature, + display_symbol="Delta(T)", + display_latex="\\Delta T", +) """ Change in the body's :symbols:`temperature` """ law = Eq(heat, heat_capacity * temperature_change) -r""" -:code:`Q = C * dT` +""" +:laws:symbol:: -Latex: - .. math:: - Q = C \Delta T +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/helmholtz_free_energy_via_internal_energy.py b/symplyphysics/laws/thermodynamics/helmholtz_free_energy_via_internal_energy.py index cba8d37ba..9c1505ea6 100644 --- a/symplyphysics/laws/thermodynamics/helmholtz_free_energy_via_internal_energy.py +++ b/symplyphysics/laws/thermodynamics/helmholtz_free_energy_via_internal_energy.py @@ -8,28 +8,20 @@ from sympy import Eq from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, symbols, ) -helmholtz_free_energy = Symbol("helmholtz_free_energy", units.energy) +helmholtz_free_energy = symbols.helmholtz_free_energy """ -Helmholtz free energy of the system. - -Symbol: - :code:`F` +:symbols:`helmholtz_free_energy` of the system. """ -internal_energy = Symbol("internal_energy", units.energy) +internal_energy = symbols.internal_energy """ -Internal energy of the system. - -Symbol: - :code:`U` +:symbols:`internal_energy` of the system. """ temperature = symbols.temperature @@ -37,21 +29,16 @@ :symbols:`temperature` of the system. """ -entropy = Symbol("entropy", units.energy / units.temperature) +entropy = symbols.entropy """ -Entropy of the system. - -Symbol: - :code:`S` +:symbols:`entropy` of the system. """ law = Eq(helmholtz_free_energy, internal_energy - temperature * entropy) -r""" -:code:`F = U - T * S` +""" +:laws:symbol:: -Latex: - .. math:: - F = U - T S +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/internal_energy_of_ideal_gas_via_temperature.py b/symplyphysics/laws/thermodynamics/internal_energy_of_ideal_gas_via_temperature.py index 153b25878..b021fd5b8 100644 --- a/symplyphysics/laws/thermodynamics/internal_energy_of_ideal_gas_via_temperature.py +++ b/symplyphysics/laws/thermodynamics/internal_energy_of_ideal_gas_via_temperature.py @@ -1,4 +1,4 @@ -r""" +""" Internal energy of ideal gas via temperature ============================================ @@ -11,18 +11,23 @@ **Conditions:** #. The gas is ideal. + +.. + TODO replace `mass/molar_mass` with `amount_of_substance` """ -from sympy import (Eq, solve) -from symplyphysics import (units, Quantity, Symbol, validate_input, validate_output, symbols, - quantities) +from sympy import Eq, solve +from symplyphysics import ( + Quantity, + validate_input, + validate_output, + symbols, + quantities, +) -internal_energy = Symbol("energy", units.energy) +internal_energy = symbols.internal_energy """ -Internal energy of the gas. - -Symbol: - :code:`U` +:symbols:`internal_energy` of the gas. """ mass = symbols.mass @@ -35,21 +40,16 @@ :symbols:`temperature` of the gas. """ -molar_mass = Symbol("molar_mass", units.mass / units.amount_of_substance) +molar_mass = symbols.molar_mass """ -Mass of gas per unit amount of substance. - -Symbol: - :code:`M` +:symbols:`molar_mass` of the gas. """ -law = Eq(internal_energy, 1.5 * mass * quantities.molar_gas_constant * temperature / molar_mass) -r""" -:code:`U = (3 / 2) * (m / M) * R * T` +law = Eq(internal_energy, 3 * mass * quantities.molar_gas_constant * temperature / (2 * molar_mass)) +""" +:laws:symbol:: -Latex: - .. math:: - U = \frac{3}{2} \frac{m}{M} R T +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/internal_energy_via_helmholtz_free_energy.py b/symplyphysics/laws/thermodynamics/internal_energy_via_helmholtz_free_energy.py index f34f95f65..554176cc4 100644 --- a/symplyphysics/laws/thermodynamics/internal_energy_via_helmholtz_free_energy.py +++ b/symplyphysics/laws/thermodynamics/internal_energy_via_helmholtz_free_energy.py @@ -12,12 +12,10 @@ from sympy import Eq, Derivative, Point2D, solve from symplyphysics import ( symbols, - units, Quantity, - Symbol, - Function, validate_input, validate_output, + clone_as_function, ) from symplyphysics.core.geometry.line import two_point_function from symplyphysics.core.expr_comparisons import expr_equals @@ -26,20 +24,9 @@ entropy_is_derivative_of_free_energy as entropy_law, ) -internal_energy = Symbol("internal_energy", units.energy) +internal_energy = symbols.internal_energy """ -Internal energy of the system. - -Symbol: - :code:`U` -""" - -free_energy = Function("free_energy", units.energy) -""" -Helmholtz free energy of the system as a function of temperature and volume. - -Symbol: - :code:`F(T, V)` +:symbols:`internal_energy` of the system. """ temperature = symbols.temperature @@ -47,12 +34,14 @@ :symbols:`temperature` of the system. """ -volume = Symbol("volume", units.volume) +volume = symbols.volume +""" +:symbols:`volume` of the system. """ -Volume of the system. -Symbol: - :code:`V` +free_energy = clone_as_function(symbols.helmholtz_free_energy, [temperature, volume]) +""" +:symbols:`helmholtz_free_energy` of the system as a function of temperature and volume. """ # Volume is held constant during the evalution of the derivative @@ -61,12 +50,10 @@ internal_energy, free_energy(temperature, volume) - temperature * Derivative(free_energy(temperature, volume), temperature)) -r""" -:code:`U = F(T, V) - T * Derivative(F(T, V), T)` +""" +:laws:symbol:: -Latex: - .. math:: - U = F(T, V) - T \left( \frac{\partial F}{\partial T} \right)_V +:laws:latex:: """ # Derive from definition of free energy and thermodynamical Maxwell relations diff --git a/symplyphysics/laws/thermodynamics/isentropic_speed_of_sound_via_pressure_derivative.py b/symplyphysics/laws/thermodynamics/isentropic_speed_of_sound_via_pressure_derivative.py index 631444da4..f468e2042 100644 --- a/symplyphysics/laws/thermodynamics/isentropic_speed_of_sound_via_pressure_derivative.py +++ b/symplyphysics/laws/thermodynamics/isentropic_speed_of_sound_via_pressure_derivative.py @@ -12,56 +12,44 @@ from sympy import Eq, sqrt, Derivative from symplyphysics import ( - units, Quantity, - Symbol, - Function, validate_input, validate_output, + symbols, + clone_as_function, + clone_as_symbol, ) -speed_of_sound = Symbol("speed_of_sound", units.velocity) +speed_of_sound = clone_as_symbol( + symbols.speed, + display_symbol="v_s", + display_latex="v_\\text{s}", +) """ -Speed of sound in the fluid. - -Symbol: - :code:`c` +:symbols:`speed` of sound in the fluid. """ -pressure = Function("pressure", units.pressure) +density = symbols.density """ -Pressure inside the fluid. - -Symbol: - :code:`p` +:symbols:`density` of the fluid. """ -density = Symbol("density", units.mass / units.volume) -r""" -Density of the fluid. - -Symbol: - :code:`rho` - -Latex: - :math:`\rho` +entropy = symbols.entropy """ - -entropy = Symbol("entropy", units.energy / units.temperature) +:symbols:`entropy` of the fluid. """ -Entropy of the fluid. -Symbol: - :code:`S` +pressure = clone_as_function(symbols.pressure, [density, entropy]) +""" +:symbols:`pressure` inside the fluid as a function of :attr:`~density` and +:attr:`~entropy`. """ law = Eq(speed_of_sound, sqrt(Derivative(pressure(density, entropy), density))) -r""" -:code:`c = sqrt(Derivative(p(rho, S), rho))` +""" +:laws:symbol:: -Latex: - .. math:: - c = \sqrt{\left( \frac{\partial p}{\partial \rho} \right)_S} +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/isobaric_molar_heat_capacity_of_ideal_gas_via_adiabatic_index.py b/symplyphysics/laws/thermodynamics/isobaric_molar_heat_capacity_of_ideal_gas_via_adiabatic_index.py index 9137b4811..466da11e9 100644 --- a/symplyphysics/laws/thermodynamics/isobaric_molar_heat_capacity_of_ideal_gas_via_adiabatic_index.py +++ b/symplyphysics/laws/thermodynamics/isobaric_molar_heat_capacity_of_ideal_gas_via_adiabatic_index.py @@ -1,4 +1,4 @@ -r""" +""" Isobaric molar heat capacity of ideal gas via adiabatic index ============================================================= @@ -16,13 +16,12 @@ from sympy import Eq, solve from symplyphysics import ( - units, - dimensionless, Quantity, - Symbol, validate_input, validate_output, quantities, + symbols, + clone_as_symbol, ) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.definitions import heat_capacity_ratio @@ -31,37 +30,27 @@ from symplyphysics.laws.quantities import ( quantity_is_molar_quantity_times_amount_of_substance as molar_qty_law,) -isobaric_molar_heat_capacity = Symbol( - "isobaric_molar_heat_capacity", units.energy / (units.temperature * units.amount_of_substance)) -r""" -Heat capacity at constant pressure per unit amount of substance. - -Symbol: - :code:`C_p` - -Latex: - :math:`C_p` +isobaric_molar_heat_capacity = clone_as_symbol( + symbols.molar_heat_capacity, + display_symbol="c_pm", + display_latex="c_{p, m}", +) +""" +:symbols:`molar_heat_capacity` at constant :symbols:`pressure`. """ -adiabatic_index = Symbol("adiabatic_index", dimensionless) -r""" -Adiabatic index, or :doc:`heat capacity ratio ` of the gas. - -Symbol: - :code:`gamma` - -Latex: - :math:`\gamma` +adiabatic_index = symbols.adiabatic_index +""" +:symbols:`adiabatic_index`, or :doc:`heat capacity ratio ` +of the gas. """ law = Eq(isobaric_molar_heat_capacity, quantities.molar_gas_constant * adiabatic_index / (adiabatic_index - 1)) -r""" -:code:`C_p = R * gamma / (gamma - 1)` +""" +:laws:symbol:: -Latex: - .. math:: - C_p = \frac{R \gamma}{\gamma - 1} +:laws:latex:: """ # Derive law from the Mayer's law for heat capacities and the definition of adiabatic index diff --git a/symplyphysics/laws/thermodynamics/isochoric_and_isobaric_heat_capacities_of_homogeneous_substance.py b/symplyphysics/laws/thermodynamics/isochoric_and_isobaric_heat_capacities_of_homogeneous_substance.py index 2075ca277..209dd1eee 100644 --- a/symplyphysics/laws/thermodynamics/isochoric_and_isobaric_heat_capacities_of_homogeneous_substance.py +++ b/symplyphysics/laws/thermodynamics/isochoric_and_isobaric_heat_capacities_of_homogeneous_substance.py @@ -2,49 +2,41 @@ Isochoric and isobaric heat capacities of homogeneous substance =============================================================== -The *Mayer's relation* is the relation between heat capacity at constant pressure and heat +The **Mayer's relation** is the relation between heat capacity at constant pressure and heat capacity at constant volume. In the current form it is applicable to any homogeneous substance, not just ideal gases. """ from sympy import Eq, solve from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, symbols, + clone_as_symbol, ) -isobaric_heat_capacity = Symbol("isobaric_heat_capacity", units.energy / units.temperature) -r""" -Heat capacity at constant pressure. - -Symbol: - :code:`C_p` - -Latex: - :math:`C_p` +isobaric_heat_capacity = clone_as_symbol( + symbols.heat_capacity, + display_symbol="C_p", + display_latex="C_p", +) """ - -isochoric_heat_capacity = Symbol("isochoric_heat_capacity", units.energy / units.temperature) -r""" -Heat capacity at constant volume. - -Symbol: - :code:`C_V` - -Latex: - :math:`C_V` +:symbols:`heat_capacity` at constant :symbols:`pressure`. """ -volume = Symbol("volume", units.volume) +isochoric_heat_capacity = clone_as_symbol( + symbols.heat_capacity, + display_symbol="C_V", + display_latex="C_V", +) +""" +:symbols:`heat_capacity` at constant :symbols:`volume`. """ -Volume of the substance. -Symbol: - :code:`V` +volume = symbols.volume +""" +:symbols:`volume` of the substance. """ temperature = symbols.temperature @@ -52,39 +44,32 @@ :symbols:`temperature` of the substance. """ -thermal_expansion_coefficient = Symbol("thermal_expansion_coefficient", 1 / units.temperature) -r""" -:doc:`Thermal volumetric expansion coefficient ` -of the substance. - -Symbol: - :code:`alpha_V` - -Latex: - :math:`\alpha_V` +thermal_expansion_coefficient = clone_as_symbol( + symbols.thermal_expansion_coefficient, + subscript="V", +) +""" +:symbols:`thermal_expansion_coefficient` of the substance. Also see :doc:`Thermal volumetric expansion +coefficient `. """ -isothermal_compressibility = Symbol("isothermal_compressibility", 1 / units.pressure) -r""" -:doc:`Isothermal compressibility ` of the substance. - -Symbol: - :code:`beta_T` - -Latex: - :math:`\beta_T` +isothermal_compressibility = clone_as_symbol( + symbols.thermodynamic_compressibility, + subscript="T", +) +""" +:symbols:`thermodynamic_compressibility` of the substance. Also see :doc:`Isothermal compressibility +`. """ law = Eq( isobaric_heat_capacity - isochoric_heat_capacity, volume * temperature * thermal_expansion_coefficient**2 / isothermal_compressibility, ) -r""" -:code:`C_p - C_V = V * T * (alpha_V)^2 / beta_T` +""" +:laws:symbol:: -Latex: - .. math:: - C_p - C_V = V T \frac{\alpha_V^2}{\beta_T} +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/isochoric_and_isobaric_heat_capacity_of_ideal_gas.py b/symplyphysics/laws/thermodynamics/isochoric_and_isobaric_heat_capacity_of_ideal_gas.py index 317dbb0c4..3dc4150d2 100644 --- a/symplyphysics/laws/thermodynamics/isochoric_and_isobaric_heat_capacity_of_ideal_gas.py +++ b/symplyphysics/laws/thermodynamics/isochoric_and_isobaric_heat_capacity_of_ideal_gas.py @@ -1,8 +1,8 @@ -r""" +""" Isochoric and isobaric heat capacities of ideal gas =================================================== -Mayer's relation is the relation between heat capacity at constant pressure and that at +The **Mayer's relation** is the relation between heat capacity at constant pressure and that at constant volume in the case of an ideal gas. **Notation:** @@ -16,54 +16,37 @@ from sympy import Eq, solve from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, quantities, + symbols, + clone_as_symbol, ) -isobaric_heat_capacity = Symbol("isobaric_heat_capacity", units.energy / units.temperature) +isobaric_heat_capacity = clone_as_symbol(symbols.heat_capacity, subscript="p") """ -Heat capacity of gas at constant pressure. - -Symbol: - :code:`C_p` - -Latex: - :math:`C_p` +:symbols:`heat_capacity` of gas at constant :symbols:`pressure`. """ -isochoric_heat_capacity = Symbol("isochoric_heat_capacity", units.energy / units.temperature) +isochoric_heat_capacity = clone_as_symbol(symbols.heat_capacity, subscript="V") """ -Heat capacity of gas at constant volume. - -Symbol: - :code:`C_V` - -Latex: - :math:`C_V` +:symbols:`heat_capacity` of gas at constant :symbols:`volume`. """ -amount_of_substance = Symbol("amount_of_substance", units.amount_of_substance) +amount_of_substance = symbols.amount_of_substance """ -Amount of gas substance. - -Symbol: - :code:`n` +:symbols:`amount_of_substance`. """ law = Eq( isobaric_heat_capacity - isochoric_heat_capacity, amount_of_substance * quantities.molar_gas_constant, ) -r""" -:code:`C_p - C_V = n * R` +""" +:laws:symbol:: -Latex: - .. math:: - C_p - C_V = n R +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/isochoric_molar_heat_capacity_of_ideal_gas_via_adiabatic_index.py b/symplyphysics/laws/thermodynamics/isochoric_molar_heat_capacity_of_ideal_gas_via_adiabatic_index.py index 3db203d90..88909fcce 100644 --- a/symplyphysics/laws/thermodynamics/isochoric_molar_heat_capacity_of_ideal_gas_via_adiabatic_index.py +++ b/symplyphysics/laws/thermodynamics/isochoric_molar_heat_capacity_of_ideal_gas_via_adiabatic_index.py @@ -1,4 +1,4 @@ -r""" +""" Isochoric molar heat capacity of ideal gas via adiabatic index ============================================================== @@ -12,13 +12,12 @@ from sympy import Eq, solve from symplyphysics import ( - units, - dimensionless, Quantity, - Symbol, validate_input, validate_output, quantities, + symbols, + clone_as_symbol, ) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.definitions import heat_capacity_ratio @@ -27,36 +26,25 @@ from symplyphysics.laws.quantities import ( quantity_is_molar_quantity_times_amount_of_substance as molar_qty_law,) -isochoric_molar_heat_capacity = Symbol( - "isochoric_molar_heat_capacity", units.energy / (units.temperature * units.amount_of_substance)) -r""" -Heat capacity of ideal gas at constant volume per unit amount of substance. - -Symbol: - :code:`C_V` - -Latex: - :math:`C_V` +isochoric_molar_heat_capacity = clone_as_symbol( + symbols.molar_heat_capacity, + display_symbol="c_Vm", + display_latex="c_{V, m}", +) +""" +:symbols:`molar_heat_capacity` at constant :symbols:`volume`. """ -adiabatic_index = Symbol("adiabatic_index", dimensionless) -r""" -Adiabatic index, also known as :doc:`heat capacity ratio `, of the gas. - -Symbol: - :code:`gamma` - -Latex: - :math:`\gamma` +adiabatic_index = symbols.adiabatic_index +""" +:symbols:`adiabatic_index`, also known as :doc:`heat capacity ratio `, of the gas. """ law = Eq(isochoric_molar_heat_capacity, quantities.molar_gas_constant / (adiabatic_index - 1)) -r""" -:code:`C_V = R / (gamma - 1)` +""" +:laws:symbol:: -Latex: - .. math:: - C_V = \frac{R}{\gamma - 1} +:laws:latex:: """ # Derive law from the Mayer's law for heat capacities and the definition of adiabatic index diff --git a/symplyphysics/laws/thermodynamics/isochoric_molar_heat_capacity_of_ideal_gas_via_degrees_of_freedom.py b/symplyphysics/laws/thermodynamics/isochoric_molar_heat_capacity_of_ideal_gas_via_degrees_of_freedom.py index 74ff52365..851af3bc1 100644 --- a/symplyphysics/laws/thermodynamics/isochoric_molar_heat_capacity_of_ideal_gas_via_degrees_of_freedom.py +++ b/symplyphysics/laws/thermodynamics/isochoric_molar_heat_capacity_of_ideal_gas_via_degrees_of_freedom.py @@ -20,49 +20,39 @@ **Conditions:** #. Gas is ideal. -#. Works in the classical theory of heat capacity of gases. For a more accurate represention refer to +#. Works in the classical theory of heat capacity of gases. For a more accurate representation refer to the quantum theory, which accounts for the "freezing" of the degrees of freedom and other phenomena. """ from sympy import Eq from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, quantities, + symbols, + clone_as_symbol, ) -isochoric_molar_heat_capacity = Symbol( - "isochoric_molar_heat_capacity", - units.energy / (units.temperature * units.amount_of_substance), +isochoric_molar_heat_capacity = clone_as_symbol( + symbols.molar_heat_capacity, + display_symbol="c_Vm", + display_latex="c_{V, m}", ) -r""" -Heat capacity of ideal gas at constant volume per unit amount of substance. - -Symbol: - :code:`C_V` - -Latex: - :math:`C_V` """ - -degrees_of_freedom = Symbol("degrees_of_freedom", integer=True) +:symbols:`molar_heat_capacity` at constant :symbols:`volume`. """ -Number of degrees of freedom of gas molecules. -Symbol: - :code:`f` +degrees_of_freedom = symbols.degrees_of_freedom +""" +Number of :symbols:`degrees_of_freedom` of gas molecules. """ law = Eq(isochoric_molar_heat_capacity, (degrees_of_freedom / 2) * quantities.molar_gas_constant) -r""" -:code:`C_V = (f / 2) * R` +""" +:laws:symbol:: -Latex: - .. math:: - C_V = \frac{f}{2} R +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/maxwell_boltzmann_statistics/energy_distribution.py b/symplyphysics/laws/thermodynamics/maxwell_boltzmann_statistics/energy_distribution.py index c33358944..a94d92656 100644 --- a/symplyphysics/laws/thermodynamics/maxwell_boltzmann_statistics/energy_distribution.py +++ b/symplyphysics/laws/thermodynamics/maxwell_boltzmann_statistics/energy_distribution.py @@ -22,7 +22,7 @@ from symplyphysics import ( units, Quantity, - Symbol, + SymbolNew, validate_input, validate_output, clone_as_symbol, @@ -33,22 +33,17 @@ from symplyphysics.laws.dynamics import kinetic_energy_from_mass_and_speed as kinetic_energy_law from symplyphysics.laws.thermodynamics.maxwell_boltzmann_statistics import speed_distribution -energy_distribution_function = Symbol("energy_distribution_function", - 1 / units.energy, - positive=True) +energy = clone_as_symbol(symbols.energy, positive=True) """ -Energy distribution function. - -Symbol: - :code:`f(E)` +:symbols:`energy` of the ensemble. """ -energy = Symbol("energy", units.energy, positive=True) +energy_distribution_function = SymbolNew( + "f(E)", + 1 / units.energy, + positive=True) """ -Energy of the ensemble. - -Symbol: - :code:`E` +:attr:`~energy` distribution function. """ equilibrium_temperature = clone_as_symbol(symbols.temperature, positive=True) @@ -60,12 +55,10 @@ energy_distribution_function, 2 * sqrt(energy / pi) * (quantities.boltzmann_constant * equilibrium_temperature)**Rational(-3, 2) * exp(-1 * energy / (quantities.boltzmann_constant * equilibrium_temperature))) -r""" -:code:`f(E) = 2 * sqrt(E / pi) * (k_B * T)^(3/2) * exp(-1 * E / (k_B * T))` +""" +:laws:symbol:: -Latex: - .. math:: - f(E) = 2 \sqrt \frac{E}{\pi} \left( k_\text{B} T \right)^{3/2} \exp \left( - \frac{E}{k_\text{B} T} \right) +:laws:latex:: """ # Derive from speed distribution and kinetic energy formula diff --git a/symplyphysics/laws/thermodynamics/pressure_and_temperature_in_isochoric_process.py b/symplyphysics/laws/thermodynamics/pressure_and_temperature_in_isochoric_process.py index cdd05eb68..31e9c1786 100644 --- a/symplyphysics/laws/thermodynamics/pressure_and_temperature_in_isochoric_process.py +++ b/symplyphysics/laws/thermodynamics/pressure_and_temperature_in_isochoric_process.py @@ -11,56 +11,49 @@ #. Applies to ideal gases. """ -from sympy import (Eq, solve) -from symplyphysics import (clone_as_symbol, symbols, units, Quantity, Symbol, validate_input, - validate_output) -from symplyphysics.laws.thermodynamics.equations_of_state import ideal_gas_equation as thermodynamics_law - -initial_pressure = Symbol("initial_pressure", units.pressure) +from sympy import Eq, solve +from symplyphysics import ( + clone_as_symbol, + symbols, + Quantity, + validate_input, + validate_output, +) +from symplyphysics.laws.thermodynamics.equations_of_state import ( + ideal_gas_equation as thermodynamics_law, +) + +initial_pressure = clone_as_symbol(symbols.pressure, subscript="0") """ -Initial pressure of the gas. - -Symbol: - :code:`p0` - -Latex: - :math:`p_0` +Initial :symbols:`pressure` of the gas. """ -final_pressure = Symbol("final_pressure", units.pressure) +final_pressure = clone_as_symbol(symbols.pressure, subscript="1") """ -Final pressure of the gas. - -Symbol: - :code:`p1` - -Latex: - :math:`p_1` +Final :symbols:`pressure` of the gas. """ -initial_temperature = clone_as_symbol(symbols.temperature, display_symbol="T0", display_latex="T_0") +initial_temperature = clone_as_symbol(symbols.temperature, subscript="0") """ Initial :symbols:`temperature` of the gas. """ -final_temperature = clone_as_symbol(symbols.temperature, display_symbol="T1", display_latex="T_1") +final_temperature = clone_as_symbol(symbols.temperature, subscript="1") """ Final :symbols:`temperature` of the gas. """ law = Eq(initial_pressure / final_pressure, initial_temperature / final_temperature) -r""" -:code:`p0 / p1 = T0 / T1` +""" +:laws:symbol:: -Latex: - .. math:: - \frac{p_0}{p_1} = \frac{T_0}{T_1} +:laws:latex:: """ ## Derive the same law from the general ideal gas law -_volume_start = Symbol("volume_start", units.volume) -_volume_end = Symbol("volume_end", units.volume) +_volume_start = clone_as_symbol(symbols.volume, subscript="0") +_volume_end = clone_as_symbol(symbols.volume, subscript="1") _isochoric_condition = Eq(_volume_start, _volume_end) diff --git a/symplyphysics/laws/thermodynamics/pressure_and_volume_in_adiabatic_process.py b/symplyphysics/laws/thermodynamics/pressure_and_volume_in_adiabatic_process.py index 063a416da..5f1f6c501 100644 --- a/symplyphysics/laws/thermodynamics/pressure_and_volume_in_adiabatic_process.py +++ b/symplyphysics/laws/thermodynamics/pressure_and_volume_in_adiabatic_process.py @@ -4,12 +4,21 @@ An *adiabatic process* is a type of thermodynamic process that occurs without transferring heat or mass between the thermodynamic system and its environment. + +.. + TODO rename file """ -from sympy import Eq, Rational, solve, Symbol as SymSymbol, Function as SymFunction, dsolve, symbols as sym_symbols -from sympy.abc import t -from symplyphysics import (clone_as_symbol, symbols, units, Quantity, Symbol, dimensionless, - validate_input, validate_output) +from sympy import Eq, Rational, solve, dsolve +from sympy.abc import t as _t +from symplyphysics import ( + clone_as_symbol, + clone_as_function, + symbols, + Quantity, + validate_input, + validate_output, +) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.definitions import heat_capacity_ratio from symplyphysics.laws.thermodynamics import ( @@ -20,83 +29,51 @@ ) from symplyphysics.laws.thermodynamics.equations_of_state import ideal_gas_equation -adiabatic_index = Symbol("adiabatic_index", dimensionless) -r""" -Adiabatic index, also known as :doc:`heat capacity ratio `, of the gas. - -Symbol: - :code:`gamma` - -Latex: - :math:`\gamma` +adiabatic_index = symbols.adiabatic_index +""" +:symbols:`adiabatic_index`, also known as :doc:`heat capacity ratio `, of the gas. """ # Some of the following parameters depend on each other. It is up to user which to choose as known. -initial_temperature = clone_as_symbol(symbols.temperature, display_symbol="T0", display_latex="T_0") +initial_temperature = clone_as_symbol(symbols.temperature, subscript="0") """ Initial :symbols:`temperature` of the system. """ -final_temperature = clone_as_symbol(symbols.temperature, display_symbol="T1", display_latex="T_1") +final_temperature = clone_as_symbol(symbols.temperature, subscript="1") """ Final :symbols:`temperature` of the system. """ -initial_volume = Symbol("initial_volume", units.volume) +initial_volume = clone_as_symbol(symbols.volume, subscript="0") """ -Initial volume of the system. - -Symbol: - :code:`V0` - -Latex: - :math:`V_0` +Initial :symbols:`volume` of the system. """ -final_volume = Symbol("final_volume", units.volume) +final_volume = clone_as_symbol(symbols.volume, subscript="1") """ -Final volume of the system. - -Symbol: - :code:`V1` - -Latex: - :math:`V_1` +Final :symbols:`volume` of the system. """ -initial_pressure = Symbol("initial_pressure", units.pressure) +initial_pressure = clone_as_symbol(symbols.pressure, subscript="0") """ -Initial pressure inside the system. - -Symbol: - :code:`p0` - -Latex: - :math:`p_0` +Initial :symbols:`pressure` inside the system. """ -final_pressure = Symbol("final_pressure", units.pressure) +final_pressure = clone_as_symbol(symbols.pressure, subscript="1") """ -Final pressure inside the system. - -Symbol: - :code:`p1` - -Latex: - :math:`p_1` +Final :symbols:`pressure` inside the system. """ adiabatic_condition = Eq( initial_pressure * (initial_volume**adiabatic_index), final_pressure * (final_volume**adiabatic_index), ) -r""" -:code:`p0 * V0^gamma = p1 * V1^gamma` +""" +:laws:symbol:: -Latex: - .. math:: - p_0 V_0^\gamma = p_1 V_1^\gamma +:laws:latex:: """ eq_start = ideal_gas_equation.law.subs({ @@ -119,13 +96,13 @@ _pressure = ideal_gas_equation.pressure _volume = ideal_gas_equation.volume -_adiabatic_index = Symbol("adiabatic_index", positive=True) +_adiabatic_index = clone_as_symbol(symbols.adiabatic_index, positive=True) _isobaric_heat_capacity = mayers_relation.isobaric_heat_capacity _isochoric_heat_capacity = mayers_relation.isochoric_heat_capacity -_temperature_change = SymSymbol("temperature_change") -_pressure_change = SymSymbol("pressure_change") -_volume_change = SymSymbol("volume_change") +_temperature_change = clone_as_symbol(symbols.temperature) +_pressure_change = clone_as_symbol(symbols.pressure) +_volume_change = clone_as_symbol(symbols.volume) _internal_energy_change_expr = internal_energy_law.law.rhs.subs({ internal_energy_law.temperature_change: _temperature_change, @@ -145,17 +122,17 @@ # Expressing the temperature differential through pressure and volume differentials -_parameterized_pressure = sym_symbols("pressure", cls=SymFunction) -_parameterized_volume = sym_symbols("volume", cls=SymFunction) +_parameterized_pressure = clone_as_function(symbols.pressure) +_parameterized_volume = clone_as_function(symbols.volume) _temperature_change_expr = solve(ideal_gas_equation.law, _temperature)[0].subs({ - _pressure: _parameterized_pressure(t), - _volume: _parameterized_volume(t), -}).diff(t).subs({ - _parameterized_pressure(t).diff(t): _pressure_change, - _parameterized_volume(t).diff(t): _volume_change, - _parameterized_pressure(t): _pressure, - _parameterized_volume(t): _volume, + _pressure: _parameterized_pressure(_t), + _volume: _parameterized_volume(_t), +}).diff(_t).subs({ + _parameterized_pressure(_t).diff(_t): _pressure_change, + _parameterized_volume(_t).diff(_t): _volume_change, + _parameterized_pressure(_t): _pressure, + _parameterized_volume(_t): _volume, }) _mayers_relation = mayers_relation.law.subs(mayers_relation.amount_of_substance, diff --git a/symplyphysics/laws/thermodynamics/pressure_and_volume_in_isothermal_process.py b/symplyphysics/laws/thermodynamics/pressure_and_volume_in_isothermal_process.py index ae500de45..b567f3c8b 100644 --- a/symplyphysics/laws/thermodynamics/pressure_and_volume_in_isothermal_process.py +++ b/symplyphysics/laws/thermodynamics/pressure_and_volume_in_isothermal_process.py @@ -3,71 +3,53 @@ ========================================= A thermodynamic process is isothermal when the temperature of the system stays the same. -Boyle's law states that the product of pressure and volume is constant during an isothermal +**Boyle's law** states that the product of pressure and volume is constant during an isothermal process. """ -from sympy import (Eq, solve) -from symplyphysics import (units, Quantity, Symbol, validate_input, validate_output) -from symplyphysics.laws.thermodynamics.equations_of_state import ideal_gas_equation as thermodynamics_law - -initial_pressure = Symbol("initial_pressure", units.pressure) +from sympy import Eq, solve +from symplyphysics import ( + Quantity, + validate_input, + validate_output, + symbols, + clone_as_symbol, +) +from symplyphysics.laws.thermodynamics.equations_of_state import ( + ideal_gas_equation as thermodynamics_law, +) + +initial_pressure = clone_as_symbol(symbols.pressure, subscript="0") """ -Initial pressure inside the system. - -Symbol: - :code:`p0` - -Latex: - :math:`p_0` +Initial :symbols:`pressure` inside the system. """ -final_pressure = Symbol("final_pressure", units.pressure) +final_pressure = clone_as_symbol(symbols.pressure, subscript="1") """ -Final pressure inside the system. - -Symbol: - :code:`p1` - -Latex: - :math:`p_1` +Final :symbols:`pressure` inside the system. """ -initial_volume = Symbol("initial_volume", units.volume) +initial_volume = clone_as_symbol(symbols.volume, subscript="0") """ -Initial volume of the system. - -Symbol: - :code:`V0` - -Latex: - :math:`V_0` +Initial :symbols:`volume` of the system. """ -final_volume = Symbol("final_volume", units.volume) +final_volume = clone_as_symbol(symbols.volume, subscript="1") """ -Final volume of the system. - -Symbol: - :code:`V1` - -Latex: - :math:`V_1` +Final :symbols:`volume` of the system. """ law = Eq(initial_pressure * initial_volume, final_pressure * final_volume) -r""" -:code:`p0 * V0 = p1 * V1` +""" +:laws:symbol:: -Latex: - .. math:: - p_0 V_0 = p_1 V_1 +:laws:latex:: """ ## Derive the same law from the general ideal gas law -_temperature_start = Symbol("temperature_start", units.temperature) -_temperature_end = Symbol("temperature_end", units.temperature) +_temperature_start = clone_as_symbol(symbols.temperature, subscript="0") +_temperature_end = clone_as_symbol(symbols.temperature, subscript="1") _isothermal_condition = Eq(_temperature_start, _temperature_end) diff --git a/symplyphysics/laws/thermodynamics/pressure_of_ideal_gas_from_height_and_temperature.py b/symplyphysics/laws/thermodynamics/pressure_of_ideal_gas_from_height_and_temperature.py index e0215593b..424ce1160 100644 --- a/symplyphysics/laws/thermodynamics/pressure_of_ideal_gas_from_height_and_temperature.py +++ b/symplyphysics/laws/thermodynamics/pressure_of_ideal_gas_from_height_and_temperature.py @@ -15,27 +15,24 @@ #. The gas is in a uniform gravity field. """ -from sympy import (Eq, solve, exp) -from symplyphysics import (symbols, units, Quantity, Symbol, validate_input, validate_output, - quantities) - -final_pressure = Symbol("final_pressure", units.pressure) +from sympy import Eq, solve, exp +from symplyphysics import ( + symbols, + Quantity, + validate_input, + validate_output, + quantities, + clone_as_symbol, +) + +final_pressure = symbols.pressure """ -Pressure of the gas at final height. - -Symbol: - :code:`p` +:symbols:`pressure` of the gas at final height. """ -initial_pressure = Symbol("initial_pressure", units.pressure) +initial_pressure = clone_as_symbol(symbols.pressure, subscript="0") """ -Pressure of the gas at initial height. - -Symbol: - :code:`p0` - -Latex: - :math:`p_0` +:symbols:`pressure` of the gas at initial height. """ molecular_mass = symbols.mass @@ -43,15 +40,13 @@ :symbols:`mass` of a single gas molecule. """ -height_change = Symbol("height_change", units.length) -r""" -Change in height between :math:`p_0` and :math:`p`. - -Symbol: - :code:`dh` - -Latex: - :math:`\Delta h` +height_change = clone_as_symbol( + symbols.height, + display_symbol="Delta(h)", + display_latex="\\Delta h", +) +""" +Change in :symbols:`height` between :attr:`~initial_pressure` and :attr:`~final_pressure`. """ temperature = symbols.temperature @@ -64,12 +59,10 @@ initial_pressure * exp(-quantities.acceleration_due_to_gravity * molecular_mass * height_change / (quantities.boltzmann_constant * temperature))) -r""" -:code:`p = p0 * exp(-1 * g * m * dh / (k_B * T))` +""" +:laws:symbol:: -Latex: - .. math:: - p = p_0 \exp \left( - \frac{g m \Delta h}{k_\text{B} T} \right) +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/probability_of_finding_ideal_gas_molecules_in_volume.py b/symplyphysics/laws/thermodynamics/probability_of_finding_ideal_gas_molecules_in_volume.py index 467a878cf..241d7b04e 100644 --- a/symplyphysics/laws/thermodynamics/probability_of_finding_ideal_gas_molecules_in_volume.py +++ b/symplyphysics/laws/thermodynamics/probability_of_finding_ideal_gas_molecules_in_volume.py @@ -15,57 +15,39 @@ from sympy import Eq from symplyphysics import ( Quantity, - Symbol, - dimensionless, - units, validate_input, validate_output, convert_to_float, + clone_as_symbol, + symbols, ) from symplyphysics.core.symbols.probability import Probability -probability = Symbol("probability", dimensionless) +probability = clone_as_symbol(symbols.probability) """ -Probability of finding :math:`N` gas particles in volume :math:`V`. - -Symbol: - :code:`P` +:symbols:`probability` of finding :attr:`~particle_count` gas particles in :attr:`~partial_volume`. """ -total_volume = Symbol("total_volume", units.volume) +total_volume = clone_as_symbol(symbols.volume, subscript="0") """ -Total volume of the region. - -Symbol: - :code:`V0` - -Latex: - :math:`V_0` +Total :symbols:`volume` of the region. """ -partial_volume = Symbol("partial_volume", units.volume) +partial_volume = symbols.volume """ -Volume of part of the container where we are looking for the particles. - -Symbol: - :code:`V` +:symbols:`volume` of part of the container where we are looking for the particles. """ -particle_count = Symbol("particle_count", dimensionless, integer=True) +particle_count = clone_as_symbol(symbols.particle_count, integer=True) """ -Number of gas particles in :math:`V`. - -Symbol: - :code:`N` +:symbols:`particle_count` in :attr:`~partial_volume`. """ law = Eq(probability, (partial_volume / total_volume)**particle_count) -r""" -:code:`P = (V / V0)^N` +""" +:laws:symbol:: -Latex: - .. math:: - P = \left( \frac{V}{V_0} \right)^N +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/quantum_isochoric_molar_heat_capacity_of_solids.py b/symplyphysics/laws/thermodynamics/quantum_isochoric_molar_heat_capacity_of_solids.py index 85a3415f0..696138253 100644 --- a/symplyphysics/laws/thermodynamics/quantum_isochoric_molar_heat_capacity_of_solids.py +++ b/symplyphysics/laws/thermodynamics/quantum_isochoric_molar_heat_capacity_of_solids.py @@ -17,40 +17,36 @@ from sympy import Eq, exp from symplyphysics import ( dimensionless, - units, Quantity, - Symbol, + SymbolNew, validate_input, validate_output, quantities, + clone_as_symbol, + symbols, ) -isochoric_molar_heat_capacity = Symbol( - "isochoric_molar_heat_capacity", units.energy / (units.temperature * units.amount_of_substance)) -r""" -Heat capacity at constant volume per unit amount of substance. - -Symbol: - :code:`C_V` - -Latex: - :math:`C_V` +isochoric_molar_heat_capacity = clone_as_symbol( + symbols.molar_heat_capacity, + display_symbol="c_Vm", + display_latex="c_{V, m}", +) +""" +:symbols:`molar_heat_capacity` at constant :symbols:`volume`. """ -reduced_photon_energy = Symbol("reduced_photon_energy", dimensionless) +reduced_photon_energy = SymbolNew("x", dimensionless) r""" Reduced photon energy, defined as the ratio of photon energy :math:`\hbar \omega` or :math:`h \nu` to thermal energy :math:`k_\text{B} T`. """ law = Eq(isochoric_molar_heat_capacity, (3 * quantities.molar_gas_constant) * - reduced_photon_energy**2 * exp(reduced_photon_energy) / (exp(reduced_photon_energy) - 1)**2) -r""" -:code:`C_V = 3 * R * x^2 * exp(x) / (exp(x) - 1)^2` + (reduced_photon_energy**2 * exp(reduced_photon_energy) / (exp(reduced_photon_energy) - 1)**2)) +""" +:laws:symbol:: -Latex: - .. math:: - C_V = 3 R \frac{x^2 e^x}{\left( e^x - 1 \right)^2} +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/radiation_power_via_temperature.py b/symplyphysics/laws/thermodynamics/radiation_power_via_temperature.py index 177889bd3..a3b214721 100644 --- a/symplyphysics/laws/thermodynamics/radiation_power_via_temperature.py +++ b/symplyphysics/laws/thermodynamics/radiation_power_via_temperature.py @@ -15,40 +15,25 @@ from sympy import Eq from symplyphysics import ( symbols, - units, - dimensionless, Quantity, - Symbol, validate_input, validate_output, quantities, ) -radiation_power = Symbol("radiation_power", units.power) +radiation_power = symbols.power """ -Power of radiation emitted or absorbed by the body. - -Symbol: - :code:`P` +:symbols:`power` of radiation emitted or absorbed by the body. """ -emissivity = Symbol("emissivity", dimensionless) -r""" -Emissivity of the body's material. - -Symbol: - :code:`epsilon` - -Latex: - :math:`\varepsilon` +emissivity = symbols.emissivity """ - -surface_area = Symbol("surface_area", units.area) +:symbols:`emissivity` of the body's material. """ -Surface area of the body. -Symbol: - :code:`A` +surface_area = symbols.area +""" +Surface :symbols:`area` of the body. """ temperature = symbols.temperature @@ -60,12 +45,10 @@ radiation_power, quantities.stefan_boltzmann_constant * emissivity * surface_area * temperature**4, ) -r""" -:code:`P = sigma * epsilon * A * T^4` +""" +:laws:symbol:: -Latex: - .. math:: - P = \sigma \varepsilon A T^4 +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/rate_of_energy_conduction_through_slab.py b/symplyphysics/laws/thermodynamics/rate_of_energy_conduction_through_slab.py index af9e12e15..16f401be4 100644 --- a/symplyphysics/laws/thermodynamics/rate_of_energy_conduction_through_slab.py +++ b/symplyphysics/laws/thermodynamics/rate_of_energy_conduction_through_slab.py @@ -11,51 +11,37 @@ from symplyphysics import ( clone_as_symbol, symbols, - units, Quantity, - Symbol, validate_input, validate_output, ) -energy_conduction_rate = Symbol("energy_conduction_rate", units.power, positive=True) +energy_conduction_rate = symbols.power """ -Rate of energy conductivity through the slab. - -Symbol: - :code:`P` +Rate of energy conductivity through the slab. See :symbols:`power`. """ -thermal_conductivity = Symbol("thermal_conductivity", - units.power / (units.length * units.temperature), - positive=True) +thermal_conductivity = symbols.thermal_conductivity """ -Thermal conductivity of the slab's material. - -Symbol: - :code:`k` +:symbols:`thermal_conductivity` of the slab's material. """ -face_area = Symbol("face_area", units.area, positive=True) +face_area = symbols.area """ -Area of the face of the slab. - -Symbol: - :code:`A` +:symbols:`area` of the face of the slab. """ -slab_thickness = Symbol("slab_thickness", units.length, positive=True) +slab_thickness = symbols.thickness """ -Distance between the two faces of the slab. - -Symbol: - :code:`l` +Distance between the two faces of the slab. See :symbols:`thickness`. """ -temperature_difference = clone_as_symbol(symbols.temperature, - display_symbol="dT", +temperature_difference = clone_as_symbol( + symbols.temperature, + display_symbol="Delta(T)", display_latex="\\Delta T", - real=True) + real=True, +) """ :symbols:`temperature` difference between the two faces of the slab. """ @@ -64,12 +50,10 @@ energy_conduction_rate, thermal_conductivity * face_area * abs(temperature_difference) / slab_thickness, ) -r""" -:code:`P = k * A * abs(dT) / l` +""" +:laws:symbol:: -Latex: - .. math:: - P = k A \frac{|\Delta T|}{l} +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/relative_humidity_is_ratio_of_vapor_pressure.py b/symplyphysics/laws/thermodynamics/relative_humidity_is_ratio_of_vapor_pressure.py index 5c7aacca5..ceb45e936 100644 --- a/symplyphysics/laws/thermodynamics/relative_humidity_is_ratio_of_vapor_pressure.py +++ b/symplyphysics/laws/thermodynamics/relative_humidity_is_ratio_of_vapor_pressure.py @@ -2,55 +2,48 @@ Relative humidity is ratio of vapor pressure ============================================ -*Relative humidity* is the ratio of actual water vapor pressure :math:`p` to saturation vapor -pressure :math:`p_0` at a given temperature. *Saturation vapor* is vapor in dynamic +**Relative humidity** is the ratio of actual water vapor pressure :math:`p` to saturation vapor +pressure :math:`p_0` at a given temperature. **Saturation vapor** is vapor in dynamic equilibrium with a liquid or solid of the same composition in a closed system. In such a system, the number of evaporating molecules is equal to the number of condensing molecules per unit time. """ -from sympy import (Eq, solve) -from symplyphysics import (units, Quantity, Symbol, validate_input, validate_output, dimensionless) +from sympy import Eq, solve +from symplyphysics import ( + Quantity, + validate_input, + validate_output, + symbols, + clone_as_symbol, +) -relative_humidity = Symbol("relative_humidity", dimensionless) -r""" -Relative humidity of air. - -Symbol: - :code:`phi` - -Latex: - :math:`\varphi` +relative_humidity = symbols.relative_humidity +""" +:symbols:`relative_humidity` of air. """ -actual_vapor_pressure = Symbol("actual_vapor_pressure", units.pressure) +actual_vapor_pressure = symbols.pressure """ -*Partial pressure of water vapor* in the medium, representing how much water vapor is +Partial :symbols:`pressure` of water vapor in the medium, representing how much water vapor is actually in the air. - -Symbol: - :code:`p` """ -saturation_vapor_pressure = Symbol("saturation_vapor_pressure", units.pressure) -r""" -*Equilibrium vapor pressure* of water above a flat surface of liquid water or solid ice, +saturation_vapor_pressure = clone_as_symbol( + symbols.pressure, + display_symbol="p_s", + display_latex="p_\\text{s}", +) +""" +Equilibrium :symbols:`pressure` of water vapor above a flat surface of liquid water or solid ice, representing how much water vapor the air could potentially contain at a given temperature. - -Symbol: - :code:`p_s` - -Latex: - :math:`p_\text{s}` """ law = Eq(relative_humidity, actual_vapor_pressure / saturation_vapor_pressure) -r""" -:code:`phi = p / p_s` +""" +:laws:symbol:: -Latex: - .. math:: - \varphi = \frac{p}{p_\text{s}} +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/relativistic/reduced_temperature_in_maxwell_juettner_statistics.py b/symplyphysics/laws/thermodynamics/relativistic/reduced_temperature_in_maxwell_juettner_statistics.py index 168755681..5a8bfef8b 100644 --- a/symplyphysics/laws/thermodynamics/relativistic/reduced_temperature_in_maxwell_juettner_statistics.py +++ b/symplyphysics/laws/thermodynamics/relativistic/reduced_temperature_in_maxwell_juettner_statistics.py @@ -16,7 +16,7 @@ from sympy import Eq from symplyphysics import ( dimensionless, - Symbol, + SymbolNew, Quantity, validate_input, validate_output, @@ -25,15 +25,9 @@ quantities, ) -reduced_temperature = Symbol("reduced_temperature", dimensionless) -r""" -Reduced temperature. - -Symbol: - :code:`theta` - -Latex: - :math:`\theta` +reduced_temperature = SymbolNew("theta", dimensionless, display_latex="\\theta") +""" +Reduced :symbols:`temperature`. """ temperature = symbols.temperature @@ -50,12 +44,10 @@ reduced_temperature, (quantities.boltzmann_constant * temperature) / (particle_mass * quantities.speed_of_light**2), ) -r""" -:code:`theta = (k_B * T) / (m * c^2)` +""" +:laws:symbol:: -Latex: - .. math:: - \theta = \frac{k_\text{B} T}{m c^2} +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/speed_of_sound_in_ideal_gas.py b/symplyphysics/laws/thermodynamics/speed_of_sound_in_ideal_gas.py index 5f24357ae..7fd4c4431 100644 --- a/symplyphysics/laws/thermodynamics/speed_of_sound_in_ideal_gas.py +++ b/symplyphysics/laws/thermodynamics/speed_of_sound_in_ideal_gas.py @@ -11,8 +11,16 @@ #. :quantity_notation:`molar_gas_constant`. """ -from sympy import Eq, solve, sqrt, Function as SymFunction, symbols as sym_symbols -from symplyphysics import Quantity, Symbol, dimensionless, symbols, units, validate_input, validate_output, quantities +from sympy import Eq, solve, sqrt +from symplyphysics import ( + Quantity, + symbols, + validate_input, + validate_output, + quantities, + clone_as_symbol, + clone_as_function, +) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.laws.thermodynamics import ( isentropic_speed_of_sound_via_pressure_derivative as sound_law, @@ -24,12 +32,13 @@ quantity_is_volumetric_density_times_volume as density_law, ) -speed_of_sound = Symbol("speed_of_sound", units.velocity) +speed_of_sound = clone_as_symbol( + symbols.speed, + display_symbol="v_s", + display_latex="v_\\text{s}", +) """ -Speed of sound in gas. - -Symbol: - :code:`c` +:symbols:`speed` of sound in gas. """ temperature = symbols.temperature @@ -37,40 +46,29 @@ :symbols:`temperature` of the gas. """ -heat_capacity_ratio = Symbol("heat_capacity_ratio", dimensionless) -r""" -Heat capacity ratio, or adiabatic index, of the gas. - -Symbol: - :code:`gamma` - -Latex: - :math:`\gamma` +heat_capacity_ratio = symbols.adiabatic_index """ - -molar_mass = Symbol("molar_mass", units.mass / units.amount_of_substance) +Heat capacity ratio, or :symbols:`adiabatic_index`, of the gas. """ -Mass of one mole of the gas. -Symbol: - :code:`M` +molar_mass = symbols.molar_mass +""" +:symbols:`molar_mass` of the gas. """ law = Eq(speed_of_sound, sqrt(heat_capacity_ratio * quantities.molar_gas_constant * temperature / molar_mass)) -r""" -:code:`c = sqrt(gamma * R * T / M)` +""" +:laws:symbol:: -Latex: - .. math:: - c = \sqrt{\frac{\gamma R T}{M}} +:laws:latex:: """ # Derive from law of speed of sound and adiabate equation. _gas_mass = density_law.extensive_quantity _density = density_law.volumetric_density -_pressure = sym_symbols("pressure", cls=SymFunction)(_density) +_pressure = clone_as_function(symbols.pressure)(_density) _volume_expr = solve(density_law.law, density_law.volume)[0] diff --git a/symplyphysics/laws/thermodynamics/temperature_derivative_via_volume_derivative.py b/symplyphysics/laws/thermodynamics/temperature_derivative_via_volume_derivative.py index 0fb567577..5717e8c45 100644 --- a/symplyphysics/laws/thermodynamics/temperature_derivative_via_volume_derivative.py +++ b/symplyphysics/laws/thermodynamics/temperature_derivative_via_volume_derivative.py @@ -2,12 +2,12 @@ Temperature derivative via volume derivative ============================================ -The *Joule—Thompson effect* describes the change in temperature that accompanies the expansion of +The **Joule—Thompson effect** describes the change in temperature that accompanies the expansion of a gas without production of work or transfer of heat, which is in effect an isenthalpic process. **Notes:** -#. The left-hand side of the equation is also called the *Joule—Thompson coefficient*. +#. The left-hand side of the equation is also called the **Joule—Thompson coefficient**. **Conditions:** @@ -18,68 +18,54 @@ from sympy import Eq, Derivative, solve from symplyphysics import ( Quantity, - Symbol, - Function, symbols, units, validate_input, validate_output, + clone_as_function, + clone_as_symbol, ) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.core.geometry.line import two_point_function, Point2D from symplyphysics.laws.thermodynamics.equations_of_state import ideal_gas_equation -temperature = Function("temperature", units.temperature) +pressure = symbols.pressure """ -Temperature of the system as a function of pressure and enthalpy. - -Symbol: - :code:`T(p, H)` +:symbols:`pressure` inside the system. """ -pressure = Symbol("pressure", units.pressure) +enthalpy = symbols.enthalpy """ -Pressure inside the system. - -Symbol: - :code:`p` +:symbols:`enthalpy` of the system. """ -volume = Function("volume", units.volume) +temperature = clone_as_function(symbols.temperature, [pressure, enthalpy]) """ -Volume of the system as a function of temperature and pressure. - -Symbol: - :code:`V(T(p, H), p)` +:symbols:`temperature` of the system as a function of :attr:`~pressure` and +:attr:`~enthalpy`. """ -enthalpy = Symbol("enthalpy", units.energy) +volume = clone_as_function( + symbols.volume, + [temperature(pressure, enthalpy), pressure], +) """ -Enthalpy of the system. - -Symbol: - :code:`H` +:symbols:`volume` of the system as a function of :attr:`~temperature` and +:attr:`~pressure`. """ -isobaric_heat_capacity = Symbol("isobaric_heat_capacity", units.energy / units.temperature) +isobaric_heat_capacity = clone_as_symbol(symbols.heat_capacity, subscript="p") r""" -Heat capacity of the system at constant pressure. - -Symbol: - :code:`C_p` +:symbols:`heat_capacity` of the system at constant pressure. """ law = Eq(Derivative(temperature(pressure, enthalpy), pressure), (1 / isobaric_heat_capacity) * (temperature(pressure, enthalpy) * Derivative(volume(temperature(pressure, enthalpy), pressure), temperature(pressure, enthalpy)) - volume(temperature(pressure, enthalpy), pressure))) -r""" -:code:`Derivative(T(p, H), p) = (1 / C_p) * (T(p, H) * Derivative(V(T(p, H), p), T(p, H)) - V(T(p, H), p))` +""" +:laws:symbol:: -Latex: - .. math:: - \left( \frac{\partial T}{\partial p} \right)_H = \frac{1}{C_p} \left( - T(p, H) \left( \frac{\partial V}{\partial T} \right)_p - V(T(p, H), p) - \right) +:laws:latex:: """ # TODO: derive from enthalpy differential and Maxwell relations. diff --git a/symplyphysics/laws/thermodynamics/temperature_is_derivative_of_internal_energy.py b/symplyphysics/laws/thermodynamics/temperature_is_derivative_of_internal_energy.py index 906ebbe16..f8ecc0912 100644 --- a/symplyphysics/laws/thermodynamics/temperature_is_derivative_of_internal_energy.py +++ b/symplyphysics/laws/thermodynamics/temperature_is_derivative_of_internal_energy.py @@ -7,14 +7,11 @@ from sympy import Eq, Derivative, solve from symplyphysics import ( - units, - dimensionless, Quantity, - Symbol, - Function, validate_input, validate_output, symbols, + clone_as_function, ) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.laws.thermodynamics import internal_energy_differential @@ -24,45 +21,34 @@ :symbols:`temperature` of the system. """ -internal_energy = Function("internal_energy", units.energy) +entropy = symbols.entropy """ -Internal energy of the system as a function of entropy, volume, and particle count. - -Symbol: - :code:`U(S, V, N)` +:symbols:`entropy` of the system. """ -entropy = Symbol("entropy", units.energy / units.temperature) +volume = symbols.volume """ -Entropy of the system. - -Symbol: - :code:`S` +:symbols:`volume` of the system. """ -volume = Symbol("volume", units.volume) +particle_count = symbols.particle_count """ -Volume of the system. - -Symbol: - :code:`V` +:symbols:`particle_count` of the system. """ -particle_count = Symbol("particle_count", dimensionless) +internal_energy = clone_as_function( + symbols.internal_energy, + [entropy, volume, particle_count], +) """ -Number of particles in the system. - -Symbol: - :code:`N` +:symbols:`internal_energy` of the system as a function of its natural variables. """ law = Eq(temperature, Derivative(internal_energy(entropy, volume, particle_count), entropy)) -r""" -:code:`T = Derivative(U(S, V, N), S)` +""" +:laws:symbol:: -Latex: - .. math:: - T = \left( \frac{\partial U}{\partial S} \right)_{V, N} +:laws:latex:: """ # Derive from fundamental relation for internal energy diff --git a/symplyphysics/laws/thermodynamics/volume_and_temperature_in_isobaric_process.py b/symplyphysics/laws/thermodynamics/volume_and_temperature_in_isobaric_process.py index 14cb5e408..b5b822683 100644 --- a/symplyphysics/laws/thermodynamics/volume_and_temperature_in_isobaric_process.py +++ b/symplyphysics/laws/thermodynamics/volume_and_temperature_in_isobaric_process.py @@ -2,61 +2,54 @@ Volume and temperature in isobaric process ========================================== -A thermodynamic process is called isobaric when the pressure inside the system stays -constant. Also called Guy-Lussac's law, it states that the volume of the gas scales +A thermodynamic process is called **isobaric** when the pressure inside the system stays +constant. Also called **Guy-Lussac's law**, it states that the volume of the gas scales by the same amount as the temperature during an isobaric process. """ -from sympy import (Eq, solve) -from symplyphysics import (clone_as_symbol, symbols, units, Quantity, Symbol, validate_input, - validate_output) -from symplyphysics.laws.thermodynamics.equations_of_state import ideal_gas_equation as thermodynamics_law - -initial_temperature = clone_as_symbol(symbols.temperature, display_symbol="T0", display_latex="T_0") +from sympy import Eq, solve +from symplyphysics import ( + clone_as_symbol, + symbols, + Quantity, + validate_input, + validate_output, +) +from symplyphysics.laws.thermodynamics.equations_of_state import ( + ideal_gas_equation as thermodynamics_law, +) + +initial_temperature = clone_as_symbol(symbols.temperature, subscript="0") """ Initial :symbols:`temperature` of the system. """ -final_temperature = clone_as_symbol(symbols.temperature, display_symbol="T1", display_latex="T_1") +final_temperature = clone_as_symbol(symbols.temperature, subscript="1") """ Final :symbols:`temperature` of the system. """ -initial_volume = Symbol("initial_volume", units.volume) +initial_volume = clone_as_symbol(symbols.volume, subscript="0") """ -Initial volume of the system. - -Symbol: - :code:`V0` - -Latex: - :math:`V_0` +Initial :symbols:`volume` of the system. """ -final_volume = Symbol("final_volume", units.volume) +final_volume = clone_as_symbol(symbols.volume, subscript="1") """ -Final volume of the system. - -Symbol: - :code:`V1` - -Latex: - :math:`V_1` +Final :symbols:`volume` of the system. """ law = Eq(initial_volume / final_volume, initial_temperature / final_temperature) -r""" -:code:`V0 / V1 = T0 / T1` +""" +:laws:symbol:: -Latex: - .. math:: - \frac{V_0}{V_1} = \frac{T_0}{T_1} +:laws:latex:: """ ## Derive the same law from the general ideal gas law -_pressure_start = Symbol("_pressure_start", units.pressure) -_pressure_end = Symbol("_pressure_end", units.pressure) +_pressure_start = clone_as_symbol(symbols.pressure, subscript="0") +_pressure_end = clone_as_symbol(symbols.pressure, subscript="1") _isobaric_condition = Eq(_pressure_start, _pressure_end) diff --git a/symplyphysics/laws/thermodynamics/volumetric_and_linear_expansion_coefficients_in_isotropic_materials.py b/symplyphysics/laws/thermodynamics/volumetric_and_linear_expansion_coefficients_in_isotropic_materials.py index f959b8446..30eea798a 100644 --- a/symplyphysics/laws/thermodynamics/volumetric_and_linear_expansion_coefficients_in_isotropic_materials.py +++ b/symplyphysics/laws/thermodynamics/volumetric_and_linear_expansion_coefficients_in_isotropic_materials.py @@ -4,15 +4,20 @@ Coefficients of thermal expansion describe how the size of an object changes with a change in temperature at a constant pressure. In isotropic materials, the volumetric coefficient is three times the linear one. + +**Conditions:** + +#. The material is isotropic. +#. The pressure is constant during the volume change. """ -from sympy import Eq, symbols, solve +from sympy import Eq, solve from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, + clone_as_symbol, + symbols, ) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.definitions import ( @@ -20,46 +25,36 @@ volumetric_coefficient_of_thermal_expansion as volumetric_def, ) -volumetric_expansion_coefficient = Symbol("volumetric_expansion_coefficient", 1 / units.temperature) -r""" -:doc:`Volumetric expansion coefficient ` of the material. - -Symbol: - :code:`alpha_V` - -Latex: - :math:`\alpha_V` +volumetric_expansion_coefficient = clone_as_symbol(symbols.thermal_expansion_coefficient, subscript="V") +""" +Volumetric :symbols:`thermal_expansion_coefficient` of the material. Also see +:doc:`Volumetric expansion coefficient `. """ -linear_expansion_coefficient = Symbol("linear_expansion_coefficient", 1 / units.temperature) +linear_expansion_coefficient = clone_as_symbol(symbols.thermal_expansion_coefficient, subscript="l") r""" -:doc:`Linear expansion coefficient ` of the material. - -Symbol: - :code:`alpha_L` - -Latex: - :math:`\alpha_L` +Linear :symbols:`thermal_expansion_coefficient` of the material. Also see +:doc:`Linear expansion coefficient `. """ law = Eq(volumetric_expansion_coefficient, 3 * linear_expansion_coefficient) -r""" -:code:`alpha_V = 3 * alpha_L` +""" +:laws:symbol:: -Latex: - .. math:: - \alpha_V = 3 \alpha_L +:laws:latex:: """ # Derive from their definitions for a cube-sized object -_volume_change = symbols("volume_change") -_initial_length, _length_change = symbols("initial_length length_change") -_temperature_change = symbols("temperature_change") +_volume_change = clone_as_symbol(symbols.volume, display_symbol="dV") +_initial_length = clone_as_symbol(symbols.length, subscript="0") +_length_change = clone_as_symbol(symbols.length, display_symbol="dl") +_temperature_change = clone_as_symbol(symbols.temperature, display_symbol="dT") _final_length_expr = _initial_length + _length_change -_volume, _length = symbols("volume length") +_volume = clone_as_symbol(symbols.volume) +_length = clone_as_symbol(symbols.length) _volume_eqn = Eq(_volume, _length**3) _volume_expr = solve(_volume_eqn, _volume)[0] _initial_volume_expr = _volume_expr.subs(_length, _initial_length) diff --git a/symplyphysics/laws/thermodynamics/volumetric_expansion_coefficient_of_ideal_gas.py b/symplyphysics/laws/thermodynamics/volumetric_expansion_coefficient_of_ideal_gas.py index 2d07c21b1..e58c73193 100644 --- a/symplyphysics/laws/thermodynamics/volumetric_expansion_coefficient_of_ideal_gas.py +++ b/symplyphysics/laws/thermodynamics/volumetric_expansion_coefficient_of_ideal_gas.py @@ -11,26 +11,20 @@ from sympy import Eq, solve from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, symbols, + clone_as_symbol, ) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.definitions import volumetric_coefficient_of_thermal_expansion as coef_def from symplyphysics.laws.thermodynamics.equations_of_state import ideal_gas_equation -volumetric_expansion_coefficient = Symbol("volumetric_expansion_coefficient", 1 / units.temperature) -r""" -:doc:`Volumetric expansion coefficient ` of the gas. - -Symbol: - :code:`alpha_V` - -Latex: - :math:`\alpha_V` +volumetric_expansion_coefficient = clone_as_symbol(symbols.thermal_expansion_coefficient, subscript="V") +""" +Volumetric :symbols:`thermal_expansion_coefficient` of the material. Also see +:doc:`Volumetric expansion coefficient `. """ temperature = symbols.temperature @@ -39,12 +33,10 @@ """ law = Eq(volumetric_expansion_coefficient, 1 / temperature) -r""" -:code:`alpha_V = 1 / T` +""" +:laws:symbol:: -Latex: - .. math:: - \alpha_V = \frac{1}{T} +:laws:latex:: """ # Derive from ideal gas equation and definition of volumetric expansion coefficient diff --git a/symplyphysics/laws/thermodynamics/work_is_integral_of_pressure_over_volume.py b/symplyphysics/laws/thermodynamics/work_is_integral_of_pressure_over_volume.py index 0b9be1646..df9ecfcda 100644 --- a/symplyphysics/laws/thermodynamics/work_is_integral_of_pressure_over_volume.py +++ b/symplyphysics/laws/thermodynamics/work_is_integral_of_pressure_over_volume.py @@ -11,77 +11,54 @@ #. The system is closed. """ -from sympy import Eq, Integral, Point2D, solve, symbols, Function as SymFunction +from sympy import Eq, Integral, Point2D, solve from symplyphysics import ( - units, Quantity, - Symbol, - Function, validate_input, validate_output, + symbols, + clone_as_function, + clone_as_symbol, ) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.core.geometry.line import two_point_function from symplyphysics.laws.thermodynamics import infinitesimal_work_in_quasistatic_process as work_law -work = Symbol("work", units.energy) +work = symbols.work """ -Pressure-volume work done by the system. - -Symbol: - :code:`W` +Pressure-volume :symbols:`work` done by the system. """ -pressure = Function("pressure", units.pressure) +volume = symbols.volume """ -Pressure inside the system as a function of volume. - -Symbol: - :code:`p(V)` +:symbols:`volume` of the system. """ -volume = Symbol("volume", units.volume) +pressure = clone_as_function(symbols.pressure, [volume]) """ -Volume of the system. - -Symbol: - :code:`V` +:symbols:`pressure` inside the system as a function of :attr:`~volume`. """ -initial_volume = Symbol("initial_volume", units.volume) +initial_volume = clone_as_symbol(symbols.volume, subscript="0") """ -Initial volume of the system. - -Symbol: - :code:`V0` - -Latex: - :math:`V_0` +Initial :symbols:`volume` of the system. """ -final_volume = Symbol("final_volume", units.volume) +final_volume = clone_as_symbol(symbols.volume, subscript="1") """ -Final volume of the system. - -Symbol: - :code:`V1` - -Latex: - :math:`V_1` +Final :symbols:`volume` of the system. """ law = Eq(work, Integral(pressure(volume), (volume, initial_volume, final_volume))) -r""" -:code:`W = Integral(p(V), (V, V0, V1))` +""" +:laws:symbol:: -Latex: - .. math:: - W = \int \limits_{V_0}^{V_1} p(V) \, dV +:laws:latex:: """ # Derive law from infinitesimal counterpart -_work_function = symbols("work", cls=SymFunction) +_work_function = clone_as_function(symbols.work) # Prepare law for integration # Note that `dW = (dW/dV) * dV` and we set `dV` to 1 diff --git a/symplyphysics/laws/thermodynamics/work_of_ideal_gas_in_isobaric_process.py b/symplyphysics/laws/thermodynamics/work_of_ideal_gas_in_isobaric_process.py index ab9ee599b..ffffc20cc 100644 --- a/symplyphysics/laws/thermodynamics/work_of_ideal_gas_in_isobaric_process.py +++ b/symplyphysics/laws/thermodynamics/work_of_ideal_gas_in_isobaric_process.py @@ -8,58 +8,47 @@ **Conditions:** #. The gas is ideal. +#. The process is isobaric. """ from sympy import Eq, solve -from symplyphysics import (units, Quantity, Symbol, validate_input, validate_output) +from symplyphysics import ( + Quantity, + validate_input, + validate_output, + symbols, + clone_as_symbol, +) from symplyphysics.core.expr_comparisons import expr_equals -from symplyphysics.laws.thermodynamics import work_is_integral_of_pressure_over_volume as work_law +from symplyphysics.laws.thermodynamics import ( + work_is_integral_of_pressure_over_volume as work_law, +) -work = Symbol("work", units.energy) +work = symbols.work """ -Work done by the gas during the isobaric process. - -Symbol: - :code:`W` +:symbols:`work` done by the gas during the isobaric process. """ -pressure = Symbol("pressure", units.pressure) +pressure = symbols.pressure """ -Pressure of the gas, constant during the process. - -Symbol: - :code:`p` +:symbols:`pressure` of the gas, constant during the process. """ -initial_volume = Symbol("initial_volume", units.volume) +initial_volume = clone_as_symbol(symbols.volume, subscript="0") """ -Initial volume of the gas. - -Symbol: - :code:`V0` - -Latex: - :math:`V_0` +Initial :symbols:`volume` of the gas. """ -final_volume = Symbol("final_volume", units.volume) +final_volume = clone_as_symbol(symbols.volume, subscript="1") """ -Final volume of the gas - -Symbol: - :code:`V1` - -Latex: - :math:`V_1` +Final :symbols:`volume` of the gas """ law = Eq(work, pressure * (final_volume - initial_volume)) -r""" -:code:`W = p * (V1 - V0)` +""" +:laws:symbol:: -Latex: - .. math:: - W = p (V_1 - V_0) +:laws:latex:: """ # Derive law from work integral diff --git a/symplyphysics/laws/thermodynamics/work_of_ideal_gas_in_isothermal_process.py b/symplyphysics/laws/thermodynamics/work_of_ideal_gas_in_isothermal_process.py index 32a8d59ea..77a6d3f33 100644 --- a/symplyphysics/laws/thermodynamics/work_of_ideal_gas_in_isothermal_process.py +++ b/symplyphysics/laws/thermodynamics/work_of_ideal_gas_in_isothermal_process.py @@ -13,10 +13,11 @@ **Conditions:** +#. The gas is ideal. See :ref:`Ideal gas equation`. #. The temperature of the gas stays constant during the expansion. """ -from sympy import Eq, solve, Symbol as SymSymbol, log +from sympy import Eq, solve, log from symplyphysics import ( Quantity, validate_input, @@ -39,12 +40,12 @@ :symbols:`amount_of_substance` of ideal gas. """ -initial_volume = clone_as_symbol(symbols.volume, display_symbol="V_0", display_latex="V_0") +initial_volume = clone_as_symbol(symbols.volume, subscript="0") """ Initial :symbols:`volume` of the gas. """ -final_volume = clone_as_symbol(symbols.volume, display_symbol="V_1", display_latex="V_1") +final_volume = clone_as_symbol(symbols.volume, subscript="1") """ Final :symbols:`volume` of the gas. """ @@ -75,8 +76,8 @@ _pressure_expr = solve(_ideal_gas_eqn, ideal_gas_equation.pressure)[0].subs(ideal_gas_equation.volume, work_law.volume) -_volume_before = SymSymbol("volume_before", positive=True) -_volume_after = SymSymbol("volume_after", positive=True) +_volume_before = clone_as_symbol(symbols.volume, subscript="0", positive=True) +_volume_after = clone_as_symbol(symbols.volume, subscript="1", positive=True) _work_expr = work_law.law.rhs.subs({ work_law.initial_volume: _volume_before, diff --git a/symplyphysics/symbols/__init__.py b/symplyphysics/symbols/__init__.py index fd178f944..83a7c9769 100644 --- a/symplyphysics/symbols/__init__.py +++ b/symplyphysics/symbols/__init__.py @@ -32,6 +32,8 @@ "linear_density", "whole_number", "spectral_energy_density", + "molar_mass", + "probability", # chemistry, "mass_fraction", "amount_of_substance", @@ -39,6 +41,7 @@ "band_gap", "work_function", "drift_velocity", + "molar_concentration", # classical mechanics "force", "speed", @@ -88,6 +91,11 @@ "phase", "tension", "mach_number", + "radius", + "diffusion_coefficient", + "dynamic_viscosity", + "diffusion_flux", + "degrees_of_freedom", # electrodynamics "admittance", "electrical_conductance", @@ -115,6 +123,7 @@ "electrical_reactance", "current_density", "relative_permeability", + "emissivity", # optics "relative_refractive_index", "radiant_exitance", @@ -132,4 +141,18 @@ "thermal_conductivity", "thermal_insulance", "compressibility_factor", + "partition_function", + "boltzmann_factor", + "entropy", + "molar_heat_capacity", + "chemical_potential", + "gibbs_energy", + "enthalpy", + "helmholtz_free_energy", + "internal_energy", + "thermal_wavelength", + "heat", + "thermal_efficiency", + "statistical_weight", + "relative_humidity", ] diff --git a/symplyphysics/symbols/basic.py b/symplyphysics/symbols/basic.py index cccc31b8c..d3f5cb762 100644 --- a/symplyphysics/symbols/basic.py +++ b/symplyphysics/symbols/basic.py @@ -30,6 +30,11 @@ when a force is applied. """ +molar_mass = SymbolNew("M", units.mass / units.amount_of_substance) +""" +**Molar mass** is defined as the mass per unit amount of substance. +""" + work = SymbolNew("W", units.energy) """ **Work** is the energy transferred to or from an object via the application of force. @@ -102,3 +107,8 @@ """ An **angle** is the difference in direction between two lines or surfaces. """ + +probability = SymbolNew("P", dimensionless) +""" +**Probability** is a measure of an event's likelihood. +""" diff --git a/symplyphysics/symbols/chemistry.py b/symplyphysics/symbols/chemistry.py index 58dc0e669..f062b3e73 100644 --- a/symplyphysics/symbols/chemistry.py +++ b/symplyphysics/symbols/chemistry.py @@ -43,3 +43,9 @@ **Drift velocity** is the average velocity attained by charged particles, such as electrons, in a material due to an electric field. """ + +molar_concentration = SymbolNew("c", units.amount_of_substance / units.volume) +""" +**Molar concentration**, or **molarity**, is a quantity most commonly defined as amount of substance of +solute per unit volume of solution, or per unit volume available to the species. +""" diff --git a/symplyphysics/symbols/classical_mechanics.py b/symplyphysics/symbols/classical_mechanics.py index 903267e80..5a717b8e3 100644 --- a/symplyphysics/symbols/classical_mechanics.py +++ b/symplyphysics/symbols/classical_mechanics.py @@ -58,7 +58,13 @@ **Length** is a measure of a size of an object. """ -thickness = SymbolNew("d", units.length) +radius = SymbolNew("r", units.length) +""" +**Radius** of a sphere is the distance from the center of the sphere to any point on +the sphere. +""" + +thickness = SymbolNew("h", units.length) """ **Thickness** is a measure of a size of an object, usually the separation between two layers, or the distance through an object distinct from length and width. @@ -280,3 +286,39 @@ The **Mach number** is a dimensionless quantity in fluid dynamics representing the ratio of flow velocity past a boundary to the local speed of sound. """ + +diffusion_coefficient = SymbolNew("D", units.area / units.time) +""" +**Diffusion coefficient**, or **diffusivity**, is usually defined as the proportionality constant between +the molar flux due to molecular diffusion and the negative value of the gradient in the concentration of +the species. + +**Links:** + +#. `Mass diffusivity `__. +""" + +dynamic_viscosity = SymbolNew("mu", units.pressure * units.time) +""" +**Dynamic viscosity** is a physical quantity measuring the resistance to deformation at a given rate. +Specifically in fluid mechanics, it is the proportionality factor between the shear stress of the adjacent +layers of the fluid and the local sheer velocity. + +**Links:** + +#. `Dynamic viscosity `__. +""" + +diffusion_flux = SymbolNew("J", units.amount_of_substance / (units.area * units.time)) +""" +**Diffusion flux** is a physical quantity that measures the amount of substance that will flow through +a unit area during a unit time interval. For the general definition of flux, see `Flux +`__. +""" + +degrees_of_freedom = SymbolNew("f", dimensionless, integer=True, positive=True) +""" +A **degree of freedom** is a physical parameter in the parameterization of a physical system. The number +of degrees of freedom indicates the smallest number of parameters whose values determine all parameters +in the chosen parameterization. +""" diff --git a/symplyphysics/symbols/electrodynamics.py b/symplyphysics/symbols/electrodynamics.py index 0ea9af81c..2f5d26bca 100644 --- a/symplyphysics/symbols/electrodynamics.py +++ b/symplyphysics/symbols/electrodynamics.py @@ -155,3 +155,8 @@ """ **Current density** is the amount of charge per unit time that flows through a unit area of a chosen cross section. """ + +emissivity = SymbolNew("epsilon", dimensionless, display_latex="\\varepsilon") +""" +The **emissivity** of the surface of a material is its effectiveness in emitting energy as thermal radiation. +""" diff --git a/symplyphysics/symbols/thermodynamics.py b/symplyphysics/symbols/thermodynamics.py index e35b5fe14..668d5c488 100644 --- a/symplyphysics/symbols/thermodynamics.py +++ b/symplyphysics/symbols/thermodynamics.py @@ -27,6 +27,11 @@ supplied to an object to produce a unit change in its temperature. """ +molar_heat_capacity = SymbolNew("c_m", units.energy / (units.temperature * units.amount_of_substance)) +""" +**Molar heat capacity** is defined as the heat capacity per unit amount of substance. +""" + thermal_expansion_coefficient = SymbolNew("alpha", 1 / units.temperature, display_latex="\\alpha") """ **Thermal expansion coefficient** describes how the size of an object changes with a change in temperature at @@ -63,3 +68,92 @@ The **compressibility factor**, also known as the **compression factor** or the **gas deviation factor**, describes the deviation of a real gas from ideal gas behavior. """ + +partition_function = SymbolNew("Z", dimensionless) +""" +In statistical mechanics, the **partition function** describes the statistical properties of a system in +thermodynamic equilibrium. It plays the role of a normalization constant in microstate distributions of +the system by encoding the information about how the probabilities are partitioned among the different +microstates based on the specific microstate variables. +""" + +boltzmann_factor = SymbolNew("f", dimensionless) +""" +In statistical mechanics, the **Boltzmann factor** is a quantity that describes the approximate fraction +of particles in the canonical ensemble. +""" + +entropy = SymbolNew("S", units.energy / units.temperature) +""" +**Entropy** is a physical quantity most commonly associated with a state of randomness or disorder. In the +approach of the classical thermodynamics, entropy is defined in terms of macroscopically measurable physical +properties, such as volume, bulk mass, pressure, etc. The statistical definition defines it in terms of the +statistics of the motions of the microscopic constituents of a system. +""" + +chemical_potential = SymbolNew("mu", units.energy, display_latex="\\mu") +""" +The **chemical potential** of a species is the energy that can be absorbed or released due to a change of the +particle number of the given species, e.g. in a chemical reaction or phase transition. +""" + +gibbs_energy = SymbolNew("G", units.energy) +""" +The **Gibbs energy** is a thermodynamic potential that can be used to calculate the maximum amount of work, +other than pressure-volume work, that may be performed by a thermodynamically closed system at constant +temperature and pressure. +""" + +enthalpy = SymbolNew("H", units.energy) +""" +**Enthalpy** is a state function defined as the sum of a thermodynamic system's internal energy and the +product of its pressure and volume, used in measurements at a constant external pressure. +""" + +helmholtz_free_energy = SymbolNew("F", units.energy) +""" +In thermodynamics, the **Helmholtz free energy** (or **Helmholtz energy**) is a thermodynamic potential +that measures the useful work obtainable from a closed thermodynamic system at a constant temperature. +""" + +internal_energy = SymbolNew("U", units.energy) +""" +**Internal energy** is a thermodynamical state function which denotes the entire energy of a closed system +of molecules or the sum of a substance's molecular kinetic and potential energy. It excludes the potential +and kinetic energies of the system as a whole and is only concerned with the energy of the molecules comprising +the system. +""" + +thermal_wavelength = SymbolNew("lambda", units.length, display_latex="\\lambda") +""" +The **thermal de Broglie wavelength** is a quantity that is roughly the average de Broglie wavelength of +particles in an ideal gas at the specified temperature. + +**Links:** + +#. `Thermal de Broglie wavelength `__. +""" + +heat = SymbolNew("Q", units.energy) +""" +In thermodynamics, **heat** is energy in transfer between a thermodynamic system and its surroundings by modes +other than thermodynamic work and transfer of matter. +""" + +thermal_efficiency = SymbolNew("eta", dimensionless, display_latex="\\eta") +""" +The **thermal efficiency** is a dimensionless performance measure of a device that uses thermal energy. A generic +definition of thermal energy is the ratio of the energy benefit to the energy costs attributed to the defice. +""" + +statistical_weight = SymbolNew("Omega", dimensionless, display_latex="\\Omega") +""" +**Statistical weight**, or **multiplicity**, is a physical quantity denoting the number of microstates +corresponding to a particular macrostate of a thermodynamic system. +""" + +relative_humidity = SymbolNew("phi", dimensionless, display_latex="\\varphi") +""" +**Relative humidity** is a quantity that indicates a present state of absolute humidity relative to a +maximum humidity given the same temperature. +""" diff --git a/test/thermodynamics/gibbs_energy_via_enthalpy_test.py b/test/thermodynamics/gibbs_energy_via_enthalpy_test.py index 9e660e371..28d878d36 100644 --- a/test/thermodynamics/gibbs_energy_via_enthalpy_test.py +++ b/test/thermodynamics/gibbs_energy_via_enthalpy_test.py @@ -14,8 +14,8 @@ @fixture(name="test_args") def test_args_fixture() -> Args: - thermal_effect = Quantity(552866 * units.joule / units.mole) - entropy = Quantity(155 * (units.joule / units.mole / units.kelvin)) + thermal_effect = Quantity(552866 * units.joule) + entropy = Quantity(155 * (units.joule / units.kelvin)) temperature = Quantity(298 * units.kelvin) return Args(thermal_effect=thermal_effect, entropy=entropy, temperature=temperature) @@ -24,7 +24,7 @@ def test_args_fixture() -> Args: def test_basic_isobaric_potential(test_args: Args) -> None: result = potential_law.calculate_isobaric_potential(test_args.thermal_effect, test_args.entropy, test_args.temperature) - assert_equal(result, 506676 * units.joule / units.mole) + assert_equal(result, 506676 * units.joule) def test_bad_thermal_effect(test_args: Args) -> None: