Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#3999 closed defect (fixed)

Variable name creation problem in C sources when model using complex object hierarchy and algebraic loops are built

Reported by: robert@… Owned by: Willi Braun
Priority: normal Milestone: 1.11.0
Component: Backend Version: v1.11.0
Keywords: Cc:

Description

To reproduce the problem I created a simple test library and a test .mo file which are attached to the ticket.

To reproduce the problem, follow the steps below:

  1. Download and extract the attached TestLibrary 0.0.1.zip to a convenient location.
  2. Download the attached TestPlant.mo file.
  3. Start the OMShell by typing 'OMShell-terminal'
  4. Issue a 'setModelicaPath(<parent path where you extracted the test library>)' command. The system's reply shall be 'true'.
  5. Issue a 'loadModel(TestLibrary)' command. The system's reply should be 'true' again.
  6. Issue a 'loadFile(<the path where you've downloaded the TestPlant.mo>)' command. Again, the expected reply is 'true'.
  7. Issue a 'simulate(Model2Test, outputFormat="csv")' command.

Here the OMShell reports an error message: 'Failed to build model: Model2Test'.
By this time the C sources are sitting in the folder where the OMShell had been started in and the Model2Test.log file is crowded with messages like this:

Model2Test_12jac.c:150:3: error: expected expression

$Pi$Psm4$Pspecies_TestLibrary.Models.ModelContainer2.Model2.Species.SP4_$P$pDERNLSJac1$PdummyVarNLSJac1 = (7.142857142857143e-05) * ((data->simulationInfo->realParameter[5] /* i._sm1._S4 PARAM */) * (($Pi_sm4_species_TestLibrary.Models.ModelContainer2.Model2.Species.SP1_SeedNLSJac1) * (DIVISION_SIM(data->localData[0]->realVars[11] /* i._sm4._var51 variable */,(tmp6 * tmp6),"(i.sm4.species[TestLibrary.Models.ModelContainer2.Model2.Species.SP1] + i.sm4.var51) 2.0",equationIndexes))));

(If needed, I can attach the full log as well).

So it seems that the generated C code is invalid. The expected behavior is that if the Modelica code is invalid, we should get a meaningful error message before the C code is generated; if however, the Modelica code is correct, then the C compilation should not fail.

I was able to reproduce the problem on a Mac and on Ubuntu xenial as well.

The omc --version command returned 'OpenModelica 1.11.0~dev-44-g9e3a252'

Thanks for your efforts!

Please let me know if further details are needed to investigate the problem.

The omc--version command

Attachments (3)

TestLibrary 0.0.1.zip (1.6 MB ) - added by robert@… 8 years ago.
Test library for reproducing the problem.
TestPlant.mo (593 bytes ) - added by robert@… 8 years ago.
Test model for reproducing the issue.
total.mo (11.0 KB ) - added by Martin Sjölund 8 years ago.
Total model of the attached example

Download all attachments as: .zip

Change History (7)

by robert@…, 8 years ago

Attachment: TestLibrary 0.0.1.zip added

Test library for reproducing the problem.

by robert@…, 8 years ago

Attachment: TestPlant.mo added

Test model for reproducing the issue.

by Martin Sjölund, 8 years ago

Attachment: total.mo added

Total model of the attached example

comment:1 by Martin Sjölund, 8 years ago

Owner: changed from somebody to Willi Braun
Status: newassigned

The generated cref contains dots instead of underscores (also for the #define). Willi: can you have a look?

comment:2 by Willi Braun, 8 years ago

Status: assignedaccepted

comment:3 by Willi Braun, 8 years ago

Component: *unknown*Backend
Resolution: fixed
Status: acceptedclosed

Ihe issue was related to the usage of enumerations as array subscript.
Fixed in 895a1e1/OMCompiler.

comment:4 by Willi Braun, 8 years ago

Milestone: Future1.11.0
Note: See TracTickets for help on using tickets.