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

Elementwise multiplication operator

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   September 19, 2008, 11:08
Default Hi, I need an operator that
  #1
Senior Member
 
John Deas
Join Date: Mar 2009
Posts: 160
Rep Power: 7
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, 11:45
Default > myOperator.H:8: error: expec
  #2
Senior Member
 
Gavin Tabor
Join Date: Mar 2009
Posts: 183
Rep Power: 7
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, 09:45
Default
  #3
Senior Member
 
bigphil's Avatar
 
Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 496
Rep Power: 17
bigphil 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
bigphil is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ouput Variable Operator selim CFX 1 October 24, 2007 11:15
Operator Splitting. Maria. Main CFD Forum 5 September 17, 2005 22:10
Operator precedence hemph OpenFOAM 1 September 13, 2005 12:40
Vector multiplication and scaling in CFD-ACE/VIEW MK Main CFD Forum 0 August 29, 2005 18:11
a math operator in UDF lichun Dong FLUENT 7 June 18, 2005 22:04


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