def _OperatorVariableClass(self, baseClass=None): """ >>> from fipy.meshes import Grid1D >>> a = CellVariable(mesh=Grid1D(nx=1), value=1) >>> c = -a >>> b = c.old + 3 >>> print(b) [2] >>> from builtins import str >>> print(str(b.getsctype()) == str(numerix.NUMERIX.obj2sctype(numerix.array(1)))) True replacing with the same thing is no problem >>> a.value = (3) >>> b = c.old + 3 >>> print(b) [0] replacing with multiple copies causes the reference counting problem >>> a.value = (3) >>> b = (c + c).old + 3 >>> print(b) [-3] the order matters >>> b = (c + c).old + 3 >>> a.value = (2) >>> print(b) [-1] """ baseClass = _MeshVariable._OperatorVariableClass(self, baseClass=baseClass) class _CellOperatorVariable(baseClass): @property def old(self): if self._old is None: oldVar = [] for v in self.var: if hasattr(v, "old"): oldVar.append(v.old) else: oldVar.append(v) self._old = self.__class__(op=self.op, var=oldVar, opShape=self.opShape, canInline=self.canInline) return self._old return _CellOperatorVariable