@@ -47,39 +47,72 @@ namespace libMesh
4747// Full specialization for Real datatypes
4848template < typename T >
4949std ::unique_ptr < NumericVector < T >>
50- NumericVector < T > ::build (const Parallel ::Communicator & comm , const SolverPackage solver_package )
50+ NumericVector < T > ::build (const Parallel ::Communicator & comm ,
51+ SolverPackage solver_package ,
52+ ParallelType parallel_type )
5153{
5254 // Build the appropriate vector
5355 switch (solver_package )
5456 {
5557
5658#ifdef LIBMESH_HAVE_LASPACK
5759 case LASPACK_SOLVERS :
58- return std ::make_unique < LaspackVector < T >>(comm , AUTOMATIC );
60+ return std ::make_unique < LaspackVector < T >>(comm , parallel_type );
5961#endif
6062
6163#ifdef LIBMESH_HAVE_PETSC
6264 case PETSC_SOLVERS :
63- return std ::make_unique < PetscVector < T >>(comm , AUTOMATIC );
65+ return std ::make_unique < PetscVector < T >>(comm , parallel_type );
6466#endif
6567
6668#ifdef LIBMESH_TRILINOS_HAVE_EPETRA
6769 case TRILINOS_SOLVERS :
68- return std ::make_unique < EpetraVector < T >>(comm , AUTOMATIC );
70+ return std ::make_unique < EpetraVector < T >>(comm , parallel_type );
6971#endif
7072
7173#ifdef LIBMESH_HAVE_EIGEN
7274 case EIGEN_SOLVERS :
73- return std ::make_unique < EigenSparseVector < T >>(comm , AUTOMATIC );
75+ return std ::make_unique < EigenSparseVector < T >>(comm , parallel_type );
7476#endif
7577
7678 default :
77- return std ::make_unique < DistributedVector < T >>(comm , AUTOMATIC );
79+ return std ::make_unique < DistributedVector < T >>(comm , parallel_type );
7880 }
7981}
8082
8183
8284
85+ template < typename T >
86+ void NumericVector < T > ::set_type (ParallelType t )
87+ {
88+ // Check for no-op
89+ if (_type == t )
90+ return ;
91+
92+ // If the NumericVector is not yet initialized, then it is generally
93+ // safe to change the ParallelType, with minor restrictions.
94+ if (!this -> initialized ())
95+ {
96+ // If ghosted vectors are not enabled and the user requested a
97+ // GHOSTED vector, fall back on SERIAL.
98+ #ifndef LIBMESH_ENABLE_GHOSTED
99+ if (t == GHOSTED )
100+ {
101+ _type = SERIAL ;
102+ return ;
103+ }
104+ #endif
105+
106+ _type = t ;
107+ return ;
108+ }
109+
110+ // If we made it here, then the NumericVector was already
111+ // initialized and we don't currently allow the ParallelType to be
112+ // changed, although this could potentially be added later.
113+ libmesh_not_implemented ();
114+ }
115+
83116template < typename T >
84117void NumericVector < T > ::insert (const T * v ,
85118 const std ::vector < numeric_index_type > & dof_indices )
0 commit comments