From aed09e4ee9c177f6287ca405a2d4a6ddc97e047e Mon Sep 17 00:00:00 2001 From: Gertjan van Zwieten Date: Tue, 22 Oct 2024 10:21:32 +0200 Subject: [PATCH] Rename System.optimize to solve_constraints 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. --- examples/adaptivity.py | 4 ++-- examples/cylinderflow.py | 2 +- examples/drivencavity.py | 4 ++-- examples/elasticity.py | 2 +- examples/finitestrain.py | 2 +- examples/laplace.py | 2 +- examples/platewithhole.py | 4 ++-- examples/poisson.py | 2 +- nutils/solver.py | 6 +++--- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/adaptivity.py b/examples/adaptivity.py index 9716cfee2..71d468e1c 100644 --- a/examples/adaptivity.py +++ b/examples/adaptivity.py @@ -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) diff --git a/examples/cylinderflow.py b/examples/cylinderflow.py index 0821a9e7d..7e6ec1b01 100644 --- a/examples/cylinderflow.py +++ b/examples/cylinderflow.py @@ -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 diff --git a/examples/drivencavity.py b/examples/drivencavity.py index 0009bbf22..c110924af 100644 --- a/examples/drivencavity.py +++ b/examples/drivencavity.py @@ -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 diff --git a/examples/elasticity.py b/examples/elasticity.py index 0091e42e9..7cc82879a 100644 --- a/examples/elasticity.py +++ b/examples/elasticity.py @@ -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) diff --git a/examples/finitestrain.py b/examples/finitestrain.py index 7cf4de8f0..058d5bd6b 100644 --- a/examples/finitestrain.py +++ b/examples/finitestrain.py @@ -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) diff --git a/examples/laplace.py b/examples/laplace.py index d9d75284f..0c52ddfbc 100644 --- a/examples/laplace.py +++ b/examples/laplace.py @@ -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` diff --git a/examples/platewithhole.py b/examples/platewithhole.py index 088b61ef2..5f8845858 100644 --- a/examples/platewithhole.py +++ b/examples/platewithhole.py @@ -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) diff --git a/examples/poisson.py b/examples/poisson.py index c88c8d188..10081a1d0 100644 --- a/examples/poisson.py +++ b/examples/poisson.py @@ -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) diff --git a/nutils/solver.py b/nutils/solver.py index d3b915078..d66c3094e 100644 --- a/nutils/solver.py +++ b/nutils/solver.py @@ -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 @@ -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)