Skip to content

Commit dd4a238

Browse files
author
davidcorteso
committed
Removed Ms_long in micro Zeeman class
1 parent 802e203 commit dd4a238

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

fidimag/micro/zeeman.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,10 @@ def setup(self, mesh, spin, Ms):
7070
self.n = mesh.n
7171

7272
self.Ms = Ms
73-
self.Ms_long = np.zeros(3 * mesh.n)
7473

7574
# TODO: Check if it is necessary to define a 3D matrix for
7675
# the Ms vectors. Maybe there is a way that uses less memory
7776
# (see the calculation in the *compute_energy* function)
78-
self.Ms_long.shape = (3, -1)
79-
for i in range(mesh.n):
80-
self.Ms_long[:, i] = Ms[i]
81-
82-
self.Ms_long.shape = (-1,)
8377
self.field = np.zeros(3 * self.n)
8478
self.field[:] = helper.init_vector(self.H0, self.mesh)
8579
# print self.field
@@ -101,14 +95,14 @@ def average_field(self):
10195

10296
def compute_energy(self):
10397

104-
sf = self.field * self.spin * self.Ms_long * mu_0
98+
sf = self.field * self.spin * mu_0
10599

106-
energy = -np.sum(sf)
100+
energy_density = -np.sum(sf.reshape(-1, 3), axis=1) * self.Ms
107101

108-
return energy * (self.mesh.dx *
109-
self.mesh.dy *
110-
self.mesh.dz *
111-
self.mesh.unit_length ** 3.)
102+
return np.sum(energy_density) * (self.mesh.dx *
103+
self.mesh.dy *
104+
self.mesh.dz *
105+
self.mesh.unit_length ** 3.)
112106

113107

114108
class TimeZeeman(Zeeman):

0 commit comments

Comments
 (0)