CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How to use List< List<vector> > (http://www.cfd-online.com/Forums/openfoam-programming-development/124626-how-use-list-list-vector.html)

 HakikiCanakkaleli October 9, 2013 11:12

How to use List< List<vector> >

Hi,

== 1 ==

I defined the following list of the list of vectors.

Code:

`List< List<vector> > example(...);`
== 2 ==

I populate this with a number of lists of vectors. e.g. list1, list2, list3 ... etc.

== 3 ==

The question is that how I can reach one of the vectors inside example?

For example, I can reach the 3rd vector inside a "List<vector> other_example" like that:

Code:

`Info << other_example[2] << endl;`
But I couldn't achieve the same task for the list< list<vector> >.

== 4 ==

In the end, I would like to use this example list of lists in for loops so that I can do some algeabraic operation with them.

Many thanks for any help in advance.

 JNSN October 10, 2013 04:33

have you tried
Code:

`anotherExample[2][0]`
?

 JNSN October 10, 2013 05:01

Code:

```    vector exampleVector = vector::zero;     Info << "vector:" << tab << exampleVector << endl;     scalar listLength(5);     List<vector> exampleVectorList(listLength,vector::zero);     forAll(exampleVectorList, i)     {         vector& v = exampleVectorList[i];         v = vector(i,2*i,3*i);         Info << "vector:" << tab << v << endl;     }     Info << endl << endl;     List<List<vector> > exampleVectorListList(listLength,exampleVectorList);     forAll(exampleVectorListList,i)     {         List<vector>& vList = exampleVectorListList[i];         forAll(vList,j)         {             vector& v = vList[j];             Info << "vector:" << tab << v << endl;         }     }```

 HakikiCanakkaleli October 10, 2013 05:28

Many thanks for this reply.

I had tried example[2][0] at the first hand; but, it seems I misunderstood the error message. Now, it confirmed that I made some other mistake. Many thanks.

 All times are GMT -4. The time now is 13:30.