Skip to content

Commit 83f359c

Browse files
committed
Add a remove interaction function to sim base
1 parent 293bc43 commit 83f359c

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

fidimag/common/sim_base.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class SimBase(object):
1111
atomistic simulations
1212
1313
"""
14+
1415
def __init__(self, mesh, name):
1516

1617
self.name = name
@@ -215,6 +216,44 @@ def get_interaction(self, name):
215216
"available interactions: {1}.".format(
216217
name, [x.name for x in self.interactions]))
217218

219+
def remove(self, name):
220+
"""
221+
Removes an interaction from a simulation.
222+
223+
This is useful because it reduces the run-time
224+
if the interaction calculation time is substantial.
225+
"""
226+
227+
interaction = None
228+
# First we remove it from the list of interactions
229+
print(self.interactions)
230+
for i, intn in enumerate(self.interactions):
231+
print(intn.name)
232+
if intn.name == name:
233+
interaction = self.interactions.pop(i)
234+
break
235+
236+
if not interaction:
237+
raise ValueError("Could not find the "
238+
"interaction with name {}".format(name))
239+
240+
# Next, we need to change the data saver entities.
241+
# We don't want to remove the relevant interaction
242+
# completely because if this is done, the table
243+
# would be incorrect. What we need to do is therefore
244+
# replace the lambda functions with dummy ones which
245+
# just return zeros; for example.if no Zeeman intn then
246+
# the Zeeman energy and field are zero anyway.
247+
self.data_saver.entities['E_{}'.format(name)]['get'] = lambda sim: 0
248+
# We don't save field by default, so need to check if
249+
# save field is selected. Easiest just to use a try/except
250+
# block here; not a performance critical function.
251+
try:
252+
self.data_saver.entities[name]['get'] = \
253+
lambda sim: np.array([0.0, 0.0, 0.0])
254+
except:
255+
pass
256+
218257
def skyrmion_number(self):
219258
pass
220259

0 commit comments

Comments
 (0)