Thread Previous • Date Previous • Date Next • Thread Next |
Kent Andre wrote:
On ma., 2008-09-15 at 11:48 +0100, Garth N. Wells wrote:Kent Andre wrote:The problem is that I could also create the function, and then use it with a vector that hasn't been initialised properly.On ma., 2008-09-15 at 11:19 +0100, Garth N. Wells wrote:The reason for this, I think, is initialization as such:DOLFIN wrote:Vector::init() only resizes the vector if necessary, but it also zeroes the vector. Looks to me like it is desirable to zero the vector?One or more new changesets pushed to the primary dolfin repository. A short summary of the last three changesets is included below. changeset: 4751:df802d1b2b349e91a51b70f799ba6d0d3b825376 tag: tip user: Anders Logg <logg@xxxxxxxxx> date: Sat Sep 13 08:55:34 2008 +0200 files: dolfin/function/DiscreteFunction.cpp description: Don't initialize vector in DiscreteFunction if already initialized.Garthsolve(A, x, b, cg, amg) u = Function(element, mesh, x) plot(u)But then you would not use this constructor?The most robust approach, which I've been working towards, is that a DiscreteFunction always owns it's vector and can't be initialised with a Vector. The above code would beu = Function(element, mesh) solve(A, u.vec(), b, cg, amg) plot(u) GarthIt is fine by me if DiscreteFunction owns the vector, then the entriesof x has to be copied.
I've set it up now such that if a Function is created using the simple constructor interface (no smart pointers), it always owns the vector and a reference to the vector is returned by Function::vector(). This vector is initialised to zero.
It's possible to create a Function and associate it with a particular vector by using the interface with smart pointers, in which case the vector is not initialised to zero.
Garth
I'm having similar design decisions in BlockVectors and BlockMatrix. Should they own the subvectors and submatrices ? For now I have a boolean flag. In general I think it should be possible to set and get underlying pointers. This is dangerous but it is often something onewould like to do particulary when coupling to other software packages.Kent
Thread Previous • Date Previous • Date Next • Thread Next |