Skip to content

Mesh checkpointing refactor#387

Merged
MakisH merged 11 commits into
developfrom
mesh-checkpointing-refactor
Feb 2, 2026
Merged

Mesh checkpointing refactor#387
MakisH merged 11 commits into
developfrom
mesh-checkpointing-refactor

Conversation

@vidulejs
Copy link
Copy Markdown
Collaborator

@vidulejs vidulejs commented Jan 14, 2026

Overview

This pull request removes redundant checkpointing methods, which were either unused or had no effect. More detail on this later. This results in the large amount of line removals of this PR. In addition I refactored and cleaned up the mesh points checkpointing.

This pull request is one half of a larger refactor - PR #369, which also contains logic to correctly checkpoint mesh volumes, however it became clear that mesh volume checkpointing should not be merged at this time.

All methods and comments related to volume checkpointing were completely removed, since they haven't served any purpose so far. In the future the volume checkpointing could be re-implemented based on PR #369, however the only effect would be on implicit subcycling (see discussion on that PR).

Changes:

  • Removed volume checkpointing methods and comments
  • Removed comments and checkpoints for mesh fields which are unused (meshSurfaceVectorFields_, meshVolVectorFields_, volScalarInternalFields_)
  • Updated multi-line debug statements to one-liners.
  • Mesh points checkpointing refactor
    • Changed the checkpoints from references to pointers, just like the rest of the checkpoints
    • Renamed oldMeshPoints to meshOldPoints (like fvMesh.oldPoints() method)
    • Fixed subtle issue in mesh oldPoints restoration, added code comment, see below

Cleanup and refactor

This relates to the bulk of line removals in this branch.

Just like checkpointed fields of physical variables, there were different types of checkpointed mesh fields, however they were unnecessary and empty. There were no meshVolVectorFields_ or meshSurfaceVectorFields_ (none that needed checkpointing) . The only checkpointed mesh field is face motion flux mesh_.phi() of type surfaceScalarField. As pointed to by in a comment in setupMeshCheckpointing():

// The other mesh Fields:
// C
// Cf
// Sf
// magSf
// delta
// are updated by the function fvMesh::movePoints. Only the meshPhi needs checkpointing.

Edit: See new comment below with further explanation.

Mesh Points Checkpointing

  • Store meshPoints_ and meshOldPoints_ as pointers instead of objects for consistency with the rest of the codebase. These are actually pointers to the copies managed by the adapter.

  • The main logic of restoring mesh point checkpoints is like this:

    // Reload mesh points
    const_cast<Foam::fvMesh&>(mesh_).movePoints(*meshPoints_);

    // polyMesh.movePoints will only update oldPoints
    // if (curMotionTimeIndex_ != time().timeIndex())
    // I.e., first implicit iteration
    const_cast<pointField&>(mesh_.oldPoints()) = *meshOldPoints_;

Otherwise mesh_.oldPoints() would not get updated inside of fvMesh.movePoints() -> polyMesh.movePoints() in implicit iterations.

Potentially this has can have no effect on the results, since we already checkpoint face motion flux mesh_.phi(), which is the delta between points and oldPoints. However, there will be a difference when doing implicit subcycling, see the discussion in PR #369.

TODO list:

  • I updated the documentation in docs/
  • I added a changelog entry in changelog-entries/ (create directory if missing)

…eckpointing. Remove unused mesh fields (meshSurfaceVectorFields_, meshVolVectorFields_, volScalarInternalFields_).
… of a reference, consistent with the rest of the checkpoints.
@vidulejs vidulejs marked this pull request as ready for review January 14, 2026 09:54
@vidulejs
Copy link
Copy Markdown
Collaborator Author

The reason why we do not need to checkpoint the mesh fields is that they are calculated on-demand once the mesh points move. This was also pointed to by the comment that was already in the OpenFOAM-adapter. Another reason why we don't need checkpoints for these fields is that they do not have .oldTime() method and thus do not participate in the time integration scheme. When we reload the checkpoint we will call fvMesh::movePoints(), which will in turn invalidate the old versions of these fields and recompute them in fvMesh::updateGeomNotOldVol().

void Foam::fvMesh::movePoints(const pointField& p)
{
   // [...] The comment below is not mine, but from the OpenFOAM source code.

    polyMesh::movePoints(p);

    // Update or delete the local geometric properties as early as possible so
    // they can be used if necessary. These get recreated here instead of
    // demand driven since they might do parallel transfers which can conflict
    // with when they're actually being used.
    // Note that between above "polyMesh::movePoints(p)" and here nothing
    // should use the local geometric properties.
    updateGeomNotOldVol();

   // [...]
}
void Foam::fvMesh::updateGeomNotOldVol()
{
    const bool haveV = (VPtr_ != nullptr);
    const bool haveSf = (SfPtr_ != nullptr);
    const bool haveMagSf = (magSfPtr_ != nullptr);
    const bool haveCP = (CPtr_ != nullptr);
    const bool haveCf = (CfPtr_ != nullptr);

    clearGeomNotOldVol();

    // Now recreate the fields
    if (haveV)
    {
        (void)V();
    }

    if (haveSf)
    {
        (void)Sf();
    }

    if (haveMagSf)
    {
        (void)magSf();
    }

    if (haveCP)
    {
        (void)C();
    }

    if (haveCf)
    {
        (void)Cf();
    }
}

@MakisH MakisH self-requested a review January 16, 2026 10:45
@MakisH MakisH self-assigned this Jan 16, 2026
@MakisH MakisH added dev Not directly affecting users, but helping future development trigger-system-tests labels Jan 16, 2026
Copy link
Copy Markdown
Member

@MakisH MakisH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this long-overdue cleanup!

It's nice to see so much code deleted. Let's also add an overview of checkpointed and non-checkpointed fields in the documentation (as you had a draft in #324 and as discussed on Matrix). The most fitting place would be a new section in https://precice.org/adapter-openfoam-extend.html (formulated from the perspective "this is what the adapter currently checkpoints, you might need to add more for a different use case").

Comment thread Adapter.C
Comment on lines +1310 to +1313
// Store mesh points
// swap pointers
*(meshOldPoints_) = *(meshPoints_);
*(meshPoints_) = mesh_.points();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this (and the previous way, if we use the same sizes) will break once we go for remeshing, correct?

#382

Not necessary to solve it now, but as a first impulse for discussion.

@vidulejs
Copy link
Copy Markdown
Collaborator Author

Added documentation on checkpointed fields in extend.md

Comment thread docs/images/docs-adapter-openfoam-implicit-loop.png
Comment thread docs/extend.md Outdated
Comment thread docs/extend.md Outdated
Comment thread docs/extend.md Outdated
Comment thread docs/extend.md Outdated
Comment thread docs/extend.md
Comment thread docs/extend.md
Comment thread docs/extend.md
vidulejs and others added 6 commits February 2, 2026 13:01
Co-authored-by: Gerasimos Chourdakis <gerasimos.chourdakis@ipvs.uni-stuttgart.de>
Co-authored-by: Gerasimos Chourdakis <gerasimos.chourdakis@ipvs.uni-stuttgart.de>
Co-authored-by: Gerasimos Chourdakis <gerasimos.chourdakis@ipvs.uni-stuttgart.de>
… case headings. Added source file for diagram.
@MakisH MakisH merged commit c166132 into develop Feb 2, 2026
6 checks passed
@MakisH MakisH deleted the mesh-checkpointing-refactor branch February 2, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dev Not directly affecting users, but helping future development trigger-system-tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants