HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
IBComputeNormalGradient.c
Go to the documentation of this file.
1 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <arrayfunctions.h>
9 #include <immersedboundaries.h>
10 #include <mpivars.h>
11 #include <hypar.h>
12 
34  void* m,
35  const double* const var,
36  int nvars,
37  double** const grad_var
38  )
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 }
Facet3D * facet
#define _ArraySetValue_(x, size, value)
double interp_coeffs[_IB_NNODES_]
Structure containing variables for immersed boundary implementation.
Structure defining a facet map.
Structures and function definitions for immersed boundaries.
void * ib
Definition: hypar.h:443
int flag_ib
Definition: hypar.h:441
MPI related function definitions.
double interp_coeffs_ns[_IB_NNODES_]
int interp_nodes_ns[_IB_NNODES_]
int interp_nodes[_IB_NNODES_]
Contains structure definition for hypar.
Contains macros and function definitions for common array operations.
Structure of MPI-related variables.
int IBComputeNormalGradient(void *, void *, const double *const, int, double **const)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _IB_NNODES_