← Back to team overview

ufl team mailing list archive

[noreply@xxxxxxxxxxxxx: [Branch ~ufl-core/ufl/main] Rev 917: Implement 'division' function in PartExtractor.]

 

I don't think there are any UFL experts left so your guess is as good
as mine.

--
Anders
--- Begin Message ---
------------------------------------------------------------
revno: 917
committer: Garth N. Wells <gnw20@xxxxxxxxx>
branch nick: ufl
timestamp: Sat 2010-06-05 19:30:34 +0100
message:
  Implement 'division' function in PartExtractor.
  
  Some simple tests seem to work.
  
  UFL experts (if there are any left ;)), please look at the logic of the function. PartExtractor has no docstring, so there's a degree of guess work in figuring out what exactly it's supposed to do.
modified:
  ufl/algorithms/formtransformations.py


--
lp:ufl
https://code.launchpad.net/~ufl-core/ufl/main

Your team UFL Core Team is subscribed to branch lp:ufl.
To unsubscribe from this branch go to https://code.launchpad.net/~ufl-core/ufl/main/+edit-subscription
=== modified file 'ufl/algorithms/formtransformations.py'
--- ufl/algorithms/formtransformations.py	2010-06-05 10:09:59 +0000
+++ ufl/algorithms/formtransformations.py	2010-06-05 18:30:34 +0000
@@ -5,7 +5,7 @@
 __date__ = "2008-10-01"
 
 # Modified by Anders Logg, 2008-2009.
-# Modified by Garth Nl Wells, 2010.
+# Modified by Garth N. Wells, 2010.
 # Last changed: 2010-03-23
 
 from itertools import izip
@@ -37,8 +37,9 @@
 
     def expr(self, x):
         "The default is a nonlinear operator not accepting any basis functions in its children."
+        # TODO: Other operators to implement particularly? Will see when errors here trigger...
         if any(isinstance(t, Argument) for t in traverse_terminals(x)):
-            error("Found basis function in %s, this is an invalid expression." % repr(x)) # TODO: Other operators to implement particularly? Will see when errors here trigger...
+            error("Found basis function in %s, this is an invalid expression." % repr(x))
         return (x, set())
     terminal = expr
 
@@ -122,7 +123,29 @@
     dot = product
 
     def division(self, x, *ops):
-        error("Please implement PartExtracter divsion.")
+        # FIXME: Check logic of this function
+
+        # Get numerator and denominator
+        numerator, denominator = x.operands()
+
+        provides = []
+
+        # Visit numerator
+        numerator_x, numerator_provides = self.visit(numerator)
+        provides.extend(numerator_provides)
+
+        # Visit denominator
+        denominator_x, denominator_provides = self.visit(denominator)
+        provides.extend(denominator_provides)
+
+        # Check for basis function in the denominator
+        if any(isinstance(t, Argument) for t in traverse_terminals(denominator)):
+            error("Found basis function in denominator of %s , this is an invalid expression." % repr(x))
+
+        # FIXME: Should we try using 'reuse_if_possible'?
+
+        provides = set(provides)
+        return (x, provides)
 
     def linear_operator(self, x, arg):
         "A linear operator in a single argument accepting arity > 0, providing whatever basis functions its argument does."
@@ -168,7 +191,6 @@
     pe = PartExtracter(arguments)
     def _transform(e):
         e, provides = pe.visit(e)
-        #print "compute_form_with_arity:", arity, bf, e, provides
         if provides == arguments:
             return e
         return Zero()


--- End Message ---

Attachment: signature.asc
Description: Digital signature