Skip to content

Commit

Permalink
fluids: Add SmartSimDataDestroy
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwrigh committed Nov 27, 2023
1 parent e17e35b commit b306c3f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/fluids/navierstokes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions examples/fluids/navierstokes.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,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);
Expand Down
9 changes: 9 additions & 0 deletions examples/fluids/src/smartsim/smartsim.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,12 @@ PetscErrorCode SmartSimSetup(User user) {
PetscCall(SmartSimTrainingSetup(user));
PetscFunctionReturn(PETSC_SUCCESS);
}

PetscErrorCode SmartSimDataDestroy(SmartSimData smartsim) {
PetscFunctionBeginUser;
if (!smartsim) PetscFunctionReturn(PETSC_SUCCESS);

SmartRedisCall(DeleteCClient(&smartsim->client));
PetscCall(PetscFree(smartsim));
PetscFunctionReturn(PETSC_SUCCESS);
}
9 changes: 9 additions & 0 deletions examples/fluids/src/smartsim_weak.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit b306c3f

Please sign in to comment.