Skip to content

Commit

Permalink
Remove last else-cases in FF and CHT (#197)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: David Schneider <[email protected]>
  • Loading branch information
3 people authored Dec 3, 2021
1 parent 88be6ae commit 49b6267
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 32 deletions.
53 changes: 37 additions & 16 deletions Adapter.C
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
16 changes: 12 additions & 4 deletions CHT/CHT.C
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -194,18 +196,22 @@ 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
// 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::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(
Expand Down Expand Up @@ -280,12 +286,14 @@ 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
// to add your new coupling data user as a coupling data
// 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;
}
4 changes: 2 additions & 2 deletions CHT/CHT.H
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

}
Expand Down
16 changes: 12 additions & 4 deletions FF/FF.C
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -129,18 +131,22 @@ 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
// 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::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(
Expand Down Expand Up @@ -171,12 +177,14 @@ 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
// to add your new coupling data user as a coupling data
// 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;
}
4 changes: 2 additions & 2 deletions FF/FF.H
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

}
Expand Down
20 changes: 18 additions & 2 deletions FSI/FSI.C
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions FSI/FSI.H
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

}
Expand Down
1 change: 1 addition & 0 deletions changelog-entries/197.md
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 49b6267

Please sign in to comment.