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

#include <GIDI_data.hpp>

Public Member Functions

 Vector (std::size_t a_number=0)
 Vector (std::vector< double > const &a_values)
 Vector (std::size_t a_number, double const *a_values)
 Vector (Vector const &a_vector)
 ~Vector ()
Vectoroperator= (Vector const &a_rhs)
std::size_t size () const
void resize (std::size_t a_number, double a_value=0.0)
std::vector< double > & data ()
double & operator[] (std::size_t a_index)
double operator[] (std::size_t a_index) const
Vector operator+ (double a_value) const
Vectoroperator+= (double a_value)
Vector operator+ (Vector const &a_rhs) const
Vectoroperator+= (Vector const &a_rhs)
Vector operator- (double a_value) const
Vectoroperator-= (double a_value)
Vector operator- (Vector const &a_rhs) const
Vectoroperator-= (Vector const &a_rhs)
Vector operator* (double a_value) const
Vectoroperator*= (double a_value)
Vector operator/ (double a_value) const
Vectoroperator/= (double a_value)
void reverse ()
void setToValueInFlatRange (std::size_t a_start, std::size_t a_end, double a_value)
double sum ()
void print (std::string const &a_prefix) const
void write (FILE *a_file, std::string const &a_prefix) const
void writeWithBoundaries (FILE *a_file, char const *a_format, std::vector< double > const &a_boundaries, double a_epsilon) const

Detailed Description

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

Definition at line 63 of file GIDI_data.hpp.

Constructor & Destructor Documentation

◆ Vector() [1/4]

GIDI::Vector::Vector ( std::size_t a_size = 0)
Parameters
a_size[in] Number of initial elements of the matrix. All elements are initialized to 0.

Definition at line 25 of file GIDI_vector.cc.

25 {
26
27 m_vector.resize( a_size, 0.0 );
28}

Referenced by operator*(), operator*=(), operator+(), operator+(), operator+=(), operator+=(), operator-(), operator-(), operator-=(), operator-=(), operator/(), operator/=(), operator=(), Vector(), and writeWithBoundaries().

◆ Vector() [2/4]

GIDI::Vector::Vector ( std::vector< double > const & a_values)
Parameters
a_values[in] A list of doubles to initialize this with.

Definition at line 35 of file GIDI_vector.cc.

35 {
36
37 m_vector = a_values;
38}

◆ Vector() [3/4]

GIDI::Vector::Vector ( std::size_t a_number,
double const * a_values )
Parameters
a_number[in] This number of element pointed to by a_values.
a_values[in] A list of doubles to initialize this with.

Definition at line 46 of file GIDI_vector.cc.

46 {
47
48 m_vector.resize( a_number );
49 for( std::size_t i1 = 0; i1 < a_number; ++i1 ) m_vector[i1] = a_values[i1];
50}

◆ Vector() [4/4]

GIDI::Vector::Vector ( Vector const & a_vector)
Parameters
a_vector[in] Vector to copy.

Definition at line 57 of file GIDI_vector.cc.

57 :
58 m_vector( a_vector.m_vector ) {
59
60}

◆ ~Vector()

GIDI::Vector::~Vector ( )

Definition at line 80 of file GIDI_vector.cc.

80 {
81
82}

Member Function Documentation

◆ data()

std::vector< double > & GIDI::Vector::data ( )
inline

Definition at line 81 of file GIDI_data.hpp.

81{ return( m_vector ); }

Referenced by GIDI::gridded1d2GIDI_Ys1d(), and GIDI::Functions::FissionEnergyRelease::multiGroupQ().

◆ operator*()

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

Returns a new Vector whose elements are this multiplied by a_value.

Parameters
a_value[in] The value to multiply each element by.
Returns
New Vector whose elements are this multiply by a_value.

Definition at line 219 of file GIDI_vector.cc.

219 {
220
221 Vector gidiVector( *this );
222
223 gidiVector *= a_value;
224 return( gidiVector );
225}
Vector(std::size_t a_number=0)

◆ operator*=()

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

Multiplies each element of this by a_value.

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

Definition at line 234 of file GIDI_vector.cc.

234 {
235
236 for( std::vector<double>::iterator iter = m_vector.begin( ); iter < m_vector.end( ); ++iter ) *iter *= a_value;
237
238 return( *this );
239}

◆ operator+() [1/2]

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

Returns a new Vector whose elements are this plus a_value.

Parameters
a_value[in] The value to add to each element.
Returns
New Vector whose elements are this plus a_value.

Definition at line 91 of file GIDI_vector.cc.

91 {
92
93 Vector gidiVector( *this );
94
95 gidiVector += a_value;
96 return( gidiVector );
97}

◆ operator+() [2/2]

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

Adds two Vectors.

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

Definition at line 120 of file GIDI_vector.cc.

120 {
121
122 Vector gidiVector( *this );
123
124 gidiVector += a_rhs;
125 return( gidiVector );
126}

◆ operator+=() [1/2]

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

Adds a_value to each element of this.

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

Definition at line 106 of file GIDI_vector.cc.

106 {
107
108 for( std::vector<double>::iterator iter = m_vector.begin( ); iter < m_vector.end( ); ++iter ) *iter += a_value;
109
110 return( *this );
111}

◆ operator+=() [2/2]

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

Adds a_rhs to this.

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

Definition at line 135 of file GIDI_vector.cc.

135 {
136
137 if( a_rhs.size( ) == 0 ) return( *this );
138
139 if( size( ) == 0 ) resize( a_rhs.size( ) );
140 if( size( ) != a_rhs.size( ) ) throw Exception( "vector sizes differ." );
141
142 std::size_t i1 = 0;
143 for( std::vector<double>::iterator iter = m_vector.begin( ); iter < m_vector.end( ); ++iter, ++i1 ) *iter += a_rhs[i1];
144
145 return( *this );
146}
std::size_t size() const
Definition GIDI_data.hpp:79
void resize(std::size_t a_number, double a_value=0.0)
Definition GIDI_data.hpp:80

◆ operator-() [1/2]

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

Returns a new Vector whose elements are this minus a_value.

Parameters
a_value[in] The value to subtract from each element.
Returns
New Vector whose elements are this plus a_value.

Definition at line 155 of file GIDI_vector.cc.

155 {
156
157 Vector gidiVector( *this );
158
159 gidiVector -= a_value;
160 return( gidiVector );
161}

◆ operator-() [2/2]

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

Subtracts a_rhs from this.

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

Definition at line 184 of file GIDI_vector.cc.

184 {
185
186 Vector gidiVector( *this );
187
188 gidiVector -= a_rhs;
189 return( gidiVector );
190}

◆ operator-=() [1/2]

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

Subtracts a_value from each element of this.

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

Definition at line 170 of file GIDI_vector.cc.

170 {
171
172 for( std::vector<double>::iterator iter = m_vector.begin( ); iter < m_vector.end( ); ++iter ) *iter -= a_value;
173
174 return( *this );
175}

◆ operator-=() [2/2]

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

Subtracts a_rhs to this.

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

Definition at line 199 of file GIDI_vector.cc.

199 {
200
201 if( a_rhs.size( ) == 0 ) return( *this );
202
203 if( size( ) == 0 ) resize( a_rhs.size( ) );
204 if( size( ) != a_rhs.size( ) ) throw Exception( "vector sizes differ." );
205
206 std::size_t i1 = 0;
207 for( std::vector<double>::iterator iter = m_vector.begin( ); iter < m_vector.end( ); ++iter, ++i1 ) *iter -= a_rhs[i1];
208
209 return( *this );
210}

◆ operator/()

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

Returns a new Vector whose elements are this divided by a_value.

Parameters
a_value[in] The value to divide each element by.
Returns
New Vector whose elements are this divided by a_value.

Definition at line 248 of file GIDI_vector.cc.

248 {
249
250 Vector gidiVector( *this );
251
252 gidiVector /= a_value;
253 return( gidiVector );
254}

◆ operator/=()

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

Divides each element of this by a_value.

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

Definition at line 263 of file GIDI_vector.cc.

263 {
264
265 if( a_value == 0 ) throw Exception( "divide by zero." );
266 for( std::vector<double>::iterator iter = m_vector.begin( ); iter < m_vector.end( ); ++iter ) *iter /= a_value;
267
268 return( *this );
269}

◆ operator=()

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

Returns a new Vector whose elements are this plus a_rhs.

Parameters
a_rhs[in] The value to add to each element.
Returns
New Vectors whose elements are this plus a_rhs.

Definition at line 69 of file GIDI_vector.cc.

69 {
70
71 if( this != &a_rhs ) {
72 m_vector = a_rhs.m_vector;
73 }
74
75 return( *this );
76}

◆ operator[]() [1/2]

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

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

Definition at line 83 of file GIDI_data.hpp.

◆ operator[]() [2/2]

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

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

Definition at line 84 of file GIDI_data.hpp.

◆ print()

void GIDI::Vector::print ( std::string const & a_prefix) const

Prints the contents of this to std::cout as one line prefixed with a_prefix.

Parameters
a_prefix[in] Prefix to add to line.

Definition at line 320 of file GIDI_vector.cc.

320 {
321
322 std::cout << a_prefix;
323 for( std::vector<double>::const_iterator iter = m_vector.begin( ); iter < m_vector.end( ); ++iter ) printf( "%19.11e", *iter );
324 std::cout << std::endl;
325}

◆ resize()

void GIDI::Vector::resize ( std::size_t a_number,
double a_value = 0.0 )
inline

Resizes this to a_number elements. For details, see std::vector.resize.

Definition at line 80 of file GIDI_data.hpp.

Referenced by MCGIDI::Functions::Gridded1d::Gridded1d(), operator+=(), operator-=(), and GIDI::parseFlattened1d().

◆ reverse()

void GIDI::Vector::reverse ( )

Reverse the elements of this.

Definition at line 275 of file GIDI_vector.cc.

275 {
276
277 std::size_t i2 = size( ), n_2 = i2 / 2;
278
279 --i2;
280 for( std::size_t i1 = 0; i1 < n_2; ++i1, --i2 ) {
281 double temp = m_vector[i1];
282
283 m_vector[i1] = m_vector[i2];
284 m_vector[i2] = temp;
285 }
286}

◆ setToValueInFlatRange()

void GIDI::Vector::setToValueInFlatRange ( std::size_t a_start,
std::size_t a_end,
double a_value )

Sets all elements in the range [a_start,a_end) to a_value.

Parameters
a_start[in] The starting flat-cell index of this to fill with a_value.
a_end[in] One after the last flat-cell index of this to fill with a_value.
a_value[in] The value to set each double in the range to.

Definition at line 296 of file GIDI_vector.cc.

296 {
297
298 a_end = std::min( a_end, m_vector.size( ) );
299 for( ; a_start < a_end; ++a_start ) m_vector[a_start] = a_value;
300}

◆ size()

◆ sum()

double GIDI::Vector::sum ( )

Returns the sum over the values of this.

Definition at line 305 of file GIDI_vector.cc.

305 {
306
307 double sum1 = 0.0;
308
309 for( std::size_t i1 = 0; i1 < size( ); ++i1 ) sum1 += m_vector[i1];
310
311 return( sum1 );
312}

◆ write()

void GIDI::Vector::write ( FILE * a_file,
std::string const & a_prefix ) const

Writes the contents of this to a_file as one line prefixed with a_prefix.

Parameters
a_file[in] A pointer to an opened C FILE instance where the data are to be written.
a_prefix[in] Prefix to add to line.

Definition at line 334 of file GIDI_vector.cc.

334 {
335
336 if( a_prefix.size( ) > 0 ) fprintf( a_file, "# %s\n", a_prefix.c_str( ) );
337 for( std::vector<double>::const_iterator iter = m_vector.begin( ); iter < m_vector.end( ); ++iter ) fprintf( a_file, "%19.11e\n", *iter );
338}

◆ writeWithBoundaries()

void GIDI::Vector::writeWithBoundaries ( FILE * a_file,
char const * a_format,
std::vector< double > const & a_boundaries,
double a_epsilon ) const

This method writes the contents of this to output a_file with each pair (boundary, value) as one line. Each line is written with the C printf style format as specified via the a_format arguement. If a_epsilon is zero then ( size() + 1 ) lines are printed with the last y-value being the last value in this. If a_epsilon is not zero then ( 2 * size() ) lines are printed with each boundary with index 1 to size() being print at first ( boundary[index] * ( 1 - a_epsilon ) ) and then ( boundary[index] * ( 1 + a_epsilon ) ) as :

 boundary[index] * ( 1 - a_epsilon ) ), this[index-1]
 boundary[index] * ( 1 + a_epsilon ) ), this[index]
Parameters
a_file[in] A pointer to an opened C FILE instance where the data are to be written.
a_format[in] A C printf style format to wrint one line of each (boundary, value) pair. Must include the line feed character.
a_boundaries[in] The list of boundaries. Must contain (size() + 1) values except for the case when size() is 0.
a_epsilon[in] Prefix to add to line.

Definition at line 357 of file GIDI_vector.cc.

357 {
358
359 if( size( ) == 0 ) {
360 if( a_boundaries.size( ) > 0 ) {
361 Vector vector( a_boundaries.size( ) - 1 );
362 vector.writeWithBoundaries2( a_file, a_format, a_boundaries, a_epsilon ); } }
363 else {
364 if( size( ) + 1 != a_boundaries.size( ) ) throw Exception( "Vector::writeWithBoundaries: Vector size and number of boundaries are not compatible." );
365 writeWithBoundaries2( a_file, a_format, a_boundaries, a_epsilon );
366 }
367}

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