CppNoddy  0.92
Loading...
Searching...
No Matches
Functions
Utils_Fill Namespace Reference

Functions

void time_seed ()
 initialise RNG More...
 
template<typename _Type >
void fill_identity (CppNoddy::Sequential_Matrix_base< _Type > &A)
 Fill diagonal with unit values. More...
 
template<typename _Type >
void fill_band (CppNoddy::Sequential_Matrix_base< _Type > &A, const int &offset, const _Type &value)
 Fill a diagonal band of a matrix. More...
 
template<typename _Type >
void fill (CppNoddy::DenseVector< _Type > &X, const _Type &value)
 Set all elements of a DENSE vector. More...
 
void fill_random (CppNoddy::SparseVector< double > &V, const unsigned &num_of_elts)
 
void fill_random (CppNoddy::SparseVector< std::complex< double > > &V, const unsigned &num_of_elts)
 
void fill_random (CppNoddy::DenseVector< double > &V)
 
void fill_random (CppNoddy::DenseVector< std::complex< double > > &V)
 
void fill_random (CppNoddy::DenseMatrix< double > &A)
 
void fill_random (CppNoddy::BandedMatrix< double > &A)
 

Function Documentation

◆ fill()

template<typename _Type >
void Utils_Fill::fill ( CppNoddy::DenseVector< _Type > &  X,
const _Type &  value 
)

Set all elements of a DENSE vector.

Parameters
XThe DENSE vector to be filled
valueThe value to be placed in each element of the vector

Definition at line 46 of file Utils_Fill.h.

46 {
47 for(std::size_t i = 0; i < X.size(); ++i) {
48 X[ i ] = value;
49 }
50 }
std::size_t size() const
A pass-thru definition to get the size of the vector.
Definition: DenseVector.h:330

References CppNoddy::DenseVector< _Type >::size().

◆ fill_band()

template<typename _Type >
void Utils_Fill::fill_band ( CppNoddy::Sequential_Matrix_base< _Type > &  A,
const int &  offset,
const _Type &  value 
)

Fill a diagonal band of a matrix.

Parameters
AThe matrix to be used
offsetThe offset of the band from the main diagonal e.g. 0 = main diagional, -1 = first sub-diagonal
valueThe value to be written to the band elements

Definition at line 34 of file Utils_Fill.h.

34 {
35 for (std::size_t row = 0; row < A.nrows(); ++row) {
36 if ((row + offset < A.ncols()) && (row + offset >= 0)) {
37 A(row, row + offset) = value;
38 }
39 }
40 }

Referenced by main().

◆ fill_identity()

template<typename _Type >
void Utils_Fill::fill_identity ( CppNoddy::Sequential_Matrix_base< _Type > &  A)

◆ fill_random() [1/6]

void Utils_Fill::fill_random ( CppNoddy::BandedMatrix< double > &  A)

Definition at line 103 of file Utils_Fill.h.

103 {
104 for(std::size_t row = 0; row < A.nrows(); ++row) {
105 for(std::size_t col = std::max((int)(row - A.noffdiag()), 0);
106 (int) col <= std::min((int)(row + A.noffdiag()), (int) A.ncols()); ++col) {
107 double x = (double) rand() / ((double) RAND_MAX + (double) 1) ;
108 A(row, col) = x;
109 }
110 }
111 }

◆ fill_random() [2/6]

void Utils_Fill::fill_random ( CppNoddy::DenseMatrix< double > &  A)

Definition at line 95 of file Utils_Fill.h.

95 {
96 CppNoddy::DenseVector<double> temp(A.ncols(), 0.0);
97 for(std::size_t row = 0; row < A.nrows(); ++row) {
98 fill_random(temp);
99 A[ row ] = temp;
100 }
101 }
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
void fill_random(CppNoddy::SparseVector< double > &V, const unsigned &num_of_elts)
Definition: Utils_Fill.h:53

References fill_random().

◆ fill_random() [3/6]

void Utils_Fill::fill_random ( CppNoddy::DenseVector< double > &  V)

Definition at line 77 of file Utils_Fill.h.

77 {
78 for(unsigned i = 0; i < V.size(); ++i) {
79 double x = (double) rand() /
80 ((double) RAND_MAX + (double) 1) ;
81 V[ i ] = x;
82 }
83 }
@ V
Definition: BVPKarman.cpp:20

References V.

◆ fill_random() [4/6]

void Utils_Fill::fill_random ( CppNoddy::DenseVector< std::complex< double > > &  V)

Definition at line 85 of file Utils_Fill.h.

85 {
86 for(unsigned i = 0; i < V.size(); ++i) {
87 double x = (double) rand() /
88 ((double) RAND_MAX + (double) 1) ;
89 double y = (double) rand() /
90 ((double) RAND_MAX + (double) 1) ;
91 V[ i ] = std::complex<double>(x, y);
92 }
93 }

References V.

◆ fill_random() [5/6]

void Utils_Fill::fill_random ( CppNoddy::SparseVector< double > &  V,
const unsigned &  num_of_elts 
)

Definition at line 53 of file Utils_Fill.h.

53 {
54 do {
55 double index = (double) rand() /
56 ((double) RAND_MAX + (double) 1) ;
57 index *= V.size();
58 double x = (double) rand() /
59 ((double) RAND_MAX + (double) 1) ;
60 V[(unsigned) index ] = x;
61 } while(V.nelts() < num_of_elts);
62 }

References V.

Referenced by fill_random(), and main().

◆ fill_random() [6/6]

void Utils_Fill::fill_random ( CppNoddy::SparseVector< std::complex< double > > &  V,
const unsigned &  num_of_elts 
)

Definition at line 64 of file Utils_Fill.h.

64 {
65 do {
66 double index = (double) rand() /
67 ((double) RAND_MAX + (double) 1) ;
68 index *= V.size();
69 double x = (double) rand() /
70 ((double) RAND_MAX + (double) 1) ;
71 double y = (double) rand() /
72 ((double) RAND_MAX + (double) 1) ;
73 V[(unsigned) index ] = std::complex<double>(x, y);
74 } while(V.nelts() < num_of_elts);
75 }

References V.

◆ time_seed()

void Utils_Fill::time_seed ( )

initialise RNG

Definition at line 14 of file Utils_Fill.h.

14 {
15 srand((unsigned) std::time(0));
16 }

Referenced by main().

© 2012

R.E. Hewitt