diff --git a/examples/fluids/navierstokes.c b/examples/fluids/navierstokes.c index 74beee5d5e..64875ca72e 100644 --- a/examples/fluids/navierstokes.c +++ b/examples/fluids/navierstokes.c @@ -259,6 +259,7 @@ int main(int argc, char **argv) { PetscCall(SgsDDDataDestroy(user->sgs_dd_data)); PetscCall(DifferentialFilterDataDestroy(user->diff_filter)); PetscCall(SGS_DD_TrainingDataDestroy(user->sgs_dd_train)); + PetscCall(SmartSimDataDestroy(user->smartsim)); // -- Vectors PetscCallCeed(ceed, CeedVectorDestroy(&ceed_data->x_coord)); diff --git a/examples/fluids/navierstokes.h b/examples/fluids/navierstokes.h index eae2561bad..1e493c73f1 100644 --- a/examples/fluids/navierstokes.h +++ b/examples/fluids/navierstokes.h @@ -513,6 +513,7 @@ PetscErrorCode DifferentialFilterMmsICSetup(ProblemData *problem); // SGS Data-Driven Training via SmartSim // ----------------------------------------------------------------------------- PetscErrorCode SmartSimSetup(User user); +PetscErrorCode SmartSimDataDestroy(SmartSimData smartsim); PetscErrorCode SGS_DD_TrainingSetup(Ceed ceed, User user, CeedData ceed_data, ProblemData *problem); PetscErrorCode TSMonitor_SGS_DD_Training(TS ts, PetscInt step_num, PetscReal solution_time, Vec Q, void *ctx); PetscErrorCode TSPostStep_SGS_DD_Training(TS ts); diff --git a/examples/fluids/src/smartsim/smartsim.c b/examples/fluids/src/smartsim/smartsim.c index 9228a8cc27..2fcbc22141 100644 --- a/examples/fluids/src/smartsim/smartsim.c +++ b/examples/fluids/src/smartsim/smartsim.c @@ -64,3 +64,13 @@ PetscErrorCode SmartSimSetup(User user) { PetscCall(SmartSimTrainingSetup(user)); PetscFunctionReturn(0); } + +PetscErrorCode SmartSimDataDestroy(SmartSimData smartsim) { + PetscFunctionBeginUser; + if (!smartsim) PetscFunctionReturn(PETSC_SUCCESS); + + SmartRedisCall(DeleteCClient(&smartsim->client)); + PetscCall(PetscFree(smartsim)); + + PetscFunctionReturn(PETSC_SUCCESS); +} diff --git a/examples/fluids/src/smartsim_weak.c b/examples/fluids/src/smartsim_weak.c index 3a1c5cd001..bf3031c959 100644 --- a/examples/fluids/src/smartsim_weak.c +++ b/examples/fluids/src/smartsim_weak.c @@ -35,3 +35,12 @@ PetscErrorCode TSPostStep_SGS_DD_Training(TS ts) { PetscFunctionBeginUser; SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_SUP, "Must build with SMARTREDIS_DIR set to run %s", __func__); }; + +PetscErrorCode SmartSimDataDestroy(SmartSimData smartsim) __attribute__((weak)); +PetscErrorCode SmartSimDataDestroy(SmartSimData smartsim) { + PetscFunctionBeginUser; + if (!smartsim) PetscFunctionReturn(PETSC_SUCCESS); + PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Warning: SmartSimData struct should not be initialized if SMARTREDIS_DIR isn't set on build...")); + + PetscFunctionReturn(PETSC_SUCCESS); +}