Added copy constructors
git-svn-id: http://svn.sintef.no/trondheim/IFEM/trunk@848 e10b68d5-8a6e-419e-a041-bce267b0401d
This commit is contained in:
parent
86cff9c8c8
commit
2b8d092d3d
@ -1,4 +1,4 @@
|
|||||||
// $Id: Tensor.C,v 1.11 2010-12-20 13:52:42 kmo Exp $
|
// $Id$
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
//!
|
//!
|
||||||
//! \file Tensor.C
|
//! \file Tensor.C
|
||||||
@ -51,6 +51,13 @@ Tensor::Tensor (const std::vector<real>& t1, const std::vector<real>& t2) : n(3)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Tensor::Tensor (const Tensor& T) : n(T.n)
|
||||||
|
{
|
||||||
|
v.resize(n*n);
|
||||||
|
this->operator=(T);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Tensor& Tensor::operator= (const Tensor& T)
|
Tensor& Tensor::operator= (const Tensor& T)
|
||||||
{
|
{
|
||||||
if (v.size() == T.v.size())
|
if (v.size() == T.v.size())
|
||||||
@ -134,12 +141,10 @@ Tensor& Tensor::operator*= (real val)
|
|||||||
|
|
||||||
real Tensor::innerProd (const Tensor& T)
|
real Tensor::innerProd (const Tensor& T)
|
||||||
{
|
{
|
||||||
real value = 0.0;
|
real value = real(0);
|
||||||
if (v.size() == T.v.size()) {
|
if (v.size() == T.v.size())
|
||||||
std::vector<real> vec = T;
|
|
||||||
for (t_ind i = 0; i < v.size(); i++)
|
for (t_ind i = 0; i < v.size(); i++)
|
||||||
value += v[i]*vec[i];
|
value += v[i]*T.v[i];
|
||||||
}
|
|
||||||
else
|
else
|
||||||
std::cerr <<"Tensor::innerProd(const Tensor&): "
|
std::cerr <<"Tensor::innerProd(const Tensor&): "
|
||||||
<<"Not implemented for tensors of different size."<< std::endl;
|
<<"Not implemented for tensors of different size."<< std::endl;
|
||||||
@ -327,6 +332,13 @@ SymmTensor::SymmTensor (const std::vector<real>& vec) : Tensor(0)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SymmTensor::SymmTensor (const SymmTensor& T) : Tensor(0)
|
||||||
|
{
|
||||||
|
this->redim(T.n);
|
||||||
|
std::copy(T.v.begin(),T.v.end(),v.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Perform the triple matrix product \f[{\bf A} = {\bf T}^T{\bf A T}\f]
|
Perform the triple matrix product \f[{\bf A} = {\bf T}^T{\bf A T}\f]
|
||||||
where \b A = \a *this
|
where \b A = \a *this
|
||||||
@ -522,9 +534,9 @@ SymmTensor operator- (const SymmTensor& T, real a)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SymmTensor4::SymmTensor4 (const std::vector<real>& x, t_ind nsd) : v(x), n(nsd)
|
SymmTensor4::SymmTensor4 (const std::vector<real>& x, t_ind nsd)
|
||||||
|
: n(nsd), m(0), v(x)
|
||||||
{
|
{
|
||||||
m = 0;
|
|
||||||
if (n == 3)
|
if (n == 3)
|
||||||
m = 6;
|
m = 6;
|
||||||
else if (n == 2)
|
else if (n == 2)
|
||||||
@ -532,7 +544,7 @@ SymmTensor4::SymmTensor4 (const std::vector<real>& x, t_ind nsd) : v(x), n(nsd)
|
|||||||
else
|
else
|
||||||
std::cerr <<" *** Invalid fourth-order tensor, dim="<< n << std::endl;
|
std::cerr <<" *** Invalid fourth-order tensor, dim="<< n << std::endl;
|
||||||
|
|
||||||
if (v.size() < m*m)
|
if (v.size() < (size_t)m*m)
|
||||||
std::cerr <<" *** Invalid fourth-order tensor,"
|
std::cerr <<" *** Invalid fourth-order tensor,"
|
||||||
<<" matrix represention too small, size="<< v.size() << std::endl;
|
<<" matrix represention too small, size="<< v.size() << std::endl;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// $Id: Tensor.h,v 1.9 2010-11-18 11:22:10 kmo Exp $
|
// $Id$
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
//!
|
//!
|
||||||
//! \file Tensor.h
|
//! \file Tensor.h
|
||||||
@ -44,6 +44,8 @@ public:
|
|||||||
Tensor(const t_ind nsd) : n(nsd) { v.resize(n*n,real(0)); }
|
Tensor(const t_ind nsd) : n(nsd) { v.resize(n*n,real(0)); }
|
||||||
//! \brief Constructor creating a transformation from two tangent vectors.
|
//! \brief Constructor creating a transformation from two tangent vectors.
|
||||||
Tensor(const std::vector<real>& t1, const std::vector<real>& t2);
|
Tensor(const std::vector<real>& t1, const std::vector<real>& t2);
|
||||||
|
//! \brief Copy constructor.
|
||||||
|
Tensor(const Tensor& T);
|
||||||
|
|
||||||
//! \brief Set to 0-tensor.
|
//! \brief Set to 0-tensor.
|
||||||
void zero() { std::fill(v.begin(),v.end(),real(0)); }
|
void zero() { std::fill(v.begin(),v.end(),real(0)); }
|
||||||
@ -76,14 +78,14 @@ public:
|
|||||||
//! \brief Scaling operator.
|
//! \brief Scaling operator.
|
||||||
Tensor& operator*=(real val);
|
Tensor& operator*=(real val);
|
||||||
|
|
||||||
//! \brief Inner product
|
//! \brief Inner product of two tensors.
|
||||||
real innerProd(const Tensor& T);
|
real innerProd(const Tensor& T);
|
||||||
|
|
||||||
//! \brief Return the dimension of this tensor.
|
//! \brief Return the dimension of this tensor.
|
||||||
t_ind dim() const { return n; }
|
t_ind dim() const { return n; }
|
||||||
|
|
||||||
//! \brief Query whether this tensor is symmetric or not.
|
//! \brief Query whether this tensor is symmetric or not.
|
||||||
bool symmetric() const { return v.size() == n*(n+1)/2; }
|
bool symmetric() const { return v.size() == (size_t)(n*(n+1)/2); }
|
||||||
|
|
||||||
//! brief Query whether this tensor is zero within the given tolerance.
|
//! brief Query whether this tensor is zero within the given tolerance.
|
||||||
bool isZero(real tol = real(1.0e-6)) const;
|
bool isZero(real tol = real(1.0e-6)) const;
|
||||||
@ -153,6 +155,8 @@ public:
|
|||||||
SymmTensor(const t_ind nsd) : Tensor(nsd) { v.resize(n*(n+1)/2,real(0)); }
|
SymmTensor(const t_ind nsd) : Tensor(nsd) { v.resize(n*(n+1)/2,real(0)); }
|
||||||
//! \brief Constructor creating a symmetric tensor from a vector.
|
//! \brief Constructor creating a symmetric tensor from a vector.
|
||||||
SymmTensor(const std::vector<real>& vec);
|
SymmTensor(const std::vector<real>& vec);
|
||||||
|
//! \brief Copy constructor.
|
||||||
|
SymmTensor(const SymmTensor& T);
|
||||||
|
|
||||||
//! \brief Transpose the symmetric tensor (do nothing).
|
//! \brief Transpose the symmetric tensor (do nothing).
|
||||||
virtual Tensor& transpose() { return *this; }
|
virtual Tensor& transpose() { return *this; }
|
||||||
|
Loading…
Reference in New Issue
Block a user