HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
IBIdentifyBoundary.c
Go to the documentation of this file.
1 
6 #include <stdlib.h>
7 #include <arrayfunctions.h>
8 #include <mpivars.h>
9 #include <immersedboundaries.h>
10 
16  int imax,
17  int jmax,
18  int kmax,
19  int ghosts,
20  double *blank
23  )
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 }
78 
80 static int SetBoundaryPoints(
81  int imax,
82  int jmax,
83  int kmax,
84  int ghosts,
85  double *blank,
88  void *b
89  )
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 }
151 
159  void *ib,
160  void *m,
161  int *dim_l,
162  int ghosts,
163  double *blank
165  )
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 }
int IBIdentifyBoundary(void *, void *, int *, int, double *)
Structure defining an immersed boundary node.
Structure containing variables for immersed boundary implementation.
Structure defining a body.
Structures and function definitions for immersed boundaries.
#define _IB_NDIMS_
MPI related function definitions.
static int CountBoundaryPoints(int imax, int jmax, int kmax, int ghosts, double *blank)
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArrayCopy1D_(x, y, size)
static int SetBoundaryPoints(int imax, int jmax, int kmax, int ghosts, double *blank, void *b)
Contains macros and function definitions for common array operations.
Structure of MPI-related variables.