Thermodynamics is the study of energy relationships. The first law of thermodynamics states that the total energy of the universe remains constant: energy is neither created, nor destroyed. The second law states that the degree of randmomness, or entropy, always tends to increase and the energy available to do work decreases. Thermodynamics describes how systems change when they interact with one another or with their surroundings. This can be applied to a wide variety of topics in science and engineering, such as engines, phase transitions, and chemical reactions. Thermodynamics is built on the study of energy transfers that can be strictly resolved into two distinct components, heat and work, specified by macroscopic variables.
Equilibrium thermodynamics studies transformations of matter and energy in systems as they approach equilibrium. The equilibrium means balance. In a thermodynamic equilibrium state there is no macroscopic flow and no macroscopic change is occurring or can be triggered; within the system, every microscopic process is balanced by its opposite; this is called the principle of detailed balance. A central aim in equilibrium thermodynamics is: given a system in a well-defined initial state, subject to accurately specified constraints, to calculate what the state of the system will be once it has reached equilibrium. A thermodynamic system is said to be homogeneous when all its locally defined intensive variables are spatially invariant. A system in thermodynamic equilibrium is homogeneous unless it is affected by a time-invariant externally imposed field of force, such as gravity, electricity, or magnetism.