Advanced Topics

Periodic Work

Yggdrasil’s controller object permits for periodic work to be inserted at a chosen cadence into the simulation. This is done by passing a periodicWork argument to the controller constructor:

controller = Controller(integrator=integrator,
                        statStep=100,
                        periodicWork=periodicWork)

Suppose, for instance, I want to insert periodic work that oscillates the value of my phi field at a certain cadence in the center of the grid domain. I can do this by creating an oscillator class in Python:

class oscillate:
    def __init__(self,nodeList,grid,width,height,workCycle=1):
        self.nodeList = nodeList
        self.cycle = workCycle
        self.grid = grid
        self.width = width
        self.height = height
        self.phi = nodeList.phi
    def __call__(self,cycle,time,dt):
        a = 5*(cos(time))
        i = int(self.width/2)
        j = int(self.height/2)
        idx = self.grid.index(i,j,0)
        self.phi.setValue(idx,a)

Then I construct the associated periodic work object like so:

osc = oscillate(nodeList=myNodeList,grid=grid,cs=cs,width=nx,height=ny)
periodicWork = [osc]

before passing this Python list to the controller constructor. The controller expects a __call__(self,cycle,time,dt) method inside each periodic work function and will invoke each call method at your chosen cadence. You can use periodic work to implement many other effects in your simulation, or to perform analysis tasks in real time during integration.

Calculators and Linear Algebra

Yggdrasil also includes a small number of calculator objects that can be used anywhere in a Yggdrasil script. These includes

cosmology
stringArt
timeDilation

Each of these has an example script in the examples directory.

In addition to the above-mentioned calculators, Yggdrasil includes a fairly well-featured linear algebra computational package through its Vector and Tensor class methods.

Note

Nihoggr’s Vector and Tensor classes are limited to a maximum of three dimensions along any span.

Implicit vs. Explicit Time integration

Most of the physics packages in Yggdrasil are designed for use with explicit time integration and can become quite unstable if you try to run them with implicit time integration (e.g. Crank-Nicolson). As of version 0.8.5, the only physics module that is stable under implicit time integration is ImplicitPhysicsXd.