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

Creating pre-processing utility

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 10, 2010, 16:41
Default Creating pre-processing utility
  #1
Member
 
Pascal
Join Date: Jun 2009
Location: Montreal
Posts: 65
Rep Power: 16
Pascal_doran is on a distinguished road
Hi all,

I've created an utility (vit_cond_init_2t_test) and every thing goes right. But now I would like to be able to give parameters (entries) to my utility to customize it like that:

vit_cond_init_2t_test a b c d

where a, b, c and d are input parameters

I would like to modify my utility to do so. Here's what I've tried :

Code:
int main(int argc, char *argv[])  
{  
 
# include "setRootCase.H"  
# include "createTime.H"  
# include "createMesh.H"  
# include "createFields.H" 

  argList::validArgs.append("value");
  argList::validArgs.append("value");
  argList::validArgs.append("value");
  argList::validArgs.append("value");

  scalar a(readScalar(IStringStream(args.args()[1])()));
  scalar b(readScalar(IStringStream(args.args()[2])()));
  scalar c(readScalar(IStringStream(args.args()[3])()));
  scalar d(readScalar(IStringStream(args.args()[4])()));

...

return(0);  
}
I have the following error message when I run the code :

Code:
Wrong number of arguments, expected 0 found 4

FOAM exiting
Thank you,

Pascal
Pascal_doran is offline   Reply With Quote

Old   May 11, 2010, 02:22
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,685
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by Pascal_doran View Post

I would like to modify my utility to do so. Here's what I've tried :

Code:
int main(int argc, char *argv[])  
{  
 
# include "setRootCase.H"  
# include "createTime.H"  
# include "createMesh.H"  
# include "createFields.H" 

  argList::validArgs.append("value");
  argList::validArgs.append("value");
  argList::validArgs.append("value");
  argList::validArgs.append("value");

  scalar a(readScalar(IStringStream(args.args()[1])()));
  scalar b(readScalar(IStringStream(args.args()[2])()));
  scalar c(readScalar(IStringStream(args.args()[3])()));
  scalar d(readScalar(IStringStream(args.args()[4])()));

...

return(0);  
}
I have the following error message when I run the code :

Code:
Wrong number of arguments, expected 0 found 4

FOAM exiting
Simple to solve. If you see what the #include "setRootCase.H" actually does, you'll see that you've tried to parse the command-line before actually defining which options and arguments it can handle.

You want something like this:

Code:
int main(int argc, char *argv[])  
{  
  // does it work correctly in parallel? If not you need this:
  // argList::noParallel(); 

// define allowable options and arguments
  argList::validArgs.append("valueA");
   argList::validArgs.append("valueB");
   argList::validArgs.append("valueC");
   argList::validArgs.append("valueD");
 
// construct 'args' from command-line, parsing options/arguments:
# include "setRootCase.H"  

# include "createTime.H"  
# include "createMesh.H"  
# include "createFields.H" 

  const scalar a(readScalar(IStringStream(args.args()[1])()));
  const scalar b(readScalar(IStringStream(args.args()[2])()));
  const scalar c(readScalar(IStringStream(args.args()[3])()));
  const  scalar d(readScalar(IStringStream(args.args()[4])()));

...

return 0;  
}
To be especially pedantic, I've added a 'const' in front of the scalars, since they are probably invariant.

This hopefully gets you going.
gaza and Ramkumar21194 like this.
olesen is offline   Reply With Quote

Old   May 11, 2010, 17:58
Default
  #3
Member
 
Pascal
Join Date: Jun 2009
Location: Montreal
Posts: 65
Rep Power: 16
Pascal_doran is on a distinguished road
Thanks a lot M. Olesen, everything works perfectly!

Pascal
Pascal_doran is offline   Reply With Quote

Reply

Tags
entries, pre-processing, utility


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
[Commercial meshers] Fluent3DMeshToFoam simvun OpenFOAM Meshing & Mesh Conversion 50 January 19, 2020 15:33
[blockMesh] BlockMeshmergePatchPairs hjasak OpenFOAM Meshing & Mesh Conversion 11 August 15, 2008 07:36
Problems with Meshing: Collapsed Cells Emmanuel Resch Siemens 1 July 30, 2007 03:02
Creating new utility Lorentz force calculation adekian OpenFOAM Running, Solving & CFD 0 May 24, 2007 05:16
PRE and POST processing package Astrid Barros Main CFD Forum 6 November 16, 2000 10:31


All times are GMT -4. The time now is 12:50.