Skip to content

Commit

Permalink
[Janitor mode] Fix whitespace
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21436 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
OpenModelica-Hudson committed Jul 7, 2014
1 parent 0268b29 commit 322f92b
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 105 deletions.
208 changes: 104 additions & 104 deletions SimulationRuntime/cpp/Solver/Kinsol/Kinsol.cpp
Expand Up @@ -13,10 +13,10 @@ Kinsol::Kinsol(IAlgLoop* algLoop, INonLinSolverSettings* settings)
, _fScale (NULL)
, _f (NULL)
, _helpArray (NULL)
, _zeroVec (NULL)
, _currentIterate (NULL)
, _zeroVec (NULL)
, _currentIterate (NULL)
, _jac (NULL)
,_fHelp(NULL)
,_fHelp(NULL)
,_yHelp(NULL)
, _dimSys (0)
, _fnorm(10.0)
Expand All @@ -37,8 +37,8 @@ Kinsol::~Kinsol()
if(_helpArray) delete [] _helpArray;
if(_jac) delete [] _jac;
if(_fHelp) delete [] _fHelp;
if(_zeroVec) delete [] _zeroVec;
if(_currentIterate) delete [] _currentIterate;
if(_zeroVec) delete [] _zeroVec;
if(_currentIterate) delete [] _currentIterate;
N_VDestroy_Serial(_Kin_y);
N_VDestroy_Serial(_Kin_y0);
N_VDestroy_Serial(_Kin_yScale);
Expand Down Expand Up @@ -79,17 +79,17 @@ void Kinsol::initialize()
if(_jac) delete [] _jac;
if(_yHelp) delete [] _yHelp;
if(_fHelp) delete [] _fHelp;
if(_zeroVec) delete [] _zeroVec;
if(_currentIterate) delete [] _currentIterate;
if(_zeroVec) delete [] _zeroVec;
if(_currentIterate) delete [] _currentIterate;

_y = new double[_dimSys];
_y0 = new double[_dimSys];
_yScale = new double[_dimSys];
_fScale = new double[_dimSys];
_f = new double[_dimSys];
_helpArray = new double[_dimSys];
_zeroVec = new double[_dimSys];
_currentIterate = new double[_dimSys];
_zeroVec = new double[_dimSys];
_currentIterate = new double[_dimSys];

_jac = new double[_dimSys*_dimSys];
_yHelp = new double[_dimSys];
Expand All @@ -102,15 +102,15 @@ void Kinsol::initialize()
memset(_yHelp,0,_dimSys*sizeof(double));
memset(_fHelp,0,_dimSys*sizeof(double));
memset(_jac,0,_dimSys*_dimSys*sizeof(double));
memset(_zeroVec,0,_dimSys*sizeof(double));
memset(_currentIterate,0,_dimSys*sizeof(double));
memset(_zeroVec,0,_dimSys*sizeof(double));
memset(_currentIterate,0,_dimSys*sizeof(double));


_algLoop->getNominalReal(_yScale);

for (int i=0;i<_dimSys;i++)
_yScale[i] = 1/_yScale[i];
_yScale[i] = 1/_yScale[i];


_Kin_y = N_VMake_Serial(_dimSys, _y);
_Kin_y0 = N_VMake_Serial(_dimSys, _y0);
Expand Down Expand Up @@ -138,7 +138,7 @@ void Kinsol::initialize()

idid = KINSetFuncNormTol(_kinMem, _fnormtol);
idid = KINSetScaledStepTol(_kinMem, _scsteptol);
idid = KINSetRelErrFunc(_kinMem, 1e-14);
idid = KINSetRelErrFunc(_kinMem, 1e-14);

_counter = 0;

Expand Down Expand Up @@ -198,91 +198,91 @@ void Kinsol::solve()
else
{
_counter++;
_eventRetry = false;
// Try Dense first
////////////////////////////
for(int i=0;i<_dimSys;i++) // Reset Scaling
_fScale[i] = 1.0;
_eventRetry = false;

// Try Dense first
////////////////////////////
for(int i=0;i<_dimSys;i++) // Reset Scaling
_fScale[i] = 1.0;


KINDense(_kinMem, _dimSys);
solveNLS();
if(_iterationStatus == DONE)
return;
else // Try Scaling
{
_iterationStatus = CONTINUE;
_algLoop->setReal(_y0);
_algLoop->evaluate();
_algLoop->getRHS(_fScale);
for(int i=0;i<_dimSys;i++)
{
if(abs(_fScale[i]) >1.0)
_fScale[i] = abs(1/_fScale[i]);
else
_fScale[i] = 1;
}
solveNLS();
}
if(_iterationStatus == DONE)
return;
//Try iterative Solvers
/////////////////////////////////////
for(int i=0;i<_dimSys;i++) // Reset Scaling
_fScale[i] = 1.0;
return;
else // Try Scaling
{
_iterationStatus = CONTINUE;
_algLoop->setReal(_y0);
_algLoop->evaluate();
_algLoop->getRHS(_fScale);
for(int i=0;i<_dimSys;i++)
{
if(abs(_fScale[i]) >1.0)
_fScale[i] = abs(1/_fScale[i]);
else
_fScale[i] = 1;
}
solveNLS();
}
if(_iterationStatus == DONE)
return;

//Try iterative Solvers
/////////////////////////////////////
for(int i=0;i<_dimSys;i++) // Reset Scaling
_fScale[i] = 1.0;

KINSpgmr(_kinMem,_dimSys);
_iterationStatus = CONTINUE;
solveNLS();
if(_iterationStatus == DONE)
return;
else // Try Scaling
{
_iterationStatus = CONTINUE;
_algLoop->setReal(_y0);
_algLoop->evaluate();
_algLoop->getRHS(_fScale);
for(int i=0;i<_dimSys;i++)
{
if(abs(_fScale[i]) >1.0)
_fScale[i] = abs(1/_fScale[i]);
else
_fScale[i] = 1;
}
solveNLS();
}
if(_iterationStatus == DONE)
return;
return;
else // Try Scaling
{
_iterationStatus = CONTINUE;
_algLoop->setReal(_y0);
_algLoop->evaluate();
_algLoop->getRHS(_fScale);
for(int i=0;i<_dimSys;i++)
{
if(abs(_fScale[i]) >1.0)
_fScale[i] = abs(1/_fScale[i]);
else
_fScale[i] = 1;
}
solveNLS();
}
if(_iterationStatus == DONE)
return;

for(int i=0;i<_dimSys;i++) // Reset Scaling
_fScale[i] = 1.0;
_fScale[i] = 1.0;

KINSpbcg(_kinMem,_dimSys);
KINSpbcg(_kinMem,_dimSys);
_iterationStatus = CONTINUE;
solveNLS();
if(_iterationStatus == DONE)
return;
else // Try Scaling
{
_iterationStatus = CONTINUE;
_algLoop->setReal(_y0);
_algLoop->evaluate();
_algLoop->getRHS(_fScale);
for(int i=0;i<_dimSys;i++)
{
if(abs(_fScale[i]) >1.0)
_fScale[i] = abs(1/_fScale[i]);
else
_fScale[i] = 1;
}
solveNLS();
}
if(_iterationStatus == DONE)
return;
/*
return;
else // Try Scaling
{
_iterationStatus = CONTINUE;
_algLoop->setReal(_y0);
_algLoop->evaluate();
_algLoop->getRHS(_fScale);
for(int i=0;i<_dimSys;i++)
{
if(abs(_fScale[i]) >1.0)
_fScale[i] = abs(1/_fScale[i]);
else
_fScale[i] = 1;
}
solveNLS();
}
if(_iterationStatus == DONE)
return;

/*
// Try Sptfqmr
KINSptfqmr(_kinMem, _dimSys);
_iterationStatus = CONTINUE;
Expand All @@ -292,7 +292,7 @@ void Kinsol::solve()
//_firstCall = false;
return;
}
*/
*/

if(_eventRetry)
{
Expand Down Expand Up @@ -400,7 +400,7 @@ void Kinsol::solveNLS()
limit = maxStepsHigh,
locTol = 1e-6;

_currentIterateNorm = 100.0;
_currentIterateNorm = 100.0;

while(_iterationStatus == CONTINUE)
{
Expand All @@ -414,14 +414,14 @@ void Kinsol::solveNLS()
// Call Kinsol
idid = KINSol(_kinMem, _Kin_y, method, _Kin_yScale, _Kin_fScale);

KINGetFuncNorm(_kinMem, &_fnorm);
KINGetFuncNorm(_kinMem, &_fnorm);
//if(_fnorm/euclidNorm(_dimSys,_yScale) < 1e-4)
if(idid != KIN_SUCCESS && _fnorm < locTol && _fnorm < _currentIterateNorm)
{
_currentIterateNorm = _fnorm;
for(int i=0;i<_dimSys;i++)
_currentIterate[i] = _y[i];
}
for(int i=0;i<_dimSys;i++)
_currentIterate[i] = _y[i];
}


// Check the return status for possible restarts
Expand Down Expand Up @@ -545,22 +545,22 @@ void Kinsol::solveNLS()
check4EventRetry(_y);
// Try diffent maxStsps
/*
if (maxSteps > limit)
if (maxSteps > limit)
{
// The starting maxSteps is reached again -> Solvererror
if (maxSteps > maxStepsStart)
{
*/
_iterationStatus = SOLVERERROR;
/*
*/
_iterationStatus = SOLVERERROR;
/*
} else // Try lower maxStep values
{
maxSteps = maxStepsLow;
limit = maxStepsStart;
}
}else
maxSteps *= 10;
*/
*/
}
break;
// Other failures (setup etc) -> directly break
Expand All @@ -573,13 +573,13 @@ void Kinsol::solveNLS()
break;
}
}
// Check if the best found solution suffices
if(_iterationStatus == SOLVERERROR && _currentIterateNorm < locTol)
{
_iterationStatus = DONE;
for(int i=0;i<_dimSys;i++)
_y[i] = _currentIterate[i];
}
// Check if the best found solution suffices
if(_iterationStatus == SOLVERERROR && _currentIterateNorm < locTol)
{
_iterationStatus = DONE;
for(int i=0;i<_dimSys;i++)
_y[i] = _currentIterate[i];
}



Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/cpp/Solver/Kinsol/Kinsol.h
Expand Up @@ -78,7 +78,7 @@ class Kinsol : public IAlgLoopSolver

N_Vector
_Kin_y, ///< Temp - Initial values in the Sundials Format
_Kin_y0,
_Kin_y0,
_Kin_yScale,
_Kin_fScale;

Expand Down

0 comments on commit 322f92b

Please sign in to comment.