Skip to content

Commit fd10ddb

Browse files
authored
Merge branch 'maintenance/v2.1' into all-cvode-steps
2 parents dd04f81 + 95ff321 commit fd10ddb

4 files changed

Lines changed: 276 additions & 160 deletions

File tree

src/OMSimulatorLib/Flags.cpp

Lines changed: 85 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,48 @@
4545
#include <regex>
4646
#include <sstream>
4747

48-
oms::Flags::Flags()
48+
oms::Flags::FlagValues::FlagValues() :
49+
addParametersToCSV(false),
50+
algLoopSolver(oms_alg_solver_kinsol),
51+
cvodeMaxErrTestFails(100),
52+
cvodeMaxNLSFails(100),
53+
cvodeMaxNLSIterations(5),
54+
cvodeMaxSteps(1000),
55+
cvodeMaxOrder(2),
56+
defaultModeIsCS(false),
57+
deleteTempFiles(true),
58+
directionalDerivatives(true),
59+
dumpAlgLoops(false),
60+
emitEvents(true),
61+
ignoreInitialUnknowns(false),
62+
initialStepSize(1e-6),
63+
inputExtrapolation(false),
64+
intervals(100),
65+
masterAlgorithm(oms_solver_wc_ma),
66+
maxEventIteration(100),
67+
maximumStepSize(1e-3),
68+
maxLoopIteration(10),
69+
minimumStepSize(1e-12),
70+
numProcs(1),
71+
progressBar(false),
72+
realTime(false),
73+
resultFile("<default>"),
74+
skipCSVHeader(true),
75+
solver(oms_solver_sc_cvode),
76+
solverStats(false),
77+
startTime(0.0),
78+
stopTime(1.0),
79+
stripRoot(false),
80+
suppressPath(true),
81+
timeout(0),
82+
tolerance(1e-4),
83+
wallTime(false),
84+
zeroNominal(false)
85+
{
86+
}
87+
88+
oms::Flags::Flags() : flagValues()
4989
{
50-
setDefaults();
51-
5290
for (unsigned int i=0; i<flags.size(); ++i)
5391
{
5492
lookup[flags[i].name] = i;
@@ -63,41 +101,7 @@ oms::Flags::~Flags()
63101

64102
void oms::Flags::setDefaults()
65103
{
66-
addParametersToCSV = false;
67-
algLoopSolver = oms_alg_solver_kinsol;
68-
cvodeMaxErrTestFails = 100;
69-
cvodeMaxNLSFails = 100;
70-
cvodeMaxNLSIterations = 5;
71-
cvodeMaxSteps = 1000;
72-
defaultModeIsCS = false;
73-
deleteTempFiles = true;
74-
directionalDerivatives = true;
75-
dumpAlgLoops = false;
76-
emitEvents = true;
77-
ignoreInitialUnknowns = false;
78-
initialStepSize = 1e-6;
79-
inputExtrapolation = false;
80-
intervals = 100;
81-
masterAlgorithm = oms_solver_wc_ma;
82-
maxEventIteration = 100;
83-
maximumStepSize = 1e-3;
84-
maxLoopIteration = 10;
85-
minimumStepSize = 1e-12;
86-
numProcs = 1;
87-
progressBar = false;
88-
realTime = false;
89-
resultFile = "<default>";
90-
skipCSVHeader = true;
91-
solver = oms_solver_sc_cvode;
92-
solverStats = false;
93-
startTime = 0.0;
94-
stopTime = 1.0;
95-
stripRoot = false;
96-
suppressPath = true;
97-
timeout = 0;
98-
tolerance = 1e-4;
99-
wallTime = false;
100-
zeroNominal = false;
104+
flagValues = FlagValues();
101105
}
102106

103107
oms::Flags& oms::Flags::GetInstance()
@@ -186,16 +190,16 @@ oms_status_enu_t oms::Flags::SetCommandLineOption(const std::string& cmd)
186190

187191
oms_status_enu_t oms::Flags::AddParametersToCSV(const std::string& value)
188192
{
189-
GetInstance().addParametersToCSV = (value == "true");
193+
GetInstance().flagValues.addParametersToCSV = (value == "true");
190194
return oms_status_ok;
191195
}
192196

193197
oms_status_enu_t oms::Flags::AlgLoopSolver(const std::string& value)
194198
{
195199
if (value == "fixedpoint")
196-
GetInstance().algLoopSolver = oms_alg_solver_fixedpoint;
200+
GetInstance().flagValues.algLoopSolver = oms_alg_solver_fixedpoint;
197201
else if (value == "kinsol")
198-
GetInstance().algLoopSolver = oms_alg_solver_kinsol;
202+
GetInstance().flagValues.algLoopSolver = oms_alg_solver_kinsol;
199203
else
200204
return logError("Invalid solver method");
201205
return oms_status_ok;
@@ -209,49 +213,55 @@ oms_status_enu_t oms::Flags::ClearAllOptions(const std::string& value)
209213

210214
oms_status_enu_t oms::Flags::CVODEMaxErrTestFails(const std::string& value)
211215
{
212-
GetInstance().cvodeMaxErrTestFails = atoi(value.c_str());
216+
GetInstance().flagValues.cvodeMaxErrTestFails = atoi(value.c_str());
213217
return oms_status_ok;
214218
}
215219

216220
oms_status_enu_t oms::Flags::CVODEMaxNLSFailures(const std::string& value)
217221
{
218-
GetInstance().cvodeMaxNLSFails = atoi(value.c_str());
222+
GetInstance().flagValues.cvodeMaxNLSFails = atoi(value.c_str());
219223
return oms_status_ok;
220224
}
221225

222226
oms_status_enu_t oms::Flags::CVODEMaxNLSIterations(const std::string& value)
223227
{
224-
GetInstance().cvodeMaxNLSIterations = atoi(value.c_str());
228+
GetInstance().flagValues.cvodeMaxNLSIterations = atoi(value.c_str());
225229
return oms_status_ok;
226230
}
227231

228232
oms_status_enu_t oms::Flags::CVODEMaxSteps(const std::string& value)
229233
{
230-
GetInstance().cvodeMaxSteps = atoi(value.c_str());
234+
GetInstance().flagValues.cvodeMaxSteps = atoi(value.c_str());
235+
return oms_status_ok;
236+
}
237+
238+
oms_status_enu_t oms::Flags::CVODEMaxOrder(const std::string& value)
239+
{
240+
GetInstance().flagValues.cvodeMaxOrder = atoi(value.c_str());
231241
return oms_status_ok;
232242
}
233243

234244
oms_status_enu_t oms::Flags::DeleteTempFiles(const std::string& value)
235245
{
236-
GetInstance().deleteTempFiles = (value == "true");
246+
GetInstance().flagValues.deleteTempFiles = (value == "true");
237247
return oms_status_ok;
238248
}
239249

240250
oms_status_enu_t oms::Flags::DirectionalDerivatives(const std::string& value)
241251
{
242-
GetInstance().directionalDerivatives = (value == "true");
252+
GetInstance().flagValues.directionalDerivatives = (value == "true");
243253
return oms_status_ok;
244254
}
245255

246256
oms_status_enu_t oms::Flags::DumpAlgLoops(const std::string& value)
247257
{
248-
GetInstance().dumpAlgLoops = (value == "true");
258+
GetInstance().flagValues.dumpAlgLoops = (value == "true");
249259
return oms_status_ok;
250260
}
251261

252262
oms_status_enu_t oms::Flags::EmitEvents(const std::string& value)
253263
{
254-
GetInstance().emitEvents = (value == "true");
264+
GetInstance().flagValues.emitEvents = (value == "true");
255265
return oms_status_ok;
256266
}
257267

@@ -332,19 +342,19 @@ oms_status_enu_t oms::Flags::Help(const std::string& value)
332342

333343
oms_status_enu_t oms::Flags::IgnoreInitialUnknowns(const std::string& value)
334344
{
335-
GetInstance().ignoreInitialUnknowns = (value == "true");
345+
GetInstance().flagValues.ignoreInitialUnknowns = (value == "true");
336346
return oms_status_ok;
337347
}
338348

339349
oms_status_enu_t oms::Flags::InputExtrapolation(const std::string& value)
340350
{
341-
GetInstance().inputExtrapolation = (value == "true");
351+
GetInstance().flagValues.inputExtrapolation = (value == "true");
342352
return oms_status_ok;
343353
}
344354

345355
oms_status_enu_t oms::Flags::Intervals(const std::string& value)
346356
{
347-
GetInstance().intervals = atoi(value.c_str());
357+
GetInstance().flagValues.intervals = atoi(value.c_str());
348358
return oms_status_ok;
349359
}
350360

@@ -362,58 +372,58 @@ oms_status_enu_t oms::Flags::LogLevel(const std::string& value)
362372

363373
oms_status_enu_t oms::Flags::MaxEventIteration(const std::string& value)
364374
{
365-
GetInstance().maxEventIteration = atoi(value.c_str());
375+
GetInstance().flagValues.maxEventIteration = atoi(value.c_str());
366376
return oms_status_ok;
367377
}
368378

369379
oms_status_enu_t oms::Flags::MaxLoopIteration(const std::string& value)
370380
{
371-
GetInstance().maxLoopIteration = atoi(value.c_str());
381+
GetInstance().flagValues.maxLoopIteration = atoi(value.c_str());
372382
return oms_status_ok;
373383
}
374384

375385
oms_status_enu_t oms::Flags::Mode(const std::string& value)
376386
{
377-
GetInstance().defaultModeIsCS = (value == "cs");
387+
GetInstance().flagValues.defaultModeIsCS = (value == "cs");
378388
return oms_status_ok;
379389
}
380390

381391
oms_status_enu_t oms::Flags::NumProcs(const std::string& value)
382392
{
383-
GetInstance().numProcs = atoi(value.c_str());
393+
GetInstance().flagValues.numProcs = atoi(value.c_str());
384394
return oms_status_ok;
385395
}
386396

387397
oms_status_enu_t oms::Flags::ProgressBar(const std::string& value)
388398
{
389-
GetInstance().progressBar = (value == "true");
399+
GetInstance().flagValues.progressBar = (value == "true");
390400
return oms_status_ok;
391401
}
392402

393403
oms_status_enu_t oms::Flags::RealTime(const std::string& value)
394404
{
395-
GetInstance().realTime = (value == "true");
405+
GetInstance().flagValues.realTime = (value == "true");
396406
return oms_status_ok;
397407
}
398408

399409
oms_status_enu_t oms::Flags::ResultFile(const std::string& value)
400410
{
401-
GetInstance().resultFile = value;
411+
GetInstance().flagValues.resultFile = value;
402412
return oms_status_ok;
403413
}
404414

405415
oms_status_enu_t oms::Flags::SkipCSVHeader(const std::string& value)
406416
{
407-
GetInstance().skipCSVHeader = (value == "true");
417+
GetInstance().flagValues.skipCSVHeader = (value == "true");
408418
return oms_status_ok;
409419
}
410420

411421
oms_status_enu_t oms::Flags::Solver(const std::string& value)
412422
{
413423
if (value == "euler")
414-
GetInstance().solver = oms_solver_sc_explicit_euler;
424+
GetInstance().flagValues.solver = oms_solver_sc_explicit_euler;
415425
else if (value == "cvode")
416-
GetInstance().solver = oms_solver_sc_cvode;
426+
GetInstance().flagValues.solver = oms_solver_sc_cvode;
417427
else
418428
return logError("Invalid solver method");
419429

@@ -422,13 +432,13 @@ oms_status_enu_t oms::Flags::Solver(const std::string& value)
422432

423433
oms_status_enu_t oms::Flags::SolverStats(const std::string& value)
424434
{
425-
GetInstance().solverStats = (value == "true");
435+
GetInstance().flagValues.solverStats = (value == "true");
426436
return oms_status_ok;
427437
}
428438

429439
oms_status_enu_t oms::Flags::StartTime(const std::string& value)
430440
{
431-
GetInstance().startTime = atof(value.c_str());
441+
GetInstance().flagValues.startTime = atof(value.c_str());
432442
return oms_status_ok;
433443
}
434444

@@ -454,30 +464,30 @@ oms_status_enu_t oms::Flags::StepSize(const std::string& value)
454464

455465
if (options.size() > 1)
456466
{
457-
GetInstance().initialStepSize = atof(options[0].c_str());
458-
GetInstance().minimumStepSize = atof(options[1].c_str());
459-
GetInstance().maximumStepSize = atof(options[2].c_str());
467+
GetInstance().flagValues.initialStepSize = atof(options[0].c_str());
468+
GetInstance().flagValues.minimumStepSize = atof(options[1].c_str());
469+
GetInstance().flagValues.maximumStepSize = atof(options[2].c_str());
460470
}
461471
else
462-
GetInstance().maximumStepSize = atof(options[0].c_str());
472+
GetInstance().flagValues.maximumStepSize = atof(options[0].c_str());
463473
return oms_status_ok;
464474
}
465475

466476
oms_status_enu_t oms::Flags::StopTime(const std::string& value)
467477
{
468-
GetInstance().stopTime = atof(value.c_str());
478+
GetInstance().flagValues.stopTime = atof(value.c_str());
469479
return oms_status_ok;
470480
}
471481

472482
oms_status_enu_t oms::Flags::StripRoot(const std::string& value)
473483
{
474-
GetInstance().stripRoot = (value == "true");
484+
GetInstance().flagValues.stripRoot = (value == "true");
475485
return oms_status_ok;
476486
}
477487

478488
oms_status_enu_t oms::Flags::SuppressPath(const std::string& value)
479489
{
480-
GetInstance().suppressPath = (value == "true");
490+
GetInstance().flagValues.suppressPath = (value == "true");
481491
return oms_status_ok;
482492
}
483493

@@ -489,13 +499,13 @@ oms_status_enu_t oms::Flags::TempDir(const std::string& value)
489499

490500
oms_status_enu_t oms::Flags::Timeout(const std::string& value)
491501
{
492-
GetInstance().timeout = atoi(value.c_str());
502+
GetInstance().flagValues.timeout = atoi(value.c_str());
493503
return oms_status_ok;
494504
}
495505

496506
oms_status_enu_t oms::Flags::Tolerance(const std::string& value)
497507
{
498-
GetInstance().tolerance = atof(value.c_str());
508+
GetInstance().flagValues.tolerance = atof(value.c_str());
499509
return oms_status_ok;
500510
}
501511

@@ -513,12 +523,12 @@ oms_status_enu_t oms::Flags::WorkingDir(const std::string& value)
513523

514524
oms_status_enu_t oms::Flags::WallTime(const std::string& value)
515525
{
516-
GetInstance().wallTime = (value == "true");
526+
GetInstance().flagValues.wallTime = (value == "true");
517527
return oms_status_ok;
518528
}
519529

520530
oms_status_enu_t oms::Flags::ZeroNominal(const std::string& value)
521531
{
522-
GetInstance().zeroNominal = (value == "true");
532+
GetInstance().flagValues.zeroNominal = (value == "true");
523533
return oms_status_ok;
524534
}

0 commit comments

Comments
 (0)