Skip to content

Commit

Permalink
switch to half-static half-dynamic clients
Browse files Browse the repository at this point in the history
  • Loading branch information
FoamScience committed Nov 2, 2023
1 parent e3c6e84 commit 4dfd763
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ namespace functionObjects
{
defineTypeNameAndDebug(smartSimFunctionObject, 0);
addToRunTimeSelectionTable(functionObject, smartSimFunctionObject, dictionary);
SmartRedis::Client smartSimFunctionObject::redisDB(false, "default");
}
}

Expand All @@ -60,11 +59,15 @@ Foam::functionObjects::smartSimFunctionObject::smartSimFunctionObject
)
:
fvMeshFunctionObject(name, runTime, dict),
//clusterMode_(dict.getOrDefault<bool>("clusterMode", true)),
clusterMode_(dict.getOrDefault<bool>("clusterMode", true)),
clientName_(dict.getOrDefault<word>("clientName", "default")),
fieldNames_(dict.get<wordList>("fieldNames")),
fieldDimensions_(dict.get<labelList>("fieldDimensions"))//,
fieldDimensions_(dict.get<labelList>("fieldDimensions")),
redisDBPtr_(nullptr)
//client_(clusterMode_)
{
static SmartRedis::Client client(clusterMode_, clientName_.c_str());
redisDBPtr_.reset(&client);
read(dict);
}

Expand Down Expand Up @@ -118,7 +121,7 @@ bool Foam::functionObjects::smartSimFunctionObject::end()
const volScalarField& sField = mesh_.lookupObject<volScalarField>(fieldNames_[fieldI]);

// Send the cell-centered scalar field to SmartRedis
redisDB.put_tensor(sField.name(), (void*)sField.internalField().cdata(), dims,
redisDB().put_tensor(sField.name(), (void*)sField.internalField().cdata(), dims,
SRTensorTypeDouble, SRMemLayoutContiguous);

}
Expand All @@ -128,7 +131,7 @@ bool Foam::functionObjects::smartSimFunctionObject::end()
const volVectorField& vField = mesh_.lookupObject<volVectorField>(fieldNames_[fieldI]);

// Send the cell-centered scalar field to SmartRedis
redisDB.put_tensor(vField.name(), (void*)vField.internalField().cdata(), dims,
redisDB().put_tensor(vField.name(), (void*)vField.internalField().cdata(), dims,
SRTensorTypeDouble, SRMemLayoutContiguous);
}
else if (fieldDimensions_[fieldI] == 6) // TODO(TM): symmTensor field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ class smartSimFunctionObject
// Private Data

//- Set to false if not using a clustered database
//bool clusterMode_;
bool clusterMode_;

//- Client name
word clientName_;

//- List of field names to send-receive from SmartRedis
wordList fieldNames_;
Expand All @@ -177,16 +180,15 @@ class smartSimFunctionObject
// list (1,3,6), 1 is scalar field dimension, 3 is a vector field
// dimension and 6 is a symmetric tensor field dimension.
labelList fieldDimensions_;

//- Pointer to the client
autoPtr<SmartRedis::Client> redisDBPtr_;

public:

//- Runtime type information
TypeName("smartSimFunctionObject");


//- SmartRedis Database Client
static SmartRedis::Client redisDB;

// Constructors

//- Construct from Time and dictionary
Expand Down Expand Up @@ -217,6 +219,8 @@ public:
virtual bool end();

virtual bool write();

SmartRedis::Client& redisDB() {return *redisDBPtr_;}
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ TEST_CASE("Shared SmartRedis client", "[cavity][serial][parallel]")
dict1.set("fieldDimensions", labelList());
functionObjects::smartSimFunctionObject o0("smartSim0", runTime, dict0);
functionObjects::smartSimFunctionObject o1("smartSim1", runTime, dict1);
REQUIRE(&(o0.redisDB) == &(o1.redisDB));
REQUIRE(&(o0.redisDB()) == &(o1.redisDB()));
}

0 comments on commit 4dfd763

Please sign in to comment.