Skip to content
Draft
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
53 changes: 36 additions & 17 deletions Adapter.C
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ bool preciceAdapter::Adapter::configFileRead()
{
FFenabled_ = true;
}

if (module == "GENERAL")
{
generalModuleEnabled_ = true;
}
}

// Every interface is a subdictionary of "interfaces",
Expand Down Expand Up @@ -138,17 +143,20 @@ bool preciceAdapter::Adapter::configFileRead()
}

DEBUG(adapterInfo(" writeData : "));
auto writeData = interfaceDict.get<wordList>("writeData");
for (auto writeDatum : writeData)
// Get writeData as a dictionary
const dictionary& writeDataDict = interfaceDict.subDict("writeData");
for (const entry& writeDatumEntry : writeDataDict)
{
word writeDatum = writeDatumEntry.keyword();
interfaceConfig.writeData.push_back(writeDatum);
DEBUG(adapterInfo(" - " + writeDatum));
}

DEBUG(adapterInfo(" readData : "));
auto readData = interfaceDict.get<wordList>("readData");
for (auto readDatum : readData)
const dictionary& readDataDict = interfaceDict.subDict("readData");
for (const entry& readDatumEntry : readDataDict)
{
word readDatum = readDatumEntry.keyword();
interfaceConfig.readData.push_back(readDatum);
DEBUG(adapterInfo(" - " + readDatum));
}
Expand All @@ -159,6 +167,15 @@ bool preciceAdapter::Adapter::configFileRead()

// NOTE: set the switch for your new module here

if (generalModuleEnabled_)
{
MODULE_ = new MODULE::GeneralInterface(mesh_);
if (!MODULE_->configure(preciceDict))
{
return false;
}
}

// If the CHT module is enabled, create it, read the
// CHT-specific options and configure it.
if (CHTenabled_)
Expand Down Expand Up @@ -206,7 +223,7 @@ bool preciceAdapter::Adapter::configFileRead()

// NOTE: Create your module and read any options specific to it here

if (!CHTenabled_ && !FSIenabled_ && !FFenabled_) // NOTE: Add your new switch here
if (!CHTenabled_ && !FSIenabled_ && !FFenabled_ && !generalModuleEnabled_) // NOTE: Add your new switch here
{
adapterInfo("No module is enabled.", "error-deferred");
return false;
Expand Down Expand Up @@ -290,22 +307,15 @@ void preciceAdapter::Adapter::configure()
unsigned int inModules = 0;

// Add CHT-related coupling data writers
if (CHTenabled_ && CHT_->addWriters(dataName, interface))
{
inModules++;
}
if (CHTenabled_ && CHT_->addWriters(dataName, interface)) inModules++;

// Add FSI-related coupling data writers
if (FSIenabled_ && FSI_->addWriters(dataName, interface))
{
inModules++;
}
if (FSIenabled_ && FSI_->addWriters(dataName, interface)) inModules++;

// Add FF-related coupling data writers
if (FFenabled_ && FF_->addWriters(dataName, interface))
{
inModules++;
}
if (FFenabled_ && FF_->addWriters(dataName, interface)) inModules++;

if (generalModuleEnabled_ && MODULE_->addWriters(dataName, interface)) inModules++;

if (inModules == 0)
{
Expand Down Expand Up @@ -339,6 +349,8 @@ void preciceAdapter::Adapter::configure()
// Add FF-related coupling data readers
if (FFenabled_ && FF_->addReaders(dataName, interface)) inModules++;

if (generalModuleEnabled_ && MODULE_->addReaders(dataName, interface)) inModules++;

if (inModules == 0)
{
adapterInfo("I don't know how to read \"" + dataName
Expand Down Expand Up @@ -1639,6 +1651,13 @@ void preciceAdapter::Adapter::teardown()
FF_ = NULL;
}

if (NULL != MODULE_)
{
DEBUG(adapterInfo("Destroying the general module..."));
delete MODULE_;
MODULE_ = NULL;
}

// NOTE: Delete your new module here

return;
Expand Down
7 changes: 7 additions & 0 deletions Adapter.H
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// Fluid-Fluid module
#include "FF/FF.H"

#include "GENERAL/MODULE.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 @@ -102,6 +104,9 @@ private:

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

//- Switch to enable General module
bool generalModuleEnabled_ = false;

//- Interfaces
std::vector<Interface*> interfaces_;

Expand All @@ -122,6 +127,8 @@ private:

// NOTE: Add here a pointer for your new module object

MODULE::GeneralInterface* MODULE_ = NULL;

// Timesteps

//- Timestep used by the solver
Expand Down
136 changes: 136 additions & 0 deletions GENERAL/MODULE.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#include "MODULE.H"

#include "Utilities.H"

using namespace Foam;

preciceAdapter::MODULE::GeneralInterface::GeneralInterface(
const Foam::fvMesh& mesh)
: mesh_(mesh) {}

bool preciceAdapter::MODULE::GeneralInterface::configure(const IOdictionary& adapterConfig)
{
DEBUG(adapterInfo("Configuring the GENERAL module..."));

// Read the GENERAL-specific options from the adapter's configuration file
if (!readConfig(adapterConfig))
{
return false;
}

return true;
}

bool preciceAdapter::MODULE::GeneralInterface::readConfig(const IOdictionary& adapterConfig)
{
DEBUG(adapterInfo("Reading GENERAL module configuration..."));

// const dictionary& moduleDict = adapterConfig.subOrEmptyDict("MODULE");

// TODO: Reduce code duplication and get the interfaces configuration from preciceAdapter:Adapter

const dictionary* interfaceDictPtr = adapterConfig.findDict("interfaces");
struct InterfaceConfig interfaceConfig;

for (const entry& interfaceDictEntry : *interfaceDictPtr)
{
if (interfaceDictEntry.isDict())
{
const dictionary& interfaceDict = interfaceDictEntry.dict();

DEBUG(adapterInfo(" writeData : "));
// Get writeData as a dictionary
const dictionary& writeDataDict = interfaceDict.subDict("writeData");
for (const entry& writeDatumEntry : writeDataDict)
{

const dictionary& writeDatumDict = writeDatumEntry.dict();
word dataName = writeDatumEntry.keyword();

struct fieldConfig fieldConfig;
fieldConfig.name = dataName;
fieldConfig.solver_name = writeDatumDict.lookupOrDefault<word>("solver_name", dataName); // default solver_name is the same
fieldConfig.operation = writeDatumDict.lookupOrDefault<word>("operation", "value"); // default operation is "value"

interfaceConfig.writeData.push_back(fieldConfig);

DEBUG(adapterInfo(" - " + dataName));
DEBUG(adapterInfo(" solver_name: " + fieldConfig.solver_name));
DEBUG(adapterInfo(" operation : " + fieldConfig.operation));
}

DEBUG(adapterInfo(" readData : "));
const dictionary& readDataDict = interfaceDict.subDict("readData");
for (const entry& readDatumEntry : readDataDict)
{
const dictionary& readDatumDict = readDatumEntry.dict();
word dataName = readDatumEntry.keyword();

struct fieldConfig fieldConfig;
fieldConfig.name = dataName;
fieldConfig.solver_name = readDatumDict.lookupOrDefault<word>("solver_name", dataName); // default solver_name is the same
fieldConfig.operation = readDatumDict.lookupOrDefault<word>("operation", "value"); // default operation is "value"

interfaceConfig.readData.push_back(fieldConfig);

DEBUG(adapterInfo(" - " + dataName));
DEBUG(adapterInfo(" solver_name: " + fieldConfig.solver_name));
DEBUG(adapterInfo(" operation : " + fieldConfig.operation));
}
interfacesConfig_.push_back(interfaceConfig);
}
}

return true;
}

bool preciceAdapter::MODULE::GeneralInterface::addWriters(std::string dataName, Interface* interface)
{
bool found = true; // Set to false later, if needed.

// TODO: refactor to get rid of the loop
// TODO: determine type of data (scalar, vector, etc.) from lookupObject

// for all interfaces
for (uint i = 0; i < interfacesConfig_.size(); i++)
{
// find the writer corresponding to dataName
for (uint j = 0; j < interfacesConfig_.at(i).writeData.size(); j++)
{
const struct fieldConfig& fieldConfig = interfacesConfig_.at(i).writeData.at(j);
if (fieldConfig.name == dataName)
{
interface->addCouplingDataWriter(
dataName,
new ScalarFieldCoupler(mesh_, fieldConfig));

DEBUG(adapterInfo("Added writer: " + dataName));
}
}
}

return found;
}

bool preciceAdapter::MODULE::GeneralInterface::addReaders(std::string dataName, Interface* interface)
{
bool found = true; // Set to false later, if needed.

for (uint i = 0; i < interfacesConfig_.size(); i++)
{
for (uint j = 0; j < interfacesConfig_.at(i).readData.size(); j++)
{
const struct fieldConfig& fieldConfig = interfacesConfig_.at(i).readData.at(j);
if (fieldConfig.name == dataName)
{
interface->addCouplingDataReader(
dataName,
new ScalarFieldCoupler(mesh_, fieldConfig));

DEBUG(adapterInfo("Added reader: " + dataName));
}
}
}

return found;
}
51 changes: 51 additions & 0 deletions GENERAL/MODULE.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef GENERALMODULE_H
#define GENERALMODULE_H

#include "Interface.H"

#include "GENERAL/ReadWrite.H"

#include "fvCFD.H"

namespace preciceAdapter
{
namespace MODULE
{

class GeneralInterface
{
protected:
//- OpenFOAM fvMesh object
const Foam::fvMesh& mesh_;

//- Read the Module related options from the adapter's configuration file
bool readConfig(const IOdictionary& adapterConfig);

//- Struct to store interfaces configuration (modified from Adapter.C)
struct InterfaceConfig
{
std::vector<struct fieldConfig> writeData;
std::vector<struct fieldConfig> readData;
};

//- Configuration interfaces
std::vector<struct InterfaceConfig> interfacesConfig_;

public:
//- Constructor
GeneralInterface(const Foam::fvMesh& mesh);

//- Configure
bool configure(const IOdictionary& adapterConfig);

//- Add coupling data writers
bool addWriters(std::string dataName, Interface* interface);

//- Add coupling data readers
bool addReaders(std::string dataName, Interface* interface);
};

}
}

#endif
3 changes: 3 additions & 0 deletions GENERAL/ModuleGeneral.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Central inlude file to reduce the number of build targets and build time
#include "ReadWrite.C"
#include "MODULE.C"
Loading