@@ -19,45 +19,43 @@ class FDConstraintSolver(Solver):
1919 def __init__ (self ,
2020 numdata : FDNumericalData ,
2121 constraints : Sequence [Constraint ] = None ,
22- max_iter : int = 100 ,
23- tol_dxyz : float = 1E-3 ,
22+ kmax : int = 100 ,
2423 tol_res : float = 1E-3 ,
24+ tol_disp : float = 1E-3 ,
2525 ** kwargs
2626 ) -> None :
27- super (FDConstraintSolver , self ).__init__ (numdata , max_iter , ** kwargs )
27+ super (FDConstraintSolver , self ).__init__ (numdata , kmax , ** kwargs )
2828 self .constraints = constraints
29- self .tol_dxyz = tol_dxyz
3029 self .tol_res = tol_res
30+ self .tol_disp = tol_disp
3131
3232 def solve (self ) -> None :
3333 """Apply force density algorithm for a single iteration."""
34- free , fixed , xyz , C , q , Q , p , A , Ai , Af , * _ = self .numdata
35- b = p [free ] - Af .dot (xyz [fixed ])
36- xyz [free ] = spsolve (Ai , b )
37- self .numdata .residuals = p - A .dot (xyz )
38- self .numdata .xyz_prev = xyz .copy ()
39- self .numdata .xyz = xyz
34+ nd = self .numdata
35+ b = nd .p [nd .free ] - nd .Af .dot (nd .xyz [nd .fixed ])
36+ nd .xyz [nd .free ] = spsolve (nd .Ai , b )
37+ nd .residuals = nd .p - nd .A .dot (nd .xyz )
38+ nd .xyz_prev = nd .xyz .copy ()
4039 self ._update_constraints ()
4140
4241 def _update_constraints (self ):
4342 """Update all vertex constraints by the residuals of the current iteration,
4443 and store their updated vertex coordinates in the numdata attribute.
4544 """
46- xyz = self .numdata .xyz
47- residuals = self .numdata .residuals
45+ nd = self .numdata
4846 for vertex , constraint in enumerate (self .constraints ):
4947 if not constraint :
5048 continue
51- constraint .location = xyz [vertex ]
52- constraint .residual = residuals [vertex ]
53- xyz [vertex ] = constraint .location + constraint .tangent * 0.5
54- self .numdata .tangent_residuals = asarray ([c .tangent for c in self .constraints if c ])
55- self .numdata .xyz = xyz
49+ constraint .location = nd .xyz [vertex ]
50+ constraint .residual = nd .residuals [vertex ]
51+ nd .xyz [vertex ] = constraint .location + constraint .tangent * 0.5
52+ nd .tangent_residuals = asarray ([c .tangent for c in self .constraints if c ])
5653
5754 @property
5855 def is_converged (self ) -> bool :
5956 """Verify if all convergence criteria are met."""
60- return self ._is_converged_residuals and self ._is_converged_xyz
57+ return (self ._is_converged_residuals and
58+ self ._is_converged_displacements )
6159
6260 @property
6361 def _is_converged_residuals (self ) -> bool :
@@ -69,18 +67,16 @@ def _is_converged_residuals(self) -> bool:
6967 return max_res < self .tol_res
7068
7169 @property
72- def _is_converged_xyz (self ) -> bool :
70+ def _is_converged_displacements (self ) -> bool :
7371 """Verify whether the maximum coordinate displacement
7472 between consecutive iterations is within tolerance.
7573 """
76- new_xyz = self .numdata .xyz
77- old_xyz = self .numdata .xyz_prev
78- max_dxyz = max (norm (new_xyz - old_xyz , axis = 1 ))
79- return max_dxyz < self .tol_dxyz
74+ nd = self .numdata
75+ max_dxyz = max (norm (nd .xyz - nd .xyz_prev , axis = 1 ))
76+ return max_dxyz < self .tol_disp
8077
8178 def post_process (self ) -> None :
8279 """Compute dependent variables after ending the solver loop."""
83- _ , _ , xyz , C , q , * _ = self .numdata
84- lengths = normrow (C .dot (xyz ))
85- self .numdata .forces = q * lengths
86- self .numdata .lengths = lengths
80+ nd = self .numdata
81+ nd .lengths = normrow (nd .C .dot (nd .xyz ))
82+ nd .forces = nd .q * nd .lengths
0 commit comments