/// <summary> /// Calculate the pressure $p$ via /// $p = (\kappa - 1) \rho e$ /// </summary> /// <param name="state"> /// <see cref="IEquationOfState.GetPressure"/> /// </param> /// <returns> /// \f$ \rho e (\kappa - 1)\f$ /// where /// \f$ \rho e\f$ = <see name="StateVector.InnerEnergy"/> /// and \f$ \kappa\f$ is the heat capacity ratio /// supplied to <see cref="IdealGas.IdealGas"/>. /// </returns> public double GetPressure(StateVector state) { var r = (HeatCapacityRatio - 1.0) * state.InnerEnergy; Debug.Assert(r > 0, "pressure in ideal gas law is zero or negative"); return(r); }
/// <summary> /// Returns AV acoording to the configured sensor using a smoothed /// (sine wave) AV activation profile. /// </summary> /// <param name="jCell"> /// The considered cell /// </param> /// <param name="cellSize"> /// A measure for the size of the cell /// </param> /// <param name="state"> /// The local flow state /// </param> /// <returns> /// For some sensor value \f$ s \f$, the artificial viscosity /// \f$ \nu \f$ is calculated as /// \f[ /// \nu = \nu_0 \begin{cases} /// 0 & \text{ if } s \lt s_0 - \kappa\\ /// 1 & \text{ if } s \gt s_0 + \kappa\\ /// \frac{1}{2} \left(1 + \sin(\frac{1}{2 \kappa} \pi (s - s_0) \right) /// \end{cases} /// \f] /// </returns> public double GetViscosity(int jCell, double cellSize, StateVector state) { double sensorValue = Math.Log10(sensor.GetSensorValue(jCell) + 1e-15); double epsilonE; if (sensorValue < sensorLimit - kappa) { epsilonE = 0.0; } else if (sensorValue > sensorLimit + kappa) { epsilonE = refMaxViscosity; } else { epsilonE = 0.5 * refMaxViscosity * (1.0 + Math.Sin(0.5 * Math.PI * (sensorValue - sensorLimit) / kappa)); } double lambdaMax = this.lambdaMax ?? state.SpeedOfSound + state.Velocity.Abs(); Debug.Assert(lambdaMax >= 0.0, "lambdaMax is NaN or negative"); //lambdaMax = 20; //DMR //lambdaMax = 2; //Shock Tube double fudgeFactor = this.fudgeFactor ?? 0.5; // Kloeckner (2011) epsilonE = fudgeFactor * epsilonE * lambdaMax * cellSize / dgDegree; Debug.Assert(epsilonE >= 0.0, "AV is NaN or negative"); return(epsilonE); }
private void SetAVForSpecies(CellMask speciesMask, string speciesName) { int D = CompressibleEnvironment.NumberOfDimensions; foreach (Chunk chunk in speciesMask) { MultidimensionalArray meanValues = MultidimensionalArray.Create(chunk.Len, D + 2); this.Density.GetSpeciesShadowField(speciesName).EvaluateMean(chunk.i0, chunk.Len, meanValues.ExtractSubArrayShallow(-1, 0), 0, 0.0); for (int d = 0; d < D; d++) { this.Momentum[d].GetSpeciesShadowField(speciesName).EvaluateMean(chunk.i0, chunk.Len, meanValues.ExtractSubArrayShallow(-1, d + 1), 0, 0.0); } this.Energy.GetSpeciesShadowField(speciesName).EvaluateMean(chunk.i0, chunk.Len, meanValues.ExtractSubArrayShallow(-1, D + 1), 0, 0.0); for (int i = 0; i < chunk.Len; i++) { int cell = chunk.i0 + i; StateVector state = new StateVector(meanValues.ExtractSubArrayShallow(i, -1).To1DArray(), this.Control.GetMaterial()); Debug.Assert(!double.IsNaN(state.SpeedOfSound), "State vector is NaN! Okay if level set is outside of the domain"); double localViscosity = this.ArtificialViscosityLaw.GetViscosity(cell, ((GridData)this.GridData).Cells.h_min[cell], state); Debug.Assert(localViscosity >= 0.0); this.ArtificialViscosityField.SetMeanValue(cell, localViscosity); } } }
public void New2QubitStateVectorInitialStateTest() { // Arrange StateVector sv; Complex expect0IdxValue = Complex.One; Complex expect1IdxValue = Complex.Zero; Complex expect2IdxValue = Complex.Zero; Complex expect3IdxValue = Complex.Zero; // Act sv = new StateVector(2); Complex actual0IdxValue = sv[0]; Complex actual1IdxValue = sv[1]; Complex actual2IdxValue = sv[2]; Complex actual3IdxValue = sv[3]; // Assert Assert.IsTrue(expect0IdxValue == actual0IdxValue && expect1IdxValue == actual1IdxValue && expect2IdxValue == actual2IdxValue && expect3IdxValue == actual3IdxValue, $"Initial StateVector state with 2 qubit, " + $"expected [ {expect0IdxValue}, {expect1IdxValue}, {expect2IdxValue}, {expect3IdxValue} ]" + $"but found [ {actual0IdxValue}, {actual1IdxValue}, {actual2IdxValue}, {actual3IdxValue} ]."); }
/* * public void ApplyTo(ref StateVector inStateVector, ref StateVector outStateVector) { * int controlToBinary = 1 << _controlQubit; * int currentToBinary = 1 << _qubit; * * * for (int i = 0; i < inStateVector.length; i++) { * * if ((i & controlToBinary) > 0) { * int swapPosition = i ^ currentToBinary; * outStateVector[swapPosition] = inStateVector[i]; * } else { * outStateVector[i] = inStateVector[i]; * } * } * * } */ public void ApplyTo(ref StateVector inStateVector, ref StateVector outStateVector) { int qubit0ToBinary = 1 << _qubit0; int qubit1ToBinary = 1 << _qubit1; int qubit0Mask = ~qubit0ToBinary; int qubit1Mask = ~qubit1ToBinary; StateVector auxStateVector = outStateVector; outStateVector = inStateVector; inStateVector = auxStateVector; int match = _qubit0 | _qubit1; int currentPosition = match; while (currentPosition < inStateVector.length) { int swapPosition0 = currentPosition & qubit0Mask; int swapPosition1 = currentPosition & qubit1Mask; Complex c = outStateVector[swapPosition0]; outStateVector[swapPosition0] = outStateVector[swapPosition1]; outStateVector[swapPosition1] = c; // next pos currentPosition += 1; currentPosition |= match; } }
/// <summary> /// Calculates the boundary value for an isolating slip wall according /// to the first variant described in VegtVen2002. The basic idea is to /// impose \f$ \vec{u} \cdot \vec{n} = 0\f$ (slip wall) by /// setting the edge momentum to /// \f$ \vec{m}^+ = \vec{m}^- - 2((\rho \vec{u})^- \cdot \vec{n})\vec{n}\f$ /// which mimics a mirrored flow at the other side of the wall. /// </summary> /// <param name="time"> /// <see cref="BoundaryCondition.GetBoundaryState"/> /// </param> /// <param name="x"> /// <see cref="BoundaryCondition.GetBoundaryState"/> /// </param> /// <param name="normal"> /// <see cref="BoundaryCondition.GetBoundaryState"/> /// </param> /// <param name="stateIn"> /// <see cref="BoundaryCondition.GetBoundaryState"/> /// </param> /// <returns> /// <see cref="BoundaryCondition.GetBoundaryState"/> /// </returns> public override StateVector GetBoundaryState(double time, double[] x, double[] normal, StateVector stateIn) { Vector normalVector = GetNormalVector(normal); Debug.Assert(normal.Length == stateIn.Dimension); int D = normal.Length; StateVector stateOut; if (WallVelocities == null) { // VegtVen2002, page 14, second equation Vector mOut = stateIn.Momentum - 2.0 * (stateIn.Momentum * normalVector) * normalVector; stateOut = new StateVector(stateIn.Material, stateIn.Density, mOut, stateIn.Energy); } else { Vector uWall = new Vector(D); for (int d = 0; d < D; d++) { uWall[d] = WallVelocities[d](x, time); } Vector uOut = stateIn.Velocity - 2.0 * ((stateIn.Velocity - uWall) * normalVector) * normalVector; stateOut = StateVector.FromPrimitiveQuantities( stateIn.Material, stateIn.Density, uOut, stateIn.Pressure); } return(stateOut); }
public void ApplyOneGateTest() { // Arrange QuantumCircuit qc = new QuantumCircuit(2); StateVector sv = new StateVector(2); sv[0] = Complex.Zero; sv[1] = Complex.Zero; sv[2] = Complex.Zero; sv[3] = Complex.One; IGate gate = new IGateMocks.GateStub(_ => sv); Complex expect0IdxValue = Complex.Zero; Complex expect1IdxValue = Complex.Zero; Complex expect2IdxValue = Complex.Zero; Complex expect3IdxValue = Complex.One; // Act qc.Apply(gate); Complex actual0IdxValue = qc.stateVector[0]; Complex actual1IdxValue = qc.stateVector[1]; Complex actual2IdxValue = qc.stateVector[2]; Complex actual3IdxValue = qc.stateVector[3]; // Assert Assert.IsTrue(expect0IdxValue == actual0IdxValue && expect1IdxValue == actual1IdxValue && expect2IdxValue == actual2IdxValue && expect3IdxValue == actual3IdxValue, $"Apply IGate should modify StateVector, " + $"expected [ {expect0IdxValue}, {expect1IdxValue}, {expect2IdxValue}, {expect3IdxValue} ]" + $"but found [ {actual0IdxValue}, {actual1IdxValue}, {actual2IdxValue}, {actual3IdxValue} ]."); }
public void ApplyOneGateProvideStateVectorToGate() { // Arrange QuantumCircuit qc = new QuantumCircuit(2); qc.stateVector[0] = Complex.Zero; qc.stateVector[1] = Complex.Zero; qc.stateVector[2] = Complex.One; qc.stateVector[3] = Complex.Zero; StateVector sv = new StateVector(2); IGate gate = new IGateMocks.GateStub(s => sv = s); Complex expect0IdxValue = Complex.Zero; Complex expect1IdxValue = Complex.Zero; Complex expect2IdxValue = Complex.One; Complex expect3IdxValue = Complex.Zero; // Act qc.Apply(gate); Complex actual0IdxValue = sv[0]; Complex actual1IdxValue = sv[1]; Complex actual2IdxValue = sv[2]; Complex actual3IdxValue = sv[3]; // Assert Assert.IsTrue(expect0IdxValue == actual0IdxValue && expect1IdxValue == actual1IdxValue && expect2IdxValue == actual2IdxValue && expect3IdxValue == actual3IdxValue, $"QuantumCircuit should pass the current StateVector to the gate, " + $"expected [ {expect0IdxValue}, {expect1IdxValue}, {expect2IdxValue}, {expect3IdxValue} ]" + $"but found [ {actual0IdxValue}, {actual1IdxValue}, {actual2IdxValue}, {actual3IdxValue} ]."); }
/// <summary> /// Computes the exact solution of the Riemann problem, samples it at /// <paramref name="x"/> (coordinate normal to discontinuity position) /// at time <paramref name="t"/> /// </summary> /// <param name="meanPressure"></param> /// <param name="meanVelocity"></param> /// <param name="x"></param> /// <param name="t"></param> /// <returns></returns> public StateVector GetState(double meanPressure, double meanVelocity, double x, double t) { double S = x / t; Sample(meanPressure, meanVelocity, S, out densityStar, out normalVelocityStar, out pressureStar); // Return exact solution in conservative variables Vector u; Material material; if (S <= meanVelocity) { // left of the interface u = velocityLeft; material = stateLeft.Material; } else { // right of the interface u = velocityRight; material = stateRight.Material; } u[0] = normalVelocityStar; return(StateVector.FromPrimitiveQuantities( material, densityStar, u.FromEdgeCoordinates(edgeNormal), pressureStar)); }
/* * public void ApplyTo(ref StateVector inStateVector, ref StateVector outStateVector) { * int controlToBinary = 1 << _controlQubit; * int currentToBinary = 1 << _qubit; * * * for (int i = 0; i < inStateVector.length; i++) { * * if ((i & controlToBinary) > 0) { * int swapPosition = i ^ currentToBinary; * outStateVector[swapPosition] = inStateVector[i]; * } else { * outStateVector[i] = inStateVector[i]; * } * } * * } */ public void ApplyTo(ref StateVector inStateVector, ref StateVector outStateVector) { int controlToBinary = 1 << _controlQubit; int currentToBinary = 1 << _qubit; StateVector auxStateVector = outStateVector; outStateVector = inStateVector; inStateVector = auxStateVector; int match = controlToBinary | currentToBinary; int currentPosition = match; while (currentPosition < inStateVector.length) { int swapPosition = currentPosition ^ currentToBinary; Complex c = outStateVector[swapPosition]; outStateVector[swapPosition] = outStateVector[currentPosition]; outStateVector[currentPosition] = c; // next pos currentPosition += 1; currentPosition |= match; } }
public override double InnerEdgeFlux(double[] x, double time, StateVector stateIn, StateVector stateOut, ref ilPSP.Vector normal, int edgeIndex) { // Version: Subtract -s * flux from upwind double uIn = stateIn.Velocity * normal; double uOut = stateOut.Velocity * normal; double correction = 0.0; if (edgeIndex < 0) { double s = levelSetVelocity(x, time) * normal; double relativeSpeed = 0.5 * (uIn + uOut) - s; if (relativeSpeed > 0.0) { correction = s * equationComponent.VariableValue(stateIn); } else { correction = s * equationComponent.VariableValue(stateOut); } } double waveSpeedIn = uIn + stateIn.SpeedOfSound; double waveSpeedOut = uOut + stateOut.SpeedOfSound; double penalty = Math.Max(waveSpeedIn, waveSpeedOut); double valueIn = equationComponent.VariableValue(stateIn); double fluxIn = equationComponent.Flux(stateIn) * normal; double valueOut = equationComponent.VariableValue(stateOut); double fluxOut = equationComponent.Flux(stateOut) * normal; return(0.5 * (fluxIn + fluxOut) - 0.5 * penalty * (valueOut - valueIn) - correction); }
/// <summary> /// Calculates the boundary value for an isolating slip wall according /// to the first variant described in VegtVen2002. The basic idea is to /// impose \f$ \vec{u} \cdot \vec{n} = 0\f$ (slip wall) by /// setting the edge momentum to /// \f$ \vec{m}^+ = \vec{m}^- - 2((\rho \vec{u})^- \cdot \vec{n})\vec{n}\f$ /// which mimics a mirrored flow at the other side of the wall. /// </summary> /// <param name="time"> /// <see cref="BoundaryCondition.GetBoundaryState"/> /// </param> /// <param name="x"> /// <see cref="BoundaryCondition.GetBoundaryState"/> /// </param> /// <param name="normal"> /// <see cref="BoundaryCondition.GetBoundaryState"/> /// </param> /// <param name="stateIn"> /// <see cref="BoundaryCondition.GetBoundaryState"/> /// </param> /// <returns> /// <see cref="BoundaryCondition.GetBoundaryState"/> /// </returns> public override StateVector GetBoundaryState(double time, double[] x, double[] normal, StateVector stateIn) { Vector3D normalVector = GetNormalVector(normal); StateVector stateOut; if (WallVelocities == null) { // VegtVen2002, page 14, second equation Vector3D mOut = stateIn.Momentum - 2.0 * (stateIn.Momentum * normalVector) * normalVector; stateOut = new StateVector(stateIn.Material, stateIn.Density, mOut, stateIn.Energy); } else { Vector3D uWall = new Vector3D(); for (int d = 0; d < CNSEnvironment.NumberOfDimensions; d++) { uWall[d] = WallVelocities[d](x, time); } Vector3D uOut = stateIn.Velocity - 2.0 * ((stateIn.Velocity - uWall) * normalVector) * normalVector; stateOut = StateVector.FromPrimitiveQuantities( stateIn.Material, stateIn.Density, uOut, stateIn.Pressure); } return(stateOut); }
private StateVectorDto ConvertState(StateVector state) { if (state == null) { return(null); } return(new StateVectorDto { BarometricAltitude = state.BarometricAltitude, CallSign = state.CallSign, GeometricAltitudeInMeters = state.GeometricAltitudeInMeters, Icao24 = state.Icao24, LastContact = state.LastContact, Latitude = state.Latitude, Longitude = state.Longitude, OnGround = state.OnGround, OriginCountry = state.OriginCountry, PositionSource = ConvertPositionSource(state.PositionSource), Sensors = state.Sensors, Spi = state.Spi, Squawk = state.Squawk, TimePosition = state.TimePosition, TrueTrack = state.TrueTrack, Velocity = state.Velocity, VerticalRate = state.VerticalRate }); throw new NotImplementedException(); }
/// <summary> /// Computes the maximum admissible step-size according to /// GassnerEtAl2008, equation 67. /// </summary> /// <param name="i0"></param> /// <param name="Length"></param> /// <returns></returns> protected override double GetCFLStepSize(int i0, int Length) { int iKref = gridData.Cells.GetRefElementIndex(i0); int noOfNodesPerCell = base.EvaluationPoints[iKref].NoOfNodes; MultidimensionalArray levelSetValues = speciesMap.Tracker.DataHistories[0].Current.GetLevSetValues(base.EvaluationPoints[iKref], i0, Length); SpeciesId species = speciesMap.Tracker.GetSpeciesId(speciesMap.Control.FluidSpeciesName); var hMinArray = speciesMap.CellAgglomeration.CellLengthScales[species]; //var volFrac = speciesMap.QuadSchemeHelper.CellAgglomeration.CellVolumeFrac[species]; //var hMinGass = speciesMap.h_min; //var hMin = gridData.Cells.h_min; double cfl = double.MaxValue; for (int i = 0; i < Length; i++) { int cell = i0 + i; //double hmin = hMin[cell] * volFrac[cell]; double hmin = hMinArray[cell]; //double hmin = hMinGass[cell]; for (int node = 0; node < noOfNodesPerCell; node++) { if (levelSetValues[i, node].Sign() != (double)speciesMap.Control.FluidSpeciesSign) { continue; } Material material = speciesMap.GetMaterial(double.NaN); Vector3D momentum = new Vector3D(); for (int d = 0; d < CNSEnvironment.NumberOfDimensions; d++) { momentum[d] = momentumValues[d][i, node]; } StateVector state = new StateVector( material, densityValues[i, node], momentum, energyValues[i, node]); double coeff = Math.Max(4.0 / 3.0, config.EquationOfState.HeatCapacityRatio / config.PrandtlNumber); double cflhere = hmin * hmin / coeff / (state.GetViscosity(cell) / config.ReynoldsNumber); #if DEBUG if (double.IsNaN(cflhere)) { throw new Exception("Could not determine CFL number"); } #endif cfl = Math.Min(cfl, cflhere); } } int degree = workingSet.ConservativeVariables.Max(f => f.Basis.Degree); int twoNPlusOne = 2 * degree + 1; return(cfl * GetBetaMax(degree) / twoNPlusOne / twoNPlusOne / Math.Sqrt(CNSEnvironment.NumberOfDimensions)); //return cfl / twoNPlusOne / twoNPlusOne; }
/// <summary> /// See Toro2009, equation 10.73 /// </summary> /// <param name="state"> /// <see cref="HLLCFlux.GetModifiedVariableValue"/> /// </param> /// <param name="cellWaveSpeed"> /// <see cref="HLLCFlux.GetModifiedVariableValue"/> /// </param> /// <param name="cellNormalVelocity"> /// <see cref="HLLCFlux.GetModifiedVariableValue"/> /// </param> /// <param name="intermediateWaveSpeed"> /// <see cref="HLLCFlux.GetModifiedVariableValue"/> /// </param> /// <param name="normal"> /// <see cref="HLLCFlux.GetModifiedVariableValue"/> /// </param> /// <returns>See Toro2009, equation 10.73</returns> /// <remarks> /// Always remember: DON'T multiply with intermediateWaveSpeed here /// like Toro does! He is working in a rotated coordinate system! In /// our setup, this makes result dependent on the direction of the /// normal vector. Correct version follows from BattenEtAl1997, /// equation 37 /// </remarks> protected override double GetModifiedVariableValue(StateVector state, double cellWaveSpeed, double cellNormalVelocity, double intermediateWaveSpeed, ref Vector normal) { return(state.Density * (cellWaveSpeed - cellNormalVelocity) / (cellWaveSpeed - intermediateWaveSpeed) * (state.Velocity[momentumComponent] + (intermediateWaveSpeed - cellNormalVelocity) * normal[momentumComponent])); }
/// <summary> /// Calculates the local speed of sound from the given density. For /// details, e.g. see FarhatEtAl2008. /// </summary> /// <param name="state"> /// <see cref="IEquationOfState.GetSpeedOfSound"/> /// </param> /// <returns> /// \f$ /// c = \sqrt{\gamma \alpha \rho^{gamma-1}} /// \f$ /// </returns> public double GetSpeedOfSound(StateVector state) { double r = Math.Sqrt(HeatCapacityRatio * alpha * Math.Pow(state.Density, HeatCapacityRatio - 1)); Debug.Assert(r > 0, "speed of sound smaller or equal to 0.0"); Debug.Assert(!r.IsNaNorInf(), "speed of sound is NAN or INF"); return(r); }
/// <summary> /// Calculates the speed of sound. /// </summary> /// <param name="state"> /// <see cref="IEquationOfState.GetSpeedOfSound"/> /// </param> /// <returns> /// \f$ /// a = \sqrt{\kappa \frac{p}{\rho (1 - \rho b)}} /// \f$ /// </returns> public double GetSpeedOfSound(StateVector state) { double r = Math.Sqrt(HeatCapacityRatio * state.Pressure / state.Density / (1.0 - state.Density * Covolume)); Debug.Assert(r > 0, "speed of sound smaller or equal to 0.0"); Debug.Assert(!r.IsNaNorInf(), "speed of sound is NAN or INF"); return(r); }
/// <summary> /// Calculates the boundary values for a subsonic outlet (Mach number /// smaller than 1). We have to impose one condition (here, we choose /// the pressure <see cref="pressureFunction"/>) and extrapolate the /// other values following FerzigerPeric2001 (p. 315ff) /// </summary> /// <param name="time"> /// <see cref="BoundaryCondition.GetBoundaryState"/> /// </param> /// <param name="x"> /// <see cref="BoundaryCondition.GetBoundaryState"/> /// </param> /// <param name="normal"> /// <see cref="BoundaryCondition.GetBoundaryState"/> /// </param> /// <param name="stateIn"> /// <see cref="BoundaryCondition.GetBoundaryState"/> /// </param> /// <returns> /// \f$ /// (\rho^-, u^-, p^*)^T /// \f$ /// </returns> public override StateVector GetBoundaryState(double time, double[] x, double[] normal, StateVector stateIn) { return(StateVector.FromPrimitiveQuantities( stateIn.Material, stateIn.Density, stateIn.Velocity, pressureFunction(x, time))); }
/// <summary> /// Calculates the speed of sound $a$ via /// $a = \sqrt{\kappa \frac{p + \pi}{\rho}}$. /// </summary> /// <param name="state"> /// <see cref="IEquationOfState.GetSpeedOfSound"/> /// </param> /// <returns> /// \f$ \sqrt{\kappa \frac{p + \pi}{\rho}}\f$ /// where /// \f$ \rho\f$ = <see name="StateVector.Density"/>, /// \f$ p\f$ = <see name="StateVector.Pressure"/> /// and \f$ \kappa\f$ and /// \f$ \pi\f$ are the heat capacity ratio /// and the reference pressure supplied to /// <see cref="StiffenedGas.StiffenedGas"/>, respectively. /// </returns> public double GetSpeedOfSound(StateVector state) { double r = Math.Sqrt(HeatCapacityRatio * (state.Pressure + ReferencePressure) / state.Density); Debug.Assert(r > 0, "speed of sound smaller or equal to 0.0"); Debug.Assert(!r.IsNaNorInf(), "speed of sound is NAN or INF"); return(r); }
/// <summary> /// Calculates the speed of sound. /// </summary> /// <param name="state"> /// <see cref="IEquationOfState.GetSpeedOfSound"/> /// </param> /// <returns> /// \f$ /// a = \sqrt{\frac{\kappa p + a \rho^2 (2 b \rho - 1)}{\rho (1 - \rho b)}} /// \f$ /// </returns> public double GetSpeedOfSound(StateVector state) { double p = state.Pressure; double rho = state.Density; return(Math.Sqrt((HeatCapacityRatio * p + attraction * rho * rho * (2.0 * covolume * rho - 1.0)) / rho / (1.0 - covolume * rho))); }
/// <summary> /// Calculates the local speed of sound \f$a\f$ via /// \f$a = \sqrt{\frac{p}{\rho}} / \text{Ma}\f$, where /// \f$\text{Ma}\f$ is the reference Mach number /// </summary> /// <param name="state"> /// <see cref="IEquationOfState.GetSpeedOfSound"/> /// </param> /// <returns> /// \f$ \sqrt{\frac{p}{\rho}} / \text{Ma}\f$ /// where /// \f$ \rho\f$ = <see name="StateVector.Density"/> /// \f$ p\f$ = <see name="StateVector.Pressure"/>. /// </returns> public double GetSpeedOfSound(StateVector state) { // Equals sqrt{\kappa \frac{p}{\rho}} for Ma = \kappa double r = Math.Sqrt(state.Pressure / state.Density) / state.Material.MachNumber; Debug.Assert(r > 0, "speed of sound smaller or equal to 0.0"); Debug.Assert(r.IsNaNorInf() == false, "speed of sound is NAN or INF"); return(r); }
/// <summary> /// Uses <see cref="ExactRiemannSolver"/> in order to compute the exact /// solution of the Riemann problem. /// </summary> /// <param name="x"> /// <see cref="InnerEdgeFlux(double[], double, StateVector, StateVector, ref Vector3D, int)"/> /// </param> /// <param name="time"> /// <see cref="InnerEdgeFlux(double[], double, StateVector, StateVector, ref Vector3D, int)"/> /// </param> /// <param name="stateIn"> /// <see cref="InnerEdgeFlux(double[], double, StateVector, StateVector, ref Vector3D, int)"/> /// </param> /// <param name="stateOut"> /// <see cref="InnerEdgeFlux(double[], double, StateVector, StateVector, ref Vector3D, int)"/> /// </param> /// <param name="normal"> /// <see cref="InnerEdgeFlux(double[], double, StateVector, StateVector, ref Vector3D, int)"/> /// </param> /// <param name="edgeIndex"> /// <see cref="InnerEdgeFlux(double[], double, StateVector, StateVector, ref Vector3D, int)"/> /// </param> /// <returns> /// <see cref="ExactRiemannSolver.GetCentralState"/> /// </returns> protected internal override double InnerEdgeFlux(double[] x, double time, StateVector stateIn, StateVector stateOut, ref Vector3D normal, int edgeIndex) { ExactRiemannSolver riemannSolver = new ExactRiemannSolver( stateIn, stateOut, normal); StateVector stateEdge = riemannSolver.GetCentralState(); return(equationComponent.Flux(stateEdge) * normal); }
/// <summary> /// Calculates the pressure. /// </summary> /// <param name="state"> /// <see cref="IEquationOfState.GetPressure"/> /// </param> /// <returns> /// \f$ /// p = (\kappa - 1) \frac{\rho}{1 - \rho b} e /// \f$ /// </returns> public double GetPressure(StateVector state) { double apparentDensity = state.Density / (1.0 - Covolume * state.Density); Debug.Assert( apparentDensity > 0.0, "Invalid density (might be bigger than 1 / covolume)"); return((HeatCapacityRatio - 1.0) * apparentDensity * state.SpecificInnerEnergy); }
/// <summary> /// Constructor for the multiphase case, initializes values /// </summary> /// <param name="stateLeft"> /// State left of the discontinuity /// </param> /// <param name="stateRight"> /// State right of the discontinuity /// </param> /// <param name="edgeNormal"> /// The normal vector of the edge between the 'left' and the 'right' /// state (pointing from 'left' to 'right'). /// </param> public ExactRiemannSolver(StateVector stateLeft, StateVector stateRight, Vector edgeNormal) { IdealGas gasLeft = stateLeft.Material.EquationOfState as IdealGas; IdealGas gasRight = stateRight.Material.EquationOfState as IdealGas; if (gasLeft == null || gasRight == null) { throw new ArgumentException( "Exact Riemann solver only implemented for ideal gases"); } this.edgeNormal = edgeNormal; this.stateLeft = stateLeft; this.stateRight = stateRight; this.kappaLeft = gasLeft.HeatCapacityRatio; this.kappaRight = gasRight.HeatCapacityRatio; this.densityLeft = stateLeft.Density; this.pressureLeft = stateLeft.Pressure; this.densityRight = stateRight.Density; this.pressureRight = stateRight.Pressure; velocityLeft = stateLeft.Velocity.ToEdgeCoordinates(edgeNormal); velocityRight = stateRight.Velocity.ToEdgeCoordinates(edgeNormal); this.normalVelocityLeft = velocityLeft[0]; this.normalVelocityRight = velocityRight[0]; speedOfSoundLeft = Math.Sqrt(kappaLeft * pressureLeft / densityLeft); speedOfSoundRight = Math.Sqrt(kappaRight * pressureRight / densityRight); // left side G1L = (kappaLeft - 1.0) / (2.0 * kappaLeft); G2L = (kappaLeft + 1.0) / (2.0 * kappaLeft); G3L = 2.0 * kappaLeft / (kappaLeft - 1.0); G4L = 2.0 / (kappaLeft - 1.0); G5L = 2.0 / (kappaLeft + 1.0); G6L = (kappaLeft - 1.0) / (kappaLeft + 1.0); G7L = (kappaLeft - 1.0) / 2.0; G8L = kappaLeft - 1.0; // right side G1R = (kappaRight - 1.0) / (2.0 * kappaRight); G2R = (kappaRight + 1.0) / (2.0 * kappaRight); G3R = 2.0 * kappaRight / (kappaRight - 1.0); G4R = 2.0 / (kappaRight - 1.0); G5R = 2.0 / (kappaRight + 1.0); G6R = (kappaRight - 1.0) / (kappaRight + 1.0); G7R = (kappaRight - 1.0) / 2.0; G8R = kappaRight - 1.0; // the pressure positivity condition is tested for if (G4L * (speedOfSoundLeft + speedOfSoundRight) <= (normalVelocityRight - normalVelocityLeft)) { throw new ArgumentOutOfRangeException("the initial data is such that vacuum is generated"); } }
/// <summary> /// Calculates the speed of sound. /// </summary> /// <param name="state"> /// <see cref="IEquationOfState.GetSpeedOfSound"/> /// </param> /// <returns> /// \f$ /// a = \sqrt{\frac{\kappa p + a \rho^2 (2 b \rho - 1)}{\rho (1 - \rho b)}} /// \f$ /// </returns> public double GetSpeedOfSound(StateVector state) { double p = state.Pressure; double rho = state.Density; double r = Math.Sqrt((HeatCapacityRatio * p + attraction * rho * rho * (2.0 * covolume * rho - 1.0)) / rho / (1.0 - covolume * rho)); Debug.Assert(r > 0, "speed of sound smaller or equal to 0.0"); Debug.Assert(!r.IsNaNorInf(), "speed of sound is NAN or INF"); return(r); }
public ComplexShape(List <PointOnGrid> inputPoints, MaxMin maxmin, eShape shape) { Vertices = inputPoints; //oMaxMin = new MaxMin(10000, 8000); oMaxMin = maxmin; stateVec = new StateVector() { PitchAngle = 0, RollAngle = 0, YawAngle = 0, XCG = 100, YCG = 0, ZCG = 0 }; ShapeID = (uint)shape; }
/// <summary> /// The viscosity to be used in the given cell /// </summary> /// <param name="jCell"></param> /// <param name="cellSize"></param> /// <param name="state"></param> /// <returns></returns> public double GetViscosity(int jCell, double cellSize, StateVector state) { if (sensor.GetSensorValue(jCell) > sensorLimit) { return(refViscosity * cellSize / dgDegree); } else { return(0.0); } }
/// <summary> /// <see cref="INonlinearFlux.BorderEdgeFlux"/> /// </summary> /// <param name="time"></param> /// <param name="jEdge"></param> /// <param name="x"></param> /// <param name="normal"></param> /// <param name="normalFlipped"></param> /// <param name="EdgeTags"></param> /// <param name="EdgeTagsOffset"></param> /// <param name="Uin"></param> /// <param name="Offset"></param> /// <param name="Lenght"></param> /// <param name="Output"></param> public void BorderEdgeFlux( double time, int jEdge, MultidimensionalArray x, MultidimensionalArray normal, bool normalFlipped, byte[] EdgeTags, int EdgeTagsOffset, MultidimensionalArray[] Uin, int Offset, int Lenght, MultidimensionalArray Output) { int NoOfNodes = Uin[0].GetLength(1); int D = CNSEnvironment.NumberOfDimensions; double sign = normalFlipped ? -1.0 : 1.0; MultidimensionalArray[] Uout = new MultidimensionalArray[Uin.Length]; for (int i = 0; i < Uin.Length; i++) { Uout[i] = MultidimensionalArray.Create(Uin[i].GetLength(0), Uin[i].GetLength(1)); } Material material = speciesMap.GetMaterial(double.NaN); for (int e = 0; e < Lenght; e++) { int edge = e + Offset; for (int n = 0; n < NoOfNodes; n++) { double[] xLocal = new double[D]; double[] normalLocal = new double[D]; for (int d = 0; d < D; d++) { xLocal[d] = x[edge, n, d]; normalLocal[d] = normal[edge, n, d] * sign; } StateVector stateIn = new StateVector(material, Uin, edge, n); StateVector stateBoundary = boundaryMap.GetBoundaryState( EdgeTags[e + EdgeTagsOffset], time, xLocal, normalLocal, stateIn); Uout[0][edge, n] = stateBoundary.Density; for (int d = 0; d < D; d++) { Uout[d + 1][edge, n] = stateBoundary.Momentum[d]; } Uout[D + 1][edge, n] = stateBoundary.Energy; } } InnerEdgeFlux(time, jEdge, x, normal, Uin, Uout, Offset, Lenght, Output); }
/// <summary> /// See Toro2009, equation 10.73 /// </summary> /// <param name="state"> /// <see cref="HLLCFlux.GetModifiedVariableValue"/> /// </param> /// <param name="cellWaveSpeed"> /// <see cref="HLLCFlux.GetModifiedVariableValue"/> /// </param> /// <param name="cellNormalVelocity"> /// <see cref="HLLCFlux.GetModifiedVariableValue"/> /// </param> /// <param name="intermediateWaveSpeed"> /// <see cref="HLLCFlux.GetModifiedVariableValue"/> /// </param> /// <param name="normal"> /// <see cref="HLLCFlux.GetModifiedVariableValue"/> /// </param> /// <returns>See Toro2009, equation 10.73</returns> protected override double GetModifiedVariableValue(StateVector state, double cellWaveSpeed, double cellNormalVelocity, double intermediateWaveSpeed, ref Vector normal) { // corrected according to dimensionless equations double MachScaling = config.EquationOfState.HeatCapacityRatio * config.MachNumber * config.MachNumber; double factor = intermediateWaveSpeed * MachScaling + state.Pressure / (state.Density * (cellWaveSpeed - cellNormalVelocity)); return(state.Density * (cellWaveSpeed - cellNormalVelocity) / (cellWaveSpeed - intermediateWaveSpeed) * (state.Energy / state.Density + factor * (intermediateWaveSpeed - cellNormalVelocity))); }
public StateContext(int length, Action <string> onError) { _onError = onError; _buffer = new char[length]; _bufferIndex = 0; this.Character = '\0'; this.Head = null; this.Flags = new StateVector(); this.State = State.None; this.Stack = new Stack <MemberExpression>(); }