HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
IBComputeNormalGradient.c File Reference

Compute normal gradient of a provided variable on immersed body surface. More...

#include <stdio.h>
#include <stdlib.h>
#include <arrayfunctions.h>
#include <immersedboundaries.h>
#include <mpivars.h>
#include <hypar.h>

Go to the source code of this file.

Functions

int IBComputeNormalGradient (void *s, void *m, const double *const var, int nvars, double **const grad_var)
 

Detailed Description

Compute normal gradient of a provided variable on immersed body surface.

Author
Debojyoti Ghosh

Definition in file IBComputeNormalGradient.c.

Function Documentation

◆ IBComputeNormalGradient()

int IBComputeNormalGradient ( void *  s,
void *  m,
const double *const  var,
int  nvars,
double **const  grad_var 
)

Calculate the normal gradient of a provided variables on the immersed body surface: for each "local facet", i.e., facets (of the immersed body surface) that lie within the local computational domain of this MPI rank, compute the normal gradient.

The variable should be a grid variable with size/layout the same as the solution variable (HyPar::u) with the appropriate number of ghost points.

If the incoming variable has multiple components, this function will calculate normal gradient of each component.

The grad var array should be NULL at input; at output, it will point to an array of size (ImmersedBoundary::nfacets_local X nvars) that contains the normal gradient at each local facet. If there are no local facets, it will remain NULL.

The gradient calculation is currently first-order.

Parameters
sSolver object of type HyPar
mMPI object of type MPIVariables
varVariable to compute the gradient of
nvarsNumber of components in var
grad_varArray to store the gradient; must be NULL at input

Definition at line 33 of file IBComputeNormalGradient.c.

39 {
40  HyPar *solver = (HyPar*) s;
41  MPIVariables *mpi = (MPIVariables*) m;
42  ImmersedBoundary *IB = (ImmersedBoundary*) solver->ib;
43 
44  if (!solver->flag_ib) return(0);
45 
46  if ((*grad_var) != NULL) {
47  fprintf(stderr,"Error in IBComputeNormalGradient()\n");
48  fprintf(stderr," grad_var is not NULL on rank %d\n",
49  mpi->rank );
50  return 1;
51  }
52 
53  int nfacets_local = IB->nfacets_local;
54  FacetMap *fmap = IB->fmap;
55 
56  if (nfacets_local > 0) {
57  (*grad_var) = (double*) calloc (nvars*nfacets_local, sizeof(double));
58 
59  for (int n = 0; n < nfacets_local; n++) {
60 
61  double *alpha;
62  int *nodes, j, k;
63 
64  double v_c[nvars];
65  alpha = &(fmap[n].interp_coeffs[0]);
66  nodes = &(fmap[n].interp_nodes[0]);
67  _ArraySetValue_(v_c,nvars,0.0);
68  for (j=0; j<_IB_NNODES_; j++) {
69  for (k=0; k<nvars; k++) {
70  v_c[k] += ( alpha[j] * var[nvars*nodes[j]+k] );
71  }
72  }
73 
74  double v_ns[nvars];
75  alpha = &(fmap[n].interp_coeffs_ns[0]);
76  nodes = &(fmap[n].interp_nodes_ns[0]);
77  _ArraySetValue_(v_ns,nvars,0.0);
78  for (j=0; j<_IB_NNODES_; j++) {
79  for (k=0; k<nvars; k++) {
80  v_ns[k] += ( alpha[j] * var[nvars*nodes[j]+k] );
81  }
82  }
83 
84  double nx = fmap[n].facet->nx;
85  double ny = fmap[n].facet->ny;
86  double nz = fmap[n].facet->nz;
87 
88  for (k=0; k<nvars; k++) {
89  double dv_dx = (v_ns[k] - v_c[k]) / fmap[n].dx;
90  double dv_dy = (v_ns[k] - v_c[k]) / fmap[n].dy;
91  double dv_dz = (v_ns[k] - v_c[k]) / fmap[n].dz;
92  (*grad_var)[n*nvars+k] = dv_dx*nx + dv_dy*ny + dv_dz*nz;
93  }
94 
95  }
96 
97  }
98 
99  return(0);
100 }
double interp_coeffs[_IB_NNODES_]
Structure defining a facet map.
#define _IB_NNODES_
Structure containing variables for immersed boundary implementation.
double interp_coeffs_ns[_IB_NNODES_]
void * ib
Definition: hypar.h:443
int interp_nodes[_IB_NNODES_]
int flag_ib
Definition: hypar.h:441
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
Facet3D * facet
#define _ArraySetValue_(x, size, value)
int interp_nodes_ns[_IB_NNODES_]
Structure of MPI-related variables.