FMPy icon indicating copy to clipboard operation
FMPy copied to clipboard

Add support for array inputs

Open Maplesoft-fmigroup opened this issue 3 years ago • 6 comments

FMPy does not seem to support input arrays. I have an FMU with a 2-element Float64 input vector. The call to fmi3SetFloat64 is being made with a correct value reference for the input vector but 'nValues' set to 1 instead of 2 (and values[] contains only the first value from the csv input file). The CSV input file is of the form: "time", "InpVec", "InpVec" 0.0, 1.0, 2.0 etc.

Maplesoft-fmigroup avatar Dec 06 '22 18:12 Maplesoft-fmigroup

Hi,

correct me if I understood FMI 3.0 standard wrongly: fmi3SetFloat64() cannot be used to set values for arrays, because all array elements (of the same array) share the same value reference and you can only set a single float64 value for each value reference.

The only possible way to set value for arrays, given the current status of the FMI 3.0 standard, is to use fmi3SetString to set all elements of an array at once, by a string of decimal representations of these floats separated by whitespaces.

Regards,

Chun Tian

binghe avatar May 16 '23 10:05 binghe

@binghe Yes you can, notice that nValues does NOT have to equal nValueReferences. So you can have valueReferences = [5] and values = [1.0, 2.0, 3.0, 4.0] to set a vector of size 4.

Maplesoft-fmigroup avatar May 16 '23 12:05 Maplesoft-fmigroup

@binghe Yes you can, notice that nValues does NOT have to equal nValueReferences. So you can have valueReferences = [5] and values = [1.0, 2.0, 3.0, 4.0] to set a vector of size 4.

Thanks for your answer! What happens if there are two value references, say 5 and 6, both are vectors of size 4. Should I implement the FMU's fmi3SetFloat64 to take:

valueReferences = [5, 6]

and

values = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]

And the FMU should correct assign the first 4 values to the array behind reference 5 and the rest 4 values to the array behind reference 6? (If there's more than one dimensions for the array, the order of values will be aligned to the behavior when serializing the FMU states, as described in the standard).

binghe avatar May 16 '23 12:05 binghe

Yes, your FMU will have to know that value reference 5 represents an array and assign the appropriate number of values from the 'values' array.

Maplesoft-fmigroup avatar May 16 '23 15:05 Maplesoft-fmigroup

Thanks again for your clarification!

binghe avatar May 16 '23 17:05 binghe

Where shall the CSV format for array variables be specified? Here: https://github.com/modelica/fmi-standard.org/blob/main/CONTRIBUTING.md#csv-rules-for-inout-and-result-files-for-compatibility-information ? Or shall we put this at some other location?

chrbertsch avatar Aug 28 '23 10:08 chrbertsch