/// <summary>
        /// See <see cref="IPcgBetaParameterCalculation.CalculateBeta(PcgAlgorithmBase)"/>.
        /// </summary>
        public double CalculateBeta(PcgAlgorithmBase pcg)
        {
            double nominator = pcg.ResDotPrecondRes - pcg.PrecondResidual.DotProduct(residualOld);

            residualOld.CopyFrom(pcg.Residual);
            return((nominator > 0.0) ? nominator / pcg.ResDotPrecondResOld : 0.0);
        }
Exemple #2
0
 private void UpdateDirectionVector(IVectorView preconditionedResidual, IVector direction)
 {
     // d = s - sum(β_i * d_i), 0 <= i < currentIteration
     // β_i = (s * q_i) / (d_i * q_i)
     direction.CopyFrom(preconditionedResidual);
     for (int i = 0; i < reorthoCache.Directions.Count; ++i)
     {
         double beta = preconditionedResidual.DotProduct(reorthoCache.MatrixTimesDirections[i])
                       / reorthoCache.DirectionsTimesMatrixTimesDirections[i];
         direction.AxpyIntoThis(reorthoCache.Directions[i], -beta);
     }
 }
        internal static void CsrTransTimesVector(int numCsrRows, double[] csrValues, int[] csrRowOffsets, int[] csrColIndices,
                                                 IVectorView lhs, IVector rhs)
        {
            var temp = new double[rhs.Length];

            CsrTransTimesVector(numCsrRows, csrValues, csrRowOffsets, csrColIndices, lhs, temp);
            rhs.CopyFrom(Vector.CreateFromArray(temp));

            // The following requires a lot of indexing into the rhs vector.
            //// A^T * x = linear combination of columns of A^T = rows of A, with the entries of x as coefficients
            //for (int i = 0; i < numCsrRows; ++i)
            //{
            //    double scalar = lhs[i];
            //    int rowStart = csrRowOffsets[i]; //inclusive
            //    int rowEnd = csrRowOffsets[i + 1]; //exclusive
            //    for (int k = rowStart; k < rowEnd; ++k)
            //    {
            //        rhs.Set(csrColIndices[k], rhs[csrColIndices[k]] + scalar * csrValues[k]);
            //    }
            //}
        }
Exemple #4
0
 /// <summary>
 /// See <see cref="IPreconditioner.SolveLinearSystem(Vector)"/>.
 /// </summary>
 /// <remarks>
 /// This method works for all dimensions of the preconditioner matrix and the right hand side vector. This way the user
 /// doesn't have to define the dimensions of the linear system, which is useful when testing or benchmarking, at the
 /// expense of little extra safety.
 /// </remarks>
 public void SolveLinearSystem(IVectorView rhsVector, IVector lhsVector) => lhsVector.CopyFrom(rhsVector);
Exemple #5
0
 public void ExtractVectorSubdomainFromGlobal(ISubdomain subdomain, IVectorView globalVector, IVector subdomainVector)
 {
     Debug.Assert(subdomain == this.subdomain);
     subdomainVector.CopyFrom(globalVector);
 }