Skip to content

Commit 6c50f48

Browse files
nebm fs: debugging and improving action calc
1 parent df04876 commit 6c50f48

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

fidimag/common/chain_method_integrators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def run_for(self, n_steps):
249249
# Creep stage: minimise with a fixed eta
250250
while creepCount < self.maxCreep:
251251
# Update spin. Avoid pinned or zero-Ms sites
252-
self.band[:] = self.band_old + eta * self.etaScale * self.forces
252+
self.band[:] = self.band_old + eta * self.etaScale * self.forces_old
253253
normalise_spins(self.band)
254254

255255
self.trailAction
@@ -285,6 +285,7 @@ def run_for(self, n_steps):
285285
f'eta = {eta:>5.4e} '
286286
f'action = {self.action:>5.4e} action_old = {self.action_old:>5.4e}'
287287
)
288+
# print(self.forces)
288289

289290
# 10 seems like a magic number; we set here a minimum number of evaulations
290291
if (nStart > self.nTrail * 10) and (deltaAction < self.actionTol):

fidimag/common/nebm_FS.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,6 @@ def compute_effective_field_and_energy(self, y):
253253

254254
self.energies[i] = self.sim.compute_energy()
255255

256-
# TODO: move this calc to the action function
257-
# Compute the gradient norm per every image
258-
Gnorms2 = np.sum(self.gradientE**2, axis=1) / self.n_images
259-
# Compute the root mean square per image
260-
self.gradientENorm[:] = np.sqrt(Gnorms2)
261-
262-
# DEBUG:
263-
# print('gradEnorm', self.gradientENorm)
264-
265256
y.shape = (-1)
266257
self.gradientE.shape = (-1)
267258

@@ -328,10 +319,20 @@ def compute_action(self):
328319
# self._material_int,
329320
# self.n_dofs_image_material
330321
# )
322+
323+
# NOTE: Gradient here is projected in the S2^N tangent space
324+
self.gradientE.shape = (self.n_images, -1)
325+
Gnorms2 = np.sum(self.gradientE**2, axis=1) / self.n_images
326+
# Compute the root mean square per image
327+
self.gradientENorm[:] = np.sqrt(Gnorms2)
328+
self.gradientE.shape = (-1)
329+
330+
# DEBUG:
331+
# print('gradEnorm', self.gradientENorm)
331332

332333
# TODO: we can use a better quadrature such as Gaussian
333334
# notice that the gradient norm here is using the RMS
334-
action = spi.trapezoid(self.gradientENorm, self.path_distances)
335+
action = spi.simpson(self.gradientENorm, x=self.path_distances)
335336

336337
# DEBUG:
337338
# print('action from gradE', action)
@@ -348,9 +349,9 @@ def compute_action(self):
348349
dist_minus_norm = self.distances[:-1]
349350
# dY_plus_norm = distances[i];
350351
# dY_minus_norm = distances[i - 1];
351-
springF2 = self.k[1:-1] * ((dist_plus_norm - dist_minus_norm)**2)
352+
springF2 = 0.5 * self.k[1:-1] * ((dist_plus_norm - dist_minus_norm)**2)
352353
# CHECK: do we need to scale?
353-
action += np.sum(springF2) / (self.n_images - 2)
354+
# action += np.sum(springF2) / (self.n_images - 2)
354355

355356
# DEBUG:
356357
# print('action spring term', np.sum(springF2) / (self.n_images - 2))

tests/test_two_particles_nebm-fs.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ def relax_string(maxst, simname, init_im, interp, save_every=10000):
6060
# equal to 'the number of initial states specified', minus one.
6161
interpolations = interp
6262

63-
nebm = NEBM_FS(sim, init_im, interpolations=interpolations, name=simname)
63+
nebm = NEBM_FS(sim, init_im, interpolations=interpolations, name=simname,
64+
interpolation_method='linear')
6465

6566
# dt = integrator.stepsize means after every integrator step, the images
6667
# are rescaled. We can run more integrator steps if we decrease the
@@ -83,8 +84,8 @@ def mid_m(pos):
8384

8485
def test_energy_barrier_2particles_string():
8586
# Initial images: we set here a rotation interpolating
86-
init_im = [(-1, 0, 0), (1, 0, 0)]
87-
interp = [13]
87+
init_im = [(-1, 0, 0), (0.0, 0.0, 1.0), (1, 0, 0)]
88+
interp = [6, 6]
8889

8990
barriers = []
9091

0 commit comments

Comments
 (0)