1

I have a class with a port of dimensions [x,y] which is connected to another class having a matching port. Now I want to provide value to these variables [x,y] through external function call in which I basically read a .xml file and obtain values for x and y. But Dymola gives an error for this since during compilation it comes out as a non fixed size array.

Screenshot of error is attached.enter image description here

Rohit_D
  • 85
  • 1
  • 11

2 Answers2

3

The array sizes are structural parameters and they usually cannot depend on external function calls because they should be known at compile time. This is however supported in for example OpenModelica where a dll of the external function is built and called and the results are fetched during model compilation.

The only way to support this in all tools is to generate the model using an external tool which reads the xml and changes the .mo file with the values read. You could probably have something like Parameters.mo:

package Parameters
  constant Integer nTube = <EXTERN_NTUBE>;
  constant Integer nSeg = <EXTERN_NSEG>;
end Parameters;

and your external tool will read the XML and bind and in Parameters.mo which you can then use in your models via Parameters.nTube and Parameters.nSeg. Maybe it would be good to give some defaults so that it works to use this file directly:

package Parameters
  constant Integer nTube = 1;
  constant Integer nSeg = 2;
end Parameters;

and then your external tool will replace 1 and 2 with the needed values before compilation.

Adrian Pop
  • 4,034
  • 13
  • 16
  • Thanks for you answer. I use Dymola and could you elaborate on how results can be fetched during model compilation from the external function? – Rohit_D Jun 16 '16 at 10:44
  • It highly depends on the tool, each tool does it differently as far as I know. – Adrian Pop Jun 16 '16 at 14:36
3

This should be improved in Dymola 2017 (without the need for modifying the Modelica code). In earlier versions of Dymola it should work if the you translate the C-functions called to compute nTube and nSeg.

If that does not help your complete code would be needed to analyze the problem.

Hans Olsson
  • 11,123
  • 15
  • 38
  • Do you mean it works if you build a C library out of the functions? Or you mean you need to translate the C functions to Modelica functions? – Adrian Pop Jun 16 '16 at 14:34
  • Thanks for the info. I will install Dymola 2017 and give it a try. Also could you elaborate on what you mean by translating C-function? I translate the whole model before running. – Rohit_D Jun 16 '16 at 16:37
  • I meant directly translating the Modelica-functions wrapping the C-functions, before translating the model using them. Just select "translate" for those functions in the same way as translating a model (translating, not simulating). – Hans Olsson Aug 19 '16 at 12:27