oomph::DenseMatrix< T > Class Template Reference

#include <matrices.h>

+ Inheritance diagram for oomph::DenseMatrix< T >:

Public Member Functions

 DenseMatrix ()
 Empty constructor, simply assign the lengths N and M to 0. More...
 
 DenseMatrix (const DenseMatrix &source_matrix)
 Copy constructor: Deep copy! More...
 
DenseMatrixoperator= (const DenseMatrix &source_matrix)
 Copy assignment. More...
 
Tentry (const unsigned long &i, const unsigned long &j)
 
T get_entry (const unsigned long &i, const unsigned long &j) const
 
 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 T &initial_val)
 
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 T &initial_value)
 
void initialise (const T &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, DenseMatrix< T > >
 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
 

Protected Attributes

TMatrixdata
 Internal representation of matrix as a pointer to data. More...
 
unsigned long N
 Number of rows. More...
 
unsigned long M
 Number of columns. More...
 

Additional Inherited Members

- Protected Member Functions inherited from oomph::Matrix< T, DenseMatrix< T > >
void range_check (const unsigned long &i, const unsigned long &j) const
 

Detailed Description

template<class T>
class oomph::DenseMatrix< T >

//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// Class for dense matrices, storing all the values of the matrix as a pointer to a pointer with assorted output functions inherited from Matrix<T>. The curious recursive template pattern is used here to pass the specific class to the base class so that round bracket access can be inlined.

Constructor & Destructor Documentation

◆ DenseMatrix() [1/5]

template<class T >
oomph::DenseMatrix< T >::DenseMatrix ( )
inline

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

399 : Matrixdata(0), N(0), M(0) {}
unsigned long N
Number of rows.
Definition: matrices.h:392
T * Matrixdata
Internal representation of matrix as a pointer to data.
Definition: matrices.h:389
unsigned long M
Number of columns.
Definition: matrices.h:395

◆ DenseMatrix() [2/5]

template<class T >
oomph::DenseMatrix< T >::DenseMatrix ( const DenseMatrix< T > &  source_matrix)
inline

Copy constructor: Deep copy!

403  {
404  // Set row and column lengths
405  N = source_matrix.nrow();
406  M = source_matrix.ncol();
407  // Assign space for the data
408  Matrixdata = new T[N * M];
409  // Copy the data across from the other matrix
410  for (unsigned long i = 0; i < N; i++)
411  {
412  for (unsigned long j = 0; j < M; j++)
413  {
414  Matrixdata[M * i + j] = source_matrix(i, j);
415  }
416  }
417  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References i, j, oomph::DenseMatrix< T >::M, oomph::DenseMatrix< T >::Matrixdata, oomph::DenseMatrix< T >::N, oomph::DenseMatrix< T >::ncol(), and oomph::DenseMatrix< T >::nrow().

◆ DenseMatrix() [3/5]

template<class T >
oomph::DenseMatrix< T >::DenseMatrix ( const unsigned long &  n)

Constructor to build a square n by n matrix.

////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////

2907  {
2908  // Set row and column lengths
2909  N = n;
2910  M = n;
2911  // Assign space for the n rows
2912  Matrixdata = new T[n * n];
2913  // Initialise to zero if required
2914 #ifdef OOMPH_INITIALISE_DENSE_MATRICES
2915  initialise(T(0));
2916 #endif
2917  }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
Eigen::Triplet< double > T
Definition: EigenUnitTest.cpp:11
void initialise(const T &val)
Initialize all values in the matrix to val.
Definition: matrices.h:514

References n, and N.

◆ DenseMatrix() [4/5]

template<class T >
oomph::DenseMatrix< T >::DenseMatrix ( const unsigned long &  n,
const unsigned long &  m 
)

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

2925  {
2926  // Set row and column lengths
2927  N = n;
2928  M = m;
2929  // Assign space for the n rows
2930  Matrixdata = new T[n * m];
2931 #ifdef OOMPH_INITIALISE_DENSE_MATRICES
2932  initialise(T(0));
2933 #endif
2934  }
int * m
Definition: level2_cplx_impl.h:294

References m, n, and N.

◆ DenseMatrix() [5/5]

template<class T >
oomph::DenseMatrix< T >::DenseMatrix ( const unsigned long &  n,
const unsigned long &  m,
const T initial_val 
)

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

2944  {
2945  // Set row and column lengths
2946  N = n;
2947  M = m;
2948  // Assign space for the n rows
2949  Matrixdata = new T[n * m];
2950  initialise(initial_val);
2951  }

References m, n, and N.

◆ ~DenseMatrix()

template<class T >
virtual oomph::DenseMatrix< T >::~DenseMatrix ( )
inlinevirtual

Destructor, clean up the matrix data.

479  {
480  delete[] Matrixdata;
481  Matrixdata = 0;
482  }

References oomph::DenseMatrix< T >::Matrixdata.

Member Function Documentation

◆ entry()

template<class T >
T& oomph::DenseMatrix< T >::entry ( const unsigned long &  i,
const unsigned long &  j 
)
inline

The access function that will be called by the read-write round-bracket operator.

448  {
449 #ifdef RANGE_CHECKING
450  this->range_check(i, j);
451 #endif
452  return Matrixdata[M * i + j];
453  }
void range_check(const unsigned long &i, const unsigned long &j) const
Definition: matrices.h:78

References i, j, oomph::DenseMatrix< T >::Matrixdata, and oomph::Matrix< T, DenseMatrix< T > >::range_check().

Referenced by oomph::DenseDoubleMatrix::operator()().

◆ get_entry()

template<class T >
T oomph::DenseMatrix< T >::get_entry ( const unsigned long &  i,
const unsigned long &  j 
) const
inline

The access function the will be called by the read-only (const version) round-bracket operator.

458  {
459 #ifdef RANGE_CHECKING
460  this->range_check(i, j);
461 #endif
462  return Matrixdata[M * i + j];
463  }

References i, j, oomph::DenseMatrix< T >::Matrixdata, and oomph::Matrix< T, DenseMatrix< T > >::range_check().

Referenced by oomph::DenseDoubleMatrix::operator()().

◆ indexed_output() [1/2]

template<class T >
void oomph::DenseMatrix< T >::indexed_output ( std::ostream &  outfile) const

Indexed output as i,j,a(i,j)

Indexed output function to print a matrix to the stream outfile as i,j,a(i,j)

3090  {
3091  // Loop over the rows
3092  for (unsigned i = 0; i < N; i++)
3093  {
3094  // Loop over the columns
3095  for (unsigned j = 0; j < M; j++)
3096  {
3097  outfile << i << " " << j << " " << (*this)(i, j) << std::endl;
3098  }
3099  }
3100  }

References i, j, and N.

◆ indexed_output() [2/2]

template<class T >
void oomph::DenseMatrix< T >::indexed_output ( std::string  filename) const

Indexed output function to print a matrix to a file as i,j,a(i,j). Specify filename.

3109  {
3110  // Open file
3111  std::ofstream some_file;
3112  some_file.open(filename.c_str());
3113  indexed_output(some_file);
3114  some_file.close();
3115  }
void indexed_output(std::ostream &outfile) const
Indexed output as i,j,a(i,j)
Definition: matrices.h:3089
string filename
Definition: MergeRestartFiles.py:39

References MergeRestartFiles::filename.

◆ initialise()

template<class T >
void oomph::DenseMatrix< T >::initialise ( const T val)
inline

Initialize all values in the matrix to val.

515  {
516  for (unsigned long i = 0; i < (N * M); ++i)
517  {
518  Matrixdata[i] = val;
519  }
520  }
val
Definition: calibrate.py:119

References i, oomph::DenseMatrix< T >::M, oomph::DenseMatrix< T >::Matrixdata, oomph::DenseMatrix< T >::N, and calibrate::val.

Referenced by oomph::PeriodicOrbitTemporalMesh< ELEMENT >::assemble_residuals_and_jacobian(), oomph::FSIHermiteBeamElement::dposition_dlagrangian_at_local_coordinate(), oomph::FSIDiagHermiteShellElement::dposition_dlagrangian_at_local_coordinate(), oomph::GeneralisedElement::get_djacobian_and_dmass_matrix_dparameter(), oomph::GeneralisedElement::get_djacobian_dparameter(), ABCElement::get_inner_product_matrix(), oomph::PeriodicOrbitBaseElement::get_inner_product_matrix(), oomph::DGElement::get_inverse_mass_matrix_times_residuals(), oomph::Problem::get_jacobian(), oomph::ElasticallySupportedRingElement::get_jacobian(), ElasticFishBackElement::get_jacobian(), oomph::GeneralisedElement::get_jacobian(), oomph::GeneralisedElement::get_jacobian_and_mass_matrix(), oomph::GeneralisedElement::get_mass_matrix(), oomph::PseudoBucklingRingElement::get_residuals_generic(), oomph::SpaceTimeNavierStokesEquations< DIM >::get_vorticity(), oomph::SpaceTimeNavierStokesMixedOrderEquations< DIM >::get_vorticity(), oomph::DGElement::pre_compute_mass_matrix(), oomph::SpaceTimeNavierStokesEquations< DIM >::strain_rate(), and oomph::SpaceTimeNavierStokesMixedOrderEquations< DIM >::strain_rate().

◆ ncol()

template<class T >
unsigned long oomph::DenseMatrix< T >::ncol ( ) const
inlinevirtual

Return the number of columns of the matrix.

Implements oomph::Matrix< T, DenseMatrix< T > >.

492  {
493  return M;
494  }

References oomph::DenseMatrix< T >::M.

Referenced by oomph::ConstitutiveLaw::calculate_contravariant(), oomph::ConstitutiveLaw::calculate_d_contravariant_dG(), oomph::CRDoubleMatrixHelpers::concatenate(), oomph::CRDoubleMatrixHelpers::concatenate_without_communication(), create_matrices_to_cat(), oomph::DenseMatrix< T >::DenseMatrix(), oomph::FiniteElement::dJ_eulerian_dnodal_coordinates(), oomph::DenseDoubleMatrix::eigenvalues_by_jacobi(), oomph::GeneralisedNewtonianAxisymmetricNavierStokesEquations::extrapolated_strain_rate(), oomph::GeneralisedNewtonianNavierStokesEquations< DIM >::extrapolated_strain_rate(), fill_in_sub_matrices(), oomph::NavierStokesEquations< 2 >::full_output(), oomph::CRDoubleMatrixHelpers::gershgorin_eigenvalue_estimate(), oomph::BlockPreconditioner< MATRIX >::get_blocks(), oomph::LinearElasticityEquationsBase< DIM >::get_strain(), oomph::PoroelasticityEquations< DIM >::get_strain(), oomph::PVDEquationsBase< DIM >::get_strain(), oomph::LinearElasticityEquations< DIM >::get_stress(), oomph::PoroelasticityEquations< DIM >::get_stress(), oomph::CRDoubleMatrixHelpers::inf_norm(), main(), oomph::DenseDoubleMatrix::ncol(), oomph::DenseMatrix< T >::operator=(), oomph::LagrangeEnforcedFlowPreconditioner::setup(), oomph::LinearisedAxisymmetricNavierStokesEquations::strain_rate(), oomph::AxisymmetricNavierStokesEquations::strain_rate(), oomph::GeneralisedNewtonianAxisymmetricNavierStokesEquations::strain_rate(), oomph::GeneralisedNewtonianNavierStokesEquations< DIM >::strain_rate(), oomph::PolarNavierStokesEquations::strain_rate(), oomph::SpaceTimeNavierStokesEquations< DIM >::strain_rate(), oomph::SpaceTimeNavierStokesMixedOrderEquations< DIM >::strain_rate(), oomph::LinearisedNavierStokesEquations::strain_rate(), and oomph::PolarNavierStokesEquations::strain_rate_by_r().

◆ nrow()

template<class T >
unsigned long oomph::DenseMatrix< T >::nrow ( ) const
inlinevirtual

Return the number of rows of the matrix.

Implements oomph::Matrix< T, DenseMatrix< T > >.

486  {
487  return N;
488  }

References oomph::DenseMatrix< T >::N.

Referenced by oomph::HelmholtzMGPreconditioner< DIM >::block_preconditioner_self_test(), oomph::IsotropicStrainEnergyFunctionConstitutiveLaw::calculate_second_piola_kirchhoff_stress(), oomph::CRDoubleMatrixHelpers::concatenate(), oomph::CRDoubleMatrixHelpers::concatenate_without_communication(), create_matrices_to_cat(), oomph::DenseMatrix< T >::DenseMatrix(), oomph::FiniteElement::dJ_eulerian_dnodal_coordinates(), oomph::DenseDoubleMatrix::eigenvalues_by_jacobi(), oomph::GeneralisedNewtonianAxisymmetricNavierStokesEquations::extrapolated_strain_rate(), oomph::GeneralisedNewtonianNavierStokesEquations< DIM >::extrapolated_strain_rate(), oomph::DisplacementBasedFoepplvonKarmanEquations::fill_in_contribution_to_jacobian_and_mass_matrix(), fill_in_sub_matrices(), oomph::NavierStokesEquations< 2 >::full_output(), oomph::CRDoubleMatrixHelpers::gershgorin_eigenvalue_estimate(), oomph::BlockPreconditioner< MATRIX >::get_blocks(), oomph::LinearElasticityEquationsBase< DIM >::get_strain(), oomph::PoroelasticityEquations< DIM >::get_strain(), oomph::PVDEquationsBase< DIM >::get_strain(), oomph::LinearElasticityEquations< DIM >::get_stress(), oomph::PoroelasticityEquations< DIM >::get_stress(), oomph::CRDoubleMatrixHelpers::inf_norm(), main(), oomph::DenseDoubleMatrix::nrow(), oomph::DenseMatrix< T >::operator=(), oomph::JacksHelloWorld::say_it_external(), oomph::JacksHelloWorld::say_it_inline(), oomph::SecondInvariantHelper::second_invariant(), oomph::LagrangeEnforcedFlowPreconditioner::setup(), oomph::LinearisedAxisymmetricNavierStokesEquations::strain_rate(), oomph::AxisymmetricNavierStokesEquations::strain_rate(), oomph::GeneralisedNewtonianAxisymmetricNavierStokesEquations::strain_rate(), oomph::GeneralisedNewtonianNavierStokesEquations< DIM >::strain_rate(), oomph::PolarNavierStokesEquations::strain_rate(), oomph::SpaceTimeNavierStokesEquations< DIM >::strain_rate(), oomph::SpaceTimeNavierStokesMixedOrderEquations< DIM >::strain_rate(), oomph::LinearisedNavierStokesEquations::strain_rate(), and oomph::PolarNavierStokesEquations::strain_rate_by_r().

◆ operator=()

template<class T >
DenseMatrix& oomph::DenseMatrix< T >::operator= ( const DenseMatrix< T > &  source_matrix)
inline

Copy assignment.

421  {
422  // Don't create a new matrix if the assignment is the identity
423  if (this != &source_matrix)
424  {
425  // Check row and column length
426  unsigned long n = source_matrix.nrow();
427  unsigned long m = source_matrix.ncol();
428  if ((N != n) || (M != m))
429  {
430  resize(n, m);
431  }
432  // Copy entries across from the other matrix
433  for (unsigned long i = 0; i < N; i++)
434  {
435  for (unsigned long j = 0; j < M; j++)
436  {
437  (*this)(i, j) = source_matrix(i, j);
438  }
439  }
440  }
441  // Return reference to object itself (i.e. de-reference this pointer)
442  return *this;
443  }
void resize(const unsigned long &n)
Definition: matrices.h:498

References i, j, m, oomph::DenseMatrix< T >::M, n, oomph::DenseMatrix< T >::N, oomph::DenseMatrix< T >::ncol(), oomph::DenseMatrix< T >::nrow(), and oomph::DenseMatrix< T >::resize().

◆ output() [1/2]

template<class T >
void oomph::DenseMatrix< T >::output ( std::ostream &  outfile) const
virtual

Output function to print a matrix row-by-row to the stream outfile.

Reimplemented from oomph::Matrix< T, DenseMatrix< T > >.

3055  {
3056  // Loop over the rows
3057  for (unsigned i = 0; i < N; i++)
3058  {
3059  // Loop over the columne
3060  for (unsigned j = 0; j < M; j++)
3061  {
3062  outfile << (*this)(i, j) << " ";
3063  }
3064  // Put in a newline
3065  outfile << std::endl;
3066  }
3067  }

References i, j, and N.

◆ output() [2/2]

template<class T >
void oomph::DenseMatrix< T >::output ( std::string  filename) const

Output function to print a matrix row-by-row to a file. Specify filename.

Output function to print a matrix row-by-row to a file. Specify filename.

3075  {
3076  // Open file
3077  std::ofstream some_file;
3078  some_file.open(filename.c_str());
3079 
3080  output(some_file);
3081  some_file.close();
3082  }
void output(std::ostream &outfile) const
Output function to print a matrix row-by-row to the stream outfile.
Definition: matrices.h:3054

References MergeRestartFiles::filename, and oomph::output().

◆ output_bottom_right_zero_helper()

template<class T >
void oomph::DenseMatrix< T >::output_bottom_right_zero_helper ( std::ostream &  outfile) const
virtual

Output the "bottom right" entry regardless of it being zero or not (this allows automatic detection of matrix size in e.g. matlab, python).

Implements oomph::Matrix< T, DenseMatrix< T > >.

3126  {
3127  int last_row = this->N - 1;
3128  int last_col = this->M - 1;
3129 
3130  // Use this strange thingy because of the CRTP discussed above.
3131  T last_value = this->operator()(last_row, last_col);
3132 
3133  if (last_value == T(0))
3134  {
3135  outfile << last_row << " " << last_col << " " << T(0) << std::endl;
3136  }
3137  }
T operator()(const unsigned long &i, const unsigned long &j) const
Definition: matrices.h:128

References N.

◆ resize() [1/3]

template<class T >
void oomph::DenseMatrix< T >::resize ( const unsigned long &  n)
inline

Resize to a square nxn matrix; any values already present will be transfered

499  {
500  resize(n, n);
501  }

References n.

Referenced by SpineGravityTractionElement< ELEMENT >::assign_additional_local_eqn_numbers(), oomph::SpectralElement::assign_all_generic_local_eqn_numbers(), oomph::DenseDoubleMatrix::eigenvalues_by_jacobi(), oomph::PeriodicOrbitEquations::fill_in_generic_residual_contribution_orbit(), RefineableQAxisymCrouzeixRaviartBoussinesqElement::get_dbody_force_axi_nst_dexternal_element_data(), QAxisymCrouzeixRaviartElementWithExternalElement::get_dbody_force_axi_nst_dexternal_element_data(), RefineableQCrouzeixRaviartElementWithExternalElement< DIM >::get_dbody_force_nst_dexternal_element_data(), RefineableQCrouzeixRaviartElementWithTwoExternalElement< DIM >::get_dbody_force_nst_dexternal_element_data(), QCrouzeixRaviartElementWithTwoExternalElement< DIM >::get_dbody_force_nst_dexternal_element_data(), oomph::RefineableNavierStokesBoussinesqElement< NST_ELEMENT, AD_ELEMENT >::get_dbody_force_nst_dexternal_element_data(), oomph::NavierStokesBoussinesqElement< NST_ELEMENT, AD_ELEMENT >::get_dbody_force_nst_dexternal_element_data(), oomph::Problem::get_fd_jacobian(), oomph::DGElement::get_inverse_mass_matrix_times_residuals(), oomph::Problem::get_jacobian(), oomph::IMRBase::IMRBase(), oomph::JacksHelloWorld::JacksHelloWorld(), oomph::KirchhoffLoveShellEquations::KirchhoffLoveShellEquations(), oomph::DenseDoubleMatrix::matrix_reduction(), oomph::ContinuationStorageScheme::modify_storage(), oomph::DenseDoubleMatrix::multiply(), oomph::DenseMatrix< T >::operator=(), oomph::DGElement::pre_compute_mass_matrix(), oomph::SelfStartingBDF2::SelfStartingBDF2(), oomph::BinaryTree::setup_static_data(), oomph::OcTree::setup_static_data(), oomph::QuadTree::setup_static_data(), and oomph::HSL_MA42::solve().

◆ resize() [2/3]

template<class T >
void oomph::DenseMatrix< T >::resize ( const unsigned long &  n,
const unsigned long &  m 
)

Resize to a non-square n x m matrix; any values already present will be transfered

Resize to a non-square n_row x m_col matrix, where any values already present will be transfered.

2960  {
2961  // If the sizes are the same, do nothing
2962  if ((n == N) && (m == M))
2963  {
2964  return;
2965  }
2966  // Store old sizes
2967  unsigned long n_old = N, m_old = M;
2968  // Reassign the sizes
2969  N = n;
2970  M = m;
2971  // Store double pointer to old matrix data
2972  T* temp_matrix = Matrixdata;
2973 
2974  // Re-create Matrixdata in new size
2975  Matrixdata = new T[n * m];
2976  // Initialise to zero
2977 #ifdef OOMPH_INITIALISE_DENSE_MATRICES
2978  initialise(T(0));
2979 #endif
2980 
2981  // Transfer previously existing values
2982  unsigned long n_copy, m_copy;
2983  n_copy = std::min(n_old, n);
2984  m_copy = std::min(m_old, m);
2985 
2986  // If matrix has values, transfer them to new matrix
2987  // Loop over rows
2988  for (unsigned long i = 0; i < n_copy; i++)
2989  {
2990  // Loop over columns
2991  for (unsigned long j = 0; j < m_copy; j++)
2992  {
2993  // Transfer values from temp_matrix
2994  Matrixdata[m * i + j] = temp_matrix[m_old * i + j];
2995  }
2996  }
2997 
2998  // Now kill storage for old matrix
2999  delete[] temp_matrix;
3000  }
#define min(a, b)
Definition: datatypes.h:22

References i, j, m, min, n, and N.

◆ resize() [3/3]

template<class T >
void oomph::DenseMatrix< T >::resize ( const unsigned long &  n,
const unsigned long &  m,
const T initial_value 
)

Resize to a non-square n x m matrix and initialize the new values to initial_value.

Resize to a non-square n_row x m_col matrix and initialize the new entries to specified value.

3011  {
3012  // If the size is not changed, just return
3013  if ((n == N) && (m == M))
3014  {
3015  return;
3016  }
3017  // Store old sizes
3018  unsigned long n_old = N, m_old = M;
3019  // Reassign the sizes
3020  N = n;
3021  M = m;
3022  // Store double pointer to old matrix data
3023  T* temp_matrix = Matrixdata;
3024  // Re-create Matrixdata in new size
3025  Matrixdata = new T[n * m];
3026  // Assign initial value (will use the newly allocated data)
3027  initialise(initial_value);
3028 
3029  // Transfering values
3030  unsigned long n_copy, m_copy;
3031  n_copy = std::min(n_old, n);
3032  m_copy = std::min(m_old, m);
3033  // If matrix has values, transfer them to temp_matrix
3034  // Loop over rows
3035  for (unsigned long i = 0; i < n_copy; i++)
3036  {
3037  // Loop over columns
3038  for (unsigned long j = 0; j < m_copy; j++)
3039  {
3040  // Transfer values to temp_matrix
3041  Matrixdata[m * i + j] = temp_matrix[m_old * i + j];
3042  }
3043  }
3044 
3045  // Now kill storage for old matrix
3046  delete[] temp_matrix;
3047  }

References i, j, m, min, n, and N.

◆ sparse_indexed_output_helper()

template<class T >
void oomph::DenseMatrix< T >::sparse_indexed_output_helper ( std::ostream &  outfile) const
virtual

Sparse indexed output as i,j,a(i,j) for a(i,j)!=0 only.

Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,j)!=0 only.

Implements oomph::Matrix< T, DenseMatrix< T > >.

3144  {
3145  // Loop over the rows
3146  for (unsigned i = 0; i < N; i++)
3147  {
3148  // Loop over the column
3149  for (unsigned j = 0; j < M; j++)
3150  {
3151  if ((*this)(i, j) != T(0))
3152  {
3153  outfile << i << " " << j << " " << (*this)(i, j) << std::endl;
3154  }
3155  }
3156  }
3157  }

References i, j, and N.

Member Data Documentation

◆ M

◆ Matrixdata

◆ N


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