|
[Sponsors] |
August 1, 2015, 10:09 |
Extract subset from array
|
#1 |
New Member
Ivan
Join Date: Aug 2012
Posts: 22
Rep Power: 13 |
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 |
|
August 4, 2015, 18:26 |
|
#2 |
New Member
Ivan
Join Date: Aug 2012
Posts: 22
Rep Power: 13 |
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 =). |
|
|
|
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 |