PlasCom2  1.0
XPACC Multi-physics simluation application
EulerUtil.H
Go to the documentation of this file.
1 #ifndef __EULER_UTIL_H__
2 #define __EULER_UTIL_H__
3 
4 #include "PlasCom2.H"
5 #include "PCPPCommUtil.H"
6 #include "PCPPIntervalUtils.H"
7 #include "PCPPReport.H"
8 
9 namespace euler {
10  namespace util {
11 
12 /*
13  // MJA, to be deleted
14  // Input:
15  // inInterval: (xStart xEnd yStart yEnd zStart zEnd)
16  // bufferSize: (numX numY numZ)
17  // stateBuffer: [ *rho *rhoV *rhoE *scalarVars ]
18  //
19  // Output:
20  // dvBuffer: [1/rho p T v1 v2 v3 ]
21  int ComputeDVBufferIdeal(const pcpp::IndexIntervalType &regionInterval,
22  const std::vector<size_t> &bufferSizes,
23  const std::vector<double *> &stateBuffers,
24  std::vector<double *> &dvBuffers,
25  const double gamma,
26  const double specGasConst);
27 */
28 
29  // Input:
30  // inInterval: (xStart xEnd yStart yEnd zStart zEnd)
31  // bufferSize: (numX numY numZ)
32  // stateBuffer: [ *rho *rhoV *rhoE *scalarVars ]
33  //
34  // Output:
35  // dvBuffer: [p T 1/rho v1 v2 v3 rho*e]
36  int ComputeDVBuffer(const pcpp::IndexIntervalType &regionInterval,
37  const std::vector<size_t> &bufferSizes,
38  const std::vector<double *> &stateBuffers,
39  std::vector<double *> &dvBuffers);
40 
41 
42 
43  // Fortran-like interface
44  int ComputeDVBuffer2(const int *numDimPtr,
45  const size_t *bufferSize,
46  const size_t *numPointsPtr,
47  const size_t *bufferInterval,
48  const double *rhoBuffer,
49  const double *rhoVBuffer,
50  const double *rhoEBuffer,
51  double *pressureBuffer,
52  double *tempBuffer,
53  double *rhom1Buffer,
54  double *velBuffer);
55 
56  inline double Pulse(double amp,double width,double centerX,
57  double centerY,double centerZ,double x,double y,double z)
58  {
59  double xTerm = (x-centerX);
60  double yTerm = (y-centerY);
61  double zTerm = (z-centerZ);
62  double eTerm = zTerm*zTerm + xTerm*xTerm + yTerm*yTerm;
63  return(amp*std::exp(-(eTerm)/width));
64  };
65 
66  inline double Window(double tWidth,double wWidth,
67  double centerX,double centerY,double centerZ,
68  double x,double y,double z)
69  {
70 
71  double xWindow = 1.0;
72  double xPos = std::sqrt((x-centerX)*(x-centerX)+(y-centerY)*(y-centerY)+
73  (z-centerZ)*(z-centerZ));
74  double A = 3.14159265358979*2.0/tWidth;
75  double wPos = wWidth - xPos;
76  xWindow *= (std::tanh(A*wPos)+1.0)/2.0;
77  return(xWindow);
78  };
79 
80  inline double Parabola(double amp,double centerX,
81  double centerY,double centerZ,double x,double y,double z)
82  {
83  double xTerm = (x-centerX);
84  double yTerm = (y-centerY);
85  double zTerm = (z-centerZ);
86  double eTerm = zTerm*zTerm + xTerm*xTerm + yTerm*yTerm;
87  return(amp*eTerm);
88  };
89 
91  template<typename GridType,typename HaloType>
92  int CreateSimulationFixtures(GridType &inGrid,HaloType &inHalo,
94  const std::vector<size_t> &gridSizes,
95  int interiorOrder,
96  pcpp::CommunicatorType &inComm,
97  std::ostream *messageStreamPtr = NULL)
98  {
99 
100  int numProc = inComm.Size();
101  int myRank = inComm.Rank();
102 
103  if(!messageStreamPtr)
104  messageStreamPtr = &std::cout;
105 
106  pcpp::CommunicatorType &gridComm(inGrid.Communicator());
107 
108  int numDim = gridSizes.size();
109  std::vector<double> dX(numDim,0);
110  size_t numGlobalNodes = 1;
111  size_t numGlobalCells = 1;
112 
113  for(int iDim = 0;iDim < numDim;iDim++){
114  numGlobalNodes *= gridSizes[iDim];
115  numGlobalCells *= (gridSizes[iDim]-1);
116  dX[iDim] = 1.0/static_cast<double>(gridSizes[iDim]-1);
117  }
118 
119  inGrid.SetGridSizes(gridSizes);
120  inGrid.SetGridSpacings(dX);
121 
122  plascom2::operators::sbp::Initialize(inOperator,interiorOrder);
123  // int boundaryDepth = (inOperator.numStencils-1)/2;
124  int boundaryDepth = inOperator.boundaryDepth;
125  std::vector<int> haloDepths(2*numDim,boundaryDepth);
126 
128  cartInfo.numDimensions = numDim;
129  pcpp::ParallelTopologyInfoType pbsCartInfo;
130  pbsCartInfo.numDimensions = numDim;
131  pbsCartInfo.isPeriodic.resize(numDim,1);
132  pcpp::comm::SetupCartesianTopology(inComm,pbsCartInfo,gridComm,*messageStreamPtr);
133 
134  // Grab the local coordinates and global dimension of the Cartesian topo
135  std::vector<int> &cartCoords(gridComm.CartCoordinates());
136  std::vector<int> &cartDims(gridComm.CartDimensions());
137 
138  // Generate a report of the Cartesian setup and put it the messageStream
139  pcpp::report::CartesianSetup(*messageStreamPtr,pbsCartInfo);
140 
141  pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
142  pcpp::IndexIntervalType globalInterval;
143  globalInterval.InitSimple(gridSizes);
144 
145  // === Partition the grid ===
146  if(pcpp::util::PartitionCartesianInterval(globalInterval,cartDims,cartCoords,
147  partitionInterval,*messageStreamPtr)){
148  *messageStreamPtr << "TestFixtures:SetupSimulationFixtures:Error: Partitioning failed." << std::endl;
149  return(1);
150  }
151 
152  std::vector<size_t> extendGrid(2*numDim,0);
153  std::vector<bool> isPeriodic(numDim,true);
154  size_t numPointsPart = partitionInterval.NNodes();
155 
156  for(int iDim = 0;iDim < numDim; iDim++){
157  if(isPeriodic[iDim]){
158  extendGrid[2*iDim] = haloDepths[2*iDim];
159  extendGrid[2*iDim+1] = haloDepths[2*iDim+1];
160  } else {
161  if(partitionInterval[iDim].first == 0)
162  extendGrid[2*iDim] = haloDepths[2*iDim];
163  if(partitionInterval[iDim].second == (gridSizes[iDim]-1))
164  extendGrid[2*iDim + 1] = haloDepths[2*iDim+1];
165  }
166  }
167 
168  inGrid.SetDimensionExtensions(extendGrid);
169  if(inGrid.Finalize()){
170  *messageStreamPtr << "TestFixtures:SetupSimulationFixtures:Error: Grid finalization failed." << std::endl;
171  return(1);
172  }
173 
174  const std::vector<size_t> &bufferSizes(inGrid.BufferSizes());
175  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
176  size_t numPointsBuffer = inGrid.BufferSize();
177 
178  // Set up the HALO data structure
179  // halo_t testHalo(globalInterval,pbsPartInterval);
180  inHalo.SetGridInterval(globalInterval);
181  inHalo.SetPartitionInterval(partitionInterval);
182 
183  // This forces the halo to have neighbors even on
184  // partitions with domain boundaries.
185  std::vector<bool> haveNeighbors(2*numDim,true);
186  inHalo.SetNeighbors(haveNeighbors);
187 
188  std::vector<pcpp::IndexIntervalType> remoteHaloExtents(inHalo.CreateRemoteHaloExtents(extendGrid));
189  std::vector<pcpp::IndexIntervalType> localHaloExtents(inHalo.CreateLocalHaloExtents(extendGrid));
190 
191  inHalo.SetLocalBufferSizes(bufferSizes);
192  inHalo.SetLocalPartitionExtent(partitionBufferInterval);
193 
194  inHalo.SetRemoteHaloExtents(remoteHaloExtents);
195  inHalo.SetLocalHaloExtents(localHaloExtents);
196 
197  const std::vector<pcpp::IndexIntervalType> &remoteHaloBufferExtents(inHalo.RemoteHaloBufferExtents());
198  const std::vector<pcpp::IndexIntervalType> &localHaloBufferExtents(inHalo.LocalHaloBufferExtents());
199 
200  inHalo.CreateSimpleSendIndices();
201  inHalo.CreateSimpleRecvIndices();
202 
203  return(0);
204 
205  };
206 
207  // template<typename GridType>
208  // int CreateSimulationFixtures(GridType &inGrid,
209  // plascom2::operators::sbp::base &inOperator,
210  // std::vector<double> &physicalExtent,
211  // const std::vector<size_t> &gridSizes,
212  // int interiorOrder,
213  // pcpp::CommunicatorType &inComm,
214  // std::ostream *messageStreamPtr = NULL)
215 
217  template<typename GridType>
218  int InitializeSimulationFixtures(GridType &inGrid,
219  plascom2::operators::sbp::base &inOperator,
220  int interiorOrder,
221  pcpp::CommunicatorType &inComm,
222  std::ostream *messageStreamPtr = NULL)
223  {
224  typedef typename GridType::HaloType HaloType;
225 
226  int numProc = inComm.Size();
227  int myRank = inComm.Rank();
228 
229  if(!messageStreamPtr)
230  messageStreamPtr = &std::cout;
231 
232  pcpp::CommunicatorType &gridComm(inGrid.Communicator());
233 
234  std::vector<size_t> &gridSizes(inGrid.GridSizes());
235  std::vector<double> &physicalExtent(inGrid.PhysicalExtent());
236  std::vector<bool> &isPeriodic(inGrid.PeriodicDirs());
237 
238  int numDim = gridSizes.size();
239  std::vector<double> dX(numDim,0);
240  size_t numGlobalNodes = 1;
241  size_t numGlobalCells = 1;
242 
243  if(physicalExtent.empty()){
244  physicalExtent.resize(numDim*2,0);
245  for(int iDim = 0;iDim < numDim;iDim++)
246  physicalExtent[2*iDim+1] = 1.0;
247  }
248 
249  if(isPeriodic.empty()){
250  isPeriodic.resize(numDim,true);
251  }
252 
253  for(int iDim = 0;iDim < numDim;iDim++){
254  numGlobalNodes *= gridSizes[iDim];
255  numGlobalCells *= (gridSizes[iDim]-1);
256  dX[iDim] = (physicalExtent[2*iDim+1]-physicalExtent[2*iDim])/static_cast<double>(gridSizes[iDim]-1);
257  }
258 
259  inGrid.SetGridSpacings(dX);
260 
261  plascom2::operators::sbp::Initialize(inOperator,interiorOrder);
262 
263  int boundaryDepth = inOperator.boundaryDepth;
264  std::vector<int> haloDepths(2*numDim,boundaryDepth);
265 
267  cartInfo.numDimensions = numDim;
268  pcpp::ParallelTopologyInfoType pbsCartInfo;
269  pbsCartInfo.numDimensions = numDim;
270  pbsCartInfo.isPeriodic.resize(numDim,0);
271  for(int iDim = 0;iDim < numDim;iDim++)
272  pbsCartInfo.isPeriodic[iDim] = isPeriodic[iDim];
273 
274  pcpp::comm::SetupCartesianTopology(inComm,pbsCartInfo,gridComm,*messageStreamPtr);
275 
276  // Grab the local coordinates and global dimension of the Cartesian topo
277  std::vector<int> &cartCoords(gridComm.CartCoordinates());
278  std::vector<int> &cartDims(gridComm.CartDimensions());
279 
280  std::vector<int> gridNeighbors;
281  gridComm.CartNeighbors(gridNeighbors);
282 
283 
284  // Generate a report of the Cartesian setup and put it the messageStream
285  pcpp::report::CartesianSetup(*messageStreamPtr,pbsCartInfo);
286 
287  pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
288  pcpp::IndexIntervalType globalInterval;
289  globalInterval.InitSimple(gridSizes);
290 
291  // === Partition the grid ===
292  if(pcpp::util::PartitionCartesianInterval(globalInterval,cartDims,cartCoords,
293  partitionInterval,*messageStreamPtr)){
294  *messageStreamPtr << "TestFixtures:SetupSimulationFixtures:Error: Partitioning failed." << std::endl;
295  return(1);
296  }
297 
298  std::vector<size_t> extendGrid(2*numDim,0);
299  // std::vector<bool> isPeriodic(numDim,true);
300  size_t numPointsPart = partitionInterval.NNodes();
301 
302  std::vector<bool> haveNeighbors(2*numDim,true);
303  for(int iDim = 0;iDim < numDim; iDim++){
304  if(isPeriodic[iDim]){
305  extendGrid[2*iDim] = haloDepths[2*iDim];
306  extendGrid[2*iDim+1] = haloDepths[2*iDim+1];
307  } else {
308  if(partitionInterval[iDim].first == 0) {
309  haveNeighbors[2*iDim] = false;
310  } else {
311  extendGrid[2*iDim] = haloDepths[2*iDim];
312  }
313  if(partitionInterval[iDim].second == (gridSizes[iDim]-1)){
314  haveNeighbors[2*iDim+1] = false;
315  } else {
316  extendGrid[2*iDim + 1] = haloDepths[2*iDim+1];
317  }
318  }
319  }
320 
321  inGrid.SetDimensionExtensions(extendGrid);
322 
323 
324  if(inGrid.Finalize()){
325  *messageStreamPtr << "TestFixtures:SetupSimulationFixtures:Error: Grid finalization failed." << std::endl;
326  return(1);
327  }
328 
329  if(inGrid.GenerateCoordinates(*messageStreamPtr)){
330  *messageStreamPtr << "TestFixtures:SetupSimulationFixtures:Error: Grid coordinates generation failed."
331  << std::endl;
332  return(1);
333  }
334 
335  const std::vector<size_t> &bufferSizes(inGrid.BufferSizes());
336  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
337  size_t numPointsBuffer = inGrid.BufferSize();
338 
339  // Set up the HALO data structure
340  // halo_t testHalo(globalInterval,pbsPartInterval);
341  HaloType &inHalo(inGrid.Halo());
342  inHalo.SetGridInterval(globalInterval);
343  inHalo.SetPartitionInterval(partitionInterval);
344  inHalo.SetPeriodicDirs(pbsCartInfo.isPeriodic);
345 
346  // This forces the halo to have neighbors even on
347  // partitions with domain boundaries.
348  int rank = gridComm.Rank();
349  int numProcGrid = gridComm.NProc();
350 
351  inHalo.SetNeighbors(haveNeighbors);
352 
353  std::vector<pcpp::IndexIntervalType> remoteHaloExtents(inHalo.CreateRemoteHaloExtents(extendGrid));
354  std::vector<pcpp::IndexIntervalType> localHaloExtents(inHalo.CreateLocalHaloExtents(extendGrid));
355 
356  inHalo.SetLocalBufferSizes(bufferSizes);
357  inHalo.SetLocalPartitionExtent(partitionBufferInterval);
358 
359  inHalo.SetRemoteHaloExtents(remoteHaloExtents);
360  inHalo.SetLocalHaloExtents(localHaloExtents);
361 
362  const std::vector<pcpp::IndexIntervalType> &remoteHaloBufferExtents(inHalo.RemoteHaloBufferExtents());
363  const std::vector<pcpp::IndexIntervalType> &localHaloBufferExtents(inHalo.LocalHaloBufferExtents());
364 
365  inHalo.CreateSimpleSendIndices();
366  inHalo.CreateSimpleRecvIndices();
367 
368  return(0);
369 
370  };
371 
373  template<typename GridType,typename StateType>
374  int SetupEulerState(const GridType &inGrid,StateType &inState,StateType &inParams,int numScalars,
375  bool withFlux = false)
376  {
377 
378  size_t numPointsBuffer = inGrid.BufferSize();
379  const std::vector<size_t> &bufferSizes(inGrid.BufferSizes());
380  const std::vector<size_t> &gridSizes(inGrid.GridSizes());
381  const pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
382  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
383  const std::vector<double> &dX(inGrid.DX());
384  int numDim = bufferSizes.size();
385 
386  inState.AddField("simTime",'s',1,8,"s");
387 
388  // Conserved quantities, mass, momentum, and energy densities
389  inState.AddField("rho",'n',1,8,"mass/vol");
390  inState.AddField("rhoV",'n',numDim,8,"momentum/vol");
391  inState.AddField("rhoE",'n',1,8,"energy/vol");
392 
393  if(numScalars>0)
394  inState.AddField("scalarVars",'n',numScalars,8,"m/M");
395 
396  //for(int iScalar = 0;iScalar < numScalar;iScalar++){
397  //std::ostringstream Ostr;
398  //Ostr << "scalar-" << iScalar+1;
399  //inState.AddField(Ostr.str(),'n',1,8,"m/M");
400  //}
401 
402  // Dependent quantities, pressure, temperature, velocity
403  inState.AddField("pressure",'n',1,8,"pressure");
404  inState.AddField("temperature",'n',1,8,"temperature");
405  inState.AddField("rhom1",'n',1,8,"volume");
406  inState.AddField("velocity",'n',numDim,8,"velocity");
407 
408  // Flux quanitites (if tracking desired)
409  if(withFlux){
410  inState.AddField("massFlux",'n',numDim,8,"");
411  inState.AddField("mom1Flux",'n',numDim,8,"");
412  inState.AddField("mom2Flux",'n',numDim,8,"");
413  if(numDim == 3){
414  inState.AddField("mom3Flux",'n',3,8,"");
415  }
416  inState.AddField("energyFlux",'n',3,8,"");
417  if(numScalars>0)
418  inState.AddField("scalarVarsFlux",'n',numScalars,8,"");
419  }
420 
421  inState.Create(numPointsBuffer,0);
422  if(numScalars == 0)
423  inState.SetStateFields("rho rhoV rhoE");
424  else
425  inState.SetStateFields("rho rhoV rhoE scalarVars");
426 
427 
428  inParams.AddField("gamma",'s',1,8,"");
429  inParams.AddField("inputDT",'s',1,8,"s");
430  inParams.AddField("inputCFL",'s',1,8,"");
431  //inParams.AddField("refC",'s',1,8,"soundspeed");
432  //inParams.AddField("refR",'s',1,8,"gasconstant");
433  inParams.AddField("refRe",'s',1,8,"ReynoldsNo");
434  inParams.AddField("refPr",'s',1,8,"PrandtlNo");
435 
436  inParams.Create(numPointsBuffer,0);
437 
438  return(0);
439  };
440 
441  template<typename DatasetType>
442  int ValidateState(const DatasetType &inState,
443  const DatasetType &inParam,
444  std::ostream &outStream)
445  {
446  int RHO = 1<<1;
447  int RHOV = 1<<2;
448  int RHOE = 1<<3;
449  int SIMT = 1<<4;
450  int INDT = 1<<5;
451  int INCFL = 1<<6;
452  int REFL = 1<<7;
453  int REFP = 1<<8;
454  int REFT = 1<<9;
455  int REFRE = 1<<13;
456  int REFRHO = 1<<10;
457  int GAMMA = 1<<11;
458  int NOND = 1<<12;
459 
460  int dataFaults = 0;
461 
462  int dataHandle = inState.GetDataIndex("rho");
463  if(dataHandle < 0){
464  dataFaults |= RHO;
465  }
466  dataHandle = inState.GetDataIndex("rhoV");
467  if(dataHandle < 0){
468  dataFaults |= RHOV;
469  }
470  dataHandle = inState.GetDataIndex("rhoE");
471  if(dataHandle < 0){
472  dataFaults |= RHOE;
473  }
474  dataHandle = inState.GetDataIndex("simTime");
475  if(dataHandle < 0){
476  dataFaults |= SIMT;
477  }
478  dataHandle = inParam.GetDataIndex("inputDT");
479  if(dataHandle < 0){
480  dataFaults |= INDT;
481  }
482  dataHandle = inParam.GetDataIndex("inputCFL");
483  if(dataHandle < 0){
484  dataFaults |= INCFL;
485  }
486  dataHandle = inParam.GetDataIndex("refRho");
487  if(dataHandle < 0){
488  dataFaults |= REFRHO;
489  }
490  dataHandle = inParam.GetDataIndex("refPressure");
491  if(dataHandle < 0){
492  dataFaults |= REFP;
493  }
494  dataHandle = inParam.GetDataIndex("refTemperature");
495  if(dataHandle < 0){
496  dataFaults |= REFT;
497  }
498  dataHandle = inParam.GetDataIndex("refRe");
499  if(dataHandle < 0){
500  dataFaults |= REFRE;
501  }
502  dataHandle = inParam.GetDataIndex("gamma");
503  if(dataHandle < 0){
504  dataFaults |= GAMMA;
505  }
506  dataHandle = inParam.GetDataIndex("refLength");
507  if(dataHandle < 0){
508  dataFaults |= REFL;
509  }
510  dataHandle = inParam.GetDataIndex("nonDimensional");
511  if(dataHandle < 0){
512  dataFaults |= NOND;
513  }
514 
515  int errorState = 0;
516  if(dataFaults&RHO){
517  outStream << "Required data \"rho\" did not exist in state." << std::endl;
518  errorState++;
519  }
520  if(dataFaults&RHOV){
521  outStream << "Required data \"rhoV\" did not exist in state." << std::endl;
522  errorState++;
523  }
524  if(dataFaults&RHOE){
525  outStream << "Required data \"rhoE\" did not exist in state." << std::endl;
526  errorState++;
527  }
528  if(dataFaults&SIMT){
529  outStream << "Required data \"simTime\" did not exist in state." << std::endl;
530  errorState++;
531  }
532  if(dataFaults&INDT){
533  outStream << "Parameter data \"inputDT\" did not exist." << std::endl;
534  }
535  if(dataFaults&INCFL){
536  outStream << "Parameter data \"inputCFL\" did not exist." << std::endl;
537  }
538  if(dataFaults&REFL){
539  outStream << "Parameter data \"refLength\" did not exist." << std::endl;
540  }
541  if(dataFaults&REFP){
542  outStream << "Parameter data \"refPressure\" did not exist." << std::endl;
543  }
544  if(dataFaults&REFT){
545  outStream << "Parameter data \"refTemperature\" did not exist." << std::endl;
546  }
547  if(dataFaults&REFRHO){
548  outStream << "Parameter data \"refRho\" did not exist." << std::endl;
549  }
550  if(dataFaults&GAMMA){
551  outStream << "Parameter data \"gamma\" did not exist." << std::endl;
552  }
553  if(dataFaults&NOND){
554  outStream << "Parameter data \"nonDimensional\" did not exist." << std::endl;
555  }
556  if(dataFaults&REFRE){
557  outStream << "Parameter data \"refRe\" did not exist." << std::endl;
558  }
559  return(errorState);
560  };
561 
562  template<typename GridType,typename StateType>
563  int InitializeQuiescentState(const GridType &inGrid,StateType &inState,
564  StateType &inParam,int threadId,std::ostream *messageStream = NULL)
565  {
566  if(!messageStream)
567  messageStream = &std::cout;
568 
569  std::ostringstream Ostr;
570  if(ValidateState(inState,inParam,Ostr)){
571  std::cout << "Input State in Error:" << std::endl;
572  *messageStream << Ostr.str() << std::endl;
573  return(1);
574  } else {
575  *messageStream << "Input State Validation: " << std::endl
576  << Ostr.str() << std::endl;
577  }
578 
579  int rhoHandle = inState.GetDataIndex("rho");
580  if(rhoHandle < 0)
581  return(1);
582  pcpp::field::dataset::DataBufferType &rhoData(inState.Field(rhoHandle));
583  double *rhoPtr = rhoData.Data<double>();
584  if(!rhoPtr)
585  return(1);
586 
587  int rhoVHandle = inState.GetDataIndex("rhoV");
588  if(rhoVHandle < 0)
589  return(1);
590  pcpp::field::dataset::DataBufferType &rhoVData(inState.Field(rhoVHandle));
591  double *rhoVPtr = rhoVData.Data<double>();
592  if(!rhoVPtr)
593  return(1);
594 
595  int rhoEHandle = inState.GetDataIndex("rhoE");
596  if(rhoEHandle < 0)
597  return(1);
598  pcpp::field::dataset::DataBufferType &rhoEData(inState.Field(rhoEHandle));
599  double *rhoEPtr = rhoEData.Data<double>();
600  if(!rhoPtr)
601  return(1);
602 
603  size_t numPointsBuffer = inGrid.BufferSize();
604  const std::vector<size_t> &bufferSizes(inGrid.BufferSizes());
605  const std::vector<double> &dX(inGrid.DX());
606  const std::vector<size_t> &gridSizes(inGrid.GridSizes());
607  const pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
608  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
609 
610  int numDim = gridSizes.size();
611 
612  double *timePtr = NULL;
613  double *deltaTPtr = NULL;
614  double *gammaPtr = NULL;
615  double *CFLPtr = NULL;
616  double *lengthRefPtr = NULL;
617  double *rhoRefPtr = NULL;
618  double *presRefPtr = NULL;
619  double *tempRefPtr = NULL;
620  double *sigmaPtr = NULL;
621  double *rePtr = NULL;
622  int *nonDimenPtr = NULL;
623 
624  int dataHandle = inState.GetDataIndex("simTime");
625  if(dataHandle < 0){
626  inState.AddField("simTime",'d',1,8,"time");
627  inState.Create();
628  }
629  timePtr = inState.template GetFieldBuffer<double>("simTime");
630  if(*timePtr < 0)
631  *timePtr = 0.0;
632 
633  dataHandle = inParam.GetDataIndex("inputDT");
634  if(dataHandle < 0){
635  inParam.AddField("inputDT",'d',1,8,"time");
636  inParam.Create();
637  }
638  deltaTPtr = inParam.template GetFieldBuffer<double>("inputDT");
639 
640  dataHandle = inParam.GetDataIndex("gamma");
641  if(dataHandle < 0){
642  inParam.AddField("gamma",'d',1,8,"");
643  inParam.Create();
644  }
645  gammaPtr = inParam.template GetFieldBuffer<double>("gamma");
646 
647  dataHandle = inParam.GetDataIndex("inputCFL");
648  if(dataHandle < 0){
649  inParam.AddField("inputCFL",'d',1,8,"");
650  inParam.Create();
651  }
652  CFLPtr = inParam.template GetFieldBuffer<double>("inputCFL");
653 
654  dataHandle = inParam.GetDataIndex("refLength");
655  if(dataHandle < 0){
656  inParam.AddField("refLength",'d',1,8,"length");
657  inParam.Create();
658  }
659  lengthRefPtr = inParam.template GetFieldBuffer<double>("refLength");
660 
661  dataHandle = inParam.GetDataIndex("refRho");
662  if(dataHandle < 0){
663  inParam.AddField("refRho",'d',1,8,"density");
664  inParam.Create();
665  }
666  rhoRefPtr = inParam.template GetFieldBuffer<double>("refRho");
667 
668  dataHandle = inParam.GetDataIndex("refPressure");
669  if(dataHandle < 0){
670  inParam.AddField("refPressure",'d',1,8,"pressure");
671  inParam.Create();
672  }
673  presRefPtr = inParam.template GetFieldBuffer<double>("refPressure");
674 
675  dataHandle = inParam.GetDataIndex("refTemperature");
676  if(dataHandle < 0){
677  inParam.AddField("refTemperature",'d',1,8,"temperature");
678  inParam.Create();
679  }
680  tempRefPtr = inParam.template GetFieldBuffer<double>("refTemperature");
681 
682  dataHandle = inParam.GetDataIndex("sigma");
683  if(dataHandle < 0){
684  inParam.AddField("sigma",'d',1,8,"");
685  inParam.Create();
686  }
687  sigmaPtr = inParam.template GetFieldBuffer<double>("sigma");
688 
689  dataHandle = inParam.GetDataIndex("refRe");
690  if(dataHandle < 0){
691  inParam.AddField("refRe",'d',1,8,"ReynoldsNo");
692  inParam.Create();
693  }
694  rePtr = inParam.template GetFieldBuffer<double>("refRe");
695 
696  dataHandle = inParam.GetDataIndex("nonDimensional");
697  if(dataHandle < 0){
698  inParam.AddField("nonDimensional",'d',1,4,"");
699  inParam.Create();
700  }
701  nonDimenPtr = inParam.template GetFieldBuffer<int>("nonDimensional");
702 
703  *messageStream << "Parameters: " << std::endl
704  << "time: " << *timePtr << std::endl
705  << "deltaT: " << *deltaTPtr << std::endl
706  << "gamma: " << *gammaPtr << std::endl
707  << "CFL: " << *CFLPtr << std::endl
708  << "lengthRef: " << *lengthRefPtr << std::endl
709  << "rhoRef: " << *rhoRefPtr << std::endl
710  << "pressureRef: " << *presRefPtr << std::endl
711  << "temperatureRef: " << *tempRefPtr << std::endl
712  << "Re: " << *rePtr << std::endl
713  << "Sigma: " << *sigmaPtr << std::endl
714  << "nonDimensional: " << *nonDimenPtr << std::endl;
715 
716  double gammaValue = 1.4;
717 
718  // check the reference state. Default to a dimensional mode if set incorrectly.
719  if((*presRefPtr < 0 || *presRefPtr > 1e10) ||
720  (*rhoRefPtr < 0 || *rhoRefPtr > 1e10) ||
721  (*tempRefPtr < 0 || *tempRefPtr > 1e10)){
722  *messageStream << "Invalid reference state in Initialize quiescent state."
723  << " Defaulting to non-dimensional mode." << std::endl;
724  *presRefPtr = 101325.0;
725  *rhoRefPtr = 1.225;
726  *tempRefPtr = 288.15;
727 
728  *messageStream << "Reference state: " << std::endl
729  << "\t Density = " << *rhoRefPtr << std::endl
730  << "\t Pressure = " << *presRefPtr << std::endl
731  << "\t Temperature = " << *tempRefPtr << std::endl;
732  }
733 
734  if(*CFLPtr < 0 || *CFLPtr > 4)
735  *CFLPtr = 1.0;
736 
737  *timePtr = 0.0;
738 
739  if(*gammaPtr < 0 || *gammaPtr > 4)
740  *gammaPtr = gammaValue;
741 
742  gammaValue = *gammaPtr;
743  double cRef = sqrt(gammaValue*(*presRefPtr)/(*rhoRefPtr));
744 
745  if(*deltaTPtr < 1e-20 || *deltaTPtr > 2){
746  *messageStream << "DT parameter outside bounds (" << *deltaTPtr
747  << "). Calculating max timestep based on CFL ("
748  << *CFLPtr << ") and reference speed (" << cRef
749  << ")" << std::endl;
750  // Set params in here for now
751  double minSpacing = 100000.0;
752  std::vector<double>::const_iterator dxIt = dX.begin();
753  while(dxIt != dX.end()){
754  if(*dxIt < minSpacing) minSpacing = *dxIt;
755  dxIt++;
756  }
757  *deltaTPtr = minSpacing*(*CFLPtr)/(cRef);
758  }
759 
760  // Zero entire buffer(s)
761  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++){
762  rhoPtr[iPoint] = 0.0;
763  rhoEPtr[iPoint] = 0.0;
764  }
765  for(int iDim = 0;iDim < numDim;iDim++){
766  size_t dimOffset = iDim*numPointsBuffer;
767  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++)
768  rhoVPtr[iPoint+dimOffset] = 0.0;
769  }
770 
771  std::vector<double> rhoV(numDim,0.0); // really just velocity at this point
772  // Comment next line for quiescent, uncomment for constant flow in X
773  // rhoV[0] = 1.0;
774  double rho = 1.0;
775  double pressure = 1.0;
776  if(!*nonDimenPtr){
777  rho = *rhoRefPtr;
778  pressure = *presRefPtr;
779  }
780  double eInternal = (pressure/(gammaValue-1.0))/rho;
781  double eKinetic = 0.0;
782  std::vector<double>::iterator rhoVIt = rhoV.begin();
783  while(rhoVIt != rhoV.end()){
784  eKinetic += (rho * (*rhoVIt) * (*rhoVIt));
785  *rhoVIt *= rho; // make it rho*V for real
786  rhoVIt++;
787  }
788  eKinetic *= .5;
789  double rhoE = rho*(eInternal + eKinetic);
790 
791  if(numDim == 3){
792  size_t iStart = partitionBufferInterval[0].first;
793  size_t iEnd = partitionBufferInterval[0].second;
794  size_t jStart = partitionBufferInterval[1].first;
795  size_t jEnd = partitionBufferInterval[1].second;
796  size_t kStart = partitionBufferInterval[2].first;
797  size_t kEnd = partitionBufferInterval[2].second;
798  size_t nPlane = bufferSizes[0]*bufferSizes[1];
799  for(size_t kIndex = kStart;kIndex <= kEnd;kIndex++){
800  size_t kBufferIndex = kIndex*nPlane;
801  for(size_t jIndex = jStart;jIndex <= jEnd;jIndex++){
802  size_t jkBufferIndex = kBufferIndex + jIndex*bufferSizes[0];
803  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
804  size_t bufferIndex = jkBufferIndex + iIndex;
805  rhoPtr[bufferIndex] = rho;
806  rhoEPtr[bufferIndex] = rhoE;
807  rhoVPtr[bufferIndex] = rhoV[0];
808  rhoVPtr[bufferIndex+numPointsBuffer] = rhoV[1];
809  rhoVPtr[bufferIndex+2*numPointsBuffer] = rhoV[2];
810  }
811  }
812  }
813  } else if (numDim == 2) {
814  size_t iStart = partitionBufferInterval[0].first;
815  size_t iEnd = partitionBufferInterval[0].second;
816  size_t jStart = partitionBufferInterval[1].first;
817  size_t jEnd = partitionBufferInterval[1].second;
818  for(size_t jIndex = jStart;jIndex <= jEnd;jIndex++){
819  size_t jBufferIndex = jIndex*bufferSizes[0];
820  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
821  size_t bufferIndex = jBufferIndex + iIndex;
822  rhoPtr[bufferIndex] = rho;
823  rhoEPtr[bufferIndex] = rhoE;
824  rhoVPtr[bufferIndex] = rhoV[0];
825  rhoVPtr[bufferIndex+numPointsBuffer] = rhoV[1];
826  }
827  }
828  } else if (numDim == 1) {
829  size_t iStart = partitionBufferInterval[0].first;
830  size_t iEnd = partitionBufferInterval[0].second;
831  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
832  rhoPtr[iIndex] = rho;
833  rhoEPtr[iIndex] = rhoE;
834  rhoVPtr[iIndex] = rhoV[0];
835  }
836  }
837 
838  return(0);
839  }
840 
841  template<typename GridType,typename StateType>
842  int InitializeShock1D(const GridType &inGrid,StateType &inState,
843  StateType &inParamState,const std::vector<double> &inParams, int threadId,
844  std::ostream *messageStream)
845  {
846  if(!messageStream)
847  messageStream = &std::cout;
848 
849  double inletX = 0.0; // inlet x coordinate
850  double inletY = 0.0; // inlet y coordinate
851  double inletZ = 0.0; // inlet z coordinate
852  int direction = 1;
853  double location = 0.1;
854  double transitionWidth = 0.0;
855  double mach = 1.0; // shock pressure ratio
856  int referenceFrame = 0; // 0 for stationary (lab frame), 1 for moving with shock
857 
858  int numParams = inParams.size();
859  if(numParams > 0)
860  mach = inParams[0];
861  if(numParams > 1)
862  direction = static_cast<int>(inParams[1]);
863  if(numParams > 2)
864  location = inParams[2];
865  if(numParams > 3)
866  transitionWidth = inParams[3];
867  if(numParams > 4)
868  referenceFrame = inParams[4];
869 
870  int rhoHandle = inState.GetDataIndex("rho");
871  if(rhoHandle < 0)
872  return(1);
873  pcpp::field::dataset::DataBufferType &rhoData(inState.Field(rhoHandle));
874  double *rhoPtr = rhoData.Data<double>();
875  if(!rhoPtr)
876  return(1);
877 
878  int rhoVHandle = inState.GetDataIndex("rhoV");
879  if(rhoVHandle < 0)
880  return(1);
881  pcpp::field::dataset::DataBufferType &rhoVData(inState.Field(rhoVHandle));
882  double *rhoVPtr = rhoVData.Data<double>();
883  if(!rhoVPtr)
884  return(1);
885 
886  int rhoEHandle = inState.GetDataIndex("rhoE");
887  if(rhoEHandle < 0)
888  return(1);
889  pcpp::field::dataset::DataBufferType &rhoEData(inState.Field(rhoEHandle));
890  double *rhoEPtr = rhoEData.Data<double>();
891  if(!rhoPtr)
892  return(1);
893 
894  size_t numPointsBuffer = inGrid.BufferSize();
895  const std::vector<size_t> &bufferSizes(inGrid.BufferSizes());
896  const std::vector<double> &dX(inGrid.DX());
897  const std::vector<size_t> &gridSizes(inGrid.GridSizes());
898  const std::vector<double> &readGridExtent(inGrid.PhysicalExtent());
899  const pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
900  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
901  const std::vector<double> &coordinateData(inGrid.CoordinateData());
902 
903  int numDim = gridSizes.size();
904 
905  double *gammaPtr = inParamState.template GetFieldBuffer<double>("gamma");
906  double *lengthRefPtr = inParamState.template GetFieldBuffer<double>("refLength");
907  double *rhoRefPtr = inParamState.template GetFieldBuffer<double>("refRho");
908  double *presRefPtr = inParamState.template GetFieldBuffer<double>("refPressure");
909  double *tempRefPtr = inParamState.template GetFieldBuffer<double>("refTemperature");
910  double *rePtr = inParamState.template GetFieldBuffer<double>("refRe");
911  double *prPtr = inParamState.template GetFieldBuffer<double>("refPr");
912  int *nonDimenPtr = inParamState.template GetFieldBuffer<int>("nonDimensional");
913 
914  double gamma = *gammaPtr;
915  double refLength = *lengthRefPtr;
916  double refRho = *rhoRefPtr;
917  double refPressure = *presRefPtr;
918  double refTemperature = *tempRefPtr;
919  double sndSpdRef = sqrt(gamma*refPressure/refRho);
920  double velRef = sqrt(refPressure/refRho);
921 
922  // Zero entire buffer(s)
923  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++){
924  rhoPtr[iPoint] = 0.0;
925  rhoEPtr[iPoint] = 0.0;
926  }
927  for(int iDim = 0;iDim < numDim;iDim++){
928  size_t dimOffset = iDim*numPointsBuffer;
929  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++)
930  rhoVPtr[iPoint+dimOffset] = 0.0;
931  }
932 
933  double xMin = readGridExtent[0];
934  double xMax = readGridExtent[1];
935  double yMin = readGridExtent[2];
936  double yMax = readGridExtent[3];
937  double zMin = 0.;
938  double zMax = 0.;
939  if(numDim > 2 ) {
940  zMin = readGridExtent[4];
941  zMax = readGridExtent[5];
942  }
943 
944 
945  // dimensional flow conditions
946  // calculated from normal shock relations
947  //
948  double pressureRatio = (2.*gamma*mach*mach-(gamma-1.))/(gamma+1.);
949  double densityRatio = (gamma+1.)*mach*mach/((gamma-1.)*mach*mach+2.);
950  double mach2 = sqrt(((gamma-1.)*mach*mach+2.)/(2.*gamma*mach*mach-(gamma-1.)));
951  double rho1 = *rhoRefPtr;
952  double pressure1 = *presRefPtr;
953  double rho2 = rho1*densityRatio;
954  double pressure2 = pressure1*pressureRatio;
955  // convective velocity (behind shock wave in lab frame, shock moving)
956  double velocity1 = 0.;
957  double velocity2 = -mach*sndSpdRef*(1/densityRatio-1);
958  // moving shock reference frame
959  if(referenceFrame == 1) {
960  velocity1 = -mach*sndSpdRef;
961  velocity2 = velocity1/densityRatio;
962  }
963 
964  std::vector<double> rhoV(numDim,0.0);
965 
966  // scale for nonDimensionalization
967  if(*nonDimenPtr == 1){
968  rho1 = rho1/(*rhoRefPtr);
969  rho2 = rho2/(*rhoRefPtr);
970  pressure1 = pressure1/(*presRefPtr);
971  pressure2 = pressure2/(*presRefPtr);
972  velocity1 = velocity1/velRef;
973  velocity2 = velocity2/velRef;
974  } else if(*nonDimenPtr == 2){
975  rho1 = rho1/(*rhoRefPtr);
976  rho2 = rho2/(*rhoRefPtr);
977  pressure1 = *presRefPtr/((*rhoRefPtr)*sndSpdRef*sndSpdRef);
978  pressure2 = pressure2/((*rhoRefPtr)*sndSpdRef*sndSpdRef);
979  velocity1 = velocity1/sndSpdRef;
980  velocity2 = velocity2/sndSpdRef;
981  }
982  // internal energy
983  double rhoE1 = pressure1/(gamma-1.0) + 0.5*rho1*velocity1*velocity1;
984  double rhoE2 = pressure2/(gamma-1.0) + 0.5*rho2*velocity2*velocity2;
985 
986  if(referenceFrame == 0){
987  *messageStream << "Shock moving (lab) reference frame" << std::endl;
988  } else if (referenceFrame == 1) {
989  *messageStream << "Shock stationary (shock attached) reference frame" << std::endl;
990  } else {
991  *messageStream << "Invalid reference frame selection. "
992  << "Must be 0 (lab reference) or 1 (shock attached)." << std::endl;
993  return(1);
994  }
995 
996 
997  *messageStream << "InitializeShock1D: Pressure Ratio " << pressureRatio << std::endl;
998  *messageStream << "InitializeShock1D: Density Ratio " << densityRatio << std::endl;
999  *messageStream << "InitializeShock1D: Upstream Mach Number " << mach << std::endl;
1000  *messageStream << "InitializeShock1D: Upstream Total Energy "
1001  << rhoE1+0.5*rho1*densityRatio*velocity1*velocity1 << std::endl;
1002  *messageStream << "InitializeShock1D: Post-shock Density " << rho2 << std::endl;
1003  *messageStream << "InitializeShock1D: Post-shock Pressure " << pressure2 << std::endl;
1004  *messageStream << "InitializeShock1D: Post-shock Velocity " << velocity2 << std::endl;
1005  *messageStream << "InitializeShock1D: Post-shock Total Energy "
1006  << rhoE1*pressureRatio+0.5*rho2*velocity2*velocity2 << std::endl;
1007 
1008  double transitionPoint = 0.2;
1009  if(direction == 1) {
1010  transitionPoint = location;
1011  } else if(direction == 2) {
1012  transitionPoint = location;
1013  } else if(direction == 3) {
1014  transitionPoint = location;
1015  }
1016 
1017  if(numDim == 3){
1018  size_t iStart = partitionBufferInterval[0].first;
1019  size_t iEnd = partitionBufferInterval[0].second;
1020  size_t jStart = partitionBufferInterval[1].first;
1021  size_t jEnd = partitionBufferInterval[1].second;
1022  size_t kStart = partitionBufferInterval[2].first;
1023  size_t kEnd = partitionBufferInterval[2].second;
1024  size_t nPlane = bufferSizes[0]*bufferSizes[1];
1025  for(size_t kIndex = kStart;kIndex <= kEnd;kIndex++){
1026  size_t kBufferIndex = kIndex*nPlane;
1027  size_t kPartIndex = (kIndex - kStart) + partitionInterval[2].first;
1028  double z = kPartIndex*dX[2];
1029  for(size_t jIndex = jStart;jIndex <= jEnd;jIndex++){
1030  size_t jkBufferIndex = kBufferIndex + jIndex*bufferSizes[0];
1031  size_t jPartIndex = (jIndex - jStart) + partitionInterval[1].first;
1032  double y = jPartIndex*dX[1];
1033  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
1034  size_t bufferIndex = jkBufferIndex + iIndex;
1035  size_t iPartIndex = (iIndex - iStart) + partitionInterval[0].first;
1036  double x = iPartIndex*dX[0];
1037 
1038 
1039  double position = 0.;
1040  if(direction == 1) {
1041  position = x;
1042  } else if(direction == 2) {
1043  position = y;
1044  } else if(direction == 3) {
1045  position = z;
1046  }
1047 
1048  double transitionFactor = (1-std::tanh((position-transitionPoint)/transitionWidth))/2.0;
1049  rhoPtr[bufferIndex] = rho1+(rho2-rho1)*transitionFactor;
1050  rhoEPtr[bufferIndex] = rhoE1+(rhoE2-rhoE1)*transitionFactor;
1051  for(int iDim=0;iDim<numDim;iDim++){
1052  size_t velBufferIndex = bufferIndex+numPointsBuffer*iDim;
1053  if(direction == iDim+1){
1054  rhoVPtr[velBufferIndex] = rho1*velocity1 +
1055  (rho2*velocity2-rho1*velocity1)*transitionFactor;
1056  }
1057  }
1058  }
1059  }
1060  }
1061  } else if (numDim == 2) {
1062  size_t iStart = partitionBufferInterval[0].first;
1063  size_t iEnd = partitionBufferInterval[0].second;
1064  size_t jStart = partitionBufferInterval[1].first;
1065  size_t jEnd = partitionBufferInterval[1].second;
1066  for(size_t jIndex = jStart;jIndex <= jEnd;jIndex++){
1067  size_t jBufferIndex = jIndex*bufferSizes[0];
1068  size_t jPartIndex = (jIndex - jStart) + partitionInterval[1].first;
1069  double y = jPartIndex*dX[1];
1070  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
1071  size_t bufferIndex = jBufferIndex + iIndex;
1072  size_t iPartIndex = (iIndex - iStart) + partitionInterval[0].first;
1073  double x = iPartIndex*dX[0];
1074 
1075  double position = 0.;
1076  if(direction == 1) {
1077  position = x;
1078  } else if(direction == 2) {
1079  position = y;
1080  }
1081 
1082  double transitionFactor = (1-std::tanh((position-transitionPoint)/transitionWidth))/2.0;
1083 
1084  rhoPtr[bufferIndex] = rho1+(rho2-rho1)*transitionFactor;
1085  rhoEPtr[bufferIndex] = rhoE1+(rhoE2-rhoE1)*transitionFactor;
1086  //if((iIndex == 0 || iIndex == iEnd) && jIndex == jStart) {
1087  //*messageStream << "rho: " << rhoPtr[bufferIndex] << std::endl;
1088  //*messageStream << "rhoE internal: " << rhoEPtr[bufferIndex] << std::endl;
1089  //}
1090  for(int iDim=0;iDim<numDim;iDim++){
1091  size_t velBufferIndex = bufferIndex+numPointsBuffer*iDim;
1092  if(direction == iDim+1){
1093  rhoVPtr[velBufferIndex] = rho1*velocity1 +
1094  (rho2*velocity2-rho1*velocity1)*transitionFactor;
1095  //rhoEPtr[bufferIndex] += rhoVPtr[velBufferIndex]*rhoVPtr[velBufferIndex]/
1096  //(2.0*rhoPtr[bufferIndex]);
1097  }
1098  }
1099  //if((iIndex == 0 || iIndex == iEnd) && jIndex == jStart) {
1100  //*messageStream << "rhoV: " << rhoVPtr[bufferIndex] << std::endl;
1101  //*messageStream << "rhoE total: " << rhoEPtr[bufferIndex] << std::endl;
1102  //}
1103 
1104  }
1105  }
1106  } else if (numDim == 1) {
1107  size_t iStart = partitionBufferInterval[0].first;
1108  size_t iEnd = partitionBufferInterval[0].second;
1109  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
1110  rhoPtr[iIndex] = rho1;
1111  rhoEPtr[iIndex] = rhoE1;
1112  rhoVPtr[iIndex] = rhoV[0];
1113  }
1114  }
1115 
1116  return(0);
1117  }
1118 
1119 
1121  template<typename GridType,typename StateType,typename BoundaryType>
1122  int InitializeProtoY4Test1(const GridType &inGrid,StateType &inState,
1123  StateType &inParamState,
1124  std::vector<BoundaryType> &inBoundaries,
1125  const std::vector<double> &inParams,
1126  const std::vector<int> &inFlags,int threadId)
1127  {
1128 
1129  double pulseAmp = 0.01;
1130  double pulseWidth = 0.000001;
1131  double pulseRadius = 0.005;
1132  double centerX = 0.5;
1133  double centerY = 0.010;
1134  double crossFlowSpeed = 1.0;
1135  double injectionSpeed = .2;
1136 
1137 
1138  int INIT_ACOUSTIC_PULSE = 1;
1139  int INIT_CROSSFLOW = 2;
1140  int INIT_CROSSFLOW_PROFILE = 4;
1141  int INIT_INJECTION_FLOW = 8;
1142  int INIT_INJECTION_PROFILE = 16;
1143  int INIT_MASS_GLOB = 32;
1144 
1145  int numParams = inParams.size();
1146  if(numParams > 0)
1147  pulseAmp = inParams[0];
1148  if(numParams > 1)
1149  pulseWidth = inParams[1];
1150  if(numParams > 2)
1151  pulseRadius = inParams[2];
1152  if(numParams > 3)
1153  centerX = inParams[3];
1154  if(numParams > 4)
1155  centerY = inParams[4];
1156  if(numParams > 5)
1157  crossFlowSpeed = inParams[5];
1158  if(numParams > 6)
1159  injectionSpeed = inParams[6];
1160 
1161  int optionBits = 7;
1162  if(!inFlags.empty()){
1163  optionBits = inFlags[0];
1164  }
1165 
1166  size_t numPointsBuffer = inGrid.BufferSize();
1167  const std::vector<size_t> &gridSizes(inGrid.GridSizes());
1168  const pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
1169  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
1170  const std::vector<simulation::grid::subregion> &gridSubRegions(inGrid.SubRegions());
1171  const std::vector<double> &dX(inGrid.DX());
1172  const std::vector<size_t> &bufferSizes(inGrid.BufferSizes());
1173 
1174 
1175 
1177  bufferInterval.InitSimple(bufferSizes);
1178 
1179 
1180  pcpp::IndexIntervalType gridInterval;
1181  gridInterval.InitSimple(gridSizes);
1182 
1183  std::ostringstream messageStream;
1184  fixtures::CommunicatorType &gridComm(inGrid.Communicator());
1185 
1186  messageStream << "ProtoY4Test1: Grid Sizes: (";
1187  pcpp::io::DumpContents(messageStream,gridSizes,",");
1188  messageStream << ")" << std::endl
1189  << "ProtoY4Test1: Partition Interval: ";
1190  partitionInterval.PrettyPrint(messageStream);
1191  messageStream << std::endl << "ProtoY4Test1: Partition Buffer Interval: ";
1192  partitionBufferInterval.PrettyPrint(messageStream);
1193  messageStream << std::endl;
1194 
1195  pcpp::io::Everyone(messageStream.str(),std::cout,gridComm);
1196  pcpp::io::RenewStream(messageStream);
1197 
1198  std::string pulseType;
1199  bool pulseOn = false;
1200  if(optionBits&INIT_ACOUSTIC_PULSE){
1201  pulseType = "Acoustic";
1202  pulseOn = true;
1203  }
1204  if(optionBits&INIT_MASS_GLOB){
1205  pulseType += "Mass";
1206  pulseOn = true;
1207  }
1208 
1209  if(!pulseType.empty()){
1210  messageStream << "ProtoY4Test1: " << pulseType << " pulse amplitude: "
1211  << pulseAmp << std::endl
1212  << "ProtoY4Test1: "
1213  << pulseType << " pulse width: "
1214  << pulseWidth << std::endl
1215  << "ProtoY4Test1: Relative pulse centerX: " << centerX << std::endl
1216  << "ProtoY4Test1: Pulse CenterY: " << centerY << std::endl;
1217  } else {
1218  messageStream << "ProtoY4Test1: No pulse configured." << std::endl;
1219  }
1220  if(optionBits&INIT_CROSSFLOW){
1221  messageStream << "ProtoY4Test1: CrossFlowSpeed: " << crossFlowSpeed << std::endl;
1222  if(optionBits&INIT_CROSSFLOW_PROFILE)
1223  messageStream << "ProtoY4Test1: Crossflow profile enabled." << std::endl;
1224  }
1225  if(optionBits&INIT_INJECTION_FLOW){
1226  messageStream << "ProtoY4Test1: InjectionSpeed: " << injectionSpeed << std::endl;
1227  if(optionBits&INIT_INJECTION_PROFILE)
1228  messageStream << "ProtoY4Test1: Injection flow profile enabled." << std::endl;
1229  }
1230 
1231  if(gridComm.Rank() == 0)
1232  std::cout << messageStream.str();
1233  pcpp::io::RenewStream(messageStream);
1234 
1235  const std::vector<double> &coordinateData(inGrid.CoordinateData());
1236 
1237  int rhoHandle = inState.GetDataIndex("rho");
1238  if(rhoHandle < 0)
1239  return(1);
1240  pcpp::field::dataset::DataBufferType &rhoData(inState.Field(rhoHandle));
1241  double *rhoPtr = rhoData.Data<double>();
1242  if(!rhoPtr)
1243  return(1);
1244 
1245  int rhoVHandle = inState.GetDataIndex("rhoV");
1246  if(rhoVHandle < 0)
1247  return(1);
1248  pcpp::field::dataset::DataBufferType &rhoVData(inState.Field(rhoVHandle));
1249  double *rhoVPtr = rhoVData.Data<double>();
1250  if(!rhoVPtr)
1251  return(1);
1252 
1253  int rhoEHandle = inState.GetDataIndex("rhoE");
1254  if(rhoEHandle < 0)
1255  return(1);
1256  pcpp::field::dataset::DataBufferType &rhoEData(inState.Field(rhoEHandle));
1257  double *rhoEPtr = rhoEData.Data<double>();
1258  if(!rhoPtr)
1259  return(1);
1260 
1261  double *gammaPtr = inParamState.template GetFieldBuffer<double>("gamma");
1262  double *lengthRefPtr = inParamState.template GetFieldBuffer<double>("refLength");
1263  double *rhoRefPtr = inParamState.template GetFieldBuffer<double>("refRho");
1264  double *presRefPtr = inParamState.template GetFieldBuffer<double>("refPressure");
1265  double *tempRefPtr = inParamState.template GetFieldBuffer<double>("refTemperature");
1266  double *rePtr = inParamState.template GetFieldBuffer<double>("refRe");
1267  double *prPtr = inParamState.template GetFieldBuffer<double>("refPr");
1268  int *nonDimenPtr = inParamState.template GetFieldBuffer<int>("nonDimensional");
1269 
1270  double gamma = *gammaPtr;
1271  double refLength = *lengthRefPtr;
1272  double refRho = *rhoRefPtr;
1273  double refPressure = *presRefPtr;
1274  double refTemperature = *tempRefPtr;
1275  double sndSpdRef = sqrt(gamma*refPressure/refRho);
1276  double velRef = sqrt(refPressure/refRho);
1277  if(*nonDimenPtr == 2){
1278  velRef = sndSpdRef;
1279  refTemperature *= (gamma-1);
1280  }
1281 
1282  double testSectionP = 7176.9492187500000;
1283  double testSectionT = 121.23677825927734;
1284  double testSectionRho = 0.22785909473896027;
1285  double testSectionVel = 566.97581634521487; // for mach 2.7
1286 
1287  double portP = 204233.73437500000;
1288  double portT = 248.33332824707031;
1289  double portRho = 3.1655802726745605;
1290  double portVel = 300.53918457031250; // for mach 1.0
1291 
1292  double transitionWidth = 20.0*dX[0];
1293 
1294 
1295  // Must have one of these for ProtoY4 configuration
1296  int combustionChamberIndex = inGrid.GetRegionIndex("ChamberBottom");
1297  if(combustionChamberIndex < 0)
1298  combustionChamberIndex = inGrid.GetRegionIndex("Bottom");
1299  if(combustionChamberIndex < 0)
1300  return(1);
1301 
1302  const simulation::grid::subregion &combustionChamberRegion(gridSubRegions[combustionChamberIndex]);
1303  const pcpp::IndexIntervalType &chamberInterval(combustionChamberRegion.regionInterval);
1304  pcpp::IndexIntervalType combustionChamberInterval(chamberInterval);
1305  // Augment the boundary extent to create an extent that covers the
1306  // entire test section.
1307  combustionChamberInterval[1].first = gridInterval[1].first;
1308  combustionChamberInterval[1].second = gridInterval[1].second;
1309 
1310  pcpp::IndexIntervalType chamberPartitionInterval;
1311  partitionInterval.Overlap(combustionChamberInterval,chamberPartitionInterval);
1312 
1313  if(chamberPartitionInterval.NNodes() > 0){ // Points in the chamber
1314 
1315  pcpp::IndexIntervalType chamberBufferInterval;
1316  chamberPartitionInterval.RelativeTranslation(partitionInterval,
1317  partitionBufferInterval,
1318  chamberBufferInterval);
1319 
1320  double windowWidth = 5; // leave this many grid spacings on the edge
1321 
1322  double chamberStartX = combustionChamberInterval[0].first * dX[0];
1323  double chamberEndX = combustionChamberInterval[0].second * dX[0];
1324  double chamberWidth = chamberEndX - chamberStartX;
1325  double chamberHalf = chamberWidth/2.0;
1326  double chamberCenter = chamberStartX + chamberHalf;
1327  double pulseWindowX1 = chamberStartX + windowWidth*dX[0];
1328  double pulseWindowX2 = chamberEndX - windowWidth*dX[0];
1329 
1330  std::cout << "TestSection X := [" << chamberStartX << ","
1331  << chamberEndX << "]" << std::endl;
1332  // these only matter for test pulse
1333  centerX *= chamberWidth;
1334  centerX += chamberStartX;
1335  centerX = .000025;
1336 
1337  double pulseWindowWidth = (centerX - pulseWindowX1);
1338  double pulseWindowY1 = centerY - pulseWindowWidth/2.0;
1339  double pulseWindowY2 = centerY + pulseWindowWidth/2.0;
1340 
1341  double profileX1 = chamberStartX + windowWidth*dX[0];
1342  double profileX2 = chamberEndX - windowWidth*dX[0];
1343  double profileWidth = (profileX2 - profileX1)/2.0;
1344 
1345  messageStream << "ProtoY4Test1: Found combustion chamber interval: ";
1346  combustionChamberInterval.PrettyPrint(messageStream);
1347  messageStream << ",(" << chamberStartX << "," << chamberEndX << ")"
1348  << std::endl
1349  << "ProtoY4Test1: My combustion chamber interval: ";
1350  chamberPartitionInterval.PrettyPrint(messageStream);
1351  messageStream << std::endl;
1352  if(pulseOn){
1353  messageStream << "ProtoY4Test1: Pulse location = (" << centerX << ","
1354  << centerY << ")" << std::endl;
1355  messageStream << "ProtoY4Test1: Pulse window width = " << pulseWindowWidth
1356  << std::endl;
1357  }
1358 
1359  pcpp::io::RenewStream(messageStream);
1360 
1361  std::vector<size_t> chamberNodes;
1362  bufferInterval.GetFlatIndices(chamberBufferInterval,chamberNodes);
1363 
1364  std::vector<size_t>::iterator nodeIt = chamberNodes.begin();
1365  while(nodeIt != chamberNodes.end()){
1366 
1367  size_t bufferNodeId = *nodeIt++;
1368  size_t yBufferIndex = bufferNodeId + numPointsBuffer;
1369  double x = coordinateData[bufferNodeId];
1370  double y = coordinateData[bufferNodeId+numPointsBuffer];
1371  double xDist = (x - centerX);
1372  double yDist = (y - centerY);
1373  double radDist = std::sqrt(xDist*xDist + yDist*yDist);
1374  double pulseWeight = Pulse(pulseAmp,pulseWidth,centerX,centerY,0,x,y,0);
1375  //double velocityProfile =
1376  // Parabola(-1.0/(chamberHalf*chamberHalf),chamberCenter,0,0,x,0,0) + 1.0;
1377  double velocityProfile = Window(transitionWidth,profileWidth,chamberCenter,0,0,x,0,0);
1378  double pulseProfile = Window(transitionWidth,pulseWindowWidth,centerX,centerY,0,x,y,0);
1379 
1380 
1381  if(!(optionBits&INIT_CROSSFLOW_PROFILE))
1382  velocityProfile = 1.0;
1383  if(radDist > pulseRadius)
1384  pulseWeight = 0.0;
1385 
1386  rhoPtr[bufferNodeId] = testSectionRho/refRho;
1387 
1388  if(optionBits&INIT_MASS_GLOB)
1389  rhoPtr[bufferNodeId] *= (1.0 + pulseWeight);
1390 
1391  rhoVPtr[bufferNodeId] = 0.0;
1392 
1393  if(optionBits&INIT_CROSSFLOW){
1394  rhoVPtr[yBufferIndex] = rhoPtr[bufferNodeId]*testSectionVel*velocityProfile/velRef;
1395  }
1396 
1397  rhoEPtr[bufferNodeId] = rhoPtr[bufferNodeId]*testSectionT/refTemperature/gamma +
1398  0.5*rhoVPtr[yBufferIndex]*rhoVPtr[yBufferIndex]/rhoPtr[bufferNodeId];
1399 
1400  if(optionBits&INIT_ACOUSTIC_PULSE)
1401  rhoEPtr[bufferNodeId] *= (1.0 + pulseWeight*pulseProfile);
1402 
1403  }
1404  }
1405 
1406 
1407  int portIndex = inGrid.GetRegionIndex("Port");
1408  if(portIndex >= 0){
1409 
1410  const simulation::grid::subregion &portRegion(gridSubRegions[portIndex]);
1411  const pcpp::IndexIntervalType &portInterval(portRegion.regionInterval);
1412 
1413  pcpp::IndexIntervalType myPortInterval;
1414  partitionInterval.Overlap(portInterval,myPortInterval);
1415 
1416  if(myPortInterval.NNodes() > 0){
1417 
1418  double portStartY = portInterval[1].first * dX[1];
1419  double portEndY = portInterval[1].second * dX[1];
1420  double portWidth = portEndY - portStartY;
1421  double portHalf = portWidth/2.0;
1422  double portCenter = portStartY + portHalf;
1423 
1424  messageStream << "ProtoY4Test1: Initializing Port..." << std::endl
1425  << "ProtoY4Test1: Port Interval: ";
1426  portInterval.PrettyPrint(messageStream);
1427  messageStream << ", Y = [" << portStartY << "," << portEndY << "]" << std::endl;
1428 
1429  pcpp::IndexIntervalType portBufferInterval;
1430  myPortInterval.RelativeTranslation(partitionInterval,
1431  partitionBufferInterval,
1432  portBufferInterval);
1433  std::vector<size_t> portNodes;
1434  bufferInterval.GetFlatIndices(portBufferInterval,portNodes);
1435 
1436  std::vector<size_t>::iterator nodeIt = portNodes.begin();
1437  while(nodeIt != portNodes.end()){
1438 
1439 
1440  size_t bufferNodeId = *nodeIt++;
1441  double y = coordinateData[bufferNodeId+numPointsBuffer];
1442  // double injectionProfile =
1443  // Parabola(-1.0/(portHalf*portHalf),0,portCenter,0,0,y,0) + 1.0;
1444  double injectionProfile = std::tanh(10000.0*(y - portStartY)) -
1445  std::tanh(10000.0*(y-portEndY)) - 1.0;
1446 
1447  rhoPtr[bufferNodeId] = portRho/refRho;
1448  rhoVPtr[bufferNodeId+numPointsBuffer] = 0.0;
1449 
1450  if(!(optionBits&INIT_INJECTION_PROFILE))
1451  injectionProfile = 1.0;
1452 
1453  rhoVPtr[bufferNodeId] = rhoPtr[bufferNodeId]*portVel/velRef*injectionProfile;
1454 
1455  rhoEPtr[bufferNodeId] = rhoPtr[bufferNodeId]*portT/refTemperature/gamma +
1456  0.5*(rhoVPtr[bufferNodeId]*rhoVPtr[bufferNodeId])/rhoPtr[bufferNodeId];
1457  }
1458  }
1459 
1460  // Initialize the plug of gas between the port and the test section
1461  int plugTopId = inGrid.GetRegionIndex("PortWallTop");
1462  if(plugTopId < 0){
1463  std::cout << "ProtoY4Init:Error: Failed to find required boundary [PortWallTop]. Aborting." << std::endl;
1464  return(1);
1465  }
1466 
1467  // First, find out if local process owns part of the plug - this procedure
1468  // is used a lot. Could be a utility.
1470  const simulation::grid::subregion &portTopRegion(gridSubRegions[plugTopId]);
1471  const pcpp::IndexIntervalType &portTopInterval(portTopRegion.regionInterval);
1472  pcpp::IndexIntervalType plugInterval(portInterval);
1473  plugInterval[0].second = portTopInterval[0].second;
1474  plugInterval[0].first++;
1475  pcpp::IndexIntervalType myPlugInterval;
1476  partitionInterval.Overlap(plugInterval,myPlugInterval);
1477 
1478  if(myPlugInterval.NNodes() > 0){
1479 
1480  pcpp::IndexIntervalType plugBufferInterval;
1481  myPlugInterval.RelativeTranslation(partitionInterval,
1482  partitionBufferInterval,
1483  plugBufferInterval);
1484  std::vector<size_t> plugNodes;
1485  bufferInterval.GetFlatIndices(plugBufferInterval,plugNodes);
1486 
1487  std::vector<size_t>::iterator plugNodeIt = plugNodes.begin();
1488  while(plugNodeIt != plugNodes.end()){
1489  size_t bufferIndex = *plugNodeIt++;
1490 
1491  rhoPtr[bufferIndex] = testSectionRho/refRho;
1492  rhoVPtr[bufferIndex] = 0.0;
1493  rhoVPtr[bufferIndex+numPointsBuffer] = 0.0;
1494  rhoEPtr[bufferIndex] = rhoPtr[bufferIndex]*testSectionT/refTemperature/gamma;
1495 
1496  }
1497  } // initialize plug
1498  } // domain has a port (if not, hrm?)
1499 
1500  return(0);
1501  };
1502 
1503 
1504 
1506  template<typename GridType,typename StateType>
1507  int InitializeConvectingVortex(const GridType &inGrid,StateType &inState,
1508  StateType &inParam,
1509  const std::vector<double> &inParams,
1510  const std::vector<int> &inFlags,int threadId)
1511  {
1512 
1513  double vortexStrength = 0.01;
1514  double vortexWidth = 0.01;
1515  double vortexCenterX = 0.5;
1516  double vortexCenterY = 0.5;
1517  double crossFlowX = 0.5;
1518  double crossFlowY = 0.0;
1519 
1520 
1521  int INIT_VORTEX = 1;
1522  int INIT_CROSSFLOW = 2;
1523  int INIT_CROSSFLOW_PROFILE = 4;
1524 
1525  std::ostringstream messageStream;
1526  int numParams = inParams.size();
1527  if(numParams > 0)
1528  vortexStrength = inParams[0];
1529  if(numParams > 1)
1530  vortexWidth = inParams[1];
1531  if(numParams > 2)
1532  vortexCenterX = inParams[2];
1533  if(numParams > 3)
1534  vortexCenterY = inParams[3];
1535  if(numParams > 4)
1536  crossFlowX = inParams[4];
1537  if(numParams > 5)
1538  crossFlowY = inParams[5];
1539 
1540  int optionBits = 7;
1541  if(!inFlags.empty()){
1542  optionBits = inFlags[0];
1543  }
1544 
1545  messageStream << "VortexInit: vortexStrength = " << vortexStrength << std::endl
1546  << "VortexInit: vortexWidth = " << vortexWidth << std::endl
1547  << "VortexInit: vortexCenterX = " << vortexCenterX << std::endl
1548  << "VortexInit: vortexCenterY = " << vortexCenterY << std::endl
1549  << "VortexInit: crossFlowX = " << crossFlowX << std::endl
1550  << "VortexInit: crossFlowY = " << crossFlowY << std::endl
1551  << "VortexInit: VORTEX is " << (optionBits&INIT_VORTEX ? "ON" : "OFF") << std::endl
1552  << "VortexInit: CROSSFLOW is " << (optionBits&INIT_CROSSFLOW ? "ON" : "OFF") << std::endl
1553  << "VortexInit: INJECTION PROFILE is " << (optionBits&INIT_CROSSFLOW_PROFILE ? "ON" : "OFF")
1554  << std::endl;
1555 
1556  size_t numPointsBuffer = inGrid.BufferSize();
1557  const std::vector<size_t> &gridSizes(inGrid.GridSizes());
1558  const pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
1559  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
1560  const std::vector<simulation::grid::subregion> &gridSubRegions(inGrid.SubRegions());
1561  const std::vector<double> &dX(inGrid.DX());
1562  const std::vector<double> &gridCoordinates(inGrid.CoordinateData());
1563  double rho = 1.0;
1564 
1565  int rhoHandle = inState.GetDataIndex("rho");
1566  if(rhoHandle < 0)
1567  return(1);
1568  pcpp::field::dataset::DataBufferType &rhoData(inState.Field(rhoHandle));
1569  double *rhoPtr = rhoData.Data<double>();
1570  if(!rhoPtr)
1571  return(1);
1572 
1573  int rhoVHandle = inState.GetDataIndex("rhoV");
1574  if(rhoVHandle < 0)
1575  return(1);
1576  pcpp::field::dataset::DataBufferType &rhoVData(inState.Field(rhoVHandle));
1577  double *rhoVPtr = rhoVData.Data<double>();
1578  if(!rhoVPtr)
1579  return(1);
1580 
1581  int rhoEHandle = inState.GetDataIndex("rhoE");
1582  if(rhoEHandle < 0)
1583  return(1);
1584  pcpp::field::dataset::DataBufferType &rhoEData(inState.Field(rhoEHandle));
1585  double *rhoEPtr = rhoEData.Data<double>();
1586  if(!rhoPtr)
1587  return(1);
1588 
1589  double L2M1 = 1.0/(vortexWidth*vortexWidth);
1590  double gamma = 1.4;
1591 
1592 
1593  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++){
1594  size_t yIndex = numPointsBuffer + iPoint;
1595  double x = gridCoordinates[iPoint];
1596  double y = gridCoordinates[yIndex];
1597  double r2L = L2M1*((x-vortexCenterX)*(x-vortexCenterX)
1598  + (y-vortexCenterY)*(y-vortexCenterY));
1599  double eFac = std::exp(.5*(1.0-r2L));
1600  double vortexVx = -1.0*vortexStrength*(y-vortexCenterY)*eFac;
1601  double vortexVy = vortexStrength*(x-vortexCenterX)*eFac;
1602 
1603  if(optionBits&INIT_CROSSFLOW){
1604  vortexVx += crossFlowX;
1605  vortexVy += crossFlowY;
1606  }
1607 
1608 
1609  double vortexP = (1.0-0.5*(gamma-1.0)*vortexStrength*vortexStrength*eFac*eFac);
1610  vortexP = std::pow(vortexP,gamma/(gamma-1.0));
1611  vortexP *= (1.0/gamma);
1612  double vortexRho = gamma*vortexP;
1613  vortexRho = std::pow(vortexRho,(1.0/gamma));
1614 
1615 
1616  if(!(optionBits&INIT_VORTEX)){
1617  vortexRho = 1.0;
1618  vortexVx = 0.0;
1619  vortexVy = 0.0;
1620  vortexP = 1.0;
1621  }
1622 
1623  rhoPtr[iPoint] = vortexRho;
1624  rhoVPtr[iPoint] = vortexRho*vortexVx;
1625  rhoVPtr[yIndex] = vortexRho*vortexVy;
1626  rhoEPtr[iPoint] = vortexP/(gamma-1.0)
1627  + 0.5*vortexRho*(vortexVx*vortexVx+vortexVy*vortexVy);
1628  }
1629 
1630  return(0);
1631  }
1632 
1634  template<typename GridType,typename StateType>
1635  int InitializeAcousticPulse(const GridType &inGrid,StateType &inState,
1636  StateType &inParam,const std::vector<double> &inParams,
1637  const std::vector<int> &inFlags,int threadId,
1638  std::ostream *messageStream)
1639  {
1640 
1641  if(!messageStream)
1642  messageStream = &std::cout;
1643 
1644  double pulseAmp = 0.01;
1645  double pulseWidth = 0.000001;
1646  double pulseRadius = 100.0;
1647  double relCenterX = 0.5;
1648  double relCenterY = 0.5;
1649  double relCenterZ = 0.5;
1650  double crossFlowSpeed = 0.0;
1651  double injectionSpeed = 0.0;
1652 
1653 
1654  int INIT_CROSSFLOW = 1;
1655  int INIT_CROSSFLOW_PROFILE = 2;
1656 
1657 
1658  int numParams = inParams.size();
1659  if(numParams > 0)
1660  pulseAmp = inParams[0];
1661  if(numParams > 1)
1662  pulseWidth = inParams[1];
1663  if(numParams > 2)
1664  pulseRadius = inParams[2];
1665  if(numParams > 3)
1666  relCenterX = inParams[3];
1667  if(numParams > 4)
1668  relCenterY = inParams[4];
1669  if(numParams > 5)
1670  relCenterZ = inParams[5];
1671  if(numParams > 6)
1672  crossFlowSpeed = inParams[6];
1673 
1674  int optionBits = 0;
1675  if(!inFlags.empty()){
1676  optionBits = inFlags[0];
1677  }
1678 
1679  size_t numPointsBuffer = inGrid.BufferSize();
1680  const std::vector<size_t> &bufferSizes(inGrid.BufferSizes());
1681  const std::vector<size_t> &gridSizes(inGrid.GridSizes());
1682  const pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
1683  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
1684  const std::vector<simulation::grid::subregion> &gridSubRegions(inGrid.SubRegions());
1685  const std::vector<double> &dX(inGrid.DX());
1686  const std::vector<double> &coordinateData(inGrid.CoordinateData());
1687  const std::vector<double> &physicalExtent(inGrid.PhysicalExtent());
1688  int numDim = gridSizes.size();
1689  if(dX.size() != numDim){
1690  *messageStream << "AcousticPulse:Error: Grid not initialized."
1691  << std::endl;
1692  return(1);
1693  }
1694 
1695  pcpp::IndexIntervalType gridInterval;
1696  gridInterval.InitSimple(gridSizes);
1697 
1698  std::vector<double> pulseCenter(3,0);
1699  pulseCenter[0] = relCenterX;
1700  pulseCenter[1] = relCenterY;
1701  pulseCenter[2] = relCenterZ;
1702  for(int iDim = 0;iDim < numDim;iDim++){
1703  pulseCenter[iDim] *= (physicalExtent[iDim*2+1] - physicalExtent[iDim*2]);
1704  pulseCenter[iDim] += physicalExtent[iDim*2];
1705  }
1706  if(numDim < 3)
1707  pulseCenter[2] = 0.0;
1708  if(numDim < 2)
1709  pulseCenter[1] = 0.0;
1710 
1711 
1712  *messageStream << "AcousticPulse: Grid Sizes: (";
1713  pcpp::io::DumpContents(*messageStream,gridSizes,",");
1714  *messageStream << ")" << std::endl
1715  << "AcousticPulse: Partition Interval: ";
1716  partitionInterval.PrettyPrint(*messageStream);
1717  *messageStream << std::endl << "AcousticPulse: Partition Buffer Interval: ";
1718  partitionBufferInterval.PrettyPrint(*messageStream);
1719  *messageStream << std::endl;
1720 
1721  *messageStream << "AcousticPulse: Amplitude: "
1722  << pulseAmp << std::endl
1723  << "AcousticPulse: Width: "
1724  << pulseWidth << std::endl
1725  << "AcousticPulse: Relative center: (" << relCenterX
1726  << "," << relCenterY << "," << relCenterZ << ")" << std::endl
1727  << "AcousticPulse: Center: (" << pulseCenter[0] << ","
1728  << pulseCenter[1] << "," << pulseCenter[2] << ")" << std::endl;
1729  if(optionBits&INIT_CROSSFLOW){
1730  *messageStream << "AcousticPulse: CrossFlowSpeed: " << crossFlowSpeed << std::endl;
1731  if(optionBits&INIT_CROSSFLOW_PROFILE)
1732  *messageStream << "AcousticPulse: Crossflow profile enabled." << std::endl;
1733  }
1734 
1735  double *gammaPtr = inParam.template GetFieldBuffer<double>("gamma");
1736  double gammaValue = *gammaPtr;
1737 
1738 
1739  int rhoHandle = inState.GetDataIndex("rho");
1740  if(rhoHandle < 0)
1741  return(1);
1742  pcpp::field::dataset::DataBufferType &rhoData(inState.Field(rhoHandle));
1743  double *rhoPtr = rhoData.Data<double>();
1744  if(!rhoPtr)
1745  return(1);
1746 
1747  int rhoVHandle = inState.GetDataIndex("rhoV");
1748  if(rhoVHandle < 0)
1749  return(1);
1750  pcpp::field::dataset::DataBufferType &rhoVData(inState.Field(rhoVHandle));
1751  double *rhoVPtr = rhoVData.Data<double>();
1752  if(!rhoVPtr)
1753  return(1);
1754 
1755  int rhoEHandle = inState.GetDataIndex("rhoE");
1756  if(rhoEHandle < 0)
1757  return(1);
1758  pcpp::field::dataset::DataBufferType &rhoEData(inState.Field(rhoEHandle));
1759  double *rhoEPtr = rhoEData.Data<double>();
1760  if(!rhoPtr)
1761  return(1);
1762 
1763 
1764  // Zero entire buffer(s)
1765  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++){
1766  rhoPtr[iPoint] = 0.0;
1767  rhoEPtr[iPoint] = 0.0;
1768  }
1769  for(int iDim = 0;iDim < numDim;iDim++){
1770  size_t dimOffset = iDim*numPointsBuffer;
1771  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++)
1772  rhoVPtr[iPoint+dimOffset] = 0.0;
1773  }
1774 
1775 
1776  std::vector<double> velocity(numDim,0.0); // really just velocity at this point
1777  // Comment next line for quiescent, uncomment for constant flow
1778  velocity[0] = crossFlowSpeed;
1779 
1780  if(numDim == 3){
1781  size_t iStart = partitionBufferInterval[0].first;
1782  size_t iEnd = partitionBufferInterval[0].second;
1783  size_t jStart = partitionBufferInterval[1].first;
1784  size_t jEnd = partitionBufferInterval[1].second;
1785  size_t kStart = partitionBufferInterval[2].first;
1786  size_t kEnd = partitionBufferInterval[2].second;
1787  size_t nPlane = bufferSizes[0]*bufferSizes[1];
1788  for(size_t kIndex = kStart;kIndex <= kEnd;kIndex++){
1789  size_t kBufferIndex = kIndex*nPlane;
1790  size_t kPartIndex = (kIndex - kStart) + partitionInterval[2].first;
1791  for(size_t jIndex = jStart;jIndex <= jEnd;jIndex++){
1792  size_t jkBufferIndex = kBufferIndex + jIndex*bufferSizes[0];
1793  size_t jPartIndex = (jIndex - jStart) + partitionInterval[1].first;
1794  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
1795  size_t bufferIndex = jkBufferIndex + iIndex;
1796  size_t iPartIndex = (iIndex - iStart) + partitionInterval[0].first;
1797  double x = coordinateData[bufferIndex];
1798  double y = coordinateData[numPointsBuffer+bufferIndex];
1799  double z = coordinateData[2*numPointsBuffer+bufferIndex];
1800  double xRad = x - pulseCenter[0];
1801  double yRad = y - pulseCenter[1];
1802  double zRad = z - pulseCenter[2];
1803  double xyzRad = std::sqrt(xRad*xRad+yRad*yRad+zRad*zRad);
1804 
1805  rhoPtr[bufferIndex] = 1.0;
1806  rhoVPtr[bufferIndex] = rhoPtr[bufferIndex]*velocity[0];
1807  rhoVPtr[bufferIndex+numPointsBuffer] = rhoPtr[bufferIndex]*velocity[1];
1808  rhoVPtr[bufferIndex+2*numPointsBuffer] = rhoPtr[bufferIndex]*velocity[2];
1809  rhoEPtr[bufferIndex] = (1.0+Pulse(pulseAmp,pulseWidth,
1810  pulseCenter[0],pulseCenter[1],pulseCenter[2],x,y,z))/(gammaValue-1.0);
1811  rhoEPtr[bufferIndex] +=
1812  (rhoVPtr[bufferIndex]*rhoVPtr[bufferIndex] +
1813  rhoVPtr[bufferIndex+numPointsBuffer]*rhoVPtr[bufferIndex+numPointsBuffer] +
1814  rhoVPtr[bufferIndex+2*numPointsBuffer]*rhoVPtr[bufferIndex+2*numPointsBuffer])/
1815  (2.0*rhoPtr[bufferIndex]);
1816  }
1817  }
1818  }
1819  } else if (numDim == 2) {
1820  size_t iStart = partitionBufferInterval[0].first;
1821  size_t iEnd = partitionBufferInterval[0].second;
1822  size_t jStart = partitionBufferInterval[1].first;
1823  size_t jEnd = partitionBufferInterval[1].second;
1824  for(size_t jIndex = jStart;jIndex <= jEnd;jIndex++){
1825  size_t jBufferIndex = jIndex*bufferSizes[0];
1826  size_t jPartIndex = (jIndex - jStart)+partitionInterval[1].first;
1827  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
1828  size_t bufferIndex = jBufferIndex + iIndex;
1829  size_t iPartIndex = (iIndex - iStart)+partitionInterval[0].first;
1830  double x = coordinateData[bufferIndex];
1831  double y = coordinateData[numPointsBuffer+bufferIndex];
1832  double xRad = x - pulseCenter[0];
1833  double yRad = y - pulseCenter[1];
1834  double xyzRad = std::sqrt(xRad*xRad+yRad*yRad);
1835  rhoPtr[bufferIndex] = 1.0;
1836  rhoVPtr[bufferIndex] = rhoPtr[bufferIndex]*velocity[0];
1837  rhoVPtr[bufferIndex+numPointsBuffer] = rhoPtr[bufferIndex]*velocity[1];
1838  rhoEPtr[bufferIndex] = rhoPtr[bufferIndex]*((1.0/(gammaValue*(gammaValue-1.0))) +
1839  .5*(velocity[0]*velocity[0] + velocity[1]*velocity[1]));
1840  rhoEPtr[bufferIndex] = (1.0 + Pulse(pulseAmp,pulseWidth,
1841  pulseCenter[0],pulseCenter[1],.5,x,y,.5))/(gammaValue-1.0);
1842  rhoEPtr[bufferIndex] +=
1843  (rhoVPtr[bufferIndex]*rhoVPtr[bufferIndex] +
1844  rhoVPtr[bufferIndex+numPointsBuffer]*rhoVPtr[bufferIndex+numPointsBuffer])/
1845  (2.0*rhoPtr[bufferIndex]);
1846 
1847  }
1848  }
1849  } else if (numDim == 1) {
1850  size_t iStart = partitionBufferInterval[0].first;
1851  size_t iEnd = partitionBufferInterval[0].second;
1852  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
1853  size_t iPartIndex = (iIndex - iStart)+partitionInterval[0].first;
1854  double x = coordinateData[iIndex];
1855  double xRad = x - pulseCenter[0];
1856  double xyzRad = std::sqrt(xRad*xRad);
1857  rhoPtr[iIndex] = 1.0;
1858  rhoVPtr[iIndex] = rhoPtr[iIndex]*velocity[0];
1859  rhoEPtr[iIndex] = (1.0 + Pulse(pulseAmp,pulseWidth,pulseCenter[0],.5,.5,x,.5,.5))/(gammaValue-1.0);
1860  rhoEPtr[iIndex] += (rhoVPtr[iIndex]*rhoVPtr[iIndex])/(2.0*rhoPtr[iIndex]);
1861  }
1862  }
1863 
1864 
1865  return(0);
1866  };
1867 
1868  // initialization for scalar advection test problem
1869  template<typename GridType,typename StateType>
1870  int InitializeDensityPulse(const GridType &inGrid,StateType &inState, StateType &inParamState,
1871  const std::vector<double> &inParams,int threadId,
1872  std::ostream *messageStream = NULL)
1873  {
1874 
1875  if(!messageStream)
1876  messageStream = &std::cout;
1877 
1878  *messageStream << "Starting Density Pulse Flow Initialization" << std::endl;
1879 
1880  size_t numPointsBuffer = inGrid.BufferSize();
1881  const std::vector<size_t> &gridSizes(inGrid.GridSizes());
1882  const std::vector<size_t> &bufferSizes(inGrid.BufferSizes());
1883  const pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
1884  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
1885  int numDim = gridSizes.size();
1886  const std::vector<double> &dX(inGrid.DX());
1887  const std::vector<double> &readGridExtent(inGrid.PhysicalExtent());
1888 
1889  // first 2 parameters are pulse amplitude and width
1890  // force the user to supply an additional 4 or 6 parameters in 2 or 3D to fully
1891  // define the problem
1892  int numParams = inParams.size();
1893  std::vector<double> position(3,0.0); // initial position
1894  std::vector<double> velocity(3,0.0); // initial velocity
1895  double pulseAmp=1.0;
1896  double pulseWidth=1.0;
1897 
1898  if(numParams < 2){
1899  *messageStream << "Invalid number of parameters, user must"
1900  << "specify an x location and u velocity " << std::endl;
1901  return(1);
1902  } else {
1903  pulseAmp = inParams[0];
1904  pulseWidth = inParams[1];
1905  }
1906 
1907  int locationInd = 2;
1908  int velocityInd = locationInd+numDim;
1909 
1910  if(numDim == 1) {
1911  if(numParams == 4){
1912  position[0] = inParams[locationInd];
1913  velocity[0] = inParams[velocityInd];
1914  } else {
1915  *messageStream << "Invalid number of parameters, user must"
1916  << "specify an x location and u velocity " << std::endl;
1917  return(1);
1918  }
1919  } else if(numDim == 2) {
1920  if(numParams == 6){
1921  position[0] = inParams[locationInd];
1922  position[1] = inParams[locationInd+1];
1923  velocity[0] = inParams[velocityInd];
1924  velocity[1] = inParams[velocityInd+1];
1925  } else {
1926  *messageStream << "Invalid number of parameters, user must"
1927  << "specify an <x,y> location and <u,v> velocity " << std::endl;
1928  return(1);
1929  }
1930  } else if(numDim == 3) {
1931  if(numParams == 8){
1932  position[0] = inParams[locationInd+0];
1933  position[1] = inParams[locationInd+1];
1934  position[2] = inParams[locationInd+2];
1935  velocity[0] = inParams[velocityInd];
1936  velocity[1] = inParams[velocityInd+1];
1937  velocity[2] = inParams[velocityInd+2];
1938  } else {
1939  *messageStream << "Invalid number of parameters, user must"
1940  << "specify an <x,y> location and <u,v> velocity " << std::endl;
1941  return(1);
1942  }
1943  }
1944 
1945  // check on dimensionality
1946  int nonDimensionalMode=0;
1947  {
1948  int paramHandle = inParamState.GetDataIndex("nonDimensional");
1949  if(paramHandle >= 0){
1950  const pcpp::field::dataset::DataBufferType &paramData(inParamState.Field(paramHandle));
1951  const int *paramPtr = paramData.Data<int>();
1952  nonDimensionalMode = *paramPtr;
1953  } else {
1954  nonDimensionalMode = 0;
1955  }
1956  }
1957 
1958  // get reference conditions
1959  double *gammaPtr = inParamState.template GetFieldBuffer<double>("gamma");
1960  double *rhoRefPtr = inParamState.template GetFieldBuffer<double>("refRho");
1961  double *refLengthPtr = inParamState.template GetFieldBuffer<double>("refLength");
1962  double *presRefPtr = inParamState.template GetFieldBuffer<double>("refPressure");
1963  double *tempRefPtr = inParamState.template GetFieldBuffer<double>("refTemperature");
1964 
1965  double gamma = *gammaPtr;
1966  double refLength = *refLengthPtr;
1967  double refRho = *rhoRefPtr;
1968  double refPressure = *presRefPtr;
1969  double refTemperature = *tempRefPtr;
1970  double sndSpdRef = sqrt(gamma*refPressure/refRho);
1971 
1972  pcpp::IndexIntervalType gridInterval;
1973  gridInterval.InitSimple(gridSizes);
1974 
1975  //*messageStream << "Grid Sizes: (";
1976  //pcpp::io::DumpContents(*messageStream,gridSizes,",");
1977  //*messageStream << ")" << std::endl
1978  //<< "Partition Interval: ";
1979  //partitionInterval.PrettyPrint(*messageStream);
1980  //*messageStream << std::endl << "Poiseulle: Partition Buffer Interval: ";
1981  //partitionBufferInterval.PrettyPrint(*messageStream);
1982  //*messageStream << std::endl;
1983  //*messageStream << "Poiseulle: pipe height " << height << std::endl;
1984  //if(numDim > 2)
1985  //*messageStream << "Poiseulle: pipe width " << width << std::endl;
1986  //*messageStream << "Poiseulle: pipe length " << length << std::endl;
1987 
1988  const std::vector<double> &coordinateData(inGrid.CoordinateData());
1989 
1990  int rhoHandle = inState.GetDataIndex("rho");
1991  if(rhoHandle < 0)
1992  return(1);
1993  pcpp::field::dataset::DataBufferType &rhoData(inState.Field(rhoHandle));
1994  double *rhoPtr = rhoData.Data<double>();
1995  if(!rhoPtr)
1996  return(1);
1997 
1998  int rhoVHandle = inState.GetDataIndex("rhoV");
1999  if(rhoVHandle < 0)
2000  return(1);
2001  pcpp::field::dataset::DataBufferType &rhoVData(inState.Field(rhoVHandle));
2002  double *rhoVPtr = rhoVData.Data<double>();
2003  if(!rhoVPtr)
2004  return(1);
2005 
2006  int rhoEHandle = inState.GetDataIndex("rhoE");
2007  if(rhoEHandle < 0)
2008  return(1);
2009  pcpp::field::dataset::DataBufferType &rhoEData(inState.Field(rhoEHandle));
2010  double *rhoEPtr = rhoEData.Data<double>();
2011  if(!rhoEPtr)
2012  return(1);
2013 
2014  // Zero entire buffer(s)
2015  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++){
2016  rhoPtr[iPoint] = 0.0;
2017  rhoEPtr[iPoint] = 0.0;
2018  }
2019  for(int iDim = 0;iDim < numDim;iDim++){
2020  size_t dimOffset = iDim*numPointsBuffer;
2021  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++)
2022  rhoVPtr[iPoint+dimOffset] = 0.0;
2023  }
2024 
2025  // flow conditions
2026  // working in dimensional units
2027  double rho = refRho;
2028  double pressure = refPressure;
2029  double temperature = refTemperature;
2030 
2031  if(nonDimensionalMode == 1){
2032  rho /= refRho;
2033  pressure /= refPressure;
2034  temperature /= refTemperature;
2035  } else if (nonDimensionalMode == 2) {
2036  rho /= refRho;
2037  pressure /= gamma*refPressure;
2038  temperature /= (gamma-1)*refTemperature;
2039  }
2040 
2041  double rhoE = pressure/(gamma-1)/rho;
2042 
2043  *messageStream << "Density Pulse: Initial state" << std::endl;
2044  *messageStream << "\t nonDimensional: " << nonDimensionalMode << std::endl;
2045  //*messageStream << "\t Reynolds Number: " << Re << std::endl;
2046  *messageStream << "\t rho: " << rho << std::endl;
2047  *messageStream << "\t pressure: " << pressure << std::endl;
2048  *messageStream << "\t temperature: " << temperature << std::endl;
2049  *messageStream << "\t rhoE: " << rhoE << std::endl;
2050  for(int iDim=0;iDim<numDim;iDim++){
2051  *messageStream << "\t position[" << iDim << "]: " << position[iDim] << std::endl;
2052  }
2053  for(int iDim=0;iDim<numDim;iDim++){
2054  *messageStream << "\t u[" << iDim << "]: " << velocity[iDim] << std::endl;
2055  }
2056 
2057  size_t iStart = partitionBufferInterval[0].first;
2058  size_t iEnd = partitionBufferInterval[0].second;
2059  size_t jStart = partitionBufferInterval[1].first;
2060  size_t jEnd = partitionBufferInterval[1].second;
2061  size_t kStart = 0;
2062  size_t kEnd = 0;
2063  size_t nPlane = 0;
2064  if(numDim > 2 ){
2065  kStart = partitionBufferInterval[2].first;
2066  kEnd = partitionBufferInterval[2].second;
2067  nPlane = bufferSizes[0]*bufferSizes[1];
2068  }
2069 
2070  for(size_t kIndex = kStart;kIndex <= kEnd;kIndex++){
2071  size_t kBufferIndex = kIndex*nPlane;
2072  size_t kPartIndex = 0;
2073  double z = 0;
2074  if (numDim > 2){
2075  kPartIndex = (kIndex - kStart) + partitionInterval[2].first;
2076  z = kPartIndex*dX[2];
2077  }
2078 
2079  for(size_t jIndex = jStart;jIndex <= jEnd;jIndex++){
2080  size_t jkBufferIndex = kBufferIndex + jIndex*bufferSizes[0];
2081  size_t jPartIndex = (jIndex - jStart) + partitionInterval[1].first;
2082  double y = jPartIndex*dX[1];
2083  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
2084  size_t bufferIndex = jkBufferIndex + iIndex;
2085  size_t iPartIndex = (iIndex - iStart) + partitionInterval[0].first;
2086  double x = iPartIndex*dX[0];
2087 
2088  double densityPulse = Pulse(pulseAmp,pulseWidth,
2089  position[0],position[1],position[2],x,y,z);
2090  // cutoff for gaussian
2091  rhoPtr[bufferIndex] = rho;
2092  if(densityPulse > 1.e-6)
2093  rhoPtr[bufferIndex] += densityPulse;
2094 
2095  rhoEPtr[bufferIndex] = pressure/(gamma-1);
2096  for (int iDim=0;iDim<numDim;iDim++){
2097  rhoVPtr[bufferIndex+numPointsBuffer*iDim] = rhoPtr[bufferIndex]*velocity[iDim];
2098  rhoEPtr[bufferIndex] += 0.5*rhoPtr[bufferIndex]*velocity[iDim]*velocity[iDim];
2099  }
2100 
2101  }
2102  }
2103  }
2104 
2105  return(0);
2106  };
2107 
2108  // initialization for scalar advection test problem
2109  template<typename GridType,typename StateType>
2110  int InitializeGaussianScalar(const GridType &inGrid,StateType &inState, StateType &inParamState,
2111  const std::vector<double> &inParams,int threadId,
2112  std::ostream *messageStream = NULL)
2113  {
2114 
2115  if(!messageStream)
2116  messageStream = &std::cout;
2117 
2118  *messageStream << "Starting Gaussian Scalar Flow Initialization" << std::endl;
2119 
2120  size_t numPointsBuffer = inGrid.BufferSize();
2121  const std::vector<size_t> &gridSizes(inGrid.GridSizes());
2122  const std::vector<size_t> &bufferSizes(inGrid.BufferSizes());
2123  const pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
2124  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
2125  int numDim = gridSizes.size();
2126  const std::vector<double> &dX(inGrid.DX());
2127  const std::vector<double> &readGridExtent(inGrid.PhysicalExtent());
2128 
2129  // first 2 parameters are pulse amplitude and width
2130  // force the user to supply an additional 4 or 6 parameters in 2 or 3D to fully
2131  // define the problem
2132  int numParams = inParams.size();
2133  std::vector<double> position(3,0.0); // initial position
2134  std::vector<double> velocity(3,0.0); // initial velocity
2135  double pulseAmp=1.0;
2136  double pulseWidth=1.0;
2137 
2138  if(numParams < 2){
2139  *messageStream << "Invalid number of parameters, user must"
2140  << "specify an x location and u velocity " << std::endl;
2141  return(1);
2142  } else {
2143  pulseAmp = inParams[0];
2144  pulseWidth = inParams[1];
2145  }
2146 
2147  int locationInd = 2;
2148  int velocityInd = locationInd+numDim;
2149 
2150  if(numDim == 1) {
2151  if(numParams == 4){
2152  position[0] = inParams[locationInd];
2153  velocity[0] = inParams[velocityInd];
2154  } else {
2155  *messageStream << "Invalid number of parameters, user must"
2156  << "specify an x location and u velocity " << std::endl;
2157  return(1);
2158  }
2159  } else if(numDim == 2) {
2160  if(numParams == 6){
2161  position[0] = inParams[locationInd];
2162  position[1] = inParams[locationInd+1];
2163  velocity[0] = inParams[velocityInd];
2164  velocity[1] = inParams[velocityInd+1];
2165  } else {
2166  *messageStream << "Invalid number of parameters, user must"
2167  << "specify an <x,y> location and <u,v> velocity " << std::endl;
2168  return(1);
2169  }
2170  } else if(numDim == 3) {
2171  if(numParams == 8){
2172  position[0] = inParams[locationInd+0];
2173  position[1] = inParams[locationInd+1];
2174  position[2] = inParams[locationInd+2];
2175  velocity[0] = inParams[velocityInd];
2176  velocity[1] = inParams[velocityInd+1];
2177  velocity[2] = inParams[velocityInd+2];
2178  } else {
2179  *messageStream << "Invalid number of parameters, user must"
2180  << "specify an <x,y> location and <u,v> velocity " << std::endl;
2181  return(1);
2182  }
2183  }
2184 
2185  // setup the pulse offset for multiple species
2186  // probably could write a loop to do this cleaner
2187  std::vector< std::vector<double> > pulseOffset;
2188 
2189  //(0,0,0)
2190  std::vector<double> tempOffset(numDim,0.);
2191  pulseOffset.push_back(tempOffset);
2192 
2193  //(1,0,0)
2194  tempOffset[0] = (readGridExtent[1]-readGridExtent[0])-2*position[0];
2195  pulseOffset.push_back(tempOffset);
2196 
2197  //(0,1,0)
2198  tempOffset[0] = 0.;
2199  tempOffset[1] = (readGridExtent[3]-readGridExtent[2])-2*position[1];
2200  pulseOffset.push_back(tempOffset);
2201 
2202  //(1,1,0)
2203  tempOffset[0] = (readGridExtent[1]-readGridExtent[0])-2*position[0];
2204  pulseOffset.push_back(tempOffset);
2205 
2206  if(numDim > 2){
2207  //(0,0,readGridExtent[2])
2208  tempOffset[0] = 0.;
2209  tempOffset[1] = 0.;
2210  tempOffset[2] = (readGridExtent[5]-readGridExtent[4])-2*position[2];
2211  pulseOffset.push_back(tempOffset);
2212 
2213  //(readGridExtent[0],0,readGridExtent[2])
2214  tempOffset[0] = (readGridExtent[1]-readGridExtent[0])-2*position[0];
2215  pulseOffset.push_back(tempOffset);
2216 
2217  //(0,readGridExtent[1],readGridExtent[2])
2218  tempOffset[0] = 0.;
2219  tempOffset[1] = (readGridExtent[3]-readGridExtent[2])-2*position[1];
2220  pulseOffset.push_back(tempOffset);
2221 
2222  //(readGridExtent[0],readGridExtent[1],readGridExtent[2])
2223  tempOffset[0] = (readGridExtent[1]-readGridExtent[0])-2*position[0];
2224  pulseOffset.push_back(tempOffset);
2225  }
2226 
2227 
2228  // check on dimensionality
2229  int nonDimensionalMode=0;
2230  {
2231  int paramHandle = inParamState.GetDataIndex("nonDimensional");
2232  if(paramHandle >= 0){
2233  const pcpp::field::dataset::DataBufferType &paramData(inParamState.Field(paramHandle));
2234  const int *paramPtr = paramData.Data<int>();
2235  nonDimensionalMode = *paramPtr;
2236  } else {
2237  nonDimensionalMode = 0;
2238  }
2239  }
2240 
2241  // get reference conditions
2242  double *gammaPtr = inParamState.template GetFieldBuffer<double>("gamma");
2243  double *rhoRefPtr = inParamState.template GetFieldBuffer<double>("refRho");
2244  double *refLengthPtr = inParamState.template GetFieldBuffer<double>("refLength");
2245  double *presRefPtr = inParamState.template GetFieldBuffer<double>("refPressure");
2246  double *tempRefPtr = inParamState.template GetFieldBuffer<double>("refTemperature");
2247 
2248  double gamma = *gammaPtr;
2249  double refLength = *refLengthPtr;
2250  double refRho = *rhoRefPtr;
2251  double refPressure = *presRefPtr;
2252  double refTemperature = *tempRefPtr;
2253  double sndSpdRef = sqrt(gamma*refPressure/refRho);
2254 
2255  pcpp::IndexIntervalType gridInterval;
2256  gridInterval.InitSimple(gridSizes);
2257 
2258  //*messageStream << "Grid Sizes: (";
2259  //pcpp::io::DumpContents(*messageStream,gridSizes,",");
2260  //*messageStream << ")" << std::endl
2261  //<< "Partition Interval: ";
2262  //partitionInterval.PrettyPrint(*messageStream);
2263  //*messageStream << std::endl << "Poiseulle: Partition Buffer Interval: ";
2264  //partitionBufferInterval.PrettyPrint(*messageStream);
2265  //*messageStream << std::endl;
2266  //*messageStream << "Poiseulle: pipe height " << height << std::endl;
2267  //if(numDim > 2)
2268  //*messageStream << "Poiseulle: pipe width " << width << std::endl;
2269  //*messageStream << "Poiseulle: pipe length " << length << std::endl;
2270 
2271  const std::vector<double> &coordinateData(inGrid.CoordinateData());
2272 
2273  int rhoHandle = inState.GetDataIndex("rho");
2274  if(rhoHandle < 0)
2275  return(1);
2276  pcpp::field::dataset::DataBufferType &rhoData(inState.Field(rhoHandle));
2277  double *rhoPtr = rhoData.Data<double>();
2278  if(!rhoPtr)
2279  return(1);
2280 
2281  int rhoVHandle = inState.GetDataIndex("rhoV");
2282  if(rhoVHandle < 0)
2283  return(1);
2284  pcpp::field::dataset::DataBufferType &rhoVData(inState.Field(rhoVHandle));
2285  double *rhoVPtr = rhoVData.Data<double>();
2286  if(!rhoVPtr)
2287  return(1);
2288 
2289  int rhoEHandle = inState.GetDataIndex("rhoE");
2290  if(rhoEHandle < 0)
2291  return(1);
2292  pcpp::field::dataset::DataBufferType &rhoEData(inState.Field(rhoEHandle));
2293  double *rhoEPtr = rhoEData.Data<double>();
2294  if(!rhoEPtr)
2295  return(1);
2296 
2297  int scalarHandle = inState.GetDataIndex("scalarVars");
2298  if(scalarHandle < 0)
2299  return(1);
2300  pcpp::field::dataset::DataBufferType &scalarData(inState.Field(scalarHandle));
2301  int numScalars = inState.Meta()[scalarHandle].ncomp;
2302  double *scalarPtr = scalarData.Data<double>();
2303  if(!scalarPtr)
2304  return(1);
2305 
2306  // Zero entire buffer(s)
2307  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++){
2308  rhoPtr[iPoint] = 0.0;
2309  rhoEPtr[iPoint] = 0.0;
2310  }
2311  for(int iDim = 0;iDim < numDim;iDim++){
2312  size_t dimOffset = iDim*numPointsBuffer;
2313  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++)
2314  rhoVPtr[iPoint+dimOffset] = 0.0;
2315  }
2316  for(int iScalar = 0;iScalar < numScalars;iScalar++){
2317  size_t scalarOffset = iScalar*numPointsBuffer;
2318  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++)
2319  scalarPtr[iPoint+scalarOffset] = 0.0;
2320  }
2321 
2322  // flow conditions
2323  // working in dimensional units
2324  double rho = refRho;
2325  double pressure = refPressure;
2326  double temperature = refTemperature;
2327 
2328  if(nonDimensionalMode == 1){
2329  rho /= refRho;
2330  pressure /= refPressure;
2331  temperature /= refTemperature;
2332  } else if (nonDimensionalMode == 2) {
2333  rho /= refRho;
2334  pressure /= gamma*refPressure;
2335  temperature /= (gamma-1)*refTemperature;
2336  }
2337 
2338  double rhoE = pressure/(gamma-1)/rho;
2339 
2340  *messageStream << "Scalar Advection: Initial state" << std::endl;
2341  *messageStream << "\t nonDimensional: " << nonDimensionalMode << std::endl;
2342  //*messageStream << "\t Reynolds Number: " << Re << std::endl;
2343  *messageStream << "\t rho: " << rho << std::endl;
2344  *messageStream << "\t pressure: " << pressure << std::endl;
2345  *messageStream << "\t temperature: " << temperature << std::endl;
2346  *messageStream << "\t rhoE: " << rhoE << std::endl;
2347  for(int iDim=0;iDim<numDim;iDim++){
2348  *messageStream << "\t position[" << iDim << "]: " << position[iDim] << std::endl;
2349  }
2350  for(int iDim=0;iDim<numDim;iDim++){
2351  *messageStream << "\t u[" << iDim << "]: " << velocity[iDim] << std::endl;
2352  }
2353 
2354  for(int iScalar=0;iScalar<numScalars;iScalar++){
2355  for(int iDim=0;iDim<numDim;iDim++){
2356  std::cout << "pulseOffset["<<iScalar<<"]["<<iDim<<"] "<<pulseOffset[iScalar][iDim] << std::endl;
2357  }
2358  }
2359 
2360  size_t iStart = partitionBufferInterval[0].first;
2361  size_t iEnd = partitionBufferInterval[0].second;
2362  size_t jStart = partitionBufferInterval[1].first;
2363  size_t jEnd = partitionBufferInterval[1].second;
2364  size_t kStart = 0;
2365  size_t kEnd = 0;
2366  size_t nPlane = 0;
2367  if(numDim > 2 ){
2368  kStart = partitionBufferInterval[2].first;
2369  kEnd = partitionBufferInterval[2].second;
2370  nPlane = bufferSizes[0]*bufferSizes[1];
2371  }
2372 
2373  for(size_t kIndex = kStart;kIndex <= kEnd;kIndex++){
2374  size_t kBufferIndex = kIndex*nPlane;
2375  size_t kPartIndex = 0;
2376  double z = 0;
2377  if (numDim > 2){
2378  kPartIndex = (kIndex - kStart) + partitionInterval[2].first;
2379  z = kPartIndex*dX[2];
2380  }
2381 
2382  for(size_t jIndex = jStart;jIndex <= jEnd;jIndex++){
2383  size_t jkBufferIndex = kBufferIndex + jIndex*bufferSizes[0];
2384  size_t jPartIndex = (jIndex - jStart) + partitionInterval[1].first;
2385  double y = jPartIndex*dX[1];
2386  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
2387  size_t bufferIndex = jkBufferIndex + iIndex;
2388  size_t iPartIndex = (iIndex - iStart) + partitionInterval[0].first;
2389  double x = iPartIndex*dX[0];
2390 
2391  rhoPtr[bufferIndex] = rho;
2392  rhoEPtr[bufferIndex] = pressure/(gamma-1);
2393  for (int iDim=0;iDim<numDim;iDim++){
2394  rhoVPtr[bufferIndex+numPointsBuffer*iDim] = rhoPtr[bufferIndex]*velocity[iDim];
2395  rhoEPtr[bufferIndex] += 0.5*rho*velocity[iDim]*velocity[iDim];
2396  }
2397 
2398  // when there is more than one scalar, put multiple globs in varying locations
2399  // the first scalar is treated as background
2400  if(numScalars > 1) {
2401  scalarPtr[bufferIndex] = 1.0;
2402  for(int iScalar=1;iScalar<numScalars;iScalar++){
2403 
2404  double scalarPulse = Pulse(pulseAmp,pulseWidth,
2405  position[0]+pulseOffset[iScalar-1][0],
2406  position[1]+pulseOffset[iScalar-1][1],
2407  position[2]+pulseOffset[iScalar-1][2],
2408  x,y,z);
2409  // cutoff for gaussian
2410  if(scalarPulse > 1.e-6)
2411  scalarPtr[bufferIndex+numPointsBuffer*iScalar] += scalarPulse;
2412  }
2413  } else {
2414  scalarPtr[bufferIndex] = 1.0;
2415 
2416  double scalarPulse = Pulse(pulseAmp,pulseWidth,
2417  position[0], position[1], position[2], x,y,z);
2418  // cutoff for gaussian
2419  if(scalarPulse > 1.e-6)
2420  scalarPtr[bufferIndex] += scalarPulse;
2421  }
2422  }
2423  }
2424  }
2425 
2426  return(0);
2427  };
2428 
2429  // initialization for scalar advection-diffusion verification
2430  template<typename GridType,typename StateType>
2431  int InitializeAdvectionDiffusion(const GridType &inGrid,StateType &inState, StateType &inParamState,
2432  const std::vector<double> &inParams,int threadId,
2433  std::ostream *messageStream = NULL)
2434  {
2435 
2436  if(!messageStream)
2437  messageStream = &std::cout;
2438 
2439  *messageStream << "Advection-Diffusion Initialization" << std::endl;
2440 
2441  size_t numPointsBuffer = inGrid.BufferSize();
2442  const std::vector<size_t> &gridSizes(inGrid.GridSizes());
2443  const std::vector<size_t> &bufferSizes(inGrid.BufferSizes());
2444  const pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
2445  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
2446 
2447  int numDim = gridSizes.size();
2448  const std::vector<double> &dX(inGrid.DX());
2449  const std::vector<double> &readGridExtent(inGrid.PhysicalExtent());
2450 
2451  // first 2 parameters are pulse amplitude and width
2452  // force the user to supply an additional 4 or 6 parameters in 2 or 3D to fully
2453  // define the problem
2454  int numParams = inParams.size();
2455  std::vector<double> position(3,0.0); // initial position
2456  std::vector<double> velocity(3,0.0); // initial velocity
2457  double waveAmp=.01;
2458  double waveK=2.0*3.14159265358979323846;
2459 
2460  if(numParams >= 1)
2461  waveAmp = inParams[0];
2462  if(numParams >= 2)
2463  waveK = inParams[1];
2464 
2465  bool hasPosition = numParams >= (2+numDim);
2466  bool hasVelocity = numParams >= (2+2*numDim);
2467 
2468  int locationInd = 2;
2469  int velocityInd = locationInd+numDim;
2470 
2471  if(numDim == 1) {
2472  if(hasPosition)
2473  position[0] = inParams[locationInd];
2474  if(hasVelocity)
2475  velocity[0] = inParams[velocityInd];
2476  } else if(numDim == 2) {
2477  if(hasPosition){
2478  position[0] = inParams[locationInd];
2479  position[1] = inParams[locationInd+1];
2480  }
2481  if(hasVelocity){
2482  velocity[0] = inParams[velocityInd];
2483  velocity[1] = inParams[velocityInd+1];
2484  }
2485  } else if(numDim == 3) {
2486  if(hasPosition){
2487  position[0] = inParams[locationInd+0];
2488  position[1] = inParams[locationInd+1];
2489  position[2] = inParams[locationInd+2];
2490  }
2491  if(hasVelocity){
2492  velocity[0] = inParams[velocityInd];
2493  velocity[1] = inParams[velocityInd+1];
2494  velocity[2] = inParams[velocityInd+2];
2495  }
2496  }
2497 
2498 
2499  // check on dimensionality
2500  int nonDimensionalMode=0;
2501  {
2502  int paramHandle = inParamState.GetDataIndex("nonDimensional");
2503  if(paramHandle >= 0){
2504  const pcpp::field::dataset::DataBufferType &paramData(inParamState.Field(paramHandle));
2505  const int *paramPtr = paramData.Data<int>();
2506  nonDimensionalMode = *paramPtr;
2507  } else {
2508  nonDimensionalMode = 0;
2509  }
2510  }
2511 
2512  // get reference conditions
2513  double *gammaPtr = inParamState.template GetFieldBuffer<double>("gamma");
2514  double *rhoRefPtr = inParamState.template GetFieldBuffer<double>("refRho");
2515  double *refLengthPtr = inParamState.template GetFieldBuffer<double>("refLength");
2516  double *presRefPtr = inParamState.template GetFieldBuffer<double>("refPressure");
2517  double *tempRefPtr = inParamState.template GetFieldBuffer<double>("refTemperature");
2518 
2519  double gamma = *gammaPtr;
2520  double refLength = *refLengthPtr;
2521  double refRho = *rhoRefPtr;
2522  double refPressure = *presRefPtr;
2523  double refTemperature = *tempRefPtr;
2524  double sndSpdRef = sqrt(gamma*refPressure/refRho);
2525 
2526  pcpp::IndexIntervalType gridInterval;
2527  gridInterval.InitSimple(gridSizes);
2528 
2529  const std::vector<double> &coordinateData(inGrid.CoordinateData());
2530 
2531  int rhoHandle = inState.GetDataIndex("rho");
2532  if(rhoHandle < 0)
2533  return(1);
2534  pcpp::field::dataset::DataBufferType &rhoData(inState.Field(rhoHandle));
2535  double *rhoPtr = rhoData.Data<double>();
2536  if(!rhoPtr)
2537  return(1);
2538 
2539  int rhoVHandle = inState.GetDataIndex("rhoV");
2540  if(rhoVHandle < 0)
2541  return(1);
2542  pcpp::field::dataset::DataBufferType &rhoVData(inState.Field(rhoVHandle));
2543  double *rhoVPtr = rhoVData.Data<double>();
2544  if(!rhoVPtr)
2545  return(1);
2546 
2547  int rhoEHandle = inState.GetDataIndex("rhoE");
2548  if(rhoEHandle < 0)
2549  return(1);
2550  pcpp::field::dataset::DataBufferType &rhoEData(inState.Field(rhoEHandle));
2551  double *rhoEPtr = rhoEData.Data<double>();
2552  if(!rhoEPtr)
2553  return(1);
2554 
2555  int scalarHandle = inState.GetDataIndex("scalarVars");
2556  if(scalarHandle < 0)
2557  return(1);
2558  pcpp::field::dataset::DataBufferType &scalarData(inState.Field(scalarHandle));
2559  int numScalars = inState.Meta()[scalarHandle].ncomp;
2560  double *scalarPtr = scalarData.Data<double>();
2561  if(!scalarPtr)
2562  return(1);
2563 
2564  // Zero entire buffer(s)
2565  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++){
2566  rhoPtr[iPoint] = 0.0;
2567  rhoEPtr[iPoint] = 0.0;
2568  }
2569  for(int iDim = 0;iDim < numDim;iDim++){
2570  size_t dimOffset = iDim*numPointsBuffer;
2571  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++)
2572  rhoVPtr[iPoint+dimOffset] = 0.0;
2573  }
2574  for(int iScalar = 0;iScalar < numScalars;iScalar++){
2575  size_t scalarOffset = iScalar*numPointsBuffer;
2576  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++)
2577  scalarPtr[iPoint+scalarOffset] = 0.0;
2578  }
2579 
2580  // flow conditions
2581  // working in dimensional units
2582  double rho = refRho;
2583  double pressure = refPressure;
2584  double temperature = refTemperature;
2585 
2586  if(nonDimensionalMode == 1){
2587  rho /= refRho;
2588  pressure /= refPressure;
2589  temperature /= refTemperature;
2590  } else if (nonDimensionalMode == 2) {
2591  rho /= refRho;
2592  pressure /= gamma*refPressure;
2593  temperature /= (gamma-1)*refTemperature;
2594  }
2595 
2596  double rhoE = pressure/(gamma-1)/rho;
2597 
2598  *messageStream << "Scalar Advection Diffusion: Initial state" << std::endl
2599  << "\t nonDimensional: " << nonDimensionalMode << std::endl
2600  << "\t rho: " << rho << std::endl
2601  << "\t pressure: " << pressure << std::endl
2602  << "\t temperature: " << temperature << std::endl
2603  << "\t rhoE: " << rhoE << std::endl;
2604  for(int iDim=0;iDim<numDim;iDim++){
2605  *messageStream << "\t u[" << iDim << "]: " << velocity[iDim] << std::endl;
2606  }
2607  *messageStream << "\t Wave Amp: " << waveAmp << std::endl
2608  << "\t Wave Number: " << waveK << std::endl;
2609 
2610  size_t iStart = partitionBufferInterval[0].first;
2611  size_t iEnd = partitionBufferInterval[0].second;
2612  size_t jStart = partitionBufferInterval[1].first;
2613  size_t jEnd = partitionBufferInterval[1].second;
2614  size_t kStart = 0;
2615  size_t kEnd = 0;
2616  size_t nPlane = 0;
2617 
2618  if(numDim > 2 ){
2619  kStart = partitionBufferInterval[2].first;
2620  kEnd = partitionBufferInterval[2].second;
2621  nPlane = bufferSizes[0]*bufferSizes[1];
2622  }
2623 
2624  for(size_t kIndex = kStart;kIndex <= kEnd;kIndex++){
2625  size_t kBufferIndex = kIndex*nPlane;
2626  size_t kPartIndex = 0;
2627  double z = 0;
2628  if (numDim > 2){
2629  kPartIndex = (kIndex - kStart) + partitionInterval[2].first;
2630  z = kPartIndex*dX[2];
2631  }
2632 
2633  for(size_t jIndex = jStart;jIndex <= jEnd;jIndex++){
2634  size_t jkBufferIndex = kBufferIndex + jIndex*bufferSizes[0];
2635  size_t jPartIndex = (jIndex - jStart) + partitionInterval[1].first;
2636  double y = jPartIndex*dX[1];
2637  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
2638  size_t bufferIndex = jkBufferIndex + iIndex;
2639  size_t iPartIndex = (iIndex - iStart) + partitionInterval[0].first;
2640  double x = iPartIndex*dX[0];
2641  double waveCoordinate = x;
2642  if(numDim > 1)
2643  if(position[1] > 0) waveCoordinate = y;
2644  if(numDim > 2)
2645  if(position[2] > 0) waveCoordinate = z;
2646 
2647  rhoPtr[bufferIndex] = rho;
2648  rhoEPtr[bufferIndex] = pressure/(gamma-1);
2649  for (int iDim=0;iDim<numDim;iDim++){
2650  rhoVPtr[bufferIndex+numPointsBuffer*iDim] = rhoPtr[bufferIndex]*velocity[iDim];
2651  rhoEPtr[bufferIndex] += 0.5*rho*velocity[iDim]*velocity[iDim];
2652  }
2653  for(int iScalar = 0;iScalar < numScalars;iScalar++){
2654  double phase = iScalar * waveK/4.0;
2655  size_t scalarOffset = iScalar*numPointsBuffer;
2656  scalarPtr[scalarOffset+bufferIndex] = waveAmp*std::sin(waveK*waveCoordinate+phase);
2657  }
2658  }
2659  }
2660  }
2661  return(0);
2662  };
2663 
2664  // initialization for scalar advection-diffusion verification
2665  template<typename GridType,typename StateType>
2666  int InitializeUniformFlow(const GridType &inGrid,
2667  StateType &inState,
2668  StateType &inParamState,
2669  const std::vector<double> &inParams,int threadId,
2670  std::ostream *messageStream = NULL)
2671  {
2672 
2673  if(!messageStream)
2674  messageStream = &std::cout;
2675 
2676  *messageStream << "Uniform Flow Initialization" << std::endl;
2677 
2678  size_t numPointsBuffer = inGrid.BufferSize();
2679  const std::vector<size_t> &gridSizes(inGrid.GridSizes());
2680  const std::vector<size_t> &bufferSizes(inGrid.BufferSizes());
2681  const pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
2682  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
2683 
2684  int numDim = gridSizes.size();
2685 
2686  // first 2 parameters are pulse amplitude and width
2687  // force the user to supply an additional 4 or 6 parameters in 2 or 3D to fully
2688  // define the problem
2689  int numParams = inParams.size();
2690  std::vector<double> velocity(3,0.0); // initial velocity
2691 
2692  for(int iParam = 0;iParam < numDim;iParam++)
2693  velocity[iParam] = inParams[iParam];
2694 
2695  // check on dimensionality
2696  int nonDimensionalMode=0;
2697  {
2698  int paramHandle = inParamState.GetDataIndex("nonDimensional");
2699  if(paramHandle >= 0){
2700  const pcpp::field::dataset::DataBufferType &paramData(inParamState.Field(paramHandle));
2701  const int *paramPtr = paramData.Data<int>();
2702  nonDimensionalMode = *paramPtr;
2703  } else {
2704  nonDimensionalMode = 0;
2705  }
2706  }
2707 
2708  // get reference conditions
2709  double *gammaPtr = inParamState.template GetFieldBuffer<double>("gamma");
2710  double *rhoRefPtr = inParamState.template GetFieldBuffer<double>("refRho");
2711  double *refLengthPtr = inParamState.template GetFieldBuffer<double>("refLength");
2712  double *presRefPtr = inParamState.template GetFieldBuffer<double>("refPressure");
2713  double *tempRefPtr = inParamState.template GetFieldBuffer<double>("refTemperature");
2714 
2715  double gamma = *gammaPtr;
2716  double refLength = *refLengthPtr;
2717  double refRho = *rhoRefPtr;
2718  double refPressure = *presRefPtr;
2719  double refTemperature = *tempRefPtr;
2720  double sndSpdRef = sqrt(gamma*refPressure/refRho);
2721 
2722  pcpp::IndexIntervalType gridInterval;
2723  gridInterval.InitSimple(gridSizes);
2724 
2725  int rhoHandle = inState.GetDataIndex("rho");
2726  if(rhoHandle < 0){
2727  *messageStream << "Required variable (rho) not found in state." << std::endl;
2728  return(1);
2729  }
2730  pcpp::field::dataset::DataBufferType &rhoData(inState.Field(rhoHandle));
2731  double *rhoPtr = rhoData.Data<double>();
2732  if(!rhoPtr)
2733  return(1);
2734 
2735  int rhoVHandle = inState.GetDataIndex("rhoV");
2736  if(rhoVHandle < 0){
2737  *messageStream << "Required variable (rhoV) not found in state." << std::endl;
2738  return(1);
2739  }
2740 
2741  pcpp::field::dataset::DataBufferType &rhoVData(inState.Field(rhoVHandle));
2742  double *rhoVPtr = rhoVData.Data<double>();
2743  if(!rhoVPtr)
2744  return(1);
2745 
2746  int rhoEHandle = inState.GetDataIndex("rhoE");
2747  if(rhoEHandle < 0){
2748  *messageStream << "Required variable (rhoE) not found in state." << std::endl;
2749  return(1);
2750  }
2751  pcpp::field::dataset::DataBufferType &rhoEData(inState.Field(rhoEHandle));
2752  double *rhoEPtr = rhoEData.Data<double>();
2753  if(!rhoEPtr)
2754  return(1);
2755 
2756  // Zero entire buffer(s)
2757  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++){
2758  rhoPtr[iPoint] = 0.0;
2759  rhoEPtr[iPoint] = 0.0;
2760  }
2761  for(int iDim = 0;iDim < numDim;iDim++){
2762  size_t dimOffset = iDim*numPointsBuffer;
2763  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++)
2764  rhoVPtr[iPoint+dimOffset] = 0.0;
2765  }
2766 
2767  // flow conditions
2768  // working in dimensional units
2769  double rho = refRho;
2770  double pressure = refPressure;
2771  double temperature = refTemperature;
2772 
2773  if(nonDimensionalMode == 1){
2774  rho /= refRho;
2775  pressure /= refPressure;
2776  temperature /= refTemperature;
2777  } else if (nonDimensionalMode == 2) {
2778  rho /= refRho;
2779  pressure /= gamma*refPressure;
2780  temperature /= (gamma-1)*refTemperature;
2781  }
2782 
2783  double rhoE = pressure/(gamma-1)/rho;
2784 
2785  *messageStream << "Uniform Flow: Initial state" << std::endl
2786  << "\t nonDimensional: " << nonDimensionalMode << std::endl
2787  << "\t rho: " << rho << std::endl
2788  << "\t pressure: " << pressure << std::endl
2789  << "\t temperature: " << temperature << std::endl
2790  << "\t rhoE: " << rhoE << std::endl
2791  << "\t velocity: (";
2792  for(int iDim=0;iDim<numDim;iDim++){
2793  if(iDim > 0) *messageStream << ",";
2794  *messageStream << velocity[iDim];
2795  }
2796  *messageStream << ")" << std::endl;
2797 
2798  size_t iStart = partitionBufferInterval[0].first;
2799  size_t iEnd = partitionBufferInterval[0].second;
2800  size_t jStart = partitionBufferInterval[1].first;
2801  size_t jEnd = partitionBufferInterval[1].second;
2802  size_t kStart = 0;
2803  size_t kEnd = 0;
2804  size_t nPlane = 0;
2805 
2806  if(numDim > 2 ){
2807  kStart = partitionBufferInterval[2].first;
2808  kEnd = partitionBufferInterval[2].second;
2809  nPlane = bufferSizes[0]*bufferSizes[1];
2810  }
2811 
2812  for(size_t kIndex = kStart;kIndex <= kEnd;kIndex++){
2813  size_t kBufferIndex = kIndex*nPlane;
2814  size_t kPartIndex = 0;
2815  if (numDim > 2){
2816  kPartIndex = (kIndex - kStart) + partitionInterval[2].first;
2817  }
2818  for(size_t jIndex = jStart;jIndex <= jEnd;jIndex++){
2819  size_t jkBufferIndex = kBufferIndex + jIndex*bufferSizes[0];
2820  size_t jPartIndex = (jIndex - jStart) + partitionInterval[1].first;
2821  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
2822  size_t bufferIndex = jkBufferIndex + iIndex;
2823  size_t iPartIndex = (iIndex - iStart) + partitionInterval[0].first;
2824  rhoPtr[bufferIndex] = rho;
2825  rhoEPtr[bufferIndex] = pressure/(gamma-1);
2826  for (int iDim=0;iDim<numDim;iDim++){
2827  rhoVPtr[bufferIndex+numPointsBuffer*iDim] = rhoPtr[bufferIndex]*velocity[iDim];
2828  rhoEPtr[bufferIndex] += 0.5*rho*velocity[iDim]*velocity[iDim];
2829  }
2830  }
2831  }
2832  }
2833  return(0);
2834  };
2835 
2836  // initialization for scalar advection-diffusion verification
2837  template<typename DomainType>
2838  int InitializeAdvectionDiffusion(DomainType &inDomain,
2839  int iGrid,const std::string &caseName,
2840  int threadId,std::ostream *messageStream = NULL)
2841  {
2842 
2843  typedef typename DomainType::GridType GridType;
2844  typedef typename DomainType::StateType StateType;
2845  fixtures::ConfigurationType &domainConfig(inDomain.Config());
2846 
2847  GridType &inGrid(inDomain.Grid(iGrid));
2848  StateType &inState(inDomain.State(iGrid));
2849  StateType &inParams(inDomain.Params(iGrid));
2850 
2851  std::string initKey(ConfigKey(ConfigKey(inDomain.Name(),"Init"),caseName));
2852  std::vector<double> initParams(domainConfig.GetValueVector<double>(ConfigKey(initKey,"Params")));
2853  std::vector<int> initFlags(domainConfig.GetValueVector<int>(ConfigKey(initKey,"Flags")));
2854 
2855  if(!messageStream)
2856  messageStream = &std::cout;
2857 
2858  *messageStream << "Advection-Diffusion Initialization" << std::endl;
2859 
2860  size_t numPointsBuffer = inGrid.BufferSize();
2861  const std::vector<size_t> &gridSizes(inGrid.GridSizes());
2862  const std::vector<size_t> &bufferSizes(inGrid.BufferSizes());
2863  const pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
2864  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
2865 
2866  int numDim = gridSizes.size();
2867  const std::vector<double> &dX(inGrid.DX());
2868  const std::vector<double> &readGridExtent(inGrid.PhysicalExtent());
2869 
2870  // first 2 parameters are pulse amplitude and width
2871  // force the user to supply an additional 4 or 6 parameters in 2 or 3D to fully
2872  // define the problem
2873  int numParams = initParams.size();
2874  std::vector<double> position(3,0.0); // initial position
2875  std::vector<double> velocity(3,0.0); // initial velocity
2876  double pulseAmp=1.0;
2877  double pulseWidth=1.0;
2878 
2879  if(numParams < 2){
2880  *messageStream << "Invalid number of parameters, user must"
2881  << "specify an x location and u velocity " << std::endl;
2882  return(1);
2883  } else {
2884  pulseAmp = initParams[0];
2885  pulseWidth = initParams[1];
2886  }
2887 
2888  int locationInd = 2;
2889  int velocityInd = locationInd+numDim;
2890 
2891  if(numDim == 1) {
2892  if(numParams == 4){
2893  position[0] = initParams[locationInd];
2894  velocity[0] = initParams[velocityInd];
2895  } else {
2896  *messageStream << "Invalid number of parameters, user must"
2897  << "specify an x location and u velocity " << std::endl;
2898  return(1);
2899  }
2900  } else if(numDim == 2) {
2901  if(numParams == 6){
2902  position[0] = initParams[locationInd];
2903  position[1] = initParams[locationInd+1];
2904  velocity[0] = initParams[velocityInd];
2905  velocity[1] = initParams[velocityInd+1];
2906  } else {
2907  *messageStream << "Invalid number of parameters, user must"
2908  << "specify an <x,y> location and <u,v> velocity " << std::endl;
2909  return(1);
2910  }
2911  } else if(numDim == 3) {
2912  if(numParams == 8){
2913  position[0] = initParams[locationInd+0];
2914  position[1] = initParams[locationInd+1];
2915  position[2] = initParams[locationInd+2];
2916  velocity[0] = initParams[velocityInd];
2917  velocity[1] = initParams[velocityInd+1];
2918  velocity[2] = initParams[velocityInd+2];
2919  } else {
2920  *messageStream << "Invalid number of parameters, user must"
2921  << "specify an <x,y> location and <u,v> velocity " << std::endl;
2922  return(1);
2923  }
2924  }
2925 
2926 
2927  // check on dimensionality
2928  int nonDimensionalMode=0;
2929  {
2930  int paramHandle = inParams.GetDataIndex("nonDimensional");
2931  if(paramHandle >= 0){
2932  const pcpp::field::dataset::DataBufferType &paramData(inParams.Field(paramHandle));
2933  const int *paramPtr = paramData.Data<int>();
2934  nonDimensionalMode = *paramPtr;
2935  } else {
2936  nonDimensionalMode = 0;
2937  }
2938  }
2939 
2940  // get reference conditions
2941  double *gammaPtr = inParams.template GetFieldBuffer<double>("gamma");
2942  double *rhoRefPtr = inParams.template GetFieldBuffer<double>("refRho");
2943  double *refLengthPtr = inParams.template GetFieldBuffer<double>("refLength");
2944  double *presRefPtr = inParams.template GetFieldBuffer<double>("refPressure");
2945  double *tempRefPtr = inParams.template GetFieldBuffer<double>("refTemperature");
2946 
2947  double gamma = *gammaPtr;
2948  double refLength = *refLengthPtr;
2949  double refRho = *rhoRefPtr;
2950  double refPressure = *presRefPtr;
2951  double refTemperature = *tempRefPtr;
2952  double sndSpdRef = sqrt(gamma*refPressure/refRho);
2953 
2954  pcpp::IndexIntervalType gridInterval;
2955  gridInterval.InitSimple(gridSizes);
2956 
2957  const std::vector<double> &coordinateData(inGrid.CoordinateData());
2958 
2959  int rhoHandle = inState.GetDataIndex("rho");
2960  if(rhoHandle < 0)
2961  return(1);
2962  pcpp::field::dataset::DataBufferType &rhoData(inState.Field(rhoHandle));
2963  double *rhoPtr = rhoData.Data<double>();
2964  if(!rhoPtr)
2965  return(1);
2966 
2967  int rhoVHandle = inState.GetDataIndex("rhoV");
2968  if(rhoVHandle < 0)
2969  return(1);
2970  pcpp::field::dataset::DataBufferType &rhoVData(inState.Field(rhoVHandle));
2971  double *rhoVPtr = rhoVData.Data<double>();
2972  if(!rhoVPtr)
2973  return(1);
2974 
2975  int rhoEHandle = inState.GetDataIndex("rhoE");
2976  if(rhoEHandle < 0)
2977  return(1);
2978  pcpp::field::dataset::DataBufferType &rhoEData(inState.Field(rhoEHandle));
2979  double *rhoEPtr = rhoEData.Data<double>();
2980  if(!rhoEPtr)
2981  return(1);
2982 
2983  int scalarHandle = inState.GetDataIndex("scalarVars");
2984  if(scalarHandle < 0)
2985  return(1);
2986  pcpp::field::dataset::DataBufferType &scalarData(inState.Field(scalarHandle));
2987  int numScalars = inState.Meta()[scalarHandle].ncomp;
2988  double *scalarPtr = scalarData.Data<double>();
2989  if(!scalarPtr)
2990  return(1);
2991 
2992  // Zero entire buffer(s)
2993  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++){
2994  rhoPtr[iPoint] = 0.0;
2995  rhoEPtr[iPoint] = 0.0;
2996  }
2997  for(int iDim = 0;iDim < numDim;iDim++){
2998  size_t dimOffset = iDim*numPointsBuffer;
2999  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++)
3000  rhoVPtr[iPoint+dimOffset] = 0.0;
3001  }
3002  for(int iScalar = 0;iScalar < numScalars;iScalar++){
3003  size_t scalarOffset = iScalar*numPointsBuffer;
3004  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++)
3005  scalarPtr[iPoint+scalarOffset] = 0.0;
3006  }
3007 
3008  // flow conditions
3009  // working in dimensional units
3010  double rho = refRho;
3011  double pressure = refPressure;
3012  double temperature = refTemperature;
3013 
3014  if(nonDimensionalMode == 1){
3015  rho /= refRho;
3016  pressure /= refPressure;
3017  temperature /= refTemperature;
3018  } else if (nonDimensionalMode == 2) {
3019  rho /= refRho;
3020  pressure /= gamma*refPressure;
3021  temperature /= (gamma-1)*refTemperature;
3022  }
3023 
3024  double rhoE = pressure/(gamma-1)/rho;
3025 
3026  *messageStream << "Scalar Advection Diffusion: Initial state" << std::endl;
3027  *messageStream << "\t nonDimensional: " << nonDimensionalMode << std::endl;
3028  //*messageStream << "\t Reynolds Number: " << Re << std::endl;
3029  *messageStream << "\t rho: " << rho << std::endl;
3030  *messageStream << "\t pressure: " << pressure << std::endl;
3031  *messageStream << "\t temperature: " << temperature << std::endl;
3032  *messageStream << "\t rhoE: " << rhoE << std::endl;
3033  for(int iDim=0;iDim<numDim;iDim++){
3034  *messageStream << "\t u[" << iDim << "]: " << velocity[iDim] << std::endl;
3035  }
3036 
3037  size_t iStart = partitionBufferInterval[0].first;
3038  size_t iEnd = partitionBufferInterval[0].second;
3039  size_t jStart = partitionBufferInterval[1].first;
3040  size_t jEnd = partitionBufferInterval[1].second;
3041  size_t kStart = 0;
3042  size_t kEnd = 0;
3043  size_t nPlane = 0;
3044  if(numDim > 2 ){
3045  kStart = partitionBufferInterval[2].first;
3046  kEnd = partitionBufferInterval[2].second;
3047  nPlane = bufferSizes[0]*bufferSizes[1];
3048  }
3049 
3050  for(size_t kIndex = kStart;kIndex <= kEnd;kIndex++){
3051  size_t kBufferIndex = kIndex*nPlane;
3052  size_t kPartIndex = 0;
3053  double z = 0;
3054  if (numDim > 2){
3055  kPartIndex = (kIndex - kStart) + partitionInterval[2].first;
3056  z = kPartIndex*dX[2];
3057  }
3058 
3059  for(size_t jIndex = jStart;jIndex <= jEnd;jIndex++){
3060  size_t jkBufferIndex = kBufferIndex + jIndex*bufferSizes[0];
3061  size_t jPartIndex = (jIndex - jStart) + partitionInterval[1].first;
3062  double y = jPartIndex*dX[1];
3063  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
3064  size_t bufferIndex = jkBufferIndex + iIndex;
3065  size_t iPartIndex = (iIndex - iStart) + partitionInterval[0].first;
3066  double x = iPartIndex*dX[0];
3067 
3068  rhoPtr[bufferIndex] = rho;
3069  rhoEPtr[bufferIndex] = pressure/(gamma-1);
3070  for (int iDim=0;iDim<numDim;iDim++){
3071  rhoVPtr[bufferIndex+numPointsBuffer*iDim] = rhoPtr[bufferIndex]*velocity[iDim];
3072  rhoEPtr[bufferIndex] += 0.5*rho*velocity[iDim]*velocity[iDim];
3073  }
3074  scalarPtr[bufferIndex] = .01*std::sin(2*3.14159265358979323846*x);
3075 
3076  }
3077  }
3078  }
3079  return(0);
3080  };
3081 
3083  template<typename GridType,typename StateType>
3084  int InitializeDensityPulse(const GridType &inGrid,StateType &inState,
3085  StateType &inParam,const std::vector<double> &inParams,
3086  const std::vector<int> &inFlags,int threadId,
3087  std::ostream *messageStream)
3088  {
3089 
3090  if(!messageStream)
3091  messageStream = &std::cout;
3092 
3093  double pulseAmp = 0.01;
3094  double pulseWidth = 0.000001;
3095  double relCenterX = 0.5;
3096  double relCenterY = 0.5;
3097  double relCenterZ = 0.5;
3098  double crossFlowSpeed = 0.0;
3099  double injectionSpeed = 0.0;
3100 
3101 
3102  int INIT_CROSSFLOW = 1;
3103  int INIT_CROSSFLOW_PROFILE = 2;
3104 
3105 
3106  int numParams = inParams.size();
3107  if(numParams > 0)
3108  pulseAmp = inParams[0];
3109  if(numParams > 1)
3110  pulseWidth = inParams[1];
3111  if(numParams > 2)
3112  relCenterX = inParams[2];
3113  if(numParams > 3)
3114  relCenterY = inParams[3];
3115  if(numParams > 4)
3116  relCenterZ = inParams[4];
3117  if(numParams > 5)
3118  crossFlowSpeed = inParams[5];
3119 
3120  int optionBits = 0;
3121  if(!inFlags.empty()){
3122  optionBits = inFlags[0];
3123  }
3124 
3125  size_t numPointsBuffer = inGrid.BufferSize();
3126  const std::vector<size_t> &bufferSizes(inGrid.BufferSizes());
3127  const std::vector<size_t> &gridSizes(inGrid.GridSizes());
3128  const pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
3129  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
3130  const std::vector<simulation::grid::subregion> &gridSubRegions(inGrid.SubRegions());
3131  const std::vector<double> &dX(inGrid.DX());
3132  const std::vector<double> &coordinateData(inGrid.CoordinateData());
3133  const std::vector<double> &physicalExtent(inGrid.PhysicalExtent());
3134  int numDim = gridSizes.size();
3135 
3136 
3137  pcpp::IndexIntervalType gridInterval;
3138  gridInterval.InitSimple(gridSizes);
3139 
3140  std::vector<double> pulseCenter(3,0);
3141  pulseCenter[0] = relCenterX;
3142  pulseCenter[1] = relCenterY;
3143  pulseCenter[2] = relCenterZ;
3144  for(int iDim = 0;iDim < numDim;iDim++){
3145  pulseCenter[iDim] *= (physicalExtent[iDim*2+1] - physicalExtent[iDim*2]);
3146  pulseCenter[iDim] += physicalExtent[iDim*2];
3147  }
3148  if(numDim < 3)
3149  pulseCenter[2] = 0.0;
3150  if(numDim < 2)
3151  pulseCenter[1] = 0.0;
3152 
3153 
3154  *messageStream << "DensityPulse: Grid Sizes: (";
3155  pcpp::io::DumpContents(*messageStream,gridSizes,",");
3156  *messageStream << ")" << std::endl
3157  << "DensityPulse: Partition Interval: ";
3158  partitionInterval.PrettyPrint(*messageStream);
3159  *messageStream << std::endl << "DensityPulse: Partition Buffer Interval: ";
3160  partitionBufferInterval.PrettyPrint(*messageStream);
3161  *messageStream << std::endl;
3162 
3163  *messageStream << "DensityPulse: Amplitude: "
3164  << pulseAmp << std::endl
3165  << "DensityPulse: Width: "
3166  << pulseWidth << std::endl
3167  << "DensityPulse: Relative center: (" << relCenterX
3168  << "," << relCenterY << "," << relCenterZ << ")" << std::endl
3169  << "DensityPulse: Center: (" << pulseCenter[0] << ","
3170  << pulseCenter[1] << "," << pulseCenter[2] << ")" << std::endl;
3171  if(optionBits > 0){
3172  *messageStream << "DensityPulse: CrossFlowSpeed: " << crossFlowSpeed << std::endl;
3173  }
3174 
3175  double *gammaPtr = inParam.template GetFieldBuffer<double>("gamma");
3176  double gammaValue = *gammaPtr;
3177 
3178 
3179  int rhoHandle = inState.GetDataIndex("rho");
3180  if(rhoHandle < 0)
3181  return(1);
3182  pcpp::field::dataset::DataBufferType &rhoData(inState.Field(rhoHandle));
3183  double *rhoPtr = rhoData.Data<double>();
3184  if(!rhoPtr)
3185  return(1);
3186 
3187  int rhoVHandle = inState.GetDataIndex("rhoV");
3188  if(rhoVHandle < 0)
3189  return(1);
3190  pcpp::field::dataset::DataBufferType &rhoVData(inState.Field(rhoVHandle));
3191  double *rhoVPtr = rhoVData.Data<double>();
3192  if(!rhoVPtr)
3193  return(1);
3194 
3195  int rhoEHandle = inState.GetDataIndex("rhoE");
3196  if(rhoEHandle < 0)
3197  return(1);
3198  pcpp::field::dataset::DataBufferType &rhoEData(inState.Field(rhoEHandle));
3199  double *rhoEPtr = rhoEData.Data<double>();
3200  if(!rhoPtr)
3201  return(1);
3202 
3203 
3204  // Zero entire buffer(s)
3205  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++){
3206  rhoPtr[iPoint] = 0.0;
3207  rhoEPtr[iPoint] = 0.0;
3208  }
3209  for(int iDim = 0;iDim < numDim;iDim++){
3210  size_t dimOffset = iDim*numPointsBuffer;
3211  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++)
3212  rhoVPtr[iPoint+dimOffset] = 0.0;
3213  }
3214 
3215 
3216  std::vector<double> velocity(numDim,0.0); // really just velocity at this point
3217  // Comment next line for quiescent, uncomment for constant flow
3218  if(optionBits > 0)
3219  velocity[optionBits-1] = crossFlowSpeed;
3220 
3221  if(numDim == 3){
3222 
3223  size_t iStart = partitionBufferInterval[0].first;
3224  size_t iEnd = partitionBufferInterval[0].second;
3225  size_t jStart = partitionBufferInterval[1].first;
3226  size_t jEnd = partitionBufferInterval[1].second;
3227  size_t kStart = partitionBufferInterval[2].first;
3228  size_t kEnd = partitionBufferInterval[2].second;
3229  size_t nPlane = bufferSizes[0]*bufferSizes[1];
3230 
3231  for(size_t kIndex = kStart;kIndex <= kEnd;kIndex++){
3232  size_t kBufferIndex = kIndex*nPlane;
3233  size_t kPartIndex = (kIndex - kStart) + partitionInterval[2].first;
3234  double z = kPartIndex*dX[2];
3235  for(size_t jIndex = jStart;jIndex <= jEnd;jIndex++){
3236  size_t jkBufferIndex = kBufferIndex + jIndex*bufferSizes[0];
3237  size_t jPartIndex = (jIndex - jStart) + partitionInterval[1].first;
3238  double y = jPartIndex*dX[1];
3239  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
3240  size_t bufferIndex = jkBufferIndex + iIndex;
3241  size_t iPartIndex = (iIndex - iStart) + partitionInterval[0].first;
3242  double x = iPartIndex*dX[0];
3243  double xRad = x - pulseCenter[0];
3244  double yRad = y - pulseCenter[1];
3245  double zRad = z - pulseCenter[2];
3246  double xyzRad = std::sqrt(xRad*xRad+yRad*yRad+zRad*zRad);
3247 
3248  rhoPtr[bufferIndex] = 1.0+Pulse(pulseAmp,pulseWidth,pulseCenter[0],pulseCenter[1],pulseCenter[2],x,y,z);
3249  rhoVPtr[bufferIndex] = rhoPtr[bufferIndex]*velocity[0];
3250  rhoVPtr[bufferIndex+numPointsBuffer] = rhoPtr[bufferIndex]*velocity[1];
3251  rhoVPtr[bufferIndex+2*numPointsBuffer] = rhoPtr[bufferIndex]*velocity[2];
3252  rhoEPtr[bufferIndex] = (1.0/(gammaValue-1.0) + .5*(velocity[0]*velocity[0] +
3253  velocity[1]*velocity[1] +
3254  velocity[2]*velocity[2]));
3255  }
3256  }
3257  }
3258  } else if (numDim == 2) {
3259  size_t iStart = partitionBufferInterval[0].first;
3260  size_t iEnd = partitionBufferInterval[0].second;
3261  size_t jStart = partitionBufferInterval[1].first;
3262  size_t jEnd = partitionBufferInterval[1].second;
3263  for(size_t jIndex = jStart;jIndex <= jEnd;jIndex++){
3264  size_t jBufferIndex = jIndex*bufferSizes[0];
3265  size_t jPartIndex = (jIndex - jStart)+partitionInterval[1].first;
3266  double y = jPartIndex*dX[1];
3267  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
3268  size_t bufferIndex = jBufferIndex + iIndex;
3269  size_t iPartIndex = (iIndex - iStart)+partitionInterval[0].first;
3270  double x = iPartIndex*dX[0];
3271  double xRad = x - pulseCenter[0];
3272  double yRad = y - pulseCenter[1];
3273  double xyzRad = std::sqrt(xRad*xRad+yRad*yRad);
3274  rhoPtr[bufferIndex] = 1.0 + Pulse(pulseAmp,pulseWidth,pulseCenter[0],pulseCenter[1],.5,x,y,.5);
3275  rhoVPtr[bufferIndex] = rhoPtr[bufferIndex]*velocity[0];
3276  rhoVPtr[bufferIndex+numPointsBuffer] = rhoPtr[bufferIndex]*velocity[1];
3277  rhoEPtr[bufferIndex] = (1.0/(gammaValue-1.0) +
3278  .5*(velocity[0]*velocity[0] + velocity[1]*velocity[1]));
3279 
3280  }
3281  }
3282  } else if (numDim == 1) {
3283  size_t iStart = partitionBufferInterval[0].first;
3284  size_t iEnd = partitionBufferInterval[0].second;
3285  for(size_t iIndex = iStart;iIndex <= iEnd;iIndex++){
3286  size_t iPartIndex = (iIndex - iStart)+partitionInterval[0].first;
3287  double x = iPartIndex*dX[0];
3288  double xRad = x - pulseCenter[0];
3289  double xyzRad = std::sqrt(xRad*xRad);
3290  rhoPtr[iIndex] = 1.0 + Pulse(pulseAmp,pulseWidth,pulseCenter[0],.5,.5,x,.5,.5);
3291  rhoVPtr[iIndex] = rhoPtr[iIndex]*velocity[0];
3292  rhoEPtr[iIndex] = (1.0/(gammaValue - 1.0) + .5*velocity[0]*velocity[0]);
3293  }
3294  }
3295 
3296  return(0);
3297  };
3298 
3299  template<typename GridType,typename StateType>
3300  int InitializeRiemann1D(const GridType &inGrid,StateType &inState,
3301  StateType &paramState,const std::vector<double> &inParams,
3302  const std::vector<int> &inFlags,int threadId)
3303  {
3304 
3305  double rhoL = 0.0;
3306  double rhoR = 0.0;
3307  double uL = 0.0;
3308  double uR = 0.0;
3309  double pL = 0.0;
3310  double pR = 0.0;
3311  double x0 = -1.0;
3312  int jumpDim = 0;
3313 
3314 
3315  int numParams = inParams.size();
3316  if(!(numParams >= 7))
3317  return(1);
3318  if(numParams > 0)
3319  rhoL = inParams[0];
3320  if(numParams > 1)
3321  uL = inParams[1];
3322  if(numParams > 2)
3323  pL = inParams[2];
3324  if(numParams > 3)
3325  rhoR = inParams[3];
3326  if(numParams > 4)
3327  uR = inParams[4];
3328  if(numParams > 5)
3329  pR = inParams[5];
3330  if(numParams > 6)
3331  x0 = inParams[6];
3332 
3333  if(!inFlags.empty()){
3334  jumpDim = inFlags[0];
3335  }
3336 
3337  size_t numPointsBuffer = inGrid.BufferSize();
3338  const std::vector<size_t> &bufferSizes(inGrid.BufferSizes());
3339  const std::vector<size_t> &gridSizes(inGrid.GridSizes());
3340  const pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
3341  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
3342  const std::vector<simulation::grid::subregion> &gridSubRegions(inGrid.SubRegions());
3343  const std::vector<double> &dX(inGrid.DX());
3344  const std::vector<double> &gridCoords(inGrid.CoordinateData());
3345  const std::vector<double> &physicalExtent(inGrid.PhysicalExtent());
3346  int numDim = gridSizes.size();
3347 
3348 
3349  pcpp::IndexIntervalType gridInterval;
3350  gridInterval.InitSimple(gridSizes);
3351 
3352 
3353  int rhoHandle = inState.GetDataIndex("rho");
3354  if(rhoHandle < 0)
3355  return(1);
3356  pcpp::field::dataset::DataBufferType &rhoData(inState.Field(rhoHandle));
3357  double *rhoPtr = rhoData.Data<double>();
3358  if(!rhoPtr)
3359  return(1);
3360 
3361  int rhoVHandle = inState.GetDataIndex("rhoV");
3362  if(rhoVHandle < 0)
3363  return(1);
3364  pcpp::field::dataset::DataBufferType &rhoVData(inState.Field(rhoVHandle));
3365  double *rhoVPtr = rhoVData.Data<double>();
3366  if(!rhoVPtr)
3367  return(1);
3368 
3369  int rhoEHandle = inState.GetDataIndex("rhoE");
3370  if(rhoEHandle < 0)
3371  return(1);
3372  pcpp::field::dataset::DataBufferType &rhoEData(inState.Field(rhoEHandle));
3373  double *rhoEPtr = rhoEData.Data<double>();
3374  if(!rhoPtr)
3375  return(1);
3376 
3377 
3378  double *gammaPtr = paramState.template GetFieldBuffer<double>("gamma");
3379  double gamma = *gammaPtr;
3380 
3381  // Zero entire buffer(s)
3382  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++){
3383  rhoPtr[iPoint] = 0.0;
3384  rhoEPtr[iPoint] = 0.0;
3385  }
3386  for(int iDim = 0;iDim < numDim;iDim++){
3387  size_t dimOffset = iDim*numPointsBuffer;
3388  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++)
3389  rhoVPtr[iPoint+dimOffset] = 0.0;
3390  }
3391 
3392 
3393  // "left" state
3394  double rhoVL = rhoL*uL;
3395  double rhoEL = pL/(gamma-1.0) + 0.5*rhoL*uL*uL;
3396 
3397  // "right" state
3398  double rhoVR = rhoR*uR;
3399  double rhoER = pR/(gamma-1.0) + 0.5*rhoR*uR*uR;
3400 
3401  // locations of jumps, using physical coordinates
3402  double loc1 = physicalExtent[2*(jumpDim-1)]+x0;
3403  double loc2 = x0;
3404 
3405  size_t iStart = partitionBufferInterval[0].first;
3406  size_t iEnd = partitionBufferInterval[0].second;
3407  size_t jStart = partitionBufferInterval[1].first;
3408  size_t jEnd = partitionBufferInterval[1].second;
3409 
3410  // if numDim == 2 this will set kIndex = 0, so bufferIndex will still be
3411  // computed correctly
3412  size_t kStart = 0;
3413  size_t kEnd = 0;
3414  if (numDim == 3) {
3415  kStart = partitionBufferInterval[2].first;
3416  kEnd = partitionBufferInterval[2].second;
3417  }
3418 
3419  for (size_t kIndex = kStart; kIndex <= kEnd; kIndex++) {
3420  size_t kBufferIndex = kIndex*bufferSizes[0]*bufferSizes[1];
3421  for (size_t jIndex = jStart; jIndex <= jEnd; jIndex++) {
3422  size_t jBufferIndex = jIndex*bufferSizes[0] + kBufferIndex;
3423  for (size_t iIndex = iStart; iIndex <= iEnd; iIndex++) {
3424  size_t bufferIndex = jBufferIndex + iIndex;
3425 
3426  //*messageStream << "before cloc, i = " << iIndex << ", j = " << jIndex
3427  // << ", k = " << kIndex << std::endl;
3428  //*messageStream << " bufferIndex = " << bufferIndex << std::endl;
3429  //*messageStream << " jumpDim = " << jumpDim << std::endl;
3430  //*messageStream << " gridCoords.size() = " << gridCoords.size() << std::endl;
3431  double cloc = gridCoords[bufferIndex + (jumpDim-1)*numPointsBuffer];
3432  //*messageStream << "after cloc, i = " << iIndex << ", j = " << jIndex
3433  // << ", k = " << kIndex << std::endl;
3434 
3435  if (cloc > loc1 && cloc < loc2) {
3436  rhoPtr[bufferIndex] = rhoL;
3437  // V is zero in non-jump directions
3438  // for (int vDim=0; vDim<numDim; vDim++) {
3439  rhoVPtr[bufferIndex + (jumpDim-1)*numPointsBuffer] = rhoVL;
3440  // }
3441  rhoEPtr[bufferIndex] = rhoEL;
3442  } else {
3443  rhoPtr[bufferIndex] = rhoR;
3444  // V is zero in non-jump directions
3445  // for (int vDim=0; vDim<numDim; vDim++) {
3446  rhoVPtr[bufferIndex + (jumpDim-1)*numPointsBuffer] = rhoVR;
3447  // }
3448  rhoEPtr[bufferIndex] = rhoER;
3449  }
3450  }
3451  }
3452  }
3453  return(0);
3454  };
3455 
3456  template<typename GridType,typename StateType>
3457  int InitializeShocktube(const GridType &inGrid,StateType &inState,
3458  StateType &paramState,const std::vector<double> &inParams,
3459  const std::vector<int> &inFlags,int threadId)
3460  {
3461 
3462  double M_init = 0.0;
3463 
3464  int numParams = inParams.size();
3465  if(!(numParams >= 1))
3466  return(1);
3467  if(numParams > 0)
3468  M_init = inParams[0];
3469 
3470  //if(!inFlags.empty()){
3471  // jumpDim = inFlags[0];
3472  //}
3473 
3474  size_t numPointsBuffer = inGrid.BufferSize();
3475  const std::vector<size_t> &bufferSizes(inGrid.BufferSizes());
3476  const std::vector<size_t> &gridSizes(inGrid.GridSizes());
3477  const pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
3478  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
3479  const std::vector<simulation::grid::subregion> &gridSubRegions(inGrid.SubRegions());
3480  const std::vector<double> &dX(inGrid.DX());
3481  const std::vector<double> &gridCoords(inGrid.CoordinateData());
3482  const std::vector<double> &physicalExtent(inGrid.PhysicalExtent());
3483  int numDim = gridSizes.size();
3484 
3485 
3486  pcpp::IndexIntervalType gridInterval;
3487  gridInterval.InitSimple(gridSizes);
3488 
3489 
3490  int rhoHandle = inState.GetDataIndex("rho");
3491  if(rhoHandle < 0)
3492  return(1);
3493  pcpp::field::dataset::DataBufferType &rhoData(inState.Field(rhoHandle));
3494  double *rhoPtr = rhoData.Data<double>();
3495  if(!rhoPtr)
3496  return(1);
3497 
3498  int rhoVHandle = inState.GetDataIndex("rhoV");
3499  if(rhoVHandle < 0)
3500  return(1);
3501  pcpp::field::dataset::DataBufferType &rhoVData(inState.Field(rhoVHandle));
3502  double *rhoVPtr = rhoVData.Data<double>();
3503  if(!rhoVPtr)
3504  return(1);
3505 
3506  int rhoEHandle = inState.GetDataIndex("rhoE");
3507  if(rhoEHandle < 0)
3508  return(1);
3509  pcpp::field::dataset::DataBufferType &rhoEData(inState.Field(rhoEHandle));
3510  double *rhoEPtr = rhoEData.Data<double>();
3511  if(!rhoPtr)
3512  return(1);
3513 
3514 
3515  double *gammaPtr = paramState.template GetFieldBuffer<double>("gamma");
3516  double gamma = *gammaPtr;
3517 
3518  // Zero entire buffer(s)
3519  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++){
3520  rhoPtr[iPoint] = 0.0;
3521  rhoEPtr[iPoint] = 0.0;
3522  }
3523  for(int iDim = 0;iDim < numDim;iDim++){
3524  size_t dimOffset = iDim*numPointsBuffer;
3525  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++)
3526  rhoVPtr[iPoint+dimOffset] = 0.0;
3527  }
3528 
3529  // reference values
3530  double rhoRef = 0.42869404474479600;
3531  double TRef = 298.15;
3532  double R = 286.9;
3533  double gm1 = gamma - 1;
3534  double gp1 = gamma + 1;
3535 
3536  // constants for shock smoothing
3537  double C = 4.5951198501345889;
3538  double delta1 = 0.05;
3539 
3540  double rho1 = rhoRef;
3541  double T1 = TRef;
3542  double p1 = rho1*R*T1;
3543  double a1 = std::sqrt(gamma*R*T1);
3544  double M1 = M_init*M_init;
3545 
3546  double rho2 = rhoRef*(gp1*M1)/(gm1*M1 + 2);
3547  double p2 = p1*(2*gamma*M1 - gm1)/gp1;
3548  double T2 = T1*(p2*rho1)/(rho2*p1);
3549  double M2 = (gm1*M1 + 2)/(2*gamma*M1 - gm1);
3550  double u2 = M_init*a1 - std::sqrt(M2*gamma*R*T2);
3551 
3552  // since we are using a periodic domain, need to define another location
3553  // for a second discontinuity
3554  double xn = -4.5;
3555 
3556  size_t iStart = partitionBufferInterval[0].first;
3557  size_t iEnd = partitionBufferInterval[0].second;
3558  size_t jStart = partitionBufferInterval[1].first;
3559  size_t jEnd = partitionBufferInterval[1].second;
3560 
3561  // if numDim == 2 this will set kIndex = 0, so bufferIndex will still be
3562  // computed correctly
3563  size_t kStart = 0;
3564  size_t kEnd = 0;
3565  if (numDim == 3) {
3566  kStart = partitionBufferInterval[2].first;
3567  kEnd = partitionBufferInterval[2].second;
3568  }
3569 
3570  for (size_t kIndex = kStart; kIndex <= kEnd; kIndex++) {
3571  size_t kBufferIndex = kIndex*bufferSizes[0]*bufferSizes[1];
3572  for (size_t jIndex = jStart; jIndex <= jEnd; jIndex++) {
3573  size_t jBufferIndex = jIndex*bufferSizes[0] + kBufferIndex;
3574  for (size_t iIndex = iStart; iIndex <= iEnd; iIndex++) {
3575  size_t bufferIndex = jBufferIndex + iIndex;
3576 
3577  double x = gridCoords[bufferIndex];
3578  double eta;
3579  if (x > -0.1) {
3580  eta = 0.5*(1 + std::tanh(C*x/delta1));
3581  } else {
3582  eta = 0.5*(1 + std::tanh(C*(xn-x)/delta1));
3583  }
3584 
3585  rhoPtr[bufferIndex] = ((1-eta)*rho2 + eta*rho1)/rhoRef;
3586  // V is zero in y,z directions
3587  // for (int vDim=0; vDim<numDim; vDim++) {
3588  //rhoVPtr[bufferIndex + (vDim-1)*numPointsBuffer] = rhoV;
3589  rhoVPtr[bufferIndex] = ((1-eta)*rho2*u2)/(rhoRef*a1);
3590  // }
3591  rhoEPtr[bufferIndex] = ((1-eta)*(p2/gm1 + 0.5*rho2*u2*u2) + eta*(p1/gm1))/(rhoRef*a1*a1);
3592  }
3593  }
3594  }
3595  return(0);
3596  };
3597 
3599  template<typename GridType,typename StateType,typename BoundaryType>
3600  int InitializeHoles(const GridType &inGrid,StateType &inState,
3601  StateType &inParam,std::vector<BoundaryType> &inBoundaries)
3602  {
3603  size_t numPointsBuffer = inGrid.BufferSize();
3604  const std::vector<size_t> &bufferSizes(inGrid.BufferSizes());
3605  const std::vector<double> &dX(inGrid.DX());
3606  const std::vector<size_t> &gridSizes(inGrid.GridSizes());
3607  const pcpp::IndexIntervalType &partitionInterval(inGrid.PartitionInterval());
3608  const pcpp::IndexIntervalType &partitionBufferInterval(inGrid.PartitionBufferInterval());
3609 
3610  int numDim = gridSizes.size();
3611 
3612  double *timePtr = inState.template GetFieldBuffer<double>("simTime");
3613  double *deltaTPtr = inParam.template GetFieldBuffer<double>("inputDT");
3614  double *gammaPtr = inParam.template GetFieldBuffer<double>("gamma");
3615  double *CFLPtr = inParam.template GetFieldBuffer<double>("inputCFL");
3616  double *cRefPtr = inParam.template GetFieldBuffer<double>("refC");
3617 
3618  double cflValue = *CFLPtr;
3619  double cRefValue = *cRefPtr;
3620  double gammaValue = *gammaPtr;
3621 
3622 
3623  int rhoHandle = inState.GetDataIndex("rho");
3624  if(rhoHandle < 0)
3625  return(1);
3626  pcpp::field::dataset::DataBufferType &rhoData(inState.Field(rhoHandle));
3627  double *rhoPtr = rhoData.Data<double>();
3628  if(!rhoPtr)
3629  return(1);
3630 
3631  int rhoVHandle = inState.GetDataIndex("rhoV");
3632  if(rhoVHandle < 0)
3633  return(1);
3634  pcpp::field::dataset::DataBufferType &rhoVData(inState.Field(rhoVHandle));
3635  double *rhoVPtr = rhoVData.Data<double>();
3636  if(!rhoVPtr)
3637  return(1);
3638 
3639  int rhoEHandle = inState.GetDataIndex("rhoE");
3640  if(rhoEHandle < 0)
3641  return(1);
3642  pcpp::field::dataset::DataBufferType &rhoEData(inState.Field(rhoEHandle));
3643  double *rhoEPtr = rhoEData.Data<double>();
3644  if(!rhoPtr)
3645  return(1);
3646 
3647 
3649  // Quiescent and non-singular
3650  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++){
3651  rhoPtr[iPoint] = 1.0;
3652  rhoEPtr[iPoint] = 1.0/(gammaValue-1.0);
3653  }
3654  for(int iDim = 0;iDim < numDim;iDim++){
3655  size_t dimOffset = iDim*numPointsBuffer;
3656  for(size_t iPoint = 0;iPoint < numPointsBuffer;iPoint++)
3657  rhoVPtr[iPoint+dimOffset] = 0.0;
3658  }
3659 
3660  return(0);
3661  };
3662  }
3663 }
3664 #endif
3665 // typename std::vector<BoundaryType>::iterator boundIt = inBoundaries.begin();
3666 
3667 // int numBoundaries = 0;
3668 // while(boundIt != inBoundaries.end()){
3669 
3670 // BoundaryType &domainBoundary(*boundIt++);
3671 // std::string boundaryName(domainBoundary.Name());
3672 // int gridRegionID = domainBoundary.GridRegionID();
3673 
3674 // const simulation::grid::subregion &subRegion(gridSubRegions[gridRegionID]);
3675 // const pcpp::IndexIntervalType &subRegionInterval(subRegion.regionInterval);
3676 // const pcpp::IndexIntervalType &subRegionPartitionInterval(subRegion.regionPartitionInterval);
3677 // const pcpp::IndexIntervalType &subRegionPartitionBufferInterval(subRegion.regionPartitionBufferInterval);
3678 
3679 // if(subRegionPartitionInterval.NNodes() == 0){
3680 // messageStream << "ProtoY4Test1: Empty boundary: " << boundaryName << std::endl;
3681 // continue;
3682 // }
3683 
3684 
3685 // // if(boundaryName == "HoleLower" || boundaryName == "Bottom" ){
3686 // if(boundaryName == "ChamberBottom" || boundaryName == "ChamberTop"){
3687 
3688 // numBoundaries++;
3689 
3690 // // Select only "my" part of the combustion chamber
3691 // // if(boundaryName == "HoleLower")
3692 // // combustionChamberInterval[0].first = subRegionInterval[0].second + 1;
3693 // combustionChamberInterval[0] = subRegionInterval[0];
3694 // combustionChamberInterval.Overlap(partitionInterval,chamberPartitionInterval);
int ComputeDVBuffer(const pcpp::IndexIntervalType &regionInterval, const std::vector< size_t > &bufferSizes, const std::vector< double *> &stateBuffers, std::vector< double *> &dvBuffers)
Definition: EulerUtil.C:153
void size_t int size_t int size_t int int int int double int int double double *void size_t int size_t int int int int int double int size_t size_t size_t double double *void size_t int size_t int size_t size_t int double int double double *void size_t size_t * bufferSize
int InitializeConvectingVortex(const GridType &inGrid, StateType &inState, StateType &inParam, const std::vector< double > &inParams, const std::vector< int > &inFlags, int threadId)
Definition: EulerUtil.H:1507
pcpp::IndexIntervalType regionInterval
Definition: Grid.H:39
int InitializeAcousticPulse(const GridType &inGrid, StateType &inState, StateType &inParam, const std::vector< double > &inParams, const std::vector< int > &inFlags, int threadId, std::ostream *messageStream)
Definition: EulerUtil.H:1635
int ValidateState(const DatasetType &inState, const DatasetType &inParam, std::ostream &outStream)
Definition: EulerUtil.H:442
int InitializeGaussianScalar(const GridType &inGrid, StateType &inState, StateType &inParamState, const std::vector< double > &inParams, int threadId, std::ostream *messageStream=NULL)
Definition: EulerUtil.H:2110
void const size_t const size_t const size_t const int const int const double const double const double * rhoVBuffer
Definition: EulerKernels.H:10
Definition: Euler.f90:1
int InitializeAdvectionDiffusion(const GridType &inGrid, StateType &inState, StateType &inParamState, const std::vector< double > &inParams, int threadId, std::ostream *messageStream=NULL)
Definition: EulerUtil.H:2431
int InitializeProtoY4Test1(const GridType &inGrid, StateType &inState, StateType &inParamState, std::vector< BoundaryType > &inBoundaries, const std::vector< double > &inParams, const std::vector< int > &inFlags, int threadId)
Definition: EulerUtil.H:1122
int ComputeDVBuffer2(const int *numDimPtr, const size_t *bufferSize, const size_t *numPointsPtr, const size_t *bufferInterval, const double *rhoBuffer, const double *rhoVBuffer, const double *rhoEBuffer, double *pressureBuffer, double *tempBuffer, double *rhom1Buffer, double *velBuffer)
Definition: EulerUtil.C:285
void const size_t const size_t * gridSizes
Definition: EulerKernels.H:10
void RenewStream(std::ostringstream &outStream)
double Window(double tWidth, double wWidth, double centerX, double centerY, double centerZ, double x, double y, double z)
Definition: EulerUtil.H:66
void const size_t const size_t const size_t const double const double double * y
int InitializeQuiescentState(const GridType &inGrid, StateType &inState, StateType &inParam, int threadId, std::ostream *messageStream=NULL)
Definition: EulerUtil.H:563
void CartesianSetup(std::ostream &outStream, const std::vector< int > &cartCoords, const std::vector< int > &cartDims)
Definition: PCPPReport.C:199
int InitializeHoles(const GridType &inGrid, StateType &inState, StateType &inParam, std::vector< BoundaryType > &inBoundaries)
Definition: EulerUtil.H:3600
int SetupEulerState(const GridType &inGrid, StateType &inState, StateType &inParams, int numScalars, bool withFlux=false)
Definition: EulerUtil.H:374
void const size_t const size_t const size_t const int const double const int const double * velocity
Definition: MetricKernels.H:19
int InitializeUniformFlow(const GridType &inGrid, StateType &inState, StateType &inParamState, const std::vector< double > &inParams, int threadId, std::ostream *messageStream=NULL)
Definition: EulerUtil.H:2666
int InitializeShocktube(const GridType &inGrid, StateType &inState, StateType &paramState, const std::vector< double > &inParams, const std::vector< int > &inFlags, int threadId)
Definition: EulerUtil.H:3457
void const size_t const size_t const size_t const double const double * x
size_t NNodes() const
Definition: IndexUtil.H:254
void const size_t const size_t const size_t const int const int const double const double const double const double * rhoEBuffer
Definition: EulerKernels.H:10
std::vector< int > isPeriodic
Definition: PCPPCommUtil.H:24
void Everyone(const std::string &outString, std::ostream &outStream, fixtures::CommunicatorType &comm)
Definition: PCPPIO.C:51
void const size_t const size_t const size_t const int const int const double const double const double const double const double const double * pressureBuffer
Definition: EulerKernels.H:10
double Parabola(double amp, double centerX, double centerY, double centerZ, double x, double y, double z)
Definition: EulerUtil.H:80
int InitializeSimulationFixtures(GridType &inGrid, plascom2::operators::sbp::base &inOperator, int interiorOrder, pcpp::CommunicatorType &inComm, std::ostream *messageStreamPtr=NULL)
Definition: EulerUtil.H:218
int CreateSimulationFixtures(GridType &inGrid, HaloType &inHalo, plascom2::operators::sbp::base &inOperator, const std::vector< size_t > &gridSizes, int interiorOrder, pcpp::CommunicatorType &inComm, std::ostream *messageStreamPtr=NULL)
Definition: EulerUtil.H:92
Main encapsulation of MPI.
Definition: COMM.H:62
sizeextent RelativeTranslation(const sizeextent &inOrigin, const sizeextent &inDestination) const
Definition: IndexUtil.H:535
Encapsulation for a collection of operator stencils.
Definition: Stencil.H:26
void Overlap(const sizeextent &inextent, sizeextent &outextent) const
Definition: IndexUtil.H:324
int InitializeDensityPulse(const GridType &inGrid, StateType &inState, StateType &inParamState, const std::vector< double > &inParams, int threadId, std::ostream *messageStream=NULL)
Definition: EulerUtil.H:1870
void DumpContents(std::ostream &Ostr, const ContainerType &c, std::string del="\)
Dump container contents.
Definition: AppTools.H:117
void const size_t const size_t * bufferSizes
Definition: MetricKernels.H:19
int InitializeRiemann1D(const GridType &inGrid, StateType &inState, StateType &paramState, const std::vector< double > &inParams, const std::vector< int > &inFlags, int threadId)
Definition: EulerUtil.H:3300
void const size_t const size_t const size_t const int * numScalars
Definition: EulerKernels.H:17
void size_t int size_t int size_t int int int int double int int double double *void size_t int size_t int int int int int double int size_t size_t size_t double double *void size_t int size_t int size_t size_t int double int double double *void size_t size_t size_t * bufferInterval
int PartitionCartesianInterval(const pcpp::IndexIntervalType &globalExtent, const std::vector< int > &cartDims, const std::vector< int > &cartCoords, pcpp::IndexIntervalType &partExtent, std::ostream &messageStream)
Get local sub-interval of an n-dimensional integer interval.
std::string ConfigKey(const std::string &configName, const std::string &keyName)
Definition: PCPPUtil.C:191
std::ostream & PrettyPrint(std::ostream &outStream) const
Definition: IndexUtil.C:6
int SetupCartesianTopology(pcpp::CommunicatorType &parallelCommunicator, pcpp::ParallelTopologyInfoType &topologyInfo, pcpp::CommunicatorType &topoCommunicator, std::ostream &messageStream)
Sets up a communicator with Cartesian topology.
Definition: PCPPCommUtil.C:48
int Initialize(base &stencilSet, int interiorOrder)
Initialize the sbp::base stencilset with the SBP operator of given order.
Definition: Stencil.C:360
void const size_t const size_t const size_t const int const int const double const double * rhoBuffer
Definition: EulerKernels.H:10
Simple Block Structured Mesh object.
Definition: IndexUtil.H:21
int boundaryDepth
Boundary depth is the number of biased boundary stencils for one boundary.
Definition: Stencil.H:114
int InitializeShock1D(const GridType &inGrid, StateType &inState, StateType &inParamState, const std::vector< double > &inParams, int threadId, std::ostream *messageStream)
Definition: EulerUtil.H:842
void InitSimple(const ContainerType &inSize)
Definition: IndexUtil.H:169
void const size_t * numPointsBuffer
Definition: MetricKernels.H:19
double Pulse(double amp, double width, double centerX, double centerY, double centerZ, double x, double y, double z)
Definition: EulerUtil.H:56