Skip to content

Clarify/Allow ExternalObject (member) functions to be used for (flexible) array parameters/dimensions #2425

@beutlich

Description

@beutlich

Based on the technical blog post from @Claytex, it is currently either tool-specific or unspecified, if ExternalObject (member) functions can be used for flexible array sizes (as described in section 12.4.5 of the Modelica Language Specification v3.4).

The below example demonstrates what @GarronFish's intention is, i.e., to read a vector of unknown dimension from an XML file and use it as parameter.

// Fails in Dymola 2020/2020x/2021/2021x
// Works in SimulationX 4.x
model SizingExampleXML2
  constant String hString = "multiTank.tankHeights" "XML element name";
  constant String fName = "C:\\temp\\multiTank1.xml" "XML file name";
  parameter ExternData.XMLFile extObj(fileName=fName) "Implemented as external object";
  parameter Real heightVector[:] = extObj.getRealArray1D(hString, extObj.getArraySize1D(hString)) "Array parameter";
  annotation(uses(ExternData(version="2.5.0")));
end SizingExampleXML2;

with

<?xml version="1.0"?> <!-- multiTank1.xml -->
<ExternData>
  <multiTank>
     <tankHeights>{30,20,10,0}</tankHeights>
     <initialTankLevels>{10,0,0,0}</initialTankLevels>
  </multiTank>
</ExternData>

This example fails in Dymola 2020 with

Translation of SizingExampleXML2:

Failed to expand the variable heightVector
and its definition equation:
extObj.getRealArray1D_Unique'"extObj"'(
hString, 
extObj.getArraySize1D_Unique'"extObj"'(
hString, 
extObj.xml), 
extObj.xml)

Errors detected in variable declarations.

Translation aborted.

ERRORS have been issued.

but runs in SimulationX 4.0.

@GarronFish's workaround was to wrap the C code of the external object in another C functions to be used as Modelica functions for flexible array sizes. (In his case, problems with thread-safety were introduced when using global variables for one-time construction and destruction of the external object. This of course could be improved, but I'd claim, that it would be even better, if no such workaround would be necessary at all.)

Please clarify, if ExternalObject (member) functions can be used for parameter expressions of flexible array size.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions