CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM

Vector Declaration

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   June 16, 2010, 11:15
Default Vector Declaration
  #1
Member
 
Tony
Join Date: Jun 2010
Posts: 54
Rep Power: 7
tonyuprm is on a distinguished road
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!

Last edited by tonyuprm; June 16, 2010 at 12:41. Reason: more info
tonyuprm is offline   Reply With Quote

Old   June 17, 2010, 02:49
Default
  #2
Senior Member
 
Stefan Herbert
Join Date: Dec 2009
Location: Darmstadt, Germany
Posts: 129
Rep Power: 8
herbert is on a distinguished road
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
herbert is offline   Reply With Quote

Old   June 17, 2010, 11:27
Default
  #3
Member
 
Tony
Join Date: Jun 2010
Posts: 54
Rep Power: 7
tonyuprm is on a distinguished road
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!

Last edited by tonyuprm; June 17, 2010 at 13:44.
tonyuprm is offline   Reply With Quote

Old   June 18, 2010, 08:21
Default
  #4
Senior Member
 
David Boger
Join Date: Mar 2009
Location: Penn State Applied Research Laboratory
Posts: 146
Rep Power: 8
boger is on a distinguished road
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
        )
    )
);
__________________
David A. Boger
boger is offline   Reply With Quote

Old   June 21, 2010, 12:17
Default
  #5
Member
 
Tony
Join Date: Jun 2010
Posts: 54
Rep Power: 7
tonyuprm is on a distinguished road
Thanks David!
tonyuprm is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On



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