diff --git a/2023-01/smartsim/smartsim_function_object/smartSimFunctionObject/smartSimFunctionObject.C b/2023-01/smartsim/smartsim_function_object/smartSimFunctionObject/smartSimFunctionObject.C index 912e43b5..8279abc6 100644 --- a/2023-01/smartsim/smartsim_function_object/smartSimFunctionObject/smartSimFunctionObject.C +++ b/2023-01/smartsim/smartsim_function_object/smartSimFunctionObject/smartSimFunctionObject.C @@ -45,7 +45,6 @@ namespace functionObjects { defineTypeNameAndDebug(smartSimFunctionObject, 0); addToRunTimeSelectionTable(functionObject, smartSimFunctionObject, dictionary); - SmartRedis::Client smartSimFunctionObject::redisDB(false, "default"); } } @@ -60,11 +59,15 @@ Foam::functionObjects::smartSimFunctionObject::smartSimFunctionObject ) : fvMeshFunctionObject(name, runTime, dict), - //clusterMode_(dict.getOrDefault("clusterMode", true)), + clusterMode_(dict.getOrDefault("clusterMode", true)), + clientName_(dict.getOrDefault("clientName", "default")), fieldNames_(dict.get("fieldNames")), - fieldDimensions_(dict.get("fieldDimensions"))//, + fieldDimensions_(dict.get("fieldDimensions")), + redisDBPtr_(nullptr) //client_(clusterMode_) { + static SmartRedis::Client client(clusterMode_, clientName_.c_str()); + redisDBPtr_.reset(&client); read(dict); } @@ -118,7 +121,7 @@ bool Foam::functionObjects::smartSimFunctionObject::end() const volScalarField& sField = mesh_.lookupObject(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); } @@ -128,7 +131,7 @@ bool Foam::functionObjects::smartSimFunctionObject::end() const volVectorField& vField = mesh_.lookupObject(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 diff --git a/2023-01/smartsim/smartsim_function_object/smartSimFunctionObject/smartSimFunctionObject.H b/2023-01/smartsim/smartsim_function_object/smartSimFunctionObject/smartSimFunctionObject.H index 20de6964..018f0442 100644 --- a/2023-01/smartsim/smartsim_function_object/smartSimFunctionObject/smartSimFunctionObject.H +++ b/2023-01/smartsim/smartsim_function_object/smartSimFunctionObject/smartSimFunctionObject.H @@ -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_; @@ -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 redisDBPtr_; public: //- Runtime type information TypeName("smartSimFunctionObject"); - - //- SmartRedis Database Client - static SmartRedis::Client redisDB; - // Constructors //- Construct from Time and dictionary @@ -217,6 +219,8 @@ public: virtual bool end(); virtual bool write(); + + SmartRedis::Client& redisDB() {return *redisDBPtr_;} }; diff --git a/2023-01/smartsim/smartsim_function_object/tests/smartSimFOTest.C b/2023-01/smartsim/smartsim_function_object/tests/smartSimFOTest.C index 054e63dc..0203f23a 100644 --- a/2023-01/smartsim/smartsim_function_object/tests/smartSimFOTest.C +++ b/2023-01/smartsim/smartsim_function_object/tests/smartSimFOTest.C @@ -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())); }