This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

DirichletBC: sometimes `.function_arg` exists, sometimes it doesn't

+2 votes

When defining a DirichletBC, one might want to access its values after the object has been created (e.g., to alter a parameter in it in case it is an Expression).

I've always used function_arg for it, i.e.,

d1 = DirichletBC(V, '0.0', 'on_boundary')
d1.function_arg.t = 42.0

but now I noticed that it just _does not exist_ in some cases. A common example would be

ex1 = Function(V)
d2 = DirichletBC(V, ex1, 'on_boundary')
print(d2.function_arg)
# AttributeError: 'DirichletBC' object has no attribute 'function_arg'

What is the reason for this?

asked Nov 25, 2013 by nschloe FEniCS User (7,120 points)
edited Nov 26, 2013 by nschloe

1 Answer

+2 votes
 
Best answer

It was never meant to be used. It is there to keep a reference to an Expression avoiding garbage collection in Python. The easiest thing for you is probably to keep a reference to your value either outside the DirichletBC or just attach it to it as an attribute your self.

answered Nov 25, 2013 by johanhake FEniCS Expert (22,480 points)
selected Nov 26, 2013 by nschloe
...