Tensor (outer) product of vectors
Moderators: silvia, selimgunay, Moderators
Tensor (outer) product of vectors
I have to calculate tensor product of two vectors a and b as c=a*b'
I checked in Matrix and Vector class but could not find any function to obtain transpose of a vector, or to calculate outer/tensor product of a vector. Is there any function that can perform this task?
I also found a class Tensor which further includes BJtensor.h. However, when I try to include Tensor or BJtensor to myelement.h file using #include <Tensor.h>, it gives error because core folder does not have Tensor class files. Should I copy paste Tensor and BJtensor class from OpenSees svn? Where would I get header and .cpp files of this class?
I checked in Matrix and Vector class but could not find any function to obtain transpose of a vector, or to calculate outer/tensor product of a vector. Is there any function that can perform this task?
I also found a class Tensor which further includes BJtensor.h. However, when I try to include Tensor or BJtensor to myelement.h file using #include <Tensor.h>, it gives error because core folder does not have Tensor class files. Should I copy paste Tensor and BJtensor class from OpenSees svn? Where would I get header and .cpp files of this class?
Manish Kumar
Department of Civil, Structural and Environmental Engineering
University at Buffalo, The State University of New York
http://www.manishkumar.org
Department of Civil, Structural and Environmental Engineering
University at Buffalo, The State University of New York
http://www.manishkumar.org
Re: Tensor (outer) product of vectors
there is no existing method in the Vector class, one could simply be added.
as for the Tensor classes. They have been removed as no classes currently in the framework were using them.
as for the Tensor classes. They have been removed as no classes currently in the framework were using them.
Re: Tensor (outer) product of vectors
Thanks for the reply Frank.
I have added a function for a=b*c' for two-dimensional vectors in Vector class and working with that right now. In future would it be possible to add that function in Vector and Matrix classes? In fact a tensor operator(%) overloading to be added in Matrix and Vector classes to return a Matrix would be really helpful.
I have added a function for a=b*c' for two-dimensional vectors in Vector class and working with that right now. In future would it be possible to add that function in Vector and Matrix classes? In fact a tensor operator(%) overloading to be added in Matrix and Vector classes to return a Matrix would be really helpful.
Manish Kumar
Department of Civil, Structural and Environmental Engineering
University at Buffalo, The State University of New York
http://www.manishkumar.org
Department of Civil, Structural and Environmental Engineering
University at Buffalo, The State University of New York
http://www.manishkumar.org
Re: Tensor (outer) product of vectors
sure .. why don't you send me what you have written and i will just add that.
Re: Tensor (outer) product of vectors
Here it is, Frank. It's a very primitive function for two dimensional vector and matrices because that's what I need right now. May be in the future if I need it, I will write for n dimensional vectors and matrices.
Declaration to be added in Vector.h:
//methods added by Manish @ UB
Matrix operator%(const Vector &V) const;
Definition to be added in Vector.cpp:
Matrix Vector::operator%(const Vector &V) const
{
//returns M=A*B'
Matrix M(2,2);
M.Zero();
M(0,0)=theData[0]*V(0);
M(0,1)=theData[0]*V(1);
M(1,0)=theData[1]*V(0);
M(1,1)=theData[1]*V(1);
return M;
}
Declaration to be added in Vector.h:
//methods added by Manish @ UB
Matrix operator%(const Vector &V) const;
Definition to be added in Vector.cpp:
Matrix Vector::operator%(const Vector &V) const
{
//returns M=A*B'
Matrix M(2,2);
M.Zero();
M(0,0)=theData[0]*V(0);
M(0,1)=theData[0]*V(1);
M(1,0)=theData[1]*V(0);
M(1,1)=theData[1]*V(1);
return M;
}
Manish Kumar
Department of Civil, Structural and Environmental Engineering
University at Buffalo, The State University of New York
http://www.manishkumar.org
Department of Civil, Structural and Environmental Engineering
University at Buffalo, The State University of New York
http://www.manishkumar.org
Re: Tensor (outer) product of vectors
i would need a more general routine if i was to include it, this is too specific and limited.
Re: Tensor (outer) product of vectors
Hi Frank, here's a more generalized version:
Declaration to be added in Vector.h:
//methods added by Manish @ UB
Matrix operator%(const Vector &V) const;
Definition to be added in Vector.cpp:
Matrix Vector::operator%(const Vector &V) const
{
// if sizes are compatable add
#ifdef _G3DEBUG
if (sz != V.sz) {
// else sizes are incompatable, do nothing but warning
opserr << "WARNING Vector::tensor multiplication operator % - incompatable Vector sizes\n";
return -1;
}
#endif
//we want result=a*b'
Matrix result(sz,sz);
for (int i=0; i<sz; i++)
for (int j=0; j<sz; j++)
result(i,j)=theData[i]*V.theData[j];
return result;
}
Declaration to be added in Vector.h:
//methods added by Manish @ UB
Matrix operator%(const Vector &V) const;
Definition to be added in Vector.cpp:
Matrix Vector::operator%(const Vector &V) const
{
// if sizes are compatable add
#ifdef _G3DEBUG
if (sz != V.sz) {
// else sizes are incompatable, do nothing but warning
opserr << "WARNING Vector::tensor multiplication operator % - incompatable Vector sizes\n";
return -1;
}
#endif
//we want result=a*b'
Matrix result(sz,sz);
for (int i=0; i<sz; i++)
for (int j=0; j<sz; j++)
result(i,j)=theData[i]*V.theData[j];
return result;
}
Manish Kumar
Department of Civil, Structural and Environmental Engineering
University at Buffalo, The State University of New York
http://www.manishkumar.org
Department of Civil, Structural and Environmental Engineering
University at Buffalo, The State University of New York
http://www.manishkumar.org