cuIBM
A GPU-based Immersed Boundary Method code
generateL.inl
Go to the documentation of this file.
1 
14 template <>
16 {
17 
18  int nx = domInfo->nx,
19  ny = domInfo->ny;
20 
21  real Cx0 = 0.0, Cx1 = 0.0, Cy0 = 0.0, Cy1 = 0.0,
22  scale = 0.0,
23  dx0 = 1.0, dx1 = 1.0, dy0 = 1.0, dy1 = 1.0;
24 
25  real *dx = thrust::raw_pointer_cast(&(domInfo->dx[0])),
26  *dy = thrust::raw_pointer_cast(&(domInfo->dy[0]));
27 
28  int numU = (nx-1)*ny;
29  int numUV = numU + nx*(ny-1);
30  int I,
31  num_elements = 0;
32 
33  cooH LHost(numUV, numUV, 5*numUV-4*(nx+ny)+4);
34 
35  real nu = (*paramDB)["flow"]["nu"].get<real>();
37  for (int j=0; j < ny; j++)
38  {
39  if(j == 0)
40  {
41  dy0 = 0.5*dy[0];
42  dy1 = 0.5*(dy[0]+dy[1]);
43  }
44  else if(j == ny-1)
45  {
46  dy0 = 0.5*(dy[ny-2]+dy[ny-1]);
47  dy1 = 0.5*dy[ny-1];
48  }
49  else
50  {
51  dy0 = 0.5*(dy[j]+dy[j-1]);
52  dy1 = 0.5*(dy[j]+dy[j+1]);
53  }
54  Cy0 = 2.0 * nu / ( dy1*(dy1+dy0) );
55  Cy1 = 2.0 * nu / ( dy0*(dy1+dy0) );
56 
57  for (int i=0; i < nx-1; i++)
58  {
59  I = j*(nx-1) + i;
60 
61  Cx0 = 2.0 * nu / ( dx[i+1]*(dx[i+1]+dx[i]) );
62  Cx1 = 2.0 * nu / ( dx[i]*(dx[i+1]+dx[i]) );
63 
64  scale = 0.5*(dx[i+1]+dx[i]);
65 
66  // south
67  if(j>0)
68  {
69  LHost.row_indices[num_elements] = I;
70  LHost.column_indices[num_elements] = I - (nx-1);
71  LHost.values[num_elements] = Cy1 * scale / dy[j-1];
72  num_elements++;
73  }
74  // west
75  if(i>0)
76  {
77  LHost.row_indices[num_elements] = I;
78  LHost.column_indices[num_elements] = I - 1;
79  LHost.values[num_elements] = Cx1 * scale / dy[j];
80  num_elements++;
81  }
82  // centre
83  LHost.row_indices[num_elements] = I;
84  LHost.column_indices[num_elements] = I;
85  LHost.values[num_elements] = (-Cy0-Cy1-Cx0-Cx1) * scale / dy[j];
86  num_elements++;
87  // east
88  if(i<nx-2) // no east coefficient for the rightmost column
89  {
90  LHost.row_indices[num_elements] = I;
91  LHost.column_indices[num_elements] = I + 1;
92  LHost.values[num_elements] = Cx0 * scale / dy[j];
93  num_elements++;
94  }
95  // north
96  if(j<ny-1)
97  {
98  LHost.row_indices[num_elements] = I;
99  LHost.column_indices[num_elements] = I + (nx-1);
100  LHost.values[num_elements] = Cy0 * scale / dy[j+1];
101  num_elements++;
102  }
103  }
104  }
105 
107  for (int j=0; j < ny-1; j++)
108  {
109  Cy0 = 2.0 * nu / ( dy[j+1]*(dy[j+1]+dy[j]) );
110  Cy1 = 2.0 * nu / ( dy[j]*(dy[j+1]+dy[j]) );
111 
112  for (int i=0; i < nx; i++)
113  {
114  I = j*nx + i + numU; // calculate the row of the matrix
115 
116  if((i>0) && (i<nx-1))
117  {
118  dx0 = 0.5*(dx[i]+dx[i-1]);
119  dx1 = 0.5*(dx[i]+dx[i+1]);
120  }
121  else if(i==0)
122  {
123  dx0 = 0.5*dx[i];
124  dx1 = 0.5*(dx[i]+dx[i+1]);
125  }
126  else if(i==nx-1)
127  {
128  dx0 = 0.5*(dx[i]+dx[i-1]);
129  dx1 = 0.5*dx[i];
130  }
131  Cx0 = 2.0 * nu /( dx1*(dx1+dx0) );
132  Cx1 = 2.0 * nu /( dx0*(dx1+dx0) );
133 
134  scale = 0.5*(dy[j+1]+dy[j]); // scaling factor (to obtain the normalised matrix)
135 
136  // south
137  if(j>0) // no south coefficient for the bottom row
138  {
139  LHost.row_indices[num_elements] = I;
140  LHost.column_indices[num_elements] = I - nx;
141  LHost.values[num_elements] = Cy1 * scale / dx[i];
142  num_elements++;
143  }
144  // west
145  if(i>0) // no west coefficient for the leftmost column
146  {
147  LHost.row_indices[num_elements] = I;
148  LHost.column_indices[num_elements] = I - 1;
149  LHost.values[num_elements] = Cx1 * scale / dx[i-1];
150  num_elements++;
151  }
152  // centre
153  LHost.row_indices[num_elements] = I;
154  LHost.column_indices[num_elements] = I;
155  LHost.values[num_elements] = (-Cy0-Cy1-Cx0-Cx1) * scale / dx[i];
156  num_elements++;
157  // east
158  if(i<nx-1) // no east coefficient for the rightmost column
159  {
160  LHost.row_indices[num_elements] = I;
161  LHost.column_indices[num_elements] = I + 1;
162  LHost.values[num_elements] = Cx0 * scale / dx[i+1];
163  num_elements++;
164  }
165  // north
166  if(j<ny-2)
167  {
168  LHost.row_indices[num_elements] = I;
169  LHost.column_indices[num_elements] = I + nx;
170  LHost.values[num_elements] = Cy0 * scale / dx[i];
171  num_elements++;
172  }
173  }
174  }
175  L = LHost;
176 } // generateL
177 
178 
179 /*
180 template <typename Matrix, typename Vector>
181 template <>
182 void NavierStokesSolver<Matrix, Vector>::generateBN<3>()
183 {
184  Matrix temp1, temp2;
185  cusp::multiply(Minv, L, temp1);
186  cusp::multiply(temp1, Minv, BN);
187  cusp::add(Minv, BN, BN);
188  cusp::multiply(temp1, BN, temp2);
189  cusp::add(Minv, temp2, BN);
190 }*/
double real
Is a float or a double depending on the machine precision.
Definition: types.h:116
virtual void generateL()
cusp::coo_matrix< int, real, host_memory > cooH
COO matrix stored on the host.
Definition: types.h:126