HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
PetscRHSFunctionIMEX.cpp
Go to the documentation of this file.
1 
6 #ifdef with_petsc
7 
8 #include <stdlib.h>
9 #include <basic.h>
10 #include <arrayfunctions.h>
11 #include <mpivars_cpp.h>
12 #include <simulation_object.h>
13 #include <petscinterface.h>
14 
15 #undef __FUNCT__
16 #define __FUNCT__ "PetscRHSFunctionIMEX"
17 
49 PetscErrorCode PetscRHSFunctionIMEX( TS ts,
50  PetscReal t,
51  Vec Y,
52  Vec F,
53  void *ctxt )
54 {
55  PETScContext* context = (PETScContext*) ctxt;
56  SimulationObject* sim = (SimulationObject*) context->simobj;
57  int nsims = context->nsims;
58 
59  context->waqt = t;
60 
61  PetscFunctionBegin;
62  for (int ns = 0; ns < nsims; ns++) {
63 
64  HyPar* solver = &(sim[ns].solver);
65  MPIVariables* mpi = &(sim[ns].mpi);
66 
67  solver->count_RHSFunction++;
68 
69  int size = solver->npoints_local_wghosts;
70  double *u = solver->u;
71  double *rhs = solver->rhs;
72 
73  /* copy solution from PETSc vector */
74  TransferVecFromPETSc(u,Y,context,ns,context->offsets[ns]);
75  /* apply boundary conditions and exchange data over MPI interfaces */
76  solver->ApplyBoundaryConditions(solver,mpi,u,NULL,t);
77  MPIExchangeBoundariesnD(solver->ndims,solver->nvars,solver->dim_local,
78  solver->ghosts,mpi,u);
79 
80  /* initialize right-hand side to zero */
81  _ArraySetValue_(rhs,size*solver->nvars,0.0);
82 
83  /* Evaluate hyperbolic, parabolic and source terms and the RHS */
84  if ((!strcmp(solver->SplitHyperbolicFlux,"yes")) && solver->flag_fdf_specified) {
85  if (context->flag_hyperbolic_f == _EXPLICIT_) {
86  solver->HyperbolicFunction(solver->hyp,u,solver,mpi,t,0,solver->FdFFunction,solver->UpwindFdF);
87  _ArrayAXPY_(solver->hyp,-1.0,rhs,size*solver->nvars);
88  }
89  if (context->flag_hyperbolic_df == _EXPLICIT_) {
90  solver->HyperbolicFunction(solver->hyp,u,solver,mpi,t,0,solver->dFFunction,solver->UpwinddF);
91  _ArrayAXPY_(solver->hyp,-1.0,rhs,size*solver->nvars);
92  }
93  } else if (!strcmp(solver->SplitHyperbolicFlux,"yes")) {
94  if (context->flag_hyperbolic_f == _EXPLICIT_) {
95  solver->HyperbolicFunction(solver->hyp,u,solver,mpi,t,0,solver->FFunction,solver->Upwind);
96  _ArrayAXPY_(solver->hyp,-1.0,rhs,size*solver->nvars);
97  solver->HyperbolicFunction(solver->hyp,u,solver,mpi,t,0,solver->dFFunction,solver->UpwinddF);
98  _ArrayAXPY_(solver->hyp, 1.0,rhs,size*solver->nvars);
99  }
100  if (context->flag_hyperbolic_df == _EXPLICIT_) {
101  solver->HyperbolicFunction(solver->hyp,u,solver,mpi,t,0,solver->dFFunction,solver->UpwinddF);
102  _ArrayAXPY_(solver->hyp,-1.0,rhs,size*solver->nvars);
103  }
104  } else {
105  if (context->flag_hyperbolic == _EXPLICIT_) {
106  solver->HyperbolicFunction(solver->hyp,u,solver,mpi,t,0,solver->FFunction,solver->Upwind);
107  _ArrayAXPY_(solver->hyp,-1.0,rhs,size*solver->nvars);
108  }
109  }
110  if (context->flag_parabolic == _EXPLICIT_) {
111  solver->ParabolicFunction (solver->par,u,solver,mpi,t);
112  _ArrayAXPY_(solver->par, 1.0,rhs,size*solver->nvars);
113  }
114  if (context->flag_source == _EXPLICIT_) {
115  solver->SourceFunction (solver->source,u,solver,mpi,t);
116  _ArrayAXPY_(solver->source, 1.0,rhs,size*solver->nvars);
117  }
118 
119  /* Transfer RHS to PETSc vector */
120  TransferVecToPETSc(rhs,F,context,ns,context->offsets[ns]);
121  }
122 
123  PetscFunctionReturn(0);
124 }
125 
126 #endif
int count_RHSFunction
Definition: hypar.h:422
int TransferVecToPETSc(const double *const, Vec, void *, const int, const int)
int nvars
Definition: hypar.h:29
int(* ParabolicFunction)(double *, double *, void *, void *, double)
Definition: hypar.h:256
Structure defining a simulation.
char SplitHyperbolicFlux[_MAX_STRING_SIZE_]
Definition: hypar.h:92
C++ declarations for MPI-related functions.
double * par
Definition: hypar.h:122
int MPIExchangeBoundariesnD(int, int, int *, int, void *, double *)
int(* ApplyBoundaryConditions)(void *, void *, double *, double *, double)
Definition: hypar.h:214
double * u
Definition: hypar.h:116
Some basic definitions and macros.
Simulation object.
int(* FdFFunction)(double *, double *, int, void *, double)
Definition: hypar.h:286
int(* Upwind)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:295
int(* SourceFunction)(double *, double *, void *, void *, double)
Definition: hypar.h:259
int ndims
Definition: hypar.h:26
int(* HyperbolicFunction)(double *, double *, void *, void *, double, int, int(*)(double *, double *, int, void *, double), int(*)(double *, double *, double *, double *, double *, double *, int, void *, double))
Definition: hypar.h:250
int(* FFunction)(double *, double *, int, void *, double)
Definition: hypar.h:276
double * rhs
Definition: hypar.h:399
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
PetscErrorCode PetscRHSFunctionIMEX(TS ts, PetscReal t, Vec Y, Vec F, void *ctxt)
#define _ArrayAXPY_(x, a, y, size)
int(* UpwindFdF)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:307
int flag_fdf_specified
Definition: hypar.h:290
Structure containing the variables for time-integration with PETSc.
#define _ArraySetValue_(x, size, value)
int * dim_local
Definition: hypar.h:37
int(* dFFunction)(double *, double *, int, void *, double)
Definition: hypar.h:280
int(* UpwinddF)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:300
int ghosts
Definition: hypar.h:52
Structure of MPI-related variables.
int npoints_local_wghosts
Definition: hypar.h:42
Contains macros and function definitions for common array operations.
int TransferVecFromPETSc(double *const, const Vec, void *, const int, const int)
double * source
Definition: hypar.h:125
double * hyp
Definition: hypar.h:119
#define _EXPLICIT_