Skip to content

Commit

Permalink
Changed step sizes in numeric evaluation of the Jacobian
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@20120 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Michael Kloeppel committed Apr 14, 2014
1 parent 3206e8e commit 97a7c2a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions SimulationRuntime/cpp/Solver/Newton/Newton.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#include "stdafx.h"
#include "Newton.h"
#include <iostream>

#include <Math/ILapack.h> // needed for solution of linear system with Lapack
#include <Math/Constants.h> // definitializeion of constants like uround

Expand Down Expand Up @@ -102,14 +102,14 @@ void Newton::solve()
while(_iterationStatus == CONTINUE)
{
_iterationStatus = DONE;

calcFunction(_y,_f);
// Check stopping criterion
calcFunction(_y,_f);
if(totStps)
{
for(int i=0; i<_dimSys; ++i)
{
if(fabs(_f[i]) > _newtonSettings->getAtol() + _newtonSettings->getRtol() * (fabs(_f[i])))
if(fabs(_f[i]) > _newtonSettings->getAtol() +_newtonSettings->getRtol() * ( fabs(_f[i])))
{
_iterationStatus = CONTINUE;
break;
Expand All @@ -121,6 +121,7 @@ void Newton::solve()

// New right hand side


if(_iterationStatus == CONTINUE)
{
if(totStps < _newtonSettings->getNewtMax())
Expand Down Expand Up @@ -191,9 +192,10 @@ void Newton::calcJacobian()
{
// Reset variables for every column
memcpy(_yHelp,_y,_dimSys*sizeof(double));
double stepsize=1.e-6+(1.e-6*_yHelp[j]);


// Finitializee difference
double stepsize=_newtonSettings->getAtol()+(_newtonSettings->getRtol()*_yHelp[j]);
_yHelp[j] += stepsize;

calcFunction(_yHelp,_fHelp);
Expand All @@ -202,7 +204,7 @@ void Newton::calcJacobian()
for(int i=0; i<_dimSys; ++i)
_jac[i+j*_dimSys] = (_fHelp[i] - _f[i]) / stepsize;

_yHelp[j] = _y[j];
_yHelp[j] -=stepsize;
}
}

Expand Down

0 comments on commit 97a7c2a

Please sign in to comment.