From 17bf399edfe7d6661fd77202bf17600b60c1b512 Mon Sep 17 00:00:00 2001 From: Fraser-Birks Date: Wed, 25 Oct 2023 17:02:14 +0100 Subject: [PATCH] ENH: Added feature to allow alpha backtracking --- matscipy/fracture_mechanics/crack.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/matscipy/fracture_mechanics/crack.py b/matscipy/fracture_mechanics/crack.py index 07829ae6..1ead5a7a 100644 --- a/matscipy/fracture_mechanics/crack.py +++ b/matscipy/fracture_mechanics/crack.py @@ -1492,7 +1492,8 @@ def arc_length_continuation(self, x0, x1, N=10, ds=0.01, ftol=1e-2, opt_method='krylov', cos_alpha_min=0.9,parallel=False, pipe_output=None,data_queue=None, - kill_confirm_queue=None): + kill_confirm_queue=None, + allow_alpha_backtracking=False): import h5py assert self.variable_k # only makes sense if K can vary @@ -1503,6 +1504,9 @@ def arc_length_continuation(self, x0, x1, N=10, ds=0.01, ftol=1e-2, # ensure we start moving in the correct direction if self.variable_alpha: _, alphadot1, _ = self.unpack(xdot1) + #print(np.sign(alphadot1)) + #print(direction) + #print(direction*np.sign(alphadot1)) if direction * np.sign(alphadot1) < 0: xdot1 = -xdot1 row = 0 @@ -1549,13 +1553,13 @@ def arc_length_continuation(self, x0, x1, N=10, ds=0.01, ftol=1e-2, x2 = self.get_dofs() xdot2 = self.get_xdot(x1, x2, ds) - - if self.variable_alpha: - # monitor sign of \dot{alpha} and flip if necessary - #udot1, alphadot1, kdot1 = self.unpack(xdot1) - udot2, alphadot2, kdot2 = self.unpack(xdot2) - if direction * np.sign(alphadot2) < 0: - xdot2 = -xdot2 + if not allow_alpha_backtracking: + if self.variable_alpha: + # monitor sign of \dot{alpha} and flip if necessary + #udot1, alphadot1, kdot1 = self.unpack(xdot1) + udot2, alphadot2, kdot2 = self.unpack(xdot2) + if direction * np.sign(alphadot2) < 0: + xdot2 = -xdot2 # cos_alpha = np.dot(xdot1, xdot2) / np.linalg.norm(xdot1) / np.linalg.norm(xdot2) # print(f'cos_alpha = {cos_alpha}') @@ -1604,10 +1608,9 @@ def arc_length_continuation(self, x0, x1, N=10, ds=0.01, ftol=1e-2, if pipe_output.poll(): kill = pipe_output.recv() print(f'KILLING PROCESS,{os.getpid()}') - if kill == 1: - #kill the process - i = N - kill_confirm_queue.put(os.getpid()) + #kill the process + kill_confirm_queue.put(os.getpid()) + break else: #put data on queue data_queue.put([os.getpid(),x2,direction],block=False)