Unified Treatment of Forward and Inverse Problems in the Numerical Simulation of Tokamak Plasmas