From: Derek G. <fri...@gm...> - 2006-06-15 02:12:24
|
> The other way would be to make deep copies of all the nodes first, then > manually Elem::build() each new Element, and point its nodes to the newly-created > nodes of the same id() as the old ones had. Should be do-able... > This was my plan... I'm already working on it as we speak. I'm sure I'll have questions on it though... so ready yourself ;-) Derek On 6/14/06, John Peterson <pet...@cf...> wrote: > Roy Stogner writes: > > On Wed, 14 Jun 2006, Derek Gaston wrote: > > > > > So I was trying to make a copy of my mesh object (because I was going to > > > smooth the copy first then move nodes and project the solution later)... in > > > doing so I was going to use the copy constructor for mesh like so: > > > > > > Mesh smoothed_mesh(mesh); > > > > > > The problem is that when smoothed_mesh goes out of focus it appears to > > > delete things inside of the original mesh! Digging into the copy > > > constructor it appears that we just copy over node and element pointers... > > > instead of actually making copies of the nodes/elements. Is this actually > > > what we want? When do you want a copy of a mesh that is actually a mesh > > > reference? Shouldn't the copy constructor do a "real" or "deep" copy (ie > > > recreate all nodes and elements)? When I use a copy constructor I expect to > > > be able to do what I like with the copy and not impact the copied object in > > > the slightest... otherwise what was the point? > > > > > > Or am I just off-base? > > > > I was about to reply and tell you that there's several heavyweight > > classes in libMesh which don't go to the trouble of either > > implementing a deep copy or disabling the default copy constructor, > > and that you were probably discovering that Mesh was one of those... > > > > But looking at the code, there is an explicitly defined copy > > constructor there, and yes, all it does is copy the node pointer and > > element pointer vectors without copying the nodes and elements. > > You're not off base; I'm not sure why anyone would have written that. > > It's probably obsolete code from before John refactored the > > Mesh/MeshBase classes. > > Option 2: I wrote that code like that because I'm a dumbass :) > > The code's wrong, Derek's right. In the meantime the copy constructor > should become protected so no one can call it until it's fixed. > > Elem::clone() would be nice, but I'm not sure how to do this: the > new Elem will need Node pointers to the **newly created** nodes in the > new Mesh. I can't see how the old elem would know about those ... > > The other way would be to make deep copies of all the nodes first, then > manually Elem::build() each new Element, and point its nodes to the newly-created > nodes of the same id() as the old ones had. Should be do-able... > > > -J > > > |