CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Mesh Utilities (
-   -   Calculate cross product of mesh points and given vector (

DE25VT February 6, 2012 14:38

Calculate cross product of mesh points and given vector
1 Attachment(s)
Dear Foamers,

I am currently working on an application, which calculates the cross product of the mesh points and a given constant vector and then writes the new vector into a file.
Therefore I just want to read in the mesh points given in the constant/polyMesh direction and multiply those with my vector.
In the code I read in the points as a volVectorField, but in the points file in the polyMesh directory the points are a vectorField. So when I try to use my application I get the error:
unexpected class name vectorField expected volVectorField
while reading object points

But if I change from volVectorField to vectorField in my application, the compiler does not recognize the code for the cross product.
So I was wondering, if anyone could give me a tip, how to calculate with mesh points.
And what exactly is the difference between volVectorField and vectorField.
I had a look at the source code and couldn't find volVectorField, but in vectorField the operator I need to use is not defined.
It would be great if someone would answer.
Please find the file of the application attached.
I am using Foam version 2.1.0.


mturcios777 February 6, 2012 15:13

A volVectorField is a vector field that is defined on a volume mesh. Even though the operator for cross product isn't defined for the field as a whole, it should be relatively straightforward to step through the field and perform the operation vector by vector.

DE25VT February 7, 2012 10:27

Thank you for your help.
I was able to calculate the vectorField using a for-loop.
And afterwards putting the single vectors back together into a vectorField.
Do you know a way, how I can write out the field, like I can do with volVectorField, because I would like to have a look at the file at a later time and with the command used for volVectorField or volScalarField (see attached) I can not write out a vectorField.

volScalarField pPrime2
sqr(p - pMean)
How do I have to change this for a vectorField?

mturcios777 February 7, 2012 13:52

When you say the code you posted does not work, do you mean that the code doesn't compile or that you don't get the field written out the way you want to?

The process you need to follow to write out the fields is:

1) Create the vectorField , using a constructor similar to what you posted, but use the IOobject::NO_READ and IOobject::AUTO_WRITE options (look at the createFields.H of nearly any solver or utility for examples)

2) Perform your cross product calculation.

3) Write out the field either using the field.write() command, or with all the other fields by using the global write command.

Good luck!

DE25VT February 12, 2012 11:32

I tried using the same way to put out my vectorField given in all the solvers. Unfortunately, the operator I am using is not known this way, but Foam knows it, when instead of vectorField, I use volVectorField. So I am not sure whether that is the right way to get it done.
So right know I am having a look at BlockMesh, because this is similar to what I want, the field 'points' is a vectorField as well. So if I figure out how this works I can use it for my case.
Thank you for your help.
Ideas are always warmly welcomed.

potentialFoam January 13, 2016 11:05

Dear Foamers and/or DE25VT,

did you finally solve the problem?
I've got the same issue, I would like to write out a vectorField variable like I would do with a volVectorField variable:

volVectorField test = U;
if (mesh().time().outputTime())


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