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

Identiy the boundary nodes of the immersed body. More...

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

Go to the source code of this file.

Functions

static int CountBoundaryPoints (int imax, int jmax, int kmax, int ghosts, double *blank)
 
static int SetBoundaryPoints (int imax, int jmax, int kmax, int ghosts, double *blank, void *b)
 
int IBIdentifyBoundary (void *ib, void *m, int *dim_l, int ghosts, double *blank)
 

Detailed Description

Identiy the boundary nodes of the immersed body.

Author
Debojyoti Ghosh

Definition in file IBIdentifyBoundary.c.

Function Documentation

◆ CountBoundaryPoints()

static int CountBoundaryPoints ( int  imax,
int  jmax,
int  kmax,
int  ghosts,
double *  blank 
)
static

Count the number of immersed boundary points: boundary points are those grid points inside the immersed body that are within stencil-width-distance of a grid point outside the body.

Parameters
imaxNumber of grid points in x
jmaxNumber of grid points in y
kmaxNumber of grid points in z
ghostsNumber of ghost points
blankblanking array where entries are zero for grid points inside, and one for grid points outside.

Definition at line 15 of file IBIdentifyBoundary.c.

24 {
25  static int dim[_IB_NDIMS_], indexC[_IB_NDIMS_], indexN[_IB_NDIMS_],
26  i, j, k, p, q, count;
27  dim[0] = imax;
28  dim[1] = jmax;
29  dim[2] = kmax;
30 
31  count = 0;
32  for (i = 0; i < imax; i++) {
33  for (j = 0; j < jmax; j++) {
34  for (k = 0; k < kmax; k++) {
35  indexC[0] = i;
36  indexC[1] = j;
37  indexC[2] = k;
38  _ArrayIndex1D_(_IB_NDIMS_,dim,indexC,ghosts,p);
39  /* if this point is inside the body (0), find out if any */
40  /* of the neighboring points are outside (1) */
41  if (!blank[p]){
42 
43  int g, flag = 0;
44  for (g = 1; g <= ghosts; g++){
45 
46  _ArrayCopy1D_(indexC,indexN,_IB_NDIMS_); indexN[0] += g;
47  _ArrayIndex1D_(_IB_NDIMS_,dim,indexN,ghosts,q);
48  if (blank[q]) flag = 1;
49 
50  _ArrayCopy1D_(indexC,indexN,_IB_NDIMS_); indexN[0] -= g;
51  _ArrayIndex1D_(_IB_NDIMS_,dim,indexN,ghosts,q);
52  if (blank[q]) flag = 1;
53 
54  _ArrayCopy1D_(indexC,indexN,_IB_NDIMS_); indexN[1] += g;
55  _ArrayIndex1D_(_IB_NDIMS_,dim,indexN,ghosts,q);
56  if (blank[q]) flag = 1;
57 
58  _ArrayCopy1D_(indexC,indexN,_IB_NDIMS_); indexN[1] -= g;
59  _ArrayIndex1D_(_IB_NDIMS_,dim,indexN,ghosts,q);
60  if (blank[q]) flag = 1;
61 
62  _ArrayCopy1D_(indexC,indexN,_IB_NDIMS_); indexN[2] += g;
63  _ArrayIndex1D_(_IB_NDIMS_,dim,indexN,ghosts,q);
64  if (blank[q]) flag = 1;
65 
66  _ArrayCopy1D_(indexC,indexN,_IB_NDIMS_); indexN[2] -= g;
67  _ArrayIndex1D_(_IB_NDIMS_,dim,indexN,ghosts,q);
68  if (blank[q]) flag = 1;
69 
70  }
71  if (flag) count++;
72  }
73  }
74  }
75  }
76  return(count);
77 }
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _IB_NDIMS_
#define _ArrayCopy1D_(x, y, size)

◆ SetBoundaryPoints()

static int SetBoundaryPoints ( int  imax,
int  jmax,
int  kmax,
int  ghosts,
double *  blank,
void *  b 
)
static

Set the indices of the immersed boundary points.

Parameters
imaxNumber of grid points in x
jmaxNumber of grid points in y
kmaxNumber of grid points in z
ghostsNumber of ghost points
blankblanking array where entries are zero for grid points inside, and one for grid points outside.
bArray of immersed boundary points of type IBNode

Definition at line 80 of file IBIdentifyBoundary.c.

90 {
91  IBNode *boundary = (IBNode*) b;
92  static int dim[_IB_NDIMS_], indexC[_IB_NDIMS_], indexN[_IB_NDIMS_],
93  i, j, k, p, q, count;
94  dim[0] = imax;
95  dim[1] = jmax;
96  dim[2] = kmax;
97 
98  count = 0;
99  for (i = 0; i < imax; i++) {
100  for (j = 0; j < jmax; j++) {
101  for (k = 0; k < kmax; k++) {
102  indexC[0] = i;
103  indexC[1] = j;
104  indexC[2] = k;
105  _ArrayIndex1D_(_IB_NDIMS_,dim,indexC,ghosts,p);
106  /* if this point is inside the body (0), find out if any */
107  /* of the neighboring points are outside (1) */
108  if (!blank[p]){
109 
110  int g, flag = 0;
111  for (g = 1; g <= ghosts; g++){
112 
113  _ArrayCopy1D_(indexC,indexN,_IB_NDIMS_); indexN[0] += g;
114  _ArrayIndex1D_(_IB_NDIMS_,dim,indexN,ghosts,q);
115  if (blank[q]) flag = 1;
116 
117  _ArrayCopy1D_(indexC,indexN,_IB_NDIMS_); indexN[0] -= g;
118  _ArrayIndex1D_(_IB_NDIMS_,dim,indexN,ghosts,q);
119  if (blank[q]) flag = 1;
120 
121  _ArrayCopy1D_(indexC,indexN,_IB_NDIMS_); indexN[1] += g;
122  _ArrayIndex1D_(_IB_NDIMS_,dim,indexN,ghosts,q);
123  if (blank[q]) flag = 1;
124 
125  _ArrayCopy1D_(indexC,indexN,_IB_NDIMS_); indexN[1] -= g;
126  _ArrayIndex1D_(_IB_NDIMS_,dim,indexN,ghosts,q);
127  if (blank[q]) flag = 1;
128 
129  _ArrayCopy1D_(indexC,indexN,_IB_NDIMS_); indexN[2] += g;
130  _ArrayIndex1D_(_IB_NDIMS_,dim,indexN,ghosts,q);
131  if (blank[q]) flag = 1;
132 
133  _ArrayCopy1D_(indexC,indexN,_IB_NDIMS_); indexN[2] -= g;
134  _ArrayIndex1D_(_IB_NDIMS_,dim,indexN,ghosts,q);
135  if (blank[q]) flag = 1;
136 
137  }
138  if (flag) {
139  boundary[count].i = i;
140  boundary[count].j = j;
141  boundary[count].k = k;
142  boundary[count].p = p;
143  count++;
144  }
145  }
146  }
147  }
148  }
149  return(count);
150 }
Structure defining an immersed boundary node.
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _IB_NDIMS_
#define _ArrayCopy1D_(x, y, size)

◆ IBIdentifyBoundary()

int IBIdentifyBoundary ( void *  ib,
void *  m,
int *  dim_l,
int  ghosts,
double *  blank 
)

Identify the immersed boundary points: an immersed boundary point is any grid point inside the immersed body that is within stencil-width-distance of a grid point outside the immersed body. This function does the following:

  • count the number of immersed boundary points.
  • allocate the array of immersed boundary points and set their indices.
Parameters
ibImmersed boundary object of type ImmersedBoundary
mMPI object of type MPIVariables
dim_llocal dimensions
ghostsnumber of ghost points
blankBlanking array: for grid points within the immersed body, this value will be set to 0

Definition at line 158 of file IBIdentifyBoundary.c.

166 {
168  MPIVariables *mpi = (MPIVariables*) m;
169  Body3D *body = IB->body;
170 
171  int imax = dim_l[0],
172  jmax = dim_l[1],
173  kmax = dim_l[2];
174 
175  int n_boundary_nodes = CountBoundaryPoints(imax,jmax,kmax,ghosts,blank);
176  IB->n_boundary_nodes = n_boundary_nodes;
177  if (n_boundary_nodes == 0) IB->boundary = NULL;
178  else {
179  IB->boundary = (IBNode*) calloc (n_boundary_nodes, sizeof(IBNode));
180  int check = SetBoundaryPoints(imax,jmax,kmax,ghosts,blank,IB->boundary);
181  if (check != n_boundary_nodes) {
182  fprintf(stderr,"Error in IBIdentifyBoundary(): Inconsistency encountered when setting boundary indices. ");
183  fprintf(stderr,"on rank %d.\n",mpi->rank);
184  fprintf(stderr,"SetBoundaryPoints() returned %d, while n_boundary_nodes is %d.\n",check,n_boundary_nodes);
185  }
186  }
187 
188  return(n_boundary_nodes);
189 }
Structure defining a body.
Structure defining an immersed boundary node.
Structure containing variables for immersed boundary implementation.
Structure of MPI-related variables.
static int CountBoundaryPoints(int imax, int jmax, int kmax, int ghosts, double *blank)
static int SetBoundaryPoints(int imax, int jmax, int kmax, int ghosts, double *blank, void *b)