Skip to content

Commit 339764c

Browse files
Added ADD method to the Baryakhtar code (not optimal but working for now, we could move this function to the helpers). Made CHI parameter a property so it is updated properly when this driver parameter is called and defined
1 parent d22bbf9 commit 339764c

File tree

1 file changed

+71
-2
lines changed

1 file changed

+71
-2
lines changed

fidimag/micro/baryakhtar.py

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,30 @@ def __init__(self, mesh, spin, Ms, field, pins,
2424
use_jac=use_jac
2525
)
2626

27-
self.chi = chi
27+
self._chi = 1e-3
28+
add(Relaxation(self.chi, name='chi_relax'),
29+
self.interactions, self.data_saver,
30+
self.mesh, self.spin, self._Ms)
31+
2832
self.lap = Laplace(mesh)
29-
self.add(Relaxation(chi))
33+
# OLD: self.add(Relaxation(chi))
3034

3135
self.beta = 0
3236

37+
def get_chi(self):
38+
"""
39+
"""
40+
return self._chi
41+
42+
def set_chi(self, chi):
43+
"""
44+
"""
45+
for i in self.interactions:
46+
if i.name == 'chi_relax':
47+
i.chi = chi
48+
49+
chi = property(get_chi, set_chi)
50+
3351
def sundials_rhs(self, t, y, ydot):
3452

3553
self.t = t
@@ -107,3 +125,54 @@ def sundials_rhs(self, t, y, ydot):
107125
#ydot[:] = self.dm_dt[:]
108126

109127
return 0
128+
129+
130+
def add(interaction, interactions_list, data_saver,
131+
mesh, spin, magnetisation, save_field=False):
132+
133+
"""
134+
135+
Add an interaction to the interaction list.
136+
This function is based on the Sim class *add* method
137+
(it is likely that this function will be moved to the common
138+
helpers in the future)
139+
140+
OPTIONAL ARGUMENTS:
141+
142+
save_field :: Set True to save the average values of this
143+
interaction field when relaxing the system
144+
145+
"""
146+
147+
# magnetisation is Ms for the micromagnetic Sim class, and it is
148+
# mu_s for the atomistic Sim class
149+
interaction.setup(mesh, spin, magnetisation)
150+
151+
# TODO: FIX --> ??
152+
# When adding an interaction that was previously added, using
153+
# the same name, append a '_2' to the new interaction name (?)
154+
for i in interactions_list:
155+
if i.name == interaction.name:
156+
interaction.name = i.name + '_2'
157+
158+
interactions_list.append(interaction)
159+
160+
# Specify a name for the energy of the interaction, which will
161+
# appear in a file with saved values
162+
# When saving the energy values, we call the compute_energy() method
163+
# from the (micromagnetic/atomistic) Energy class (overhead?)
164+
energy_name = 'E_{0}'.format(interaction.name)
165+
data_saver.entities[energy_name] = {
166+
'unit': '<J>',
167+
'get': lambda sim: sim.get_interaction(interaction.name).compute_energy(),
168+
'header': energy_name}
169+
170+
# Save the average values of the interaction vector field components
171+
if save_field:
172+
fn = '{0}'.format(interaction.name)
173+
data_saver.entities[fn] = {
174+
'unit': '<>',
175+
'get': lambda sim: sim.get_interaction(interaction.name).average_field(),
176+
'header': ('%s_x' % fn, '%s_y' % fn, '%s_z' % fn)}
177+
178+
data_saver.update_entity_order()

0 commit comments

Comments
 (0)