On Thu, 20 Nov 2008, Yujie wrote:
> I notice that if i need to add vectors in LinearImplicitSystem using
> System::add_vector() it must be done before System::init(). However, I can't
> confirm the vector number at the beginning. How to dynamically add vectors?
Try the following patch, and let me know if it works; if so I'll commit it to SVN.
--- src/solvers/system.C (revision 3160)
+++ src/solvers/system.C (working copy)
@@ -493,21 +493,17 @@
- // We can only add new vectors before initializing...
- if (!_can_add_vectors)
- std::cerr << "ERROR: Too late. Cannot add vectors to the system after initialization"
- << std::endl
- << " any more. You should have done this earlier."
- << std::endl;
- // Otherwise build the vector and return it.
+ // Otherwise build the vector
NumericVector<Number>* buf = NumericVector<Number>::build().release();
_vectors.insert (std::make_pair (vec_name, buf));
_vector_projections.insert (std::make_pair (vec_name, projections));
+ // Initialize it if necessary
+ if (!_can_add_vectors)
+ buf->init (this->n_dofs(), this->n_local_dofs());
> In addition, In the same LinearImplicitSystem, the vectors added by
> add_vector() have similar characteristics with the variable added by
> add_variable(), such as parallel distribution, same Dofs? thanks a lot.
Every vector added to a system has dofs for every variable in that system. All
vectors have the same indexing and the same parallel distribution. (In
particular they're all parallelized like solution, and if you want ghost dof
coefficients you'll need to create a local vector to hold them)