oomph::DenseComplexMatrix Class Reference

#include <complex_matrices.h>

+ Inheritance diagram for oomph::DenseComplexMatrix:

Public Member Functions

 DenseComplexMatrix ()
 Empty constructor, simply assign the lengths N and M to 0. More...
 
 DenseComplexMatrix (const unsigned long &n)
 Constructor to build a square n by n matrix. More...
 
 DenseComplexMatrix (const unsigned long &n, const unsigned long &m)
 Constructor to build a matrix with n rows and m columns. More...
 
 DenseComplexMatrix (const unsigned long &n, const unsigned long &m, const std::complex< double > &initial_val)
 
 DenseComplexMatrix (const DenseComplexMatrix &matrix)=delete
 Broken copy constructor. More...
 
void operator= (const DenseComplexMatrix &)=delete
 Broken assignment operator. More...
 
unsigned long nrow () const
 Return the number of rows of the matrix. More...
 
unsigned long ncol () const
 Return the number of columns of the matrix. More...
 
std::complex< doubleoperator() (const unsigned long &i, const unsigned long &j) const
 
std::complex< double > & operator() (const unsigned long &i, const unsigned long &j)
 
virtual ~DenseComplexMatrix ()
 Destructor, delete the storage for Index vector and LU storage (if any) More...
 
int ludecompose ()
 
void lubksub (Vector< std::complex< double >> &rhs)
 Back substitute an LU decomposed matrix. More...
 
void residual (const Vector< std::complex< double >> &x, const Vector< std::complex< double >> &rhs, Vector< std::complex< double >> &residual)
 Find the residual of Ax=b, i.e. r=b-Ax. More...
 
void multiply (const Vector< std::complex< double >> &x, Vector< std::complex< double >> &soln)
 Multiply the matrix by the vector x: soln=Ax. More...
 
void multiply_transpose (const Vector< std::complex< double >> &x, Vector< std::complex< double >> &soln)
 Multiply the transposed matrix by the vector x: soln=A^T x. More...
 
- Public Member Functions inherited from oomph::ComplexMatrixBase
 ComplexMatrixBase ()
 (Empty) constructor. More...
 
 ComplexMatrixBase (const ComplexMatrixBase &matrix)=delete
 Broken copy constructor. More...
 
void operator= (const ComplexMatrixBase &)=delete
 Broken assignment operator. More...
 
virtual ~ComplexMatrixBase ()
 virtual (empty) destructor More...
 
virtual void solve (Vector< std::complex< double >> &rhs)
 
virtual void solve (const Vector< std::complex< double >> &rhs, Vector< std::complex< double >> &soln)
 
virtual double max_residual (const Vector< std::complex< double >> &x, const Vector< std::complex< double >> &rhs)
 
- Public Member Functions inherited from oomph::DenseMatrix< std::complex< double > >
 DenseMatrix ()
 Empty constructor, simply assign the lengths N and M to 0. More...
 
 DenseMatrix (const DenseMatrix &source_matrix)
 Copy constructor: Deep copy! More...
 
 DenseMatrix (const unsigned long &n)
 Constructor to build a square n by n matrix. More...
 
 DenseMatrix (const unsigned long &n, const unsigned long &m)
 Constructor to build a matrix with n rows and m columns. More...
 
 DenseMatrix (const unsigned long &n, const unsigned long &m, const std::complex< double > &initial_val)
 
DenseMatrixoperator= (const DenseMatrix &source_matrix)
 Copy assignment. More...
 
std::complex< double > & entry (const unsigned long &i, const unsigned long &j)
 
std::complex< doubleget_entry (const unsigned long &i, const unsigned long &j) const
 
virtual ~DenseMatrix ()
 Destructor, clean up the matrix data. More...
 
unsigned long nrow () const
 Return the number of rows of the matrix. More...
 
unsigned long ncol () const
 Return the number of columns of the matrix. More...
 
void resize (const unsigned long &n)
 
void resize (const unsigned long &n, const unsigned long &m)
 
void resize (const unsigned long &n, const unsigned long &m, const std::complex< double > &initial_value)
 
void initialise (const std::complex< double > &val)
 Initialize all values in the matrix to val. More...
 
void output (std::ostream &outfile) const
 Output function to print a matrix row-by-row to the stream outfile. More...
 
void output (std::string filename) const
 Output function to print a matrix row-by-row to a file. Specify filename. More...
 
void indexed_output (std::ostream &outfile) const
 Indexed output as i,j,a(i,j) More...
 
void indexed_output (std::string filename) const
 
void output_bottom_right_zero_helper (std::ostream &outfile) const
 
void sparse_indexed_output_helper (std::ostream &outfile) const
 Sparse indexed output as i,j,a(i,j) for a(i,j)!=0 only. More...
 
- Public Member Functions inherited from oomph::Matrix< T, MATRIX_TYPE >
 Matrix ()
 (Empty) constructor More...
 
 Matrix (const Matrix &matrix)=delete
 Broken copy constructor. More...
 
void operator= (const Matrix &)=delete
 Broken assignment operator. More...
 
virtual ~Matrix ()
 Virtual (empty) destructor. More...
 
T operator() (const unsigned long &i, const unsigned long &j) const
 
Toperator() (const unsigned long &i, const unsigned long &j)
 
void sparse_indexed_output (std::ostream &outfile, const unsigned &precision=0, const bool &output_bottom_right_zero=false) const
 
void sparse_indexed_output (std::string filename, const unsigned &precision=0, const bool &output_bottom_right_zero=false) const
 

Private Member Functions

void delete_lu_factors ()
 

Private Attributes

Vector< long > * Index
 Pointer to storage for the index of permutations in the LU solve. More...
 
std::complex< double > * LU_factors
 Pointer to storage for the LU decomposition. More...
 
bool Overwrite_matrix_storage
 

Additional Inherited Members

- Protected Member Functions inherited from oomph::Matrix< T, MATRIX_TYPE >
void range_check (const unsigned long &i, const unsigned long &j) const
 
- Protected Attributes inherited from oomph::DenseMatrix< std::complex< double > >
std::complex< double > * Matrixdata
 Internal representation of matrix as a pointer to data. More...
 
unsigned long N
 Number of rows. More...
 
unsigned long M
 Number of columns. More...
 

Detailed Description

Class of matrices containing double complex, and stored as a DenseMatrix<complex<double> >, but with solving functionality inherited from the abstract ComplexMatrix class.

Constructor & Destructor Documentation

◆ DenseComplexMatrix() [1/5]

oomph::DenseComplexMatrix::DenseComplexMatrix ( )
inline

Empty constructor, simply assign the lengths N and M to 0.

175  Index(0),
176  LU_factors(0),
178  {
179  }
bool Overwrite_matrix_storage
Definition: complex_matrices.h:165
Vector< long > * Index
Pointer to storage for the index of permutations in the LU solve.
Definition: complex_matrices.h:158
std::complex< double > * LU_factors
Pointer to storage for the LU decomposition.
Definition: complex_matrices.h:161

◆ DenseComplexMatrix() [2/5]

oomph::DenseComplexMatrix::DenseComplexMatrix ( const unsigned long &  n)
inline

Constructor to build a square n by n matrix.

184  Index(0),
185  LU_factors(0),
187  {
188  }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11

◆ DenseComplexMatrix() [3/5]

oomph::DenseComplexMatrix::DenseComplexMatrix ( const unsigned long &  n,
const unsigned long &  m 
)
inline

Constructor to build a matrix with n rows and m columns.

193  Index(0),
194  LU_factors(0),
196  {
197  }
int * m
Definition: level2_cplx_impl.h:294

◆ DenseComplexMatrix() [4/5]

oomph::DenseComplexMatrix::DenseComplexMatrix ( const unsigned long &  n,
const unsigned long &  m,
const std::complex< double > &  initial_val 
)
inline

Constructor to build a matrix with n rows and m columns, with initial value initial_val

204  : DenseMatrix<std::complex<double>>(n, m, initial_val),
205  Index(0),
206  LU_factors(0),
208  {
209  }

◆ DenseComplexMatrix() [5/5]

oomph::DenseComplexMatrix::DenseComplexMatrix ( const DenseComplexMatrix matrix)
delete

Broken copy constructor.

◆ ~DenseComplexMatrix()

oomph::DenseComplexMatrix::~DenseComplexMatrix ( )
virtual

Destructor, delete the storage for Index vector and LU storage (if any)

Destructor clean up the LU factors that have been allocated.

105  {
106  // Delete the storage for the index vector
107  delete Index;
108 
109  // Delete the pointer to the LU factors
110  delete[] LU_factors;
111 
112  // Null out the vector
113  LU_factors = 0;
114  }

References Index, and LU_factors.

Member Function Documentation

◆ delete_lu_factors()

void oomph::DenseComplexMatrix::delete_lu_factors ( )
private

Function that deletes the storage for the LU_factors, if it is not the same as the matrix storage

Delete the storage that has been allocated for the LU factors, if the matrix data is not itself being overwritten.

88  {
89  // Clean up the LU factor storage, if it has been allocated
90  // and it's not the same as the matrix storage
91  if ((!Overwrite_matrix_storage) && (LU_factors != 0))
92  {
93  // Delete the pointer to the LU factors
94  delete[] LU_factors;
95  // Null out the vector
96  LU_factors = 0;
97  }
98  }

References LU_factors, and Overwrite_matrix_storage.

Referenced by ludecompose().

◆ lubksub()

void oomph::DenseComplexMatrix::lubksub ( Vector< std::complex< double >> &  rhs)
virtual

Back substitute an LU decomposed matrix.

Overload the LU back substitution. Note that the rhs will be overwritten with the solution vector

Reimplemented from oomph::ComplexMatrixBase.

375  {
376 #ifdef PARANOID
377  // Check Matrix is square
378  if (N != M)
379  {
380  throw OomphLibError(
381  "This matrix is not square, the matrix MUST be square!",
384  }
385  // Check that size of rhs=nrow() and index=nrow() are correct!
386  if (rhs.size() != N)
387  {
388  std::ostringstream error_message_stream;
389  error_message_stream << "The rhs vector is not the right size. It is "
390  << rhs.size() << ", it should be " << N << std::endl;
391 
392  throw OomphLibError(error_message_stream.str(),
395  }
396  if (Index == 0)
397  {
398  throw OomphLibError(
399  "Index vector has not been allocated. Have you called ludecompse()\n",
402  }
403  if (Index->size() != N)
404  {
405  std::ostringstream error_message_stream;
406  error_message_stream << "The Index vector is not the right size. It is "
407  << Index->size() << ", it should be " << N
408  << std::endl;
409 
410  throw OomphLibError(error_message_stream.str(),
413  }
414 #endif
415 
416  unsigned long ii = 0;
417  for (unsigned i = 0; i < N; i++)
418  {
419  unsigned long ip = (*Index)[i];
420  std::complex<double> sum = rhs[ip];
421  rhs[ip] = rhs[i];
422 
423  if (ii != 0)
424  {
425  for (unsigned long j = ii - 1; j < i; j++)
426  {
427  sum -= LU_factors[M * i + j] * rhs[j];
428  }
429  }
430  else if (sum != 0.0)
431  {
432  ii = i + 1;
433  }
434  rhs[i] = sum;
435  }
436 
437  // Now do the back substitution
438  for (long i = long(N) - 1; i >= 0; i--)
439  {
440  std::complex<double> sum = rhs[i];
441  for (long j = i + 1; j < long(N); j++)
442  sum -= LU_factors[M * i + j] * rhs[j];
443  rhs[i] = sum / LU_factors[M * i + i];
444  }
445  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
unsigned long N
Number of rows.
Definition: matrices.h:392
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References i, Index, j, LU_factors, oomph::DenseMatrix< std::complex< double > >::N, OOMPH_CURRENT_FUNCTION, and OOMPH_EXCEPTION_LOCATION.

◆ ludecompose()

int oomph::DenseComplexMatrix::ludecompose ( )
virtual

Overload the LU decomposition. For this storage scheme the matrix storage will be over-writeen by its LU decomposition

LU decompose a matrix, over-writing it and recording the pivots numbers in the Index vector. Returns the sign of the determinant.

Reimplemented from oomph::ComplexMatrixBase.

122  {
123 #ifdef PARANOID
124  // Check Matrix is square
125  if (N != M)
126  {
127  throw OomphLibError(
128  "This matrix is not square, the matrix MUST be square!",
131  }
132 #endif
133 
134  // Small constant
135  const double small_number = 1.0e-20;
136 
137  // If the Index vector has not already been allocated,
138  // allocated storage for the index of permutations
139  if (Index == 0)
140  {
141  Index = new Vector<long>;
142  }
143 
144  // Resize the index vector to the correct length
145  Index->resize(N);
146 
147  // Vector scaling stores the implicit scaling of each row
148  Vector<double> scaling(N);
149 
150  // Integer to store the sign that must multiply the determinant as
151  // a consequence of the row/column interchanges
152  int signature = 1;
153 
154  // Loop over rows to get implicit scaling information
155  for (unsigned long i = 0; i < N; i++)
156  {
157  double big = 0.0;
158  for (unsigned long j = 0; j < M; j++)
159  {
160  double tmp = std::abs((*this)(i, j));
161  if (tmp > big) big = tmp;
162  }
163  if (big == 0.0)
164  {
165  throw OomphLibError(
167  }
168  // Save the scaling
169  scaling[i] = 1.0 / big;
170  }
171 
172  // Firsly, we shall delete any previous LU storage.
173  // If the user calls this function twice without changing the matrix
174  // then it is their own inefficiency, not ours (this time).
176 
177  // Now if we're saving the LU factors separately (the default).
179  {
180  // Allocate storage for the LU factors
181  // Assign space for the n rows
182  LU_factors = new std::complex<double>[N * M];
183 
184  // Now we know that memory has been allocated, copy over
185  // the matrix values
186  for (unsigned long i = 0; i < (N * M); i++)
187  {
188  LU_factors[i] = Matrixdata[i];
189  }
190  }
191  // Otherwise the pointer to the LU_factors is the same as the
192  // matrix data
193  else
194  {
196  }
197 
198  // Loop over columns
199  for (unsigned long j = 0; j < M; j++)
200  {
201  // Initialise imax
202  unsigned long imax = 0;
203 
204  for (unsigned long i = 0; i < j; i++)
205  {
206  std::complex<double> sum = LU_factors[M * i + j];
207  for (unsigned long k = 0; k < i; k++)
208  {
209  sum -= LU_factors[M * i + k] * LU_factors[M * k + j];
210  }
211  LU_factors[M * i + j] = sum;
212  }
213 
214  // Initialise search for largest pivot element
215  double largest_entry = 0.0;
216  for (unsigned long i = j; i < N; i++)
217  {
218  std::complex<double> sum = LU_factors[M * i + j];
219  for (unsigned long k = 0; k < j; k++)
220  {
221  sum -= LU_factors[M * i + k] * LU_factors[M * k + j];
222  }
223  LU_factors[M * i + j] = sum;
224  // Set temporary
225  double tmp = scaling[i] * std::abs(sum);
226  if (tmp >= largest_entry)
227  {
228  largest_entry = tmp;
229  imax = i;
230  }
231  }
232 
233  // Test to see if we need to interchange rows
234  if (j != imax)
235  {
236  for (unsigned long k = 0; k < N; k++)
237  {
238  std::complex<double> tmp = LU_factors[M * imax + k];
239  LU_factors[M * imax + k] = LU_factors[M * j + k];
240  LU_factors[M * j + k] = tmp;
241  }
242  // Change the parity of signature
243  signature = -signature;
244  // Interchange scale factor
245  scaling[imax] = scaling[j];
246  }
247 
248  // Set the index
249  (*Index)[j] = imax;
250  if (LU_factors[M * j + j] == 0.0)
251  {
252  LU_factors[M * j + j] = small_number;
253  }
254  // Divide by pivot element
255  if (j != N - 1)
256  {
257  std::complex<double> tmp = 1.0 / LU_factors[M * j + j];
258  for (unsigned long i = j + 1; i < N; i++)
259  {
260  LU_factors[M * i + j] *= tmp;
261  }
262  }
263 
264  } // End of loop over columns
265 
266 
267  // Now multiply all the diagonal terms together to get the determinant
268  // Note that we need to use the mantissa, exponent formulation to
269  // avoid underflow errors. This is way more tedious in complex arithmetic.
270  std::complex<double> determinant_mantissa(1.0, 0.0);
271  std::complex<int> determinant_exponent(0, 0);
272  for (unsigned i = 0; i < N; i++)
273  {
274  // Get the next entry in mantissa exponent form
275  std::complex<double> entry;
276  int iexp_real = 0, iexp_imag = 0;
277  entry =
278  std::complex<double>(frexp(LU_factors[M * i + i].real(), &iexp_real),
279  frexp(LU_factors[M * i + i].imag(), &iexp_imag));
280 
281  // Now calculate the four terms that contribute to the real
282  // and imaginary parts
283  // i.e. A + Bi * C + Di = AC - BD + i(AD + BC)
284  double temp_mantissa[4];
285  int temp_exp[4];
286 
287  // Get the first contribution to the real part, AC
288  temp_mantissa[0] = determinant_mantissa.real() * entry.real();
289  temp_exp[0] = determinant_exponent.real() + iexp_real;
290  // Get the second contribution to the real part, DB
291  temp_mantissa[1] = determinant_mantissa.imag() * entry.imag();
292  temp_exp[1] = determinant_exponent.imag() + iexp_imag;
293 
294  // Get the first contribution to the imaginary part, AD
295  temp_mantissa[2] = determinant_mantissa.real() * entry.imag();
296  temp_exp[2] = determinant_exponent.real() + iexp_imag;
297  // Get the second contribution to the imaginary part, BC
298  temp_mantissa[3] = determinant_mantissa.imag() * entry.real();
299  temp_exp[3] = determinant_exponent.imag() + iexp_real;
300 
301  // Align the exponents in the two terms for each sum (real or imaginary)
302  // We always align up to the larger exponent
303  for (unsigned i = 0; i < 3; i += 2)
304  {
305  // If the first exponent is smaller, move it up
306  if (temp_exp[i] < temp_exp[i + 1])
307  {
308  // The smaller term
309  int lower = temp_exp[i];
310  // Loop over the difference in the exponents,
311  // scaling down the mantissa each time
312  for (int index = lower; index < temp_exp[i + 1]; ++index)
313  {
314  temp_mantissa[i] /= 2.0;
315  ++temp_exp[i];
316  }
317  }
318  // Otherwise the second exponent is smaller
319  else
320  {
321  // The smaller term is the other
322  int lower = temp_exp[i + 1];
323  // Loop over the difference in the exponents,
324  // scaling down the mantissa each time
325  for (int index = lower; index < temp_exp[i]; ++index)
326  {
327  temp_mantissa[i + 1] /= 2.0;
328  ++temp_exp[i + 1];
329  }
330  }
331  }
332 
333  // Now combine the terms AC - BD
334  // and Combine the terms AD + BC
335  determinant_mantissa =
336  std::complex<double>(temp_mantissa[0] - temp_mantissa[1],
337  temp_mantissa[2] + temp_mantissa[3]);
338  // The exponents will be the same, so pick one
339  determinant_exponent = std::complex<int>(temp_exp[0], temp_exp[2]);
340 
341  // Finally normalise the result
342  determinant_mantissa =
343  std::complex<double>(frexp(determinant_mantissa.real(), &iexp_real),
344  frexp(determinant_mantissa.imag(), &iexp_imag));
345 
346  int temp_real = determinant_exponent.real() + iexp_real;
347  int temp_imag = determinant_exponent.imag() + iexp_imag;
348 
349  determinant_exponent = std::complex<int>(temp_real, temp_imag);
350  }
351 
352  // Integer to store the sign of the determinant
353  int sign = 0;
354  // Find the sign of the determinant (left or right half-plane)
355  if (std::abs(determinant_mantissa) > 0.0)
356  {
357  sign = 1;
358  }
359  if (std::abs(determinant_mantissa) < 0.0)
360  {
361  sign = -1;
362  }
363 
364  // Multiply the sign by the signature
365  sign *= signature;
366 
367  // Return the sign of the determinant
368  return sign;
369  }
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
AnnoyingScalar imag(const AnnoyingScalar &)
Definition: AnnoyingScalar.h:132
void delete_lu_factors()
Definition: complex_matrices.cc:87
std::complex< double > & entry(const unsigned long &i, const unsigned long &j)
Definition: matrices.h:447
std::complex< double > * Matrixdata
Internal representation of matrix as a pointer to data.
Definition: matrices.h:389
unsigned long M
Number of columns.
Definition: matrices.h:395
float real
Definition: datatypes.h:10
char char char int int * k
Definition: level2_impl.h:374
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365
T sign(T x)
Definition: cxx11_tensor_builtins_sycl.cpp:172
std::string lower(std::string s)
returns the input string after converting upper-case characters to lower case
Definition: StringHelpers.cc:11

References abs(), delete_lu_factors(), oomph::DenseMatrix< std::complex< double > >::entry(), i, imag(), Index, j, k, helpers::lower(), LU_factors, oomph::DenseMatrix< std::complex< double > >::M, oomph::DenseMatrix< std::complex< double > >::Matrixdata, oomph::DenseMatrix< std::complex< double > >::N, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, Overwrite_matrix_storage, SYCL::sign(), and tmp.

◆ multiply()

void oomph::DenseComplexMatrix::multiply ( const Vector< std::complex< double >> &  x,
Vector< std::complex< double >> &  soln 
)
virtual

Multiply the matrix by the vector x: soln=Ax.

Implements oomph::ComplexMatrixBase.

509  {
510 #ifdef PARANOID
511  // Check to see if x.size() = ncol().
512  if (x.size() != M)
513  {
514  std::ostringstream error_message_stream;
515  error_message_stream << "The x vector is not the right size. It is "
516  << x.size() << ", it should be " << M << std::endl;
517 
518  throw OomphLibError(error_message_stream.str(),
521  }
522 #endif
523 
524  if (soln.size() != N)
525  {
526  // Resize and initialize the solution vector
527  soln.resize(N);
528  }
529 
530  // Multiply the matrix A, by the vector x
531  for (unsigned long i = 0; i < N; i++)
532  {
533  soln[i] = 0.0;
534  for (unsigned long j = 0; j < M; j++)
535  {
536  soln[i] += Matrixdata[M * i + j] * x[j];
537  }
538  }
539  }
list x
Definition: plotDoE.py:28

References i, j, oomph::DenseMatrix< std::complex< double > >::M, oomph::DenseMatrix< std::complex< double > >::Matrixdata, oomph::DenseMatrix< std::complex< double > >::N, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and plotDoE::x.

◆ multiply_transpose()

void oomph::DenseComplexMatrix::multiply_transpose ( const Vector< std::complex< double >> &  x,
Vector< std::complex< double >> &  soln 
)
virtual

Multiply the transposed matrix by the vector x: soln=A^T x.

Implements oomph::ComplexMatrixBase.

547  {
548 #ifdef PARANOID
549  // Check to see x.size() = nrow()
550  if (x.size() != N)
551  {
552  std::ostringstream error_message_stream;
553  error_message_stream << "The x vector is not the right size. It is "
554  << x.size() << ", it should be " << N << std::endl;
555 
556  throw OomphLibError(error_message_stream.str(),
559  }
560 #endif
561 
562  if (soln.size() != M)
563  {
564  // Resize and initialize the solution vector
565  soln.resize(M);
566  }
567 
568  // Initialise the solution
569  for (unsigned long i = 0; i < M; i++)
570  {
571  soln[i] = 0.0;
572  }
573 
574 
575  // Matrix vector product
576  for (unsigned long i = 0; i < N; i++)
577  {
578  for (unsigned long j = 0; j < M; j++)
579  {
580  soln[j] += Matrixdata[N * i + j] * x[i];
581  }
582  }
583  }

References i, j, oomph::DenseMatrix< std::complex< double > >::M, oomph::DenseMatrix< std::complex< double > >::Matrixdata, oomph::DenseMatrix< std::complex< double > >::N, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and plotDoE::x.

◆ ncol()

unsigned long oomph::DenseComplexMatrix::ncol ( ) const
inlinevirtual

Return the number of columns of the matrix.

Implements oomph::ComplexMatrixBase.

226  {
228  }
unsigned long ncol() const
Return the number of columns of the matrix.
Definition: complex_matrices.h:225

◆ nrow()

unsigned long oomph::DenseComplexMatrix::nrow ( ) const
inlinevirtual

Return the number of rows of the matrix.

Implements oomph::ComplexMatrixBase.

220  {
222  }
unsigned long nrow() const
Return the number of rows of the matrix.
Definition: complex_matrices.h:219

◆ operator()() [1/2]

std::complex<double>& oomph::DenseComplexMatrix::operator() ( const unsigned long &  i,
const unsigned long &  j 
)
inline

Overload the non-const version of the round-bracket access operator for read-write access

242  {
244  }

References oomph::DenseMatrix< std::complex< double > >::entry(), i, and j.

◆ operator()() [2/2]

std::complex<double> oomph::DenseComplexMatrix::operator() ( const unsigned long &  i,
const unsigned long &  j 
) const
inlinevirtual

Overload the const version of the round-bracket access operator for read-only access.

Implements oomph::ComplexMatrixBase.

234  {
236  }
std::complex< double > get_entry(const unsigned long &i, const unsigned long &j) const
Definition: matrices.h:457

References oomph::DenseMatrix< std::complex< double > >::get_entry(), i, and j.

◆ operator=()

void oomph::DenseComplexMatrix::operator= ( const DenseComplexMatrix )
delete

Broken assignment operator.

◆ residual()

void oomph::DenseComplexMatrix::residual ( const Vector< std::complex< double >> &  x,
const Vector< std::complex< double >> &  rhs,
Vector< std::complex< double >> &  residual 
)
virtual

Find the residual of Ax=b, i.e. r=b-Ax.

Find the residual of Ax=b, ie r=b-Ax for the "solution" x.

Implements oomph::ComplexMatrixBase.

453  {
454 #ifdef PARANOID
455  // Check Matrix is square
456  if (N != M)
457  {
458  throw OomphLibError(
459  "This matrix is not square, the matrix MUST be square!",
462  }
463  // Check that size of rhs = nrow()
464  if (rhs.size() != N)
465  {
466  std::ostringstream error_message_stream;
467  error_message_stream << "The rhs vector is not the right size. It is "
468  << rhs.size() << ", it should be " << N << std::endl;
469 
470  throw OomphLibError(error_message_stream.str(),
473  }
474  // Check that the size of x is correct
475  if (x.size() != N)
476  {
477  std::ostringstream error_message_stream;
478  error_message_stream << "The x vector is not the right size. It is "
479  << x.size() << ", it should be " << N << std::endl;
480 
481  throw OomphLibError(error_message_stream.str(),
484  }
485 #endif
486  // If size of residual is wrong, correct it!
487  if (residual.size() != N)
488  {
489  residual.resize(N);
490  }
491 
492  // Multiply the matrix by the vector x in residual vector
493  for (unsigned long i = 0; i < N; i++)
494  {
495  residual[i] = rhs[i];
496  for (unsigned long j = 0; j < M; j++)
497  {
498  residual[i] -= Matrixdata[M * i + j] * x[j];
499  }
500  }
501  }
void residual(const Vector< std::complex< double >> &x, const Vector< std::complex< double >> &rhs, Vector< std::complex< double >> &residual)
Find the residual of Ax=b, i.e. r=b-Ax.
Definition: complex_matrices.cc:450

References i, j, oomph::DenseMatrix< std::complex< double > >::M, oomph::DenseMatrix< std::complex< double > >::Matrixdata, oomph::DenseMatrix< std::complex< double > >::N, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and plotDoE::x.

Member Data Documentation

◆ Index

Vector<long>* oomph::DenseComplexMatrix::Index
private

Pointer to storage for the index of permutations in the LU solve.

Referenced by lubksub(), ludecompose(), and ~DenseComplexMatrix().

◆ LU_factors

std::complex<double>* oomph::DenseComplexMatrix::LU_factors
private

Pointer to storage for the LU decomposition.

Referenced by delete_lu_factors(), lubksub(), ludecompose(), and ~DenseComplexMatrix().

◆ Overwrite_matrix_storage

bool oomph::DenseComplexMatrix::Overwrite_matrix_storage
private

Boolean flag used to decided whether the LU decomposition is stored separately, or not

Referenced by delete_lu_factors(), and ludecompose().


The documentation for this class was generated from the following files: