HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
PetscSetInitialGuessROM.cpp File Reference

Compute an initial guess for implicit solves using a reduced-order model. More...

#include <simulation_object.h>
#include <petscinterface.h>
#include <librom_interface.h>

Go to the source code of this file.

Functions

PetscErrorCode PetscSetInitialGuessROM (SNES snes, Vec X, void *ctxt)
 

Detailed Description

Compute an initial guess for implicit solves using a reduced-order model.

Author
Debojyoti Ghosh

Definition in file PetscSetInitialGuessROM.cpp.

Function Documentation

◆ PetscSetInitialGuessROM()

PetscErrorCode PetscSetInitialGuessROM ( SNES  snes,
Vec  X,
void *  ctxt 
)

Compute the initial guess for a nonlinear solve using a trained libROM reduced-order model.

Parameters
snesNonlinear solver object (see PETSc SNES)
XInitial guess vector
ctxtApplication context

Definition at line 18 of file PetscSetInitialGuessROM.cpp.

21 {
22  PETScContext* context = (PETScContext*) ctxt;
23  SimulationObject* sim = (SimulationObject*) context->simobj;
24  int nsims = context->nsims;
25 
26  PetscFunctionBegin;
27 
28  double stage_time = context->t_start;
29  if (context->stage_times.size() > (context->stage_index+1)) {
30  stage_time += context->stage_times[context->stage_index+1] * context->dt;
31  } else {
32  stage_time += context->dt;
33  }
34 
35  ((libROMInterface*)context->rom_interface)->predict(sim, stage_time);
36  if (!context->rank) {
37  printf( "libROM: Predicted ROM intial guess (time %1.4e), wallclock time: %f.\n",
38  stage_time, ((libROMInterface*)context->rom_interface)->predictWallclockTime() );
39  }
40 
41  for (int ns = 0; ns < nsims; ns++) {
42  TransferVecToPETSc(sim[ns].solver.u,X,context,ns,context->offsets[ns]);
43  }
44 
45 
46  PetscFunctionReturn(0);
47 }
int TransferVecToPETSc(const double *const, Vec, void *, const int, const int)
Structure defining a simulation.
std::vector< double > stage_times
Structure containing the variables for time-integration with PETSc.
Class implementing interface with libROM.