/// <summary> /// Constructs a new flux builder. /// </summary> /// <param name="control"></param> /// <param name="boundaryMap"></param> /// <param name="speciesMap"></param> /// <param name="gridData"></param> public OptimizedSIPGFluxBuilder(CNSControl control, IBoundaryConditionMap boundaryMap, ISpeciesMap speciesMap, GridData gridData) : base(control, boundaryMap, speciesMap) { this.gridData = gridData; //Create Functions for calculation the cell metric, needed as Func<> because //LevelSet field and HMF options are not known at this point if (speciesMap is IBM.ImmersedSpeciesMap) { // IBM case ImmersedSpeciesMap IBMspeciesMap = speciesMap as ImmersedSpeciesMap; cellMetricFunc = delegate() { SpeciesId species = IBMspeciesMap.Tracker.GetSpeciesId(IBMspeciesMap.Control.FluidSpeciesName); MultidimensionalArray cellMetric = IBMspeciesMap.CellAgglomeration.CellLengthScales[species].CloneAs(); cellMetric.ApplyAll(x => 1 / x); // Needed, because 1/x produces NaN in void cells and can happen that penalty factor leads then to NaN cellMetric.ApplyAll(delegate(double x) { if (double.IsNaN(x) || double.IsInfinity(x)) { return(0); } else { return(x); } }); return(cellMetric); }; } else { // Non-IBM cellMetricFunc = () => gridData.Cells.cj; } }
public static Query Integral(string fieldName) { return(delegate(IApplication <AppControl> app, double time) { IProgram <CNSControl> program = app as IProgram <CNSControl>; if (program == null) { throw new Exception(); } ImmersedSpeciesMap speciesMap = program.SpeciesMap as ImmersedSpeciesMap; IBMControl control = program.Control as IBMControl; if (speciesMap == null || control == null) { throw new Exception( "Query is only valid for immersed boundary runs"); } SpeciesId species = speciesMap.Tracker.GetSpeciesId(control.FluidSpeciesName); int order = control.LevelSetQuadratureOrder; CellQuadratureScheme scheme = speciesMap.QuadSchemeHelper.GetVolumeQuadScheme( species, true, speciesMap.SubGrid.VolumeMask); DGField dgField = app.IOFields.Single(f => f.Identification == fieldName); return DGField.IntegralOverEx(scheme, new Func((X, U, j) => (U[0])), 2, dgField); }); }
public ConductivityInSpeciesBulk(double penalty, double sw, ThermalMultiphaseBoundaryCondMap bcMap, int D, string spcName, SpeciesId spcId, double _kA, double _kB) : base(penalty, D, bcMap) { base.m_alpha = sw; this.m_bcMap = bcMap; this.m_spcId = spcId; ValidSpecies = spcName; switch (spcName) { case "A": currentk = _kA; complementk = _kB; break; case "B": currentk = _kB; complementk = _kA; break; default: throw new ArgumentException("Unknown species."); } double muFactor = Math.Max(currentk, complementk) / currentk; base.m_penalty_base = penalty * muFactor; base.tempFunction = this.m_bcMap.bndFunction[VariableNames.Temperature + "#" + spcName]; base.fluxFunction = D.ForLoop(d => bcMap.bndFunction[VariableNames.HeatFluxVectorComponent(d) + "#" + spcName]); }
public DivergenceInSpeciesBulk_Volume(int _component, int _D, SpeciesId spcId, double _rho, double _vorZeichen, bool _RescaleConti) : base(_component, _D) { m_spcId = spcId; scale = _vorZeichen / ((_RescaleConti) ? _rho : 1.0); }
//MultidimensionalArray h_max_Edge; /// <summary> /// Ctor. /// </summary> public PressureStabilizationInBulk(double PressureStabilizationFactor, double Reynolds, string spcName, SpeciesId spcId) : base(PressureStabilizationFactor, Reynolds) { this.PressureStabilizationFactor = PressureStabilizationFactor; this.Reynolds = Reynolds; this.m_spcName = spcName; this.m_spcId = spcId; }
/// <summary> /// Configuration sanity checks, to be used by constructors of derived classes. /// </summary> protected void CommonConfigurationChecks() { if (this.Config_MassMatrixShapeandDependence == MassMatrixShapeandDependence.IsNonIdentity && this.Config_LevelSetHandling != LevelSetHandling.None) { throw new ArgumentOutOfRangeException("illegal configuration"); } if (this.Config_MassMatrixShapeandDependence == MassMatrixShapeandDependence.IsIdentity && this.Config_MassScale != null) { // may occur e.g. if one runs the FSI solver as a pure single-phase solver, // i.e. if the Level-Set is outside the domain. foreach (var kv in this.Config_MassScale) { SpeciesId spId = kv.Key; double[] scaleVec = kv.Value.ToArray(); //for (int i = 0; i < scaleVec.Length; i++) { // if (scaleVec[i] != 1.0) // throw new ArithmeticException(string.Format("XDG time-stepping: illegal mass scale, mass matrix option {0} is set, but scaling factor for species {1}, variable no. {2} ({3}) is set to {4} (expecting 1.0).", // MassMatrixShapeandDependence.IsIdentity, this.m_LsTrk.GetSpeciesName(kv.Key), i, this.CurrentStateMapping.Fields[i].Identification, scaleVec[i])); //} } } }
public PowerofGravity(int SpatDim, string spcNmn, SpeciesId spcId, double _rho) { m_D = SpatDim; m_spcId = spcId; ValidSpecies = spcNmn; rho = _rho; }
public static void GetDefaultSelection(this SubBlockSelector sbs, SelectionType SType, int iCell) { SpeciesId A = ((XdgAggregationBasis)sbs.GetMapping.AggBasis[0]).UsedSpecies[0]; SpeciesId B = ((XdgAggregationBasis)sbs.GetMapping.AggBasis[0]).UsedSpecies[1]; sbs.CellSelector(iCell, false); //do not change this, selection corresponds to hardcoded masking //see GetSubIndices switch (SType) { case SelectionType.degrees: sbs.ModeSelector(p => p == 1); break; case SelectionType.species: sbs.SpeciesSelector(A); break; case SelectionType.variables: sbs.VariableSelector(1); break; case SelectionType.all_combined: sbs.ModeSelector(p => p == 1); sbs.SpeciesSelector(A); sbs.VariableSelector(1); break; } }
//int[][,] CoarseToFineSpeciesIndex; /// <summary> /// Returns the species index of species <paramref name="spid"/> in /// composite/aggregate cell <paramref name="jAgg"/> . /// </summary> public int GetSpeciesIndex(int jAgg, SpeciesId spid) { if (AggCellsSpecies[jAgg] != null) { return(Array.IndexOf(AggCellsSpecies[jAgg], spid)); } else { int[] BaseCells = this.AggGrid.iLogicalCells.AggregateCellToParts[jAgg]; var LsTrk = this.XDGBasis.Tracker; int iSpc = LsTrk.Regions.IsSpeciesPresentInCell(spid, BaseCells[0]) ? 0 : -1; #if DEBUG if (iSpc >= 0) { foreach (int j in BaseCells) { Debug.Assert(LsTrk.Regions.GetSpeciesIndex(spid, j) == iSpc); } } else { foreach (int j in BaseCells) { Debug.Assert(LsTrk.Regions.IsSpeciesPresentInCell(spid, BaseCells[0]) == false); } } #endif return(iSpc); } }
public override double Perform(double dt) { if (agglomerationPatternHasChanged) { // TO DO: Agglomerate difference between old $cutAndTargetCells and new $cutAndTargetCells only BuildEvaluatorsAndMasks(); // Required whenever agglomeration pattern changes SpeciesId speciesId = speciesMap.Tracker.GetSpeciesId(speciesMap.Control.FluidSpeciesName); IBMMassMatrixFactory massMatrixFactory = speciesMap.GetMassMatrixFactory(Mapping); BlockMsrMatrix nonAgglomeratedMassMatrix = massMatrixFactory.BaseFactory.GetMassMatrix( Mapping, new Dictionary <SpeciesId, IEnumerable <double> >() { { speciesId, Enumerable.Repeat(1.0, Mapping.NoOfVariables) } }, inverse: false); IBMUtility.SubMatrixSpMV(nonAgglomeratedMassMatrix, 1.0, CurrentState, 0.0, CurrentState, cutCells); speciesMap.Agglomerator.ManipulateRHS(CurrentState, Mapping); IBMUtility.SubMatrixSpMV(massMatrixFactory.InverseMassMatrix, 1.0, CurrentState, 0.0, CurrentState, cutAndTargetCells); speciesMap.Agglomerator.Extrapolate(CurrentState.Mapping); //Broadcast to RungeKutta ??? } dt = base.Perform(dt); speciesMap.Agglomerator.Extrapolate(CurrentState.Mapping); return(dt); }
public ViscosityInSpeciesBulk_GradUtranspTerm(double penalty, double sw, IncompressibleMultiphaseBoundaryCondMap bcMap, string spcName, SpeciesId spcId, int _d, int _D, double _muA, double _muB, double _betaS = 0.0) : base(penalty, _d, _D, bcMap, NSECommon.ViscosityOption.ConstantViscosity, constantViscosityValue: double.NegativeInfinity) { base.m_alpha = sw; this.m_bcMap = bcMap; m_spcId = spcId; switch (spcName) { case "A": currentMu = _muA; complementMu = _muB; break; case "B": currentMu = _muB; complementMu = _muA; break; default: throw new ArgumentException("Unknown species."); } double muFactor = Math.Max(currentMu, complementMu) / currentMu; base.m_penalty_base = penalty * muFactor; int D = base.m_D; base.velFunction = D.ForLoop(d => this.m_bcMap.bndFunction[VariableNames.Velocity_d(d) + "#" + spcName]); betaS = _betaS; }
/// <summary> /// L2 error with respect to given reference solution. The quadrature /// is determined from the settings in <see cref="IBMControl"/> /// </summary> /// <param name="fieldName"></param> /// <param name="referenceSolution"></param> /// <returns></returns> public static Query L2Error(string fieldName, Func <double[], double, double> referenceSolution) { return(delegate(IApplication <AppControl> app, double time) { IProgram <CNSControl> program = app as IProgram <CNSControl>; if (program == null) { throw new Exception(); } ImmersedSpeciesMap speciesMap = program.SpeciesMap as ImmersedSpeciesMap; IBMControl control = program.Control as IBMControl; if (speciesMap == null || control == null) { throw new Exception( "Query is only valid for immersed boundary runs"); } SpeciesId species = speciesMap.Tracker.GetSpeciesId(control.FluidSpeciesName); int order = control.LevelSetQuadratureOrder; CellQuadratureScheme scheme = speciesMap.QuadSchemeHelper.GetVolumeQuadScheme( species, true, speciesMap.SubGrid.VolumeMask); DGField dgField = app.IOFields.Single(f => f.Identification == fieldName); return dgField.L2Error(referenceSolution.Vectorize(time), order, scheme); }); }
/// <summary> /// Initialize identity /// </summary> public AuxiliaryHeatFlux_Identity(int component, string spcName, SpeciesId spcId) { this.component = component; ValidSpecies = spcName; this.m_spcId = spcId; }
public ConvectionInSpeciesBulk_LLF(int SpatDim, IncompressibleMultiphaseBoundaryCondMap _bcmap, string spcName, SpeciesId spcId, int _component, double _rho, double _LFF, LevelSetTracker _lsTrk) : base(SpatDim, _bcmap, _component, false) { // rho = _rho; m_spcId = spcId; ValidSpecies = spcName; //varMode = _varMode; this.lsTrk = _lsTrk; this.LFF = _LFF; this.m_bcmap = _bcmap; int dir = base.m_component; base.velFunction = new Func <double[], double, double> [GridCommons.FIRST_PERIODIC_BC_TAG, SpatDim]; for (int d = 0; d < SpatDim; d++) { base.velFunction.SetColumn(m_bcmap.bndFunction[VariableNames.Velocity_d(d) + "#" + spcName], d); } //SubGrdMask = lsTrk.Regions.GetSpeciesSubGrid(spcId).VolumeMask.GetBitMaskWithExternal(); }
public static void ProjectKineticDissipation(this XDGField proj, LevelSetTracker LsTrk, DGField[] Velocity, double[] mu, int momentFittingOrder, int HistInd = 1) { using (new FuncTrace()) { int D = LsTrk.GridDat.SpatialDimension; if (Velocity.Count() != D) { throw new ArgumentException(); } if (LsTrk.SpeciesIdS.Count != mu.Length) { throw new ArgumentException(); } var SchemeHelper = LsTrk.GetXDGSpaceMetrics(LsTrk.SpeciesIdS.ToArray(), momentFittingOrder, HistInd).XQuadSchemeHelper; for (int iSpc = 0; iSpc < LsTrk.SpeciesIdS.Count; iSpc++) { SpeciesId spcId = LsTrk.SpeciesIdS[iSpc]; double _mu = mu[iSpc]; var Uspc = Velocity.Select(u => (u as XDGField).GetSpeciesShadowField(spcId)).ToArray(); ScalarFunctionEx spcKinDissip = GetSpeciesKineticDissipationFunc(Uspc, _mu); proj.GetSpeciesShadowField(spcId).ProjectField(spcKinDissip); } } }
/// <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; }
public Dissipation(int SpatDim, double _mu, string spcNmn, SpeciesId spcId, bool _withPressure) { m_D = SpatDim; mu = _mu; m_spcId = spcId; ValidSpecies = spcNmn; this.withPressure = _withPressure; }
public StressDivergence_Local(int SpatDim, double _mu, string spcNmn, SpeciesId spcId, bool transposed = false) { m_D = SpatDim; mu = _mu; m_spcId = spcId; transposedTerm = transposed; ValidSpecies = spcNmn; }
public PressureInSpeciesBulk(int _d, IncompressibleMultiphaseBoundaryCondMap bcMap, string spcName, SpeciesId spcId) : base(_d, bcMap) { base.pressureFunction = bcMap.bndFunction[VariableNames.Pressure + "#" + spcName]; this.m_bcMap = bcMap; //this.m_spcName = spcName; this.m_spcId = spcId; }
protected void BlockTest() { double MU_A = 0.1; BlockMsrMatrix Msc; double[] bsc; MultiphaseCellAgglomerator aggsc; MassMatrixFactory mass_sc; AssembleMatrix(MU_A, 1.0, out Msc, out bsc, out aggsc, out mass_sc); BlockMsrMatrix Mref; double[] bRef; MultiphaseCellAgglomerator aggRef; MassMatrixFactory massRef; AssembleMatrix(1.0, 1.0, out Mref, out bRef, out aggRef, out massRef); SpeciesId IdA = this.LsTrk.GetSpeciesId("A"); int J = this.GridData.iLogicalCells.NoOfLocalUpdatedCells; int N = this.u.Basis.NonX_Basis.Length; int[] ColIdx = null; for (int j = 0; j < J; j++) { ReducedRegionCode rrc; this.LsTrk.Regions.GetNoOfSpecies(j, out rrc); int SpAIdx = this.LsTrk.GetSpeciesIndex(rrc, IdA); if (SpAIdx < 0) { continue; } int n0 = N * SpAIdx; int nE = n0 + N; for (int n = n0; n < nE; n++) { int i = (int)u.Mapping.GlobalUniqueCoordinateIndex(0, j, n); //var row = Mref.GetRowShallow(i); //for (int k = 0; k < row.Length; k++) // row[k].Value *= MU_A; int LL = Mref.GetOccupiedColumnIndices(i, ref ColIdx); for (int ll = 0; ll < LL; ll++) { Mref[i, ColIdx[ll]] *= MU_A; } } } Mref.Acc(-1.0, Msc); double MdiffNorm = Mref.InfNorm(); Console.WriteLine("matrix difference norm {0}", MdiffNorm); Console.WriteLine("Symm. diff: {0}", Msc.SymmetryDeviation()); }
/// <summary> /// Initialize Diffusion for artificial diffusion /// </summary> public DiffusionInBulk(int _order, int _dimension, MultidimensionalArray _cj, string _variable, string spcName, SpeciesId spcId) : base(_order, _dimension, _cj, _variable) { this.order = _order; this.dimension = _dimension; this.cj = _cj; this.variable = _variable; this.m_spcId = spcId; }
public void NowIntegratingBulk(string speciesName, SpeciesId SpcId, MultidimensionalArray LengthScales) { switch (speciesName) { case "A": alpha = alpha_A; break; case "B": alpha = alpha_B; break; default: throw new NotImplementedException(); } }
public void SetParameter(string speciesName, SpeciesId SpcId, MultidimensionalArray LenScales) { switch (speciesName) { case "A": scale = vorZeichen / ((RescaleConti) ? rhoA : 1.0); break; case "B": scale = vorZeichen / ((RescaleConti) ? rhoB : 1.0); break; default: throw new ArgumentException("Unknown species."); } }
public void SetParameter(string speciesName, SpeciesId SpcId) { switch (speciesName) { case "A": alpha = alpha_A; break; case "B": alpha = alpha_B; break; default: throw new NotImplementedException(); } }
public override int GetHashCode() { unchecked { var hashCode = PetId.GetHashCode(); hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0); hashCode = (hashCode * 397) ^ SpeciesId.GetHashCode(); hashCode = (hashCode * 397) ^ IsActive.GetHashCode(); return(hashCode); } }
public void SetParameter(string speciesName, SpeciesId SpcId) { switch (speciesName) { case "A": rho = rhoA; scale = vorZeichen / ((RescaleConti) ? rhoA : 1.0); SetBndfunction("A"); break; case "B": rho = rhoB; scale = vorZeichen / ((RescaleConti) ? rhoB : 1.0); SetBndfunction("B"); break; default: throw new ArgumentException("Unknown species."); } }
public void SetParameter(string speciesName, SpeciesId SpcId, MultidimensionalArray LenScales) { switch (speciesName) { case "A": oneOverRho = 1.0 / m_rhoA; SetBndfunction("A"); break; case "B": oneOverRho = 1.0 / m_rhoB; SetBndfunction("B"); break; default: throw new ArgumentException("Unknown species."); } }
public void SetParameter(string speciesName, SpeciesId SpcId) { switch (speciesName) { case "A": Viscosity = m_muA; rhs = m_rhsA; complementViscosity = m_muB; break; case "B": Viscosity = m_muB; rhs = m_rhsB; complementViscosity = m_muA; break; default: throw new ArgumentException("Unknown species."); } }
public void SetParameter(string speciesName, SpeciesId __SpcId) { switch (speciesName) { case "A": species_Mu = muA; otherSpecies_Mu = muB; SpcId = __SpcId; break; case "B": species_Mu = muB; otherSpecies_Mu = muA; SpcId = __SpcId; break; default: throw new ArgumentException("Unknown species."); } current_species = speciesName; }
public void SetParameter(string speciesName, SpeciesId SpcId, MultidimensionalArray LengthScales) { switch (speciesName) { case "A": Viscosity = m_muA; rhs = m_rhsA; complementViscosity = m_muB; break; case "B": Viscosity = m_muB; rhs = m_rhsB; complementViscosity = m_muA; break; default: throw new ArgumentException("Unknown species."); } m_LengthScales = LengthScales; }