Skip to content

Commit 88c72bf

Browse files
Minor changes
1 parent 1788c81 commit 88c72bf

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

Diff for: fidimag/common/chain_method_integrators.py

+55-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,12 @@ class FSIntegrator(BaseIntegrator):
150150
"""A step integrator considering the action of the band
151151
"""
152152
def __init__(self, band, forces, action, rhs_fun, n_images, n_dofs_image,
153-
max_steps=1000):
153+
max_steps=1000,
154+
maxCreep=5, eta_scale=1.0, stopping_dE=1e-6, dEta=2,
155+
etaMin=0.001,
156+
# perturbSeed=42, perturbFactor=0.1,
157+
nTrail=10, resetMax=20, mXgradE_tol=0.1
158+
):
154159
super(FSIntegrator, self).__init__(band, rhs_fun)
155160

156161
self.i_step = 0
@@ -161,10 +166,59 @@ def __init__(self, band, forces, action, rhs_fun, n_images, n_dofs_image,
161166
self.forces = forces
162167
self.max_steps = max_steps
163168

169+
self.y_last = np.zeros_like(self.y) # y -> band
170+
self.step = 0
171+
self.nTrail = nTrail
172+
164173
def run_until(self, t):
165174
pass
166175

167176
def run_for(self, n_steps):
177+
178+
nStart = 0
179+
exitFlag = False
180+
totalRestart = True
181+
resetCount = 0
182+
creepCount = 0
183+
self.trailE = np.zeros(nTrail)
184+
trailPool = cycle(range(nTrail)) # cycle through 0,1,...,(nTrail-1),0,1,...
185+
eta = 1.0
186+
187+
while not exitFlag:
188+
189+
if totalRestart:
190+
if self.step > 0:
191+
print('Restarting')
192+
self.y[:] = self.y_last
193+
194+
# Compute from self.band. Do not update the step at this stage:
195+
# This step updates the forces in the G array of the nebm module,
196+
# using the current band state self.y
197+
self.rhs(t, self.y)
198+
199+
200+
# self.step += 1
201+
self.gradE_last[:] = -self.field # Scale field??
202+
self.gradE_last[~_material] = 0.0
203+
self.gradE[:] = self.gradE_last
204+
self.totalE_last = self.totalE
205+
self.trailE[nStart] = self.totalE
206+
nStart = next(trailPool)
207+
eta = 1.0
208+
totalRestart = False
209+
210+
creepCount = 0
211+
212+
# Creep stage: minimise with a fixed eta
213+
while creepCount < maxCreep:
214+
# Update spin. Avoid pinned or zero-Ms sites
215+
self.y[:] = self.y_last - eta * eta_scale * self.forces_images
216+
217+
218+
219+
220+
221+
168222
# while abs(self.i_step - steps) > EPSILON:
169223
st = 1
170224
while st < n_steps:

Diff for: fidimag/common/nebm_FS.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def compute_spring_force(self, y):
314314
)
315315

316316
def compute_action(self):
317-
action = spi.cumulative_trapezoid(self.distances, self.gradientENorm)
317+
action = spi.trapezoid(self.gradientENorm, self.distances)
318318
return action
319319

320320
def compute_min_action(self):

0 commit comments

Comments
 (0)