Electromagnetic Energy and Virtual Work
Another technique to calculate forces is to derive the electromagnetic energy 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 Force and Torque
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, the total force and torque are computed in the same way but with opposite signs,
Electric Force And Torque
Under the condition of constant charges, the total electric force and torque on a system are computed as
Under the condition of constant potentials, the total electric force and torque on a system are computed as
 
See Deformed Geometry and Moving Mesh and Sensitivity Analysis in the COMSOL Multiphysics Reference Manual.