@@ -196,6 +196,47 @@ namespace pfasst
196196 }
197197 }
198198
199+ /* *
200+ * Read config parameters from file.
201+ *
202+ * A potential INI file might look like the following:
203+ *
204+ * @code
205+ * # Global
206+ * quiet=yes
207+ *
208+ * # Duration
209+ * dt=0.015625
210+ * num_steps=2
211+ * num_iter=10
212+ *
213+ * # Tolerances
214+ * rel_res_tol=1e-10
215+ *
216+ * # PFASST
217+ * num_blocks=1
218+ * @endcode
219+ *
220+ * @param[in] file_name name of the INI-like file containing config parameters;
221+ * path/name may be relative
222+ * @throws invalid_argument if the given file could not be opened
223+ *
224+ * @see
225+ * [Boost Program Options Documentation on supported INI-like file format]
226+ * (http://www.boost.org/doc/libs/1_57_0/doc/html/program_options/overview.html#idp343292240)
227+ */
228+ static inline void read_config_file (const string& file_name)
229+ {
230+ ifstream ifs (file_name.c_str (), ios_base::in);
231+ if (!ifs) {
232+ throw invalid_argument (" Config file '" + file_name + " ' not found." );
233+ } else {
234+ po::store (po::parse_config_file (ifs, options::get_instance ().get_all_options ()),
235+ options::get_instance ().get_variables_map ());
236+ po::notify (options::get_instance ().get_variables_map ());
237+ }
238+ }
239+
199240 /* *
200241 * Read and parse command line parameters.
201242 *
@@ -217,6 +258,11 @@ namespace pfasst
217258 po::store (parsed, options::get_instance ().get_variables_map ());
218259 po::notify (options::get_instance ().get_variables_map ());
219260
261+ if (options::get_instance ().get_variables_map ().count (" input" )) {
262+ string input_file = config::get_value<string>(" input" );
263+ read_config_file (input_file);
264+ }
265+
220266 if (options::get_instance ().get_variables_map ().count (" help" )) {
221267 if (get_rank () == 0 ) {
222268 cout << print_help () << endl;
@@ -231,29 +277,6 @@ namespace pfasst
231277 }
232278 }
233279
234- /* *
235- * Read config parameters from file.
236- *
237- * @param[in] file_name name of the INI-like file containing config parameters;
238- * path/name may be relative
239- * @throws invalid_argument if the given file could not be opened
240- *
241- * @see
242- * [Boost Program Options Documentation on supported INI-like file format]
243- * (http://www.boost.org/doc/libs/1_57_0/doc/html/program_options/overview.html#idp343292240)
244- */
245- static inline void read_config_file (const string& file_name)
246- {
247- ifstream ifs (file_name.c_str (), ios_base::in);
248- if (!ifs) {
249- throw invalid_argument (" Config file '" + file_name + " ' not found." );
250- } else {
251- po::store (po::parse_config_file (ifs, options::get_instance ().get_all_options ()),
252- options::get_instance ().get_variables_map ());
253- po::notify (options::get_instance ().get_variables_map ());
254- }
255- }
256-
257280 /* *
258281 * Initialize options detection and parsing.
259282 *
@@ -262,6 +285,8 @@ namespace pfasst
262285 * Group | Parameter | Type
263286 * -----------|---------------|---------
264287 * Global | `h`, `help` | `bool`
288+ * Global | `q`, `quiet` | `bool`
289+ * Global | `input` | `string`
265290 * Duration | `dt` | `double`
266291 * Duration | `tend` | `double`
267292 * Duration | `num_iters` | `size_t`
@@ -272,6 +297,7 @@ namespace pfasst
272297 {
273298 options::add_option (" Global" , " help,h" , " display this help message" );
274299 options::add_option (" Global" , " quiet,q" , " don't log to stdout" );
300+ options::add_option<string>(" Global" , " input" , " INI file with configuration options" );
275301
276302 options::add_option<double >(" Duration" , " dt" , " time step size" );
277303 options::add_option<double >(" Duration" , " tend" , " final time of simulation" );
0 commit comments