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

Version fusion #128

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 7 additions & 2 deletions Adapter.C
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ void preciceAdapter::Adapter::execute()
{
// Check if the time directory already exists
// (i.e. the solver wrote results that need to be updated)
if (runTime_.timePath().type() == fileName::DIRECTORY)
#include "version-specific/directory_type.H"
if (runTime_.timePath().type() == directory_type)
{
adapterInfo
(
Expand Down Expand Up @@ -607,7 +608,11 @@ void preciceAdapter::Adapter::adjustSolverTimeStep()
// Update the solver's timestep (but don't trigger the adjustDeltaT(),
// which also triggers the functionObject's adjustTimeStep())
// TODO: Keep this in mind if any relevant problem appears.
const_cast<Time&>(runTime_).setDeltaT(timestepSolver_, false);
//
// Version-specific code with possible variants:
// - const_cast<Time&>(runTime_).setDeltaT(timestepSolver_, false);
// - const_cast<Time&>(runTime_).setDeltaTNoAdjust(timestepSolver_);
#include "version-specific/setDeltaT.H"

return;
}
Expand Down
10 changes: 10 additions & 0 deletions Allwmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ ADAPTER_TARGET_DIR="${FOAM_USER_LIBBIN}"
# More information for compatibility with OpenFOAM
DOC_COMPATIBILITY="https://github.com/precice/openfoam-adapter/wiki/Notes-on-OpenFOAM"

################################################################################
# Guess the OpenFOAM version.
# We have version-specific files under variants/
ADAPTER_OPENFOAM_VARIANT="default"
if [ "${WM_PROJECT}" = "OpenFOAM" ]; then
ADAPTER_OPENFOAM_VARIANT=${WM_PROJECT_VERSION}
fi

################################################################################
# Funtion to print to screen and copy to a logfile
log () {
Expand Down Expand Up @@ -65,6 +73,7 @@ fi
# Export the environment variables
export ADAPTER_PRECICE_ROOT
export ADAPTER_PRECICE_DEP
export ADAPTER_OPENFOAM_VARIANT
export ADAPTER_PREP_FLAGS
export ADAPTER_TARGET_DIR
export ADAPTER_GLOBAL_CPLUS_INC_PATHS
Expand All @@ -78,6 +87,7 @@ log ""
log "Current OpenFOAM environment:"
log " WM_PROJECT = ${WM_PROJECT}"
log " WM_PROJECT_VERSION = ${WM_PROJECT_VERSION}"
log " ADAPTER_OPENFOAM_VARIANT = ${ADAPTER_OPENFOAM_VARIANT}"

if [ -z "${WM_PROJECT}" ]; then
log ""
Expand Down
1 change: 1 addition & 0 deletions Make/options
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ EXE_INC = \
-I$(LIB_SRC)/TurbulenceModels/incompressible/lnInclude \
-I$(LIB_SRC)/triSurface/lnInclude \
$(ADAPTER_GLOBAL_CPLUS_INC_PATHS) \
-Ivariants/$(ADAPTER_OPENFOAM_VARIANT) \
-I$(ADAPTER_PRECICE_ROOT)/src \
$(ADAPTER_PKG_CONFIG_CFLAGS) \
-I../ \
Expand Down
8 changes: 2 additions & 6 deletions preciceAdapterFunctionObject.C
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,8 @@ Foam::functionObjects::preciceAdapterFunctionObject::preciceAdapterFunctionObjec
fvMeshFunctionObject(name, runTime, dict),
adapter_(runTime, mesh_)
{
#if (defined OPENFOAM_PLUS && (OPENFOAM_PLUS >= 1712) ) || (defined OPENFOAM && (OPENFOAM >= 1806))
// Patch for issue #27: warning "MPI was already finalized" while
// running in serial. This only affects openfoam.com, while initNull()
// does not exist in openfoam.org.
UPstream::initNull();
#endif

#include "version-specific/init.H"

read(dict);
}
Expand Down
1 change: 1 addition & 0 deletions variants/4.0/version-specific/directory_type.H
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
auto directory_type{fileName::DIRECTORY};
1 change: 1 addition & 0 deletions variants/4.0/version-specific/init.H
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
std::cout << "Using a variant of the preciceAdapter for OpenFOAM 4.0 and 4.1." << std::endl;
1 change: 1 addition & 0 deletions variants/4.0/version-specific/setDeltaT.H
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const_cast<Time&>(runTime_).setDeltaT(timestepSolver_, false);
1 change: 1 addition & 0 deletions variants/4.1
1 change: 1 addition & 0 deletions variants/5.0/version-specific/directory_type.H
1 change: 1 addition & 0 deletions variants/5.0/version-specific/init.H
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
std::cout << "Using a variant of the preciceAdapter for OpenFOAM 5.0 and 5.x." << std::endl;
1 change: 1 addition & 0 deletions variants/5.0/version-specific/setDeltaT.H
1 change: 1 addition & 0 deletions variants/6/version-specific/directory_type.H
1 change: 1 addition & 0 deletions variants/6/version-specific/init.H
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
std::cout << "Using a variant of the preciceAdapter for OpenFOAM 6." << std::endl;
1 change: 1 addition & 0 deletions variants/6/version-specific/setDeltaT.H
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const_cast<Time&>(runTime_).setDeltaTNoAdjust(timestepSolver_);
1 change: 1 addition & 0 deletions variants/7/version-specific/directory_type.H
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
auto directory_type{fileType::directory};
1 change: 1 addition & 0 deletions variants/7/version-specific/init.H
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
std::cout << "Using a variant of the preciceAdapter for OpenFOAM 7 or newer." << std::endl;
1 change: 1 addition & 0 deletions variants/7/version-specific/setDeltaT.H
1 change: 1 addition & 0 deletions variants/default
1 change: 1 addition & 0 deletions variants/dev
1 change: 1 addition & 0 deletions variants/v1712/version-specific/directory_type.H
6 changes: 6 additions & 0 deletions variants/v1712/version-specific/init.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
std::cout << "Using a variant of the preciceAdapter for OpenFOAM v1812 or newer." << std::endl;

// Patch for issue #27: warning "MPI was already finalized" while
// running in serial. This only affects openfoam.com, while initNull()
// does not exist in openfoam.org.
UPstream::initNull();
1 change: 1 addition & 0 deletions variants/v1712/version-specific/setDeltaT.H
1 change: 1 addition & 0 deletions variants/v1806
1 change: 1 addition & 0 deletions variants/v1812
1 change: 1 addition & 0 deletions variants/v1906
1 change: 1 addition & 0 deletions variants/v1912