Electromagnetic Energy, Coenergy and Virtual Work
Another technique to calculate forces is to derive the electromagnetic energy or coenergy of the system and calculate the force by studying the effect of a small displacement. This is known as the method of virtual work or the principle of virtual displacement.
The method of virtual work is used for the electric energy and magnetic energy separately for calculating the total electric or magnetic force as follows.
mAGNETIC ENERGY, COENERGy, Force and torque
For nonlinear magnetic materials without hysteresis, the magnetic energy and coenergy densities are respectively
Knowing either of these, the other can be computed through the relation
For the case of linear materials, the magnetic energy and coenergy densities are equal.
The method of virtual work utilizes that, under constant magnetic flux conditions (Ref. 5), the total magnetic force on a system is computed as
If the system is constrained to rotate about an axis the torque is computed as
where is the rotational angle about the axis.
Under the condition of constant currents and linear materials, the total force and torque can be computed in the same way but with opposite signs,
Under the condition of constant currents and nonlinear materials, the total force and torque must be computed from the magnetic coenergy and with opposite signs,
electric ENERGY, COENERGy, Force and torque
For nonlinear dielectric materials without hysteresis, the electric energy and coenergy densities are respectively
Knowing either of these, the other can be computed through the relation
For the case of linear materials, the electric energy and coenergy densities are equal.
Under the condition of constant charges, the total electric force and torque on a system are computed as
Under the condition of constant potentials and linear materials, the total electric force and torque on a system can be computed as
Under the condition of constant potentials and nonlinear materials, the total electric force and torque on a system must be computed from the electric coenergy as
 
See Deformed Geometry and Moving Mesh and Sensitivity Analysis in the COMSOL Multiphysics Reference Manual.