-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into condition-dielectric-equation-of-state
- Loading branch information
Showing
5 changed files
with
157 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
""" |
88 changes: 88 additions & 0 deletions
88
...odynamics/dielectrics/internal_energy_change_via_heat_and_electric_displacement_change.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...mics/dielectrics/internal_energy_change_via_heat_and_electric_displacement_change_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |