def variable(self, o): e, l = o.ufl_operands # noqa: E741 v = self.variable_map.get(l) if v is None: e = self.visit(e) l2 = Label(len(self.variable_map)) v = Variable(e, l2) self.variable_map[l] = v return v
def variable(self, o): # Check cache e, l = o.operands() c = self._variable_cache.get(l) if c is not None: return c if o.label() == self._variable.label(): # dv/dv = "1" op = self._make_ones_diff(o) else: # differentiate expression behind variable e2, ep = self.visit(e) op = ep if not e2 == e: o = Variable(e2, l) # return variable and derivative of its expression c = (o, op) self._variable_cache[l] = c return c
def variable(e): """UFL operator: Define a variable representing the given expression, see also ``diff()``.""" e = as_ufl(e) return Variable(e)