CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Elementwise multiplication operator (http://www.cfd-online.com/Forums/openfoam-solving/58538-elementwise-multiplication-operator.html)

johndeas September 19, 2008 11:08

Hi, I need an operator that
 
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

grtabor September 19, 2008 11:45

> myOperator.H:8: error: expec
 
> 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

bigphil May 14, 2012 09:45

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


All times are GMT -4. The time now is 09:22.