Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 4712b7a

Browse files
qichenghuaOpenModelica-Hudson
authored andcommitted
Set algloop to high values instead when otherwise errors were thrown.
1 parent 2659444 commit 4712b7a

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

SimulationRuntime/cpp/Solver/Nox/Nox.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,16 @@ void Nox::solve()
115115
//_solverParametersPtr->sublist("Direction").set("Method", "Steepest Descent");
116116

117117
//resetting Line search method to default (Full Step, ie. Standard Newton with lambda=1)
118-
_solverParametersPtr->sublist("Line Search").set("Method", "Backtrack");
118+
_solverParametersPtr->sublist("Line Search").set("Method", "Full Step");
119+
//_solverParametersPtr->sublist("Line Search").sublist("Full Step").set("Full Step", 0.5);
120+
//_solverParametersPtr->sublist("Line Search").set("Method", "Polynomial");
119121
// Set the level of output
120122
if (_generateoutput){
121123
_solverParametersPtr->sublist("Printing").set("Output Information", NOX::Utils::Error + NOX::Utils::Warning + NOX::Utils::OuterIteration + NOX::Utils::Details + NOX::Utils::Debug); //(there are also more options, but error and outer iteration are the ones that I commonly use.
122124
}else{
123125
_solverParametersPtr->sublist("Printing").set("Output Information", NOX::Utils::Error);
124126
}
125-
_solverParametersPtr->sublist("Printing").set("Output Information", NOX::Utils::Error + NOX::Utils::Warning + NOX::Utils::OuterIteration + NOX::Utils::InnerIteration + NOX::Utils::Details + NOX::Utils::Debug); //(there are also more options, but error and outer iteration are the ones that I commonly use.
127+
// _solverParametersPtr->sublist("Printing").set("Output Information", NOX::Utils::Error + NOX::Utils::Warning + NOX::Utils::OuterIteration + NOX::Utils::InnerIteration + NOX::Utils::Details + NOX::Utils::Debug); //(there are also more options, but error and outer iteration are the ones that I commonly use.
126128

127129

128130
if (_generateoutput) std::cout << "creating noxLapackInterface" << std::endl;
@@ -330,7 +332,13 @@ void Nox::solve()
330332
int numberofdifferentnormtests=5;//this variable is used twice.
331333

332334
_algLoop->setReal(_y);
333-
_algLoop->evaluate();
335+
try{
336+
_algLoop->evaluate();
337+
}
338+
catch(const std::exception &ex)
339+
{
340+
if (_generateoutput) std::cout << "algloop evaluation after solve failed with error message:" << std::endl << ex.what() << std::endl << "Trying to continue without. This should hopefully lead to statusTest::Failed." << std::endl;
341+
}
334342

335343
if (_generateoutput) {
336344
std::cout << "solutionvector=(";
@@ -684,7 +692,12 @@ void Nox::LocaHomotopySolve(int numberofhomotopytries)
684692
}
685693

686694
_algLoop->setReal(_y);
687-
_algLoop->evaluate();
695+
try{
696+
_algLoop->evaluate();
697+
}catch(const std::exception &ex)
698+
{
699+
if (_generateoutput) std::cout << "algloop evaluation after solve failed with error message:" << std::endl << ex.what() << std::endl << "Trying to continue without. This should hopefully lead to statusTest::Failed." << std::endl;
700+
}
688701

689702
if (_generateoutput) {
690703
std::cout << "solutionvector=(";

SimulationRuntime/cpp/Solver/Nox/NoxLapackInterface.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,38 @@ bool NoxLapackInterface::computeActualF(NOX::LAPACK::Vector& f, const NOX::LAPAC
187187
}
188188
}
189189

190-
_algLoop->setReal(xp);
191-
_algLoop->evaluate();
192-
_algLoop->getRHS(rhs);
193-
194190
if (_generateoutput) {
195191
std::cout << "we are at position x=(";
196192
for (int i=0;i<_dimSys;i++){
197193
std::cout << std::setprecision (std::numeric_limits<double>::digits10 + 8) << x(i) << " ";
198194
}
199195
std::cout << ")" << std::endl;
200196
std::cout << std::endl;
197+
}
198+
199+
_algLoop->setReal(xp);
200+
_algLoop->getRHS(rhs);
201+
try{
202+
_algLoop->evaluate();
203+
_algLoop->getRHS(rhs);
204+
}catch(const std::exception &ex)
205+
{
206+
if (_generateoutput) std::cout << "calculating right hand side failed with error message:" << std::endl << ex.what() << std::endl;
207+
//the following should be done when some to be implemented flag like "continue if function evaluation fails" is activated.
208+
if (_generateoutput) std::cout << "setting high values into right hand side:" << std::endl << "(";
209+
for(int i=0;i<_dimSys;i++){
210+
if (rhs[i]==0.0){
211+
rhs[i]=1000000.0;
212+
}else{
213+
rhs[i]=1000000.0*rhs[i];
214+
}
215+
if (_generateoutput) std::cout << rhs[i] << " ";
216+
}
217+
if (_generateoutput) std::cout << ")" << std::endl;
218+
}
201219

220+
221+
if (_generateoutput) {
202222
std::cout << "the right hand side is given by (";
203223
for (int i=0;i<_dimSys;i++){
204224
std::cout << rhs[i] << " ";

0 commit comments

Comments
 (0)