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

How to make deep copies with split(U)

+2 votes

It seems there are several ways to use split. What is the difference between them?

V = FunctionSpace(...)
W = FunctionSpace(...)
U = V * W

a,b = split(U)

or

a,b = U.split()

How do I make a deep copy in the first case? Based on what I have read it seems like the first case is preferred.

asked Jun 27, 2016 by aldenpack FEniCS User (1,450 points)

2 Answers

+5 votes
 
Best answer

split is a UFL operator. It returns UFL objects that you can use in defining variational forms.

Function.split provides a view into the data of a mixed element Function.

If you want to make a copy of one component of a mixed finite element function, you can use the FunctionAssigner class. For example,

v = Function(V)
assigner = FunctionAssigner(V, U.sub(0))
assigner.assign(v, u.sub(0))

You can also use FunctionAssigner for copying in the other direction.

answered Jun 28, 2016 by Magne Nordaas FEniCS Expert (13,820 points)
selected Jun 30, 2016 by aldenpack

Is the copy created using the FunctionAssigner class a deep copy or a shallow copy?

It's a deep copy.

+1 vote

a, b = U.split(deepcopy = True) will work.

answered Oct 4, 2016 by JeonghunLee FEniCS User (1,050 points)
...