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

programming issue

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 27, 2009, 04:51
Smile [Solve]programming issue
  #1
Member
 
Julien Schaguene
Join Date: Apr 2009
Location: France
Posts: 55
Rep Power: 17
Schag is on a distinguished road
Hi,

I think it's quite trivial, but I spent time on finding how to get a float as argument for an application.

It's a little application dealing with boundary conditions, let's name it JulienFoam

I want to be able to use it as:
JulienFoam <Boundary> -numericalarg <float>

for the moment, I have that:

int main(int argc, char *argv[])
{
float numericalarg;
argList::validArgs.append("patchName");
argList::validOptions.insert("numericalarg",numeri calarg);

word patchName(args.args()[1]);

[...]

}

and I don't find how to get my numericalarg as a float, it seems that argList only gets strings.

If someone can give me any piece of advice, I think it would be very usefull for my future using, not just for that program.

Regards

Julien

Last edited by Schag; July 27, 2009 at 05:33.
Schag is offline   Reply With Quote

Old   July 27, 2009, 05:01
Default
  #2
Senior Member
 
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18
henrik is on a distinguished road
Julien,

yes, arguments are passed only as strings.

Have a look into fluentMeshToFoam.L where it says:
Code:
    scalar scaleFactor = 1.0;
    if (args.options().found("scale"))
    {
        scaleFactor = atof(args.options()["scale"].c_str());
    }
Henrik
henrik is offline   Reply With Quote

Old   July 27, 2009, 05:27
Default
  #3
Member
 
Julien Schaguene
Join Date: Apr 2009
Location: France
Posts: 55
Rep Power: 17
Schag is on a distinguished road
Perfect, that is exactly what I was looking for! I looked over other applications but not that one.

Thanks a lot!
Schag is offline   Reply With Quote

Old   July 28, 2009, 02:31
Default
  #4
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,684
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Just for completeness (to followup on what Henrik mentioned), you might note that readScalar operates on an Istream, and IStringStream can be used to create an Istream from a string.
Thus the following would also work:
Code:
if (args.options().found("scale"))
{
    scaleFactor = readScalar(IStringStream(args.options()["scale"])());
}
The extra '()' on the IStringStream constructor casts away constness.

Of course, both solutions look fairly messy.
olesen is offline   Reply With Quote

Old   July 28, 2009, 02:40
Default
  #5
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,684
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
In OpenFOAM-1.6, the same thing becomes much more convenient:
Code:
    scalar scaleFactor = 1.0;
    args.optionReadIfPresent("scale", scaleFactor);
olesen is offline   Reply With Quote

Reply

Tags
programming


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
A book for a beginner wanting to learn programming frank Main CFD Forum 9 May 12, 2014 23:15
OpenFoam programming prapanj OpenFOAM 10 March 18, 2010 07:23
Programming in OpenFOAM vinu OpenFOAM 2 July 11, 2009 10:16
new CFD Programming Forum Thinker Main CFD Forum 14 November 19, 2002 16:03
STAR-CD Dynamics issue 16 CD adapco Group Marketing Siemens 0 November 30, 2001 10:25


All times are GMT -4. The time now is 17:03.