Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix different dimensions error / Checkpointing issue #158 #344

Merged
merged 11 commits into from
Jan 10, 2025
64 changes: 64 additions & 0 deletions Adapter.C
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ void preciceAdapter::Adapter::execute()
// Read checkpoint if required
if (requiresReadingCheckpoint())
{
pruneCheckpointedFields();
readCheckpoint();
}

Expand Down Expand Up @@ -923,6 +924,69 @@ void preciceAdapter::Adapter::setupCheckpointing()
ACCUMULATE_TIMER(timeInCheckpointingSetup_);
}

void preciceAdapter::Adapter::pruneCheckpointedFields()
{
// Check if checkpointed fields exist in OpenFOAM registry
// If not, remove them from the checkpointed fields vector

word obj;
bool found = false;
std::vector<word> regFields;
std::vector<word> toRemove;

#undef doLocalCode
#define doLocalCode(GeomField, GeomField_, GeomFieldCopies_) \
regFields.clear(); \
toRemove.clear(); \
/* Iterate through fields in OpenFOAM registry */ \
for (const word& obj : mesh_.sortedNames<GeomField>()) \
{ \
regFields.push_back(obj); \
} \
/* Iterate through checkpointed fields */ \
for (uint i = 0; i < GeomFieldCopies_.size(); i++) \
{ \
found = false; \
obj = GeomFieldCopies_.at(i)->name(); \
for (uint j = 0; j < regFields.size(); j++) \
{ \
if (obj == regFields.at(j)) \
{ \
found = true; \
break; \
} \
} \
if (!found) \
{ \
toRemove.push_back(obj); \
} \
} \
if (!toRemove.empty()) \
{ \
for (int i = toRemove.size() - 1; i >= 0; i--) \
{ \
GeomField_.erase(GeomField_.begin() + i); \
delete GeomFieldCopies_.at(i); \
GeomFieldCopies_.erase(GeomFieldCopies_.begin() + i); \
DEBUG(adapterInfo("Removed " #GeomField " : " + toRemove.at(i) + " from the checkpointed fields list.")); \
} \
}

doLocalCode(volScalarField, volScalarFields_, volScalarFieldCopies_);
doLocalCode(volVectorField, volVectorFields_, volVectorFieldCopies_);
doLocalCode(volTensorField, volTensorFields_, volTensorFieldCopies_);
doLocalCode(volSymmTensorField, volSymmTensorFields_, volSymmTensorFieldCopies_);

doLocalCode(surfaceScalarField, surfaceScalarFields_, surfaceScalarFieldCopies_);
doLocalCode(surfaceVectorField, surfaceVectorFields_, surfaceVectorFieldCopies_);
doLocalCode(surfaceTensorField, surfaceTensorFields_, surfaceTensorFieldCopies_);

doLocalCode(pointScalarField, pointScalarFields_, pointScalarFieldCopies_);
doLocalCode(pointVectorField, pointVectorFields_, pointVectorFieldCopies_);
doLocalCode(pointTensorField, pointTensorFields_, pointTensorFieldCopies_);

#undef doLocalCode
}

// All mesh checkpointed fields

Expand Down
4 changes: 4 additions & 0 deletions Adapter.H
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ private:
//- Configure the checkpointing
void setupCheckpointing();

//- Remove checkpointed fields which are not used by OpenFOAM anymore
void pruneCheckpointedFields();


//- Make a copy of the runTime object
void storeCheckpointTime();

Expand Down
2 changes: 2 additions & 0 deletions changelog-entries/344.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fixed a bug where a field was checkpointed, but doesn't exist anymore in OpenFOAM registry, causing a crash when reloading last timestep into OpenFOAM [#344](https://github.com/precice/openfoam-adapter/pull/344)
- Added new function 'pruneCheckpointedFields()' which is called before readCheckpoint().
Loading