public void MultiplyWithMatrix(IVector <double> vIn, IVector <double> vOut) { matrixCalculator.MultiplyWithMatrix(vIn, vOut); //foreach (ISolverSubdomain subdomain in subdomainsDictionary.Values) //{ // SkylineMatrix2D<double> k = ((SkylineMatrix2D<double>)subdomain.Matrix); // k.Multiply(vIn, ((Vector<double>)vOut).Data); //} }
public void Solve(int maxIterations, double tolerance) { int iLagr = x.Length; iterations = 0; //matrixCalculator.Projectr(r, w); //matrixCalculator.Precondition(w, z); //matrixCalculator.Projectz(z, y); if (r.Norm > 1e-25) { matrixCalculator.Precondition(r, z); errors.Clear(); for (currentIteration = 0; currentIteration < maxIterations; currentIteration++) { search.CalculateSearchVector(this); matrixCalculator.MultiplyWithMatrix(p, q); double a = search.CalculateGradient(this); double detz = 0; //Parallel.For(0, iLagr, i => for (int i = 0; i < iLagr; i++) { r[i] -= a * q[i]; x[i] += a * p[i]; detz += r[i] * r[i]; } ; errors.Add(Math.Sqrt(detz) / detf); if (errors[currentIteration] < tolerance) { break; } //matrixCalculator.Projectr(r, w); //matrixCalculator.Precondition(w, z); //matrixCalculator.Projectz(z, y); matrixCalculator.Precondition(r, z); } iterations = currentIteration; } //StreamWriter sw = File.CreateText(@"iterationsPCG.txt"); //for (int i = 0; i < errors.Count; i++) // sw.WriteLine(errors[i].ToString()); //sw.Close(); StreamWriter sw = File.AppendText(String.Format(@"iterationsPCG-{0}.txt", Process.GetCurrentProcess().Id)); sw.WriteLine(iterations.ToString()); sw.Close(); }