/// <summary> /// extract the Fields from the solution, Resample them equally spaced and ready to use in an fft /// </summary> private void Resample(int iterIndex, double[] currentSol, MultigridOperator Mgop, string component) { if (Mgop.GridData.SpatialDimension == 2 && Mgop.LevelIndex == 0) { MultidimensionalArray SamplePoints; GridData GD = (GridData)Mgop.Mapping.AggGrid.AncestorGrid; BoundingBox BB = GD.GlobalBoundingBox; double xDist = BB.Max[0] - BB.Min[0]; double yDist = BB.Max[1] - BB.Min[1]; double aspectRatio = xDist / yDist; MGViz viz = new MGViz(Mgop); DGField[] Fields = viz.ProlongateToDg(currentSol, "Error"); for (int p = 0; p < Fields.Length; p++) { var field = Fields[p]; int DOF = field.DOFLocal; double N = Math.Sqrt(DOF); int Nx = (int)Math.Round(Math.Sqrt(aspectRatio) * N); int Ny = (int)Math.Round(1 / Math.Sqrt(aspectRatio) * N); SamplePoints = MultidimensionalArray.Create(Ny, Nx); for (int i = 0; i < Nx; i++) { MultidimensionalArray points = MultidimensionalArray.Create(Ny, 2); for (int k = 0; k < Ny; k++) { points[k, 0] = BB.Min[0] + (i + 1) * xDist / (Nx + 1); points[k, 1] = BB.Min[1] + (k + 1) * yDist / (Ny + 1); } List <DGField> fields = new List <DGField>(); fields.Add(field); FieldEvaluation FE = new FieldEvaluation(GD); MultidimensionalArray Result = MultidimensionalArray.Create(Ny, 1); FE.Evaluate(1.0, fields, points, 1.0, Result); SamplePoints.ExtractSubArrayShallow(-1, i).Acc(1.0, Result.ExtractSubArrayShallow(-1, 0)); } SamplePoints.SaveToTextFile("ResampleFFT_lvl" + Mgop.LevelIndex + "_" + iterIndex + "_" + component + "_" + field.Identification + ".txt"); } } }
/// <summary> /// defines the problem matrix /// </summary> public void Init(MultigridOperator op) { this.m_MgOperator = op; var Mtx = op.OperatorMatrix; var MgMap = op.Mapping; viz = new MGViz(op); if (!Mtx.RowPartitioning.EqualsPartition(MgMap.Partitioning)) { throw new ArgumentException("Row partitioning mismatch."); } if (!Mtx.ColPartition.EqualsPartition(MgMap.Partitioning)) { throw new ArgumentException("Column partitioning mismatch."); } MxxHistory.Clear(); SolHistory.Clear(); double Dim = MgMap.ProblemMapping.GridDat.SpatialDimension; // set operator // ============ if (op.CoarserLevel == null) { throw new NotSupportedException("Multigrid algorithm cannot be used as a solver on the finest level."); } this.OpMatrix = Mtx; // initiate coarser level // ====================== if (this.CoarserLevelSolver == null) { throw new NotSupportedException("Missing coarse level solver."); } this.CoarserLevelSolver.Init(op.CoarserLevel); // init smoother // ============= if (PreSmoother != null) { PreSmoother.Init(op); } if (PostSmoother != null && !object.ReferenceEquals(PreSmoother, PostSmoother)) { PostSmoother.Init(op); } }