CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

3D vector in OpenFOAM

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

Like Tree3Likes
  • 1 Post By ngj
  • 1 Post By ngj
  • 1 Post By wyldckat

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 8, 2013, 09:20
Default 3D vector in OpenFOAM
  #1
New Member
 
Join Date: Oct 2013
Posts: 19
Rep Power: 12
Daniel73 is on a distinguished road
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...
Daniel73 is offline   Reply With Quote

Old   December 8, 2013, 09:55
Default
  #2
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 21
Bernhard is on a distinguished road
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).
Bernhard is offline   Reply With Quote

Old   December 8, 2013, 10:06
Default
  #3
New Member
 
Join Date: Oct 2013
Posts: 19
Rep Power: 12
Daniel73 is on a distinguished road
Quote:
Originally Posted by Bernhard View Post
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 is offline   Reply With Quote

Old   December 8, 2013, 12:27
Default 3D vector in OpenFOAM
  #4
New Member
 
Join Date: Oct 2013
Posts: 19
Rep Power: 12
Daniel73 is on a distinguished road
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)

Last edited by Daniel73; December 8, 2013 at 13:59.
Daniel73 is offline   Reply With Quote

Old   December 8, 2013, 16:40
Default
  #5
New Member
 
Join Date: Oct 2013
Posts: 19
Rep Power: 12
Daniel73 is on a distinguished road
Quote:
Originally Posted by deepsterblue View Post
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?
Daniel73 is offline   Reply With Quote

Old   December 8, 2013, 21:22
Default
  #6
Senior Member
 
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25
deepsterblue will become famous soon enough
Here's the magic words:
#include <vector>
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue is offline   Reply With Quote

Old   December 9, 2013, 04:56
Default
  #7
New Member
 
Join Date: Oct 2013
Posts: 19
Rep Power: 12
Daniel73 is on a distinguished road
Quote:
Originally Posted by deepsterblue View Post
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...
Daniel73 is offline   Reply With Quote

Old   December 9, 2013, 16:42
Default
  #8
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
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
Daniel73 likes this.
__________________
Please note that I do not use the Friend-feature, so do not be offended, if I do not accept a request.
ngj is offline   Reply With Quote

Old   December 10, 2013, 01:56
Default
  #9
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 21
Bernhard is on a distinguished road
Quote:
Originally Posted by Daniel73 View Post
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 )
Bernhard is offline   Reply With Quote

Old   December 10, 2013, 06:11
Default
  #10
New Member
 
Join Date: Oct 2013
Posts: 19
Rep Power: 12
Daniel73 is on a distinguished road
Quote:
Originally Posted by Bernhard View Post
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.
Daniel73 is offline   Reply With Quote

Old   December 10, 2013, 07:01
Default
  #11
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Hi Danial,

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

Kind regards,

Niels
__________________
Please note that I do not use the Friend-feature, so do not be offended, if I do not accept a request.
ngj is offline   Reply With Quote

Old   December 10, 2013, 07:06
Default
  #12
New Member
 
Join Date: Oct 2013
Posts: 19
Rep Power: 12
Daniel73 is on a distinguished road
Quote:
Originally Posted by ngj View Post
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.
Daniel73 is offline   Reply With Quote

Old   December 10, 2013, 07:25
Default
  #13
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
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 likes this.
__________________
Please note that I do not use the Friend-feature, so do not be offended, if I do not accept a request.
ngj is offline   Reply With Quote

Old   December 10, 2013, 12:44
Default
  #14
New Member
 
Join Date: Oct 2013
Posts: 19
Rep Power: 12
Daniel73 is on a distinguished road
Quote:
Originally Posted by ngj View Post
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 ?
Daniel73 is offline   Reply With Quote

Old   December 10, 2013, 16:49
Default
  #15
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Greetings to all!

Quote:
Originally Posted by Bernhard View Post
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 View Post
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
__________________
wyldckat is offline   Reply With Quote

Old   December 12, 2013, 14:32
Default
  #16
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Thanks Bruno, I did not know how to visualise the point until know.

Cheers,

Niels
__________________
Please note that I do not use the Friend-feature, so do not be offended, if I do not accept a request.
ngj is offline   Reply With Quote

Old   January 21, 2014, 10:09
Default
  #17
New Member
 
Join Date: Oct 2013
Posts: 19
Rep Power: 12
Daniel73 is on a distinguished road
Quote:
Originally Posted by wyldckat View Post
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)
Daniel73 is offline   Reply With Quote

Old   January 21, 2014, 15:28
Default
  #18
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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
Daniel73 likes this.
__________________
wyldckat is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Issues with OpenFoam sanjibdsharma OpenFOAM 0 August 14, 2009 08:41
Problem installing OpenFOAM 1.5 installation on RHEL 4. vwsj84 OpenFOAM Installation 4 April 23, 2009 04:48
2009 OpenFOAM Summer School in Zagreb, Croatia hjasak OpenFOAM Announcements from Other Sources 0 March 27, 2009 12:08
64bitrhel5 OF installation instructions mirko OpenFOAM Installation 2 August 12, 2008 18:07
OpenFOAM Training and Workshop Hrvoje Jasak Main CFD Forum 0 October 7, 2005 07:14


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