mfem icon indicating copy to clipboard operation
mfem copied to clipboard

Suggested added feature: OptionsParser taking input from file

Open IdoAkkerman opened this issue 1 year ago • 1 comments

In my application I would like to be able to store parameters in a file for a part of the simulation, while still be able to give command line parameters. Therefore I would like to have 2 distinct OptionsParser objects, one taking the command line options in the usual way, and a second one that can read the options from a file (name of the file could be command line input). My current solution is, to augment the OptionsParser with the following constructor:

 OptionsParser(int argc_, std::string argv_[])
      : argc(argc_)
   {
      error_type = error_idx = 0;
      argv = new char*[argc];
      for (int i = 0; i < argc; i++)
      {
         argv[i] = new char[100];
         strcpy(argv[i], argv_[i].c_str());
      }
   }

and use that constructor as follows in the application code.

   ifstream input(param_file);
   int argc = 0;
   char **argv = new char*[32];
   argv[0] = new char[32];
   strcpy(argv[0], param_file.c_str());
   while (!input.eof())
   {
      argv[argc+1] = new char[32];
      input >> argv[argc+1];
      argc++;
   }
   OptionsParser args(argc, argv);

Is there any merit and/or desire to add this constructor to OptionsParser. Shortcuts such as OptionsParser(std::string filename) and OptionsParser(std::ifstream file) can also be easily devised.

IdoAkkerman avatar Jun 04 '24 09:06 IdoAkkerman

I think this feature is very necessary when dealing with linear solvers. Many linear solvers, like hypre, have so many parameters (such as AMG).

fanronghong avatar Jul 09 '24 08:07 fanronghong

:warning: This issue has been automatically marked as stale because it has not had any activity in the last month. If no activity occurs in the next week, it will be automatically closed. Thank you for your contributions.

github-actions[bot] avatar Nov 15 '24 23:11 github-actions[bot]