Changeset 14008


Ignore:
Timestamp:
Nov 11, 2019 8:32:28 PM (4 weeks ago)
Author:
Christian Andersson
Message:

Updated the no state solver and added tests. Related to ticket:5720

Location:
branches/dev-cw-ii
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-cw-ii/Python/src/pymodelica/compiler_logging.py

    r13384 r14008  
    9797    JVM is unable to allocate enough memory.
    9898    """
     99    def close(self):
     100        pass
     101       
    99102    def __init__(self, stream):
    100103        self.stream = stream
  • branches/dev-cw-ii/Python/src/tests_jmodelica/test_fmi.py

    r13384 r14008  
    239239        res = model.simulate(final_time=1.0)
    240240        nose.tools.assert_almost_equal(res.final("x"),1.0)
     241   
     242    @testattr(stddist_full = True)
     243    def test_no_state_solver(self):
     244        model = load_fmu(Test_FMUModelCS1.rlc_circuit)
     245       
     246        model.set("_cs_solver",2) #Set the no state solver
     247
     248        nose.tools.assert_raises(Exception, model.initialize)
    241249
    242250    @testattr(stddist_full = True)
  • branches/dev-cw-ii/Python/src/tests_jmodelica/test_fmi_2.py

    r13384 r14008  
    181181        cls.assert_fail = compile_fmu("AssertFail",os.path.join(path_to_mofiles,"Terminate.mo"),target="cs", version="2.0")
    182182        cls.initialize_solver = compile_fmu("Inputs.DiscChange",os.path.join(path_to_mofiles,"InputTests.mo"),target="cs", version="2.0")
     183   
     184    @testattr(stddist_full = True)
     185    def test_no_state_solver(self):
     186        model = load_fmu(Test_FMUModelCS2.coupled_name)
     187       
     188        model.set("_cs_solver",2) #Set the no state solver
     189
     190        nose.tools.assert_raises(Exception, model.initialize)
    183191   
    184192    @testattr(stddist_full = True)
  • branches/dev-cw-ii/RuntimeLibrary/src/fmi1_cs/fmi1_cs.c

    r11712 r14008  
    299299    /* These options for the solver need to be found in a better way. */
    300300    options = jmi_ode_solver_default_options();
    301     options.method                  = fmi1_me->jmi.options.cs_solver;
     301    if (ode_problem->sizes.states > 0) {
     302        options.method                  = fmi1_me->jmi.options.cs_solver;
     303       
     304        if (options.method == JMI_ODE_NO_STATE) {
     305            jmi_log_node(ode_problem->log, logError, "FMIState",
     306                "Can only use the 'no state' solver for models without states, please choose another solver.");
     307            return fmiError;
     308        }
     309    } else {
     310        options.method                  = JMI_ODE_NO_STATE;
     311    }
    302312    options.euler_options.step_size = fmi1_me->jmi.options.cs_step_size;
    303313    options.cvode_options.rel_tol   = fmi1_me->jmi.options.cs_rel_tol;
  • branches/dev-cw-ii/RuntimeLibrary/src/fmi2/fmi2_cs.c

    r13384 r14008  
    194194    ode_sizes.event_indicators = jmi->n_relations;
    195195    fmi2_cs->cs_data = jmi_new_cs_data(c, jmi->n_real_u);
    196     fmi2_cs -> ode_problem = jmi_new_ode_problem(&jmi->jmi_callbacks,
    197         fmi2_cs->cs_data, ode_callbacks, ode_sizes, jmi->log);
     196    fmi2_cs->ode_problem = jmi_new_ode_problem(&jmi->jmi_callbacks,
     197    fmi2_cs->cs_data, ode_callbacks, ode_sizes, jmi->log);
    198198   
    199199    return fmi2OK;
  • branches/dev-cw-ii/RuntimeLibrary/src/fmi2/fmi2_me.c

    r13384 r14008  
    276276        if (ode_problem->sizes.states > 0) {
    277277            options.method                  = jmi->options.cs_solver;
     278           
     279            if (options.method == JMI_ODE_NO_STATE) {
     280                jmi_log_node(((fmi2_me_t *)c)->jmi.log, logError, "FMIState",
     281                    "Can only use the 'no state' solver for models without states, please choose another solver.");
     282                return fmi2Error;
     283            }
    278284        } else {
    279285            options.method                  = JMI_ODE_NO_STATE;
  • branches/dev-cw-ii/RuntimeLibrary/src/jmi/jmi_ode_no_state.c

    r12187 r14008  
    6262        return JMI_ODE_ERROR;
    6363    }
    64 
    65 
     64   
    6665    /* Check if an event indicator has triggered */
    67     if(sizes.event_indicators > 0){
     66    if(sizes.event_indicators > 0) {
    6867        flag = problem->ode_callbacks.root_func(tend, NULL, event_indicators, sizes, problem->problem_data);
    6968       
    70         if (flag != 0){
     69        if (flag != 0) {
    7170            jmi_log_node(problem->log, logError, "NoStateSolver",
    7271                "Could not retrieve event indicators");
    7372            return JMI_ODE_ERROR;
    7473        }
     74
     75        for (k = 0; k < sizes.event_indicators; k++) {
     76            if (event_indicators[k]*event_indicators_previous[k] < 0) {
     77                zero_crossning_event = 1;
     78                break;
     79            }
     80        }
     81        memcpy(event_indicators_previous, event_indicators, sizes.event_indicators * sizeof(jmi_real_t));
    7582    }
    76 
    77     for (k = 0; k < sizes.event_indicators; k++) {
    78         if (event_indicators[k]*event_indicators_previous[k] < 0) {
    79             zero_crossning_event = 1;
    80             break;
    81         }
    82     }
    83     memcpy(event_indicators_previous, event_indicators, sizes.event_indicators * sizeof(jmi_real_t));
    84        
     83   
    8584    /* After each step call completed integrator step */
    8685    flag = problem->ode_callbacks.complete_step_func(&step_event, &terminate, problem->problem_data);
     
    9392    /* Handle events */
    9493    if (zero_crossning_event || step_event == TRUE) {
    95         jmi_log_node(problem->log, logInfo, "EulerEvent", "An event was detected at <t:%g>", tend);
     94        jmi_log_node(problem->log, logInfo, "NoStateSolver", "An event was detected at <t:%g>", tend);
    9695        return JMI_ODE_EVENT;
    9796    }
Note: See TracChangeset for help on using the changeset viewer.