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

Elementwise multiplication operator

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By bigphil

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 19, 2008, 12:08
Default Hi, I need an operator that
  #1
Senior Member
 
John Deas
Join Date: Mar 2009
Posts: 160
Rep Power: 17
johndeas is on a distinguished road
Hi,

I need an operator that behaves like Matlab .* which is an element-wise multiplication of two vectors. I would like it to be able to handle volVectorField.

For example (a,b,c) .* (A,B,C) = (aA,bB,cC)

I have written this:

volVectorField operator || (volVectorField a,volVectorField b)
{
volVectorField p;
p.component(vector::x)=a.component(vector::x)+b.co mponent(vector::x);
p.component(vector::y)=a.component(vector::y)+b.co mponent(vector::y);
p.component(vector::z)=a.component(vector::z)+b.co mponent(vector::z);
return p
};

but I got this error message:

SOURCE=myStatFoam.C ; g++ -m32 -Dlinux -DDP -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast -O3 -DNoRepository -ftemplate-depth-40 -I/home/flurec/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude -I/home/flurec/OpenFOAM/OpenFOAM-1.5/src/sampling/lnInclude -I/home/flurec/OpenFOAM/OpenFOAM-1.5/src/meshTools/lnInclude -IlnInclude -I. -I/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude -I/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OSspecific/Unix/lnInclude -fPIC -pthread -c $SOURCE -o Make/linuxGccDPOpt/myStatFoam.o
In file included from myStatFoam.C:42:
myOperator.H: In function 'Foam::volVectorField operator||(Foam::volVectorField, Foam::volVectorField)':
myOperator.H:3: error: no matching function for call to 'Foam::GeometricField<foam::vector<double>, Foam::fvPatchField, Foam::volMesh>::GeometricField()'
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:611: note: candidates are: Foam::GeometricField<type,>::GeometricField(const Foam::IOobject&, const Foam::GeometricField<type,>&, const Foam::wordList&) [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:576: note: Foam::GeometricField<type,>::GeometricField(const Foam::IOobject&, const Foam::GeometricField<type,>&, const Foam::word&) [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:545: note: Foam::GeometricField<type,>::GeometricField(const Foam::word&, const Foam::tmp<foam::geometricfield<type,> >&) [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:512: note: Foam::GeometricField<type,>::GeometricField(const Foam::word&, const Foam::GeometricField<type,>&) [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:480: note: Foam::GeometricField<type,>::GeometricField(const Foam::IOobject&, const Foam::GeometricField<type,>&) [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:448: note: Foam::GeometricField<type,>::GeometricField(const Foam::tmp<foam::geometricfield<type,> >&) [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:416: note: Foam::GeometricField<type,>::GeometricField(const Foam::GeometricField<type,>&) [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:378: note: Foam::GeometricField<type,>::GeometricField(const Foam::IOobject&, const typename GeoMesh::Mesh&, Foam::Istream&) [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:337: note: Foam::GeometricField<type,>::GeometricField(const Foam::IOobject&, const typename GeoMesh::Mesh&) [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:313: note: Foam::GeometricField<type,>::GeometricField(const Foam::IOobject&, const typename GeoMesh::Mesh&, const Foam::dimensionSet&, const Foam::Field<type>&, const Foam::PtrList<patchfield<type> >&) [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:283: note: Foam::GeometricField<type,>::GeometricField(const Foam::IOobject&, const typename GeoMesh::Mesh&, const Foam::dimensioned<type>&, const Foam::wordList&) [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:254: note: Foam::GeometricField<type,>::GeometricField(const Foam::IOobject&, const typename GeoMesh::Mesh&, const Foam::dimensioned<type>&, const Foam::word&) [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:227: note: Foam::GeometricField<type,>::GeometricField(const Foam::IOobject&, const typename GeoMesh::Mesh&, const Foam::dimensionSet&, const Foam::wordList&) [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:197: note: Foam::GeometricField<type,>::GeometricField(const Foam::IOobject&, const typename GeoMesh::Mesh&, const Foam::dimensionSet&, const Foam::word&) [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
myOperator.H:4: error: no matching function for call to 'Foam::GeometricField<foam::vector<double>, Foam::fvPatchField, Foam::volMesh>::component(<unresolved>)'
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:943: note: candidates are: Foam::tmp<foam::geometricfield<typename>::cmptType , PatchField, GeoMesh> > Foam::GeometricField<type,>::component(Foam::direc tion) const [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
myOperator.H:4: error: no matching function for call to 'Foam::GeometricField<foam::vector<double>, Foam::fvPatchField, Foam::volMesh>::component(<unresolved>)'
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:943: note: candidates are: Foam::tmp<foam::geometricfield<typename>::cmptType , PatchField, GeoMesh> > Foam::GeometricField<type,>::component(Foam::direc tion) const [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
myOperator.H:4: error: no matching function for call to 'Foam::GeometricField<foam::vector<double>, Foam::fvPatchField, Foam::volMesh>::component(<unresolved>)'
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:943: note: candidates are: Foam::tmp<foam::geometricfield<typename>::cmptType , PatchField, GeoMesh> > Foam::GeometricField<type,>::component(Foam::direc tion) const [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
myOperator.H:5: error: no matching function for call to 'Foam::GeometricField<foam::vector<double>, Foam::fvPatchField, Foam::volMesh>::component(<unresolved>)'
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:943: note: candidates are: Foam::tmp<foam::geometricfield<typename>::cmptType , PatchField, GeoMesh> > Foam::GeometricField<type,>::component(Foam::direc tion) const [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
myOperator.H:5: error: no matching function for call to 'Foam::GeometricField<foam::vector<double>, Foam::fvPatchField, Foam::volMesh>::component(<unresolved>)'
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:943: note: candidates are: Foam::tmp<foam::geometricfield<typename>::cmptType , PatchField, GeoMesh> > Foam::GeometricField<type,>::component(Foam::direc tion) const [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
myOperator.H:5: error: no matching function for call to 'Foam::GeometricField<foam::vector<double>, Foam::fvPatchField, Foam::volMesh>::component(<unresolved>)'
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:943: note: candidates are: Foam::tmp<foam::geometricfield<typename>::cmptType , PatchField, GeoMesh> > Foam::GeometricField<type,>::component(Foam::direc tion) const [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
myOperator.H:6: error: no matching function for call to 'Foam::GeometricField<foam::vector<double>, Foam::fvPatchField, Foam::volMesh>::component(<unresolved>)'
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:943: note: candidates are: Foam::tmp<foam::geometricfield<typename>::cmptType , PatchField, GeoMesh> > Foam::GeometricField<type,>::component(Foam::direc tion) const [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
myOperator.H:6: error: no matching function for call to 'Foam::GeometricField<foam::vector<double>, Foam::fvPatchField, Foam::volMesh>::component(<unresolved>)'
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:943: note: candidates are: Foam::tmp<foam::geometricfield<typename>::cmptType , PatchField, GeoMesh> > Foam::GeometricField<type,>::component(Foam::direc tion) const [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
myOperator.H:6: error: no matching function for call to 'Foam::GeometricField<foam::vector<double>, Foam::fvPatchField, Foam::volMesh>::component(<unresolved>)'
/home/flurec/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricField.C:943: note: candidates are: Foam::tmp<foam::geometricfield<typename>::cmptType , PatchField, GeoMesh> > Foam::GeometricField<type,>::component(Foam::direc tion) const [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
myOperator.H:8: error: expected ';' before '}' token
createAverages.H: In function 'int main(int, char**)':
createAverages.H:312: warning: unused variable 'Umean'
createAverages.H:313: warning: unused variable 'R'
make: *** [Make/linuxGccDPOpt/myStatFoam.o] Error 1

Could you help me, as I am going to need it extensively.

JD
johndeas is offline   Reply With Quote

Old   September 19, 2008, 12:45
Default > myOperator.H:8: error: expec
  #2
Senior Member
 
Gavin Tabor
Join Date: Mar 2009
Posts: 181
Rep Power: 17
grtabor is on a distinguished road
> myOperator.H:8: error: expected ';' before '}' token

You missed a semicolon after "return p"!

> myOperator.H:3: error: no matching function for call to 'Foam::GeometricField<foam::vector<double>, Foam::fvPatchField, Foam::volMesh>::GeometricField()'

Also (and more significantly) volVectorField doesnt have a null constructor.

I assume you wanted multiplications rather than additions on lines 4,5,6?

There also seems to be something wrong with the way you are accessing the components, but I'm not quite sure what

Gavin
grtabor is offline   Reply With Quote

Old   May 14, 2012, 10:45
Default
  #3
Super Moderator
 
bigphil's Avatar
 
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,097
Rep Power: 34
bigphil will become famous soon enoughbigphil will become famous soon enough
Hi JD,

Were you successful in implementing a element-wise multiplication operator?

I would like a tensor element-wise multiplication with another tensor.

Actually one of the tensors is the identity - I essentially want to set the off-diagonals of a tensor to zero. I am open to any suggestions other people might have?
At the moment I use a forAll loop through all the cells of the volTensorField.

Best regards,
Philip
hlf4223355 likes this.
bigphil is offline   Reply With Quote

Old   March 9, 2019, 14:03
Default
  #4
New Member
 
Luofeng
Join Date: May 2016
Posts: 5
Rep Power: 10
hlf4223355 is on a distinguished road
solution found?
hlf4223355 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
Ouput Variable Operator selim CFX 1 October 24, 2007 12:15
Operator Splitting. Maria. Main CFD Forum 5 September 17, 2005 23:10
Operator precedence hemph OpenFOAM 1 September 13, 2005 13:40
Vector multiplication and scaling in CFD-ACE/VIEW MK Main CFD Forum 0 August 29, 2005 19:11
a math operator in UDF lichun Dong FLUENT 7 June 18, 2005 23:04


All times are GMT -4. The time now is 20:30.