crdoublematrix_copy_constructor.cc File Reference
#include "generic.h"

Functions

template<typename myType >
void construct_vector (const myType given_array[], const unsigned given_arraysize, Vector< myType > &result_vector)
 
template<typename myType >
void output_vector (const Vector< myType > &given_vector)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ construct_vector()

template<typename myType >
void construct_vector ( const myType  given_array[],
const unsigned  given_arraysize,
Vector< myType > &  result_vector 
)
38 {
39  // Clear and reserve the required memory.
40  result_vector.clear();
41 
42  std::copy(given_array,
43  given_array + given_arraysize,
44  std::back_inserter(result_vector));
45 }
EIGEN_BLAS_FUNC() copy(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:32

References copy().

Referenced by main().

◆ main()

int main ( int argc  ,
char argv[] 
)

Driver code: Testing CRDoubleMatrixHelpers::add(...)

The script validate.sh should run this self test on 1, 2, 3 and 4 cores.

65 {
66 #ifdef OOMPH_HAS_MPI
67  // Initialise MPI
68  MPI_Helpers::init(argc,argv);
69 #endif
70 
71  // Get the global oomph-lib communicator
72  const OomphCommunicator* const comm_pt = MPI_Helpers::communicator_pt();
73 
74  // my rank and number of processors.
75  // This is used later for putting the data.
76  const unsigned my_rank = comm_pt->my_rank();
77  const unsigned nproc = comm_pt->nproc();
78 
79  // Matrix 1
80  // [1 2 0 0 0
81  // 3 0 4 0 0
82  // 0 0 0 5 6
83  // 7 8 0 0 9
84  // 0 0 0 0 0]
85  //
86  // values = 1 2 3 4 5 6 7 8 9
87  // col i = 0 1 0 2 3 4 0 1 4
88  // row s = 0 2 4 6 9 9
89  unsigned nrow_global_t1m1 = 5;
90  unsigned ncol_t1m1 = 5;
91  unsigned nnz_t1m1 = 9;
92  Vector<double> val_t1m1;
93  Vector<int> col_i_t1m1;
94  Vector<int> row_s_t1m1;
95 
96  double val_array_t1m1[] = {1,2,3,4,5,6,7,8,9};
97  int col_i_array_t1m1[] = {0,1,0,2,3,4,0,1,4};
98  int row_s_array_t1m1[] = {0,2,4,6,9,9};
99 
100  construct_vector(val_array_t1m1,nnz_t1m1,val_t1m1);
101  construct_vector(col_i_array_t1m1,nnz_t1m1,col_i_t1m1);
102  construct_vector(row_s_array_t1m1,nrow_global_t1m1+1,row_s_t1m1);
103 
104  CRDoubleMatrix mat_t1m1;
106  nrow_global_t1m1,ncol_t1m1,comm_pt,
107  val_t1m1,col_i_t1m1,row_s_t1m1,mat_t1m1);
108 
109  std::ostringstream mat_t1m1_stream;
110  mat_t1m1_stream << "t1m1_NP"<<nproc<<"R"<<my_rank;
111  mat_t1m1.sparse_indexed_output(mat_t1m1_stream.str());
112 
113  // Test the copy constructor
114  CRDoubleMatrix copy_of_mat_t1m1(mat_t1m1);
115 
116  std::ostringstream copy_of_mat_t1m1_stream;
117  copy_of_mat_t1m1_stream << "copy_of_t1m1_NP" << nproc << "R" << my_rank;
118  copy_of_mat_t1m1.sparse_indexed_output(copy_of_mat_t1m1_stream.str());
119 
120 
121  // Next matrix, testing non-square matrix where nrow < ncol.
122  // A = [1 2 3 4 5 6
123  // 7 8 9 10 11 12
124  // 13 14 15 16 17 18]
125  unsigned nrow_global_t2m1 = 3;
126  unsigned ncol_t2m1 = 6;
127  unsigned nnz_t2m1 = 18;
128  Vector<double> val_t2m1;
129  Vector<int> col_i_t2m1;
130  Vector<int> row_s_t2m1;
131 
132  double val_array_t2m1[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};
133  int col_i_array_t2m1[] = {0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,5};
134  int row_s_array_t2m1[] = {0,6,12,18};
135 
136  construct_vector(val_array_t2m1,nnz_t2m1,val_t2m1);
137  construct_vector(col_i_array_t2m1,nnz_t2m1,col_i_t2m1);
138  construct_vector(row_s_array_t2m1,nrow_global_t2m1+1,row_s_t2m1);
139 
140  CRDoubleMatrix mat_t2m1;
142  nrow_global_t2m1,ncol_t2m1,comm_pt,
143  val_t2m1,col_i_t2m1,row_s_t2m1,mat_t2m1);
144 
145  std::ostringstream mat_t2m1_stream;
146  mat_t2m1_stream << "t2m1_NP"<<nproc<<"R"<<my_rank;
147  mat_t2m1.sparse_indexed_output(mat_t2m1_stream.str());
148 
149  // Test the copy constructor
150  CRDoubleMatrix copy_of_mat_t2m1(mat_t2m1);
151 
152  std::ostringstream copy_of_mat_t2m1_stream;
153  copy_of_mat_t2m1_stream << "copy_of_t2m1_NP" << nproc << "R" << my_rank;
154  copy_of_mat_t2m1.sparse_indexed_output(copy_of_mat_t2m1_stream.str());
155 
156 
157  // Testing non square matrix where nrow > ncol
158  // A = [1 2 3
159  // 4 5 6
160  // 7 8 9
161  // 10 11 12
162  // 13 14 15
163  // 16 17 18]
164  unsigned nrow_global_t3m1 = 6;
165  unsigned ncol_t3m1 = 3;
166  unsigned nnz_t3m1 = 18;
167  Vector<double> val_t3m1;
168  Vector<int> col_i_t3m1;
169  Vector<int> row_s_t3m1;
170 
171  double val_array_t3m1[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};
172  int col_i_array_t3m1[] = {0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2};
173  int row_s_array_t3m1[] = {0,3,6,9,12,15,18};
174 
175  construct_vector(val_array_t3m1,nnz_t3m1,val_t3m1);
176  construct_vector(col_i_array_t3m1,nnz_t3m1,col_i_t3m1);
177  construct_vector(row_s_array_t3m1,nrow_global_t3m1+1,row_s_t3m1);
178 
179  CRDoubleMatrix mat_t3m1;
181  nrow_global_t3m1,ncol_t3m1,comm_pt,
182  val_t3m1,col_i_t3m1,row_s_t3m1,mat_t3m1);
183 
184  std::ostringstream mat_t3m1_stream;
185  mat_t3m1_stream << "t3m1_NP"<<nproc<<"R"<<my_rank;
186  mat_t3m1.sparse_indexed_output(mat_t3m1_stream.str());
187 
188  // Test the copy constructor
189  CRDoubleMatrix copy_of_mat_t3m1(mat_t3m1);
190 
191  std::ostringstream copy_of_mat_t3m1_stream;
192  copy_of_mat_t3m1_stream << "copy_of_t3m1_NP" << nproc << "R" << my_rank;
193  copy_of_mat_t3m1.sparse_indexed_output(copy_of_mat_t3m1_stream.str());
194 
195 #ifdef OOMPH_HAS_MPI
196  // finalize MPI
197  MPI_Helpers::finalize();
198 #endif
199  return(EXIT_SUCCESS);
200 } // end_of_main
Definition: matrices.h:888
void sparse_indexed_output(std::ostream &outfile, const unsigned &precision=0, const bool &output_bottom_right_zero=false) const
Definition: matrices.h:182
Definition: communicator.h:54
int my_rank() const
my rank
Definition: communicator.h:176
int nproc() const
number of processors
Definition: communicator.h:157
void construct_vector(const myType given_array[], const unsigned given_arraysize, Vector< myType > &result_vector)
Definition: crdoublematrix_copy_constructor.cc:35
void create_uniformly_distributed_matrix(const unsigned &nrow, const unsigned &ncol, const OomphCommunicator *const comm_pt, const Vector< double > &values, const Vector< int > &column_indices, const Vector< int > &row_start, CRDoubleMatrix &matrix_out)
Definition: matrices.cc:3676

References oomph::MPI_Helpers::communicator_pt(), construct_vector(), oomph::CRDoubleMatrixHelpers::create_uniformly_distributed_matrix(), oomph::MPI_Helpers::finalize(), oomph::MPI_Helpers::init(), oomph::OomphCommunicator::my_rank(), oomph::OomphCommunicator::nproc(), and oomph::Matrix< T, MATRIX_TYPE >::sparse_indexed_output().

◆ output_vector()

template<typename myType >
void output_vector ( const Vector< myType > &  given_vector)
50 {
52 
53  for(it = given_vector.begin(); it != given_vector.end(); ++it)
54  {
55  oomph_info << *it << std::endl;
56  }
57 }
OomphInfo oomph_info
Definition: oomph_definitions.cc:319

References oomph::oomph_info.

Referenced by oomph::ODEProblem::output_solution(), oomph::ODEProblem::write_additional_trace_data(), and oomph::MyProblem::write_trace().