Skip to content

Commit

Permalink
- attempt to fix gcc test-suite
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16393 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Willi Braun committed Jun 19, 2013
1 parent d133bbf commit 388b23c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
4 changes: 0 additions & 4 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -2705,8 +2705,6 @@ template equationNonlinear(SimEqSystem eq, Context context, Text &varDecls /*BUF
match eq
case SES_NONLINEAR(__) then
let size = listLength(crefs)
let eqncalls = (eqs |> eq2 => equationNamesExtraResidualsPreBody(eq2) ;separator="\n")
let otherinlines = (eqs |> eq2 => equationNamesExtraResidualsPreBodyInline(eq2,context) ;separator="\n")
let nonlinindx = indexNonLinearSystem
<<
#ifdef _OMC_MEASURE_TIME
Expand All @@ -2726,8 +2724,6 @@ template equationNonlinear(SimEqSystem eq, Context context, Text &varDecls /*BUF
/* write solution */
<%crefs |> name hasindex i0 => '<%cref(name)%> = data->simulationInfo.nonlinearSystemData[<%indexNonLinearSystem%>].nlsx[<%i0%>];' ;separator="\n"%>
<%inlineCrefs(context,crefs)%>
<%eqncalls%>
<%otherinlines%>
#ifdef _OMC_MEASURE_TIME
SIM_PROF_ACC_EQ(modelInfoXmlGetEquation(&data->modelData.modelDataXml,<%index%>).profileBlockIndex);
#endif<%\n%>
Expand Down
41 changes: 35 additions & 6 deletions SimulationRuntime/c/simulation/solver/nonlinearSolverHybrd.c
Expand Up @@ -406,6 +406,7 @@ int solveHybrd(DATA *data, int sysNumber)
int assertCalled = 0;
int assertRetries = 0;
int assertMessage = 0;
static state mem_state;

modelica_boolean* relationsPreBackup;
relationsPreBackup = (modelica_boolean*) malloc(data->modelData.nRelations*sizeof(modelica_boolean));
Expand Down Expand Up @@ -443,10 +444,11 @@ int solveHybrd(DATA *data, int sysNumber)
if(scaling)
solverData->useXScaling = 0;

state mem_state = get_memory_state();
mem_state = get_memory_state();
/* try */
if (!setjmp(nonlinearJmpbuf)) {
wrapper_fvec_hybrj(&solverData->n, solverData->x, solverData->fvec, solverData->fjac, &solverData->ldfjac, &iflag, data);
restore_memory_state(mem_state);
} else { /* catch */
restore_memory_state(mem_state);
WARNING(LOG_STDOUT, "Non-Linear Solver try to handle a problem with a called assert.");
Expand Down Expand Up @@ -491,7 +493,7 @@ int solveHybrd(DATA *data, int sysNumber)

giveUp = 1;

state mem_state = get_memory_state();
mem_state = get_memory_state();
/* try */
if (!setjmp(nonlinearJmpbuf)) {
_omc_hybrj_(wrapper_fvec_hybrj, &solverData->n, solverData->x,
Expand All @@ -501,6 +503,7 @@ int solveHybrd(DATA *data, int sysNumber)
&solverData->nfev, &solverData->njev, solverData->r__,
&solverData->lr, solverData->qtf, solverData->wa1,
solverData->wa2, solverData->wa3, solverData->wa4, data);
restore_memory_state(mem_state);
if (assertCalled){
INFO(LOG_NLS, "After asserts was called, values reached which avoided assert call.");
memcpy(systemData->nlsxOld, solverData->x, solverData->n*(sizeof(double)));
Expand Down Expand Up @@ -552,11 +555,12 @@ int solveHybrd(DATA *data, int sysNumber)

((DATA*)data)->simulationInfo.solveContinuous = 0;

state mem_state = get_memory_state();
mem_state = get_memory_state();
/* try */
if (!setjmp(nonlinearJmpbuf))
{
wrapper_fvec_hybrj(&solverData->n, solverData->x, solverData->fvec, solverData->fjac, &solverData->ldfjac, &iflag, data);
restore_memory_state(mem_state);
} else { /* catch */
restore_memory_state(mem_state);
WARNING(LOG_STDOUT, "Non-Linear Solver try to handle a problem with a called assert.");
Expand Down Expand Up @@ -651,6 +655,32 @@ int solveHybrd(DATA *data, int sysNumber)
printStatus(solverData, &nfunc_evals, &xerror, &xerror_scaled, LOG_NLS);

}
int scaling = solverData->useXScaling;
if(scaling)
solverData->useXScaling = 0;

/* take the solution */
memcpy(systemData->nlsx, solverData->x, solverData->n*(sizeof(double)));

mem_state = get_memory_state();
/* try */
if (!setjmp(nonlinearJmpbuf))
{
wrapper_fvec_hybrj(&solverData->n, solverData->x, solverData->fvec, solverData->fjac, &solverData->ldfjac, &iflag, data);
restore_memory_state(mem_state);
} else { /* catch */
restore_memory_state(mem_state);
WARNING(LOG_STDOUT, "Non-Linear Solver try to handle a problem with a called assert.");

solverData->info = 4;
xerror_scaled = 1;
xerror = 1;
assertCalled = 1;
success = 0;
giveUp = 0;
}
if(scaling)
solverData->useXScaling = 1;
}
else if((solverData->info == 4 || solverData->info == 5) && assertRetries < 1+solverData->n && assertCalled)
{
Expand Down Expand Up @@ -950,12 +980,11 @@ int solveHybrd(DATA *data, int sysNumber)
INFO1(LOG_NLS, "### No Solution! ###\n after %d restarts", retries*retries2*retries3);
printStatus(solverData, &nfunc_evals, &xerror, &xerror_scaled, LOG_NLS);
}
/* take the best approximation */
memcpy(systemData->nlsx, solverData->x, solverData->n*(sizeof(double)));
}
}

/* take the best approximation */
memcpy(systemData->nlsx, solverData->x, solverData->n*(sizeof(double)));

/* reset some solving data */
solverData->factor = initial_factor;
solverData->mode = 1;
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/simulation/solver/perform_simulation.c
Expand Up @@ -115,9 +115,9 @@ int performSimulation(DATA* data, SOLVER_INFO* solverInfo)
while(solverInfo->currentTime < simInfo->stopTime)
{
mem_state = get_memory_state();
currectJumpState = ERROR_SIMULATION;
/* try */
if (!setjmp(simulationJmpbuf)) {
currectJumpState = ERROR_SIMULATION;

if (measure_time_flag) {
for(i = 0; i < data->modelData.modelDataXml.nFunctions + data->modelData.modelDataXml.nProfileBlocks; i++) {
Expand Down
6 changes: 5 additions & 1 deletion SimulationRuntime/c/simulation/solver/solver_main.c
Expand Up @@ -314,6 +314,7 @@ int initializeModel(DATA* data, const char* init_initMethod,
int lambda_steps)
{
int retValue = 0;
state mem_state;

SIMULATION_INFO *simInfo = &(data->simulationInfo);

Expand All @@ -334,20 +335,23 @@ int initializeModel(DATA* data, const char* init_initMethod,
setZCtol(simInfo->tolerance);


currectJumpState = ERROR_SIMULATION;
mem_state = get_memory_state();
/* try */
if (!setjmp(simulationJmpbuf))
{
currectJumpState = ERROR_SIMULATION;
if(initialization(data, init_initMethod, init_optiMethod, init_file, init_time, lambda_steps))
{
WARNING(LOG_STDOUT, "Error in initialization. Storing results and exiting.\nUse -lv=LOG_INIT -w for more information.");
simInfo->stopTime = simInfo->startTime;
retValue = -1;
}
restore_memory_state(mem_state);
}
/* catch */
else
{
restore_memory_state(mem_state);
retValue = -1;
INFO(LOG_STDOUT, "model terminate | Simulation terminated by an assert at initialization");
}
Expand Down

0 comments on commit 388b23c

Please sign in to comment.