Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GIDI::Matrix Class Reference

#include <GIDI_data.hpp>

Public Member Functions

 Matrix (std::size_t a_rows, std::size_t a_columns)
 Matrix (Matrix const &a_gidi_matrix)
 ~Matrix ()
Matrixoperator= (Matrix const &a_rhs)
std::size_t size () const
Vectoroperator[] (std::size_t a_index)
Vector const & operator[] (std::size_t a_index) const
void operator() (std::size_t a_row, std::size_t a_column, double a_value)
std::vector< Vector > const & matrix () const
Matrix operator+ (double a_value) const
Matrixoperator+= (double a_value)
Matrix operator+ (Matrix const &a_rhs) const
Matrixoperator+= (Matrix const &a_rhs)
Matrix operator- (double a_value) const
Matrixoperator-= (double a_value)
Matrix operator- (Matrix const &a_rhs) const
Matrixoperator-= (Matrix const &a_rhs)
Matrix operator* (double a_value) const
Matrixoperator*= (double a_value)
Matrix operator/ (double a_value) const
Matrixoperator/= (double a_value)
std::size_t numberOfColumns () const
void set (std::size_t a_row, std::size_t a_column, double a_value)
void set (std::size_t a_row, Vector const &a_vector)
void push_back (Vector const &a_vector)
Matrix transpose ()
void reverse ()
void print (std::string const &a_prefixForRow) const

Detailed Description

This class stores a mathematical matrix and has methods that perform several matrix operations (e.g., addition, subtraction).

Definition at line 116 of file GIDI_data.hpp.

Constructor & Destructor Documentation

◆ Matrix() [1/2]

GIDI::Matrix::Matrix ( std::size_t a_rows,
std::size_t a_columns )
Parameters
a_rows[in] Number of rows of the matrix.
a_columns[in] Number of columns of the matrix.

Definition at line 24 of file GIDI_matrix.cc.

24 {
25
26 m_matrix.resize( a_rows );
27
28 for( std::size_t i1 = 0; i1 < a_rows; ++i1 ) m_matrix[i1].resize( a_columns );
29}

Referenced by Matrix(), operator*(), operator*=(), operator+(), operator+(), operator+=(), operator+=(), operator-(), operator-(), operator-=(), operator-=(), operator/(), operator/=(), operator=(), and transpose().

◆ Matrix() [2/2]

GIDI::Matrix::Matrix ( Matrix const & a_matrix)
Parameters
a_matrix[in] Matrix to copy.

Definition at line 36 of file GIDI_matrix.cc.

36 {
37
38 std::size_t rows = a_matrix.size( );
39
40 m_matrix.resize( rows );
41
42 for( std::size_t i1 = 0; i1 < rows; ++i1 ) m_matrix[i1] = a_matrix[i1];
43}

◆ ~Matrix()

GIDI::Matrix::~Matrix ( )

Definition at line 48 of file GIDI_matrix.cc.

48 {
49
50}

Member Function Documentation

◆ matrix()

std::vector< Vector > const & GIDI::Matrix::matrix ( ) const
inline

Definition at line 138 of file GIDI_data.hpp.

138{ return( m_matrix ); }

Referenced by operator=().

◆ numberOfColumns()

std::size_t GIDI::Matrix::numberOfColumns ( ) const

Returns the number of columns of this.

Returns
The number of columns of this.

Definition at line 274 of file GIDI_matrix.cc.

274 {
275
276 if( size( ) == 0 ) return( 0 );
277 return( m_matrix[0].size( ) );
278}
std::size_t size() const

Referenced by operator+=(), operator-=(), and transpose().

◆ operator()()

void GIDI::Matrix::operator() ( std::size_t a_row,
std::size_t a_column,
double a_value )
inline

Sets the cell at row a_row and column a_column to a_value.

Parameters
a_rowThe cell's row.
a_columnThe cell's row.
a_valueThe value to put in the cell.

Definition at line 133 of file GIDI_data.hpp.

136 { m_matrix[a_row][a_column] = a_value; }

◆ operator*()

Matrix GIDI::Matrix::operator* ( double a_value) const

Returns a new Matrix whose cells are this multiplied by a_value.

Parameters
a_value[in] The value to multiply each cell by.
Returns
New Matrix whose cells are this multiply by a_value.

Definition at line 216 of file GIDI_matrix.cc.

216 {
217
218 Matrix gidiMatrix( *this );
219
220 gidiMatrix *= a_value;
221 return( gidiMatrix );
222}
Matrix(std::size_t a_rows, std::size_t a_columns)

◆ operator*=()

Matrix & GIDI::Matrix::operator*= ( double a_value)

Multiplies each cell of this by a_value.

Parameters
a_value[in] The value to multiply each cell by.
Returns
Returns reference to this.

Definition at line 231 of file GIDI_matrix.cc.

231 {
232
233 for( std::vector<Vector>::iterator iter = m_matrix.begin( ); iter < m_matrix.end( ); ++iter ) *iter *= a_value;
234
235 return( *this );
236}

◆ operator+() [1/2]

Matrix GIDI::Matrix::operator+ ( double a_value) const

Returns a new Matrix whose cells are this plus a_value.

Parameters
a_value[in] The value to add to each cell.
Returns
New Matrix whose cells are this plus a_value.

Definition at line 76 of file GIDI_matrix.cc.

76 {
77
78 Matrix gidiMatrix( *this );
79
80 gidiMatrix += a_value;
81 return( gidiMatrix );
82}

◆ operator+() [2/2]

Matrix GIDI::Matrix::operator+ ( Matrix const & a_rhs) const

Adds two Matrices.

Parameters
a_rhs[in] Matrix to add to this.
Returns
New Matrix that is the matrix sum of this and a_rhs.

Definition at line 105 of file GIDI_matrix.cc.

105 {
106
107 Matrix gidiMatrix( *this );
108
109 gidiMatrix += a_rhs;
110 return( gidiMatrix );
111}

◆ operator+=() [1/2]

Matrix & GIDI::Matrix::operator+= ( double a_value)

Adds a_value to each cell of this.

Parameters
a_value[in] The value to add to each cell.
Returns
Returns reference to this.

Definition at line 91 of file GIDI_matrix.cc.

91 {
92
93 for( std::vector<Vector>::iterator iter = m_matrix.begin( ); iter < m_matrix.end( ); ++iter ) *iter += a_value;
94
95 return( *this );
96}

◆ operator+=() [2/2]

Matrix & GIDI::Matrix::operator+= ( Matrix const & a_rhs)

Adds a_rhs to this.

Parameters
a_rhs[in] Matrix to add to this.
Returns
Returns reference to this.

Definition at line 120 of file GIDI_matrix.cc.

120 {
121
122 std::size_t i1, rhs_size = a_rhs.size( );
123
124 if( rhs_size == 0 ) return( *this ); // Do nothing if rhs is empty.
125
126 if( size( ) == 0 ) {
127 for( i1 = 0; i1 < rhs_size; ++i1 ) m_matrix.push_back( Vector( a_rhs.numberOfColumns( ) ) );
128 }
129
130 if( size( ) != a_rhs.size( ) ) throw Exception( "matrix sizes differ." );
131 if( m_matrix[0].size( ) != a_rhs[0].size( ) ) throw Exception( "matrix colums numbers differ." );
132
133 i1 = 0;
134 for( std::vector<Vector>::iterator iter = m_matrix.begin( ); iter < m_matrix.end( ); ++iter, ++i1 ) *iter += a_rhs[i1];
135
136 return( *this );
137}

◆ operator-() [1/2]

Matrix GIDI::Matrix::operator- ( double a_value) const

Returns a new Matrix whose cells are this minus a_value.

Parameters
a_value[in] The value to subtract from each cell.
Returns
New Matrix whose cells are this plus a_value.

Definition at line 146 of file GIDI_matrix.cc.

146 {
147
148 Matrix gidiMatrix( *this );
149
150 gidiMatrix -= a_value;
151 return( gidiMatrix );
152}

◆ operator-() [2/2]

Matrix GIDI::Matrix::operator- ( Matrix const & a_rhs) const

Subtracts a_rhs from this.

Parameters
a_rhs[in] Matrix to subtract from this.
Returns
New Matrix that is this minus a_rhs.

Definition at line 175 of file GIDI_matrix.cc.

175 {
176
177 Matrix gidiMatrix( *this );
178
179 gidiMatrix -= a_rhs;
180 return( gidiMatrix );
181}

◆ operator-=() [1/2]

Matrix & GIDI::Matrix::operator-= ( double a_value)

Subtracts a_value from each cell of this.

Parameters
a_value[in] The value to subtract from each cell.
Returns
Returns reference to this.

Definition at line 161 of file GIDI_matrix.cc.

161 {
162
163 for( std::vector<Vector>::iterator iter = m_matrix.begin( ); iter < m_matrix.end( ); ++iter ) *iter -= a_value;
164
165 return( *this );
166}

◆ operator-=() [2/2]

Matrix & GIDI::Matrix::operator-= ( Matrix const & a_rhs)

Subtracts a_rhs to this.

Parameters
a_rhs[in] Matrix to subtract from this.
Returns
Returns reference to this.

Definition at line 190 of file GIDI_matrix.cc.

190 {
191
192 std::size_t i1, rhs_size = a_rhs.size( );
193
194 if( rhs_size == 0 ) return( *this ); // Do nothing if rhs is empty.
195
196 if( size( ) == 0 ) {
197 for( i1 = 0; i1 < rhs_size; ++i1 ) m_matrix.push_back( Vector( a_rhs.numberOfColumns( ) ) );
198 }
199
200 if( size( ) != a_rhs.size( ) ) throw Exception( "matrix sizes differ." );
201 if( m_matrix[0].size( ) != a_rhs[0].size( ) ) throw Exception( "matrix colums numbers differ." );
202
203 i1 = 0;
204 for( std::vector<Vector>::iterator iter = m_matrix.begin( ); iter < m_matrix.end( ); ++iter, ++i1 ) *iter -= a_rhs[i1];
205
206 return( *this );
207}

◆ operator/()

Matrix GIDI::Matrix::operator/ ( double a_value) const

Returns a new Matrix whose cells are this divided by a_value.

Parameters
a_value[in] The value to divide each cell by.
Returns
New Matrix whose cells are this divided by a_value.

Definition at line 245 of file GIDI_matrix.cc.

245 {
246
247 Matrix gidiMatrix( *this );
248
249 gidiMatrix /= a_value;
250 return( gidiMatrix );
251}

◆ operator/=()

Matrix & GIDI::Matrix::operator/= ( double a_value)

Divides each cell of this by a_value.

Parameters
a_value[in] The value to divide each cell by.
Returns
Returns reference to this.

Definition at line 260 of file GIDI_matrix.cc.

260 {
261
262 if( a_value == 0 ) throw Exception( "divide by zero." );
263 for( std::vector<Vector>::iterator iter = m_matrix.begin( ); iter < m_matrix.end( ); ++iter ) *iter /= a_value;
264
265 return( *this );
266}

◆ operator=()

Matrix & GIDI::Matrix::operator= ( Matrix const & a_rhs)

The assignment operator. This method sets the members of this to those of a_rhs.

Parameters
a_rhs[in] Instance whose member are used to set the members of this.
Returns
A reference to the updated Matrix instance.

Definition at line 60 of file GIDI_matrix.cc.

60 {
61
62 if( this != &a_rhs ) {
63 m_matrix = a_rhs.matrix( );
64 }
65
66 return( *this );
67}

◆ operator[]() [1/2]

Vector & GIDI::Matrix::operator[] ( std::size_t a_index)
inline

Returns a reference to the (a_index-1)th row.

Definition at line 129 of file GIDI_data.hpp.

◆ operator[]() [2/2]

Vector const & GIDI::Matrix::operator[] ( std::size_t a_index) const
inline

Returns a reference to the (a_index-1)th row.

Definition at line 130 of file GIDI_data.hpp.

◆ print()

void GIDI::Matrix::print ( std::string const & a_prefixForRow) const

Prints the contents of this by calling the print method of each row with a_prefixForRow as an argument.

Parameters
a_prefixForRow[in] Argument passed to each row's print method.

Definition at line 333 of file GIDI_matrix.cc.

333 {
334
335 for( std::vector<Vector>::const_iterator iter = m_matrix.begin( ); iter < m_matrix.end( ); ++iter ) iter->print( a_prefixForRow );
336}

◆ push_back()

void GIDI::Matrix::push_back ( Vector const & a_vector)

Adds a row to this.

Parameters
a_vector[in] The Vector to add to this as another row.

Definition at line 286 of file GIDI_matrix.cc.

286 {
287
288 if( size( ) > 0 ) {
289 if( (*this)[0].size( ) != a_vector.size( ) ) throw Exception( "matrix::push_back: size different" );
290 }
291 m_matrix.push_back( a_vector );
292}

Referenced by GIDI::collapse().

◆ reverse()

void GIDI::Matrix::reverse ( )

Reverse the rows of this.

Definition at line 313 of file GIDI_matrix.cc.

313 {
314
315 std::size_t i2 = size( ), n_2 = i2 / 2;
316
317 for( std::size_t i1 = 0; i1 < i2; ++i1 ) m_matrix[i1].reverse( );
318 --i2;
319 for( std::size_t i1 = 0; i1 < n_2; ++i1, --i2 ) {
320 Vector temp = m_matrix[i1];
321
322 m_matrix[i1] = m_matrix[i2];
323 m_matrix[i2] = temp;
324 }
325}

Referenced by reverse().

◆ set() [1/2]

void GIDI::Matrix::set ( std::size_t a_row,
std::size_t a_column,
double a_value )
inline

Sets the cell at row a_row and column a_column to a_value.

Parameters
a_rowThe cell's row.
a_columnThe cell's row.
a_valueThe value to put in the cell.

Definition at line 158 of file GIDI_data.hpp.

161 { m_matrix[a_row][a_column] = a_value; }

Referenced by GIDI::Reaction::multiGroupProductMatrix().

◆ set() [2/2]

void GIDI::Matrix::set ( std::size_t a_row,
Vector const & a_vector )
inline

Sets the row at a_row to a_vector.

Parameters
a_rowThe row to set.
a_vectorThe Vector to set at row a_row.

Definition at line 163 of file GIDI_data.hpp.

165 { m_matrix[a_row] = a_vector; }

◆ size()

◆ transpose()

Matrix GIDI::Matrix::transpose ( )

Transposes the cells of this.

Definition at line 298 of file GIDI_matrix.cc.

298 {
299
300 std::size_t __numberOfColumns( numberOfColumns( ) );
301 Matrix __matrix( __numberOfColumns, size( ) );
302
303 for( std::size_t i1 = 0; i1 < size( ); ++i1 ) {
304 for( std::size_t i2 = 0; i2 < __numberOfColumns; ++i2 ) __matrix( i2, i1, (*this)[i1][i2] );
305 }
306 return( __matrix );
307}
std::size_t numberOfColumns() const

Referenced by GIDI::collapse().


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