/* In the diagram below Ui represents the interior state. This should be represnted by (*this). Ug1 and Ug2 are the first and second layers of ghost cells respectively. They are the output of the function. The input "layer" determines whether Ug1 or Ug2 is output for BCs that use extrapolation. Reflected boundaries (slipWall, viscousWall) do not use the layer input. Instead Ui+1 must be specified as (*this) to output Ug2. ____________________|___________ | | | | | | | | | Ug2 | Ug1 | Ui | | | | | | | | | |_________|_________|__________| | boundary face Currently the following boundary conditions are supported: slipWall, viscousWall, characteristic, stagnationInlet, pressureOutlet, subsonicInflow, subsonicOutflow, supersonicInflow, supersonicOutflow */ primVars primVars::GetGhostState( const string &bcType, const vector3d<double> &areaVec, const string &surf, const input &inputVars, const idealGas &eqnState, const int layer )const{ //bcType -- type of boundary condition to supply ghost cell for //areaVec -- area vector of boundary face //surf -- i, j, k surface of boundary //inputVar -- all input variables //eqnState -- equation of state //layer -- layer of ghost cell to return (first (closest) or second (farthest)) //the instance of primVars being acted upon should be the interior cell bordering the boundary primVars ghostState = (*this); //set ghost state equal to boundary state to start //check to see that ghost layer corresponds to allowable number if ( !(layer == 1 || layer == 2) ){ cerr << "ERROR: Error in primVars::GetGhostState. Requesting ghost state at a ghost layer " << layer << ". Please choose either 1 or 2" << endl; exit(0); } //normalize area vector (should always point out of domain) vector3d<double> normArea; if (surf == "il" || surf == "jl" || surf == "kl"){ normArea = -1.0 * areaVec / areaVec.Mag(); //at lower surface normal should point out of domain for ghost cell calculation } else if (surf == "iu" || surf == "ju" || surf == "ku"){ normArea = areaVec / areaVec.Mag(); } double normVelCellCenter = 0; //slip wall boundary condition ---------------------------------------------------------------------------------------------------------------- //slipWall is implemented as a reflection of the interior states so that there is no mass flow across the boundary. if (bcType == "slipWall"){ //for slip wall state should be reflected across boundary face, density and pressure stay equal to the boundary cell vector3d<double> stateVel = (*this).Velocity(); normVelCellCenter = stateVel.DotProd(normArea); //for a slip wall the velocity of the boundary cell center is reflected across the boundary face to get the velocity at the ghost cell center vector3d<double> ghostVel (stateVel.X() - 2.0 * normArea.X() * normVelCellCenter, stateVel.Y() - 2.0 * normArea.Y() * normVelCellCenter, stateVel.Z() - 2.0 * normArea.Z() * normVelCellCenter); ghostState.data[1] = ghostVel.X(); ghostState.data[2] = ghostVel.Y(); ghostState.data[3] = ghostVel.Z(); //numerical BCs for rho and pressure, same as boundary state } //viscous wall boundary condition ---------------------------------------------------------------------------------------------------------------- //viscous wall uses the interior density and pressure, but flips the sign on the velocity so that the velocity at the boundary is 0. else if (bcType == "viscousWall"){ //for viscous wall velocity at face should be 0.0, density and pressure stay equal to the boundary cell vector3d<double> stateVel = (*this).Velocity(); //ghost cell velocity at cell center is set to opposite of velocity at boundary cell center so that velocity at face will be zero vector3d<double> ghostVel (-1.0 * stateVel.X(), -1.0 * stateVel.Y(), -1.0 * stateVel.Z() ); ghostState.data[1] = ghostVel.X(); ghostState.data[2] = ghostVel.Y(); ghostState.data[3] = ghostVel.Z(); //numerical BCs for rho and pressure, same as boundary state } //subsonic inflow boundary condition -------------------------------------------------------------------------------------------------------------- //this boundary condition enforces density and velocity as freestream inputs (constant) and extrapolates from the interior state to get pressure //this is a primative implementation, stagnationInlet or characteristic are better options else if (bcType == "subsonicInflow"){ //set velocity and density to freestream values double sos = eqnState.GetSoS( inputVars.PRef(), inputVars.RRef() ); vector3d<double> ghostVel = inputVars.VelRef() / sos; //nondimensionalize velocity ghostState.data[0] = 1.0; ghostState.data[1] = ghostVel.X(); ghostState.data[2] = ghostVel.Y(); ghostState.data[3] = ghostVel.Z(); //numerical bc for pressure, same as boundary state if (layer == 2){ //extrapolate to get ghost state at 2nd layer ghostState = 2.0 * ghostState - (*this); } } //subsonic outflow boundary condition ------------------------------------------------------------------------------------------------------------ //this boundary condition enforces pressure as a freestream input (constant) and extrapolates density and velocity from the interior state //this is a primative implementation, pressureOutlet or characteristic are better options else if (bcType == "subsonicOutflow"){ //set pressure to freestream value ghostState.data[4] = 1.0 / eqnState.Gamma(); //numerical bcs for density, velocity -- equal to boundary cell if (layer == 2){ //extrapolate to get ghost state at 2nd layer ghostState = 2.0 * ghostState - (*this); } } //characteristic boundary condition --------------------------------------------------------------------------------------------------------------- //this is a characteristic based boundary condition which is appropriate for subsonic and supersonic flow. It automatically switches between inflow //and outflow as needed. It also automatically determines the number of characteristics that need to be specified at the boundary (subsonic vs supersonic) else if (bcType == "characteristic"){ //freestream variables double freeSoS = eqnState.GetSoS(inputVars.PRef(), inputVars.RRef()); vector3d<double> freeVel = inputVars.VelRef() / freeSoS; primVars freeState(1.0, 1.0/eqnState.Gamma(), freeVel); //internal variables double velIntNorm = (*this).Velocity().DotProd(normArea); double SoSInt = eqnState.GetSoS((*this).P(), (*this).Rho()); double machInt = fabs(velIntNorm)/SoSInt; if ( machInt >= 1.0 && velIntNorm < 0.0 ){ //supersonic inflow ------------------------------------------------------------ //characteristics all go into the domain, so use freestream values for both riemann invariants ghostState = freeState; } else if ( machInt >= 1.0 && velIntNorm >= 0.0 ){ //supersonic outflow ----------------------------------------------------- //characteristics all leave the domain, so use interior values for both riemann invariants ghostState = (*this); } else if ( machInt < 1.0 && velIntNorm < 0.0 ){ //subsonic inflow ----------------------------------------------------------- //characteristics go in both directions, use interior values for plus characteristic and freestream values for minus characteristic double rhoSoSInt = (*this).Rho() * SoSInt; vector3d<double> velDiff = freeState.Velocity() - (*this).Velocity(); ghostState.data[4] = 0.5 * (freeState.P() + (*this).P() - rhoSoSInt * normArea.DotProd(velDiff)); //plus characteristic //minus characteristic ghostState.data[0] = freeState.Rho() + (ghostState.P() - freeState.P()) / (SoSInt * SoSInt); ghostState.data[1] = freeState.U() - normArea.X() * (freeState.P() - ghostState.P()) / rhoSoSInt; ghostState.data[2] = freeState.V() - normArea.Y() * (freeState.P() - ghostState.P()) / rhoSoSInt; ghostState.data[3] = freeState.W() - normArea.Z() * (freeState.P() - ghostState.P()) / rhoSoSInt; } else if ( machInt < 1.0 && velIntNorm >= 0.0 ){ //subsonic outflow ---------------------------------------------------------- //characteristics go in both directions, use interior values for plus characteristic and freestream values for minus characteristic double rhoSoSInt = (*this).Rho() * SoSInt; ghostState.data[4] = freeState.P(); //minus characteristic //plus characteristic ghostState.data[0] = (*this).Rho() + ( ghostState.P() - (*this).P() ) / (SoSInt * SoSInt); ghostState.data[1] = (*this).U() + normArea.X() * ( (*this).P() - ghostState.P() ) / rhoSoSInt; ghostState.data[2] = (*this).V() + normArea.Y() * ( (*this).P() - ghostState.P() ) / rhoSoSInt; ghostState.data[3] = (*this).W() + normArea.Z() * ( (*this).P() - ghostState.P() ) / rhoSoSInt; } else { cerr << "ERROR: flow condition for characteristic BC is not recognized!" << endl; cerr << "Interior state: " << (*this) << endl; cerr << "Ghost state: " << ghostState << endl; exit(0); } if (layer == 2){ //extrapolate to get ghost state at 2nd layer ghostState = 2.0 * ghostState - (*this); } } //supersonic inflow boundary condition ------------------------------------------------------------------------------------------------------------ //this boundary condition enforces the entire state as the specified freestream state else if (bcType == "supersonicInflow"){ //physical boundary conditions - fix everything double sos = eqnState.GetSoS(inputVars.PRef(),inputVars.RRef()); vector3d<double> vel = inputVars.VelRef() / sos; //nondimensional velocity ghostState.data[0] = 1.0; //nondimensional density ghostState.data[1] = vel.X(); ghostState.data[2] = vel.Y(); ghostState.data[3] = vel.Z(); ghostState.data[4] = 1.0 / eqnState.Gamma(); //nondimensional pressure } //supersonic outflow boundary condition ------------------------------------------------------------------------------------------------------------ //this boundary condition enforces the entire state as extrapolated from the interior (zeroth order extrapolation) else if (bcType == "supersonicOutflow"){ //do nothing and return boundary state -- numerical BCs for all if (layer == 2){ //extrapolate to get ghost state at 2nd layer ghostState = 2.0 * ghostState - (*this); } } //stagnation inlet boundary condition -------------------------------------------------------------------------------------------------------------- //this boundary condition is appropriate for subsonic flow. It is particularly well suited for internal flows. Implementation from Blazek else if (bcType == "stagnationInlet"){ double g = eqnState.Gamma() - 1.0; //calculate outgoing riemann invarient double rNeg = (*this).Velocity().DotProd(normArea) - 2.0 * (*this).SoS(eqnState) / g; //calculate SoS on boundary double cosTheta = -1.0 * (*this).Velocity().DotProd(normArea) / (*this).Velocity().Mag(); double stagSoSsq = pow((*this).SoS(eqnState),2.0) + 0.5 * g * (*this).Velocity().MagSq(); double sosB = -1.0 * rNeg * g / (g * cosTheta * cosTheta + 2.0) * (1.0 + cosTheta * sqrt( (g * cosTheta * cosTheta + 2.0) * stagSoSsq / (g * rNeg * rNeg) - 0.5 * g ) ); double tb = inputVars.StagInletT0() / inputVars.TRef() * (sosB * sosB / stagSoSsq); double aRef = eqnState.GetSoS(inputVars.PRef(),inputVars.RRef()); double pb = inputVars.StagInletP0() / (inputVars.RRef() * aRef * aRef) * pow(sosB * sosB / stagSoSsq, eqnState.Gamma()/g); double vbMag = sqrt(2.0 / g * (inputVars.StagInletT0() / inputVars.TRef() - tb)); ghostState.data[0] = eqnState.GetDensityTP(tb,pb); ghostState.data[1] = vbMag * inputVars.StagInletDx(); ghostState.data[2] = vbMag * inputVars.StagInletDy(); ghostState.data[3] = vbMag * inputVars.StagInletDz(); ghostState.data[4] = pb; if (layer == 2){ //extrapolate to get ghost state at 2nd layer ghostState = 2.0 * ghostState - (*this); } } //pressure outlet boundary condition --------------------------------------------------------------------------------------------------------------- //this boundary condition is appropriate for subsonic flow. Implementation from Blazek else if (bcType == "pressureOutlet"){ double aRef = eqnState.GetSoS(inputVars.PRef(),inputVars.RRef()); //reference speed of sound double pb = inputVars.PressureOutletP() / (inputVars.RRef() * aRef * aRef); //nondimensional pressure from input file double SoSInt = (*this).SoS(eqnState); double rhoSoSInt = (*this).Rho() * SoSInt; ghostState.data[4] = pb; ghostState.data[0] = (*this).Rho() + ( ghostState.P() - (*this).P() ) / (SoSInt * SoSInt); ghostState.data[1] = (*this).U() + normArea.X() * ( (*this).P() - ghostState.P() ) / rhoSoSInt; ghostState.data[2] = (*this).V() + normArea.Y() * ( (*this).P() - ghostState.P() ) / rhoSoSInt; ghostState.data[3] = (*this).W() + normArea.Z() * ( (*this).P() - ghostState.P() ) / rhoSoSInt; if (layer == 2){ //extrapolate to get ghost state at 2nd layer ghostState = 2.0 * ghostState - (*this); } } //interblock boundary condition --------------------------------------------------------------------------------------------------------------- //this boundary condition is appropriate for point matched interfaces between physical blocks or processor blocks else if (bcType == "interblock"){ //do nothing -- assign interior state to ghost state (already done) //for second layer of ghost cells interior state should be 2nd interior cell } else { cerr << "ERROR: Error in primVars::GetGhostState ghost state for BC type " << bcType << " is not supported!" << endl; cerr << "surface is " << surf << endl; exit(0); } return ghostState; }