/// <summary> /// computes the residual on this level. /// </summary> public void Residual <V1, V2, V3>(V1 rl, V2 xl, V3 bl) where V1 : IList <double> where V2 : IList <double> where V3 : IList <double> { OpMatrix.SpMV(-1.0, xl, 0.0, rl); rl.AccV(1.0, bl); }
/// <summary> /// Tests if a matrix (associated with some operator) depends only on values in this sub-grid, /// or not. /// </summary> /// <param name="_Mtx">some operator matrix</param> /// <param name="RowMap">row-/co-domain mapping for matrix <paramref name="_Mtx"/></param> /// <param name="ColMap">column/domain mapping for matrix <paramref name="_Mtx"/></param> /// <param name="NoOfTests"></param> /// <returns> /// 0.0 if there is no dependency of the matrix <paramref name="_Mtx"/> /// on values outside of this subgrid. /// </returns> public double TestMatrixDependency(MsrMatrix _Mtx, UnsetteledCoordinateMapping RowMap, UnsetteledCoordinateMapping ColMap, int NoOfTests = 10) { Random RND = new Random(); if (!_Mtx.RowPartitioning.Equals(RowMap)) { throw new ArgumentException(); } if (!_Mtx.ColPartition.Equals(ColMap)) { throw new ArgumentException(); } var Mtx = new ilPSP.LinSolvers.monkey.CPU.RefMatrix(_Mtx); int[] IR = RowMap.BasisS.Count.ForLoop(i => i); int[] IC = ColMap.BasisS.Count.ForLoop(i => i); var SgrdRow = RowMap.GetSubvectorIndices(this, true, IR); var SgrdCol = SgrdRow; // ColMap.GetSubvectorIndices(this, true, true, IC); double[] X0 = new double[ColMap.LocalLength]; double[] Y0 = new double[RowMap.LocalLength]; for (int i = 0; i < X0.Length; i++) { X0[i] = RND.NextDouble(); } Mtx.SpMV(1.0, X0, 0.0, Y0); int i0Row = RowMap.i0; int i0Col = ColMap.i0; int iECol = ColMap.iE; double err = 0; for (int iTest = 0; iTest < NoOfTests; iTest++) { double[] X1 = new double[ColMap.LocalLength]; double[] Y1 = new double[RowMap.LocalLength]; for (int i = 0; i < X0.Length; i++) { X1[i] = RND.NextDouble(); } foreach (int i in SgrdCol) { if (i >= i0Col && i < iECol) { X1[i - i0Col] = X0[i - i0Col]; } } Mtx.SpMV(1.0, X1, 0.0, Y1); foreach (int k in SgrdRow) { double Y1k = Y1[k - i0Row]; double Y0k = Y0[k - i0Row]; //Debug.Assert((Y0k - Y1k).Pow2() < 1.0e-8); err += (Y0k - Y1k).Pow2(); } } return(err.MPISum()); }