PlasCom2  1.0
XPACC Multi-physics simluation application
ViscidTestFixtures.H
Go to the documentation of this file.
1 #ifndef __VISCID_TEST_FIXTURES_H__
2 #define __VISCID_TEST_FIXTURES_H__
3 
4 #include <cmath>
5 
6 namespace testfixtures {
7  namespace viscid {
8 
12 
13  inline double Parabola(double amp,double centerX, double centerY,double centerZ,
14  double x,double y,double z,int direction)
15  {
16  double xTerm = (x-centerX);
17  double yTerm = (y-centerY);
18  double zTerm = (z-centerZ);
19  double eTerm = 0;
20 
21  // return the parabola for a negative direction
22  // return the derivative for a non-negative direction
23  if(direction < 0){
24  eTerm = zTerm*zTerm + xTerm*xTerm + yTerm*yTerm;
25  } else if(direction == 0){
26  eTerm = 2*xTerm;
27  } else if(direction == 1){
28  eTerm = 2*yTerm;
29  } else if(direction == 2){
30  eTerm = 2*zTerm;
31  }
32  return(amp*eTerm);
33  };
34 
35  inline double Linear(std::vector<double> amp, double x0, double y0,double z0,
36  double x,double y,double z,int direction)
37  {
38  double xTerm = (x-x0);
39  double yTerm = (y-y0);
40  double zTerm = (z-z0);
41  double eTerm = 0;
42 
43  if(direction < 0){
44  eTerm = amp[0]*xTerm + amp[1]*yTerm + amp[2]*zTerm;
45  } else if(direction == 0){
46  eTerm = amp[0];
47  } else if(direction == 1){
48  eTerm = amp[1];
49  } else if(direction == 2){
50  eTerm = amp[2];
51  }
52 
53  return(eTerm);
54  };
55 
56  inline double Cosine(std::vector<double> amp, std::vector<double> period, double x0, double y0,double z0,
57  double x,double y,double z,int direction)
58  {
59  const double PI = 3.14159265359;
60  double xTerm = (x-x0);
61  double yTerm = (y-y0);
62  double zTerm = (z-z0);
63  double eTerm = 0;
64 
65  // return the cosine function for a negative direction
66  // return the derivative (sine) for a non-negative direction
67  if(direction < 0){
68  eTerm = amp[0]*cos(2*PI*xTerm/period[0])
69  + amp[1]*cos(2*PI*yTerm/period[1])
70  + amp[2]*cos(2*PI*zTerm/period[2]);
71  } else if(direction == 0){
72  eTerm = -2.0*PI*amp[0]/period[0]*sin(2*PI*xTerm/period[0]);
73  } else if(direction == 1){
74  eTerm = -2.0*PI*amp[1]/period[1]*sin(2*PI*yTerm/period[1]);
75  } else if(direction == 2){
76  eTerm = -2.0*PI*amp[2]/period[2]*sin(2*PI*zTerm/period[2]);
77  }
78 
79  return(eTerm);
80  };
81 
82 /*
83  inline double Gauss(const double &amplitude,const std::vector<double> &width,
84  const std::vector<double> &center, const std::vector<double> &xPos)
85  {
86  std::vector<double>::const_iterator wIt = width.begin();
87  std::vector<double>::const_iterator cIt = center.begin();
88  std::vector<double>::const_iterator xIt = xPos.begin();
89  double expTerm = 0;
90  while(wIt != width.end()){
91  double xLoc = (*xIt-*cIt)/(*wIt);
92  xIt++;
93  wIt++;
94  cIt++;
95  expTerm += xLoc*xLoc;
96  }
97  expTerm *= -1.0;
98  return(amplitude*std::exp(expTerm));
99  };
100 */
101 
102  template<typename GridType,typename StateType>
103  int SetupViscidState(const GridType &inGrid,StateType &inState,StateType &inParams,
104  int numScalars,bool withFluxes = false)
105  {
106  size_t numPointsBuffer = inGrid.BufferSize();
107  const std::vector<size_t> &bufferSizes(inGrid.BufferSizes());
108  const std::vector<size_t> &gridSizes(inGrid.GridSizes());
109  const pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
110  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
111 
112  inState.AddField("simTime",'s',1,8,"s");
113 
114  // Conserved quantities, mass, momentum, and energy densities
115  inState.AddField("rho",'n',1,8,"mass");
116  inState.AddField("rhoV",'n',3,8,"momentum");
117  inState.AddField("rhoE",'n',1,8,"energy");
118  if(numScalars>0)
119  inState.AddField("scalarVars",'n',numScalars,8,"m/M");
120 
121  // Dependent quantities, pressure, temperature, velocity
122  inState.AddField("pressure",'n',1,8,"pressure");
123  inState.AddField("temperature",'n',1,8,"temperature");
124  inState.AddField("rhom1",'n',1,8,"volume");
125  inState.AddField("velocity",'n',1,8,"velocity");
126 
127  if(withFluxes){
128  // Flux quanitites (if tracking desired)
129  inState.AddField("massFlux",'n',3,8,"");
130  inState.AddField("mom1Flux",'n',3,8,"");
131  inState.AddField("mom2Flux",'n',3,8,"");
132  inState.AddField("mom3Flux",'n',3,8,"");
133  inState.AddField("energyFlux",'n',3,8,"");
134  }
135 
136  inState.Create(numPointsBuffer,0);
137  if(numScalars == 0)
138  inState.SetStateFields("rho rhoV rhoE");
139  else
140  inState.SetStateFields("rho rhoV rhoE scalarVars");
141  inState.InitializeFieldHandles();
142 
143  inParams.AddField("gamma",'s',1,8,"");
144  inParams.AddField("inputDT",'s',1,8,"s");
145  inParams.AddField("inputCFL",'s',1,8,"");
146  inParams.AddField("refRe",'s',1,8,"");
147  inParams.AddField("refPr",'s',1,8,"");
148  inParams.AddField("Numbers",'s',3,8,"");
149  inParams.AddField("Flags",'s',1,4,"");
150  inParams.AddField("power",'s',1,8,"");
151  inParams.AddField("beta",'s',1,8,"");
152  inParams.AddField("bulkViscFac",'s',1,8,"");
153 
154  inParams.Create(numPointsBuffer,0);
155  //inState.SetStateFields("gamma CFL Re power beta bulkViscFac");
156 
157  return(0);
158  };
159 
160  template<typename GridType,typename StateType>
161  int InitializeQuiescentFlow(const GridType &inGrid,StateType &inState,bool everyWhere = false)
162  {
163  int rhoHandle = inState.GetDataIndex("rho");
164  if(rhoHandle < 0)
165  return(1);
166  pcpp::field::dataset::DataBufferType &rhoData(inState.Field(rhoHandle));
167  double *rhoPtr = rhoData.Data<double>();
168  if(!rhoPtr)
169  return(1);
170 
171  int rhoVHandle = inState.GetDataIndex("rhoV");
172  if(rhoVHandle < 0)
173  return(1);
174  pcpp::field::dataset::DataBufferType &rhoVData(inState.Field(rhoVHandle));
175  double *rhoVPtr = rhoVData.Data<double>();
176  if(!rhoVPtr)
177  return(1);
178 
179  int rhoEHandle = inState.GetDataIndex("rhoE");
180  if(rhoEHandle < 0)
181  return(1);
182  pcpp::field::dataset::DataBufferType &rhoEData(inState.Field(rhoEHandle));
183  double *rhoEPtr = rhoEData.Data<double>();
184  if(!rhoPtr)
185  return(1);
186 
187  size_t numPointsBuffer = inGrid.BufferSize();
188  const std::vector<size_t> &bufferSizes(inGrid.BufferSizes());
189  const std::vector<size_t> &gridSizes(inGrid.GridSizes());
190  const pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
191  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
192  int numDim = gridSizes.size();
193  double rhoE = 1.0/.4;
194  if(everyWhere){
195  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++){
196  rhoPtr[iPoint] = 1.0;
197  rhoEPtr[iPoint] = rhoE;
198  }
199  for(size_t iPoint = 0;iPoint < numDim*numPointsBuffer;iPoint++)
200  rhoVPtr[iPoint] = 0.0;
201  } else {
202  if(numDim == 3){
203  size_t iStart = partitionBufferInterval[0].first;
204  size_t iEnd = partitionBufferInterval[0].second;
205  size_t jStart = partitionBufferInterval[1].first;
206  size_t jEnd = partitionBufferInterval[1].second;
207  size_t kStart = partitionBufferInterval[2].first;
208  size_t kEnd = partitionBufferInterval[2].second;
209  size_t nPlane = bufferSizes[0]*bufferSizes[1];
210  for(size_t kIndex = kStart;kIndex <= kEnd;kIndex++){
211  size_t kBufferIndex = kIndex*nPlane;
212  for(size_t jIndex = jStart;jIndex <= jEnd;jIndex++){
213  size_t jkBufferIndex = kBufferIndex + jIndex*bufferSizes[0];
214  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
215  size_t bufferIndex = jkBufferIndex + iIndex;
216  rhoPtr[bufferIndex] = 1.0;
217  rhoEPtr[bufferIndex] = rhoE;
218  rhoVPtr[bufferIndex] = 0.0;
219  rhoVPtr[bufferIndex+numPointsBuffer] = 0.0;
220  rhoVPtr[bufferIndex+2*numPointsBuffer] = 0.0;
221  }
222  }
223  }
224  } else if (numDim == 2) {
225  size_t iStart = partitionBufferInterval[0].first;
226  size_t iEnd = partitionBufferInterval[0].second;
227  size_t jStart = partitionBufferInterval[1].first;
228  size_t jEnd = partitionBufferInterval[1].second;
229  for(size_t jIndex = jStart;jIndex <= jEnd;jIndex++){
230  size_t jBufferIndex = jIndex*bufferSizes[0];
231  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
232  size_t bufferIndex = jBufferIndex + iIndex;
233  rhoPtr[bufferIndex] = 1.0;
234  rhoEPtr[bufferIndex] = rhoE;
235  rhoVPtr[bufferIndex] = 0.0;
236  rhoVPtr[bufferIndex+numPointsBuffer] = 0.0;
237  }
238  }
239  } else if (numDim == 1) {
240  size_t iStart = partitionBufferInterval[0].first;
241  size_t iEnd = partitionBufferInterval[0].second;
242  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
243  rhoPtr[iIndex] = 1.0;
244  rhoEPtr[iIndex] = rhoE;
245  rhoVPtr[iIndex] = 0.0;
246  }
247  }
248  }
249  return(0);
250  };
251 
252  int GenerateViscidShockExact(pbsgrid_t &exactGrid, state_t &exactState, const int direction);
253  int GeneratePoiseuilleExact(pbsgrid_t &exactGrid, state_t &exactState, const int direction);
254 
255  }
256 }
257 #endif
double Cosine(std::vector< double > amp, std::vector< double > period, double x0, double y0, double z0, double x, double y, double z, int direction)
int InitializeQuiescentFlow(const GridType &inGrid, StateType &inState, bool everyWhere=false)
simulation::state::base state_t
std::vector< DomainBaseType > domainvector
Definition: Simulation.H:32
void const size_t const size_t * gridSizes
Definition: EulerKernels.H:10
void const size_t const size_t const size_t const double const double double * y
double Parabola(double amp, double centerX, double centerY, double centerZ, double x, double y, double z, int direction)
int GeneratePoiseuilleExact(pbsgrid_t &exactGrid, state_t &exactState, const int direction)
void const size_t const size_t const size_t const double const double * x
Definition: Viscid.f90:1
plascom2::application::domainvector DomainVector
double Linear(std::vector< double > amp, double x0, double y0, double z0, double x, double y, double z, int direction)
int SetupViscidState(const GridType &inGrid, StateType &inState, StateType &inParams, int numScalars, bool withFluxes=false)
void const size_t const size_t * bufferSizes
Definition: MetricKernels.H:19
void const size_t const size_t const size_t const int * numScalars
Definition: EulerKernels.H:17
simulation::grid::parallel_blockstructured pbsgrid_t
int GenerateViscidShockExact(pbsgrid_t &exactGrid, state_t &exactState, const int direction)
Simple Block Structured Mesh object.
Definition: IndexUtil.H:21
void const size_t * numPointsBuffer
Definition: MetricKernels.H:19