30 #ifndef OOMPH_DOUBLE_MULTI_VECTOR_CLASS_HEADER 31 #define OOMPH_DOUBLE_MULTI_VECTOR_CLASS_HEADER 35 #include <oomph-lib-config.h> 46 #ifdef OOMPH_HAS_TRILINOS 47 #include "Teuchos_Range1D.hpp" 78 this->
build(n_vector,dist_pt,v);
91 this->
build(n_vector,dist,v);
100 const double &initial_value=0.0) :
111 const std::vector<int> &index,
116 unsigned n_vector = index.size();
122 const unsigned n_row_local = this->
nrow_local();
123 for(
unsigned v=0;v<n_vector;v++)
125 for(
unsigned i=0;
i<n_row_local;
i++)
127 Values[v][
i] = old_vector(index[v],
i);
136 for(
unsigned v=0;v<n_vector;++v)
144 #ifdef OOMPH_HAS_TRILINOS 150 const Teuchos::Range1D &index,
155 unsigned n_vector = index.size();
161 const unsigned n_row_local = this->
nrow_local();
162 unsigned range_index = index.lbound();
163 for(
unsigned v=0;v<n_vector;v++)
165 for(
unsigned i=0;
i<n_row_local;
i++)
167 Values[v][
i] = old_vector(range_index,
i);
177 unsigned range_index = index.lbound();
178 for(
unsigned v=0;v<n_vector;v++)
193 this->
build(new_vector);
207 this->
build(old_vector);
218 if (!(*
this == old_vector))
231 for(
unsigned v=0;v<
Nvector;++v)
263 if (dist_pt->
built())
268 Values =
new double*[n_vector];
282 if (!(*
this == old_vector))
296 double**
const old_vector_values = old_vector.
values();
297 for (
unsigned i = 0;
i < n_row_local;
i++)
299 for(
unsigned v=0;v<
Nvector;v++)
301 Values[v][
i] = old_vector_values[v][
i];
311 void build(
const unsigned &n_vector,
313 const double& initial_value=0.0)
315 this->
build(n_vector,&dist,initial_value);
321 void build(
const unsigned &n_vector,
323 const double& initial_value=0.0)
335 if (dist_pt->
built())
340 Values =
new double*[n_vector];
342 const unsigned n_row_local = this->
nrow_local();
343 double *
values =
new double[n_row_local*n_vector];
345 for(
unsigned v=0;v<n_vector;v++)
347 Values[v] = &values[v*n_row_local];
348 for (
unsigned i = 0;
i < n_row_local;
i++)
366 const unsigned n_vector = this->
Nvector;
367 const unsigned n_row_local = this->
nrow_local();
370 for(
unsigned v=0;v<n_vector;v++)
372 for (
unsigned i=0;
i<n_row_local;
i++)
478 #ifdef RANGE_CHECKING 479 std::ostringstream error_message;
483 error_message <<
"Range Error: Vector " << v
484 <<
"is not in the range (0," 491 error_message <<
"Range Error: " << i
492 <<
" is not in the range (0," 500 OOMPH_CURRENT_FUNCTION,
501 OOMPH_EXCEPTION_LOCATION);
525 double**
const v_values = vec.
values();
526 const unsigned n_row_local = this->
nrow_local();
527 const unsigned n_vector = this->
nvector();
528 for(
unsigned v=0;v<n_vector;++v)
530 for(
unsigned i=0;
i<n_row_local;++
i)
549 std::ostringstream error_message;
550 error_message <<
"This vector must be setup.";
552 OOMPH_CURRENT_FUNCTION,
553 OOMPH_EXCEPTION_LOCATION);
558 std::ostringstream error_message;
559 error_message <<
"The vector v must be setup.";
561 OOMPH_CURRENT_FUNCTION,
562 OOMPH_EXCEPTION_LOCATION);
567 std::ostringstream error_message;
568 error_message <<
"The vector v and this vector must have the same " 571 OOMPH_CURRENT_FUNCTION,
572 OOMPH_EXCEPTION_LOCATION);
577 double** v_values = vec.
values();
578 const unsigned n_vector = this->
nvector();
579 const unsigned n_row_local = this->
nrow_local();
580 for(
unsigned v=0; v<n_vector;++v)
582 for(
unsigned i=0;
i<n_row_local;++
i)
596 std::ostringstream error_message;
597 error_message <<
"This vector must be setup.";
599 OOMPH_CURRENT_FUNCTION,
600 OOMPH_EXCEPTION_LOCATION);
605 std::ostringstream error_message;
606 error_message <<
"The vector v must be setup.";
608 OOMPH_CURRENT_FUNCTION,
609 OOMPH_EXCEPTION_LOCATION);
614 std::ostringstream error_message;
615 error_message <<
"The vector v and this vector must have the same " 618 OOMPH_CURRENT_FUNCTION,
619 OOMPH_EXCEPTION_LOCATION);
623 double** v_values = vec.
values();
624 const unsigned n_vector = this->
nvector();
625 const unsigned n_row_local = this->
nrow_local();
626 for(
unsigned v=0;v<n_vector;++v)
628 for(
unsigned i=0;
i<n_row_local;++
i)
642 std::ostringstream error_message;
643 error_message <<
"This vector must be setup.";
645 OOMPH_CURRENT_FUNCTION,
646 OOMPH_EXCEPTION_LOCATION);
649 const unsigned n_vector = this->
nvector();
650 const unsigned n_row_local = this->
nrow_local();
651 for(
unsigned v=0;v<n_vector;++v)
653 for(
unsigned i=0;
i<n_row_local;++
i)
688 unsigned n_vector = this->
nvector();
706 unsigned nrow = this->
nrow();
709 int* dist_first_row =
new int[nproc];
710 int* dist_nrow_local =
new int[nproc];
711 for (
int p = 0; p < nproc; p++)
718 temp =
new double*[n_vector];
719 double* temp_value =
new double[nrow*n_vector];
720 for(
unsigned v=0;v<n_vector;v++)
722 temp[v] = &temp_value[v*
nrow];
727 for(
unsigned v=0;v<n_vector;++v)
729 MPI_Allgatherv(
Values[v],nrow_local,MPI_DOUBLE,
730 temp[v],dist_nrow_local,dist_first_row,
736 delete[] dist_first_row;
737 delete[] dist_nrow_local;
748 for (
unsigned i = 0;
i <
nrow;
i++)
751 for(
unsigned v = 0; v<n_vector; v++)
753 outfile << temp[v][
i] <<
" ";
774 std::ofstream some_file;
775 some_file.open(filename.c_str());
788 std::ostringstream error_message;
789 error_message <<
"This vector must be setup.";
791 OOMPH_CURRENT_FUNCTION,
792 OOMPH_EXCEPTION_LOCATION);
796 std::ostringstream error_message;
797 error_message <<
"The input vector be setup.";
799 OOMPH_CURRENT_FUNCTION,
800 OOMPH_EXCEPTION_LOCATION);
804 std::ostringstream error_message;
805 error_message <<
"The distribution of this vector and the vector vec " 806 <<
"must be the same." 810 OOMPH_CURRENT_FUNCTION,
811 OOMPH_EXCEPTION_LOCATION);
817 int n_vector = this->
nvector();
819 for(
int v=0;v<n_vector;v++)
823 const double* vec_values_pt = vec.
values(v);
826 n[v] +=
Values[v][
i]*vec_values_pt[
i];
832 double n2[n_vector];
for(
int v=0;v<n_vector;v++) {n2[v] = n[v];}
837 MPI_Allreduce(&n,&n2,n_vector,MPI_DOUBLE,MPI_SUM,
840 for(
int v=0;v<n_vector;v++) {n[v] = n2[v];}
843 result.resize(n_vector);
844 for(
int v=0;v<n_vector;v++) {result[v] = n[v];}
848 void norm(std::vector<double> &result)
const 854 std::ostringstream error_message;
855 error_message <<
"This vector must be setup.";
857 OOMPH_CURRENT_FUNCTION,
858 OOMPH_EXCEPTION_LOCATION);
864 int n_vector = this->
nvector();
866 for(
int v=0;v<n_vector;v++)
877 double n2[n_vector];
for(
int v=0;v<n_vector;v++) {n2[v] = n[v];}
881 MPI_Allreduce(&n,&n2,n_vector,MPI_DOUBLE,MPI_SUM,
884 for(
int v=0;v<n_vector;v++) {n[v] = n2[v];}
888 result.resize(n_vector);
889 for(
int v=0;v<n_vector;v++) {result[v] = sqrt(n[v]);}
936 const unsigned n_vector = this->
nvector();
939 for(
unsigned v=0;v<n_vector;v++)
double ** values() const
access function to the underlying values (const version)
void shallow_build(const unsigned &n_vector, const LinearAlgebraDistribution *const &dist_pt)
Build the storage for pointers to vectors with a given distribution, but do not populate the pointers...
unsigned Nvector
The number of vectors.
void operator+=(DoubleMultiVector vec)
+= operator
bool operator==(const DoubleMultiVector &vec)
== operator
void redistribute(const LinearAlgebraDistribution *const &dist_pt)
Allows are external data to be used by this vector. WARNING: The size of the external data must corre...
double * values(const unsigned &i) const
access function to the i-th vector's data (const version)
void output(std::ostream &outfile) const
output the contents of the vector
double ** values()
access function to the underlying values
DoubleMultiVector()
Constructor for an uninitialized DoubleMultiVector.
void shallow_build(const unsigned &n_vector, const LinearAlgebraDistribution &dist)
Build the storage for pointers to vectors with a given distribution, but do not populate the pointers...
DoubleMultiVector(const unsigned &n_vector, const LinearAlgebraDistribution *const &dist_pt, const double &v=0.0)
Constructor. Assembles a DoubleMultiVector consisting of n_vector vectors, each with a prescribed dis...
OomphCommunicator * communicator_pt() const
const access to the communicator pointer
double & operator()(int v, int i) const
[] access function to the (local) values of the v-th vector
DoubleMultiVector(const DoubleMultiVector &new_vector)
Copy constructor.
void clear()
initialise the vector with coefficient from the vector v. Note: The vector v must be of length ...
void setup_doublevector_representation()
compute the A-norm using the matrix at matrix_pt
const DoubleVector & doublevector(const unsigned &i) const
access to the DoubleVector representation (const version)
void operator*=(const double &scalar_value)
Multiply by a scalar.
void build(const unsigned &n_vector, const LinearAlgebraDistribution *const &dist_pt, const double &initial_value=0.0)
Assembles a DoubleMultiVector with n_vector vectors, each with a distribution dist, if v is specified each element is set to v, otherwise each element is set to 0.0.
DoubleMultiVector(const DoubleMultiVector &old_vector, const Teuchos::Range1D &index, const bool &deep_copy=true)
Constructor that builds a multivector from selected columns of the input multivector and the provided...
bool Built
indicates that the vector has been built and is usable
bool distribution_built() const
bool distributed() const
distribution is serial or distributed
DoubleVector & doublevector(const unsigned &i)
access to the DoubleVector representatoin
DoubleMultiVector(const DoubleMultiVector &old_vector, const std::vector< int > &index, const bool &deep_copy=true)
Constructor that builds a multivector from selected columns of the input multivector. The boolean controls whether it is a shallow or deep copy (default deep)
Describes the distribution of a distributable linear algebra type object. Typically this is a contain...
DoubleMultiVector(const unsigned &n_vector, const DoubleMultiVector &old_vector, const double &initial_value=0.0)
Constructor. Build a multivector using the same distribution of the input vector with n_vector column...
void initialise(const double &initial_value)
initialise the whole vector with value v
void deep_copy(const CRDoubleMatrix *const in_matrix_pt, CRDoubleMatrix &out_matrix)
Create a deep copy of the matrix pointed to by in_matrix_pt.
Base class for any linear algebra object that is distributable. Just contains storage for the LinearA...
void norm(std::vector< double > &result) const
compute the 2 norm of this vector
void output(std::string filename)
output the contents of the vector
~DoubleMultiVector()
Destructor - just calls this->clear() to delete the distribution and data.
unsigned first_row() const
access function for the first row on this processor
void build(const unsigned &n_vector, const LinearAlgebraDistribution &dist, const double &initial_value=0.0)
Assembles a DoubleMultiVector with n_vector vectors, a distribution dist, if v is specified each elem...
void clear_distribution()
clear the distribution of this distributable linear algebra object
DoubleMultiVector(const unsigned &n_vector, const LinearAlgebraDistribution &dist, const double &v=0.0)
Constructor. Assembles a DoubleMultiVector consisting of n_vector vectors, each with a prescribed dis...
bool Internal_values
Boolean flag to indicate whether the vector's data (values_pt) is owned by this vector.
void shallow_build(const DoubleMultiVector &old_vector)
Provide a (shallow) copy of the old vector.
void build(const DoubleMultiVector &old_vector)
Provides a (deep) copy of the old_vector.
A multi vector in the mathematical sense, initially developed for linear algebra type applications...
void dot(const DoubleMultiVector &vec, std::vector< double > &result) const
compute the 2 norm of this vector
unsigned nrow() const
access function to the number of global rows.
void operator=(const DoubleMultiVector &old_vector)
assignment operator (deep copy)
std::string string(const unsigned &i)
Return the i-th string or "" if the relevant string hasn't been defined.
void build_distribution(const LinearAlgebraDistribution *const dist_pt)
setup the distribution of this distributable linear algebra object
unsigned nrow_local() const
access function for the num of local rows on this processor.
Vector< DoubleVector > Internal_doublevector
Need a vector of DoubleVectors to interface with our linear solvers.
A vector in the mathematical sense, initially developed for linear algebra type applications. If MPI then this vector can be distributed - its distribution is described by the LinearAlgebraDistribution object at Distribution_pt. Data is stored in a C-style pointer vector (double*)
unsigned nvector() const
Return the number of vectors.
LinearAlgebraDistribution * distribution_pt() const
access to the LinearAlgebraDistribution
void operator-=(DoubleMultiVector vec)
-= operator
double * values(const unsigned &i)
access function to the i-th vector's data