Skip to content

Commit

Permalink
Rename System.optimize to solve_constraints
Browse files Browse the repository at this point in the history
This patch renames System.optimize to solve_constraints to reflect that the
method is not limited to symmetric problems, and that its sole purpose is the
establishment of Dirichlet constraints.
  • Loading branch information
gertjanvanzwieten committed Oct 22, 2024
1 parent 498d3a8 commit aed09e4
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions examples/adaptivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ def main(etype: str = 'square',
ns.du = 'u - uexact'

sqr = domain.boundary['corner'].integral('u^2 dS' @ ns, degree=degree*2)
cons = System(sqr, trial='u').optimize(droptol=1e-15)
cons = System(sqr, trial='u').solve_constraints(droptol=1e-15)

sqr = domain.boundary.integral('du^2 dS' @ ns, degree=7)
cons = System(sqr, trial='u').optimize(droptol=1e-15, constrain=cons)
cons = System(sqr, trial='u').solve_constraints(droptol=1e-15, constrain=cons)

res = domain.integral('∇_k(v) ∇_k(u) dV' @ ns, degree=degree*2)
args = System(res, trial='u', test='v').solve(constrain=cons)
Expand Down
2 changes: 1 addition & 1 deletion examples/cylinderflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def main(nelems: int = 99,
ns.uwall_i = 'rotation ε_ij x_j' # clockwise positive rotation

sqr = domain.boundary['inflow'].integral('Σ_i (u_i - uinf_i)^2 dS' @ ns, degree=degree*2)
cons = System(sqr, trial='u').optimize(droptol=1e-15) # constrain inflow boundary to unit horizontal flow
cons = System(sqr, trial='u').solve_constraints(droptol=1e-15) # constrain inflow boundary to unit horizontal flow

sqr = domain.integral('(.5 Σ_i (u_i - uinf_i)^2 - ∇_k(u_k) p) dV' @ ns, degree=degree*2)
args = System(sqr, trial='u,p').solve(constrain=cons) # set initial condition to potential flow
Expand Down
4 changes: 2 additions & 2 deletions examples/drivencavity.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ def main(nelems: int = 32,

# strong enforcement of non-penetrating boundary conditions
sqr = domain.boundary.integral('(u_k n_k)^2 dS' @ ns, degree=degree*2)
cons = System(sqr, trial='u').optimize(droptol=1e-15)
cons = System(sqr, trial='u').solve_constraints(droptol=1e-15)

if strongbc:
# strong enforcement of tangential boundary conditions
sqr = domain.boundary.integral('(ε_ij n_i (u_j - uwall_j))^2 dS' @ ns, degree=degree*2)
tcons = System(sqr, trial='u').optimize(droptol=1e-15)
tcons = System(sqr, trial='u').solve_constraints(droptol=1e-15)
cons['u'] = numpy.choose(numpy.isnan(cons['u']), [cons['u'], tcons['u']])
else:
# weak enforcement of tangential boundary conditions via Nitsche's method
Expand Down
2 changes: 1 addition & 1 deletion examples/elasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def main(nelems: int = 24,
ns.q_i = '-δ_i1'

sqr = domain.boundary['top'].integral('u_k u_k dS' @ ns, degree=degree*2)
cons = System(sqr, trial='u').optimize(droptol=1e-15)
cons = System(sqr, trial='u').solve_constraints(droptol=1e-15)

# solve for equilibrium configuration
energy = domain.integral('(E - u_i q_i) dV' @ ns, degree=degree*2)
Expand Down
2 changes: 1 addition & 1 deletion examples/finitestrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def main(nelems: int = 20,

sqr = domain.boundary['left'].integral('u_k u_k dS' @ ns, degree=degree*2)
sqr += domain.boundary['right'].integral('((u_0 - X_1 sin(2 angle) - cos(angle) + 1)^2 + (u_1 - X_1 (cos(2 angle) - 1) + sin(angle))^2) dS' @ ns, degree=degree*2)
cons = System(sqr, trial='u').optimize(droptol=1e-15)
cons = System(sqr, trial='u').solve_constraints(droptol=1e-15)

energy = domain.integral('energy dV' @ ns, degree=degree*2)
args0 = System(energy, trial='u').solve(constrain=cons)
Expand Down
2 changes: 1 addition & 1 deletion examples/laplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def main(nelems: int = 10,

sqr = domain.boundary['left'].integral('u^2 dS' @ ns, degree=degree*2)
sqr += domain.boundary['top'].integral('(u - cosh(1) sin(x_0))^2 dS' @ ns, degree=degree*2)
cons = System(sqr, trial='u').optimize(droptol=1e-15)
cons = System(sqr, trial='u').solve_constraints(droptol=1e-15)

# The unconstrained entries of `u` are to be such that the residual
# evaluates to zero for all possible values of `v`. The resulting array `u`
Expand Down
4 changes: 2 additions & 2 deletions examples/platewithhole.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ def main(mode: Union[FCM, NURBS] = NURBS(),
log.info('hole radius exact up to L2 error {:.2e}'.format(radiuserr))

sqr = topo.boundary['sym'].integral('(u_i n_i)^2 dS' @ ns, degree=degree*2)
cons = System(sqr, trial='u').optimize(droptol=1e-15)
cons = System(sqr, trial='u').solve_constraints(droptol=1e-15)

sqr = topo.boundary['far'].integral('du_k du_k dS' @ ns, degree=20)
cons = System(sqr, trial='u').optimize(droptol=1e-15, constrain=cons)
cons = System(sqr, trial='u').solve_constraints(droptol=1e-15, constrain=cons)

res = topo.integral('∇_j(v_i) σ_ij dV' @ ns, degree=degree*2)
args = System(res, trial='u', test='v').solve(constrain=cons)
Expand Down
2 changes: 1 addition & 1 deletion examples/poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def main(nelems: int = 32):
J = function.J(x)

sqr = topo.boundary.integral(u**2 * J, degree=2)
cons = System(sqr, trial='u').optimize(droptol=1e-12)
cons = System(sqr, trial='u').solve_constraints(droptol=1e-12)

energy = topo.integral((g @ g / 2 - u) * J, degree=1)
args = System(energy, trial='u').solve(constrain=cons)
Expand Down
6 changes: 3 additions & 3 deletions nutils/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ def step(self, *, timestep: float, timetarget: str, historysuffix: str, argument

@cache.function
@log.withcontext
def optimize(self, *, droptol: Optional[float], arguments: Dict[str, numpy.ndarray] = {}, constrain: Dict[str, numpy.ndarray] = {}, linargs: Dict[str, Any] = {}) -> Tuple[Dict[str, numpy.ndarray], float]:
'''Optimize singular system.
def solve_constraints(self, *, droptol: Optional[float], arguments: Dict[str, numpy.ndarray] = {}, constrain: Dict[str, numpy.ndarray] = {}, linargs: Dict[str, Any] = {}) -> Tuple[Dict[str, numpy.ndarray], float]:
'''Solve singular system.
This method is similar to ``solve``, but specific to symmetric linear
systems, with the added ability to solve a limited class of singular
Expand Down Expand Up @@ -905,7 +905,7 @@ def optimize(target, functional: evaluable.asarray, *, tol: float = 0., argument
raise TypeError('unexpected keyword arguments: {}'.format(', '.join(kwargs)))
system = System(functional, *_split_trial_test(target))
if droptol is not None:
return system.optimize(arguments=arguments, constrain=constrain or {}, linargs=linargs, droptol=droptol)
return system.solve_constraints(arguments=arguments, constrain=constrain or {}, linargs=linargs, droptol=droptol)
method = None if system.is_linear else Newton() if linesearch is None else LinesearchNewton(strategy=linesearch, relax0=relax0, failrelax=failrelax)
return system.solve(arguments=arguments, constrain=constrain or {}, linargs=linargs, method=method, tol=tol)

Expand Down

0 comments on commit aed09e4

Please sign in to comment.