@@ -11,6 +11,7 @@ class SimBase(object):
11
11
atomistic simulations
12
12
13
13
"""
14
+
14
15
def __init__ (self , mesh , name ):
15
16
16
17
self .name = name
@@ -215,6 +216,44 @@ def get_interaction(self, name):
215
216
"available interactions: {1}." .format (
216
217
name , [x .name for x in self .interactions ]))
217
218
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
+
218
257
def skyrmion_number (self ):
219
258
pass
220
259
0 commit comments