21 #ifndef SELDON_FILE_VECTOR_PETSCVECTOR_CXX
24 #include "PetscVector.hxx"
36 template <
class T,
class Allocator>
43 ierr = VecGetSize(petsc_vector, &this->m_);
44 CHKERRABORT(mpi_communicator_, ierr);
45 PetscObjectGetComm(
reinterpret_cast<PetscObject
>(petsc_vector),
47 CHKERRABORT(mpi_communicator_, ierr);
48 ierr = VecDuplicate(petsc_vector, &petsc_vector_);
49 CHKERRABORT(mpi_communicator_, ierr);
50 ierr = VecCopy(petsc_vector, petsc_vector_);
51 CHKERRABORT(mpi_communicator_, ierr);
52 petsc_vector_deallocated_ =
false;
66 template <
class T,
class Allocator>
70 ierr = VecSet(petsc_vector_, 0.);
71 CHKERRABORT(mpi_communicator_, ierr);
76 template <
class T,
class Allocator>
84 ierr = VecSetValues(petsc_vector_, this->m_, index.GetData(),
85 data.GetData(), INSERT_VALUES);
86 CHKERRABORT(mpi_communicator_, ierr);
95 template <
class T,
class Allocator>
100 ierr = VecSet(petsc_vector_,
double(x));
101 CHKERRABORT(mpi_communicator_, ierr);
110 template <
class T,
class Allocator>
118 ierr = VecSetValues(petsc_vector_, this->m_, index.GetData(),
119 data.GetData(), INSERT_VALUES);
120 CHKERRABORT(mpi_communicator_, ierr);
134 template <
class T,
class Allocator>
135 typename PETScVector<T, Allocator>::value_type
140 ierr = VecNorm(petsc_vector_, NORM_INFINITY, &res);
141 CHKERRABORT(mpi_communicator_, ierr);
150 template <
class T,
class Allocator>
153 throw Undefined(
"PETScVector<T, Allocator>::GetNormInfIndex()");
174 template <
class T,
class Allocator>
176 ::Write(
string FileName,
bool with_size)
const
178 throw Undefined(
"Vector<T, PETScSeq, Allocator>"
179 "::Write(string FileName, bool with_size) const");
190 template <
class T,
class Allocator>
192 ::Write(ostream& FileStream,
bool with_size)
const
194 throw Undefined(
"Vector<T, PETScSeq, Allocator>"
195 "::Write(string FileName, bool with_size) const");
205 template <
class T,
class Allocator>
209 FileStream.precision(cout.precision());
210 FileStream.flags(cout.flags());
211 FileStream.open(FileName.c_str());
212 #ifdef SELDON_CHECK_IO
214 if (!FileStream.is_open())
215 throw IOError(
"Vector<T, PETScSeq, Allocator>"
216 "::WriteText(string FileName)",
217 string(
"Unable to open file \"") + FileName +
"\".");
219 this->WriteText(FileStream);
230 template <
class T,
class Allocator>
233 throw Undefined(
"Vector<T, PETScSeq, Allocator>"
234 "::WriteText(ostream& FileStream) const");
247 template <
class T,
class Allocator>
252 FileStream.open(FileName.c_str());
253 #ifdef SELDON_CHECK_IO
255 if (!FileStream.is_open())
256 throw IOError(
"Vector<T, PETScSeq, Allocator>::Read(string FileName)",
257 string(
"Unable to open file \"") + FileName +
"\".");
259 this->Read(FileStream, with_size);
273 template <
class T,
class Allocator>
275 ::Read(istream& FileStream,
bool with_size)
277 throw Undefined(
"Vector<T, PETScSeq, Allocator>"
278 "::Read(istream& FileStream, bool with_size)");
288 template <
class T,
class Allocator>
291 throw Undefined(
"Vector<T, PETScSeq, Allocator>"
292 "::ReadText(string FileName)");
302 template <
class T,
class Allocator>
305 throw Undefined(
"Vector<T, PETScSeq, Allocator>"
306 "::ReadText(istream& FileStream)");
316 template <
class T,
class Allocator>
321 for (
int i = 0; i < V.
GetLength() - 1; i++)
346 template <
class T,
class Allocator>
348 ::Write(
string FileName,
bool with_size)
const
350 throw Undefined(
"Vector<T, PETScPar, Allocator>"
351 "::Write(string FileName, bool with_size) const");
362 template <
class T,
class Allocator>
364 ::Write(ostream& FileStream,
bool with_size)
const
367 VecGetLocalSize(this->petsc_vector_, &local_n);
372 this->GetProcessorRange(i_start, i_end);
373 for (
int i = 0; i < local_n; i++)
376 VecGetValues(this->petsc_vector_, local_n, index.GetData(),
378 data.Write(FileStream, with_size);
388 template <
class T,
class Allocator>
392 FileStream.precision(cout.precision());
393 FileStream.flags(cout.flags());
394 FileStream.open(FileName.c_str());
395 #ifdef SELDON_CHECK_IO
397 if (!FileStream.is_open())
398 throw IOError(
"Vector<T, PETScPar, Allocator>"
399 "::WriteText(string FileName)",
400 string(
"Unable to open file \"") + FileName +
"\".");
402 this->WriteText(FileStream);
414 template <
class T,
class Allocator>
418 VecGetLocalSize(this->petsc_vector_, &local_n);
423 this->GetProcessorRange(i_start, i_end);
424 for (
int i = 0; i < local_n; i++)
427 VecGetValues(this->petsc_vector_, local_n, index.GetData(),
429 data.WriteText(FileStream);
442 template <
class T,
class Allocator>
447 FileStream.open(FileName.c_str());
448 #ifdef SELDON_CHECK_IO
450 if (!FileStream.is_open())
451 throw IOError(
"Vector<T, PETScPar, Allocator>::Read(string FileName)",
452 string(
"Unable to open file \"") + FileName +
"\".");
454 this->Read(FileStream, with_size);
468 template <
class T,
class Allocator>
470 ::Read(istream& FileStream,
bool with_size)
472 throw Undefined(
"PETScVector<T, PETScPar, Allocator>"
473 "::Read(istream& FileStream, bool with_size)");
483 template <
class T,
class Allocator>
486 throw Undefined(
"PETScVector<T, PETScPar, Allocator>"
487 "::ReadText(string FileName)");
497 template <
class T,
class Allocator>
500 throw Undefined(
"PETScVector<T, PETScPar, Allocator>"
501 "::ReadText(istream& FileStream)");
511 template <
class T,
class Allocator>
516 for (
int i = 0; i < V.
GetLength() - 1; i++)
527 #define SELDON_FILE_PETSCVECTOR_CXX