diff --git a/symplyphysics/laws/thermodynamics/dielectrics/__init__.py b/symplyphysics/laws/thermodynamics/dielectrics/__init__.py new file mode 100644 index 000000000..cd9447beb --- /dev/null +++ b/symplyphysics/laws/thermodynamics/dielectrics/__init__.py @@ -0,0 +1,6 @@ +""" +**Dielectric Thermodynamics** +============================= + +This module describes the laws concerning the thermodynamics of dielectric media. +""" diff --git a/symplyphysics/laws/thermodynamics/dielectrics/internal_energy_change_via_heat_and_electric_displacement_change.py b/symplyphysics/laws/thermodynamics/dielectrics/internal_energy_change_via_heat_and_electric_displacement_change.py new file mode 100644 index 000000000..b11ba1c9d --- /dev/null +++ b/symplyphysics/laws/thermodynamics/dielectrics/internal_energy_change_via_heat_and_electric_displacement_change.py @@ -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) diff --git a/symplyphysics/symbols/__init__.py b/symplyphysics/symbols/__init__.py index 9901f0677..81f09d748 100644 --- a/symplyphysics/symbols/__init__.py +++ b/symplyphysics/symbols/__init__.py @@ -140,6 +140,7 @@ "emissivity", "magnetic_moment", "absolute_permeability", + "electric_displacement", # optics "relative_refractive_index", "radiant_exitance", diff --git a/symplyphysics/symbols/electrodynamics.py b/symplyphysics/symbols/electrodynamics.py index 213535999..e88752a4a 100644 --- a/symplyphysics/symbols/electrodynamics.py +++ b/symplyphysics/symbols/electrodynamics.py @@ -176,5 +176,16 @@ **Links:** -#. `Magnetic moment `__. +#. `Wikipedia `__. +""" + +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 `__. """ diff --git a/test/thermodynamics/dielectrics/internal_energy_change_via_heat_and_electric_displacement_change_test.py b/test/thermodynamics/dielectrics/internal_energy_change_via_heat_and_electric_displacement_change_test.py new file mode 100644 index 000000000..5018d590d --- /dev/null +++ b/test/thermodynamics/dielectrics/internal_energy_change_via_heat_and_electric_displacement_change_test.py @@ -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)