Extra tools that are useful in hydrodynamical problems.

Module Contents

class GlobalArrayReducer(comm, dtype=np.float64)

Directs parallelized reduction of distributed array data.

  • comm (MPI communicator) – MPI communicator

  • dtype (data type, optional) – Array data type (default: np.float64)

reduce_scalar(local_scalar, mpi_reduce_op)

Compute global reduction of a scalar from each process.

global_min(data, empty=np.inf)

Compute global min of all array data.

global_max(data, empty=- np.inf)

Compute global max of all array data.


Compute global mean of all array data.

class GlobalFlowProperty(solver, cadence=1)

Directs parallelized determination of a global flow property on the grid.

  • solver (solver object) – Problem solver

  • cadence (int, optional) – Iteration cadence for property evaluation (default: 1)


>>> flow = GlobalFlowProperty(solver)
>>> flow.add_property('sqrt(u*u + w*w) * Lz / nu', name='Re')
>>> flow.max('Re')
add_property(property, name, precompute_integral=False)

Add a property.


Compute global min of a property on the grid.


Compute global max of a property on the grid.


Compute global mean of a property on the grid.


Compute volume average of a property.

class CFL(solver, initial_dt, cadence=1, safety=1.0, max_dt=np.inf, min_dt=0.0, max_change=np.inf, min_change=0.0, threshold=0.0)

Computes CFL-limited timestep from a set of frequencies/velocities.

  • solver (solver object) – Problem solver

  • initial_dt (float) – Initial timestep

  • cadence (int, optional) – Iteration cadence for computing new timestep (default: 1)

  • safety (float, optional) – Safety factor for scaling computed timestep (default: 1.)

  • max_dt (float, optional) – Maximum allowable timestep (default: inf)

  • min_dt (float, optional) – Minimum allowable timestep (default: 0.)

  • max_change (float, optional) – Maximum fractional change between timesteps (default: inf)

  • min_change (float, optional) – Minimum fractional change between timesteps (default: 0.)

  • threshold (float, optional) – Fractional change threshold for changing timestep (default: 0.)


The new timestep is computed by summing across the provided frequencies for each grid point, and then reciprocating the maximum “total” frequency from the entire grid.


Compute CFL-limited timestep.


Add an on-grid frequency.

add_velocity(velocity, axis)

Add grid-crossing frequency from a velocity along one axis.


Add grid-crossing frequencies from a tuple of velocity components.


Add grid-crossing frequencies from a diffusivity along all axes. This method treats the non-conservative form, e.g.

dt(C) = diff*di(di(C)) + …

The corresponding timescale for the i-th axis is therefore

freq_i = diff / spacing_i**2


Add grid-crossing frequencies from a diffusivity along all axes. This method treats the conservative form, e.g.

dt(C) = di(diff*di(C)) + …

Expanding the divergence gives advective terms and diffusive terms

di(diff*di(C)) = di(diff)*di(C) + diff*di(di(C))

This results in advective and diffusive frequencies

freq_adv_i = di(diff) / spacing_i freq_diff_i = diff / spacing_i**2