Skip to content
Draft
Show file tree
Hide file tree
Changes from 23 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/

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

#ifdef ADAPTER_ENABLE_LAGRANGIAN
// 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
DEBUG(adapterInfo("Adding in checkpointed clouds..."));

#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());
}
#endif

// 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 +1314,38 @@ void preciceAdapter::Adapter::readCheckpoint()
}
}

#ifdef ADAPTER_ENABLE_LAGRANGIAN
// 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
}
#endif

// 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 +1430,39 @@ void preciceAdapter::Adapter::writeCheckpoint()
{
*(pointTensorFieldCopies_.at(i)) == *(pointTensorFields_.at(i));
}

#ifdef ADAPTER_ENABLE_LAGRANGIAN
// 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
}
#endif

// 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 +1676,25 @@ void preciceAdapter::Adapter::teardown()
Generic_ = nullptr;
}

#ifdef ADAPTER_ENABLE_LAGRANGIAN
// 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
#endif
// NOTE: Delete your new module here

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

#include "module-generic/Generic.H"

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

// 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 +117,11 @@ private:
//- Switch to enable the FluidFluid module
bool FFenabled_ = false;

#ifdef ADAPTER_ENABLE_LAGRANGIAN
//- Switch for Lagrangian particle checkpointing
bool lagrangianCheckPointed_ = false;
#endif

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

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

// Lagrangian particle cloud pointers
#ifdef ADAPTER_ENABLE_LAGRANGIAN
//- 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_;
#endif

// 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
20 changes: 20 additions & 0 deletions Allwmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ set -e -u
# Optional: Preprocessor flags
# "-DADAPTER_DEBUG_MODE" enables debug messages
# "-DADAPTER_ENABLE_TIMINGS" enables time measurements
# "-DADAPTER_ENABLE_LAGRANGIAN" enables lagrangian particle support
ADAPTER_CFLAGS="${PRECICE_OPENFOAM_CFLAGS:-}"

# Build command and options
# In order to compile with multiple threads, set the environment variable WM_NCOMPPROCS,
# e.g., add "export WM_NCOMPPROCS=4" to your ~/.bashrc
# Make sure that these options are supported by your OpenFOAM version.
adapter_build_command(){
if [ "${ADAPTER_ENABLE_LAGRANGIAN:-0}" = "1" ]; then
log "Building implicit injectors..."
wmake libso implicitInjectionWrapper/
fi

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

Expand All @@ -37,6 +44,19 @@ warning() {
# Information header
log "Building the OpenFOAM-preCICE adapter..."

# Check if the user opted into Lagrangian particle features
if [ "${ADAPTER_ENABLE_LAGRANGIAN:-0}" = "1" ]; then
log "Enabling Lagrangian particle tracking support..."
export ADAPTER_CFLAGS="${ADAPTER_CFLAGS} -DADAPTER_ENABLE_LAGRANGIAN"

# export these variables so Make/options can link to them dynamically
export ADAPTER_LAGRANGIAN_INC="-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)/regionModels/lnInclude -I\$(LIB_SRC)/regionModels/regionModel/lnInclude -I\$(LIB_SRC)/regionModels/surfaceFilmModels/lnInclude -I\$(LIB_SRC)/regionFaModels/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"
export ADAPTER_LAGRANGIAN_LIBS="-llagrangian -llagrangianIntermediate -lspecie -lSLGThermo -lregionModels -lsurfaceFilmModels -lreactionThermophysicalModels -lthermophysicalProperties -lregionFaModels -lfiniteArea"
else
export ADAPTER_LAGRANGIAN_INC=""
export ADAPTER_LAGRANGIAN_LIBS=""
fi

# Export the environment variables
export ADAPTER_CFLAGS
export ADAPTER_TARGET_DIR
Expand Down
2 changes: 2 additions & 0 deletions Make/options
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ EXE_INC = \
-I$(LIB_SRC)/TurbulenceModels/compressible/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/incompressible/lnInclude \
-I$(LIB_SRC)/triSurface/lnInclude \
$(ADAPTER_LAGRANGIAN_INC) \
$(ADAPTER_PKG_CONFIG_CFLAGS) \
-I../ \
$(ADAPTER_CFLAGS)
Expand All @@ -22,5 +23,6 @@ LIB_LIBS = \
-lcompressibleTurbulenceModels \
-lincompressibleTurbulenceModels \
-limmiscibleIncompressibleTwoPhaseMixture \
$(ADAPTER_LAGRANGIAN_LIBS) \
$(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