Skip to content

Commit

Permalink
Patch documentation: thermodynamics (#916)
Browse files Browse the repository at this point in the history
* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Add documentation

* Fix issues with law symbols

* Fix issue with plot

* Fix documentation
  • Loading branch information
alesanter authored Nov 5, 2024
1 parent dce07eb commit 11a5e19
Show file tree
Hide file tree
Showing 64 changed files with 1,175 additions and 1,665 deletions.
6 changes: 4 additions & 2 deletions plots/thermodynamics/carnot_cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion symplyphysics/docs/symbols_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <definitions.boltzmann_factor_via_state_energy_and_temperature>` 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
<definitions.boltzmann_factor_via_state_energy_and_temperature>`.
"""

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::
"""


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,94 +15,72 @@
**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,
clone_as_symbol,
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
"""
: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::
"""


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::
"""


Expand Down
Loading

0 comments on commit 11a5e19

Please sign in to comment.