VecDouble Class Reference

#include <vecdouble.h>

Inheritance diagram for VecDouble:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 VecDouble ()
 VecDouble (const VecDouble &v)
 VecDouble (unsigned n)
 VecDouble (const Point< 3 > &p)
 VecDouble (const Point< 2 > &p)
 VecDouble (const Point< 1 > &p)
 VecDouble (const std::vector< double > &p)
bool is_owner ()
void swap (VecDouble &v)
void reinit (const unsigned int N, const bool fast=false)
virtual void reinit (const VecDouble &V, const bool fast=false)
VecDoubleoperator= (const VecDouble &v)
VecDoubleoperator= (const Vector< double > &v)
VecDoubleoperator= (const BlockVector< double > &v)
void operator= (double dd)
void copyRow (unsigned row, Matrix &M)
void getMinMaxValues (double *min, double *max) const
void set (double d1, double d2)
void setRef (double *p, unsigned size)
void setRef (Vector< double > &v)
virtual ~VecDouble ()
void term_mult (const VecDouble &v1, const VecDouble &v2)

Protected Attributes

bool m_owner

Friends

class ArrayOfVecDouble
class VecIncBC

Detailed Description

VecDouble This class is an extension of the dealII Vector<double> It has a minor difference though. In the usual way the Vector always allocate and deallocate its own memory. Although this is always the safest way, sometimes making the vector to point to someone memory is pretty pretty attractive for efficiency purposes. The old duel between efficiency and manutenability of code.

So this extension of the Vector class, allows the Vector to switch to reference mode. This mode is triggered when the user call setRef method. This is dangerous specially if the user passes a place in memory that does not correspond to the vector size. Segmentation fault may result from that or worse, set a location in memory that belongs to another variable. That why for security measures, once the vector enters this mode, it is not possible anymore to cast it to its base class dealII or even reinitialize the vector. In other words, once the object enters reference mode it cannot own any memory again in its entire lifetime. Also the method setRef is private and can be accessed only by its friend classes. This is done to discourage the use of such method by other programmers. Shallow copy might result in some very nasty errors and sometimes bugs that consumes months of development. So shallow copy can be used here only for some very few and crucial parts of the code and only there.

Right now the only class that is a friend is ArrayOfVecDouble class

Definition at line 38 of file vecdouble.h.


Constructor & Destructor Documentation

VecDouble::VecDouble (  ) 

Definition at line 163 of file vecdouble.cpp.

00164 {
00165   m_owner=true;
00166 }

VecDouble::VecDouble ( const VecDouble v  ) 

Definition at line 17 of file vecdouble.cpp.

00018    :Vector<double>(v)
00019  {
00020    m_owner=true;
00021  }

VecDouble::VecDouble ( unsigned  n  ) 

Definition at line 60 of file vecdouble.cpp.

00061    :Vector<double>(n)
00062  {
00063    m_owner=true;
00064 }

VecDouble::VecDouble ( const Point< 3 > &  p  ) 

Definition at line 35 of file vecdouble.cpp.

00036 {
00037   m_owner=true;
00038   Point<3> &paux = const_cast<Point<3>& >(p);
00039   setRef(&(paux[0]),3);
00040 }

VecDouble::VecDouble ( const Point< 2 > &  p  ) 

Definition at line 42 of file vecdouble.cpp.

00043 {
00044   m_owner=true;
00045   Point<2> &paux = const_cast<Point<2>& >(p);
00046   setRef(&(paux[0]),2);
00047 }

VecDouble::VecDouble ( const Point< 1 > &  p  ) 

Definition at line 49 of file vecdouble.cpp.

00050 {
00051   m_owner=true;
00052   Point<1> &paux = const_cast<Point<1>& >(p);
00053   setRef(&(paux[0]),1);
00054 }

VecDouble::VecDouble ( const std::vector< double > &  p  ) 

Definition at line 23 of file vecdouble.cpp.

00024 {
00025   m_owner=true;
00026   reinit(p.size());
00027   for (unsigned i=0;i<p.size();i++)
00028   {
00029     operator()(i)=p[i];
00030   }
00031 }

VecDouble::~VecDouble (  )  [virtual]

Definition at line 8 of file vecdouble.cpp.

00009 {
00010   if (!m_owner)
00011   {
00012     val=0;
00013     max_vec_size = vec_size = 0;
00014   }
00015 }


Member Function Documentation

void VecDouble::copyRow ( unsigned  row,
Matrix M 
)

Definition at line 210 of file vecdouble.cpp.

00211 {
00212    assert(M.n() == size());
00213   for (unsigned i=0;i<size();i++)
00214   {
00215     (*this)(i)=M(row,i);
00216   }
00217 }

void VecDouble::getMinMaxValues ( double *  min,
double *  max 
) const

Definition at line 180 of file vecdouble.cpp.

00181 {
00182   assert(size() != 0);
00183   *min=*max=(*this)(0);
00184   for (unsigned i=1;i<size();i++)
00185   {
00186     if ((*this)(i) < *min)
00187       *min=operator()(i);
00188     if ((*this)(i) > *max)
00189       *max=operator()(i);
00190   }
00191 
00192 }

bool VecDouble::is_owner (  )  [inline]

Definition at line 57 of file vecdouble.h.

00057 {return m_owner;}

void VecDouble::operator= ( double  dd  ) 

Definition at line 156 of file vecdouble.cpp.

00157 {
00158   if (vec_size!=0)
00159     std::fill (begin(), end(), dd);
00160 }

VecDouble & VecDouble::operator= ( const BlockVector< double > &  v  ) 

Definition at line 101 of file vecdouble.cpp.

00102 {
00103   /*
00104     This method is valid only if the vector owns its memory
00105     or in the case that both vectors have equal size
00106   */
00107   assert(m_owner || (v.size() == size()) );
00108   Vector<double>::operator=(v);
00109   return *this;
00110 }

VecDouble & VecDouble::operator= ( const Vector< double > &  v  ) 

Definition at line 113 of file vecdouble.cpp.

00114 {
00115   assert(m_owner || (v.size() == size()) );
00116   Vector<double>::operator=(v);
00117   return *this;
00118 }

VecDouble & VecDouble::operator= ( const VecDouble v  ) 

Definition at line 90 of file vecdouble.cpp.

00091 {
00092   /*
00093     This method is valid only if the vector owns its memory
00094     or in the case that both vectors have equal size
00095   */
00096   assert(m_owner || (v.size() == size()) );
00097   Vector< double >::operator=(v);  
00098   return *this;
00099 }

void VecDouble::reinit ( const VecDouble V,
const bool  fast = false 
) [virtual]

Definition at line 78 of file vecdouble.cpp.

00079 {
00080   reinit(V.size(),fast);
00081 } 

void VecDouble::reinit ( const unsigned int  N,
const bool  fast = false 
)

Definition at line 68 of file vecdouble.cpp.

00069 {
00070   if (!m_owner)
00071   {
00072     throw new Exception("VecDouble::reinit Attemp to reinit a vector that does not own its memory\n");
00073   }
00074   Vector<double>::reinit(N,fast);
00075 }

void VecDouble::set ( double  d1,
double  d2 
)

Definition at line 221 of file vecdouble.cpp.

00222 {
00223   reinit(2);
00224   operator()(0)=d1;
00225   operator()(1)=d2;
00226 }

void VecDouble::setRef ( Vector< double > &  v  ) 

Definition at line 146 of file vecdouble.cpp.

00147 {
00148   setRef(&(v(0)),v.size());
00149 }

void VecDouble::setRef ( double *  p,
unsigned  size 
)

Make the vector to point to someone else memory. Once this function is called, the object is forbidden to allocate memory by its own during its hole like.

Parameters:
p 
size 
Returns:

Reimplemented in VecDoubleRef.

Definition at line 129 of file vecdouble.cpp.

00130 {
00131   if (m_owner)
00132   {
00133     reinit(0);
00134   }
00135   m_owner=false;
00136   val=p;
00137   max_vec_size=vec_size=size;
00138 }

void VecDouble::swap ( VecDouble v  ) 

Definition at line 83 of file vecdouble.cpp.

00084 {
00085   Vector<double>::swap(v);
00086   std::swap(m_owner,v.m_owner);
00087 }

void VecDouble::term_mult ( const VecDouble v1,
const VecDouble v2 
)

Definition at line 195 of file vecdouble.cpp.

00196 {
00197   assert(v1.size() == v2.size());
00198   assert(v1.size() == size());
00199   const double *d1 = v1.val;
00200   const double *d2 = v2.val;
00201   double *d3 = &(operator()(0));
00202   for (unsigned i=0;i<v1.size();i++)
00203   {
00204     *d3++=*d1++ * *d2++;
00205   }
00206 }


Friends And Related Function Documentation

friend class ArrayOfVecDouble [friend]

Definition at line 40 of file vecdouble.h.

friend class VecIncBC [friend]

Definition at line 41 of file vecdouble.h.


Member Data Documentation

bool VecDouble::m_owner [protected]

Definition at line 46 of file vecdouble.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Sun Apr 8 23:13:33 2012 for CO2INJECTION by  doxygen 1.6.3