CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   Openfoam coding question (

conceptone August 15, 2012 20:25

Openfoam coding question
Hi everyone, I have two questions in openfoam's coding. One is that if one variable is stated as the vector, so can it be a vector container e.g.
vector p=(
(1 2 3)
(4 5 6)
(7 8 9)
or just only used like (1 2 3)?
;the second is that if I wanna define a variable distance = mag(the z component of position-the z component of position0), I write the code as distance= mag(position.z()-position0.z()), where position and position is the vector type, but the compiler reports error, how should I make it? The original code is distance = mag(position()-position0()).

Bernhard August 16, 2012 02:09

Considering your first question.
No, a vector is a vector. It has three components. If you want to store multiple vectors in one variable, you should make a variable of type vectorList.

Your second question is vague. Post the code you have tried, and the error message you got, otherwise we can only guess.

ybapat August 16, 2012 02:43

About your second question :

You are trying to calculate mag(position.z()-position0.z()).You need not take magnitude as you will directly get scalar when you take difference of only z-coordinates.

Arnoldinho August 16, 2012 03:34

One comment on your first question: I think it depends on which 'vector' you are talking about. If it is the standard OF vector, then it has three components only. But if you consider the c++ vector, then this can have more entries, as it is more like a hashSet. A construct like

std::vector<std::vector<std::pair<label, double> > > movePointsCorrelation;
e.g. contains entries in a pair of label and double values, stored in a vector (list), which are further stored in a vector (list). These vectors can then even have different sizes.


All times are GMT -4. The time now is 02:31.