Skip to content

Commit

Permalink
Merge branch 'master' into condition-dielectric-equation-of-state
Browse files Browse the repository at this point in the history
  • Loading branch information
alesanter committed Jan 3, 2025
2 parents 3f8b245 + 438a6cb commit 7105c34
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 1 deletion.
6 changes: 6 additions & 0 deletions symplyphysics/laws/thermodynamics/dielectrics/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""
**Dielectric Thermodynamics**
=============================
This module describes the laws concerning the thermodynamics of dielectric media.
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
"""
Internal energy change via heat and electric displacement change
================================================================
Internal energy change of the system with a dielectric medium can be
expressed using the infinitesimal heat flowing in or out of the system
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.2 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,
)

internal_energy_density_change = SymbolNew("dU", units.energy / units.volume)
"""
Infinitesimal change in :symbols:`internal_energy` per unit :symbols:`volume`.
"""

heat_density = SymbolNew("delta(Q)", units.energy / units.volume, display_latex="\\delta Q")
"""
Small amount of :symbols:`heat` added to or taken from the system per unit :symbols:`volume`.
"""

electric_field_strength = symbols.electric_field_strength
"""
:symbols:`electric_field_strength` in the medium.
"""

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

law = Eq(
internal_energy_density_change,
heat_density + electric_field_strength * electric_displacement_change
)
"""
:laws:symbol::
:laws:latex::
"""

# Derivation
# 1. First law of thermodynamics: `delta(Q) = dU + delta(A)`
# 2. Work done by the dielectric is composed of two parts: `delta(A) = p*dV - V*dot(E, dD)`
# We omit the former term and focus on the latter one (TODO add this law).
# 3. Divide both parts of the (1) by `V`.


@validate_input(
heat_density_=heat_density,
electric_field_strength_=electric_field_strength,
electric_displacement_change_=electric_displacement_change,
)
@validate_output(internal_energy_density_change)
def calculate_internal_energy_density_change(
heat_density_: Quantity,
electric_field_strength_: Quantity,
electric_displacement_change_: Quantity,
) -> Quantity:
result = law.rhs.subs({
heat_density: heat_density_,
electric_field_strength: electric_field_strength_,
electric_displacement_change: electric_displacement_change_,
})
return Quantity(result)
1 change: 1 addition & 0 deletions symplyphysics/symbols/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"emissivity",
"magnetic_moment",
"absolute_permeability",
"electric_displacement",
# optics
"relative_refractive_index",
"radiant_exitance",
Expand Down
13 changes: 12 additions & 1 deletion symplyphysics/symbols/electrodynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,16 @@
**Links:**
#. `Magnetic moment <https://en.wikipedia.org/wiki/Magnetic_moment>`__.
#. `Wikipedia <https://en.wikipedia.org/wiki/Magnetic_moment>`__.
"""

electric_displacement = SymbolNew("D", units.charge / units.area)
"""
**Electric displacement field**, also called **electric flux density** or **electric induction**,
is a vector field, which accounts for the electromagnetic effects of polarization and that of an
electric field, combining the two in an auxiliary field.
**Links:**
#. `Wikipedia <https://en.wikipedia.org/wiki/Electric_displacement_field>`__.
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from collections import namedtuple
from pytest import fixture, raises
from symplyphysics import (
assert_equal,
errors,
units,
Quantity,
)
from symplyphysics.laws.thermodynamics.dielectrics import (
internal_energy_change_via_heat_and_electric_displacement_change as law,
)

Args = namedtuple("Args", "dq e dd")


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


def test_law(test_args: Args) -> None:
result = law.calculate_internal_energy_density_change(test_args.dq, test_args.e, test_args.dd)
assert_equal(result, 4.1e-2 * units.joule / units.meter**3, tolerance=5e-3)


def test_bad_heat(test_args: Args) -> None:
qb = Quantity(units.second)
with raises(errors.UnitsError):
law.calculate_internal_energy_density_change(qb, test_args.e, test_args.dd)
with raises(TypeError):
law.calculate_internal_energy_density_change(100, test_args.e, test_args.dd)


def test_bad_electric_field(test_args: Args) -> None:
eb = Quantity(units.second)
with raises(errors.UnitsError):
law.calculate_internal_energy_density_change(test_args.dq, eb, test_args.dd)
with raises(TypeError):
law.calculate_internal_energy_density_change(test_args.dq, 100, test_args.dd)


def test_bad_electric_displacement(test_args: Args) -> None:
db = Quantity(units.second)
with raises(errors.UnitsError):
law.calculate_internal_energy_density_change(test_args.dq, test_args.e, db)
with raises(TypeError):
law.calculate_internal_energy_density_change(test_args.dq, test_args.e, 100)

0 comments on commit 7105c34

Please sign in to comment.