Ticket #4411: enhanced_fixed_point_iteration_fix.patch

File enhanced_fixed_point_iteration_fix.patch, 3.1 KB (added by efredriksson, 4 years ago)
  • RuntimeLibrary/src/jmi/jmi_block_residual.c

     
    124124    /* Write back the current values of the iteration variables. */
    125125    block->F(jmi, block->work_ivs, NULL, JMI_BLOCK_WRITE_BACK);
    126126    /* Reset the values of the switches and non-reals in the block. */
     127    block->F(jmi, block->work_ivs, block->res, JMI_BLOCK_EVALUATE | JMI_BLOCK_EVALUATE_NON_REALS);
    127128    jmi_block_set_sw_nr(block, block->work_switches, block->work_non_reals);
    128129   
    129130    /* Compare current switches and non-reals with their previous values */
  • RuntimeLibrary/src/jmi/jmi_block_solver.c

     
    489489            /* Write back the current iteration variables, needed for checking discrete variables. */
    490490            block_solver->F(block_solver->problem_data, x, NULL, JMI_BLOCK_WRITE_BACK);
    491491
     492            /* Check for convergence in first try before computing a reduced step */
     493            if (block_solver->check_discrete_variables_change(block_solver->problem_data, x_new) > 0) {
     494                /* Set the correct solution */
     495                block_solver->F(block_solver->problem_data, x_new, NULL, JMI_BLOCK_WRITE_BACK);
     496                block_solver->update_discrete_variables(block_solver->problem_data, &non_reals_changed_flag);
     497                jmi_log_node(log, logInfo, "Found consistent solution on first try in enhanced fixed point iteration in <block:%s, iter:%I> at <t:%E>",
     498                        block_solver->label, iter, cur_time);
     499                converged = 1;
     500            }
     501
    492502            iter = 0;
    493             while (1 && ef==0){
     503            while (ef==0 && converged==0){
    494504
    495505                jmi_log_node_t iter_node = jmi_log_enter_fmt(log, logInfo, "BlockIteration",
    496506                    "Enhanced block iteration <iter:%I> at <t:%g>",
     
    511521                block_solver->F(block_solver->problem_data,x,NULL,JMI_BLOCK_WRITE_BACK);
    512522
    513523                ef = block_solver->update_discrete_variables(block_solver->problem_data, &non_reals_changed_flag);
    514                 if (non_reals_changed_flag == 0){
     524                if (non_reals_changed_flag == 0) {
    515525                    jmi_log_node(log, logError, "Error", "Error updating discrete variables with the new x <block:%s, iter:%I> at <t:%E>",
    516526                        block_solver->label, iter, cur_time);
    517527                    jmi_log_leave(log, iter_node);
     
    567577                    jmi_log_fmt(log, iter_node, logInfo, "Found consistent solution using enhanced fixed point iteration in <block:%s, iter:%I> at <t:%E>",
    568578                        block_solver->label, iter, cur_time);
    569579                    converged = 1;
    570                     jmi_log_leave(log, iter_node);
    571                     break;
    572580                }
    573581
    574582                jmi_log_leave(log, iter_node);