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

How to use the standard C++ vectors in OpenFOAM

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 12, 2011, 22:35
Default How to use the standard C++ vectors in OpenFOAM
  #1
New Member
 
Bruce Hartley
Join Date: Jun 2011
Posts: 9
Rep Power: 14
Bruce Hartley is on a distinguished road
I want to set up some standard C++ type vectors in OpenFoam but OpenFoam has defined its own type of a vector.

How do I use the stadard C++ definitions to set up a vector of a type which I have defined?

Something like vector<mystructure> variableName;

and use the standard C++ methods on this variable.
Bruce Hartley is offline   Reply With Quote

Old   October 12, 2011, 23:16
Default
  #2
Senior Member
 
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25
deepsterblue will become famous soon enough
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.
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue is offline   Reply With Quote

Old   January 29, 2015, 22:44
Default
  #3
Senior Member
 
Freedom
Join Date: May 2014
Posts: 209
Rep Power: 12
wenxu is on a distinguished road
Then how to convert OF scalarList to STL c++ vector<double>?
wenxu is offline   Reply With Quote

Old   January 30, 2015, 03:51
Default
  #4
Senior Member
 
Jens Höpken
Join Date: Apr 2009
Location: Duisburg, Germany
Posts: 159
Rep Power: 17
jhoepken is on a distinguished road
Send a message via Skype™ to jhoepken
There are simpler solutions for sure, but if anything else fails, just loop over the scalarList and set the particular element of the std::vector to the respective element of scalarList.
__________________
Blog: sourceflux.de/blog
"The OpenFOAM Technology Primer": sourceflux.de/book
Twitter: @sourceflux_de
Interested in courses on OpenFOAM?
jhoepken is offline   Reply With Quote

Old   January 30, 2015, 06:12
Default
  #5
Senior Member
 
Freedom
Join Date: May 2014
Posts: 209
Rep Power: 12
wenxu is on a distinguished road
Thank you!

Yes, because they in the different namespace, we can use std::vector<double> to substitute scalarList.
wenxu is offline   Reply With Quote

Reply

Tags
openfoam, standard c++, vectors


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
Compiling OpenFOAM on hpc-fe.gbar.dtu.dk kaergaard OpenFOAM Installation 1 June 16, 2011 01:33
OpenFOAM 1.5.x package - CentOS 5.3 x86_64 linnemann OpenFOAM Installation 7 July 30, 2009 03:14
64bitrhel5 OF installation instructions mirko OpenFOAM Installation 2 August 12, 2008 18:07
OpenFOAM Training in Europe and USA hjasak OpenFOAM 0 August 8, 2008 05:33
The OpenFOAM extensions project mbeaudoin OpenFOAM 16 October 9, 2007 09:33


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