Ejemplo n.º 1
0
 def conditional(self, f): # TODO: Is this right? What about non-scalars?
     c, a, b = f.operands()
     s = f.shape()
     ufl_assert(s == (), "TODO: Assuming scalar valued expressions.")
     _0 = Zero()
     _1 = IntValue(1)
     da = conditional(c, _1, _0)
     db = conditional(c, _0, _1)
     return (None, da, db)
Ejemplo n.º 2
0
 def conditional(self, o, c, t, f):
     o = self.reuse_if_possible(o, c[0], t[0], f[0])
     if isinstance(t[1], Zero) and isinstance(f[1], Zero):
         tp = t[1] # Assuming t[1] and f[1] have the same indices here, which should be the case
         fi = tp.free_indices()
         fid = subdict(tp.index_dimensions(), fi)
         op = Zero(tp.shape(), fi, fid)
     else:
         op = conditional(c[0], 1, 0)*t[1] + conditional(c[0], 0, 1)*f[1]
     return (o, op)
Ejemplo n.º 3
0
 def conditional(self, o, c, t, f):
     o = self.reuse_if_possible(o, c[0], t[0], f[0])
     if isinstance(t[1], Zero) and isinstance(f[1], Zero):
         tp = t[
             1]  # Assuming t[1] and f[1] have the same indices here, which should be the case
         fi = tp.free_indices()
         fid = subdict(tp.index_dimensions(), fi)
         op = Zero(tp.shape(), fi, fid)
     else:
         op = conditional(c[0], 1, 0) * t[1] + conditional(c[0], 0,
                                                           1) * f[1]
     return (o, op)
Ejemplo n.º 4
0
 def min_value(self, o, df, dg):
     # d/dx min(f, g) =
     #  f < g: df/dx
     #  else: dg/dx
     #  Placing df,dg outside here to avoid getting arguments
     #  inside conditionals
     f, g = o.ufl_operands
     dc = conditional(f < g, 1, 0)
     return dc * df + (1.0 - dc) * dg
Ejemplo n.º 5
0
 def min_value(self, o, df, dg):
     # d/dx min(f, g) =
     #  f < g: df/dx
     #  else: dg/dx
     #  Placing df,dg outside here to avoid getting arguments
     #  inside conditionals
     f, g = o.ufl_operands
     dc = conditional(f < g, 1, 0)
     return dc*df + (1.0 - dc)*dg
Ejemplo n.º 6
0
 def conditional(self, o, unused_dc, dt, df):
     global CONDITIONAL_WORKAROUND
     if isinstance(dt, Zero) and isinstance(df, Zero):
         # Assuming dt and df have the same indices here, which
         # should be the case
         return dt
     elif CONDITIONAL_WORKAROUND:
         # Placing t[1],f[1] outside here to avoid getting
         # arguments inside conditionals.  This will fail when dt
         # or df become NaN or Inf in floating point computations!
         c = o.ufl_operands[0]
         dc = conditional(c, 1, 0)
         return dc * dt + (1.0 - dc) * df
     else:
         # Not placing t[1],f[1] outside, allowing arguments inside
         # conditionals.  This will make legacy ffc fail, but
         # should work with uflacs.
         c = o.ufl_operands[0]
         return conditional(c, dt, df)
Ejemplo n.º 7
0
 def conditional(self, o, unused_dc, dt, df):
     global CONDITIONAL_WORKAROUND
     if isinstance(dt, Zero) and isinstance(df, Zero):
         # Assuming dt and df have the same indices here, which
         # should be the case
         return dt
     elif CONDITIONAL_WORKAROUND:
         # Placing t[1],f[1] outside here to avoid getting
         # arguments inside conditionals.  This will fail when dt
         # or df become NaN or Inf in floating point computations!
         c = o.ufl_operands[0]
         dc = conditional(c, 1, 0)
         return dc*dt + (1.0 - dc)*df
     else:
         # Not placing t[1],f[1] outside, allowing arguments inside
         # conditionals.  This will make legacy ffc fail, but
         # should work with uflacs.
         c = o.ufl_operands[0]
         return conditional(c, dt, df)