@@ -218,124 +218,26 @@ void setGlobalVerboseLevel(int argc, char**argv)
218218 delete flags;
219219}
220220
221- static int getNonlinearSolverMethod ( )
221+ static void readFlag ( int *flag, int max, const char *value, const char *flagName, const char **names, const char **desc )
222222{
223223 int i;
224- const char *cflags = omc_flagValue[FLAG_NLS];
225- const string *method = cflags ? new string (cflags) : NULL ;
226-
227- if (!method)
228- return NLS_MIXED; /* default method */
229-
230- for (i=1 ; i<NLS_MAX; ++i)
231- if (*method == NLS_NAME[i])
232- return i;
233-
234- warningStreamPrint (LOG_STDOUT, 1 , " unrecognized option -nls=%s, current options are:" , method->c_str ());
235- for (i=1 ; i<NLS_MAX; ++i)
236- warningStreamPrint (LOG_STDOUT, 0 , " %-18s [%s]" , NLS_NAME[i], NLS_DESC[i]);
237- messageClose (LOG_STDOUT);
238- throwStreamPrint (NULL ," see last warning" );
239-
240- return NLS_NONE;
241- }
242-
243- static int getlinearSolverMethod ()
244- {
245- int i;
246- const char *cflags = omc_flagValue[FLAG_LS];
247- const string *method = cflags ? new string (cflags) : NULL ;
248-
249- if (!method)
250- return LS_DEFAULT; /* default method */
251-
252- for (i=1 ; i<LS_MAX; ++i)
253- if (*method == LS_NAME[i])
254- return i;
255-
256- warningStreamPrint (LOG_STDOUT, 1 , " unrecognized option -ls=%s, current options are:" , method->c_str ());
257- for (i=1 ; i<LS_MAX; ++i)
258- warningStreamPrint (LOG_STDOUT, 0 , " %-18s [%s]" , LS_NAME[i], LS_DESC[i]);
259- messageClose (LOG_STDOUT);
260- throwStreamPrint (NULL ," see last warning" );
261-
262- return LS_NONE;
263- }
264-
265- static int getlinearSparseSolverMethod ()
266- {
267- int i;
268- const char *cflags = omc_flagValue[FLAG_LSS];
269- const string *method = cflags ? new string (cflags) : NULL ;
270-
271- if (!method) {
272- return LSS_DEFAULT; /* default method */
224+ if (!value) {
225+ return ; /* keep the default value */
273226 }
274227
275- for (i=1 ; i<LSS_MAX; ++i)
276- if (*method == LSS_NAME[i])
277- return i;
278-
279- warningStreamPrint (LOG_STDOUT, 1 , " unrecognized option -lss=%s, current options are:" , method->c_str ());
280- for (i=1 ; i<LSS_MAX; ++i)
281- warningStreamPrint (LOG_STDOUT, 0 , " %-18s [%s]" , LSS_NAME[i], LSS_DESC[i]);
282- messageClose (LOG_STDOUT);
283- throwStreamPrint (NULL ," see last warning" );
284-
285- return LSS_NONE;
286- }
287-
288- static int getNewtonStrategy ()
289- {
290- int i;
291- const char *cflags = omc_flagValue[FLAG_NEWTON_STRATEGY];
292- const string *method = cflags ? new string (cflags) : NULL ;
293-
294- if (!method)
295- return NEWTON_DAMPED2; /* default method */
296-
297- for (i=1 ; i<NEWTON_MAX; ++i)
298- if (*method == NEWTONSTRATEGY_NAME[i])
299- return i;
300-
301- warningStreamPrint (LOG_STDOUT, 1 , " unrecognized option -nls=%s, current options are:" , method->c_str ());
302- for (i=1 ; i<NEWTON_MAX; ++i)
303- warningStreamPrint (LOG_STDOUT, 0 , " %-18s [%s]" , NEWTONSTRATEGY_NAME[i], NEWTONSTRATEGY_DESC[i]);
304- messageClose (LOG_STDOUT);
305- throwStreamPrint (NULL ," see last warning" );
306-
307- return NEWTON_NONE;
308- }
309-
310- static int getNlsLSSolver (int nlsSolver)
311- {
312- int i;
313- const char *cflags = omc_flagValue[FLAG_NLS_LS];
314- const string *method = cflags ? new string (cflags) : NULL ;
315-
316- if (!method)
317- {
318- if (nlsSolver == NLS_KINSOL)
319- {
320- return NLS_LS_KLU; /* default kinsol linear solver method */
321- }
322- else
323- {
324- return NLS_LS_LAPACK; /* default method */
228+ for (i=1 ; i<max; ++i) {
229+ if (0 == strcmp (value, names[i])) {
230+ *flag = i;
231+ return ;
325232 }
326233 }
327234
328- for (i=1 ; i<NLS_LS_MAX; ++i)
329- if (*method == NLS_LS_METHOD[i])
330- return i;
331-
332- warningStreamPrint (LOG_STDOUT, 1 , " unrecognized option -nls=%s, current options are:" , method->c_str ());
333- for (i=1 ; i<NLS_LS_MAX; ++i)
334- warningStreamPrint (LOG_STDOUT, 0 , " %-18s [%s]" , NLS_LS_METHOD[i], NLS_LS_METHOD_DESC[i]);
235+ warningStreamPrint (LOG_STDOUT, 1 , " unrecognized option %s=%s, current options are:" , flagName, value);
236+ for (i=1 ; i<LS_MAX; ++i) {
237+ warningStreamPrint (LOG_STDOUT, 0 , " %-18s [%s]" , names[i], desc[i]);
238+ }
335239 messageClose (LOG_STDOUT);
336240 throwStreamPrint (NULL ," see last warning" );
337-
338- return NLS_LS_UNKNOWN;
339241}
340242
341243static double getFlagReal (enum _FLAG flag, double res)
@@ -839,12 +741,12 @@ int initRuntimeAndSimulation(int argc, char**argv, DATA *data, threadData_t *thr
839741 EXIT (1 );
840742 }
841743
842- data->simulationInfo ->nlsMethod = getNonlinearSolverMethod ( );
843- data->simulationInfo ->lsMethod = getlinearSolverMethod ( );
844- data->simulationInfo ->lssMethod = getlinearSparseSolverMethod ( );
845- data->simulationInfo ->newtonStrategy = getNewtonStrategy ( );
744+ readFlag (& data->simulationInfo ->nlsMethod , NLS_MAX, omc_flagValue[FLAG_NLS], " -nls " , NLS_NAME, NLS_DESC );
745+ readFlag (& data->simulationInfo -> lsMethod, LS_MAX, omc_flagValue[FLAG_LS ], " -ls " , LS_NAME, LS_DESC );
746+ readFlag (& data->simulationInfo ->lssMethod , LSS_MAX, omc_flagValue[FLAG_LSS], " -lss " , LSS_NAME, LSS_DESC );
747+ readFlag (& data->simulationInfo ->newtonStrategy , NEWTON_MAX, omc_flagValue[FLAG_NEWTON_STRATEGY], " -newton " , NEWTONSTRATEGY_NAME, NEWTONSTRATEGY_DESC );
846748 data->simulationInfo ->nlsCsvInfomation = omc_flag[FLAG_NLS_INFO];
847- data->simulationInfo ->nlsLinearSolver = getNlsLSSolver (data-> simulationInfo -> nlsMethod );
749+ readFlag (& data->simulationInfo ->nlsLinearSolver , NLS_LS_MAX, omc_flagValue[FLAG_NLS_LS], " -nlsLS " , NLS_LS_METHOD, NLS_LS_METHOD_DESC );
848750
849751 if (omc_flag[FLAG_HOMOTOPY_ADAPT_BEND]) {
850752 homAdaptBend = atof (omc_flagValue[FLAG_HOMOTOPY_ADAPT_BEND]);
0 commit comments