HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
StdVecOps Namespace Reference

Functions

long sum (const std::vector< int > &a_iv)
 
long product (const std::vector< int > &a_iv)
 
void copyFrom (std::vector< int > &a_iv, const int *const a_iv_carr, int a_n)
 
void add (std::vector< int > &a_iv, const int a_a)
 
void copyFrom (std::vector< double > &a_iv, const double *const a_iv_carr, int a_n)
 
void createNormalVector (std::vector< double > &a_normal_vec, const int *a_vec, const int a_size)
 
void createNormalVector (std::vector< double > &a_normal_vec, const std::vector< int > &a_vec)
 
double compute2Norm (const std::vector< double > &a_a, const std::vector< double > &a_b)
 

Detailed Description

Vector operations defined for the std::vector class

Function Documentation

◆ sum()

long StdVecOps::sum ( const std::vector< int > &  a_iv)
inline

Sum of all elements

Parameters
a_ivInteger vector

Definition at line 18 of file std_vec_ops.h.

19  {
20  long retval(0);
21  for (int i=0; i<a_iv.size(); i++) retval += a_iv[i];
22  return retval;
23  }

◆ product()

long StdVecOps::product ( const std::vector< int > &  a_iv)
inline

Product of all elements

Parameters
a_ivInteger vector

Definition at line 27 of file std_vec_ops.h.

28  {
29  long retval(1);
30  for (int i=0; i<a_iv.size(); i++) retval *= a_iv[i];
31  return retval;
32  }

◆ copyFrom() [1/2]

void StdVecOps::copyFrom ( std::vector< int > &  a_iv,
const int *const  a_iv_carr,
int  a_n 
)
inline

Copy from a C-array

Parameters
a_ivC++ vector of ints
a_iv_carrC array of ints
a_nsize

Definition at line 36 of file std_vec_ops.h.

40  {
41  a_iv.resize(a_n);
42  for (int i=0; i<a_n; i++) a_iv[i] = a_iv_carr[i];
43  return;
44  }

◆ add()

void StdVecOps::add ( std::vector< int > &  a_iv,
const int  a_a 
)
inline

Add constant to all elements of a vector

Parameters
a_ivC++ vector of ints
a_aconstant to add

Definition at line 48 of file std_vec_ops.h.

50  {
51  for (int i=0; i<a_iv.size(); i++) a_iv[i] += a_a;
52  return;
53  }

◆ copyFrom() [2/2]

void StdVecOps::copyFrom ( std::vector< double > &  a_iv,
const double *const  a_iv_carr,
int  a_n 
)
inline

Copy from a C-array

Parameters
a_ivC++ vector of doubles
a_iv_carrC array of doubles
a_nsize

Definition at line 57 of file std_vec_ops.h.

61  {
62  a_iv.resize(a_n);
63  for (int i=0; i<a_n; i++) a_iv[i] = a_iv_carr[i];
64  return;
65  }

◆ createNormalVector() [1/2]

void StdVecOps::createNormalVector ( std::vector< double > &  a_normal_vec,
const int *  a_vec,
const int  a_size 
)
inline

Create a normal vector of doubles (of unit magnitude) from a C-array of integers

Parameters
a_normal_vecNormal vector
a_vecC-array of integers
a_sizesize of C-array

Definition at line 70 of file std_vec_ops.h.

73  {
74  a_normal_vec = std::vector<double>(a_size, 0.0);
75  double magn = 0.0;
76  for (int i=0; i<a_size; i++) {
77  magn += (double)(a_vec[i]*a_vec[i]);
78  }
79  magn = sqrt(magn);
80  if (magn > _MACHINE_ZERO_) {
81  for (int i=0; i<a_size; i++) {
82  a_normal_vec[i] = a_vec[i] / magn;
83  }
84  }
85  return;
86  }
#define _MACHINE_ZERO_
Definition: basic.h:26

◆ createNormalVector() [2/2]

void StdVecOps::createNormalVector ( std::vector< double > &  a_normal_vec,
const std::vector< int > &  a_vec 
)
inline

Create a normal vector of doubles (of unit magnitude) from a vector of integers

Parameters
a_normal_vecNormal vector
a_vecInteger vector

Definition at line 91 of file std_vec_ops.h.

93  {
94  createNormalVector( a_normal_vec,
95  a_vec.data(),
96  a_vec.size() );
97  return;
98  }
void createNormalVector(std::vector< double > &a_normal_vec, const std::vector< int > &a_vec)
Definition: std_vec_ops.h:91

◆ compute2Norm()

double StdVecOps::compute2Norm ( const std::vector< double > &  a_a,
const std::vector< double > &  a_b 
)
inline

Compute norm between two vectors

Parameters
a_ainput vector
a_binput vector

Definition at line 102 of file std_vec_ops.h.

104  {
105  double retval = 0.0;
106 
107  for (int i = 0; i < std::min(a_a.size(),a_b.size()); i++) {
108  retval += ( (a_a[i]-a_b[i]) * (a_a[i]-a_b[i]) );
109  }
110  retval = sqrt(retval);
111 
112  return retval;
113  }
#define min(a, b)
Definition: math_ops.h:14