Skip to content

Commit

Permalink
fix in cvode for write output
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@22319 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
niklwors committed Sep 16, 2014
1 parent afc1870 commit 47cd2a5
Showing 1 changed file with 43 additions and 42 deletions.
85 changes: 43 additions & 42 deletions SimulationRuntime/cpp/Solver/CVode/CVode.cpp
Expand Up @@ -218,9 +218,9 @@ void Cvode::initialize()
if (_idid < 0)
throw std::invalid_argument("Cvode::initialize()");

// Use own jacobian matrix
//_idid = CVDlsSetDenseJacFn(_cvodeMem, CV_JCallback);
if (_idid < 0)
// Use own jacobian matrix
_idid = CVDlsSetDenseJacFn(_cvodeMem, CV_JCallback);
if (_idid < 0)
throw std::invalid_argument("CVode::initialize()");

if (_dimZeroFunc)
Expand Down Expand Up @@ -454,8 +454,8 @@ void Cvode::CVodeCore()
_time_system->setTime(_tEnd);
// _continuous_system->setContinuousStates(NV_DATA_S(_CV_y));
// _continuous_system->evaluateAll(IContinuous::CONTINUOUS);
// if(writeOutput)
// writeToFile(0, _tEnd, _h);
if(writeOutput)
writeToFile(0, _tEnd, _h);
_accStps += _locStps;
_solverStatus = DONE;
}
Expand Down Expand Up @@ -570,7 +570,7 @@ int Cvode::calcJacobian(double t, long int N, N_Vector fHelp, N_Vector errorWeig
try
{
int j,k,l;
double fnorm, minInc, *f_data, *fHelp_data, *errorWeight_data, h, srur;
double fnorm, minInc, *f_data, *fHelp_data, *errorWeight_data, h, srur, delta_inv;

f_data = NV_DATA_S(fy);
errorWeight_data = NV_DATA_S(errorWeight);
Expand Down Expand Up @@ -632,54 +632,55 @@ int Cvode::calcJacobian(double t, long int N, N_Vector fHelp, N_Vector errorWeig
{
j = _sparsePattern_leadindex[ii-1];

}
while(j <_sparsePattern_leadindex[ii])
{
l = _sparsePattern_index[j];
k = l + ii * _dimSys;
Jac->data[k] = (fHelp_data[l] - f_data[l])/_delta[l];
j++;
}
}
}
}


} //workaround until exception can be catch from c- libraries
catch (std::exception& ex)
{
std::string error = ex.what();
cerr << "CVode integration error: " << error;
return 1;
}

/* Calculation of J without colouring
for (j = 0; j < N; j++)
{
//Generate the jth col of J(tn,y)
}
while(j <_sparsePattern_leadindex[ii])
{
l = _sparsePattern_index[j];
k = l + ii * _dimSys;
//Jac->data[k] = (fHelp_data[l] - f_data[l])/_delta[l];
delta_inv = 1.0/_delta[ii];
Jac->data[k] = (fHelp_data[l] - f_data[l])*delta_inv;
j++;
}
}
}
}

/*
//Calculation of J without colouring
for (j = 0; j < N; j++)
{
//N_VSetArrayPointer(DENSE_COL(Jac,j), jthCol);
yjsaved = y[j];
//N_VSetArrayPointer(DENSE_COL(Jac,j), jthCol);
y[j] += _delta[j];
_ysave[j] = y[j];
calcFunction(t, y, fHelp_data);
y[j] += _delta[j];
y[j] = yjsaved;
calcFunction(t, y, fHelp_data);
y[j] = _ysave[j];
delta_inv = 1.0/_delta[j];
N_VLinearSum(delta_inv, fHelp, -delta_inv, fy, jthCol);
delta_inv = 1.0/_delta[j];
N_VLinearSum(delta_inv, fHelp, -delta_inv, fy, jthCol);
for(int i=0; i<_dimSys; ++i)
for(int i=0; i<_dimSys; ++i)
{
Jac->data[i+j*_dimSys] = NV_Ith_S(jthCol,i);
}
//DENSE_COL(Jac,j) = N_VGetArrayPointer(jthCol);
//DENSE_COL(Jac,j) = N_VGetArrayPointer(jthCol);
}
*/

} //workaround until exception can be catch from c- libraries
catch (std::exception& ex)
{
std::string error = ex.what();
cerr << "CVode integration error: " << error;
return 1;
}
*/


return 0;
Expand Down

0 comments on commit 47cd2a5

Please sign in to comment.