Minimizers

In PFC simulations, one often wishes to find the field configuration \(\psi(\mathbf{r})\) that minimizes some free energy fucntional \(F[\psi]\). This is done by minimizers, which are subclasses of torusgrid.dynamics.Evolver.

To use a minimizer, instantiate a minimizer class (for example pfc_util.ConstantMuMinimizer) by passing a torusgrid.RealField object and relevant parameters:

minim = pfc.ConstantMuMinimizer(solid, dt=0.01, eps=0.1, mu=0.19)

Now, to actually run the minimization:

minim.run(31)

Note that during the minimization, the data of the field passed into the minizer’s constructor will be modified. That is, the minimization is done in-place.

By default, this would run until manually interrupted (by pressing Ctrl+C for example). This can be changed by passing a torusgrid.dynamics.EvolverHooks object:

hooks = (
    tg.dynamics.MonitorValues({'psibar': lambda e: e.field.psi.mean()})
    + tg.dynamics.DetectSlow('psibar', rtol=1e-7, atol=0, patience=200)
)

minim.run(31, hooks=hooks)

This will execute a callback every n_steps (31 in this case) time steps to monitor the mean density \(\bar\psi\), and stop the process if it changes too slow.