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

add entry to wordList

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 22, 2010, 13:03
Default add entry to wordList
  #1
New Member
 
Peter Wiemeyer
Join Date: Sep 2009
Location: Germany, Munich
Posts: 22
Rep Power: 16
peterwy is on a distinguished road
Hello,

I've a probably very easy question, but I tried already a lot - nearly the cpl. afternoon - but nothing worked so far.

First I used something like vector<std::string> and here I added strings with the command vector.push_back(....)

Now I want to use the std foam syntax

I created a wordList what should be nearly the same as vector<std::string>
To add elements at the end the .append function should work.

But now the problems comes by:
I can append only another wordList but I'm not able to append a entry like
wordList testList;
testList.append("the first entry");
testList.append("next entry");
and so far.

Is anybody able to help me? Would be greatful.

Thx a lot, bye
Peter
peterwy is offline   Reply With Quote

Old   September 24, 2010, 03:44
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,679
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by peterwy View Post
Hello,

I've a probably very easy question, but I tried already a lot - nearly the cpl. afternoon - but nothing worked so far.

First I used something like vector<std::string> and here I added strings with the command vector.push_back(....)

Now I want to use the std foam syntax

I created a wordList what should be nearly the same as vector<std::string>
To add elements at the end the .append function should work.

But now the problems comes by:
I can append only another wordList but I'm not able to append a entry like
wordList testList;
testList.append("the first entry");
testList.append("next entry");
and so far.

Is anybody able to help me?
1. a "word" has no spaces, so in your example you really want a list of "string", where "string" is actually Foam::string and not std::string.
2. If you are doing several appends, using "List" is very inefficient.

A "List" is normally used with pre-allocated space.
For example,
Code:
    // dimension for exactly 2 items
    List<string> testList(2);

    testList[0] = "the first entry";
    testList[1] = "next entry";
If you want many appends, you should use a DynamicList.
For example,
Code:
    // reserve at least 10 spaces
    DynamicList<string> testList(10);

    testList.append("the first entry");
    testList.append("next entry");
    testList.append("yet another entry");
Take a look at "applications/test/DynamicList/DynamicListTest.C" for some more ideas ... the DynamicList has lots of functionality.

Note that if you have a list of bool values, you should consider using PackedBoolList - it has many pleasant features that make it behave somewhat like a DynamicList.
olesen is offline   Reply With Quote

Old   September 24, 2010, 04:00
Default
  #3
New Member
 
Peter Wiemeyer
Join Date: Sep 2009
Location: Germany, Munich
Posts: 22
Rep Power: 16
peterwy is on a distinguished road
Thx already now for your reply. Some time ago I worked with those dynamic Lists. I will try what's possible in this case. I will come back to this threat then in the next days because at the moment other project work is urgent.

Thx & have a nice weekend
Peter
peterwy is offline   Reply With Quote

Old   October 4, 2010, 08:13
Default
  #4
New Member
 
Peter Wiemeyer
Join Date: Sep 2009
Location: Germany, Munich
Posts: 22
Rep Power: 16
peterwy is on a distinguished road
SOLVED

working with those dynamic lists is exactly what I needed because when using vector OF has problems with other include files.

Thx @ all, Best Regards, Peter
peterwy is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
NuSGsWallFunction declaration type anne OpenFOAM Running, Solving & CFD 5 April 14, 2008 15:35
Add Measure Markings or Coordinates to the Contour Colin FLUENT 4 August 25, 2004 10:54
Add source term in species equation zhou1 FLUENT 1 October 21, 2003 07:28
How to add new code in ground with PLANT? Zhang Zhiqin Phoenics 2 April 30, 2003 13:45
How to add fire source in STAR-CD?? raymond Siemens 2 February 22, 2002 14:49


All times are GMT -4. The time now is 20:10.