From 49b62673e87fb0ca42267b4ac679e306ef1672b8 Mon Sep 17 00:00:00 2001 From: Max Firmbach <76822743+maxfirmbach@users.noreply.github.com> Date: Fri, 3 Dec 2021 09:14:34 +0100 Subject: [PATCH] Remove last else-cases in FF and CHT (#197) Fixes a bug that is not allowing more than one module at the same time and adds an error message for the case when a dataset is not known by any or too many modules. Co-authored-by: Gerasimos Chourdakis Co-authored-by: David Schneider --- Adapter.C | 53 ++++++++++++++++++++++++++++------------ CHT/CHT.C | 16 +++++++++--- CHT/CHT.H | 4 +-- FF/FF.C | 16 +++++++++--- FF/FF.H | 4 +-- FSI/FSI.C | 20 +++++++++++++-- FSI/FSI.H | 4 +-- changelog-entries/197.md | 1 + 8 files changed, 86 insertions(+), 32 deletions(-) create mode 100644 changelog-entries/197.md diff --git a/Adapter.C b/Adapter.C index 111a61ed..cd2386d7 100644 --- a/Adapter.C +++ b/Adapter.C @@ -259,22 +259,37 @@ void preciceAdapter::Adapter::configure() { std::string dataName = interfacesConfig_.at(i).writeData.at(j); + unsigned int inModules = 0; + // Add CHT-related coupling data writers - if (CHTenabled_) + if (CHTenabled_ && CHT_->addWriters(dataName, interface)) { - CHT_->addWriters(dataName, interface); + inModules++; } // Add FSI-related coupling data writers - if (FSIenabled_) + if (FSIenabled_ && FSI_->addWriters(dataName, interface)) { - FSI_->addWriters(dataName, interface); + inModules++; } // Add FF-related coupling data writers - if (FFenabled_) + if (FFenabled_ && FF_->addWriters(dataName, interface)) { - FF_->addWriters(dataName, interface); + inModules++; + } + + if (inModules == 0) + { + adapterInfo("I don't know how to write \"" + dataName + + "\". Maybe this is a typo or maybe you need to enable some adapter module?", + "error-deferred"); + } + else if (inModules > 1) + { + adapterInfo("It looks like more than one modules can write \"" + dataName + + "\" and I don't know how to choose. Try disabling one of the modules.", + "error-deferred"); } // NOTE: Add any coupling data writers for your module here. @@ -285,22 +300,28 @@ void preciceAdapter::Adapter::configure() { std::string dataName = interfacesConfig_.at(i).readData.at(j); + unsigned int inModules = 0; + // Add CHT-related coupling data readers - if (CHTenabled_) - { - CHT_->addReaders(dataName, interface); - } + if (CHTenabled_ && CHT_->addReaders(dataName, interface)) inModules++; // Add FSI-related coupling data readers - if (FSIenabled_) - { - FSI_->addReaders(dataName, interface); - } + if (FSIenabled_ && FSI_->addReaders(dataName, interface)) inModules++; // Add FF-related coupling data readers - if (FFenabled_) + if (FFenabled_ && FF_->addReaders(dataName, interface)) inModules++; + + if (inModules == 0) + { + adapterInfo("I don't know how to read \"" + dataName + + "\". Maybe this is a typo or maybe you need to enable some adapter module?", + "error-deferred"); + } + else if (inModules > 1) { - FF_->addReaders(dataName, interface); + adapterInfo("It looks like more than one modules can read \"" + dataName + + "\" and I don't know how to choose. Try disabling one of the modules.", + "error-deferred"); } // NOTE: Add any coupling data readers for your module here. diff --git a/CHT/CHT.C b/CHT/CHT.C index 0c05000d..9204e92b 100644 --- a/CHT/CHT.C +++ b/CHT/CHT.C @@ -118,8 +118,10 @@ std::string preciceAdapter::CHT::ConjugateHeatTransfer::determineSolverType() return solverType; } -void preciceAdapter::CHT::ConjugateHeatTransfer::addWriters(std::string dataName, Interface* interface) +bool preciceAdapter::CHT::ConjugateHeatTransfer::addWriters(std::string dataName, Interface* interface) { + bool found = true; // Set to false later, if needed. + if (dataName.find("Sink-Temperature") == 0) { interface->addCouplingDataWriter( @@ -194,7 +196,7 @@ void preciceAdapter::CHT::ConjugateHeatTransfer::addWriters(std::string dataName } else { - adapterInfo("Unknown data type - cannot add " + dataName + ".", "error"); + found = false; } // NOTE: If you want to couple another variable, you need @@ -202,10 +204,14 @@ void preciceAdapter::CHT::ConjugateHeatTransfer::addWriters(std::string dataName // writer here (and as a reader below). // The argument of the dataName.compare() needs to match // the one provided in the adapter's configuration file. + + return found; } -void preciceAdapter::CHT::ConjugateHeatTransfer::addReaders(std::string dataName, Interface* interface) +bool preciceAdapter::CHT::ConjugateHeatTransfer::addReaders(std::string dataName, Interface* interface) { + bool found = true; // Set to false later, if needed. + if (dataName.find("Sink-Temperature") == 0) { interface->addCouplingDataReader( @@ -280,7 +286,7 @@ void preciceAdapter::CHT::ConjugateHeatTransfer::addReaders(std::string dataName } else { - adapterInfo("Unknown data type - cannot add " + dataName + ".", "error"); + found = false; } // NOTE: If you want to couple another variable, you need @@ -288,4 +294,6 @@ void preciceAdapter::CHT::ConjugateHeatTransfer::addReaders(std::string dataName // reader here (and as a writer above). // The argument of the dataName.compare() needs to match // the one provided in the adapter's configuration file. + + return found; } diff --git a/CHT/CHT.H b/CHT/CHT.H index d4bf03fb..2f0c527f 100644 --- a/CHT/CHT.H +++ b/CHT/CHT.H @@ -60,10 +60,10 @@ public: bool configure(const IOdictionary& adapterConfig); //- Add coupling data writers - void addWriters(std::string dataName, Interface* interface); + bool addWriters(std::string dataName, Interface* interface); //- Add coupling data readers - void addReaders(std::string dataName, Interface* interface); + bool addReaders(std::string dataName, Interface* interface); }; } diff --git a/FF/FF.C b/FF/FF.C index 5d016e61..00c2b695 100644 --- a/FF/FF.C +++ b/FF/FF.C @@ -97,8 +97,10 @@ std::string preciceAdapter::FF::FluidFluid::determineSolverType() return solverType; } -void preciceAdapter::FF::FluidFluid::addWriters(std::string dataName, Interface* interface) +bool preciceAdapter::FF::FluidFluid::addWriters(std::string dataName, Interface* interface) { + bool found = true; // Set to false later, if needed. + if (dataName.find("VelocityGradient") == 0) { interface->addCouplingDataWriter( @@ -129,7 +131,7 @@ void preciceAdapter::FF::FluidFluid::addWriters(std::string dataName, Interface* } else { - adapterInfo("Unknown data type - cannot add " + dataName + ".", "error"); + found = false; } // NOTE: If you want to couple another variable, you need @@ -137,10 +139,14 @@ void preciceAdapter::FF::FluidFluid::addWriters(std::string dataName, Interface* // writer here (and as a reader below). // The argument of the dataName.compare() needs to match // the one provided in the adapter's configuration file. + + return found; } -void preciceAdapter::FF::FluidFluid::addReaders(std::string dataName, Interface* interface) +bool preciceAdapter::FF::FluidFluid::addReaders(std::string dataName, Interface* interface) { + bool found = true; // Set to false later, if needed. + if (dataName.find("VelocityGradient") == 0) { interface->addCouplingDataReader( @@ -171,7 +177,7 @@ void preciceAdapter::FF::FluidFluid::addReaders(std::string dataName, Interface* } else { - adapterInfo("Unknown data type - cannot add " + dataName + ".", "error"); + found = false; } // NOTE: If you want to couple another variable, you need @@ -179,4 +185,6 @@ void preciceAdapter::FF::FluidFluid::addReaders(std::string dataName, Interface* // reader here (and as a writer above). // The argument of the dataName.compare() needs to match // the one provided in the adapter's configuration file. + + return found; } diff --git a/FF/FF.H b/FF/FF.H index a8c65582..ded126e0 100644 --- a/FF/FF.H +++ b/FF/FF.H @@ -47,10 +47,10 @@ public: bool configure(const IOdictionary& adapterConfig); //- Add coupling data writers - void addWriters(std::string dataName, Interface* interface); + bool addWriters(std::string dataName, Interface* interface); //- Add coupling data readers - void addReaders(std::string dataName, Interface* interface); + bool addReaders(std::string dataName, Interface* interface); }; } diff --git a/FSI/FSI.C b/FSI/FSI.C index 46d37915..91571f62 100644 --- a/FSI/FSI.C +++ b/FSI/FSI.C @@ -109,8 +109,10 @@ std::string preciceAdapter::FSI::FluidStructureInteraction::determineSolverType( } -void preciceAdapter::FSI::FluidStructureInteraction::addWriters(std::string dataName, Interface* interface) +bool preciceAdapter::FSI::FluidStructureInteraction::addWriters(std::string dataName, Interface* interface) { + bool found = true; // Set to false later, if needed. + if (dataName.find("Force") == 0) { interface->addCouplingDataWriter( @@ -141,16 +143,24 @@ void preciceAdapter::FSI::FluidStructureInteraction::addWriters(std::string data ); DEBUG(adapterInfo("Added writer: Stress.")); } + else + { + found = false; + } // NOTE: If you want to couple another variable, you need // to add your new coupling data user as a coupling data // writer here (and as a reader below). // The argument of the dataName.compare() needs to match // the one provided in the adapter's configuration file. + + return found; } -void preciceAdapter::FSI::FluidStructureInteraction::addReaders(std::string dataName, Interface* interface) +bool preciceAdapter::FSI::FluidStructureInteraction::addReaders(std::string dataName, Interface* interface) { + bool found = true; // Set to false later, if needed. + if (dataName.find("Force") == 0) { interface->addCouplingDataReader( @@ -181,10 +191,16 @@ void preciceAdapter::FSI::FluidStructureInteraction::addReaders(std::string data ); DEBUG(adapterInfo("Added reader: Stress.")); } + else + { + found = false; + } // NOTE: If you want to couple another variable, you need // to add your new coupling data user as a coupling data // writer here (and as a writer above). // The argument of the dataName.compare() needs to match // the one provided in the adapter's configuration file. + + return found; } diff --git a/FSI/FSI.H b/FSI/FSI.H index 237a0a9a..3e93d77e 100644 --- a/FSI/FSI.H +++ b/FSI/FSI.H @@ -56,10 +56,10 @@ public: bool configure(const IOdictionary& adapterConfig); //- Add coupling data writers - void addWriters(std::string dataName, Interface* interface); + bool addWriters(std::string dataName, Interface* interface); //- Add coupling data readers - void addReaders(std::string dataName, Interface* interface); + bool addReaders(std::string dataName, Interface* interface); }; } diff --git a/changelog-entries/197.md b/changelog-entries/197.md new file mode 100644 index 00000000..b6a532c8 --- /dev/null +++ b/changelog-entries/197.md @@ -0,0 +1 @@ +- Fixed a bug that was not allowing more than one module at the same time and added an error message for the case when a dataset is not known by any or too many modules. [#197](https://github.com/precice/openfoam-adapter/pull/197)