/// <summary> /// Updating the <see cref="CurrentLin"/> -- operator; /// </summary> /// <param name="CurrentState">input, linearization point</param> /// <param name="U0">output, linearization point, after external update, transorfmed back</param> protected void Update(IEnumerable <DGField> CurrentState, ref double[] U0) { /* * DGField[] U0fields = this.ProblemMapping.BasisS.Select( * delegate(Basis b) { * DGField ret; * if (b is XDGBasis) { * XDGField xf = new XDGField(b as XDGBasis); * xf.UpdateBehaviour = BehaveUnder_LevSetMoovement.AutoExtrapolate; * ret = xf; * } else { * ret = new SinglePhaseField(b); * } * return ret; * }).ToArray(); * * CoordinateVector u0Raw = new CoordinateVector(U0fields); * * CurrentLin.TransformSolFrom(u0Raw, U0); */ this.UpdateLinearization(CurrentState); CoordinateVector u0Raw = new CoordinateVector(CurrentState.ToArray()); int Ltrf = this.CurrentLin.Mapping.LocalLength; if (U0.Length != Ltrf) { U0 = new double[Ltrf]; } CurrentLin.TransformSolInto(u0Raw, U0); }
/// <summary> /// Updating the <see cref="CurrentLin"/> -- operator; /// </summary> /// <param name="CurrentState">input, linearization point</param> /// <param name="U0">output, linearization point, after external update, transformed back</param> /// <param name="HomotopyValue"> /// <see cref="ISpatialOperator.CurrentHomotopyValue"/> /// </param> protected void Update(IEnumerable <DGField> CurrentState, double[] U0, double HomotopyValue) { /* * DGField[] U0fields = this.ProblemMapping.BasisS.Select( * delegate(Basis b) { * DGField ret; * if (b is XDGBasis) { * XDGField xf = new XDGField(b as XDGBasis); * xf.UpdateBehaviour = BehaveUnder_LevSetMoovement.AutoExtrapolate; * ret = xf; * } else { * ret = new SinglePhaseField(b); * } * return ret; * }).ToArray(); * * CoordinateVector u0Raw = new CoordinateVector(U0fields); * * CurrentLin.TransformSolFrom(u0Raw, U0); */ this.UpdateLinearization(CurrentState, HomotopyValue); CurrentLin.TransformSolInto(new CoordinateVector(CurrentState), U0); }
/// <summary> /// Callback routine, see <see cref="ISolverWithCallback.IterationCallback"/> or <see cref="NonlinearSolver.IterationCallback"/>. /// </summary> public void IterationCallback(int iter, double[] xI, double[] rI, MultigridOperator mgOp) { if (xI.Length != SolverOperator.Mapping.LocalLength) { throw new ArgumentException(); } if (rI.Length != SolverOperator.Mapping.LocalLength) { throw new ArgumentException(); } int Lorg = SolverOperator.BaseGridProblemMapping.LocalLength; // transform residual and solution back onto the orignal grid // ========================================================== double[] Res_Org = new double[Lorg]; double[] Sol_Org = new double[Lorg]; SolverOperator.TransformRhsFrom(Res_Org, rI); SolverOperator.TransformSolFrom(Sol_Org, xI); double[] Err_Org = Sol_Org.CloneAs(); Err_Org.AccV(-1.0, this.ExactSolution); if (TecplotOut != null) { var ErrVec = InitProblemDGFields("Err"); var ResVec = InitProblemDGFields("Res"); var SolVec = InitProblemDGFields("Sol"); ErrVec.SetV(Err_Org); ResVec.SetV(Res_Org); SolVec.SetV(Sol_Org); List <DGField> ErrResSol = new List <DGField>(); ErrResSol.AddRange(ErrVec.Mapping.Fields); ErrResSol.AddRange(ResVec.Mapping.Fields); ErrResSol.AddRange(SolVec.Mapping.Fields); Tecplot.Tecplot.PlotFields(ErrResSol, TecplotOut + "." + iter, iter, 4); PlotDecomposition(xI, TecplotOut + "-sol-decomp." + iter); PlotDecomposition(rI, TecplotOut + "-res-decomp." + iter); } // Console out // =========== double l2_RES = rI.L2NormPow2().MPISum().Sqrt(); double l2_ERR = Err_Org.L2NormPow2().MPISum().Sqrt(); Console.WriteLine("Iter: {0}\tRes: {1:0.##E-00}\tErr: {2:0.##E-00}", iter, l2_RES, l2_ERR); // decompose error and residual into orthonormal vectors // ===================================================== int L0 = DecompositionOperator.Mapping.LocalLength; double[] Err_0 = new double[L0], Res_0 = new double[L0]; DecompositionOperator.TransformSolInto(Err_Org, Err_0); DecompositionOperator.TransformRhsInto(Res_Org, Res_0); IList <double[]> Err_OrthoLevels = OrthonormalMultigridDecomposition(Err_0); IList <double[]> Res_OrthoLevels = OrthonormalMultigridDecomposition(Res_0); // compute L2 norms on each level // ============================== for (var mgop = this.DecompositionOperator; mgop != null; mgop = mgop.CoarserLevel) { int[] _Degrees = mgop.Mapping.DgDegree; double[] Resi = Res_OrthoLevels[mgop.LevelIndex]; double[] Errr = Err_OrthoLevels[mgop.LevelIndex]; int JAGG = mgop.Mapping.AggGrid.iLogicalCells.NoOfLocalUpdatedCells; for (int iVar = 0; iVar < _Degrees.Length; iVar++) { for (int p = 0; p <= _Degrees[iVar]; p++) { List <double> ResNorm = this.ResNormTrend[new Tuple <int, int, int>(mgop.LevelIndex, iVar, p)]; List <double> ErrNorm = this.ErrNormTrend[new Tuple <int, int, int>(mgop.LevelIndex, iVar, p)]; double ResNormAcc = 0.0; double ErrNormAcc = 0.0; for (int jagg = 0; jagg < JAGG; jagg++) { int[] NN = mgop.Mapping.AggBasis[iVar].ModeIndexForDegree(jagg, p, _Degrees[iVar]); foreach (int n in NN) { int idx = mgop.Mapping.LocalUniqueIndex(iVar, jagg, n); ResNormAcc += Resi[idx].Pow2(); ErrNormAcc += Errr[idx].Pow2(); } } ResNorm.Add(ResNormAcc.Sqrt()); ErrNorm.Add(ErrNormAcc.Sqrt()); } } } }