Skip to content

Optimize Elsasser RHS Laplacian computations #41

@anjor

Description

@anjor

Context

Currently, z_plus_rhs() and z_minus_rhs() compute the Laplacian twice:

  1. Perpendicular Laplacian: laplacian(z, kx, ky, kz=None) for Poisson bracket
  2. Full 3D Laplacian: laplacian(z, kx, ky, kz) for dissipation

Potential Optimization

The perpendicular Laplacian is a subset of the full Laplacian:

∇²⊥z = -(kx² + ky²)|z|²
∇²z = -(kx² + ky² + kz²)|z|²

We could compute the full Laplacian once and extract the perpendicular part.

Current Performance Impact

  • Low priority: Laplacian computation is cheap (just array multiplication)
  • Current approach prioritizes code clarity
  • No bottleneck identified in profiling yet

When to Optimize

Only if profiling shows Laplacian computation is a significant fraction (>5%) of runtime.

Implementation Notes

If optimizing:

  1. Add separate_laplacians: bool = True parameter
  2. When False, compute full Laplacian and derive perpendicular part
  3. Benchmark to verify actual speedup
  4. Keep current implementation as fallback for clarity

Related

Labels

enhancement, performance, optimization

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions