Utilities

This page lists supporting public objects that are commonly used with the new Python interface.

Time Integration Solvers

Import built-in solvers from HASEonGPU:

from HASEonGPU import (
    ExplicitEuler,
    Heun,
    Midpoint,
    RungeKutta4,
    ImplicitEuler,
    ExponentialEuler,
)

Available solvers:

  • ExplicitEuler()

  • Heun()

  • Midpoint()

  • RungeKutta4()

  • ImplicitEuler(iterations=8, tolerance=1e-10)

  • ExponentialEuler()

All solvers implement:

step(rhs, betaCells, time, timeStep)

The return value is a TimeIntegrationResult with:

  • betaCells: updated beta array \(\beta_i\).

  • evaluation: the TimeDerivative used by the solver.

Custom Time Integration

Custom solvers only need the same step method:

class MyEuler:
    def step(self, rhs, betaCells, time, timeStep):
        evaluation = rhs(betaCells, time)
        return TimeIntegrationResult(
            betaCells=betaCells + timeStep * evaluation.derivative,
            evaluation=evaluation,
        )

TimeDerivative contains:

  • betaCells

  • dndtPump

  • dndtAse

  • derivative

  • tau

  • phiAse

  • aseResult

Here dndtPump, dndtAse, and derivative are contributions to \(d\beta/dt\); tau is the fluorescence lifetime \(\tau\), and phiAse is the ASE flux \(\Phi_i\).

VTK Export

vtkWedge writes point or cell data on the wedge mesh to a legacy ASCII VTK file.

Callback use:

simulation.onStep(vtkWedge("minimal_phi_ase_{step:03d}.vtk", medium))

Direct use:

state = simulation.step()
vtkWedge("phi.vtk", state, medium)
vtkWedge("beta.vtk", state.betaCells, medium, scalar_name="betaCells")

By default it reads state.phiAse (\(\Phi_i\)). Use field to export another field:

simulation.onStep(vtkWedge("beta_{step:03d}.vtk", medium, field="betaCells"))

Use every to reduce output frequency:

simulation.onStep(vtkWedge("phi_{step:03d}.vtk", medium, every=10))

The data shape must match either:

  • point data: (numberOfPoints, numberOfLevels)

  • cell data: (numberOfTriangles, numberOfLevels - 1)

Physical Constants

Constants stores the predefined physical constants used by the default pump routine. Simulation creates this object automatically, so most users do not need to pass constants explicitly.

from HASEonGPU import Constants

constants = Constants()
constants.speedOfLight
constants.planckConstant

These correspond to \(c\) and \(h\) in the pump equations.

The short names used by the low-level pump routine remain available as aliases:

constants.c
constants.h
constants.toDict()
constants.describeConstant("speedOfLight")

Backend Names

AlpakaBackends can list backend names discovered from the installed HASEonGPU backend-name library. Use these strings wherever the Python interface accepts a backend option, for example in PhiASE or the low-level calcPhiASE(...) call:

from HASEonGPU import AlpakaBackends, PhiASE

available = AlpakaBackends.all()
backend = available[0]

phi_ase = PhiASE(backend=backend)

AlpakaBackends.known() is an alias for AlpakaBackends.all(). Backend names that are valid Python identifiers are also exposed as class attributes, for example AlpakaBackends.Host_Cpu_CpuSerial.

For details on how the helper library is built and how backend names are formed, see Backend Selection.