Skip to content

Commit

Permalink
Don't factor expressions in solve
Browse files Browse the repository at this point in the history
  • Loading branch information
dsharlet committed Dec 3, 2024
1 parent b5f5316 commit 18ec43e
Showing 1 changed file with 0 additions and 7 deletions.
7 changes: 0 additions & 7 deletions Circuit/Simulation/TransientSolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ public static TransientSolution Solve(Analysis Analysis, Expression TimeStep, IE
IEnumerable<Arrow> linear = F.Solve();
if (linear.Any())
{
linear = Factor(linear);
solutions.Add(new LinearSolutions(linear));
LogExpressions(Log, MessageType.Verbose, "Linear solutions:", linear);
}
Expand All @@ -177,15 +176,12 @@ public static TransientSolution Solve(Analysis Analysis, Expression TimeStep, IE
// Find linear solutions for dy.
nonlinear.RowReduce(ly);
IEnumerable<Arrow> solved = nonlinear.Solve(ly);
solved = Factor(solved);

// Initial guess for y[t] = y[t - h].
IEnumerable<Arrow> guess = F.Unknowns.Select(i => Arrow.New(i, i.Substitute(t, t - h))).ToList();
guess = Factor(guess);

// Newton system equations.
IEnumerable<LinearCombination> equations = nonlinear.Equations.Buffer();
equations = Factor(equations);

solutions.Add(new NewtonIteration(solved, equations, nonlinear.Unknowns, guess));
LogExpressions(Log, MessageType.Verbose, String.Format("Non-linear Newton's method updates ({0}):", String.Join(", ", nonlinear.Unknowns)), equations.Select(i => Equal.New(i, 0)));
Expand All @@ -205,9 +201,6 @@ public static TransientSolution Solve(Analysis Analysis, Expression TimeStep, IE
public static TransientSolution Solve(Analysis Analysis, Expression TimeStep, ILog Log) { return Solve(Analysis, TimeStep, new Arrow[] { }, Log); }
public static TransientSolution Solve(Analysis Analysis, Expression TimeStep) { return Solve(Analysis, TimeStep, new Arrow[] { }, new NullLog()); }

private static IEnumerable<Arrow> Factor(IEnumerable<Arrow> x) { return x.Select(i => Arrow.New(i.Left, i.Right.Factor())).Buffer(); }
private static IEnumerable<LinearCombination> Factor(IEnumerable<LinearCombination> x) { return x.Select(i => LinearCombination.New(i.Select(j => new KeyValuePair<Expression, Expression>(j.Key, j.Value.Factor())))).Buffer(); }

// Shorthand for df/dx.
protected static Expression D(Expression f, Expression x) { return Call.D(f, x); }

Expand Down

0 comments on commit 18ec43e

Please sign in to comment.