16 template <
typename memoryType>
19 std::vector<body> *B = db[
"flow"][
"bodies"].get<std::vector<body> *>();
22 numBodies = B->size();
25 numPoints.resize(numBodies);
26 offsets.resize(numBodies);
28 startI.resize(numBodies);
29 startJ.resize(numBodies);
30 numCellsX.resize(numBodies);
31 numCellsY.resize(numBodies);
33 xmin.resize(numBodies);
34 xmax.resize(numBodies);
35 ymin.resize(numBodies);
36 ymax.resize(numBodies);
43 for(
int k=0; k<numBodies; k++)
45 offsets[k] = totalPoints;
46 numPoints[k] = (*B)[k].numPoints;
47 totalPoints += numPoints[k];
51 X.resize(totalPoints);
52 Y.resize(totalPoints);
53 ds.resize(totalPoints);
54 ones.resize(totalPoints);
55 cusp::blas::fill(ones, 1.0);
56 for(
int k=0; k<numBodies; k++)
58 for(
int i=0; i<numPoints[k]; i++)
60 X[i+offsets[k]] = (*B)[k].X[i];
61 Y[i+offsets[k]] = (*B)[k].Y[i];
64 x.resize(totalPoints);
65 y.resize(totalPoints);
66 uB.resize(totalPoints);
67 vB.resize(totalPoints);
68 I.resize(totalPoints);
69 J.resize(totalPoints);
72 for(
int k=0; k<numBodies; k++)
75 for(
int i=offsets[k], j = offsets[k]+numPoints[k]-1; i<offsets[k]+numPoints[k];)
78 ds[i] = sqrt( (X[i]-X[j])*(X[i]-X[j]) + (Y[i]-Y[j])*(Y[i]-Y[j]) );
84 bodiesMove = bodiesMove || (*B)[k].moving[0] || (*B)[k].moving[1];
91 calculateCellIndices(D);
92 calculateBoundingBoxes(db, D);
107 template <
typename memoryType>
113 while(D.
x[i+1] < x[0])
115 while(D.
y[j+1] < y[0])
120 for(
int k=1; k<totalPoints; k++)
131 while(D.
x[i+1] < x[k])
143 while(D.
y[j+1] < y[k])
163 template <
typename memoryType>
166 real scale = db[
"simulation"][
"scaleCV"].get<
real>(),
169 for(
int k=0; k<numBodies; k++)
171 xmin[k] = x[offsets[k]];
173 ymin[k] = y[offsets[k]];
175 for(
int l=offsets[k]+1; l<offsets[k]+numPoints[k]; l++)
177 if(x[l] < xmin[k]) xmin[k] = x[l];
178 if(x[l] > xmax[k]) xmax[k] = x[l];
179 if(y[l] < ymin[k]) ymin[k] = y[l];
180 if(y[l] > ymax[k]) ymax[k] = y[l];
182 dx = xmax[k]-xmin[k];
183 dy = ymax[k]-ymin[k];
184 xmax[k] += 0.5*dx*(scale-1.0);
185 xmin[k] -= 0.5*dx*(scale-1.0);
186 ymax[k] += 0.5*dy*(scale-1.0);
187 ymin[k] -= 0.5*dy*(scale-1.0);
190 while(D.
x[i+1] < xmin[k])
192 while(D.
y[j+1] < ymin[k])
197 while(D.
x[i] < xmax[k])
199 while(D.
y[j] < ymax[k])
201 numCellsX[k] = i - startI[k];
202 numCellsY[k] = j - startJ[k];
222 template <
typename memoryType>
225 typedef typename cusp::array1d<real, memoryType> Array;
226 typedef typename Array::iterator Iterator;
227 typedef cusp::array1d_view<Iterator> View;
230 View XView, YView, xView, yView, onesView, uBView, vBView;
233 std::vector<body> *B = db[
"flow"][
"bodies"].get<std::vector<body> *>();
235 for(
int l=0; l<numBodies; l++)
238 (*B)[l].update(Time);
243 XView = View(X.begin()+offsets[l], X.begin()+offsets[l+1]);
244 YView = View(Y.begin()+offsets[l], Y.begin()+offsets[l+1]);
245 xView = View(x.begin()+offsets[l], x.begin()+offsets[l+1]);
246 yView = View(y.begin()+offsets[l], y.begin()+offsets[l+1]);
247 onesView = View(ones.begin()+offsets[l], ones.begin()+offsets[l+1]);
248 uBView = View(uB.begin()+offsets[l], uB.begin()+offsets[l+1]);
249 vBView = View(vB.begin()+offsets[l], vB.begin()+offsets[l+1]);
253 XView = View(X.begin()+offsets[l], X.end());
254 YView = View(Y.begin()+offsets[l], Y.end());
255 xView = View(x.begin()+offsets[l], x.end());
256 yView = View(y.begin()+offsets[l], y.end());
257 onesView = View(ones.begin()+offsets[l], ones.end());
258 uBView = View(uB.begin()+offsets[l], uB.end());
259 vBView = View(vB.begin()+offsets[l], vB.end());
264 cusp::blas::axpbypcz( onesView, XView, onesView, xView, (*B)[l].Xc[0], cos((*B)[l].Theta), -(*B)[l].X0[0]*cos((*B)[l].Theta) );
265 cusp::blas::axpbypcz( xView, YView, onesView, xView, 1.0, -sin((*B)[l].Theta), (*B)[l].X0[1]*sin((*B)[l].Theta) );
267 cusp::blas::axpbypcz( onesView, XView, onesView, yView, (*B)[l].Xc[1], sin((*B)[l].Theta), -(*B)[l].X0[0]*sin((*B)[l].Theta) );
268 cusp::blas::axpbypcz( yView, YView, onesView, yView, 1.0, cos((*B)[l].Theta), -(*B)[l].X0[1]*cos((*B)[l].Theta) );
272 cusp::blas::axpbypcz(onesView, yView, onesView, uBView, (*B)[l].vel[0], -(*B)[l].angVel, (*B)[l].angVel*(*B)[l].Xc[1]);
274 cusp::blas::axpbypcz(onesView, xView, onesView, vBView, (*B)[l].vel[1], (*B)[l].angVel, -(*B)[l].angVel*(*B)[l].Xc[0]);
278 calculateCellIndices(D);
293 real *bx = thrust::raw_pointer_cast(&(xHost[0])),
294 *by = thrust::raw_pointer_cast(&(yHost[0]));
295 writeToFile(bx, by, caseFolder, timeStep);
307 template <
typename memoryType>
311 std::stringstream out;
312 out << caseFolder <<
'/' << std::setfill(
'0') << std::setw(7) << timeStep <<
"/bodies";
313 std::ofstream file(out.str().c_str());
314 file <<
'#' << std::setw(19) <<
"x-coordinate" << std::setw(20) <<
"y-coordinate" << std::endl;
315 for (
int l=0; l < totalPoints; l++)
317 file << bx[l] <<
'\t' << by[l] <<
'\n';
vecH x
x-coordinates of the nodes
double real
Is a float or a double depending on the machine precision.
Declaration of the class bodies.
void calculateBoundingBoxes(parameterDB &db, domain &D)
Calculates indices of the bounding box of each body in the flow.
std::map< std::string, componentParameter > parameterDB
Map from a string to a componentParameter.
__global__ void forceY()
Kernel not usable.
cusp::array1d< real, host_memory > vecH
Cusp 1D array stored in the host.
Stores information about the computational grid.
Contains information about bodies in the flow.
void calculateCellIndices(domain &D)
Stores index of each cell that contains a boundary point.
void writeToFile(std::string &caseFolder, int timeStep)
void initialise(parameterDB &db, domain &D)
Sets initial position and velocity of each body.
void update(parameterDB &db, domain &D, real Time)
Updates position, velocity and neighbors of each body.
__global__ void forceX(real *f, real *q, real *rn, int *tags, int nx, int ny, real *dx, real *dy, real dt, real alpha, real nu)
Kernel not usable.
vecH y
y-coordinates of the nodes