Implement deep copy for fields
Currently, if a
and b
are ippl::Field
s, the assignment a = b
does not invoke operator=(ippl::detail::Expression)
but instead simply performs a shallow copy. This means that the Kokkos views in a
and b
will address the same memory space and changes to one field will affect the other. To copy the contents from one field to another, one can
- use an explicit loop; or
- force a detour through an expression, such as by writing
a = b * 1
.
The field type should provide a deep copy function to simplify this.
Possible signatures:
-
void ippl::Field::copy(Field&, Field&)
copy the contents of one field into another -
ippl::Field ippl::Field::copy()
return a newly constructed field with the same properties and contents -
ippl::Field& operator=(const Field&)
redefine the assignment operator
The second option seems best as it's explicit, fits well with object oriented code (as opposed to the first one), and doesn't break any copy constructions (such as for functions that take non-reference arguments, even though there don't appear to be any such functions in IPPL).