Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Law: free energy change in dielectrics #943

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"""
Free energy change via temperature change and electric displacement change
blackyblack marked this conversation as resolved.
Show resolved Hide resolved
==========================================================================

The infinitesimal change in (Helmholtz) free energy of a system with a dielectric
medium can be expressed using the change in temperature and the change in electric
displacement.

**Conditions:**

#. The dielectric is isotropic whether or not the electric field is present.
#. The medium is homogeneous.
#. The volume change of the medium is insignificant.

**Links:**

#. Formula 31.7 on p. 122 of "General Course of Physics" (Obschiy kurs fiziki), vol. 3 by Sivukhin D.V. (1979).
"""

from sympy import Eq
from symplyphysics import (
symbols,
units,
Quantity,
SymbolNew,
clone_as_symbol,
validate_input,
validate_output,
)

free_energy_density_change = SymbolNew("dH", units.energy / units.volume)
"""
Infinitesimal change in :symbols:`helmholtz_free_energy` of the system
per unit :symbols:`volume`.
"""

entropy_density = SymbolNew("S", units.energy / units.temperature / units.volume)
"""
:symbols:`entropy` of the system per unit :symbols:`volume`.
"""

temperature_change = clone_as_symbol(
symbols.temperature,
display_symbol="dT",
display_latex="dT",
)
"""
Infinitesimal change in :symbols:`temperature` of the system.
"""

electric_field_strength = symbols.electric_field_strength
"""
:symbols:`electric_field_strength`.
"""

electric_displacement_change = clone_as_symbol(
symbols.electric_displacement,
display_symbol="dD",
display_latex="dD",
)
"""
Infinitesimal change in :symbols:`electric_displacement` of the system.
"""

law = Eq(
free_energy_density_change,
-1 * entropy_density * temperature_change + electric_field_strength * electric_displacement_change,
)
"""
:laws:symbol::

:laws:latex::
"""

# Derivation
## Make use of the formula for free energy and the first law of thermodynamics applied to dielectric media.


@validate_input(
entropy_density_=entropy_density,
temperature_change_=temperature_change,
electric_field_strength_=electric_field_strength,
electric_displacement_change_=electric_displacement_change,
)
@validate_output(free_energy_density_change)
def calculate_free_energy_density_change(
entropy_density_: Quantity,
temperature_change_: Quantity,
electric_field_strength_: Quantity,
electric_displacement_change_: Quantity,
) -> Quantity:
result = law.rhs.subs({
entropy_density: entropy_density_,
temperature_change: temperature_change_,
electric_field_strength: electric_field_strength_,
electric_displacement_change: electric_displacement_change_,
})
return Quantity(result)
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from collections import namedtuple
from pytest import fixture, raises
from symplyphysics import (
assert_equal,
errors,
units,
Quantity,
)
from symplyphysics.laws.thermodynamics.dielectrics import (
free_energy_change_via_temperature_change_and_electric_field_change as law,
)

Args = namedtuple("Args", "s dt e dd")


@fixture(name="test_args")
def test_args_fixture() -> Args:
s = Quantity(10 * units.joule / units.kelvin / units.meter**3)
dt = Quantity(-1e-3 * units.kelvin)
e = Quantity(15 * units.volt / units.meter)
dd = Quantity(3e-3 * units.coulomb / units.meter**2)
return Args(s=s, dt=dt, e=e, dd=dd)


def test_law(test_args: Args) -> None:
result = law.calculate_free_energy_density_change(test_args.s, test_args.dt, test_args.e, test_args.dd)
assert_equal(result, 5.5e-2 * units.joule / units.meter**3)


def test_bad_entropy_density(test_args: Args) -> None:
sb = Quantity(units.candela)
with raises(errors.UnitsError):
law.calculate_free_energy_density_change(sb, test_args.dt, test_args.e, test_args.dd)
with raises(TypeError):
law.calculate_free_energy_density_change(100, test_args.dt, test_args.e, test_args.dd)


def test_bad_temperature(test_args: Args) -> None:
tb = Quantity(units.candela)
with raises(errors.UnitsError):
law.calculate_free_energy_density_change(test_args.s, tb, test_args.e, test_args.dd)
with raises(TypeError):
law.calculate_free_energy_density_change(test_args.s, 100, test_args.e, test_args.dd)


def test_bad_electric_field(test_args: Args) -> None:
eb = Quantity(units.candela)
with raises(errors.UnitsError):
law.calculate_free_energy_density_change(test_args.s, test_args.dt, eb, test_args.dd)
with raises(TypeError):
law.calculate_free_energy_density_change(test_args.s, test_args.dt, 100, test_args.dd)


def test_bad_electric_displacement(test_args: Args) -> None:
db = Quantity(units.candela)
with raises(errors.UnitsError):
law.calculate_free_energy_density_change(test_args.s, test_args.dt, test_args.e, db)
with raises(TypeError):
law.calculate_free_energy_density_change(test_args.s, test_args.dt, test_args.e, 100)
Loading