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

Extract subset from array

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Ivan

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 1, 2015, 10:09
Default Extract subset from array
  #1
New Member
 
Ivan
Join Date: Aug 2012
Posts: 22
Rep Power: 13
Ivan is on a distinguished road
Hello,

I would like to perform a simple operation in OpenFOAM. I have a scalarList of n elements, V, and I would like to define a new reference list which points to a subset of V, i.e. all elements from V[k1] to V[k2]. Is there an easy and eficient way to do it? I have seen there is a "subset" function in ListOps.H, but I am still confused in how to use it.

Also, in a similar way, is V is a 2D array, how do I extract all the values of, let's say, the kth column?

Ivan
Ivan is offline   Reply With Quote

Old   August 4, 2015, 18:26
Default
  #2
New Member
 
Ivan
Join Date: Aug 2012
Posts: 22
Rep Power: 13
Ivan is on a distinguished road
Ok, found the solution. Let's say the new vector is called Vsub. Then you need to write,

SubSet<scalar> Vsub(V,size_of_subset,start_index); // V is of type scalarList

Vsub will not be a copy of the subset, but a pointer, which is exactly what I wanted.
You could obtain the same defining directly a pointer using standard c++ programming, but that is not safe as there is no check on the list bounds.
OpenFOAM will perform the size check instead (i.e. in Full Debug mode), which is what I wanted, plus other possible advantages of using OpenFOAM classes =).
mbookin likes this.
Ivan is offline   Reply With Quote

Reply


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
TimeVaryingMappedFixedValue best practice to extract subset points and fields podallaire OpenFOAM Running, Solving & CFD 6 May 21, 2014 10:25
[General] Contour plot: celldata2pointdata dmaz ParaView 1 April 28, 2014 16:05
[snappyHexMesh] Extracting a subset of features vkrastev OpenFOAM Meshing & Mesh Conversion 1 December 20, 2012 17:46
[General] extract Ids of point subset from a give triangular surface nacaairfoil ParaView 1 September 18, 2012 12:19
ODETest.C Compiling failed in version 1.6 sxhdhi OpenFOAM Bugs 4 April 27, 2010 05:36


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