CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (http://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Creating pre-processing utility (http://www.cfd-online.com/Forums/openfoam-post-processing/75961-creating-pre-processing-utility.html)

Pascal_doran May 10, 2010 16:41

Creating pre-processing utility
 
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

olesen May 11, 2010 02:22

Quote:

Originally Posted by Pascal_doran (Post 258228)

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.

Pascal_doran May 11, 2010 17:58

Thanks a lot M. Olesen, everything works perfectly!

Pascal


All times are GMT -4. The time now is 05:47.