Skip to content

size(A, j) as constant expression #2240

@modelica-trac-importer

Description

@modelica-trac-importer

Reported by perost on 20 Mar 2018 13:20 UTC
The specification makes an exception from the normal variability rules for size(A, j), such that it's a parameter expression as long as j is a parameter expression and A isn't declared in a function. The rationale here seems to be that it's the variability of the particular dimension of A that matters, not the variability of A itself.

However, there's no such exception in the section for constant expressions, which means that size(A, j) where A and j are constant expressions is a constant expression. This is also used in the MSL, for example to define the constants nS and nC in Modelica.Media.Interfaces.PartialMedium.

This means that size can be used to "cast" a parameter expression into a constant expression:

parameter Integer p = 3;

// Not legal:
constant Integer c = p;

// Currently legal:
constant Real x[p] = zeros(p);
constant Integer c = size(x, 1);

Would it not make more sense to define the variability of size(A, j) in terms of the variability of dimension j of A instead? I.e. the variability of size(A, j) should be the most variable of the expression j and the dimension j of the variable A.


Migrated-From: https://trac.modelica.org/Modelica/ticket/2240

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions