1 #ifndef __EULER_UTIL_H__ 2 #define __EULER_UTIL_H__ 38 const std::vector<double *> &stateBuffers,
39 std::vector<double *> &dvBuffers);
46 const size_t *numPointsPtr,
56 inline double Pulse(
double amp,
double width,
double centerX,
57 double centerY,
double centerZ,
double x,
double y,
double z)
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));
66 inline double Window(
double tWidth,
double wWidth,
67 double centerX,
double centerY,
double centerZ,
68 double x,
double y,
double z)
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;
80 inline double Parabola(
double amp,
double centerX,
81 double centerY,
double centerZ,
double x,
double y,
double z)
83 double xTerm = (x-centerX);
84 double yTerm = (y-centerY);
85 double zTerm = (z-centerZ);
86 double eTerm = zTerm*zTerm + xTerm*xTerm + yTerm*yTerm;
91 template<
typename Gr
idType,
typename HaloType>
97 std::ostream *messageStreamPtr = NULL)
100 int numProc = inComm.
Size();
101 int myRank = inComm.
Rank();
103 if(!messageStreamPtr)
104 messageStreamPtr = &std::cout;
108 int numDim = gridSizes.size();
109 std::vector<double> dX(numDim,0);
110 size_t numGlobalNodes = 1;
111 size_t numGlobalCells = 1;
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);
119 inGrid.SetGridSizes(gridSizes);
120 inGrid.SetGridSpacings(dX);
125 std::vector<int> haloDepths(2*numDim,boundaryDepth);
135 std::vector<int> &cartCoords(gridComm.CartCoordinates());
136 std::vector<int> &cartDims(gridComm.CartDimensions());
147 partitionInterval,*messageStreamPtr)){
148 *messageStreamPtr <<
"TestFixtures:SetupSimulationFixtures:Error: Partitioning failed." << std::endl;
152 std::vector<size_t> extendGrid(2*numDim,0);
153 std::vector<bool> isPeriodic(numDim,
true);
154 size_t numPointsPart = partitionInterval.NNodes();
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];
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];
168 inGrid.SetDimensionExtensions(extendGrid);
169 if(inGrid.Finalize()){
170 *messageStreamPtr <<
"TestFixtures:SetupSimulationFixtures:Error: Grid finalization failed." << std::endl;
174 const std::vector<size_t> &
bufferSizes(inGrid.BufferSizes());
180 inHalo.SetGridInterval(globalInterval);
181 inHalo.SetPartitionInterval(partitionInterval);
185 std::vector<bool> haveNeighbors(2*numDim,
true);
186 inHalo.SetNeighbors(haveNeighbors);
188 std::vector<pcpp::IndexIntervalType> remoteHaloExtents(inHalo.CreateRemoteHaloExtents(extendGrid));
189 std::vector<pcpp::IndexIntervalType> localHaloExtents(inHalo.CreateLocalHaloExtents(extendGrid));
191 inHalo.SetLocalBufferSizes(bufferSizes);
192 inHalo.SetLocalPartitionExtent(partitionBufferInterval);
194 inHalo.SetRemoteHaloExtents(remoteHaloExtents);
195 inHalo.SetLocalHaloExtents(localHaloExtents);
197 const std::vector<pcpp::IndexIntervalType> &remoteHaloBufferExtents(inHalo.RemoteHaloBufferExtents());
198 const std::vector<pcpp::IndexIntervalType> &localHaloBufferExtents(inHalo.LocalHaloBufferExtents());
200 inHalo.CreateSimpleSendIndices();
201 inHalo.CreateSimpleRecvIndices();
217 template<
typename Gr
idType>
222 std::ostream *messageStreamPtr = NULL)
224 typedef typename GridType::HaloType HaloType;
226 int numProc = inComm.
Size();
227 int myRank = inComm.
Rank();
229 if(!messageStreamPtr)
230 messageStreamPtr = &std::cout;
234 std::vector<size_t> &
gridSizes(inGrid.GridSizes());
235 std::vector<double> &physicalExtent(inGrid.PhysicalExtent());
236 std::vector<bool> &isPeriodic(inGrid.PeriodicDirs());
239 std::vector<double> dX(numDim,0);
240 size_t numGlobalNodes = 1;
241 size_t numGlobalCells = 1;
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;
249 if(isPeriodic.empty()){
250 isPeriodic.resize(numDim,
true);
253 for(
int iDim = 0;iDim < numDim;iDim++){
256 dX[iDim] = (physicalExtent[2*iDim+1]-physicalExtent[2*iDim])/static_cast<double>(
gridSizes[iDim]-1);
259 inGrid.SetGridSpacings(dX);
264 std::vector<int> haloDepths(2*numDim,boundaryDepth);
271 for(
int iDim = 0;iDim < numDim;iDim++)
272 pbsCartInfo.
isPeriodic[iDim] = isPeriodic[iDim];
277 std::vector<int> &cartCoords(gridComm.CartCoordinates());
278 std::vector<int> &cartDims(gridComm.CartDimensions());
280 std::vector<int> gridNeighbors;
281 gridComm.CartNeighbors(gridNeighbors);
293 partitionInterval,*messageStreamPtr)){
294 *messageStreamPtr <<
"TestFixtures:SetupSimulationFixtures:Error: Partitioning failed." << std::endl;
298 std::vector<size_t> extendGrid(2*numDim,0);
300 size_t numPointsPart = partitionInterval.NNodes();
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];
308 if(partitionInterval[iDim].first == 0) {
309 haveNeighbors[2*iDim] =
false;
311 extendGrid[2*iDim] = haloDepths[2*iDim];
313 if(partitionInterval[iDim].second == (
gridSizes[iDim]-1)){
314 haveNeighbors[2*iDim+1] =
false;
316 extendGrid[2*iDim + 1] = haloDepths[2*iDim+1];
321 inGrid.SetDimensionExtensions(extendGrid);
324 if(inGrid.Finalize()){
325 *messageStreamPtr <<
"TestFixtures:SetupSimulationFixtures:Error: Grid finalization failed." << std::endl;
329 if(inGrid.GenerateCoordinates(*messageStreamPtr)){
330 *messageStreamPtr <<
"TestFixtures:SetupSimulationFixtures:Error: Grid coordinates generation failed." 335 const std::vector<size_t> &
bufferSizes(inGrid.BufferSizes());
341 HaloType &inHalo(inGrid.Halo());
342 inHalo.SetGridInterval(globalInterval);
343 inHalo.SetPartitionInterval(partitionInterval);
344 inHalo.SetPeriodicDirs(pbsCartInfo.
isPeriodic);
348 int rank = gridComm.Rank();
349 int numProcGrid = gridComm.NProc();
351 inHalo.SetNeighbors(haveNeighbors);
353 std::vector<pcpp::IndexIntervalType> remoteHaloExtents(inHalo.CreateRemoteHaloExtents(extendGrid));
354 std::vector<pcpp::IndexIntervalType> localHaloExtents(inHalo.CreateLocalHaloExtents(extendGrid));
356 inHalo.SetLocalBufferSizes(bufferSizes);
357 inHalo.SetLocalPartitionExtent(partitionBufferInterval);
359 inHalo.SetRemoteHaloExtents(remoteHaloExtents);
360 inHalo.SetLocalHaloExtents(localHaloExtents);
362 const std::vector<pcpp::IndexIntervalType> &remoteHaloBufferExtents(inHalo.RemoteHaloBufferExtents());
363 const std::vector<pcpp::IndexIntervalType> &localHaloBufferExtents(inHalo.LocalHaloBufferExtents());
365 inHalo.CreateSimpleSendIndices();
366 inHalo.CreateSimpleRecvIndices();
373 template<
typename Gr
idType,
typename StateType>
375 bool withFlux =
false)
379 const std::vector<size_t> &
bufferSizes(inGrid.BufferSizes());
380 const std::vector<size_t> &
gridSizes(inGrid.GridSizes());
383 const std::vector<double> &dX(inGrid.DX());
384 int numDim = bufferSizes.size();
386 inState.AddField(
"simTime",
's',1,8,
"s");
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");
394 inState.AddField(
"scalarVars",
'n',numScalars,8,
"m/M");
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");
410 inState.AddField(
"massFlux",
'n',numDim,8,
"");
411 inState.AddField(
"mom1Flux",
'n',numDim,8,
"");
412 inState.AddField(
"mom2Flux",
'n',numDim,8,
"");
414 inState.AddField(
"mom3Flux",
'n',3,8,
"");
416 inState.AddField(
"energyFlux",
'n',3,8,
"");
418 inState.AddField(
"scalarVarsFlux",
'n',numScalars,8,
"");
421 inState.Create(numPointsBuffer,0);
423 inState.SetStateFields(
"rho rhoV rhoE");
425 inState.SetStateFields(
"rho rhoV rhoE scalarVars");
428 inParams.AddField(
"gamma",
's',1,8,
"");
429 inParams.AddField(
"inputDT",
's',1,8,
"s");
430 inParams.AddField(
"inputCFL",
's',1,8,
"");
433 inParams.AddField(
"refRe",
's',1,8,
"ReynoldsNo");
434 inParams.AddField(
"refPr",
's',1,8,
"PrandtlNo");
436 inParams.Create(numPointsBuffer,0);
441 template<
typename DatasetType>
443 const DatasetType &inParam,
444 std::ostream &outStream)
462 int dataHandle = inState.GetDataIndex(
"rho");
466 dataHandle = inState.GetDataIndex(
"rhoV");
470 dataHandle = inState.GetDataIndex(
"rhoE");
474 dataHandle = inState.GetDataIndex(
"simTime");
478 dataHandle = inParam.GetDataIndex(
"inputDT");
482 dataHandle = inParam.GetDataIndex(
"inputCFL");
486 dataHandle = inParam.GetDataIndex(
"refRho");
488 dataFaults |= REFRHO;
490 dataHandle = inParam.GetDataIndex(
"refPressure");
494 dataHandle = inParam.GetDataIndex(
"refTemperature");
498 dataHandle = inParam.GetDataIndex(
"refRe");
502 dataHandle = inParam.GetDataIndex(
"gamma");
506 dataHandle = inParam.GetDataIndex(
"refLength");
510 dataHandle = inParam.GetDataIndex(
"nonDimensional");
517 outStream <<
"Required data \"rho\" did not exist in state." << std::endl;
521 outStream <<
"Required data \"rhoV\" did not exist in state." << std::endl;
525 outStream <<
"Required data \"rhoE\" did not exist in state." << std::endl;
529 outStream <<
"Required data \"simTime\" did not exist in state." << std::endl;
533 outStream <<
"Parameter data \"inputDT\" did not exist." << std::endl;
535 if(dataFaults&INCFL){
536 outStream <<
"Parameter data \"inputCFL\" did not exist." << std::endl;
539 outStream <<
"Parameter data \"refLength\" did not exist." << std::endl;
542 outStream <<
"Parameter data \"refPressure\" did not exist." << std::endl;
545 outStream <<
"Parameter data \"refTemperature\" did not exist." << std::endl;
547 if(dataFaults&REFRHO){
548 outStream <<
"Parameter data \"refRho\" did not exist." << std::endl;
550 if(dataFaults&GAMMA){
551 outStream <<
"Parameter data \"gamma\" did not exist." << std::endl;
554 outStream <<
"Parameter data \"nonDimensional\" did not exist." << std::endl;
556 if(dataFaults&REFRE){
557 outStream <<
"Parameter data \"refRe\" did not exist." << std::endl;
562 template<
typename Gr
idType,
typename StateType>
564 StateType &inParam,
int threadId,std::ostream *messageStream = NULL)
567 messageStream = &std::cout;
569 std::ostringstream Ostr;
571 std::cout <<
"Input State in Error:" << std::endl;
572 *messageStream << Ostr.str() << std::endl;
575 *messageStream <<
"Input State Validation: " << std::endl
576 << Ostr.str() << std::endl;
579 int rhoHandle = inState.GetDataIndex(
"rho");
583 double *rhoPtr = rhoData.
Data<
double>();
587 int rhoVHandle = inState.GetDataIndex(
"rhoV");
591 double *rhoVPtr = rhoVData.
Data<
double>();
595 int rhoEHandle = inState.GetDataIndex(
"rhoE");
599 double *rhoEPtr = rhoEData.
Data<
double>();
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());
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;
624 int dataHandle = inState.GetDataIndex(
"simTime");
626 inState.AddField(
"simTime",
'd',1,8,
"time");
629 timePtr = inState.template GetFieldBuffer<double>(
"simTime");
633 dataHandle = inParam.GetDataIndex(
"inputDT");
635 inParam.AddField(
"inputDT",
'd',1,8,
"time");
638 deltaTPtr = inParam.template GetFieldBuffer<double>(
"inputDT");
640 dataHandle = inParam.GetDataIndex(
"gamma");
642 inParam.AddField(
"gamma",
'd',1,8,
"");
645 gammaPtr = inParam.template GetFieldBuffer<double>(
"gamma");
647 dataHandle = inParam.GetDataIndex(
"inputCFL");
649 inParam.AddField(
"inputCFL",
'd',1,8,
"");
652 CFLPtr = inParam.template GetFieldBuffer<double>(
"inputCFL");
654 dataHandle = inParam.GetDataIndex(
"refLength");
656 inParam.AddField(
"refLength",
'd',1,8,
"length");
659 lengthRefPtr = inParam.template GetFieldBuffer<double>(
"refLength");
661 dataHandle = inParam.GetDataIndex(
"refRho");
663 inParam.AddField(
"refRho",
'd',1,8,
"density");
666 rhoRefPtr = inParam.template GetFieldBuffer<double>(
"refRho");
668 dataHandle = inParam.GetDataIndex(
"refPressure");
670 inParam.AddField(
"refPressure",
'd',1,8,
"pressure");
673 presRefPtr = inParam.template GetFieldBuffer<double>(
"refPressure");
675 dataHandle = inParam.GetDataIndex(
"refTemperature");
677 inParam.AddField(
"refTemperature",
'd',1,8,
"temperature");
680 tempRefPtr = inParam.template GetFieldBuffer<double>(
"refTemperature");
682 dataHandle = inParam.GetDataIndex(
"sigma");
684 inParam.AddField(
"sigma",
'd',1,8,
"");
687 sigmaPtr = inParam.template GetFieldBuffer<double>(
"sigma");
689 dataHandle = inParam.GetDataIndex(
"refRe");
691 inParam.AddField(
"refRe",
'd',1,8,
"ReynoldsNo");
694 rePtr = inParam.template GetFieldBuffer<double>(
"refRe");
696 dataHandle = inParam.GetDataIndex(
"nonDimensional");
698 inParam.AddField(
"nonDimensional",
'd',1,4,
"");
701 nonDimenPtr = inParam.template GetFieldBuffer<int>(
"nonDimensional");
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;
716 double gammaValue = 1.4;
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;
726 *tempRefPtr = 288.15;
728 *messageStream <<
"Reference state: " << std::endl
729 <<
"\t Density = " << *rhoRefPtr << std::endl
730 <<
"\t Pressure = " << *presRefPtr << std::endl
731 <<
"\t Temperature = " << *tempRefPtr << std::endl;
734 if(*CFLPtr < 0 || *CFLPtr > 4)
739 if(*gammaPtr < 0 || *gammaPtr > 4)
740 *gammaPtr = gammaValue;
742 gammaValue = *gammaPtr;
743 double cRef = sqrt(gammaValue*(*presRefPtr)/(*rhoRefPtr));
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
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;
757 *deltaTPtr = minSpacing*(*CFLPtr)/(cRef);
762 rhoPtr[iPoint] = 0.0;
763 rhoEPtr[iPoint] = 0.0;
765 for(
int iDim = 0;iDim < numDim;iDim++){
768 rhoVPtr[iPoint+dimOffset] = 0.0;
771 std::vector<double> rhoV(numDim,0.0);
775 double pressure = 1.0;
778 pressure = *presRefPtr;
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));
789 double rhoE = rho*(eInternal + eKinetic);
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];
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];
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];
841 template<
typename Gr
idType,
typename StateType>
843 StateType &inParamState,
const std::vector<double> &inParams,
int threadId,
844 std::ostream *messageStream)
847 messageStream = &std::cout;
853 double location = 0.1;
854 double transitionWidth = 0.0;
856 int referenceFrame = 0;
858 int numParams = inParams.size();
862 direction =
static_cast<int>(inParams[1]);
864 location = inParams[2];
866 transitionWidth = inParams[3];
868 referenceFrame = inParams[4];
870 int rhoHandle = inState.GetDataIndex(
"rho");
874 double *rhoPtr = rhoData.
Data<
double>();
878 int rhoVHandle = inState.GetDataIndex(
"rhoV");
882 double *rhoVPtr = rhoVData.
Data<
double>();
886 int rhoEHandle = inState.GetDataIndex(
"rhoE");
890 double *rhoEPtr = rhoEData.
Data<
double>();
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());
901 const std::vector<double> &coordinateData(inGrid.CoordinateData());
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");
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);
924 rhoPtr[iPoint] = 0.0;
925 rhoEPtr[iPoint] = 0.0;
927 for(
int iDim = 0;iDim < numDim;iDim++){
930 rhoVPtr[iPoint+dimOffset] = 0.0;
933 double xMin = readGridExtent[0];
934 double xMax = readGridExtent[1];
935 double yMin = readGridExtent[2];
936 double yMax = readGridExtent[3];
940 zMin = readGridExtent[4];
941 zMax = readGridExtent[5];
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;
956 double velocity1 = 0.;
957 double velocity2 = -mach*sndSpdRef*(1/densityRatio-1);
959 if(referenceFrame == 1) {
960 velocity1 = -mach*sndSpdRef;
961 velocity2 = velocity1/densityRatio;
964 std::vector<double> rhoV(numDim,0.0);
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;
983 double rhoE1 = pressure1/(gamma-1.0) + 0.5*rho1*velocity1*velocity1;
984 double rhoE2 = pressure2/(gamma-1.0) + 0.5*rho2*velocity2*velocity2;
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;
991 *messageStream <<
"Invalid reference frame selection. " 992 <<
"Must be 0 (lab reference) or 1 (shock attached)." << std::endl;
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;
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;
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];
1039 double position = 0.;
1040 if(direction == 1) {
1042 }
else if(direction == 2) {
1044 }
else if(direction == 3) {
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;
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];
1075 double position = 0.;
1076 if(direction == 1) {
1078 }
else if(direction == 2) {
1082 double transitionFactor = (1-std::tanh((position-transitionPoint)/transitionWidth))/2.0;
1084 rhoPtr[bufferIndex] = rho1+(rho2-rho1)*transitionFactor;
1085 rhoEPtr[bufferIndex] = rhoE1+(rhoE2-rhoE1)*transitionFactor;
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;
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];
1121 template<
typename Gr
idType,
typename StateType,
typename BoundaryType>
1123 StateType &inParamState,
1124 std::vector<BoundaryType> &inBoundaries,
1125 const std::vector<double> &inParams,
1126 const std::vector<int> &inFlags,
int threadId)
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;
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;
1145 int numParams = inParams.size();
1147 pulseAmp = inParams[0];
1149 pulseWidth = inParams[1];
1151 pulseRadius = inParams[2];
1153 centerX = inParams[3];
1155 centerY = inParams[4];
1157 crossFlowSpeed = inParams[5];
1159 injectionSpeed = inParams[6];
1162 if(!inFlags.empty()){
1163 optionBits = inFlags[0];
1167 const std::vector<size_t> &
gridSizes(inGrid.GridSizes());
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());
1177 bufferInterval.InitSimple(bufferSizes);
1183 std::ostringstream messageStream;
1186 messageStream <<
"ProtoY4Test1: Grid Sizes: (";
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;
1198 std::string pulseType;
1199 bool pulseOn =
false;
1200 if(optionBits&INIT_ACOUSTIC_PULSE){
1201 pulseType =
"Acoustic";
1204 if(optionBits&INIT_MASS_GLOB){
1205 pulseType +=
"Mass";
1209 if(!pulseType.empty()){
1210 messageStream <<
"ProtoY4Test1: " << pulseType <<
" pulse amplitude: " 1211 << pulseAmp << std::endl
1213 << pulseType <<
" pulse width: " 1214 << pulseWidth << std::endl
1215 <<
"ProtoY4Test1: Relative pulse centerX: " << centerX << std::endl
1216 <<
"ProtoY4Test1: Pulse CenterY: " << centerY << std::endl;
1218 messageStream <<
"ProtoY4Test1: No pulse configured." << std::endl;
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;
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;
1231 if(gridComm.Rank() == 0)
1232 std::cout << messageStream.str();
1235 const std::vector<double> &coordinateData(inGrid.CoordinateData());
1237 int rhoHandle = inState.GetDataIndex(
"rho");
1241 double *rhoPtr = rhoData.
Data<
double>();
1245 int rhoVHandle = inState.GetDataIndex(
"rhoV");
1249 double *rhoVPtr = rhoVData.
Data<
double>();
1253 int rhoEHandle = inState.GetDataIndex(
"rhoE");
1257 double *rhoEPtr = rhoEData.
Data<
double>();
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");
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){
1279 refTemperature *= (gamma-1);
1282 double testSectionP = 7176.9492187500000;
1283 double testSectionT = 121.23677825927734;
1284 double testSectionRho = 0.22785909473896027;
1285 double testSectionVel = 566.97581634521487;
1287 double portP = 204233.73437500000;
1288 double portT = 248.33332824707031;
1289 double portRho = 3.1655802726745605;
1290 double portVel = 300.53918457031250;
1292 double transitionWidth = 20.0*dX[0];
1296 int combustionChamberIndex = inGrid.GetRegionIndex(
"ChamberBottom");
1297 if(combustionChamberIndex < 0)
1298 combustionChamberIndex = inGrid.GetRegionIndex(
"Bottom");
1299 if(combustionChamberIndex < 0)
1307 combustionChamberInterval[1].first = gridInterval[1].first;
1308 combustionChamberInterval[1].second = gridInterval[1].second;
1311 partitionInterval.
Overlap(combustionChamberInterval,chamberPartitionInterval);
1313 if(chamberPartitionInterval.
NNodes() > 0){
1317 partitionBufferInterval,
1318 chamberBufferInterval);
1320 double windowWidth = 5;
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];
1330 std::cout <<
"TestSection X := [" << chamberStartX <<
"," 1331 << chamberEndX <<
"]" << std::endl;
1333 centerX *= chamberWidth;
1334 centerX += chamberStartX;
1337 double pulseWindowWidth = (centerX - pulseWindowX1);
1338 double pulseWindowY1 = centerY - pulseWindowWidth/2.0;
1339 double pulseWindowY2 = centerY + pulseWindowWidth/2.0;
1341 double profileX1 = chamberStartX + windowWidth*dX[0];
1342 double profileX2 = chamberEndX - windowWidth*dX[0];
1343 double profileWidth = (profileX2 - profileX1)/2.0;
1345 messageStream <<
"ProtoY4Test1: Found combustion chamber interval: ";
1346 combustionChamberInterval.
PrettyPrint(messageStream);
1347 messageStream <<
",(" << chamberStartX <<
"," << chamberEndX <<
")" 1349 <<
"ProtoY4Test1: My combustion chamber interval: ";
1350 chamberPartitionInterval.
PrettyPrint(messageStream);
1351 messageStream << std::endl;
1353 messageStream <<
"ProtoY4Test1: Pulse location = (" << centerX <<
"," 1354 << centerY <<
")" << std::endl;
1355 messageStream <<
"ProtoY4Test1: Pulse window width = " << pulseWindowWidth
1361 std::vector<size_t> chamberNodes;
1362 bufferInterval.GetFlatIndices(chamberBufferInterval,chamberNodes);
1364 std::vector<size_t>::iterator nodeIt = chamberNodes.begin();
1365 while(nodeIt != chamberNodes.end()){
1367 size_t bufferNodeId = *nodeIt++;
1369 double x = coordinateData[bufferNodeId];
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);
1377 double velocityProfile =
Window(transitionWidth,profileWidth,chamberCenter,0,0,x,0,0);
1378 double pulseProfile =
Window(transitionWidth,pulseWindowWidth,centerX,centerY,0,x,y,0);
1381 if(!(optionBits&INIT_CROSSFLOW_PROFILE))
1382 velocityProfile = 1.0;
1383 if(radDist > pulseRadius)
1386 rhoPtr[bufferNodeId] = testSectionRho/refRho;
1388 if(optionBits&INIT_MASS_GLOB)
1389 rhoPtr[bufferNodeId] *= (1.0 + pulseWeight);
1391 rhoVPtr[bufferNodeId] = 0.0;
1393 if(optionBits&INIT_CROSSFLOW){
1394 rhoVPtr[yBufferIndex] = rhoPtr[bufferNodeId]*testSectionVel*velocityProfile/velRef;
1397 rhoEPtr[bufferNodeId] = rhoPtr[bufferNodeId]*testSectionT/refTemperature/gamma +
1398 0.5*rhoVPtr[yBufferIndex]*rhoVPtr[yBufferIndex]/rhoPtr[bufferNodeId];
1400 if(optionBits&INIT_ACOUSTIC_PULSE)
1401 rhoEPtr[bufferNodeId] *= (1.0 + pulseWeight*pulseProfile);
1407 int portIndex = inGrid.GetRegionIndex(
"Port");
1414 partitionInterval.
Overlap(portInterval,myPortInterval);
1416 if(myPortInterval.
NNodes() > 0){
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;
1424 messageStream <<
"ProtoY4Test1: Initializing Port..." << std::endl
1425 <<
"ProtoY4Test1: Port Interval: ";
1427 messageStream <<
", Y = [" << portStartY <<
"," << portEndY <<
"]" << std::endl;
1431 partitionBufferInterval,
1432 portBufferInterval);
1433 std::vector<size_t> portNodes;
1434 bufferInterval.GetFlatIndices(portBufferInterval,portNodes);
1436 std::vector<size_t>::iterator nodeIt = portNodes.begin();
1437 while(nodeIt != portNodes.end()){
1440 size_t bufferNodeId = *nodeIt++;
1444 double injectionProfile = std::tanh(10000.0*(y - portStartY)) -
1445 std::tanh(10000.0*(y-portEndY)) - 1.0;
1447 rhoPtr[bufferNodeId] = portRho/refRho;
1450 if(!(optionBits&INIT_INJECTION_PROFILE))
1451 injectionProfile = 1.0;
1453 rhoVPtr[bufferNodeId] = rhoPtr[bufferNodeId]*portVel/velRef*injectionProfile;
1455 rhoEPtr[bufferNodeId] = rhoPtr[bufferNodeId]*portT/refTemperature/gamma +
1456 0.5*(rhoVPtr[bufferNodeId]*rhoVPtr[bufferNodeId])/rhoPtr[bufferNodeId];
1461 int plugTopId = inGrid.GetRegionIndex(
"PortWallTop");
1463 std::cout <<
"ProtoY4Init:Error: Failed to find required boundary [PortWallTop]. Aborting." << std::endl;
1473 plugInterval[0].second = portTopInterval[0].second;
1474 plugInterval[0].first++;
1476 partitionInterval.
Overlap(plugInterval,myPlugInterval);
1478 if(myPlugInterval.
NNodes() > 0){
1482 partitionBufferInterval,
1483 plugBufferInterval);
1484 std::vector<size_t> plugNodes;
1485 bufferInterval.GetFlatIndices(plugBufferInterval,plugNodes);
1487 std::vector<size_t>::iterator plugNodeIt = plugNodes.begin();
1488 while(plugNodeIt != plugNodes.end()){
1489 size_t bufferIndex = *plugNodeIt++;
1491 rhoPtr[bufferIndex] = testSectionRho/refRho;
1492 rhoVPtr[bufferIndex] = 0.0;
1494 rhoEPtr[bufferIndex] = rhoPtr[bufferIndex]*testSectionT/refTemperature/gamma;
1506 template<
typename Gr
idType,
typename StateType>
1509 const std::vector<double> &inParams,
1510 const std::vector<int> &inFlags,
int threadId)
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;
1521 int INIT_VORTEX = 1;
1522 int INIT_CROSSFLOW = 2;
1523 int INIT_CROSSFLOW_PROFILE = 4;
1525 std::ostringstream messageStream;
1526 int numParams = inParams.size();
1528 vortexStrength = inParams[0];
1530 vortexWidth = inParams[1];
1532 vortexCenterX = inParams[2];
1534 vortexCenterY = inParams[3];
1536 crossFlowX = inParams[4];
1538 crossFlowY = inParams[5];
1541 if(!inFlags.empty()){
1542 optionBits = inFlags[0];
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")
1557 const std::vector<size_t> &
gridSizes(inGrid.GridSizes());
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());
1565 int rhoHandle = inState.GetDataIndex(
"rho");
1569 double *rhoPtr = rhoData.
Data<
double>();
1573 int rhoVHandle = inState.GetDataIndex(
"rhoV");
1577 double *rhoVPtr = rhoVData.
Data<
double>();
1581 int rhoEHandle = inState.GetDataIndex(
"rhoE");
1585 double *rhoEPtr = rhoEData.
Data<
double>();
1589 double L2M1 = 1.0/(vortexWidth*vortexWidth);
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;
1603 if(optionBits&INIT_CROSSFLOW){
1604 vortexVx += crossFlowX;
1605 vortexVy += crossFlowY;
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));
1616 if(!(optionBits&INIT_VORTEX)){
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);
1634 template<
typename Gr
idType,
typename StateType>
1636 StateType &inParam,
const std::vector<double> &inParams,
1637 const std::vector<int> &inFlags,
int threadId,
1638 std::ostream *messageStream)
1642 messageStream = &std::cout;
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;
1654 int INIT_CROSSFLOW = 1;
1655 int INIT_CROSSFLOW_PROFILE = 2;
1658 int numParams = inParams.size();
1660 pulseAmp = inParams[0];
1662 pulseWidth = inParams[1];
1664 pulseRadius = inParams[2];
1666 relCenterX = inParams[3];
1668 relCenterY = inParams[4];
1670 relCenterZ = inParams[5];
1672 crossFlowSpeed = inParams[6];
1675 if(!inFlags.empty()){
1676 optionBits = inFlags[0];
1680 const std::vector<size_t> &
bufferSizes(inGrid.BufferSizes());
1681 const std::vector<size_t> &
gridSizes(inGrid.GridSizes());
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());
1689 if(dX.size() != numDim){
1690 *messageStream <<
"AcousticPulse:Error: Grid not initialized." 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];
1707 pulseCenter[2] = 0.0;
1709 pulseCenter[1] = 0.0;
1712 *messageStream <<
"AcousticPulse: Grid Sizes: (";
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;
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;
1735 double *gammaPtr = inParam.template GetFieldBuffer<double>(
"gamma");
1736 double gammaValue = *gammaPtr;
1739 int rhoHandle = inState.GetDataIndex(
"rho");
1743 double *rhoPtr = rhoData.
Data<
double>();
1747 int rhoVHandle = inState.GetDataIndex(
"rhoV");
1751 double *rhoVPtr = rhoVData.
Data<
double>();
1755 int rhoEHandle = inState.GetDataIndex(
"rhoE");
1759 double *rhoEPtr = rhoEData.
Data<
double>();
1766 rhoPtr[iPoint] = 0.0;
1767 rhoEPtr[iPoint] = 0.0;
1769 for(
int iDim = 0;iDim < numDim;iDim++){
1772 rhoVPtr[iPoint+dimOffset] = 0.0;
1776 std::vector<double>
velocity(numDim,0.0);
1778 velocity[0] = crossFlowSpeed;
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);
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] +
1815 (2.0*rhoPtr[bufferIndex]);
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] +
1845 (2.0*rhoPtr[bufferIndex]);
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]);
1869 template<
typename Gr
idType,
typename StateType>
1871 const std::vector<double> &inParams,
int threadId,
1872 std::ostream *messageStream = NULL)
1876 messageStream = &std::cout;
1878 *messageStream <<
"Starting Density Pulse Flow Initialization" << std::endl;
1881 const std::vector<size_t> &
gridSizes(inGrid.GridSizes());
1882 const std::vector<size_t> &
bufferSizes(inGrid.BufferSizes());
1886 const std::vector<double> &dX(inGrid.DX());
1887 const std::vector<double> &readGridExtent(inGrid.PhysicalExtent());
1892 int numParams = inParams.size();
1893 std::vector<double> position(3,0.0);
1894 std::vector<double>
velocity(3,0.0);
1895 double pulseAmp=1.0;
1896 double pulseWidth=1.0;
1899 *messageStream <<
"Invalid number of parameters, user must" 1900 <<
"specify an x location and u velocity " << std::endl;
1903 pulseAmp = inParams[0];
1904 pulseWidth = inParams[1];
1907 int locationInd = 2;
1908 int velocityInd = locationInd+numDim;
1912 position[0] = inParams[locationInd];
1913 velocity[0] = inParams[velocityInd];
1915 *messageStream <<
"Invalid number of parameters, user must" 1916 <<
"specify an x location and u velocity " << std::endl;
1919 }
else if(numDim == 2) {
1921 position[0] = inParams[locationInd];
1922 position[1] = inParams[locationInd+1];
1923 velocity[0] = inParams[velocityInd];
1924 velocity[1] = inParams[velocityInd+1];
1926 *messageStream <<
"Invalid number of parameters, user must" 1927 <<
"specify an <x,y> location and <u,v> velocity " << std::endl;
1930 }
else if(numDim == 3) {
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];
1939 *messageStream <<
"Invalid number of parameters, user must" 1940 <<
"specify an <x,y> location and <u,v> velocity " << std::endl;
1946 int nonDimensionalMode=0;
1948 int paramHandle = inParamState.GetDataIndex(
"nonDimensional");
1949 if(paramHandle >= 0){
1951 const int *paramPtr = paramData.
Data<
int>();
1952 nonDimensionalMode = *paramPtr;
1954 nonDimensionalMode = 0;
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");
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);
1988 const std::vector<double> &coordinateData(inGrid.CoordinateData());
1990 int rhoHandle = inState.GetDataIndex(
"rho");
1994 double *rhoPtr = rhoData.
Data<
double>();
1998 int rhoVHandle = inState.GetDataIndex(
"rhoV");
2002 double *rhoVPtr = rhoVData.
Data<
double>();
2006 int rhoEHandle = inState.GetDataIndex(
"rhoE");
2010 double *rhoEPtr = rhoEData.
Data<
double>();
2016 rhoPtr[iPoint] = 0.0;
2017 rhoEPtr[iPoint] = 0.0;
2019 for(
int iDim = 0;iDim < numDim;iDim++){
2022 rhoVPtr[iPoint+dimOffset] = 0.0;
2027 double rho = refRho;
2028 double pressure = refPressure;
2029 double temperature = refTemperature;
2031 if(nonDimensionalMode == 1){
2033 pressure /= refPressure;
2034 temperature /= refTemperature;
2035 }
else if (nonDimensionalMode == 2) {
2037 pressure /= gamma*refPressure;
2038 temperature /= (gamma-1)*refTemperature;
2041 double rhoE = pressure/(gamma-1)/rho;
2043 *messageStream <<
"Density Pulse: Initial state" << std::endl;
2044 *messageStream <<
"\t nonDimensional: " << nonDimensionalMode << 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;
2053 for(
int iDim=0;iDim<numDim;iDim++){
2054 *messageStream <<
"\t u[" << iDim <<
"]: " << velocity[iDim] << std::endl;
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;
2065 kStart = partitionBufferInterval[2].first;
2066 kEnd = partitionBufferInterval[2].second;
2067 nPlane = bufferSizes[0]*bufferSizes[1];
2070 for(
size_t kIndex = kStart;kIndex <= kEnd;kIndex++){
2071 size_t kBufferIndex = kIndex*nPlane;
2072 size_t kPartIndex = 0;
2075 kPartIndex = (kIndex - kStart) + partitionInterval[2].first;
2076 z = kPartIndex*dX[2];
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];
2088 double densityPulse =
Pulse(pulseAmp,pulseWidth,
2089 position[0],position[1],position[2],x,y,z);
2091 rhoPtr[bufferIndex] = rho;
2092 if(densityPulse > 1.e-6)
2093 rhoPtr[bufferIndex] += densityPulse;
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];
2109 template<
typename Gr
idType,
typename StateType>
2111 const std::vector<double> &inParams,
int threadId,
2112 std::ostream *messageStream = NULL)
2116 messageStream = &std::cout;
2118 *messageStream <<
"Starting Gaussian Scalar Flow Initialization" << std::endl;
2121 const std::vector<size_t> &
gridSizes(inGrid.GridSizes());
2122 const std::vector<size_t> &
bufferSizes(inGrid.BufferSizes());
2126 const std::vector<double> &dX(inGrid.DX());
2127 const std::vector<double> &readGridExtent(inGrid.PhysicalExtent());
2132 int numParams = inParams.size();
2133 std::vector<double> position(3,0.0);
2134 std::vector<double>
velocity(3,0.0);
2135 double pulseAmp=1.0;
2136 double pulseWidth=1.0;
2139 *messageStream <<
"Invalid number of parameters, user must" 2140 <<
"specify an x location and u velocity " << std::endl;
2143 pulseAmp = inParams[0];
2144 pulseWidth = inParams[1];
2147 int locationInd = 2;
2148 int velocityInd = locationInd+numDim;
2152 position[0] = inParams[locationInd];
2153 velocity[0] = inParams[velocityInd];
2155 *messageStream <<
"Invalid number of parameters, user must" 2156 <<
"specify an x location and u velocity " << std::endl;
2159 }
else if(numDim == 2) {
2161 position[0] = inParams[locationInd];
2162 position[1] = inParams[locationInd+1];
2163 velocity[0] = inParams[velocityInd];
2164 velocity[1] = inParams[velocityInd+1];
2166 *messageStream <<
"Invalid number of parameters, user must" 2167 <<
"specify an <x,y> location and <u,v> velocity " << std::endl;
2170 }
else if(numDim == 3) {
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];
2179 *messageStream <<
"Invalid number of parameters, user must" 2180 <<
"specify an <x,y> location and <u,v> velocity " << std::endl;
2187 std::vector< std::vector<double> > pulseOffset;
2190 std::vector<double> tempOffset(numDim,0.);
2191 pulseOffset.push_back(tempOffset);
2194 tempOffset[0] = (readGridExtent[1]-readGridExtent[0])-2*position[0];
2195 pulseOffset.push_back(tempOffset);
2199 tempOffset[1] = (readGridExtent[3]-readGridExtent[2])-2*position[1];
2200 pulseOffset.push_back(tempOffset);
2203 tempOffset[0] = (readGridExtent[1]-readGridExtent[0])-2*position[0];
2204 pulseOffset.push_back(tempOffset);
2210 tempOffset[2] = (readGridExtent[5]-readGridExtent[4])-2*position[2];
2211 pulseOffset.push_back(tempOffset);
2214 tempOffset[0] = (readGridExtent[1]-readGridExtent[0])-2*position[0];
2215 pulseOffset.push_back(tempOffset);
2219 tempOffset[1] = (readGridExtent[3]-readGridExtent[2])-2*position[1];
2220 pulseOffset.push_back(tempOffset);
2223 tempOffset[0] = (readGridExtent[1]-readGridExtent[0])-2*position[0];
2224 pulseOffset.push_back(tempOffset);
2229 int nonDimensionalMode=0;
2231 int paramHandle = inParamState.GetDataIndex(
"nonDimensional");
2232 if(paramHandle >= 0){
2234 const int *paramPtr = paramData.
Data<
int>();
2235 nonDimensionalMode = *paramPtr;
2237 nonDimensionalMode = 0;
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");
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);
2271 const std::vector<double> &coordinateData(inGrid.CoordinateData());
2273 int rhoHandle = inState.GetDataIndex(
"rho");
2277 double *rhoPtr = rhoData.
Data<
double>();
2281 int rhoVHandle = inState.GetDataIndex(
"rhoV");
2285 double *rhoVPtr = rhoVData.
Data<
double>();
2289 int rhoEHandle = inState.GetDataIndex(
"rhoE");
2293 double *rhoEPtr = rhoEData.
Data<
double>();
2297 int scalarHandle = inState.GetDataIndex(
"scalarVars");
2298 if(scalarHandle < 0)
2301 int numScalars = inState.Meta()[scalarHandle].ncomp;
2302 double *scalarPtr = scalarData.Data<
double>();
2308 rhoPtr[iPoint] = 0.0;
2309 rhoEPtr[iPoint] = 0.0;
2311 for(
int iDim = 0;iDim < numDim;iDim++){
2314 rhoVPtr[iPoint+dimOffset] = 0.0;
2316 for(
int iScalar = 0;iScalar <
numScalars;iScalar++){
2319 scalarPtr[iPoint+scalarOffset] = 0.0;
2324 double rho = refRho;
2325 double pressure = refPressure;
2326 double temperature = refTemperature;
2328 if(nonDimensionalMode == 1){
2330 pressure /= refPressure;
2331 temperature /= refTemperature;
2332 }
else if (nonDimensionalMode == 2) {
2334 pressure /= gamma*refPressure;
2335 temperature /= (gamma-1)*refTemperature;
2338 double rhoE = pressure/(gamma-1)/rho;
2340 *messageStream <<
"Scalar Advection: Initial state" << std::endl;
2341 *messageStream <<
"\t nonDimensional: " << nonDimensionalMode << 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;
2350 for(
int iDim=0;iDim<numDim;iDim++){
2351 *messageStream <<
"\t u[" << iDim <<
"]: " << velocity[iDim] << std::endl;
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;
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;
2368 kStart = partitionBufferInterval[2].first;
2369 kEnd = partitionBufferInterval[2].second;
2370 nPlane = bufferSizes[0]*bufferSizes[1];
2373 for(
size_t kIndex = kStart;kIndex <= kEnd;kIndex++){
2374 size_t kBufferIndex = kIndex*nPlane;
2375 size_t kPartIndex = 0;
2378 kPartIndex = (kIndex - kStart) + partitionInterval[2].first;
2379 z = kPartIndex*dX[2];
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];
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];
2400 if(numScalars > 1) {
2401 scalarPtr[bufferIndex] = 1.0;
2402 for(
int iScalar=1;iScalar<
numScalars;iScalar++){
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],
2410 if(scalarPulse > 1.e-6)
2411 scalarPtr[bufferIndex+numPointsBuffer*iScalar] += scalarPulse;
2414 scalarPtr[bufferIndex] = 1.0;
2416 double scalarPulse =
Pulse(pulseAmp,pulseWidth,
2417 position[0], position[1], position[2], x,y,z);
2419 if(scalarPulse > 1.e-6)
2420 scalarPtr[bufferIndex] += scalarPulse;
2430 template<
typename Gr
idType,
typename StateType>
2432 const std::vector<double> &inParams,
int threadId,
2433 std::ostream *messageStream = NULL)
2437 messageStream = &std::cout;
2439 *messageStream <<
"Advection-Diffusion Initialization" << std::endl;
2442 const std::vector<size_t> &
gridSizes(inGrid.GridSizes());
2443 const std::vector<size_t> &
bufferSizes(inGrid.BufferSizes());
2448 const std::vector<double> &dX(inGrid.DX());
2449 const std::vector<double> &readGridExtent(inGrid.PhysicalExtent());
2454 int numParams = inParams.size();
2455 std::vector<double> position(3,0.0);
2456 std::vector<double>
velocity(3,0.0);
2458 double waveK=2.0*3.14159265358979323846;
2461 waveAmp = inParams[0];
2463 waveK = inParams[1];
2465 bool hasPosition = numParams >= (2+numDim);
2466 bool hasVelocity = numParams >= (2+2*numDim);
2468 int locationInd = 2;
2469 int velocityInd = locationInd+numDim;
2473 position[0] = inParams[locationInd];
2475 velocity[0] = inParams[velocityInd];
2476 }
else if(numDim == 2) {
2478 position[0] = inParams[locationInd];
2479 position[1] = inParams[locationInd+1];
2482 velocity[0] = inParams[velocityInd];
2483 velocity[1] = inParams[velocityInd+1];
2485 }
else if(numDim == 3) {
2487 position[0] = inParams[locationInd+0];
2488 position[1] = inParams[locationInd+1];
2489 position[2] = inParams[locationInd+2];
2492 velocity[0] = inParams[velocityInd];
2493 velocity[1] = inParams[velocityInd+1];
2494 velocity[2] = inParams[velocityInd+2];
2500 int nonDimensionalMode=0;
2502 int paramHandle = inParamState.GetDataIndex(
"nonDimensional");
2503 if(paramHandle >= 0){
2505 const int *paramPtr = paramData.
Data<
int>();
2506 nonDimensionalMode = *paramPtr;
2508 nonDimensionalMode = 0;
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");
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);
2529 const std::vector<double> &coordinateData(inGrid.CoordinateData());
2531 int rhoHandle = inState.GetDataIndex(
"rho");
2535 double *rhoPtr = rhoData.
Data<
double>();
2539 int rhoVHandle = inState.GetDataIndex(
"rhoV");
2543 double *rhoVPtr = rhoVData.
Data<
double>();
2547 int rhoEHandle = inState.GetDataIndex(
"rhoE");
2551 double *rhoEPtr = rhoEData.
Data<
double>();
2555 int scalarHandle = inState.GetDataIndex(
"scalarVars");
2556 if(scalarHandle < 0)
2559 int numScalars = inState.Meta()[scalarHandle].ncomp;
2560 double *scalarPtr = scalarData.Data<
double>();
2566 rhoPtr[iPoint] = 0.0;
2567 rhoEPtr[iPoint] = 0.0;
2569 for(
int iDim = 0;iDim < numDim;iDim++){
2572 rhoVPtr[iPoint+dimOffset] = 0.0;
2574 for(
int iScalar = 0;iScalar <
numScalars;iScalar++){
2577 scalarPtr[iPoint+scalarOffset] = 0.0;
2582 double rho = refRho;
2583 double pressure = refPressure;
2584 double temperature = refTemperature;
2586 if(nonDimensionalMode == 1){
2588 pressure /= refPressure;
2589 temperature /= refTemperature;
2590 }
else if (nonDimensionalMode == 2) {
2592 pressure /= gamma*refPressure;
2593 temperature /= (gamma-1)*refTemperature;
2596 double rhoE = pressure/(gamma-1)/rho;
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;
2607 *messageStream <<
"\t Wave Amp: " << waveAmp << std::endl
2608 <<
"\t Wave Number: " << waveK << std::endl;
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;
2619 kStart = partitionBufferInterval[2].first;
2620 kEnd = partitionBufferInterval[2].second;
2621 nPlane = bufferSizes[0]*bufferSizes[1];
2624 for(
size_t kIndex = kStart;kIndex <= kEnd;kIndex++){
2625 size_t kBufferIndex = kIndex*nPlane;
2626 size_t kPartIndex = 0;
2629 kPartIndex = (kIndex - kStart) + partitionInterval[2].first;
2630 z = kPartIndex*dX[2];
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;
2643 if(position[1] > 0) waveCoordinate =
y;
2645 if(position[2] > 0) waveCoordinate = z;
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];
2653 for(
int iScalar = 0;iScalar <
numScalars;iScalar++){
2654 double phase = iScalar * waveK/4.0;
2656 scalarPtr[scalarOffset+bufferIndex] = waveAmp*std::sin(waveK*waveCoordinate+phase);
2665 template<
typename Gr
idType,
typename StateType>
2668 StateType &inParamState,
2669 const std::vector<double> &inParams,
int threadId,
2670 std::ostream *messageStream = NULL)
2674 messageStream = &std::cout;
2676 *messageStream <<
"Uniform Flow Initialization" << std::endl;
2679 const std::vector<size_t> &
gridSizes(inGrid.GridSizes());
2680 const std::vector<size_t> &
bufferSizes(inGrid.BufferSizes());
2689 int numParams = inParams.size();
2690 std::vector<double>
velocity(3,0.0);
2692 for(
int iParam = 0;iParam < numDim;iParam++)
2693 velocity[iParam] = inParams[iParam];
2696 int nonDimensionalMode=0;
2698 int paramHandle = inParamState.GetDataIndex(
"nonDimensional");
2699 if(paramHandle >= 0){
2701 const int *paramPtr = paramData.
Data<
int>();
2702 nonDimensionalMode = *paramPtr;
2704 nonDimensionalMode = 0;
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");
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);
2725 int rhoHandle = inState.GetDataIndex(
"rho");
2727 *messageStream <<
"Required variable (rho) not found in state." << std::endl;
2731 double *rhoPtr = rhoData.
Data<
double>();
2735 int rhoVHandle = inState.GetDataIndex(
"rhoV");
2737 *messageStream <<
"Required variable (rhoV) not found in state." << std::endl;
2742 double *rhoVPtr = rhoVData.
Data<
double>();
2746 int rhoEHandle = inState.GetDataIndex(
"rhoE");
2748 *messageStream <<
"Required variable (rhoE) not found in state." << std::endl;
2752 double *rhoEPtr = rhoEData.
Data<
double>();
2758 rhoPtr[iPoint] = 0.0;
2759 rhoEPtr[iPoint] = 0.0;
2761 for(
int iDim = 0;iDim < numDim;iDim++){
2764 rhoVPtr[iPoint+dimOffset] = 0.0;
2769 double rho = refRho;
2770 double pressure = refPressure;
2771 double temperature = refTemperature;
2773 if(nonDimensionalMode == 1){
2775 pressure /= refPressure;
2776 temperature /= refTemperature;
2777 }
else if (nonDimensionalMode == 2) {
2779 pressure /= gamma*refPressure;
2780 temperature /= (gamma-1)*refTemperature;
2783 double rhoE = pressure/(gamma-1)/rho;
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];
2796 *messageStream <<
")" << std::endl;
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;
2807 kStart = partitionBufferInterval[2].first;
2808 kEnd = partitionBufferInterval[2].second;
2809 nPlane = bufferSizes[0]*bufferSizes[1];
2812 for(
size_t kIndex = kStart;kIndex <= kEnd;kIndex++){
2813 size_t kBufferIndex = kIndex*nPlane;
2814 size_t kPartIndex = 0;
2816 kPartIndex = (kIndex - kStart) + partitionInterval[2].first;
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];
2837 template<
typename DomainType>
2839 int iGrid,
const std::string &caseName,
2840 int threadId,std::ostream *messageStream = NULL)
2843 typedef typename DomainType::GridType GridType;
2844 typedef typename DomainType::StateType StateType;
2847 GridType &inGrid(inDomain.Grid(iGrid));
2848 StateType &inState(inDomain.State(iGrid));
2849 StateType &inParams(inDomain.Params(iGrid));
2852 std::vector<double> initParams(domainConfig.GetValueVector<
double>(
ConfigKey(initKey,
"Params")));
2853 std::vector<int> initFlags(domainConfig.GetValueVector<
int>(
ConfigKey(initKey,
"Flags")));
2856 messageStream = &std::cout;
2858 *messageStream <<
"Advection-Diffusion Initialization" << std::endl;
2861 const std::vector<size_t> &
gridSizes(inGrid.GridSizes());
2862 const std::vector<size_t> &
bufferSizes(inGrid.BufferSizes());
2867 const std::vector<double> &dX(inGrid.DX());
2868 const std::vector<double> &readGridExtent(inGrid.PhysicalExtent());
2873 int numParams = initParams.size();
2874 std::vector<double> position(3,0.0);
2875 std::vector<double>
velocity(3,0.0);
2876 double pulseAmp=1.0;
2877 double pulseWidth=1.0;
2880 *messageStream <<
"Invalid number of parameters, user must" 2881 <<
"specify an x location and u velocity " << std::endl;
2884 pulseAmp = initParams[0];
2885 pulseWidth = initParams[1];
2888 int locationInd = 2;
2889 int velocityInd = locationInd+numDim;
2893 position[0] = initParams[locationInd];
2894 velocity[0] = initParams[velocityInd];
2896 *messageStream <<
"Invalid number of parameters, user must" 2897 <<
"specify an x location and u velocity " << std::endl;
2900 }
else if(numDim == 2) {
2902 position[0] = initParams[locationInd];
2903 position[1] = initParams[locationInd+1];
2904 velocity[0] = initParams[velocityInd];
2905 velocity[1] = initParams[velocityInd+1];
2907 *messageStream <<
"Invalid number of parameters, user must" 2908 <<
"specify an <x,y> location and <u,v> velocity " << std::endl;
2911 }
else if(numDim == 3) {
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];
2920 *messageStream <<
"Invalid number of parameters, user must" 2921 <<
"specify an <x,y> location and <u,v> velocity " << std::endl;
2928 int nonDimensionalMode=0;
2930 int paramHandle = inParams.GetDataIndex(
"nonDimensional");
2931 if(paramHandle >= 0){
2933 const int *paramPtr = paramData.
Data<
int>();
2934 nonDimensionalMode = *paramPtr;
2936 nonDimensionalMode = 0;
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");
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);
2957 const std::vector<double> &coordinateData(inGrid.CoordinateData());
2959 int rhoHandle = inState.GetDataIndex(
"rho");
2963 double *rhoPtr = rhoData.
Data<
double>();
2967 int rhoVHandle = inState.GetDataIndex(
"rhoV");
2971 double *rhoVPtr = rhoVData.
Data<
double>();
2975 int rhoEHandle = inState.GetDataIndex(
"rhoE");
2979 double *rhoEPtr = rhoEData.
Data<
double>();
2983 int scalarHandle = inState.GetDataIndex(
"scalarVars");
2984 if(scalarHandle < 0)
2987 int numScalars = inState.Meta()[scalarHandle].ncomp;
2988 double *scalarPtr = scalarData.Data<
double>();
2994 rhoPtr[iPoint] = 0.0;
2995 rhoEPtr[iPoint] = 0.0;
2997 for(
int iDim = 0;iDim < numDim;iDim++){
3000 rhoVPtr[iPoint+dimOffset] = 0.0;
3002 for(
int iScalar = 0;iScalar <
numScalars;iScalar++){
3005 scalarPtr[iPoint+scalarOffset] = 0.0;
3010 double rho = refRho;
3011 double pressure = refPressure;
3012 double temperature = refTemperature;
3014 if(nonDimensionalMode == 1){
3016 pressure /= refPressure;
3017 temperature /= refTemperature;
3018 }
else if (nonDimensionalMode == 2) {
3020 pressure /= gamma*refPressure;
3021 temperature /= (gamma-1)*refTemperature;
3024 double rhoE = pressure/(gamma-1)/rho;
3026 *messageStream <<
"Scalar Advection Diffusion: Initial state" << std::endl;
3027 *messageStream <<
"\t nonDimensional: " << nonDimensionalMode << 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;
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;
3045 kStart = partitionBufferInterval[2].first;
3046 kEnd = partitionBufferInterval[2].second;
3047 nPlane = bufferSizes[0]*bufferSizes[1];
3050 for(
size_t kIndex = kStart;kIndex <= kEnd;kIndex++){
3051 size_t kBufferIndex = kIndex*nPlane;
3052 size_t kPartIndex = 0;
3055 kPartIndex = (kIndex - kStart) + partitionInterval[2].first;
3056 z = kPartIndex*dX[2];
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];
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];
3074 scalarPtr[bufferIndex] = .01*std::sin(2*3.14159265358979323846*x);
3083 template<
typename Gr
idType,
typename StateType>
3085 StateType &inParam,
const std::vector<double> &inParams,
3086 const std::vector<int> &inFlags,
int threadId,
3087 std::ostream *messageStream)
3091 messageStream = &std::cout;
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;
3102 int INIT_CROSSFLOW = 1;
3103 int INIT_CROSSFLOW_PROFILE = 2;
3106 int numParams = inParams.size();
3108 pulseAmp = inParams[0];
3110 pulseWidth = inParams[1];
3112 relCenterX = inParams[2];
3114 relCenterY = inParams[3];
3116 relCenterZ = inParams[4];
3118 crossFlowSpeed = inParams[5];
3121 if(!inFlags.empty()){
3122 optionBits = inFlags[0];
3126 const std::vector<size_t> &
bufferSizes(inGrid.BufferSizes());
3127 const std::vector<size_t> &
gridSizes(inGrid.GridSizes());
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());
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];
3149 pulseCenter[2] = 0.0;
3151 pulseCenter[1] = 0.0;
3154 *messageStream <<
"DensityPulse: Grid Sizes: (";
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;
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;
3172 *messageStream <<
"DensityPulse: CrossFlowSpeed: " << crossFlowSpeed << std::endl;
3175 double *gammaPtr = inParam.template GetFieldBuffer<double>(
"gamma");
3176 double gammaValue = *gammaPtr;
3179 int rhoHandle = inState.GetDataIndex(
"rho");
3183 double *rhoPtr = rhoData.
Data<
double>();
3187 int rhoVHandle = inState.GetDataIndex(
"rhoV");
3191 double *rhoVPtr = rhoVData.
Data<
double>();
3195 int rhoEHandle = inState.GetDataIndex(
"rhoE");
3199 double *rhoEPtr = rhoEData.
Data<
double>();
3206 rhoPtr[iPoint] = 0.0;
3207 rhoEPtr[iPoint] = 0.0;
3209 for(
int iDim = 0;iDim < numDim;iDim++){
3212 rhoVPtr[iPoint+dimOffset] = 0.0;
3216 std::vector<double>
velocity(numDim,0.0);
3219 velocity[optionBits-1] = crossFlowSpeed;
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];
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);
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]));
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]));
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]);
3299 template<
typename Gr
idType,
typename StateType>
3301 StateType ¶mState,
const std::vector<double> &inParams,
3302 const std::vector<int> &inFlags,
int threadId)
3315 int numParams = inParams.size();
3316 if(!(numParams >= 7))
3333 if(!inFlags.empty()){
3334 jumpDim = inFlags[0];
3338 const std::vector<size_t> &
bufferSizes(inGrid.BufferSizes());
3339 const std::vector<size_t> &
gridSizes(inGrid.GridSizes());
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());
3353 int rhoHandle = inState.GetDataIndex(
"rho");
3357 double *rhoPtr = rhoData.
Data<
double>();
3361 int rhoVHandle = inState.GetDataIndex(
"rhoV");
3365 double *rhoVPtr = rhoVData.
Data<
double>();
3369 int rhoEHandle = inState.GetDataIndex(
"rhoE");
3373 double *rhoEPtr = rhoEData.
Data<
double>();
3378 double *gammaPtr = paramState.template GetFieldBuffer<double>(
"gamma");
3379 double gamma = *gammaPtr;
3383 rhoPtr[iPoint] = 0.0;
3384 rhoEPtr[iPoint] = 0.0;
3386 for(
int iDim = 0;iDim < numDim;iDim++){
3389 rhoVPtr[iPoint+dimOffset] = 0.0;
3394 double rhoVL = rhoL*uL;
3395 double rhoEL = pL/(gamma-1.0) + 0.5*rhoL*uL*uL;
3398 double rhoVR = rhoR*uR;
3399 double rhoER = pR/(gamma-1.0) + 0.5*rhoR*uR*uR;
3402 double loc1 = physicalExtent[2*(jumpDim-1)]+x0;
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;
3415 kStart = partitionBufferInterval[2].first;
3416 kEnd = partitionBufferInterval[2].second;
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;
3431 double cloc = gridCoords[bufferIndex + (jumpDim-1)*numPointsBuffer];
3435 if (cloc > loc1 && cloc < loc2) {
3436 rhoPtr[bufferIndex] = rhoL;
3439 rhoVPtr[bufferIndex + (jumpDim-1)*numPointsBuffer] = rhoVL;
3441 rhoEPtr[bufferIndex] = rhoEL;
3443 rhoPtr[bufferIndex] = rhoR;
3446 rhoVPtr[bufferIndex + (jumpDim-1)*numPointsBuffer] = rhoVR;
3448 rhoEPtr[bufferIndex] = rhoER;
3456 template<
typename Gr
idType,
typename StateType>
3458 StateType ¶mState,
const std::vector<double> &inParams,
3459 const std::vector<int> &inFlags,
int threadId)
3462 double M_init = 0.0;
3464 int numParams = inParams.size();
3465 if(!(numParams >= 1))
3468 M_init = inParams[0];
3475 const std::vector<size_t> &
bufferSizes(inGrid.BufferSizes());
3476 const std::vector<size_t> &
gridSizes(inGrid.GridSizes());
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());
3490 int rhoHandle = inState.GetDataIndex(
"rho");
3494 double *rhoPtr = rhoData.
Data<
double>();
3498 int rhoVHandle = inState.GetDataIndex(
"rhoV");
3502 double *rhoVPtr = rhoVData.
Data<
double>();
3506 int rhoEHandle = inState.GetDataIndex(
"rhoE");
3510 double *rhoEPtr = rhoEData.
Data<
double>();
3515 double *gammaPtr = paramState.template GetFieldBuffer<double>(
"gamma");
3516 double gamma = *gammaPtr;
3520 rhoPtr[iPoint] = 0.0;
3521 rhoEPtr[iPoint] = 0.0;
3523 for(
int iDim = 0;iDim < numDim;iDim++){
3526 rhoVPtr[iPoint+dimOffset] = 0.0;
3530 double rhoRef = 0.42869404474479600;
3531 double TRef = 298.15;
3533 double gm1 = gamma - 1;
3534 double gp1 = gamma + 1;
3537 double C = 4.5951198501345889;
3538 double delta1 = 0.05;
3540 double rho1 = rhoRef;
3542 double p1 = rho1*R*T1;
3543 double a1 = std::sqrt(gamma*R*T1);
3544 double M1 = M_init*M_init;
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);
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;
3566 kStart = partitionBufferInterval[2].first;
3567 kEnd = partitionBufferInterval[2].second;
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;
3577 double x = gridCoords[bufferIndex];
3580 eta = 0.5*(1 + std::tanh(C*x/delta1));
3582 eta = 0.5*(1 + std::tanh(C*(xn-x)/delta1));
3585 rhoPtr[bufferIndex] = ((1-eta)*rho2 + eta*rho1)/rhoRef;
3589 rhoVPtr[bufferIndex] = ((1-eta)*rho2*u2)/(rhoRef*a1);
3591 rhoEPtr[bufferIndex] = ((1-eta)*(p2/gm1 + 0.5*rho2*u2*u2) + eta*(p1/gm1))/(rhoRef*a1*a1);
3599 template<
typename Gr
idType,
typename StateType,
typename BoundaryType>
3601 StateType &inParam,std::vector<BoundaryType> &inBoundaries)
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());
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");
3618 double cflValue = *CFLPtr;
3619 double cRefValue = *cRefPtr;
3620 double gammaValue = *gammaPtr;
3623 int rhoHandle = inState.GetDataIndex(
"rho");
3627 double *rhoPtr = rhoData.
Data<
double>();
3631 int rhoVHandle = inState.GetDataIndex(
"rhoV");
3635 double *rhoVPtr = rhoVData.
Data<
double>();
3639 int rhoEHandle = inState.GetDataIndex(
"rhoE");
3643 double *rhoEPtr = rhoEData.
Data<
double>();
3651 rhoPtr[iPoint] = 1.0;
3652 rhoEPtr[iPoint] = 1.0/(gammaValue-1.0);
3654 for(
int iDim = 0;iDim < numDim;iDim++){
3657 rhoVPtr[iPoint+dimOffset] = 0.0;
int ComputeDVBuffer(const pcpp::IndexIntervalType ®ionInterval, const std::vector< size_t > &bufferSizes, const std::vector< double *> &stateBuffers, std::vector< double *> &dvBuffers)
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)
pcpp::IndexIntervalType regionInterval
int InitializeAcousticPulse(const GridType &inGrid, StateType &inState, StateType &inParam, const std::vector< double > &inParams, const std::vector< int > &inFlags, int threadId, std::ostream *messageStream)
int ValidateState(const DatasetType &inState, const DatasetType &inParam, std::ostream &outStream)
int InitializeGaussianScalar(const GridType &inGrid, StateType &inState, StateType &inParamState, const std::vector< double > &inParams, int threadId, std::ostream *messageStream=NULL)
void const size_t const size_t const size_t const int const int const double const double const double * rhoVBuffer
int InitializeAdvectionDiffusion(const GridType &inGrid, StateType &inState, StateType &inParamState, const std::vector< double > &inParams, int threadId, std::ostream *messageStream=NULL)
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)
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)
void const size_t const size_t * gridSizes
void RenewStream(std::ostringstream &outStream)
double Window(double tWidth, double wWidth, double centerX, double centerY, double centerZ, double x, double y, double z)
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)
void CartesianSetup(std::ostream &outStream, const std::vector< int > &cartCoords, const std::vector< int > &cartDims)
int InitializeHoles(const GridType &inGrid, StateType &inState, StateType &inParam, std::vector< BoundaryType > &inBoundaries)
int SetupEulerState(const GridType &inGrid, StateType &inState, StateType &inParams, int numScalars, bool withFlux=false)
void const size_t const size_t const size_t const int const double const int const double * velocity
int InitializeUniformFlow(const GridType &inGrid, StateType &inState, StateType &inParamState, const std::vector< double > &inParams, int threadId, std::ostream *messageStream=NULL)
int InitializeShocktube(const GridType &inGrid, StateType &inState, StateType ¶mState, const std::vector< double > &inParams, const std::vector< int > &inFlags, int threadId)
void const size_t const size_t const size_t const double const double * x
void const size_t const size_t const size_t const int const int const double const double const double const double * rhoEBuffer
std::vector< int > isPeriodic
void Everyone(const std::string &outString, std::ostream &outStream, fixtures::CommunicatorType &comm)
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
double Parabola(double amp, double centerX, double centerY, double centerZ, double x, double y, double z)
int InitializeSimulationFixtures(GridType &inGrid, plascom2::operators::sbp::base &inOperator, int interiorOrder, pcpp::CommunicatorType &inComm, std::ostream *messageStreamPtr=NULL)
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)
Main encapsulation of MPI.
sizeextent RelativeTranslation(const sizeextent &inOrigin, const sizeextent &inDestination) const
Encapsulation for a collection of operator stencils.
void Overlap(const sizeextent &inextent, sizeextent &outextent) const
int InitializeDensityPulse(const GridType &inGrid, StateType &inState, StateType &inParamState, const std::vector< double > &inParams, int threadId, std::ostream *messageStream=NULL)
void const size_t const size_t * bufferSizes
int InitializeRiemann1D(const GridType &inGrid, StateType &inState, StateType ¶mState, const std::vector< double > &inParams, const std::vector< int > &inFlags, int threadId)
void const size_t const size_t const size_t const int * numScalars
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)
std::ostream & PrettyPrint(std::ostream &outStream) const
int SetupCartesianTopology(pcpp::CommunicatorType ¶llelCommunicator, pcpp::ParallelTopologyInfoType &topologyInfo, pcpp::CommunicatorType &topoCommunicator, std::ostream &messageStream)
Sets up a communicator with Cartesian topology.
int Initialize(base &stencilSet, int interiorOrder)
Initialize the sbp::base stencilset with the SBP operator of given order.
void const size_t const size_t const size_t const int const int const double const double * rhoBuffer
Simple Block Structured Mesh object.
int boundaryDepth
Boundary depth is the number of biased boundary stencils for one boundary.
int InitializeShock1D(const GridType &inGrid, StateType &inState, StateType &inParamState, const std::vector< double > &inParams, int threadId, std::ostream *messageStream)
void InitSimple(const ContainerType &inSize)
void const size_t * numPointsBuffer
double Pulse(double amp, double width, double centerX, double centerY, double centerZ, double x, double y, double z)