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++)
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))
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++)
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,"
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.";
564 std::ostringstream error_message;
565 error_message <<
"The vector v must be setup.";
573 std::ostringstream error_message;
574 error_message <<
"The vector v and this vector must have the same "
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.";
611 std::ostringstream error_message;
612 error_message <<
"The vector v must be setup.";
620 std::ostringstream error_message;
621 error_message <<
"The vector v and this vector must have the same "
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.";
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;
815 std::ostringstream error_message;
816 error_message <<
"This vector must be setup.";
823 std::ostringstream error_message;
824 error_message <<
"The input vector be setup.";
831 std::ostringstream error_message;
832 error_message <<
"The distribution of this vector and the vector vec "
833 <<
"must be the same."
844 int n_vector = this->
nvector();
846 for (
int v = 0;
v < n_vector;
v++)
850 const double* vec_values_pt = vec.
values(
v);
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.";
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++)
990 const unsigned n_vector = this->
nvector();
993 for (
unsigned v = 0;
v < n_vector;
v++)
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
float * p
Definition: Tutorial_Map_using.cpp:9
Definition: linear_algebra_distribution.h:435
void clear_distribution()
Definition: linear_algebra_distribution.h:522
bool distributed() const
distribution is serial or distributed
Definition: linear_algebra_distribution.h:493
LinearAlgebraDistribution * distribution_pt() const
access to the LinearAlgebraDistribution
Definition: linear_algebra_distribution.h:457
unsigned nrow() const
access function to the number of global rows.
Definition: linear_algebra_distribution.h:463
bool distribution_built() const
Definition: linear_algebra_distribution.h:500
unsigned nrow_local() const
access function for the num of local rows on this processor.
Definition: linear_algebra_distribution.h:469
unsigned first_row() const
access function for the first row on this processor
Definition: linear_algebra_distribution.h:481
void build_distribution(const LinearAlgebraDistribution *const dist_pt)
Definition: linear_algebra_distribution.h:507
Definition: double_multi_vector.h:56
DoubleMultiVector(const unsigned &n_vector, const LinearAlgebraDistribution &dist, const double &v=0.0)
Definition: double_multi_vector.h:81
void setup_doublevector_representation()
compute the A-norm using the matrix at matrix_pt
Definition: double_multi_vector.h:988
void output(std::ostream &outfile) const
output the contents of the vector
Definition: double_multi_vector.h:704
DoubleMultiVector(const unsigned &n_vector, const LinearAlgebraDistribution *const &dist_pt, const double &v=0.0)
Definition: double_multi_vector.h:68
void redistribute(const LinearAlgebraDistribution *const &dist_pt)
Definition: double_multi_vector.cc:37
double * values(const unsigned &i)
access function to the i-th vector's data
Definition: double_multi_vector.h:680
unsigned Nvector
The number of vectors.
Definition: double_multi_vector.h:1005
void shallow_build(const unsigned &n_vector, const LinearAlgebraDistribution &dist)
Definition: double_multi_vector.h:243
DoubleMultiVector(const unsigned &n_vector, const DoubleMultiVector &old_vector, const double &initial_value=0.0)
Definition: double_multi_vector.h:93
double ** values() const
access function to the underlying values (const version)
Definition: double_multi_vector.h:674
void build(const unsigned &n_vector, const LinearAlgebraDistribution *const &dist_pt, const double &initial_value=0.0)
Definition: double_multi_vector.h:323
DoubleMultiVector(const DoubleMultiVector &old_vector, const std::vector< int > &index, const bool &deep_copy=true)
Definition: double_multi_vector.h:105
DoubleMultiVector()
Constructor for an uninitialized DoubleMultiVector.
Definition: double_multi_vector.h:59
void operator*=(const double &scalar_value)
Multiply by a scalar.
Definition: double_multi_vector.h:642
~DoubleMultiVector()
Definition: double_multi_vector.h:198
double ** Values
Definition: double_multi_vector.h:1002
Vector< DoubleVector > Internal_doublevector
Need a vector of DoubleVectors to interface with our linear solvers.
Definition: double_multi_vector.h:1015
void initialise(const double &initial_value)
initialise the whole vector with value v
Definition: double_multi_vector.h:364
double & operator()(int v, int i) const
[] access function to the (local) values of the v-th vector
Definition: double_multi_vector.h:484
void clear()
wipes the DoubleVector
Definition: double_multi_vector.h:387
void build(const unsigned &n_vector, const LinearAlgebraDistribution &dist, const double &initial_value=0.0)
Definition: double_multi_vector.h:313
void operator=(const DoubleMultiVector &old_vector)
assignment operator (deep copy)
Definition: double_multi_vector.h:204
double * values(const unsigned &i) const
access function to the i-th vector's data (const version)
Definition: double_multi_vector.h:686
bool Built
indicates that the vector has been built and is usable
Definition: double_multi_vector.h:1012
void dot(const DoubleMultiVector &vec, std::vector< double > &result) const
compute the 2 norm of this vector
Definition: double_multi_vector.h:809
void norm(std::vector< double > &result) const
compute the 2 norm of this vector
Definition: double_multi_vector.h:889
void shallow_build(const DoubleMultiVector &old_vector)
Provide a (shallow) copy of the old vector.
Definition: double_multi_vector.h:217
DoubleVector & doublevector(const unsigned &i)
access to the DoubleVector representatoin
Definition: double_multi_vector.h:692
bool operator==(const DoubleMultiVector &vec)
== operator
Definition: double_multi_vector.h:514
double ** values()
access function to the underlying values
Definition: double_multi_vector.h:668
void operator-=(DoubleMultiVector vec)
-= operator
Definition: double_multi_vector.h:596
void operator+=(DoubleMultiVector vec)
+= operator
Definition: double_multi_vector.h:549
const DoubleVector & doublevector(const unsigned &i) const
access to the DoubleVector representation (const version)
Definition: double_multi_vector.h:698
void shallow_build(const unsigned &n_vector, const LinearAlgebraDistribution *const &dist_pt)
Definition: double_multi_vector.h:252
bool built() const
Definition: double_multi_vector.h:413
bool Internal_values
Definition: double_multi_vector.h:1009
void output(std::string filename)
output the contents of the vector
Definition: double_multi_vector.h:798
unsigned nvector() const
Return the number of vectors.
Definition: double_multi_vector.h:211
DoubleMultiVector(const DoubleMultiVector &new_vector)
Copy constructor.
Definition: double_multi_vector.h:184
void build(const DoubleMultiVector &old_vector)
Provides a (deep) copy of the old_vector.
Definition: double_multi_vector.h:281
Definition: double_vector.h:58
Definition: linear_algebra_distribution.h:64
OomphCommunicator * communicator_pt() const
const access to the communicator pointer
Definition: linear_algebra_distribution.h:335
bool built() const
Definition: linear_algebra_distribution.h:342
int nproc() const
number of processors
Definition: communicator.h:157
Definition: oomph_definitions.h:222
Definition: oomph-lib/src/generic/Vector.h:58
string filename
Definition: MergeRestartFiles.py:39
int error
Definition: calibrate.py:297
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.
Definition: matrices.h:3490
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
Definition: AnisotropicHookean.h:10
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86
std::vector< float > Values
Definition: sparse_setter.cpp:48