Renaming a Function during creation does not work completely

Issue #921 new
Carlos Baptista created an issue

Setting the label of a Function during creation does not work. You can only set the label using the .rename("name", "label") method. Here is a short example which shows this behaviour:

from fenics import *

mesh = UnitSquareMesh(4, 4)
V = FunctionSpace(mesh, "P", 1)
v = Function(V, name="v", label="Some quantity")

print("v.name(): {}    v.label(): {}".format(v.name(), v.label()))
v.rename("v", "Some quantity")
print("v.name(): {}    v.label(): {}".format(v.name(), v.label()))

Comments (5)

  1. Jan Blechta

    Is anywhere documented that this is supposed to work? I don't see a reason why this should work.

  2. Carlos Baptista reporter

    Maybe it is not, but this should be very easy to "fix". I located the issue in the init of class Function in src/site-packages/dolfin/functions/function.py:

    name = kwargs.get("name") or "f_%d" % self.count()
    self.rename(name, "a Function")
    

    This should be sufficient:

    name = kwargs.get("name") or "f_%d" % self.count()
    label = kwargs.get("label") or "a Function"
    self.rename(name, label)
    
  3. Log in to comment