cuIBM
A GPU-based Immersed Boundary Method code
DirectForcingSolver.cu
Go to the documentation of this file.
1 
7 #include <sys/stat.h>
8 #include <thrust/extrema.h>
9 #include <cusp/io/matrix_market.h>
10 
11 #include "DirectForcingSolver.h"
12 
13 
17 template <typename memoryType>
19 {
22 } // DirectForcingSolver
23 
24 
28 template <typename memoryType>
30 {
33 
34  int numUV = (nx-1)*ny + nx*(ny-1),
35  numP = nx*ny;
36 
38 
40 
42 
43  NavierStokesSolver<memoryType>::logger.startTimer("allocateMemory");
44 
45  tags.resize(numUV);
46  tagsD.resize(numUV);
47  tags2.resize(numUV);
48  tags2D.resize(numUV);
49  coeffs.resize(numUV);
50  coeffsD.resize(numUV);
51  coeffs2.resize(numUV);
52  coeffs2D.resize(numUV);
53  uv.resize(numUV);
54  uvD.resize(numUV);
55 
56  pressure.resize(numP);
57  cusp::blas::fill(pressure, 0.0);
58 
59  NavierStokesSolver<memoryType>::logger.startTimer("allocateMemory");
60 
61  tagPoints();
62 
64 } // initialise
65 
66 
74 template <typename memoryType>
76 {
77  if (NSWithBody<memoryType>::B.bodiesMove)
78  {
79  // update the locations of the body points
81 
82  // retag points
83  tagPoints();
84 
85  // assemble the matrices generated using new tags
87  }
88 } // updateSolverState
89 
90 
98 template <typename memoryType>
100 {
102 
103  NavierStokesSolver<memoryType>::logger.startTimer("updateRHS1");
104  updateRHS1();
105  NavierStokesSolver<memoryType>::logger.startTimer("updateRHS1");
106 } // assembleRHS1
107 
108 
117 template <typename memoryType>
119 {
124 
125  cusp::array1d<real, memoryType> fluxes(nx*ny);
127  int minPosition = thrust::min_element(fluxes.begin(), fluxes.end()) - fluxes.begin(),
128  maxPosition = thrust::max_element(fluxes.begin(), fluxes.end()) - fluxes.begin();
129  real minFlux = fluxes[minPosition],
130  maxFlux = fluxes[maxPosition],
131  globalSum = thrust::reduce(fluxes.begin(), fluxes.end());
132 
133  std::ofstream fluxInfoFile;
134  std::string folder = db["inputs"]["caseFolder"].get<std::string>();
135  std::stringstream out;
136  out << folder << "/massFlux";
137 
138  if(timeStep==1)
139  fluxInfoFile.open(out.str().c_str());
140  else
141  fluxInfoFile.open(out.str().c_str(), std::ios::out | std::ios::app);
142 
143  fluxInfoFile << timeStep << '\t' << minFlux << '\t' << maxFlux << '\t' << globalSum << std::endl;
144  fluxInfoFile.close();
145 } // writeMassFluxInfo
146 
147 
152 template <typename memoryType>
154 {
156 
157  NavierStokesSolver<memoryType>::logger.startTimer("projectionStep");
158  cusp::blas::axpy(NavierStokesSolver<memoryType>::lambda, pressure , 1.0);
159  NavierStokesSolver<memoryType>::logger.stopTimer("projectionStep");
160 } // projectionStep
161 
162 
166 template <typename memoryType>
168 {
169  NavierStokesSolver<memoryType>::logger.startTimer("output");
170 
172  real dt = db["simulation"]["dt"].get<real>();
174 
176 
177  // Print forces calculated using the CV approach
180 
181  writeMassFluxInfo();
182 
183  NavierStokesSolver<memoryType>::logger.stopTimer("output");
184 } // writeData
185 
186 
205 template <typename memoryType>
207 {
210  int index = 5*(ny/2)*nx - nx - ny + 5*(nx/2) - 1 + 2;
211  int row = (ny/2)*nx+nx/2;
212 
214  bool flag = true;
215  while(flag)
216  {
217  if(NavierStokesSolver<memoryType>::C.row_indices[index]==NavierStokesSolver<memoryType>::C.column_indices[index] && NavierStokesSolver<memoryType>::C.column_indices[index]==row)
218  {
220  flag = false;
221  }
222  index++;
223  }
224 } // generateC
225 
226 
227 // include inline files
233 
234 
235 // specialization of the class
__global__ void updateRHS1(real *rhs1, int numUV, int *tags)
Update the RHS vector of the velocity system at forcing nodes.
Definition: updateRHS1.cu:30
virtual void writeData()
Writes the velocity, pressure, force and mass flux data at every save point.
void initialiseBodies()
Stores the parameters of the simulation and initializes the location and motion of each immersed bodi...
Definition: NSWithBody.cu:16
double real
Is a float or a double depending on the machine precision.
Definition: types.h:116
virtual void writeCommon()
Writes flow variables and position of body points into files.
Definition: NSWithBody.cu:136
virtual void initialise()
Initialize the vectors used in the simulation.
void initialiseCommon()
Initializes parameters common to all Navier-Stokes solvers.
void writeMassFluxInfo()
Prints the min, max and sum of the divergences of the velocity field in every cell of the domain...
A fully discrete formulation of the direct forcing method.
std::map< std::string, componentParameter > parameterDB
Map from a string to a componentParameter.
Definition: parameterDB.h:64
Stores information about the computational grid.
Definition: domain.h:16
void initialiseArrays(int numQ, int numLambda)
Initializes all arrays required to solve the Navier-Stokes equations.
DirectForcingSolver(parameterDB *pDB=NULL, domain *dInfo=NULL)
Constructor. Initializes the simulation parameters and the domain info.
virtual void generateC()
Declaration of the class DirectForcingSolver.
virtual void projectionStep()
Projects the pressure gradient on to the intermediate velocity field to obtain the divergence-free ve...
Implementation of the methods of the class DirectForcingSolver to update the right hand-side of the s...
void updateBodies()
Updates location and motion of each immersed body at current time.
Definition: NSWithBody.cu:45
Implementation of the methods of the class DirectForcingSolver to tag points near the immersed bounda...
virtual void projectionStep()
Projects the flux onto the divergence-free field.
void assembleMatrices()
Assembles matrices of the intermediate flux solver and the Poisson solver.
virtual void assembleRHS1()
Assembles the matrix rhs1 for DirectForcingSolver.
virtual void assembleRHS1()
Assembles the right hand-side of the system for the intermediate flux.
__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.
virtual void calculateForce()
Generic Navier-Stokes solver in the presence of immersed boundaries.
Definition: NSWithBody.h:21
Solves the Navier-Stokes equations in a rectangular domain.
virtual void updateSolverState()
Updates the matrices every time the body is moved.
virtual void generateC()
Generates the right-hand side matrix in the Poisson step.