Changeset 14182


Ignore:
Timestamp:
Nov 26, 2019 2:19:55 PM (9 days ago)
Author:
Jonathan Kämpe
Message:

#5883 Added failing test case for differentiating composite statements.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-jk-2720/Compiler/ModelicaCBackEnd/test/modelica/CCodeGenCompositeStatementTests.mo

    r14173 r14182  
    321321    end RecordStmt5;
    322322
     323    model DifferentiatedStmt1
     324        function f
     325            input Real x;
     326            constant Real[:] c = {3,4};
     327            Real[:] t1 = {1, 2};
     328            Real[:] t2 = c;
     329            output Real[:] y = x .+ t1 .+ t2;
     330        algorithm
     331            annotation(smoothOrder=2);
     332        end f;
     333       
     334        Real[:] y = f(time);
     335        Real x;
     336    equation
     337        der(y[1]) = der(x);
     338
     339annotation(__JModelica(UnitTesting(tests={
     340    CCodeGenTestCase(
     341        name="DifferentiatedStmt1",
     342        description="",
     343        template="
     344$C_functions$
     345",
     346        generatedCode="
     347void func_CCodeGenCompositeStatementTests_DifferentiatedStmt1_f_def0(jmi_real_t x_v, jmi_array_t* y_a) {
     348    JMI_DYNAMIC_INIT()
     349    JMI_ARR(STACK, jmi_real_t, jmi_array_t, t1_a, 2, 1)
     350    JMI_ARR(STACK, jmi_real_t, jmi_array_t, t2_a, 2, 1)
     351    JMI_ARR(STACK, jmi_real_t, jmi_array_t, y_an, 2, 1)
     352    JMI_ARR(STACK, jmi_real_t, jmi_array_t, temp_1_a, 2, 1)
     353    jmi_real_t i1_0i;
     354    jmi_int_t i1_0ie;
     355    jmi_int_t i1_0in;
     356    JMI_ARRAY_INIT_1(STACK, jmi_real_t, jmi_array_t, t1_a, 2, 1, 2)
     357    JMI_ARRAY_INIT_1(STACK, jmi_real_t, jmi_array_t, temp_1_a, 2, 1, 2)
     358    jmi_array_ref_1(temp_1_a, 1) = 1;
     359    jmi_array_ref_1(temp_1_a, 2) = 2;
     360    JMI_ASG(GEN_ARR, t1_a, temp_1_a)
     361    JMI_ARRAY_INIT_1(STACK, jmi_real_t, jmi_array_t, t2_a, 2, 1, 2)
     362    JMI_ASG(GEN_ARR, t2_a, JMI_GLOBAL(CCodeGenCompositeStatementTests_DifferentiatedStmt1_f_c))
     363    if (y_a == NULL) {
     364        JMI_ARRAY_INIT_1(STACK, jmi_real_t, jmi_array_t, y_an, 2, 1, 2)
     365        y_a = y_an;
     366    }
     367    i1_0in = 0;
     368    i1_0ie = floor((2) - (1));
     369    for (i1_0i = 1; i1_0in <= i1_0ie; i1_0i = 1 + (++i1_0in)) {
     370        jmi_array_ref_1(y_a, i1_0i) = x_v + jmi_array_val_1(t1_a, i1_0i) + jmi_array_val_1(t2_a, i1_0i);
     371    }
     372    JMI_DYNAMIC_FREE()
     373    return;
     374}
     375
     376void func_CCodeGenCompositeStatementTests_DifferentiatedStmt1__der_f_def1(jmi_real_t x_v, jmi_real_t _der_x_v, jmi_array_t* _der_y_a) {
     377    JMI_DYNAMIC_INIT()
     378    JMI_ARR(STACK, jmi_real_t, jmi_array_t, _der_y_an, 2, 1)
     379    JMI_ARR(STACK, jmi_real_t, jmi_array_t, t1_a, 2, 1)
     380    JMI_ARR(STACK, jmi_real_t, jmi_array_t, _der_t1_a, 2, 1)
     381    JMI_ARR(STACK, jmi_real_t, jmi_array_t, t2_a, 2, 1)
     382    JMI_ARR(STACK, jmi_real_t, jmi_array_t, _der_t2_a, 2, 1)
     383    JMI_ARR(STACK, jmi_real_t, jmi_array_t, y_a, 2, 1)
     384    JMI_ARR(STACK, jmi_real_t, jmi_array_t, temp_1_a, 2, 1)
     385    jmi_real_t i1_1i;
     386    jmi_int_t i1_1ie;
     387    jmi_int_t i1_1in;
     388    JMI_ARRAY_INIT_1(STACK, jmi_real_t, jmi_array_t, t1_a, 2, 1, 2)
     389    JMI_ARRAY_INIT_1(STACK, jmi_real_t, jmi_array_t, _der_t1_a, 2, 1, 2)
     390    JMI_ARRAY_INIT_1(STACK, jmi_real_t, jmi_array_t, temp_1_a, 2, 1, 2)
     391    jmi_array_ref_1(temp_1_a, 1) = 1;
     392    jmi_array_ref_1(temp_1_a, 2) = 2;
     393    JMI_ASG(GEN_ARR, _der_t1_a, zeros(2.0))
     394    JMI_ASG(GEN_ARR, t1_a, temp_1_a)
     395    JMI_ARRAY_INIT_1(STACK, jmi_real_t, jmi_array_t, t2_a, 2, 1, 2)
     396    JMI_ARRAY_INIT_1(STACK, jmi_real_t, jmi_array_t, _der_t2_a, 2, 1, 2)
     397    JMI_ASG(GEN_ARR, _der_t2_a, {0.0, 0.0})
     398    JMI_ASG(GEN_ARR, t2_a, JMI_GLOBAL(CCodeGenCompositeStatementTests_DifferentiatedStmt1_f_c))
     399    JMI_ARRAY_INIT_1(STACK, jmi_real_t, jmi_array_t, y_a, 2, 1, 2)
     400    if (_der_y_a == NULL) {
     401        JMI_ARRAY_INIT_1(STACK, jmi_real_t, jmi_array_t, _der_y_an, 2, 1, 2)
     402        _der_y_a = _der_y_an;
     403    }
     404    i1_1in = 0;
     405    i1_1ie = floor((2) - (1));
     406    for (i1_1i = 1; i1_1in <= i1_1ie; i1_1i = 1 + (++i1_1in)) {
     407        jmi_array_ref_1(_der_y_a, i1_1i) = _der_x_v + jmi_array_val_1(_der_t1_a, i1_1i) + jmi_array_val_1(_der_t2_a, i1_1i);
     408        jmi_array_ref_1(y_a, i1_1i) = x_v + jmi_array_val_1(t1_a, i1_1i) + jmi_array_val_1(t2_a, i1_1i);
     409    }
     410    JMI_DYNAMIC_FREE()
     411    return;
     412}
     413")})));
     414    end DifferentiatedStmt1;
     415
    323416end CCodeGenCompositeStatementTests;
Note: See TracChangeset for help on using the changeset viewer.