Skip to content

Allow users to create custom dvar similar to dlon #2339

@erikvansebille

Description

@erikvansebille

Now that we further cleaned up the Kernel loop in #2333, and are also outputting the last output written (a huge improvement with respect to v3), there is another major output-caveat left in the Kernelloop-tutorial:

### 2. Be careful with updating particle variables that do not depend on Fields.
While assigning the interpolated value of a Field to a Particle goes well in the loop above, this is not necessarily so for assigning other attributes. For example, a line like particle.age += particle.dt is executed directly so may result in the age being dt at time = 0 in the output file.

One way to fix this is to treat custom variables the same as lon, lat and z:

  1. Also create a dvar for a custom variable var (note with to_write=False)
  2. Add code in PositionUpdate() in kernel.py that result in something like:
particles.var += particles.dvar
particles.dvar = 0

This nicely aligns with the idea to frame Kernels more as ODE solvers (#2338), where the result of a call to RK2_integrator() would then be a dx.

Open question: should every custom Variable get a d-version, or only if users set a certain flag (and then what should be the default)? This is relevant since variables that won't change during the simulation don't need a d-version and fewer variables means less memory overhead.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions