Skip to content

Commit

Permalink
Generalize System.optimize to nonsymmetric problems
Browse files Browse the repository at this point in the history
This patch lifts the restriction that System.optimize only applies to symmetric
problems, as none of the internal logic actually requires it.
  • Loading branch information
gertjanvanzwieten committed Oct 22, 2024
1 parent 76f5529 commit 498d3a8
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions nutils/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,16 +429,15 @@ def optimize(self, *, droptol: Optional[float], arguments: Dict[str, numpy.ndarr
participate in the optimization problem.
'''

log.info(f'optimizing for argument {self._trial_info} with drop tolerance {droptol:.0e}')
log.info(f'{"optimizing" if self.is_symmetric else "solving"} for argument {self._trial_info} with drop tolerance {droptol:.0e}')
if not self.is_linear:
raise ValueError('system is not linear')
if not self.is_symmetric:
raise ValueError('system is not symmetric')
x, iscons, arguments = self.prepare_solution_vector(arguments, constrain)
jac, res, val = self.assemble(arguments)
mycons = iscons | ~jac.rowsupp(droptol)
dx = -jac.solve(res, constrain=mycons, **_copy_with_defaults(linargs, symmetric=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
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
x += dx
for trial, i, j in zip(self.trials, self.__trial_offsets, self.__trial_offsets[1:]):
log.info(f'constrained {(~mycons[i:j]).sum()} degrees of freedom of u')
Expand Down

0 comments on commit 498d3a8

Please sign in to comment.