@@ -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))
0 commit comments