Subject: [Ufl] [[email-masked]: [Branch ~ufl-core/ufl/main] Rev 1145: Made Form.*_domains into properties which emit]

From: Anders Logg <[email-masked]>
Date: Wed, 22 Jun 2011 19:28:10 +0200

I thought this was already fixed in DOLFIN.

--
Anders

Subject: [Branch ~ufl-core/ufl/main] Rev 1145: Made Form.*_domains into properties which emit
From: [email-masked]
To: Anders Logg <[email-masked]>
Date: Wed, 22 Jun 2011 17:14:18 -0000

------------------------------------------------------------
revno: 1145
committer: Martin Alnes <[email-masked]>
branch nick: work
timestamp: Wed 2011-06-22 19:10:37 +0200
message:
  Made Form.*_domains into properties which emit
  a deprecation warning when they are set.
  
  We should get all pydolfin code over to use
  the dx[boundaries] syntax before 1.0 to avoid
  the bugs Form.*_domains make possible.
  
  Also did some docstring updates
modified:
  ufl/form.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/form.py'
--- ufl/form.py	2011-06-21 12:44:19 +0000
+++ ufl/form.py	2011-06-22 17:10:37 +0000
@@ -34,27 +34,49 @@
 class Form(object):
     """Description of a weak form consisting of a sum of integrals over subdomains."""
     __slots__ = ("_integrals",
-                 "_repr", "_hash", "_str", "_form_data", "_is_preprocessed",
-                 "cell_domains", "exterior_facet_domains", "interior_facet_domains")
-
-    # Note: cell_domains, exterior_facet_domains and interior_facet_domains
-    # are used by DOLFIN to pass data to the assembler. They can otherwise
-    # safely be ignored.
+                 "_repr", "_hash", "_str",
+                 "_form_data", "_is_preprocessed",
+                 "_cell_domains", "_exterior_facet_domains", "_interior_facet_domains")
 
     def __init__(self, integrals):
         self._integrals = tuple(integrals)
-        ufl_assert(all(isinstance(itg, Integral) for itg in integrals), "Expecting list of integrals.")
+        ufl_assert(all(isinstance(itg, Integral) for itg in integrals),
+                   "Expecting list of integrals.")
         self._str = None
         self._repr = None
         self._hash = None
         self._form_data = None
         self._is_preprocessed = False
 
-        # TODO: Can we attach non-ufl payloads in a more generic fashion?
-        # This seems prone to change with dolfin versions.
-        self.cell_domains = None
-        self.exterior_facet_domains = None
-        self.interior_facet_domains = None
+        # Note: cell_domains, exterior_facet_domains and interior_facet_domains
+        # are used by DOLFIN to pass data to the assembler. They are deprecated
+        # because they lead to bugs and will be removed.
+        self._cell_domains = None
+        self._exterior_facet_domains = None
+        self._interior_facet_domains = None
+
+    # TODO: Remove these completely!
+    @property
+    def cell_domains(self):
+        return self._cell_domains
+    @cell_domains.setter
+    def _set_cell_domains(self, domains):
+        warning("Deprecation warning! Attach your boundary indicators to the measure instead.")
+        self._cell_domains = domains
+    @property
+    def exterior_facet_domains(self):
+        return self._exterior_facet_domains
+    @exterior_facet_domains.setter
+    def _set_exterior_facet_domains(self, domains):
+        warning("Deprecation warning! Attach your boundary indicators to the measure instead.")
+        self._exterior_facet_domains = domains
+    @property
+    def interior_facet_domains(self):
+        return self._interior_facet_domains
+    @interior_facet_domains.setter
+    def _set_interior_facet_domains(self, domains):
+        warning("Deprecation warning! Attach your boundary indicators to the measure instead.")
+        self._interior_facet_domains = domains
 
     def cell(self):
         c = None
@@ -168,19 +190,25 @@
         return Form(newintegrals)
 
     def __sub__(self, other):
+        "Subtract other form from this one."
         return self + (-other)
 
     def __neg__(self):
-        # This enables the handy "-form" syntax for e.g. the linearized system (J, -F) from a nonlinear form F
+        """Negate all integrals in form.
+        
+        This enables the handy "-form" syntax for e.g. the
+        linearized system (J, -F) from a nonlinear form F."""
         return Form([-itg for itg in self._integrals])
 
     def __rmul__(self, scalar):
+        "Multiply all integrals in form with constant scalar value."
         # This enables the handy "0*form" syntax
-        ufl_assert(is_python_scalar(scalar), "Only multiplication by scalar literals currently supported.")
+        ufl_assert(is_python_scalar(scalar),
+                   "Only multiplication by scalar expressions currently supported.")
         return Form([scalar*itg for itg in self._integrals])
 
     def __mul__(self, coefficient):
-        "The action of this form on the given coefficient."
+        "UFL form operator: Take the action of this form on the given coefficient."
         from ufl.formoperators import action
         return action(self, coefficient)

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Wed, 22 Jun 2011 20:02:01 +0200

Possibly, but this deprecation warning will tell users to change their code.
But since dolfin has been updated, maybe their code is already broken
if they use this? Then I can just remove it. At least I got to use Python
properties again, haven't done that in a while :)

Martin

On 22 June 2011 19:28, Anders Logg <[email-masked]> wrote:
> ---------- Forwarded message ----------
> _______________________________________________
> Mailing list: https://launchpad.net/~ufl
> Post to     : [email-masked]
> Unsubscribe : https://launchpad.net/~ufl
> More help   : https://help.launchpad.net/ListHelp
>
>

---

From: "Marie E. Rognes" <[email-masked]>
Date: Thu, 23 Jun 2011 16:02:59 +0200

On 06/22/11 20:02, Martin Sandve Alnæs wrote:
> if they use this?

DOLFIN has been updated, and so the syntax

     L.exterior_facet_domains = ...

will not do anything sensible (I think ;-) )

But one can still attach whatever one wants to a form, right? So we 
better make this change pretty clear.

--
Marie

> Then I can just remove it. At least I got to use Python
> On 22 June 2011 19:28, Anders Logg<[email-masked]>  wrote:
>> To: Anders Logg<[email-masked]>
>> committer: Martin Alnes<[email-masked]>
>> branch nick: work

---

From: Anders Logg <[email-masked]>
Date: Mon, 27 Jun 2011 09:56:41 +0200

> better make this change pretty clear.

No, the __slots__ thing should prevent that.

--
Anders

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Mon, 27 Jun 2011 10:10:04 +0200

> No, the __slots__ thing should prevent that.

Now it shows:

In [3]: a.exterior_facet_domains = 'foo'
Deprecated: ufl.Form has no properties '*_domains'.
To associate domains with a form, use dss = ds[mydomains]; a = f*dss(1).

Martin

---

From: Anders Logg <[email-masked]>
Date: Mon, 27 Jun 2011 10:11:55 +0200

> To associate domains with a form, use dss = ds[mydomains]; a = f*dss(1).

Very nice!

--
Anders

---

From: "Marie E. Rognes" <[email-masked]>
Date: Mon, 27 Jun 2011 11:11:27 +0200

>> No, the __slots__ thing should prevent that.

Aha, neat :)

--
Marie