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
Adding yet another Complex record seems wrong #1122
Comments
Comment by otter on 24 May 2013 07:14 UTC
Sorry, there was a wrong import statement that I have just corrected in f8d78bf.
The used publication for the modeling of ice needed for ReferenceMoistAir used complex numbers for the (complicated) formulas. Hubertus suggested to not use Complex from MSL for that, because then tools not yet supporting operator overloading cannot handle Media. Since it seemed not easy to rewrite the equations to array notation, I made a copy of Complex and rewrote it so that it contains only a record with functions. The original Complex cannot be used because language elements "operator record" and "operator" are present, and a tool not supporting operator overloading will not support them. Stefan then used this class locally in ReferenceMoistAir and rewrote the equations. Here the mentioned small error appeared that I just fixed. |
Comment by sjoelund.se on 24 May 2013 07:43 UTC Is there any good reason why Media could not use this approach? And anyway, Complex.mo has been part of the MSL for almost 3 years when we release 3.2.1. Surely that must be enough time for tools to support it. Note that the new Complex class was added as a public interface, which means you can not later remove it without breaking backwards compatibility. |
Comment by otter on 24 May 2013 11:16 UTC
No. Complex is defined as:
and the language keyword "operator" is only supported if operator overloading is supported.
I have made MyComplex protected in 711fb85 (this required a minor rewriting, because a protected record containing encapsulated functions that import an absolute path are not correct). |
Comment by sjoelund.se on 24 May 2013 11:29 UTC
Not true. A tool only needs to change their parser to say that Also, 711fb85 introduced a parsing error. And |
Comment by otter on 24 May 2013 11:37 UTC
As you write it: A tool has to change its parser. The goal is that a current tool that does not support overloading is able to process ReferenceMoistAir (without any parser changes).
In Dymola no error is reported, and I think Dymola is right. The structure is:
If this would not be allowed then this would also not be allowed:
|
Comment by beutlich on 24 May 2013 11:46 UTC |
Comment by sjoelund.se on 24 May 2013 11:47 UTC This hack seems ugly as hell just to make sure the code works in tools that are >3 years old anyway. And keep in mind this is only to make old tools work with a newly introduced model anyway. While we have had Complex.mo in the library for soon 3 years. Why was that library added if people don't want to use it? The model Test is different from the other one (doesn't use dot-notation and exists in the same scope as the protected function). And you should still not close the ticket since Modelica 3.2.1/Modelica/Media/Air/ReferenceMoistAir.mo:2429 Error: Parse error: The identifier at start and end are different (doesn't Dymola check for this?). |
Comment by otter on 24 May 2013 11:54 UTC
Adapted example:
Of course, this must be allowed. What is not allowed is an access Test.pack.fun. |
Comment by hansolsson on 24 May 2013 12:06 UTC
Note that "process" is a key point: Modelica.Electrical.QuasiStationery, Modelica.Magnetic.FundamentalWave use the Complex class. A tool not supporting operator overloading will not be able to handle those packages either. However, I don't understand the parsing bit: Complex is defined outside of MSL (using operator overloading).
Well, more importantly you would not be able to define a protected component and connect graphically to it:
The key point is that you are not able to use That is the general idea of using "protected" for encapsulation - protected contents is hidden from the outside, you have not hidden the protected contents from yourself! (BTW: Dymola should check that the name after "end" is correct, but only generate a warning and automatically correct it.) |
Comment by otter on 24 May 2013 12:13 UTC
Thanks for this hint. I made the changes with an editor and when reading with Dymola I have overseen the warning (and Dymola could not store its changed version). Fixed in d87b322 by correcting the typo in "end MyComplex". Martin (S.) can you confirm that ReferenceMoistAir is now parsed by OpenModelica. |
Comment by sjoelund.se on 24 May 2013 12:21 UTC Anyway, the comment about changing the parser is a quick hack to get operators running. If operator record is treated as a record, and operator (function) as function, you get the subset of operator overloading that does not require you to actually implement operator overloading (namely calling the individual functions like what was done in MyComplex). You could even go so far as to create a "Complex nooverloading.mo" that did not even contain the operator keywords, etc, if you are a tool vendor that does not support operator overloading yet. record Complex
function 'constructor'
...
end Complex;
model M
Complex c = Complex.'constructor'(1,0); // Would work in tools using both versions of Complex
end M; But why not use Complex directly like the other packages already do? |
Comment by otter on 24 May 2013 12:31 UTC
The other packages that use Complex (ComplexMath, ComplexBlocks, QuasiStationary, FundamentalWave) have been designed with Complex as basic building block (e.g. QuasiStationary is an implementation of stationary computation of electrical systems using complex numbers as used in the electrical literature). I will now release MSL 3.2.1 Beta 1 with MyComplex. If the discussion reveals to go back to the "Complex" solution we can do that for the release candidate. |
Modified by sjoelund.se on 20 Dec 2016 12:30 UTC |
Reported by sjoelund.se on 24 May 2013 06:41 UTC
eeee36f introduced a new record Modelica.Media...MyRecord, which is not only wrong but seems to be a weird design choice.
First of all, import MyRecord means the record's name has to be .MyRecord, but it does not exist on the top level, so the code is wrong.
And we anyway have operator overloading and a Complex class. So why would we introduce yet another class that does the same thing?
If this is due to some tool not supporting operator overloading,
[Note, the operator overloading as defined in this section is only a short hand notation for function calls.]
, which should mean you can use the operator record without implementing operator overloading, i.e.:Migrated-From: https://trac.modelica.org/Modelica/ticket/1122
The text was updated successfully, but these errors were encountered: