Skip to content

Commit

Permalink
Switch row to column support in solve_constraints
Browse files Browse the repository at this point in the history
This patch removes rowsupp in System.solve_constraints and replaces it with a
local implementation for column support. Aside from preparing for the imminent
deprecation of rowsupp, switching to a column-based support test is more
appropriate now that solve_constraints is no longer limited to symmetric
systems, as the columns relate to the trial dofs that are being constrained.
When in future row constraints will be better supported then the local test can
be extended with a row test for non-symmetric systems.
  • Loading branch information
gertjanvanzwieten committed Oct 22, 2024
1 parent dcdb371 commit 0d4dbad
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion nutils/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,10 @@ def solve_constraints(self, *, droptol: Optional[float], arguments: Dict[str, nu
raise ValueError('system is not linear')

Check warning on line 445 in nutils/solver.py

View workflow job for this annotation

GitHub Actions / Test coverage

Line not covered

Line 445 of `nutils/solver.py` is not covered by tests.
x, iscons, arguments = self.prepare_solution_vector(arguments, constrain)
jac, res, val = self.assemble(arguments)
mycons = iscons | ~jac.rowsupp(droptol)
data, colidx, _ = jac.export('csr')
mycons = numpy.ones_like(iscons)
mycons[colidx[abs(data) > droptol]] = False # unconstrain dofs with nonzero columns
mycons |= iscons
dx = -jac.solve(res, constrain=mycons, **_copy_with_defaults(linargs, symmetric=self.is_symmetric))
if self.is_symmetric:
log.info(f'optimal value: {val+.5*(res@dx):.1e}') # val(x + dx) = val(x) + res(x) dx + .5 dx jac dx
Expand Down

0 comments on commit 0d4dbad

Please sign in to comment.