CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Wrong Overloaded operator for tensor2D in foam-extend-4.1

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 16, 2019, 13:09
Default Wrong Overloaded operator for tensor2D in foam-extend-4.1
  #1
Senior Member
 
Santiago Lopez Castano
Join Date: Nov 2012
Posts: 354
Rep Power: 16
Santiago is on a distinguished road
Hi Guys I wonder whether someone has stumbled upon the following 'hiccup'>> I am performing the following operation:

Code:
 H +=
 (
        (1.0 + (dGrad & HdGrad) / dXdGrad) * (dx * dx) / dXdGrad
     - ((dx * HdGrad) + (HdGrad * dx)) / dXdGrad
  );
Where

Code:
 vector2D HdGrad, dx; tensor2D H;
And the rest scalars.
Once I go to compile the code, gcc complains:

Code:
/home/lopezsa/foam/foam-extend-4.1.1/src/foam/lnInclude/VectorSpaceI.H:201:13: note:   no known conversion for argument 1 from ‘Foam::Tensor<double>’ to ‘const Foam::VectorSpace<Foam::Tensor2D<double>, double, 4>&’
In file included from /home/lopezsa/foam/foam-extend-4.1.1/src/foam/lnInclude/Tensor2DTemplate.H:175:0,
                 from /home/lopezsa/foam/foam-extend-4.1.1/src/foam/lnInclude/tensor2D.H:38,
                 from MomentOfFluid.C:40:
/home/lopezsa/foam/foam-extend-4.1.1/src/foam/lnInclude/Tensor2DTemplateI.H: In instantiation of ‘typename Foam::outerProduct<Foam::Vector2D<Cmpt>, Foam::Vector2D<Cmpt> >::type Foam::operator*(const Foam::Vector2D<Cmpt>&, const Foam::Vector2D<Cmpt>&) [with Cmpt = double; typename Foam::outerProduct<Foam::Vector2D<Cmpt>, Foam::Vector2D<Cmpt> >::type = Foam::Tensor<double>]’:
Notice that it's complaining about the overloaded * (outerProduct) operator used for dx * dx and HdGrad * dx, returning a Tensor<double> instead of a Tensor2D<double>. Checking upon the definition of the overloaded operator in Tensor2DTemplateI.H I find no problems (!!!!)
Code:
//- Outer-product between two vectors
template<class Cmpt>
inline typename outerProduct<Vector2D<Cmpt>, Vector2D<Cmpt> >::type
operator*(const Vector2D<Cmpt>& v1, const Vector2D<Cmpt>& v2)
{
    return Tensor2D<Cmpt>
    (
        v1.x()*v2.x(), v1.x()*v2.y(),
        v1.y()*v2.x(), v1.y()*v2.y()
    );
}
If, instead, I go and define an inline function

Code:
inline tensor2D mult2DVects ( const vector2D& v1, const vector2D& v2)
{
  return tensor2D
  (
      v1.x()*v2.x(), v1.x()*v2.y(),
      v1.y()*v2.x(), v1.y()*v2.y()
  );
}
and use it place of the overloaded operator...

Code:
 H +=
 (
        (1.0 + (dGrad & HdGrad) / dXdGrad) * mult2DVects(dx, dx) / dXdGrad
     - (mult2DVects(dx, HdGrad) + mult2DVects(HdGrad, dx)) / dXdGrad
  );
... Everything compiles smoothly. I tried a small test in OpenFOAM and the overloading work as they should. It seems like if there were two overloaded * operators for vector2D, one returning Tensor2D's and another returning Tensor<double>... Who knows... anyway, any input is deeply appreciated.
Santiago is offline   Reply With Quote

Old   December 16, 2019, 13:17
Default One more interesting detail....
  #2
Senior Member
 
Santiago Lopez Castano
Join Date: Nov 2012
Posts: 354
Rep Power: 16
Santiago is on a distinguished road
If I change the inline function to

Code:
inline Tensor2D<double> mult2DVects ( const Vector2D<double>& v1, const Vector2D<double>& v2)
{
  return Tensor2D<double>
  (
      v1.x()*v2.x(), v1.x()*v2.y(),
      v1.y()*v2.x(), v1.y()*v2.y()
  );
}
The error described earlier comes up again (????????????????)
Santiago is offline   Reply With Quote

Old   December 17, 2019, 07:05
Default A small test proves said error
  #3
Senior Member
 
Santiago Lopez Castano
Join Date: Nov 2012
Posts: 354
Rep Power: 16
Santiago is on a distinguished road
If I go and compile the following simple code:
Code:
#include "argList.H"
#include "vector2D.H"
#include "tensor2D.H"

using namespace Foam;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

// Main program:

int main(int argc, char *argv[])
{
  vector2D a(0.1,0.2);
  vector2D b(1,2);

  tensor2D c; 
  c = a * b;

  Info << c;
}
The same compiler error appears!
Santiago is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using createPatch and cyclicAMI in FOAM Extend to create periodicbox manuc OpenFOAM Running, Solving & CFD 1 April 12, 2022 12:36
[mesh manipulation] RefineMesh Error and Foam warning jiahui_93 OpenFOAM Meshing & Mesh Conversion 4 March 3, 2018 12:32
udf error srihari FLUENT 1 October 31, 2016 15:18
[blockMesh] Axisymmetrical mesh Rasmus Gjesing (Gjesing) OpenFOAM Meshing & Mesh Conversion 10 April 2, 2007 15:00
[Gmsh] Import gmsh msh to Foam adorean OpenFOAM Meshing & Mesh Conversion 24 April 27, 2005 09:19


All times are GMT -4. The time now is 03:37.