Skip to content

Commit

Permalink
improve memory handling
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@20535 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Vitalij Ruge committed May 9, 2014
1 parent 9575907 commit fab8c2e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 13 additions & 4 deletions SimulationRuntime/c/optimization/DataManagement/MoveData.c
Expand Up @@ -509,14 +509,20 @@ void optData2ModelData(OptData *optData, double *vopt, const int index){
const modelica_real *const vnom = optData->bounds.vnom;
const long double *** const scalb = optData->bounds.scalb;

int i, j, k, shift;
modelica_real * realVars[3];

int i, j, k, shift, l;
DATA * data = optData->data;

for(l = 0; l < 3; ++l)
realVars[l] = data->localData[l]->realVars;

for(i = 0, shift = 0; i < nsi; ++i){
for(j = 0; j < np; ++j, shift += nv){

memcpy(data->localData[2]->realVars, optData->v[i][j], nReal*sizeof(double));
memcpy(data->localData[1]->realVars, optData->v[i][j], nReal*sizeof(double));
for(l = 0; l < 3; ++l){
data->localData[l]->realVars = optData->v[i][j];
}

for(k = 0; k < nx; ++k)
data->localData[0]->realVars[k] = vopt[shift + k]*vnom[k];
Expand All @@ -536,13 +542,16 @@ void optData2ModelData(OptData *optData, double *vopt, const int index){
diff_symColoredLagrange(optData, &optData->J[i][j][index_la], 2, scalb[i][j]);
}

memcpy(optData->v[i][j], data->localData[0]->realVars, nReal*sizeof(double));
}
}
if(ma && index == 3){
const int index_ma = optData->s.derIndex[1];
diff_symColoredMayer(optData, &optData->J[nsi-1][np-1][index_ma], 3);
}

for(l = 0; l < 3; ++l)
data->localData[l]->realVars = realVars[l];

}

/*
Expand Down
4 changes: 1 addition & 3 deletions SimulationRuntime/c/optimization/eval_all/EvalF.c
Expand Up @@ -126,9 +126,7 @@ Bool evalfDiffF(Index n, double * vopt, Bool new_x, Number *gradF, void * useDat
}
}
}else{
int i;
for(i = 0; i<n;++i)
gradF[i] = 0.0;
memset(gradF,0.0,n*sizeof(Number));
}

if(ma){
Expand Down

0 comments on commit fab8c2e

Please sign in to comment.