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

Commit 0f722ad

Browse files
qichenghuaOpenModelica-Hudson
authored andcommitted
fixed issue that occured if evaluating the algloop at the initial guess throws a division by zero error and added homotopy solver
1 parent 4ad960f commit 0f722ad

File tree

5 files changed

+758
-59
lines changed

5 files changed

+758
-59
lines changed

SimulationRuntime/cpp/Include/Solver/Nox/Nox.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class Nox : public IAlgLoopSolver
3030
void solverinit();
3131
void createStatusTests();
3232
void createSolverParameters();
33+
void LocaHomotopySolve(int numberofhomotopytries);
34+
NOX::StatusTest::StatusType BasicNLSsolve();
35+
NOX::StatusTest::StatusType secondBasicNLSsolve();
3336

3437
//void check4EventRetry(double* y)
3538

@@ -60,6 +63,9 @@ class Nox : public IAlgLoopSolver
6063
//used for status tests
6164
Teuchos::RCP<NOX::StatusTest::NormF> _statusTestNormF;
6265
Teuchos::RCP<NOX::StatusTest::MaxIters> _statusTestMaxIters;
66+
Teuchos::RCP<NOX::StatusTest::Stagnation> _statusTestStagnation;
67+
Teuchos::RCP<NOX::StatusTest::Divergence> _statusTestDivergence;
68+
6369
Teuchos::RCP<NOX::StatusTest::Combo> _statusTestsCombo;
6470

6571
//list of solver parameters
@@ -71,5 +77,6 @@ class Nox : public IAlgLoopSolver
7177
bool _firstCall;
7278
bool _generateoutput;
7379
bool _useDomainScaling;
80+
7481
};
7582
/** @} */ // end of solverNox

SimulationRuntime/cpp/Include/Solver/Nox/NoxLapackInterface.h

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
#include "NOX_LAPACK_Group.H"
1+
//somehow this is not good...
2+
#include <LOCA.H>
3+
#include <LOCA_LAPACK.H>
24

3-
class NoxLapackInterface : public NOX::LAPACK::Interface {
5+
class NoxLapackInterface : public LOCA::LAPACK::Interface {
46

57
public:
68

79
//! Constructor
8-
NoxLapackInterface(INonLinearAlgLoop *algLoop);
10+
NoxLapackInterface(INonLinearAlgLoop *algLoop, int numberofhomotopytries);
911

1012
//! Destructor
1113
~NoxLapackInterface();
@@ -16,7 +18,19 @@ class NoxLapackInterface : public NOX::LAPACK::Interface {
1618

1719
bool computeJacobian(NOX::LAPACK::Matrix<double>& J, const NOX::LAPACK::Vector & x);
1820

21+
//! Sets parameters
22+
void setParams(const LOCA::ParameterVector& p);
23+
24+
//! Prints solution after successful step
25+
void printSolution(const NOX::LAPACK::Vector &x, const double conParam);
26+
1927
private:
28+
29+
bool computeSimplifiedF(NOX::LAPACK::Vector& f, const NOX::LAPACK::Vector &x);
30+
bool computeActualF(NOX::LAPACK::Vector& f, const NOX::LAPACK::Vector &x);
31+
NOX::LAPACK::Vector applyMatrixtoVector(const NOX::LAPACK::Matrix<double> &A, const NOX::LAPACK::Vector &x);
32+
void checkdimensionof(const NOX::LAPACK::Vector &x);
33+
2034
//! Initial guess
2135
Teuchos::RCP<NOX::LAPACK::Vector> _initialGuess;
2236
INonLinearAlgLoop *_algLoop;///< Algebraic loop to be solved, required to obtain value of f
@@ -25,4 +39,9 @@ class NoxLapackInterface : public NOX::LAPACK::Interface {
2539
bool _generateoutput;
2640
bool _useDomainScaling;
2741
bool _useFunctionValueScaling;
42+
double _lambda;//homotopy parameter
43+
bool _computedinitialguess;
44+
int _numberofhomotopytries;
45+
bool _evaluatedJacobianAtInitialGuess;
46+
Teuchos::RCP<NOX::LAPACK::Matrix<double>> _J;//F'(x_0)
2847
};

SimulationRuntime/cpp/Solver/Kinsol/Kinsol.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ void Kinsol::solveNLS()
718718
idid = KINSol(_kinMem, _Kin_y, method, _Kin_yScale, _Kin_fScale);
719719

720720
KINGetFuncNorm(_kinMem, &_fnorm);
721+
if(!_fValid && (idid==KIN_FIRST_SYSFUNC_ERR)) throw ModelicaSimulationError(ALGLOOP_SOLVER,"Algloop could not be evaluated! Evaluation failed at the first call.");
721722
//if(_fnorm/euclidNorm(_dimSys,_yScale) < 1e-4)
722723
if(idid != KIN_SUCCESS && _fnorm < locTol && _fnorm < _currentIterateNorm)
723724
{

0 commit comments

Comments
 (0)