/// <summary> /// Applies the local solver to the parent solver. /// </summary> /// <returns> /// <c>true</c> if the application was successful; otherwise, <c>false</c>. /// </returns> /// <exception cref="NoEquivalentSubcircuitException">Thrown if no equivalent contributions could be calculated.</exception> public virtual bool Apply() { if (_shouldPreorder) { Solver.Precondition((matrix, vector) => ModifiedNodalAnalysisHelper <T> .PreorderModifiedNodalAnalysis(matrix, Solver.Size - Solver.PivotSearchReduction)); _shouldPreorder = false; } if (_shouldReorder) { if (Solver.OrderAndFactor() < Solver.Size - Solver.Degeneracy) { throw new NoEquivalentSubcircuitException(); } _shouldReorder = false; } else { if (!Solver.Factor()) { _shouldReorder = true; return(false); } } // Copy the necessary elements foreach (var bridge in _elements) { bridge.Global.Add(bridge.Local.Value); } Updated = false; return(true); }
public void When_Spice3f5Reference01_Expect_NoException() { // Load a matrix from Spice 3f5 var solver = ReadSpice3f5File( Path.Combine(TestContext.CurrentContext.TestDirectory, Path.Combine("Algebra", "Matrices", "spice3f5_matrix01.dat")), Path.Combine(TestContext.CurrentContext.TestDirectory, Path.Combine("Algebra", "Matrices", "spice3f5_vector01.dat"))); // Order and factor ModifiedNodalAnalysisHelper <double> .Magnitude = Math.Abs; solver.Precondition((matrix, vector) => ModifiedNodalAnalysisHelper <double> .PreorderModifiedNodalAnalysis(matrix, matrix.Size)); Assert.AreEqual(solver.Size, solver.OrderAndFactor()); IVector <double> solution = new DenseVector <double>(solver.Size); solver.Solve(solution); }