#include <lac/dvector.h>
#include <math.h>
-dVector::dVector() : val(0)
-{
- dim=maxdim=0;
-}
+dVector::dVector() :
+ dim(0),
+ maxdim(0),
+ val(0)
+{}
-dVector::dVector(int n) : val(0)
+
+dVector::dVector(int n)
{
Assert (n>0, ExcInvalidNumber(n));
{
val = new double[maxdim];
Assert (val != 0, ExcOutOfMemory());
- (*this) = 0.;
+ clear ();
}
+ else
+ val = 0;
}
-dVector::dVector(const dVector& v) : val(0)
+
+dVector::dVector(const dVector& v)
{
dim = v.n();
maxdim = v.n();
{
val = new double[maxdim];
Assert (val != 0, ExcOutOfMemory());
- for (int i=0;i<dim;i++) val[i] = v.val[i];
+ for (int i=0; i<dim; i++)
+ val[i] = v.val[i];
}
+ else
+ val = 0;
}
+
+
void dVector::reinit(int n, int fast)
{
Assert (n>0, ExcInvalidNumber(n));
maxdim = n;
}
dim = n;
- if (!fast) (*this) = 0.;
+ if (!fast)
+ clear ();
}
+
+
void dVector::reinit(const dVector& v, int fast)
{
int n = v.n();
clear ();
}
+
+
dVector::~dVector()
{
if (val) delete[] val;
}
+
void dVector::cadd(int i, const VectorBase& V, double s, int j)
{
const dVector& v = (const dVector&) V;
val[i] += s*v.val[j];
}
+
+
void dVector::cadd(int i, const VectorBase& V, double s, int j, double t, int k)
{
const dVector& v = (const dVector&) V;
val[i] += s*v.val[j] + t*v.val[k] + q*v.val[l] + r*v.val[m];
}
+
+
void dVector::czero(int i)
{
Assert ((i>=0) && (i<dim), ExcInvalidIndex(i,dim));
val[i] = 0.;
}
+
+
void dVector::cequ(int i, const VectorBase& V, double s, int j)
{
const dVector& v = (const dVector&) V;
val[i] = s*v.val[j];
}
+
+
void dVector::cequ(int i, const VectorBase& V, double s, int j, double t, int k)
{
const dVector& v = (const dVector&) V;
val[i] = s*v.val[j] + t*v.val[k];
}
+
+
void dVector::cequ(int i, const VectorBase& V, double s, int j,
double t, int k, double q, int l, double r, int m)
{
val[i] = s*v.val[j] + t*v.val[k] + q*v.val[l] + r*v.val[m];
}
+
+
const char* dVector::name() const
{
return "dVector";
}
+
+
void dVector::print(FILE* f, const char* format) const
{
if (!format) format = " %5.2f";
- for (int j=0;j<n();j++) fprintf(f, format, val[j]);
+ for (int j=0;j<n();j++)
+ fprintf(f, format, val[j]);
fputc('\n',f);
}
+
+
void dVector::print(const char* format) const
{
if (!format) format = " %5.2f";
- for (int j=0;j<n();j++) printf (format, val[j]);
+ for (int j=0;j<n();j++)
+ printf (format, val[j]);
printf ("\n");
}
dim=maxdim=1;
val = new int[1];
Assert (val != 0, ExcOutOfMemory());
- val[0] = 0;
+ clear ();
}
iVector::iVector(int n)
maxdim = n;
val = new int[maxdim];
Assert (val != 0, ExcOutOfMemory());
- (*this) = 0;
+ clear ();
}
+
iVector::iVector(const iVector& v)
{
reinit(v.dim,1);
int i;
- for (i=0;i<dim;i++) val[i] = v.val[i];
+ for (i=0; i<dim; i++)
+ val[i] = v.val[i];
}
+
+
void iVector::reinit(int n, int fast)
{
Assert (n>0, ExcInvalidNumber(n));
maxdim = n;
}
dim = n;
- if (!fast) (*this) = 0;
+ if (!fast)
+ clear ();
}
+
+
void iVector::reinit(const iVector& v, int fast)
{
int n = v.n();
maxdim = n;
}
dim = n;
- if (!fast) (*this) = 0;
+ if (!fast)
+ clear ();
}
+
+
iVector::~iVector()
{
- delete[] val;
+ if (val)
+ delete[] val;
+}
+
+
+
+void iVector::clear () {
+ for (int i=0; i<dim; ++i)
+ val[i] = 0;
}
+
void iVector::add(const iVector& v)
{
- int i;
- for (i = 0; i < dim; i++) val[i] += v(i);
+ for (int i=0; i<dim; ++i) val[i] += v(i);
}
+
+
void iVector::add(int a, const iVector& v)
{
- int i;
- for (i = 0; i < dim; i++) val[i] += a * v(i);
+ for (int i=0; i<dim; ++i) val[i] += a * v(i);
}
+
+
void iVector::equ(int a, const iVector& u)
{
- int i;
- for (i=0;i<dim;i++) val[i] = a*u.val[i];
+ for (int i=0; i<dim; ++i) val[i] = a*u.val[i];
}
+
+
iVector& iVector::operator = (int s)
{
- int i;
// if (s==0.) memset(val,sizeof(*val) * dim, 0);
- for (i=0;i<dim;i++) val[i] = s;
+ for (int i=0; i<dim; ++i) val[i] = s;
return *this;
}
+
iVector& iVector::operator = (const iVector& v)
{
if (v.dim != dim) reinit(v,1);
- int i;
- for (i=0;i<dim;i++) val[i] = v.val[i];
+ for (int i=0; i<dim; ++i) val[i] = v.val[i];
return *this;
}