CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Vector Declaration (https://www.cfd-online.com/Forums/openfoam/77210-vector-declaration.html)

tonyuprm June 16, 2010 11:15

Vector Declaration
 
Hi,

I'm trying to declare a vector list inside a for loop while reading vectors from another list. Here is the for loop. I'm getting an error on the vector delcaration.

for(int c=0; c<turbNum ;c++) {

List<List<vector> > nacHubGrd[c,0]=nacLocation[c];

Info<<nacHubGrd<<endl;

}

Apparently I need to declare the size of the List. I'm not sure how to do this.

I appreciate any help! Thanks!

herbert June 17, 2010 02:49

Hi Tony,

you have to declare and initialize your field before accessing single columns. A vectorListList of size nxm can be declared and initialized zero as follows:
Code:

List<List<vector> > nacHubGrd (n, List<vector>(m, vector::zero))
Its working top down and tells you that your vectorListList is set to size n and is holding vectorLists of size m which are holding vectors. You can access single columns by e.g.
Code:

nacHubGrad[i][j]    //one single vector
nacHubGrad[i]        // one of the vectorLists

Regards,
Stefan

tonyuprm June 17, 2010 11:27

Thanks a lot Stefan, that worked perfectly!

ok, now it's getting a little bit more complicated and I need to do another list. Im trying:

List<List<List<vector> > > bladePoints (turbNum,bladeNum, List<vector>(3, vector::zero));

but its not working,

Any suggestions?

Thanks!

boger June 18, 2010 08:21

It's proof by induction! Actually, it is just a simple extension of Stefan's example, but maybe formatting it a little differently will help you to understand:

Code:

label l(2),m(3),n(4);

List<List<List<vector>  > > bladePoints
(
    l,
    List<List<vector> >
    (
        m,
        List<vector>
        (
            n,
            vector::zero
        )
    )
);


tonyuprm June 21, 2010 12:17

Thanks David!


All times are GMT -4. The time now is 19:58.