26 #ifndef OOMPH_DOUBLE_MULTI_VECTOR_CLASS_HEADER
27 #define OOMPH_DOUBLE_MULTI_VECTOR_CLASS_HEADER
31 #include <oomph-lib-config.h>
42 #ifdef OOMPH_HAS_TRILINOS
43 #include "Teuchos_Range1D.hpp"
70 const double& v = 0.0)
73 this->
build(n_vector, dist_pt, v);
83 const double& v = 0.0)
86 this->
build(n_vector, dist, v);
95 const double& initial_value = 0.0)
106 const std::vector<int>& index,
111 unsigned n_vector = index.size();
117 const unsigned n_row_local = this->
nrow_local();
118 for (
unsigned v = 0; v < n_vector; v++)
120 for (
unsigned i = 0;
i < n_row_local;
i++)
122 Values[v][
i] = old_vector(index[v],
i);
131 for (
unsigned v = 0; v < n_vector; ++v)
139 #ifdef OOMPH_HAS_TRILINOS
145 const Teuchos::Range1D& index,
150 unsigned n_vector = index.size();
156 const unsigned n_row_local = this->
nrow_local();
157 unsigned range_index = index.lbound();
158 for (
unsigned v = 0; v < n_vector; v++)
160 for (
unsigned i = 0;
i < n_row_local;
i++)
162 Values[v][
i] = old_vector(range_index,
i);
172 unsigned range_index = index.lbound();
173 for (
unsigned v = 0; v < n_vector; v++)
191 this->
build(new_vector);
206 this->
build(old_vector);
220 if (!(*
this == old_vector))
233 for (
unsigned v = 0; v <
Nvector; ++v)
265 if (dist_pt->
built())
270 Values =
new double*[n_vector];
284 if (!(*
this == old_vector))
298 double**
const old_vector_values = old_vector.
values();
299 for (
unsigned i = 0;
i < n_row_local;
i++)
301 for (
unsigned v = 0; v <
Nvector; v++)
303 Values[v][
i] = old_vector_values[v][
i];
313 void build(
const unsigned& n_vector,
315 const double& initial_value = 0.0)
317 this->
build(n_vector, &dist, initial_value);
323 void build(
const unsigned& n_vector,
325 const double& initial_value = 0.0)
337 if (dist_pt->
built())
342 Values =
new double*[n_vector];
344 const unsigned n_row_local = this->
nrow_local();
345 double*
values =
new double[n_row_local * n_vector];
347 for (
unsigned v = 0; v < n_vector; v++)
350 for (
unsigned i = 0;
i < n_row_local;
i++)
368 const unsigned n_vector = this->
Nvector;
369 const unsigned n_row_local = this->
nrow_local();
372 for (
unsigned v = 0; v < n_vector; v++)
374 for (
unsigned i = 0;
i < n_row_local;
i++)
486 #ifdef RANGE_CHECKING
487 std::ostringstream error_message;
491 error_message <<
"Range Error: Vector " << v
492 <<
"is not in the range (0," <<
Nvector - 1 <<
")";
498 error_message <<
"Range Error: " <<
i <<
" is not in the range (0,"
506 OOMPH_CURRENT_FUNCTION,
507 OOMPH_EXCEPTION_LOCATION);
517 if (vec.
built() && !this->built())
521 else if (!vec.
built() && this->built())
525 else if (!vec.
built() && !this->built())
531 double**
const v_values = vec.
values();
532 const unsigned n_row_local = this->
nrow_local();
533 const unsigned n_vector = this->
nvector();
534 for (
unsigned v = 0; v < n_vector; ++v)
536 for (
unsigned i = 0;
i < n_row_local; ++
i)
555 std::ostringstream error_message;
556 error_message <<
"This vector must be setup.";
558 OOMPH_CURRENT_FUNCTION,
559 OOMPH_EXCEPTION_LOCATION);
564 std::ostringstream error_message;
565 error_message <<
"The vector v must be setup.";
567 OOMPH_CURRENT_FUNCTION,
568 OOMPH_EXCEPTION_LOCATION);
573 std::ostringstream error_message;
574 error_message <<
"The vector v and this vector must have the same "
577 OOMPH_CURRENT_FUNCTION,
578 OOMPH_EXCEPTION_LOCATION);
583 double** v_values = vec.
values();
584 const unsigned n_vector = this->
nvector();
585 const unsigned n_row_local = this->
nrow_local();
586 for (
unsigned v = 0; v < n_vector; ++v)
588 for (
unsigned i = 0;
i < n_row_local; ++
i)
602 std::ostringstream error_message;
603 error_message <<
"This vector must be setup.";
605 OOMPH_CURRENT_FUNCTION,
606 OOMPH_EXCEPTION_LOCATION);
611 std::ostringstream error_message;
612 error_message <<
"The vector v must be setup.";
614 OOMPH_CURRENT_FUNCTION,
615 OOMPH_EXCEPTION_LOCATION);
620 std::ostringstream error_message;
621 error_message <<
"The vector v and this vector must have the same "
624 OOMPH_CURRENT_FUNCTION,
625 OOMPH_EXCEPTION_LOCATION);
629 double** v_values = vec.
values();
630 const unsigned n_vector = this->
nvector();
631 const unsigned n_row_local = this->
nrow_local();
632 for (
unsigned v = 0; v < n_vector; ++v)
634 for (
unsigned i = 0;
i < n_row_local; ++
i)
648 std::ostringstream error_message;
649 error_message <<
"This vector must be setup.";
651 OOMPH_CURRENT_FUNCTION,
652 OOMPH_EXCEPTION_LOCATION);
655 const unsigned n_vector = this->
nvector();
656 const unsigned n_row_local = this->
nrow_local();
657 for (
unsigned v = 0; v < n_vector; ++v)
659 for (
unsigned i = 0;
i < n_row_local; ++
i)
710 unsigned n_vector = this->
nvector();
728 unsigned nrow = this->
nrow();
731 int* dist_first_row =
new int[nproc];
732 int* dist_nrow_local =
new int[nproc];
733 for (
int p = 0; p < nproc; p++)
740 temp =
new double*[n_vector];
741 double* temp_value =
new double[
nrow * n_vector];
742 for (
unsigned v = 0; v < n_vector; v++)
744 temp[v] = &temp_value[v *
nrow];
750 for (
unsigned v = 0; v < n_vector; ++v)
764 delete[] dist_first_row;
765 delete[] dist_nrow_local;
776 for (
unsigned i = 0;
i <
nrow;
i++)
779 for (
unsigned v = 0; v < n_vector; v++)
781 outfile << temp[v][
i] <<
" ";
801 std::ofstream some_file;
802 some_file.open(filename.c_str());
815 std::ostringstream error_message;
816 error_message <<
"This vector must be setup.";
818 OOMPH_CURRENT_FUNCTION,
819 OOMPH_EXCEPTION_LOCATION);
823 std::ostringstream error_message;
824 error_message <<
"The input vector be setup.";
826 OOMPH_CURRENT_FUNCTION,
827 OOMPH_EXCEPTION_LOCATION);
831 std::ostringstream error_message;
832 error_message <<
"The distribution of this vector and the vector vec "
833 <<
"must be the same."
837 OOMPH_CURRENT_FUNCTION,
838 OOMPH_EXCEPTION_LOCATION);
844 int n_vector = this->
nvector();
846 for (
int v = 0; v < n_vector; v++)
850 const double* vec_values_pt = vec.
values(v);
853 n[v] +=
Values[v][
i] * vec_values_pt[
i];
860 for (
int v = 0; v < n_vector; v++)
875 for (
int v = 0; v < n_vector; v++)
881 result.resize(n_vector);
882 for (
int v = 0; v < n_vector; v++)
889 void norm(std::vector<double>& result)
const
895 std::ostringstream error_message;
896 error_message <<
"This vector must be setup.";
898 OOMPH_CURRENT_FUNCTION,
899 OOMPH_EXCEPTION_LOCATION);
905 int n_vector = this->
nvector();
907 for (
int v = 0; v < n_vector; v++)
919 for (
int v = 0; v < n_vector; v++)
933 for (
int v = 0; v < n_vector; v++)
940 result.resize(n_vector);
941 for (
int v = 0; v < n_vector; v++)
943 result[v] = sqrt(n[v]);
990 const unsigned n_vector = this->
nvector();
993 for (
unsigned v = 0; v < n_vector; v++)
Base class for any linear algebra object that is distributable. Just contains storage for the LinearA...
void clear_distribution()
clear the distribution of this distributable linear algebra object
bool distributed() const
distribution is serial or distributed
LinearAlgebraDistribution * distribution_pt() const
access to the LinearAlgebraDistribution
unsigned nrow() const
access function to the number of global rows.
bool distribution_built() const
if the communicator_pt is null then the distribution is not setup then false is returned,...
unsigned nrow_local() const
access function for the num of local rows on this processor.
unsigned first_row() const
access function for the first row on this processor
void build_distribution(const LinearAlgebraDistribution *const dist_pt)
setup the distribution of this distributable linear algebra object
A multi vector in the mathematical sense, initially developed for linear algebra type applications....
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...
void setup_doublevector_representation()
compute the A-norm using the matrix at matrix_pt
void output(std::ostream &outfile) const
output the contents of the vector
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...
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)
access function to the i-th vector's data
unsigned Nvector
The number of vectors.
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 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...
double ** values() const
access function to the underlying values (const version)
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,...
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....
DoubleMultiVector()
Constructor for an uninitialized DoubleMultiVector.
void operator*=(const double &scalar_value)
Multiply by a scalar.
~DoubleMultiVector()
Destructor - just calls this->clear() to delete the distribution and data.
double ** Values
the local data, need a pointer to a pointer so that the individual vectors can be extracted
Vector< DoubleVector > Internal_doublevector
Need a vector of DoubleVectors to interface with our linear solvers.
void initialise(const double &initial_value)
initialise the whole vector with value v
double & operator()(int v, int i) const
[] access function to the (local) values of the v-th vector
void clear()
initialise the vector with coefficient from the vector v. Note: The vector v must be of length
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...
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...
void operator=(const DoubleMultiVector &old_vector)
assignment operator (deep copy)
double * values(const unsigned &i) const
access function to the i-th vector's data (const version)
bool Built
indicates that the vector has been built and is usable
void dot(const DoubleMultiVector &vec, std::vector< double > &result) const
compute the 2 norm of this vector
void norm(std::vector< double > &result) const
compute the 2 norm of this vector
void shallow_build(const DoubleMultiVector &old_vector)
Provide a (shallow) copy of the old vector.
DoubleVector & doublevector(const unsigned &i)
access to the DoubleVector representatoin
bool operator==(const DoubleMultiVector &vec)
== operator
double ** values()
access function to the underlying values
void operator-=(DoubleMultiVector vec)
-= operator
void operator+=(DoubleMultiVector vec)
+= operator
const DoubleVector & doublevector(const unsigned &i) const
access to the DoubleVector representation (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...
bool Internal_values
Boolean flag to indicate whether the vector's data (values_pt) is owned by this vector.
void output(std::string filename)
output the contents of the vector
unsigned nvector() const
Return the number of vectors.
DoubleMultiVector(const DoubleMultiVector &new_vector)
Copy constructor.
void build(const DoubleMultiVector &old_vector)
Provides a (deep) copy of the old_vector.
A vector in the mathematical sense, initially developed for linear algebra type applications....
Describes the distribution of a distributable linear algebra type object. Typically this is a contain...
OomphCommunicator * communicator_pt() const
const access to the communicator pointer
bool built() const
if the communicator_pt is null then the distribution is not setup then false is returned,...
An OomphLibError object which should be thrown when an run-time error is encountered....
A slight extension to the standard template vector class so that we can include "graceful" array rang...
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.
std::string string(const unsigned &i)
Return the i-th string or "" if the relevant string hasn't been defined.
//////////////////////////////////////////////////////////////////// ////////////////////////////////...