Opened 5 years ago
Closed 5 years ago
#5889 closed defect (fixed)
Creating FMU with option -d=-disableDirectionalDerivatives makes fmi2Instantiate() crash.
Reported by: | Owned by: | Andreas Heuermann | |
---|---|---|---|
Priority: | blocker | Milestone: | Future |
Component: | FMI | Version: | v1.16.0-dev |
Keywords: | Cc: |
Description
I'm trying to setup a simple system composed by a Model Exchange FMU coupled to an implicit euler solver. To do this, I need to call the fmi2GetDirectionalDerivative function, which is available if the FMU is generated from the modelica source using the "-d=-disableDirectionalDerivatives" option.
However, this makes the fmi2Instantiate() crash with a segmentation fault, which I traced (using the crash report informations and objdump) to an issue inside the function FmiTest_Model_initialAnalyticJacobianFMIDER, generated by OpenModelica.
I've attached a minimal example. The steps to reproduce the issue are:
- unzip the folder
- run "cmake ." inside it to setup the building environment (it requires the pugixml library to be installed)
- running "make" and then "./fmitest" with files as-is make the program crash
- editing the 6th line of file "buldfmi.mos" so that it does not contain anymore the option "-d=-disableDirectionalDerivatives", then issuing "make clean" followed by "make" and "./fmitest" will not produce a program crash.
Attachments (1)
Change History (5)
by , 5 years ago
Attachment: | fmi_crash_example.zip added |
---|
comment:1 by , 5 years ago
I was able to confirm your example and recreated a minimal working example (so I don't have to add pugixml every time).
loadModel(Modelica); getErrorString(); setCommandLineOptions("-d=newInst,-disableDirectionalDerivatives"); getErrorString(); buildModelFMU(Modelica.Electrical.Analog.Examples.Rectifier, version="2.0", fmuType="me_cs", platforms={"static"}); getErrorString(); system("OMSimulator Modelica.Electrical.Analog.Examples.Rectifier.fmu"); getErrorString();
The problem is probably that the fmi jacobian doesn't get allocated at all.
In SimulationRuntime/fmi/export/openmodelica/fmi2_model_interface.c.inc
/* allocate memory for Jacobian */ comp->_has_jacobian = 0; comp->fmiDerJac = NULL; if (comp->fmuData->callback->initialPartialFMIDER != NULL){ if (! comp->fmuData->callback->initialPartialFMIDER(comp->fmuData, comp->threadData, comp->fmiDerJac)) { comp->_has_jacobian = 1; } }
Adding
if (jacobian == NULL) { jacobian = (ANALYTIC_JACOBIAN*) calloc(1,sizeof(ANALYTIC_JACOBIAN)); }
manually solves the initialization.
I will polish my solution a bit and finalize it tomorrow. Maybe deallocating memory at the end would be a good idea.
comment:2 by , 5 years ago
Thank you, applying your solution makes everything working.
I leave to you the decision about closing this issue as solved or not.
comment:3 by , 5 years ago
Did you try today's nightly build? The fix should be available as of today.
See PR 770.
If everything is working you can just close this issue.
comment:4 by , 5 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
@silvano, if you open a ticket and you are happy with the outcome, you can close it yourself, unless there are other pending issues.
Source files