Skip to content
Draft
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b01ad23
add checkpointing for basicThermoCloud Lagrangian Particles
Jun 4, 2026
63217b4
add custom implicitPatchInjection library
Jun 4, 2026
599c908
add newline character at end of Utilities.C to eliminate wmkdepend pa…
Jun 5, 2026
daccf65
add implicitPatchInjection/Make platform directories to .gitignore
Jun 6, 2026
9c30fbd
add copyright statements for Corvid Technologies, but do not change
Jun 7, 2026
4f3fc17
style: apply clang-format to pass CI
Jun 7, 2026
aeb3e46
remove contents of implicitPatchInjection/Make/linux64GccDPInt32Opt
Jun 7, 2026
fe1ff5d
update implicitPatchInjection to be able to cache and restore from
Jun 9, 2026
c5037fd
add implicitConeNozzleInjection to support implicit coupling of the C…
Jun 8, 2026
ebbde82
include support for additional cloud types for implicitPatchInjection…
Jun 10, 2026
c777742
include support for additional cloud types for implicitConeNozzleInje…
Jun 10, 2026
fdea0d0
update Adapter.C and Adapter.H to support basicKinematicCloud, basicT…
Jun 10, 2026
61f02d1
add support for basicReactingCloud types
Jun 12, 2026
07755e8
add support for basicReactingMultiphaseClouds
Jun 12, 2026
0b802fb
update formatting to support clang; my continued forgetfullness to ru…
Jun 13, 2026
011a829
refactor implicitConeNozzleInjection and implicitPatchInjection to us…
Jun 15, 2026
c1c1447
remove wmake commands for individual implicitPatchInjection and impli…
Jul 14, 2026
fff057f
added DEBUG(AdapterInfo) statement noting that clouds are being added…
Jul 14, 2026
79eb07b
updated .gitignore to make more general
Jul 14, 2026
72e0b6b
worded doc string differently; added link to native OpenFOAM source c…
Jul 14, 2026
953cbd7
reformatted implicitInjectionWrapper/implicitInjectionWrapper.H to ha…
Jul 14, 2026
9550a91
added README.md for implicitInjectionWrapper
Jul 14, 2026
d6fcdc2
modularize the Lagrangian particle support, both within the Adapter.C…
Jul 14, 2026
ac34673
Apply suggestion from @MakisH
MakisH Jul 15, 2026
3b150ad
Fix pre-commit
MakisH Jul 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
lnInclude/
Make/linux64GccDPInt32Opt/
Make/darwin64ClangDPInt32Opt/
*/Make/linux64GccDPInt32Opt/
*/Make/darwin64ClangDPInt32Opt/
Comment thread
MakisH marked this conversation as resolved.
Outdated

# Editors
.cproject
Expand Down
120 changes: 120 additions & 0 deletions Adapter.C
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,48 @@ void preciceAdapter::Adapter::setupCheckpointing()
{
SETUP_TIMER();

// Lagrangian particle checkpoint setup
activeKinematicClouds_.clear();
activeThermoClouds_.clear();
activeKinematicCollidingClouds_.clear();
activeReactingClouds_.clear();
activeReactingMultiphaseClouds_.clear();

// macro to loop over all names of the cloud type, define a cloud pointer, and populate
// the activeCloud vector with the pointer contents for a given cloud type

#undef setupCloudType
#define setupCloudType(CloudType, ActiveList) \
for (const word& cloudName : mesh_.thisDb().sortedNames<CloudType>()) \
{ \
CloudType* cloudPtr = const_cast<CloudType*>(mesh_.thisDb().getObjectPtr<CloudType>(cloudName)); \
if (cloudPtr) \
{ \
ActiveList.push_back(cloudPtr); \
lagrangianCheckPointed_ = true; \
adapterInfo("Successfully located " #CloudType " '" + cloudName + "' for Lagrangian checkpointing.", "info"); \
} \
}

// run macro for all available cloud types
setupCloudType(basicKinematicCloud, activeKinematicClouds_);
setupCloudType(basicThermoCloud, activeThermoClouds_);
setupCloudType(basicReactingCloud, activeReactingClouds_);
setupCloudType(basicReactingMultiphaseCloud, activeReactingMultiphaseClouds_);
setupCloudType(basicKinematicCollidingCloud, activeKinematicCollidingClouds_);

#undef setupCloudType

// Allocate the 2D backup array with the number of clouds found
if (lagrangianCheckPointed_)
{
backupKinematicParcelsLists_.resize(activeKinematicClouds_.size());
backupThermoParcelsLists_.resize(activeThermoClouds_.size());
backupReactingParcelsLists_.resize(activeReactingClouds_.size());
backupReactingMultiphaseParcelsLists_.resize(activeReactingMultiphaseClouds_.size());
backupKinematicCollidingParcelsLists_.resize(activeKinematicCollidingClouds_.size());
}

// Add fields in the checkpointing list - sorted for parallel consistency
DEBUG(adapterInfo("Adding in checkpointed fields..."));
Comment thread
MakisH marked this conversation as resolved.

Expand Down Expand Up @@ -1269,6 +1311,36 @@ void preciceAdapter::Adapter::readCheckpoint()
}
}

// Lagrangian particle checkpoint read; restore state
if (lagrangianCheckPointed_)
{
// macro to restore the state of different cloud types
#undef restoreCloudType
#define restoreCloudType(CloudType, ActiveList, BackupList) \
for (size_t c = 0; c < ActiveList.size(); ++c) \
{ \
auto& cloud = ActiveList[c]; \
auto& backups = BackupList[c]; \
/* Erase the future state for this cloud */ \
cloud->clear(); \
/* Resurrect the past from this cloud's backups */ \
for (auto& pPtr : backups) \
{ \
CloudType::particleType* restoredPtr = static_cast<CloudType::particleType*>(pPtr().clone().ptr()); \
cloud->addParticle(restoredPtr); \
} \
DEBUG(adapterInfo("Restored " + std::to_string(backups.size()) + " parcels for cloud '" + cloud->name() + "'.")); \
}

restoreCloudType(basicKinematicCloud, activeKinematicClouds_, backupKinematicParcelsLists_);
restoreCloudType(basicThermoCloud, activeThermoClouds_, backupThermoParcelsLists_);
restoreCloudType(basicReactingCloud, activeReactingClouds_, backupReactingParcelsLists_);
restoreCloudType(basicReactingMultiphaseCloud, activeReactingMultiphaseClouds_, backupReactingMultiphaseParcelsLists_);
restoreCloudType(basicKinematicCollidingCloud, activeKinematicCollidingClouds_, backupKinematicCollidingParcelsLists_);

#undef restoreCloudType
}

// NOTE: Add here other field types to read, if needed.

DEBUG(adapterInfo("Checkpoint was read. Time = " + std::to_string(runTime_.value())));
Expand Down Expand Up @@ -1353,6 +1425,37 @@ void preciceAdapter::Adapter::writeCheckpoint()
{
*(pointTensorFieldCopies_.at(i)) == *(pointTensorFields_.at(i));
}

// Lagrangian particle checkpoint write; save current state
if (lagrangianCheckPointed_)
{
#undef backupCloudType
#define backupCloudType(CloudType, ActiveList, BackupList) \
/* loop over all clouds */ \
for (size_t c = 0; c < ActiveList.size(); ++c) \
{ \
auto& cloud = ActiveList[c]; \
auto& backups = BackupList[c]; \
/* clear previous backups */ \
backups.clear(); \
/* Clone the current state for this specific cloud */ \
forAllIter(CloudType, *cloud, iter) \
{ \
CloudType::particleType* clonedPtr = static_cast<CloudType::particleType*>(iter().clone().ptr()); \
backups.push_back(autoPtr<CloudType::particleType>(clonedPtr)); \
} \
DEBUG(adapterInfo("Checkpointed " + std::to_string(backups.size()) + " parcels for cloud '" + cloud->name() + "'.")); \
}

backupCloudType(basicKinematicCloud, activeKinematicClouds_, backupKinematicParcelsLists_);
backupCloudType(basicThermoCloud, activeThermoClouds_, backupThermoParcelsLists_);
backupCloudType(basicReactingCloud, activeReactingClouds_, backupReactingParcelsLists_);
backupCloudType(basicReactingMultiphaseCloud, activeReactingMultiphaseClouds_, backupReactingMultiphaseParcelsLists_);
backupCloudType(basicKinematicCollidingCloud, activeKinematicCollidingClouds_, backupKinematicCollidingParcelsLists_);

#undef backupCloudType
}

// NOTE: Add here other types to write, if needed.

DEBUG(adapterInfo("Checkpoint for time t = " + std::to_string(runTime_.value()) + " was stored."));
Expand Down Expand Up @@ -1566,6 +1669,23 @@ void preciceAdapter::Adapter::teardown()
Generic_ = nullptr;
}

// Delete Lagrangian particle backups
#undef teardownCloudType
#define teardownCloudType(ActiveList, BackupList) \
for (auto& backups : BackupList) \
{ \
backups.clear(); \
} \
BackupList.clear(); \
ActiveList.clear();

teardownCloudType(activeKinematicClouds_, backupKinematicParcelsLists_);
teardownCloudType(activeThermoClouds_, backupThermoParcelsLists_);
teardownCloudType(activeReactingClouds_, backupReactingParcelsLists_);
teardownCloudType(activeReactingMultiphaseClouds_, backupReactingMultiphaseParcelsLists_);
teardownCloudType(activeKinematicCollidingClouds_, backupKinematicCollidingParcelsLists_);

#undef teardownCloudType
// NOTE: Delete your new module here

return;
Expand Down
26 changes: 26 additions & 0 deletions Adapter.H
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@

#include "module-generic/Generic.H"

// Lagrangian particle checkpointing includes
#include "basicThermoCloud.H"
#include "basicReactingCloud.H"
#include "basicReactingMultiphaseCloud.H"
#include "basicKinematicCloud.H"
#include "basicKinematicCollidingCloud.H"

// NOTE: If you want to couple a new variable, include your module's header here.
// You also need to include it in the Make/files file.
// In case you use additional OpenFOAM symbols, you may also need to specify
Expand Down Expand Up @@ -108,6 +115,9 @@ private:
//- Switch to enable the FluidFluid module
bool FFenabled_ = false;

//- Switch for Lagrangian particle checkpointing
bool lagrangianCheckPointed_ = false;

// NOTE: Add a switch for your new module here

//- Switch to enable General module
Expand Down Expand Up @@ -144,6 +154,22 @@ private:
//- Stored (fixed) timestep
double timestepStored_;

// Lagrangian particle cloud pointers

//- Pointer to all active particle clouds
std::vector<Foam::basicThermoCloud*> activeThermoClouds_;
std::vector<Foam::basicReactingCloud*> activeReactingClouds_;
std::vector<Foam::basicReactingMultiphaseCloud*> activeReactingMultiphaseClouds_;
std::vector<Foam::basicKinematicCloud*> activeKinematicClouds_;
std::vector<Foam::basicKinematicCollidingCloud*> activeKinematicCollidingClouds_;

//- 2D Array of cloned particles to hold the current state for each particle cloud
std::vector<std::vector<Foam::autoPtr<Foam::basicThermoCloud::particleType>>> backupThermoParcelsLists_;
std::vector<std::vector<Foam::autoPtr<Foam::basicReactingCloud::particleType>>> backupReactingParcelsLists_;
std::vector<std::vector<Foam::autoPtr<Foam::basicReactingMultiphaseCloud::particleType>>> backupReactingMultiphaseParcelsLists_;
std::vector<std::vector<Foam::autoPtr<Foam::basicKinematicCloud::particleType>>> backupKinematicParcelsLists_;
std::vector<std::vector<Foam::autoPtr<Foam::basicKinematicCollidingCloud::particleType>>> backupKinematicCollidingParcelsLists_;

// Checkpointing

//- Checkpointed time (value)
Expand Down
1 change: 1 addition & 0 deletions Allclean
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if [ -z "${WM_PROJECT_VERSION:-}" ]; then
fi

# Cleanup all the WMake directories
wclean implicitPatchInjection/
wclean && echo "Cleaning complete!"

# Delete the log files
Expand Down
10 changes: 10 additions & 0 deletions Allwmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ ADAPTER_CFLAGS="${PRECICE_OPENFOAM_CFLAGS:-}"
# e.g., add "export WM_NCOMPPROCS=4" to your ~/.bashrc
# Make sure that these options are supported by your OpenFOAM version.
adapter_build_command(){
# log "Building custom Lagrangian particle patch injector..."
# wmake libso implicitPatchInjection/
#
# log "Building custom Lagrangian particle cone nozzle injector..."
# wmake libso implicitConeNozzleInjection/

Comment thread
MakisH marked this conversation as resolved.
Outdated
log "Building implicit injectors..."
wmake libso implicitInjectionWrapper/

log "Building preCICE adapter..."
wmake libso
}

Expand Down
23 changes: 23 additions & 0 deletions Make/options
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/finiteArea/lnInclude \
-I$(LIB_SRC)/faOptions/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/lagrangian/intermediate/lnInclude \
-I$(LIB_SRC)/lagrangian/distributionModels/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/regionModels/lnInclude \
-I$(LIB_SRC)/regionModels/regionModel/lnInclude \
-I$(LIB_SRC)/regionModels/surfaceFilmModels/lnInclude \
-I$(LIB_SRC)/regionFaModels/lnInclude \
-I$(LIB_SRC)/transportModels/ \
-I$(LIB_SRC)/transportModels/incompressible/lnInclude \
-I$(LIB_SRC)/transportModels/compressible/lnInclude \
-I$(LIB_SRC)/transportModels/twoPhaseMixture/lnInclude \
-I$(LIB_SRC)/transportModels/interfaceProperties/lnInclude \
-I$(LIB_SRC)/transportModels/immiscibleIncompressibleTwoPhaseMixture/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/SLGThermo/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/thermophysicalProperties/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/reactionThermo/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/compressible/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/incompressible/lnInclude \
Expand All @@ -22,5 +35,15 @@ LIB_LIBS = \
-lcompressibleTurbulenceModels \
-lincompressibleTurbulenceModels \
-limmiscibleIncompressibleTwoPhaseMixture \
-llagrangian \
-llagrangianIntermediate \
-lspecie \
-lSLGThermo \
-lregionModels \
-lsurfaceFilmModels \
-lreactionThermophysicalModels \
-lthermophysicalProperties \
-lregionFaModels \
-lfiniteArea \

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 am afraid I know the answer, but: Are all of these includes and linking options really needed in the main Make/options, or some of them only in the implicitInjectionWrapper/Make/options?

If we could modularize this feature (ideally with macros to enable/disable it) and make the dependencies optional, I would feel a bit more confident that we can maintain it in the long term and for different versions.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, unfortunately they are all necessary. Lagrangian particle considerations touch a lot. I'll see if I can find an easy way to enable / disable these additions...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I used #ifdef statements to modularize the Lagrangian particle support within the Adapter.C and Adapter.H files. I then added variables so the Make/options files is dynamically modified. Allwmake is updated to look for the presence of an "ADAPTER_ENABLE_LAGRANGIAN" environment variable. If ADAPTER_ENABLE_LAGRANGIAN=1 then -DADAPTER_ENABLE_LAGRANGIAN is added to ADAPTER_CFLAGS and the implicitInjectionWrapper code will be built. If ADAPTER_ENABLE_LAGRANGIAN does not exist or is equal to something other than 1, then neither of these things happen.

$(ADAPTER_PKG_CONFIG_LIBS) \
-lprecice
2 changes: 1 addition & 1 deletion Utilities.C

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.

Unrelated change

Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ bool matchingStrings(std::string s, std::string match)
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); });
std::transform(match.begin(), match.end(), match.begin(), [](unsigned char c) { return std::tolower(c); });
return s.find(match) == 0;
}
}
7 changes: 7 additions & 0 deletions implicitInjectionWrapper/Make/files
Comment thread
MakisH marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
makeImplicitInjectorsKinematic.C
makeImplicitInjectorsKinematicColliding.C
makeImplicitInjectorsThermo.C
makeImplicitInjectorsReacting.C
makeImplicitInjectorsReactingMultiphase.C

LIB = $(FOAM_USER_LIBBIN)/libimplicitInjectors
36 changes: 36 additions & 0 deletions implicitInjectionWrapper/Make/options
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/lagrangian/intermediate/lnInclude \
-I$(LIB_SRC)/lagrangian/distributionModels/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/thermophysicalProperties/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/reactionThermo/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/SLGThermo/lnInclude \
-I$(LIB_SRC)/regionModels/regionModel/lnInclude \
-I$(LIB_SRC)/regionModels/surfaceFilmModels/lnInclude \
-I$(LIB_SRC)/regionFaModels/lnInclude \
-I$(LIB_SRC)/finiteArea/lnInclude \
-I$(LIB_SRC)/faOptions/lnInclude \
-I$(LIB_SRC)/transportModels/incompressible/lnInclude \
-I$(LIB_SRC)/transportModels/compressible/lnInclude

LIB_LIBS = \
-lfiniteVolume \
-llagrangian \
-llagrangianIntermediate \
-ldistributionModels \
-lmeshTools \
-lfluidThermophysicalModels \
-lspecie \
-lthermophysicalProperties \
-lSLGThermo \
-lregionModels \
-lsurfaceFilmModels \
-lregionFaModels \
-lfiniteArea \
-lfaOptions \
-lcompressibleTransportModels \
-lincompressibleTransportModels
Loading
Loading