diff --git a/symplyphysics/laws/thermodynamics/dielectrics/gibbs_energy_change_via_temperature_change_and_electic_displacement_change.py b/symplyphysics/laws/thermodynamics/dielectrics/gibbs_energy_change_via_temperature_change_and_electic_displacement_change.py new file mode 100644 index 000000000..70972a8cd --- /dev/null +++ b/symplyphysics/laws/thermodynamics/dielectrics/gibbs_energy_change_via_temperature_change_and_electic_displacement_change.py @@ -0,0 +1,97 @@ +""" +Gibbs energy change via temperature change and electric displacement change +=========================================================================== + +The infinitesimal change in Gibbs energy of a system with a dielectric medium +can be expressed using the change in temperature and the change in electric +field strength. + +**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.8 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, +) + +gibbs_energy_density_change = SymbolNew("dG", units.energy / units.volume) +""" +Infinitesimal change in :symbols:`gibbs_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_displacement = symbols.electric_displacement +""" +:symbols:`electric_displacement`. +""" + +electric_field_change = clone_as_symbol( + symbols.electric_field_strength, + display_symbol="dE", + display_latex="dE", +) +""" +Infinitesimal change in :symbols:`electric_field_strength`. +""" + +law = Eq( + gibbs_energy_density_change, + -1 * entropy_density * temperature_change - electric_displacement * electric_field_change, +) +""" +:laws:symbol:: + +:laws:latex:: +""" + +# Derivation +## Make use of the formula for Gibbs energy and that for free energy. + + +@validate_input( + entropy_density_=entropy_density, + temperature_change_=temperature_change, + electric_displacement_=electric_displacement, + electric_field_change_=electric_field_change, +) +@validate_output(gibbs_energy_density_change) +def calculate_gibbs_energy_density_change( + entropy_density_: Quantity, + temperature_change_: Quantity, + electric_displacement_: Quantity, + electric_field_change_: Quantity, +) -> Quantity: + result = law.rhs.subs({ + entropy_density: entropy_density_, + temperature_change: temperature_change_, + electric_displacement: electric_displacement_, + electric_field_change: electric_field_change_, + }) + return Quantity(result) diff --git a/test/thermodynamics/dielectrics/gibbs_energy_change_via_temperature_change_and_electic_displacement_change_test.py b/test/thermodynamics/dielectrics/gibbs_energy_change_via_temperature_change_and_electic_displacement_change_test.py new file mode 100644 index 000000000..f620279b0 --- /dev/null +++ b/test/thermodynamics/dielectrics/gibbs_energy_change_via_temperature_change_and_electic_displacement_change_test.py @@ -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 ( + gibbs_energy_change_via_temperature_change_and_electic_displacement_change as law, +) + +Args = namedtuple("Args", "s dt d de") + + +@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) + d = Quantity(15 * units.coulomb / units.meter**2) + de = Quantity(3e-3 * units.volt / units.meter) + return Args(s=s, dt=dt, d=d, de=de) + + +def test_law(test_args: Args) -> None: + result = law.calculate_gibbs_energy_density_change(test_args.s, test_args.dt, test_args.d, test_args.de) + assert_equal(result, -3.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_gibbs_energy_density_change(sb, test_args.dt, test_args.d, test_args.de) + with raises(TypeError): + law.calculate_gibbs_energy_density_change(100, test_args.dt, test_args.d, test_args.de) + + +def test_bad_temperature(test_args: Args) -> None: + tb = Quantity(units.candela) + with raises(errors.UnitsError): + law.calculate_gibbs_energy_density_change(test_args.s, tb, test_args.d, test_args.de) + with raises(TypeError): + law.calculate_gibbs_energy_density_change(test_args.s, 100, test_args.d, test_args.de) + + +def test_bad_electric_displacement(test_args: Args) -> None: + db = Quantity(units.candela) + with raises(errors.UnitsError): + law.calculate_gibbs_energy_density_change(test_args.s, test_args.dt, db, test_args.de) + with raises(TypeError): + law.calculate_gibbs_energy_density_change(test_args.s, test_args.dt, 100, test_args.de) + + +def test_bad_electric_field_strength(test_args: Args) -> None: + eb = Quantity(units.candela) + with raises(errors.UnitsError): + law.calculate_gibbs_energy_density_change(test_args.s, test_args.dt, test_args.d, eb) + with raises(TypeError): + law.calculate_gibbs_energy_density_change(test_args.s, test_args.dt, test_args.d, 100)