Rare earth permanent magnet models are commonly used in the design of undulators and wigglers. Normally the operating point of the magnet in the B vs. H diagram corresponds to a linear reversible characteristic. The region of linearity is strongly dependent on the temperature. The operation of part of the magnet blocks in the region of non-linearity is responsible for the so-called irreversible losses. A non-linear model for permanent magnets has been introduced in the 3D magnetostatic computer code RADIA. The model handles the complete demagnetization curve B(H) including the temperature dependence of the remanent field and intrinsic coercivity of the material. It allows careful analysis of local demagnetization in a permanent magnet structure as a function of temperature. The result of the simulation is in good agreement with the measured demagnetization of an assembly of Sm2Co17 and NdFeB magnets following a baking at several different temperatures. Such numerical simulations are of major importance in the selection of magnetic material for in-vacuum undulators which requires a baking at temperatures of 100-150 deg. C. They also allow the proper selection of NdFeB material for any application where the highest field in a selected range of temperature is desired. 1