3
3
#include "Utilities.H"
4
4
5
5
#include "IOstreams.H"
6
+ #include <algorithm>
6
7
7
8
using namespace Foam ;
8
9
@@ -437,6 +438,7 @@ void preciceAdapter::Adapter::execute()
437
438
// Read checkpoint if required
438
439
if (requiresReadingCheckpoint ())
439
440
{
441
+ pruneCheckpointedFields ();
440
442
readCheckpoint ();
441
443
}
442
444
@@ -895,12 +897,12 @@ void preciceAdapter::Adapter::setupCheckpointing()
895
897
DEBUG (adapterInfo ("Adding in checkpointed fields..." ));
896
898
897
899
#undef doLocalCode
898
- #define doLocalCode (GeomField ) \
899
- /* Checkpoint registered GeomField objects */ \
900
- for (const word& obj : mesh_.sortedNames<GeomField >()) \
901
- { \
902
- addCheckpointField(mesh_.thisDb().getObjectPtr<GeomField >(obj)); \
903
- DEBUG(adapterInfo("Checkpoint " + obj + " : " #GeomField )); \
900
+ #define doLocalCode (GeomFieldType ) \
901
+ /* Checkpoint registered GeomFieldType objects */ \
902
+ for (const word& obj : mesh_.sortedNames<GeomFieldType >()) \
903
+ { \
904
+ addCheckpointField(mesh_.thisDb().getObjectPtr<GeomFieldType >(obj)); \
905
+ DEBUG(adapterInfo("Checkpoint " + obj + " : " #GeomFieldType )); \
904
906
}
905
907
906
908
doLocalCode (volScalarField );
@@ -923,6 +925,64 @@ void preciceAdapter::Adapter::setupCheckpointing()
923
925
ACCUMULATE_TIMER (timeInCheckpointingSetup_ );
924
926
}
925
927
928
+ void preciceAdapter ::Adapter ::pruneCheckpointedFields ()
929
+ {
930
+ // Check if checkpointed fields exist in OpenFOAM registry
931
+ // If not, remove them from the checkpointed fields vector
932
+
933
+ word fieldName ;
934
+ uint index ;
935
+ std ::vector < word > regFields ;
936
+ std ::vector < uint > toRemoveIndices ;
937
+
938
+ #undef doLocalCode
939
+ #define doLocalCode (GeomFieldType , GeomField_ , GeomFieldCopies_ ) \
940
+ regFields.clear(); \
941
+ toRemoveIndices.clear(); \
942
+ index = 0; \
943
+ /* Iterate through fields in OpenFOAM registry */ \
944
+ for (const word & fieldName : mesh_ .sortedNames < GeomFieldType > ()) \
945
+ { \
946
+ regFields .push_back (fieldName ); \
947
+ } \
948
+ /* Iterate through checkpointed fields */ \
949
+ for (GeomFieldType * fieldObj : GeomFieldCopies_ ) \
950
+ { \
951
+ fieldName = fieldObj -> name (); \
952
+ if (std ::find (regFields .begin (), regFields .end (), fieldName ) == regFields .end ()) \
953
+ { \
954
+ toRemoveIndices .push_back (index ); \
955
+ } \
956
+ index += 1 ; \
957
+ } \
958
+ if (!toRemoveIndices .empty ()) \
959
+ { \
960
+ /* Iterate in reverse to avoid index shifting */ \
961
+ for (auto it = toRemoveIndices .rbegin (); it != toRemoveIndices .rend (); ++ it ) \
962
+ { \
963
+ index = * it ; \
964
+ DEBUG (adapterInfo ("Removed " #GeomFieldType " : " + GeomFieldCopies_.at(index)->name() + " from the checkpointed fields list.")); \
965
+ GeomField_.erase(GeomField_.begin() + index); \
966
+ delete GeomFieldCopies_.at(index); \
967
+ GeomFieldCopies_.erase(GeomFieldCopies_.begin() + index); \
968
+ } \
969
+ }
970
+
971
+ doLocalCode (volScalarField , volScalarFields_ , volScalarFieldCopies_ );
972
+ doLocalCode (volVectorField , volVectorFields_ , volVectorFieldCopies_ );
973
+ doLocalCode (volTensorField , volTensorFields_ , volTensorFieldCopies_ );
974
+ doLocalCode (volSymmTensorField , volSymmTensorFields_ , volSymmTensorFieldCopies_ );
975
+
976
+ doLocalCode (surfaceScalarField , surfaceScalarFields_ , surfaceScalarFieldCopies_ );
977
+ doLocalCode (surfaceVectorField , surfaceVectorFields_ , surfaceVectorFieldCopies_ );
978
+ doLocalCode (surfaceTensorField , surfaceTensorFields_ , surfaceTensorFieldCopies_ );
979
+
980
+ doLocalCode (pointScalarField , pointScalarFields_ , pointScalarFieldCopies_ );
981
+ doLocalCode (pointVectorField , pointVectorFields_ , pointVectorFieldCopies_ );
982
+ doLocalCode (pointTensorField , pointTensorFields_ , pointTensorFieldCopies_ );
983
+
984
+ #undef doLocalCode
985
+ }
926
986
927
987
// All mesh checkpointed fields
928
988
0 commit comments