CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   3D vector in OpenFOAM (https://www.cfd-online.com/Forums/openfoam-programming-development/127304-3d-vector-openfoam.html)

Daniel73 December 8, 2013 09:20

3D vector in OpenFOAM
 
Hi,

I would like to put some value in a simple 3d vector.
Do you know why this fragment of code does not work?(No matching function Error...)

vector someVec;
for (int i = 1; i < 11; ++i) someVec(i, 1, 1) = 0;



Also do you know why i cannot #include some c++ standard library such as std::vector in openFoam? (by typing #include <vector> , i get some errors,,this is happened also when i want to include some other c++ std libraries like map...

Bernhard December 8, 2013 09:55

You would need
Code:

vector someVec(i,1,1);
to properly initialize in C++. As you write it, you are calling some function with the name someVec, which does not exist clearly (as your errormessage states).

Daniel73 December 8, 2013 10:06

Quote:

Originally Posted by Bernhard (Post 465336)
You would need
Code:

vector someVec(i,1,1);
to properly initialize in C++. As you write it, you are calling some function with the name someVec, which does not exist clearly (as your errormessage states).

I had initialized it before but it did not have any influence and again i got this error:

error: no match for call to ‘(Foam::vector {aka Foam::Vector<double>}) (int&, int, int)’
someVec(i, 1, 1) = 0;

Daniel73 December 8, 2013 12:27

3D vector in OpenFOAM
 
I need to define a 3D vector in OpenFOAM.
First,i tried to use std c++ vector library but #include <vector> gave me errors.
Second, i tried to use the foam vector,but It seems that the FOAM::vector does not act like as the std vector.For example in this fragment of code:

vector someVec(2,5,1);
Info << someVec.x() << " " << someVec.y() << endl ;

2 and 5 does not represent the index of the vector, but the value of the vector! (the output is : 2 5 )
If i use : vectorList vec; i get the error that vectorList did not declared in this scope.(i included the vectorList.H...)

Also including some other standard c++ library ,specially containers, gives me some errors.Is it correct way to use just : #include <aStdLibrary> ? (it works for iostream or cmath but not for containers)

Daniel73 December 8, 2013 16:40

Quote:

Originally Posted by deepsterblue (Post 327748)
There's nothing stopping you from using STL vectors - that's why namespaces were invented in the first place.

The vector class in OpenFOAM is defined in the 'Foam' namespace, so it's actually a Foam::vector class. To use the STL version, simply use std::vector, or even plain ::vector.

I would like to use a std c++ vector library by the command e.g std::vector<int> vec;
But I've got error that ‘vector’ is not a member of ‘std’.
Do you know how can i use the standard library of c++ in OpenFOAM?

deepsterblue December 8, 2013 21:22

Here's the magic words:
#include <vector>

Daniel73 December 9, 2013 04:56

Quote:

Originally Posted by deepsterblue (Post 465388)
Here's the magic words:
#include <vector>

I forgot to say that i included that, but no influence!
maybe because there exist the vector.h header of the openFoam in InInclude folder and this code does not include the std library...

ngj December 9, 2013 16:42

Hi Daniel,

I am not used to program using std, but if you want a list of 3d vectors, you can do as follows:

Code:

vectorField v(mySize);
Also, if you want an array of lists of vector, you can do as follows:

Code:

List<vectorField> listv(anotherSize);
Obviously, looping over listv and assigning a size to the vectorField is required.

Kind regards,

Niels

Bernhard December 10, 2013 01:56

Quote:

Originally Posted by Daniel73 (Post 465345)
I need to define a 3D vector in OpenFOAM

This is your third topic about this issue. What is it that you are exactly trying to achieve? Are you sure you need std::vector? There is likely a better solution in the OpenFOAM framework.

Thus, isn't this a XY problem? ( http://mywiki.wooledge.org/XyProblem )

Daniel73 December 10, 2013 06:11

Quote:

Originally Posted by Bernhard (Post 465621)
This is your third topic about this issue. What is it that you are exactly trying to achieve? Are you sure you need std::vector? There is likely a better solution in the OpenFOAM framework.

Thus, isn't this a XY problem? ( http://mywiki.wooledge.org/XyProblem )

Let me clear the problem.
I want to use std::vector in OpenFOAM but nobody knows why it is not working.Somebody in a forum as an answer of the question of another person told that use std::vector.But for me it does not work even by including(vector.h).
Therefore i asked him again but he did not know,so i asked it generally maybe somebody can help me with an alternative way which does similar for me.

ngj December 10, 2013 07:01

Hi Danial,

What is it you want to accomplish, which requires the use of std::vector?

Kind regards,

Niels

Daniel73 December 10, 2013 07:06

Quote:

Originally Posted by ngj (Post 465680)
Hi Danial,

What is it you want to accomplish, which requires the use of std::vector?

Kind regards,

Niels

I would like to save some coordinates in a vector, and be able to assign some value to this coordinates.
in std::vector i can use this way : vec(i,j,z)= some value ;
Now, as you told, im trying to use the List of vectors to save those coordinates but im thinking how to access each element of the list(a set of coordinate) to assign some value to that.

ngj December 10, 2013 07:25

The class

Code:

pointField
is specifically designed to handle 3D coordinates. This would be a straight forward variable type to use. Also, using pointField aids in the reading of the code.

Kind regards

Niels

Daniel73 December 10, 2013 12:44

Quote:

Originally Posted by ngj (Post 465684)
The class

Code:

pointField
is specifically designed to handle 3D coordinates. This would be a straight forward variable type to use. Also, using pointField aids in the reading of the code.

Kind regards

Niels

Thank you very much.
I've done it.
Just a question, is it possible to visualize that pointFields in paraview ?

wyldckat December 10, 2013 16:49

Greetings to all!

Quote:

Originally Posted by Bernhard (Post 465621)
This is your third topic about this issue.

Clean up complete. Daniel73's related posts and respective answers have been merged into this thread, from the other two threads, namely:
Quote:

Originally Posted by Daniel73 (Post 465772)
Just a question, is it possible to visualize that pointFields in paraview ?

This is a suitable question for the OpenFOAM Paraview & paraFoam... but anyway, the quick answer is: use the "Glyph" filter and use the "sphere" as the glyph.

Best regards,
Bruno

ngj December 12, 2013 14:32

Thanks Bruno, I did not know how to visualise the point until know.

Cheers,

Niels

Daniel73 January 21, 2014 10:09

Quote:

Originally Posted by wyldckat (Post 465805)
Greetings to all!


Clean up complete. Daniel73's related posts and respective answers have been merged into this thread, from the other two threads, namely:

This is a suitable question for the OpenFOAM Paraview & paraFoam... but anyway, the quick answer is: use the "Glyph" filter and use the "sphere" as the glyph.

Best regards,
Bruno

Dear wyldcat,

Thank you for your answer but i need to plot my pointField which was initialized in my code.this just has x and y value in that and i need to plot those coordinates in paraview.
I dont have any volVoctorField to have my coordinates on that to use glyph.(my coordinates don't match exactly on the cell's coordinates)

wyldckat January 21, 2014 15:28

Hi Daniel73,

Mmm... OK, if you can put the list of points and respective data into a CSV file, then you can:
  1. Open the CSV file in ParaView.
  2. Apply the filter "Table to Points".
  3. Then apply the filter "Plot Data".
    • In the display tab/section you can configure the data being plotted.
If you need more specific help, I'll need a more specific output example that needs to be plotted.

Best regards,
Bruno


All times are GMT -4. The time now is 05:55.