-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bad and incomplete text output when using getInstanceName() #9302
Comments
The The issue that the short name isn't printed is not solved though, but doesn't have anything to do with |
@max-privato please check with the next nightly and close this if fixed. |
@perost, which code are you referring to here? |
There are two print statements in the when-equation, but only one is actually printed when simulating the model. The when-equation depends on the when-algorithm to be executed first in order to give a value to |
I've checked with 1.20.0-dev-259. Now I receive: |
@max-privato, simple function calls in equation sections are not forbidden by the specification, but they are a bit fishy, because equations can be re-ordered based on dependencies, and it's not too clear what exactly must be done with them. Is there a reason why you used an algorithm to set the variables and an equation to print them? What about putting the two print statements in the algorithm? |
I'd be curious why that is considered "fishy". Does a function call not also have a straightforward dependency relationship: depends on its arguments? So, it would be reordered to be called when its dependencies/arguments are fully known? |
See modelica/ModelicaSpecification#3227. Given that the print functions are impure and are called within a when statement, this should actually work as you expect. |
I understand that the "print" directives are very special equations (they could be used in imperative languages as statements instead of equations). I did not think much about choosing an equation or algorithm action for them, but if they are allowed as I propose, they should work. |
I tried to flatten RW.W2root, this is the outcome: class RW.W2root "OM does not write nameShort"
final parameter String w2.name = "W2root.w2";
String w2.nameShort;
Integer w2.index;
equation
when initial() then
Modelica.Utilities.Streams.print("### model full path: '" + w2.name + ".mat" + "'", "");
Modelica.Utilities.Streams.print("### model short name: '" + w2.nameShort + ".mat" + "'", "");
end when;
algorithm
when initial() then
w2.index := Modelica.Utilities.Strings.findLast(w2.name, ".", 0, true);
w2.nameShort := Modelica.Utilities.Strings.substring(w2.name, w2.index + 1, Modelica.Utilities.Strings.length(w2.name));
end when;
end RW.W2root;
/*
equation index: 4
type: WHEN
when {} then
noReturnCall(Modelica.Utilities.Streams.print("### model short name: '" + w2.nameShort + ".mat" + "'", ""))%>);
end when;
*/
void W2root_eqFunction_4(DATA *data, threadData_t *threadData)
{
TRACE_PUSH
const int equationIndexes[2] = {1,4};
static const MMC_DEFSTRINGLIT(tmp3,23,"### model short name: '");
modelica_metatype tmpMeta4;
static const MMC_DEFSTRINGLIT(tmp5,4,".mat");
modelica_metatype tmpMeta6;
modelica_metatype tmpMeta7;
if(0)
{
tmpMeta4 = stringAppend(MMC_REFSTRINGLIT(tmp3),(data->localData[0]->stringVars[0] /* w2.nameShort DISCRETE */));
tmpMeta6 = stringAppend(tmpMeta4,MMC_REFSTRINGLIT(tmp5));
tmpMeta7 = stringAppend(tmpMeta6,(modelica_string) mmc_strings_len1[39]);
omc_Modelica_Utilities_Streams_print(threadData, tmpMeta7, (modelica_string) mmc_emptystring);
}
TRACE_POP
} Obviously the statement following |
See #10763. @max-privato as a workaround for the time being you should avoid String variables corresponding to String equations that are solved at runtime. Only use String parameters and encapsulate the former when initial algorithm in a function: package RWNew
model W2root "OM does not write nameShort"
W2 w2;
end W2root;
model W2 "does not write nameShort"
final parameter String name = getInstanceName();
final parameter String nameShort = getShortName(name);
function getShortName
input String name;
output String nameShort;
protected
Integer index;
algorithm
index := Modelica.Utilities.Strings.findLast(name, ".");
nameShort := Modelica.Utilities.Strings.substring(name, index + 1, Modelica.Utilities.Strings.length(name));
end getShortName;
equation
when initial() then
Modelica.Utilities.Streams.print("### model full path: '" + name + ".mat" + "'");
Modelica.Utilities.Streams.print("### model short name: '" + nameShort + ".mat" + "'");
end when;
annotation (
experiment(StartTime = 0, StopTime = 2, Tolerance = 1e-6, Interval = 0.04));
end W2;
end RWNew; |
Good to have a work around. |
Description and Steps to Reproduce
Consider the following code:
When I run W2root, the expected output in message window, and the actual output obtained from Dymola is:
And this is what I read when I run it from Dymola. If I run W2root from OM 1.19.0, instead, I read:
### model full path: 'RW.W2root.w2.mat'
Here I see two issues:
Expected Behavior
I expect to read the following rows in the log:
Screenshots
Version and OS
OM 1.19.2 Win10 64bit
omc --version
orHelp->About OMEdit
from OMEdit]Additional Context
See also #9301 and #9303
The text was updated successfully, but these errors were encountered: