public List <GraphPoint> Imlicite() { var tempResult = new double[N + 1][]; for (int i = 0; i <= N; i++) { tempResult[i] = new double[K + 1]; } // initialize board conditions for (int i = 0; i <= N; i++) { tempResult[i][0] = U0.Value(XArg(i)); } for (int n = 0; n <= K - 1; n++) { tempResult[0][n + 1] = U1.Value(TimeArg(n + 1)); tempResult[N][n + 1] = U2.Value(TimeArg(n + 1)); } for (int n = 0; n < K; n++) { for (int i = 1; i < N; i++) { tempResult[i][n + 1] = tempResult[i][n] + Gamma * (tempResult[i + 1][n] - 2 * tempResult[i][n] + tempResult[i - 1][n]) + Tao * Fxt.Value(XArg(i), TimeArg(n)); } } var result = new List <GraphPoint>(); for (int i = 0; i <= N; i++) { result.Add(new GraphPoint { X = XArg(i), Y = tempResult[i][K] }); } return(result); }
void ParameterUpdate(IEnumerable <DGField> CurrentState, IEnumerable <DGField> ParameterVar, int CutCellQuadOrder, Dictionary <SpeciesId, MultidimensionalArray> AgglomeratedCellLengthScales) { LevelSet Phi = (LevelSet)(this.LsTrk.LevelSets[0]); SpeciesId[] SpcToCompute = AgglomeratedCellLengthScales.Keys.ToArray(); DGField[] U0; if (CurrentState != null) { U0 = CurrentState.Take(D).ToArray(); } else { U0 = null; } DGField[] Stress0; Stress0 = CurrentState.Skip(D + 1).Take(3).ToArray(); if (U0.Count() != D) { throw new ArgumentException("Spatial dimesion and number of velocity parameter components does not match!"); } if (Stress0.Count() != D + 1) { throw new ArgumentException("Spatial dimesion and number of stress parameter components does not match!"); } // linearization velocity: DGField[] U0_U0mean; if (this.U0meanrequired) { XDGBasis U0meanBasis = new XDGBasis(this.LsTrk, 0); VectorField <XDGField> U0mean = new VectorField <XDGField>(D, U0meanBasis, "U0mean_", XDGField.Factory); U0_U0mean = ArrayTools.Cat <DGField>(U0, U0mean); U0mean.Clear(); ComputeAverageU(U0, U0mean, CutCellQuadOrder, LsTrk.GetXDGSpaceMetrics(SpcToCompute, CutCellQuadOrder, 1).XQuadSchemeHelper); } else { U0_U0mean = new DGField[2 * D]; } //if (this.Control.SetParamsAnalyticalSol == false) { //SinglePhaseField[] __VelocityXGradient = ParameterVar.Skip(2 * D).Take(D).Select(f => f as SinglePhaseField).ToArray(); //SinglePhaseField[] __VelocityYGradient = ParameterVar.Skip(3 * D).Take(D).Select(f => f as SinglePhaseField).ToArray(); //Debug.Assert(ArrayTools.AreEqual(__VelocityXGradient, VelocityXGradient.ToArray(), (fa, fb) => object.ReferenceEquals(fa, fb))); //Debug.Assert(ArrayTools.AreEqual(__VelocityYGradient, VelocityYGradient.ToArray(), (fa, fb) => object.ReferenceEquals(fa, fb))); //if (VelocityXGradient == null) { // VelocityXGradient = new VectorField<XDGField>(D, CurrentState.ElementAt(0).Basis, "VelocityX_Gradient", XDGField.Factory); //} VelocityXGradient.Clear(); VelocityXGradient.GradientByFlux(1.0, U0[0]); //if (VelocityYGradient == null) { // VelocityYGradient = new VectorField<XDGField>(D, CurrentState.ElementAt(1).Basis, "VelocityY_Gradient", XDGField.Factory); //} VelocityYGradient.Clear(); VelocityYGradient.GradientByFlux(1.0, U0[1]); //} if (this.useArtificialDiffusion == true) { throw new NotImplementedException("artificial diffusion not jet fully implemented..."); //SinglePhaseField __ArtificialViscosity = ParameterVar.Skip(5 * D + 1).Take(1).Select(f => f as SinglePhaseField).ToArray()[0]; //if (!object.ReferenceEquals(this.artificalViscosity, __ArtificialViscosity)) // throw new ApplicationException(); //ArtificialViscosity.ProjectArtificalViscosityToDGField(__ArtificialViscosity, perssonsensor, this.Control.SensorLimit, artificialMaxViscosity); } }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="OpMatrix"></param> /// <param name="OpAffine"></param> /// <param name="RowMapping"></param> /// <param name="ColMapping"></param> /// <param name="CurrentState"></param> /// <param name="AgglomeratedCellLengthScales"></param> /// <param name="time"></param> /// <param name="CutCellQuadOrder"></param> /// <param name="SurfaceForce"></param> /// <param name="LevelSetGradient"></param> /// <param name="ExternalyProvidedCurvature"></param> public void AssembleMatrix <T>(BlockMsrMatrix OpMatrix, double[] OpAffine, UnsetteledCoordinateMapping RowMapping, UnsetteledCoordinateMapping ColMapping, IEnumerable <T> CurrentState, Dictionary <SpeciesId, MultidimensionalArray> AgglomeratedCellLengthScales, double time, int CutCellQuadOrder, VectorField <SinglePhaseField> SurfaceForce, VectorField <SinglePhaseField> LevelSetGradient, SinglePhaseField ExternalyProvidedCurvature, double currentWeissenberg, IEnumerable <T> CoupledCurrentState = null, IEnumerable <T> CoupledParams = null) where T : DGField { // checks: if (ColMapping.BasisS.Count != this.m_XOp.DomainVar.Count) { throw new ArgumentException(); } if (RowMapping.BasisS.Count != this.m_XOp.CodomainVar.Count) { throw new ArgumentException(); } int D = this.LsTrk.GridDat.SpatialDimension; if (CurrentState != null && CurrentState.Count() != (D + 4)) { throw new ArgumentException(); } if (OpMatrix == null && CurrentState == null) { throw new ArgumentException(); } DGField[] U0; if (CurrentState != null) { U0 = CurrentState.Take(D).ToArray(); } else { U0 = null; } DGField[] Stress0; Stress0 = CurrentState.Skip(D + 1).Take(3).ToArray(); if (U0.Count() != D) { throw new ArgumentException("Spatial dimesion and number of velocity parameter components does not match!"); } if (Stress0.Count() != D + 1) { throw new ArgumentException("Spatial dimesion and number of stress parameter components does not match!"); } // advanced settings for the navier slip boundary condition // ======================================================== CellMask SlipArea; switch (this.dntParams.GNBC_Localization) { case NavierSlip_Localization.Bulk: { SlipArea = this.LsTrk.GridDat.BoundaryCells.VolumeMask; break; } case NavierSlip_Localization.ContactLine: { SlipArea = null; break; } case NavierSlip_Localization.Nearband: { SlipArea = this.LsTrk.GridDat.BoundaryCells.VolumeMask.Intersect(this.LsTrk.Regions.GetNearFieldMask(this.LsTrk.NearRegionWidth)); break; } case NavierSlip_Localization.Prescribed: { throw new NotImplementedException(); } default: throw new ArgumentException(); } MultidimensionalArray SlipLengths; SlipLengths = this.LsTrk.GridDat.Cells.h_min.CloneAs(); SlipLengths.Clear(); //SlipLengths.AccConstant(-1.0); if (SlipArea != null) { foreach (Chunk cnk in SlipArea) { for (int i = cnk.i0; i < cnk.JE; i++) { switch (this.dntParams.GNBC_SlipLength) { case NavierSlip_SlipLength.hmin_DG: { int degU = ColMapping.BasisS.ToArray()[0].Degree; SlipLengths[i] = this.LsTrk.GridDat.Cells.h_min[i] / (degU + 1); break; } case NavierSlip_SlipLength.hmin_Grid: { SlipLengths[i] = SlipLengths[i] = this.LsTrk.GridDat.Cells.h_min[i]; break; } case NavierSlip_SlipLength.Prescribed_SlipLength: { SlipLengths[i] = this.physParams.sliplength; break; } case NavierSlip_SlipLength.Prescribed_Beta: { SlipLengths[i] = -1.0; break; } } } } } // parameter assembly // ================== LevelSet Phi = (LevelSet)(this.LsTrk.LevelSets[0]); SpeciesId[] SpcToCompute = AgglomeratedCellLengthScales.Keys.ToArray(); // normals: SinglePhaseField[] Normals; // Normal vectors: length not normalized - will be normalized at each quad node within the flux functions. if (this.NormalsRequired) { if (LevelSetGradient == null) { LevelSetGradient = new VectorField <SinglePhaseField>(D, Phi.Basis, SinglePhaseField.Factory); LevelSetGradient.Gradient(1.0, Phi); } Normals = LevelSetGradient.ToArray(); } else { Normals = new SinglePhaseField[D]; } // curvature: SinglePhaseField Curvature; if (this.CurvatureRequired) { Curvature = ExternalyProvidedCurvature; } else { Curvature = null; } // Velocity and stresses for linearization // linearization velocity: DGField[] U0_U0mean; if (this.U0meanrequired) { XDGBasis U0meanBasis = new XDGBasis(this.LsTrk, 0); VectorField <XDGField> U0mean = new VectorField <XDGField>(D, U0meanBasis, "U0mean_", XDGField.Factory); U0_U0mean = ArrayTools.Cat <DGField>(U0, U0mean); } else { U0_U0mean = new DGField[2 * D]; } if (VelocityXGradient == null) { VelocityXGradient = new VectorField <XDGField>(D, CurrentState.ElementAt(0).Basis, "VelocityX_Gradient", XDGField.Factory); } if (VelocityYGradient == null) { VelocityYGradient = new VectorField <XDGField>(D, CurrentState.ElementAt(1).Basis, "VelocityY_Gradient", XDGField.Factory); } // concatenate everything var Params = ArrayTools.Cat <DGField>( U0_U0mean, VelocityXGradient, VelocityYGradient, Stress0, //artificalViscosity, Normals, Curvature, ((SurfaceForce != null) ? SurfaceForce.ToArray() : new SinglePhaseField[D])); // linearization velocity: if (this.U0meanrequired) { VectorField <XDGField> U0mean = new VectorField <XDGField>(U0_U0mean.Skip(D).Take(D).Select(f => ((XDGField)f)).ToArray()); U0mean.Clear(); if (this.physParams.IncludeConvection) { ComputeAverageU(U0, U0mean, CutCellQuadOrder, LsTrk.GetXDGSpaceMetrics(SpcToCompute, CutCellQuadOrder, 1).XQuadSchemeHelper); } } // assemble the matrix & affine vector // =================================== IDictionary <SpeciesId, MultidimensionalArray> InterfaceLengths = this.LsTrk.GetXDGSpaceMetrics(this.LsTrk.SpeciesIdS.ToArray(), CutCellQuadOrder).CutCellMetrics.InterfaceArea; BitArray EvapMicroRegion = this.LsTrk.GridDat.GetBoundaryCells().GetBitMask(); EvapMicroRegion.SetAll(false); // compute matrix if (OpMatrix != null) { if (!useJacobianForOperatorMatrix) { XSpatialOperatorMk2.XEvaluatorLinear mtxBuilder = this.m_XOp.GetMatrixBuilder(LsTrk, ColMapping, Params, RowMapping, SpcToCompute); this.ParameterUpdate(CurrentState, Params, CutCellQuadOrder, AgglomeratedCellLengthScales); foreach (var kv in AgglomeratedCellLengthScales) { mtxBuilder.SpeciesOperatorCoefficients[kv.Key].CellLengthScales = kv.Value; mtxBuilder.SpeciesOperatorCoefficients[kv.Key].EdgeLengthScales = this.LsTrk.GridDat.Edges.h_max_Edge; mtxBuilder.SpeciesOperatorCoefficients[kv.Key].UserDefinedValues.Add("SlipLengths", SlipLengths); mtxBuilder.SpeciesOperatorCoefficients[kv.Key].UserDefinedValues.Add("EvapMicroRegion", EvapMicroRegion); } if (this.m_XOp.SurfaceElementOperator.TotalNoOfComponents > 0) { foreach (var kv in InterfaceLengths) { mtxBuilder.SpeciesOperatorCoefficients[kv.Key].UserDefinedValues.Add("InterfaceLengths", kv.Value); } } mtxBuilder.time = time; mtxBuilder.ComputeMatrix(OpMatrix, OpAffine); foreach (var kv in AgglomeratedCellLengthScales) { mtxBuilder.SpeciesOperatorCoefficients[kv.Key].UserDefinedValues.Add("Weissenbergnumber", currentWeissenberg); } } else { throw new NotImplementedException("The FDbuilder for the Jacobian is missing for the XSpatial Opearator!"); // Finite Difference Linearization //XSpatialOperatorMk2.XEvaluatorLinear FDBuilder = this.m_XOp.GetFDJacobianBuilder(domMap, Params, codMap, this.ParameterUpdate); //foreach (var kv in AgglomeratedCellLengthScales) { // FDbuilder.SpeciesOperatorCoefficients[kv.Key].CellLengthScales = kv.Value; // FDbuilder.SpeciesOperatorCoefficients[kv.Key].UserDefinedValues.Add("SlipLengths", SlipLengths); // FDbuilder.SpeciesOperatorCoefficients[kv.Key].UserDefinedValues.Add("EvapMicroRegion", EvapMicroRegion); //} //if (this.m_XOp.SurfaceElementOperator.TotalNoOfComponents > 0) { // foreach (var kv in InterfaceLengths) { // FDbuilder.SpeciesOperatorCoefficients[kv.Key].UserDefinedValues.Add("InterfaceLengths", kv.Value); // } //} //FDbuilder.time = time; //FDbuilder.ComputeMatrix(OpMatrix, OpAffine); //// FDJacobian has (Mx +b) as RHS, for unsteady calc. we must subtract Mx for real affine Vector! //OpMatrix.SpMV(-1.0, new CoordinateVector(CurrentState), 1.0, OpAffine); //foreach (var kv in AgglomeratedCellLengthScales) { // FDbuilder.SpeciesOperatorCoefficients[kv.Key].UserDefinedValues.Add("Weissenbergnumber", currentWeissenberg); //} } } else { XSpatialOperatorMk2.XEvaluatorNonlin eval = this.m_XOp.GetEvaluatorEx(this.LsTrk, CurrentState.ToArray(), Params, RowMapping, SpcToCompute); foreach (var kv in AgglomeratedCellLengthScales) { eval.SpeciesOperatorCoefficients[kv.Key].CellLengthScales = kv.Value; eval.SpeciesOperatorCoefficients[kv.Key].EdgeLengthScales = this.LsTrk.GridDat.Edges.h_max_Edge; eval.SpeciesOperatorCoefficients[kv.Key].UserDefinedValues.Add("SlipLengths", SlipLengths); eval.SpeciesOperatorCoefficients[kv.Key].UserDefinedValues.Add("EvapMicroRegion", EvapMicroRegion); eval.SpeciesOperatorCoefficients[kv.Key].UserDefinedValues.Add("Weissenbergnumber", currentWeissenberg); } if (this.m_XOp.SurfaceElementOperator.TotalNoOfComponents > 0) { foreach (var kv in InterfaceLengths) { eval.SpeciesOperatorCoefficients[kv.Key].UserDefinedValues.Add("InterfaceLengths", kv.Value); } } eval.time = time; eval.Evaluate(1.0, 1.0, OpAffine); } }
public List <GraphPoint> NotImplicite() { var tempResult = new double[N + 1][]; for (int i = 0; i <= N; i++) { tempResult[i] = new double[K + 1]; } // initialize board conditions for (int i = 0; i <= N; i++) { tempResult[i][0] = U0.Value(XArg(i)); } for (int n = 0; n <= K - 1; n++) { tempResult[0][n + 1] = U1.Value(TimeArg(n + 1)); tempResult[N][n + 1] = U2.Value(TimeArg(n + 1)); } var A = new double[N - 2]; var B = new double[N - 2]; var C = new double[N - 2]; var D = new double[N - 2]; double xi1, xi2, mu1, mu2; for (int i = 1; i <= N - 1 - 2; i++) { A[i] = Gamma; B[i] = Gamma; C[i] = (1 + 2 * Gamma); } for (int n = 0; n <= K - 1; n++) { for (int i = 2; i <= N - 1 - 1; i++) { D[i - 1] = tempResult[i][n] + Tao * Fxt.Value(XArg(i), TimeArg(n)); } xi1 = Gamma / (1 + 2 * Gamma); mu1 = (tempResult[1][n] + Tao * Fxt.Value(XArg(1), TimeArg(n)) + Gamma * tempResult[0][n]) / (1 + 2 * Gamma); xi2 = Gamma / (1 + 2 * Gamma); mu2 = (tempResult[N - 1][n] + Tao * Fxt.Value(XArg(N - 1), TimeArg(n)) + Gamma * tempResult[N][n]) / (1 + 2 * Gamma); var tempY = MetodProgonki(N - 2, A, B, C, D, xi1, mu1, xi2, mu2); for (int i = 1; i <= N - 1; i++) { tempResult[i][n + 1] = tempY[i - 1]; } } var result = new List <GraphPoint>(); for (int i = 0; i <= N; i++) { result.Add(new GraphPoint { X = XArg(i), Y = tempResult[i][K] }); } return(result); }
public void problemConfig(int _np1, int _np2, int _layout_type) { setProblemClass(); _np = this.Ranks.Length; this._np1 = _np1; this._np2 = _np2; _ntdivnp = ((nx * ny) / _np) * nz; this._layout_type = _layout_type; int layout_0D = Constants.layout_0D; int layout_1D = Constants.layout_1D; int layout_2D = Constants.layout_2D; // if(_np1 == 1 && _np2 == 1) { // _layout_type = layout_0D; // } // else if(_np1 == 1) { // _layout_type = layout_1D; // } // else { // _layout_type = layout_2D; // } if (_layout_type == layout_0D) { for (int i = 0; i < 3; i++) { _dims[0, i] = nx; _dims[1, i] = ny; _dims[2, i] = nz; } } else if (_layout_type == layout_1D) { _dims[0, 0] = nx; _dims[1, 0] = ny; _dims[2, 0] = nz; _dims[0, 1] = nx; _dims[1, 1] = ny; _dims[2, 1] = nz; _dims[0, 2] = nz; _dims[1, 2] = nx; _dims[2, 2] = ny; } else if (_layout_type == layout_2D) { _dims[0, 0] = nx; _dims[1, 0] = ny; _dims[2, 0] = nz; _dims[0, 1] = ny; _dims[1, 1] = nx; _dims[2, 1] = nz; _dims[0, 2] = nz; _dims[1, 2] = nx; _dims[2, 2] = ny; } _dims[1, 0] = _dims[1, 0] / _np1; _dims[2, 0] = _dims[2, 0] / _np2; _dims[1, 1] = _dims[1, 1] / _np1; _dims[2, 1] = _dims[2, 1] / _np2; _dims[1, 2] = _dims[1, 2] / _np1; _dims[2, 2] = _dims[2, 2] / _np2; U0.initialize_field("u0", _dims[1, 0], _dims[2, 0], _dims[0, 0], 2); U1.initialize_field("u1", _dims[1, 0], _dims[2, 0], _dims[0, 0], 2); U2.initialize_field("u2", _dims[1, 0], _dims[2, 0], _dims[0, 0], 2); _u = new double[nx, 2]; _twiddle = new double[_ntdivnp]; }