Skip to content

Commit 46e1cff

Browse files
qichenghuaOpenModelica-Hudson
authored andcommitted
Using homotopy for nominal values as start values as well.
1 parent 6eee27b commit 46e1cff

File tree

1 file changed

+28
-7
lines changed
  • SimulationRuntime/cpp/Solver/Nox

1 file changed

+28
-7
lines changed

SimulationRuntime/cpp/Solver/Nox/Nox.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void Nox::solve()
155155
// Create the list of solver parameters. For detailed calibration, check https://trilinos.org/docs/dev/packages/nox/doc/html/parameters.html
156156
_solverParametersPtr = Teuchos::rcp(new Teuchos::ParameterList);
157157
_solverParametersPtr->set("Nonlinear Solver", "Line Search Based");
158-
//_solverParametersPtr->sublist("Line Search").set("Method", "Full Step");
158+
_solverParametersPtr->sublist("Line Search").set("Method", "Full Step");
159159
addPrintingList(_solverParametersPtr);
160160

161161
if (_generateoutput) std::cout << "Does NoxLapackInterface induce this error?" << std::endl;
@@ -276,6 +276,11 @@ void Nox::solve()
276276
int numberofhomotopytries = 0;
277277
while((_iterationStatus==CONTINUE) && (numberofhomotopytries<_noxLapackInterface->getMaxNumberOfHomotopyTries()) && !_eventRetry){
278278
if (_generateoutput) std::cout << "Solving with Homotopy at numberofhomotopytries = " << numberofhomotopytries << std::endl;
279+
280+
// Reset initial guess
281+
memcpy(_y,_y0,_dimSys*sizeof(double));
282+
_algLoop->setReal(_y);
283+
279284
try{
280285
LocaHomotopySolve(numberofhomotopytries);
281286
}
@@ -291,7 +296,7 @@ void Nox::solve()
291296
//try setting initial guess to nominal values
292297
if((_iterationStatus==CONTINUE) && (!_eventRetry)){
293298
_algLoop->getNominalReal(_y);
294-
std::cout << "Trying to solve with nominal values given by ";
299+
if(_generateoutput) std::cout << "Trying to solve with nominal values given by ";
295300
for (int i=0;i<_dimSys;i++){
296301
std::cout << _y[i] << " ";
297302
}
@@ -318,11 +323,31 @@ void Nox::solve()
318323
}
319324
}
320325

326+
//try homotopy with nominal values as initial guess
327+
328+
numberofhomotopytries = 0;
329+
while((_iterationStatus==CONTINUE) && (numberofhomotopytries<_noxLapackInterface->getMaxNumberOfHomotopyTries()) && !_eventRetry){
330+
std::cout << "Solving with Homotopy at numberofhomotopytries = " << numberofhomotopytries << " with nominal values as start values." << std::endl;
331+
332+
// Reset initial guess
333+
_algLoop->getNominalReal(_y);
334+
_algLoop->setReal(_y);
335+
336+
try{
337+
LocaHomotopySolve(numberofhomotopytries);
338+
}
339+
catch(const std::exception &e){
340+
std::string errorstring(e.what());
341+
if ((_generateoutput)) std::cout << "Solving with Homotopy failed with error message " + errorstring << " at numberofhomotopytries = " << numberofhomotopytries << std::endl;
342+
}
343+
numberofhomotopytries++;
344+
}
345+
321346
//no extrapolation of the initial guess
322347

323348
if((_iterationStatus==CONTINUE) && (!_eventRetry)){
324349
memcpy(_y,_y_new,_dimSys*sizeof(double));
325-
std::cout << "Trying to solve without extrapolated values:";
350+
if (_generateoutput) std::cout << "Trying to solve without extrapolated values:";
326351
for (int i=0;i<_dimSys;i++){
327352
std::cout << _y[i] << " ";
328353
}
@@ -461,10 +486,6 @@ void Nox::LocaHomotopySolve(const int numberofhomotopytries)
461486
{
462487
if((_generateoutput)) std::cout << "We are going to solve algloop " << _algLoop->getEquationIndex() << "using homotopy with numberofhomotopytries=" << numberofhomotopytries << std::endl;
463488

464-
// Reset initial guess
465-
memcpy(_y,_y0,_dimSys*sizeof(double));
466-
_algLoop->setReal(_y);
467-
468489
//We are setting up the problem to perform arc-length continuation in the parameter "lambda" from 0 to 1 with a maximum of 50 continuation steps and maxNewtonIters nonlinear iterations per step.
469490
//Since we are doing an equilibrium continuation, we set the bifurcation method to "None".
470491
//We use a secant predictor and adaptive step size control with an initial step size of 0.1, maximum of 1.0 and minimum of 0.001.

0 commit comments

Comments
 (0)