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

Function to compute the right-hand-side for explicit time integration. More...

#include <stdlib.h>
#include <basic.h>
#include <arrayfunctions.h>
#include <mpivars_cpp.h>
#include <simulation_object.h>
#include <petscinterface.h>

Go to the source code of this file.

Macros

#define __FUNCT__   "PetscRHSFunctionExpl"
 

Functions

PetscErrorCode PetscRHSFunctionExpl (TS ts, PetscReal t, Vec Y, Vec F, void *ctxt)
 

Detailed Description

Function to compute the right-hand-side for explicit time integration.

Author
Debojyoti Ghosh

Definition in file PetscRHSFunctionExpl.cpp.

Macro Definition Documentation

◆ __FUNCT__

#define __FUNCT__   "PetscRHSFunctionExpl"

Definition at line 16 of file PetscRHSFunctionExpl.cpp.

Function Documentation

◆ PetscRHSFunctionExpl()

PetscErrorCode PetscRHSFunctionExpl ( TS  ts,
PetscReal  t,
Vec  Y,
Vec  F,
void *  ctxt 
)

Compute the right-hand-side (RHS) for the explicit time integration of the governing equations: The spatially discretized ODE can be expressed as

\begin{equation} \frac {d{\bf U}} {dt} = {\bf F}\left({\bf U}\right). \end{equation}

This function computes \({\bf F}\left({\bf U}\right)\), given \({\bf U}\).

See also
TSSetRHSFunction (https://petsc.org/release/docs/manualpages/TS/TSSetRHSFunction.html)

Note:

Parameters
tsTime integration object
tCurrent simulation time
YState vector (input)
FThe computed right-hand-side vector
ctxtObject of type PETScContext

Definition at line 36 of file PetscRHSFunctionExpl.cpp.

41 {
42  PETScContext* context = (PETScContext*) ctxt;
43  SimulationObject* sim = (SimulationObject*) context->simobj;
44  int nsims = context->nsims;
45 
46  PetscFunctionBegin;
47 
48  for (int ns = 0; ns < nsims; ns++) {
49 
50  HyPar* solver = &(sim[ns].solver);
51  MPIVariables* mpi = &(sim[ns].mpi);
52 
53  solver->count_RHSFunction++;
54 
55  int size = solver->npoints_local_wghosts;
56  double* u = solver->u;
57  double* rhs = solver->rhs;
58 
59  /* copy solution from PETSc vector */
60  TransferVecFromPETSc(u,Y,context,ns,context->offsets[ns]);
61  /* apply boundary conditions and exchange data over MPI interfaces */
62  solver->ApplyBoundaryConditions(solver,mpi,u,NULL,t);
64  solver->nvars,
65  solver->dim_local,
66  solver->ghosts,
67  mpi,
68  u );
69 
70  /* Evaluate hyperbolic, parabolic and source terms and the RHS */
71  solver->HyperbolicFunction(solver->hyp,u,solver,mpi,t,1,solver->FFunction,solver->Upwind);
72 
73  solver->ParabolicFunction (solver->par,u,solver,mpi,t);
74  solver->SourceFunction (solver->source,u,solver,mpi,t);
75 
76  _ArraySetValue_(rhs,size*solver->nvars,0.0);
77  _ArrayAXPY_(solver->hyp ,-1.0,rhs,size*solver->nvars);
78  _ArrayAXPY_(solver->par , 1.0,rhs,size*solver->nvars);
79  _ArrayAXPY_(solver->source, 1.0,rhs,size*solver->nvars);
80 
81  /* Transfer RHS to PETSc vector */
82  TransferVecToPETSc(rhs,F,context,ns,context->offsets[ns]);
83 
84  }
85 
86  PetscFunctionReturn(0);
87 }
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.
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
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
#define _ArrayAXPY_(x, a, y, size)
Structure containing the variables for time-integration with PETSc.
#define _ArraySetValue_(x, size, value)
int * dim_local
Definition: hypar.h:37
int ghosts
Definition: hypar.h:52
Structure of MPI-related variables.
int npoints_local_wghosts
Definition: hypar.h:42
int TransferVecFromPETSc(double *const, const Vec, void *, const int, const int)
double * source
Definition: hypar.h:125
double * hyp
Definition: hypar.h:119