Open TongYuan-MC opened 6 months ago
FYI: Dymola 2024x, 2023-10-06
Modelica.Math.atan2(0, 1e-14);
= 0.0
Modelica.Math.atan2(1e-14, 1e-14);
= 0.7853981633974483
Modelica.Math.atan2(-1e-14, 1e-14);
= -0.7853981633974483
Modelica.Math.atan2(-1e-14, -1);
= -3.1415926535897833
Modelica.Math.atan2(1e-14, -1);
= 3.1415926535897833
FYI: Dymola 2024x, 2023-10-06
Modelica.Math.atan2(0, 1e-14); = 0.0 Modelica.Math.atan2(1e-14, 1e-14); = 0.7853981633974483 Modelica.Math.atan2(-1e-14, 1e-14); = -0.7853981633974483 Modelica.Math.atan2(-1e-14, -1); = -3.1415926535897833 Modelica.Math.atan2(1e-14, -1); = 3.1415926535897833
That is exactly as described in the C/C++-standard, when implementing IEC 60559 (normative appendix F). I thus cannot see that atan2 is a problem.
We would need more information which specific models cause problems - it could be that the result of atan2 should be stored, but not compared for regression testing. (Using HideResult is not a good idea.)
We are not saying there's something wrong with atan2
.
Our ideal is numerical algorithms always have errors, for model x(start = 0); der(x) = cos(time)
, x
won't be exact sin(time)
, so atan2(x, sin(time))
will not exact $\pm \frac{\pi}{4}$, and unpredictable when time is near an integer multiples of $\pi$.
When modifying certain strategies of numerical algorithms, we always get result comparison failures.
Please click the simulation result in origin comment, see blow:
I believe this (issue or not) should be discussed within https://github.com/modelica-tools/csv-compare instead.
Or should the corresponding reference signals of SoftStarter and SMEE_DOL be removed?
Or should the corresponding reference signals of SoftStarter and SMEE_DOL be removed?
I haven't checked all of the signals mentioned above, but if we take SoftStarter
's imc.rotorCage.arg_V.m
for example, it is not among the comparison signals: https://github.com/modelica/MAP-LIB_ReferenceResults/blob/v4.0.0/Modelica/Electrical/PowerConverters/Examples/ACAC/SoftStarter/comparisonSignals.txt
I disagree in removing comparison signals, this makes difficult comparing versions. We should shift the discussion to a "general" atan2-discussion, not related to special models.
OM v1.20.0 (64-bit) same results as mentioned by @tobolar and @HansOlsson for Dymola.
This phenomenon has a negative impact on the following situations
Example for illustration
atan2(x, y)
will change significantly whenx
andy
change slightly near 0 (same issue foratan3
). See blow:The following simple Modelica model which also show this:
We can see for Atan2Issue:
Modelica Tool:
Simulation Result of Atan2Issue by MWORKS, Dymola and OpenModelica
### Atan2Issue `z1` and `z2` should be $\pm \frac{\pi}{4}$ in mathematical sense. However `x` was got by numerical method such as Dassl, small differences in x and y near 0 are overamplified by `atan2`. As a result, `z1` and `z2` are unpredictable near integer multiples of $\pi$. #### MWORKS with Tolerance `1e-6`(default) and `1e-7` ![Atan2Issue1e_6_vs_1e_7_MWORKS](https://github.com/modelica/ModelicaStandardLibrary/assets/153701357/9f87b3ee-b9c4-4ad0-8f98-83c9dae28fa6) #### Dymola with Tolerance `1e-6`(default) and `1e-7` ![Atan2Issue1e_6_vs_1e_7_Dymola png](https://github.com/modelica/ModelicaStandardLibrary/assets/153701357/249c1559-f723-4875-87a3-d133292ecc04) #### OpenModelica with Tolerance `1e-6`(default) and `1e-7` ![Atan2Issue1e_6_vs_1e_7_OpenModelica](https://github.com/modelica/ModelicaStandardLibrary/assets/153701357/0dcfb592-019b-4467-bbf9-b33cba6c8886) #### MWORKS, Dymola and OpenModelica with Tolerance `1e-6`(default) ![Atan2Issue1e_6](https://github.com/modelica/ModelicaStandardLibrary/assets/153701357/eb42bdb4-13f1-4f5e-9f92-a1b1ad3564f2) #### MWORKS, Dymola and OpenModelica with Tolerance `1e-7` ![Atan2Issue1e_7](https://github.com/modelica/ModelicaStandardLibrary/assets/153701357/bb910cdc-fb5d-4ee5-bf55-d3844b4d39fc)There are many models in Modelica Standard Library using atan2 and atan3, This leads to problems when doing result comparing.
The following two example models in Modelica Standard Library 4.0 have same issue as model
Atan2Issue
Simulation Result of SMEE_DOL by MWORKS, Dymola and OpenModelica
### Modelica.Magnetic.FundamentalWave.Examples.BasicMachines.SynchronousMachines.SMEE_DOL (Modelica Standard Library 4.0) #### MWORKS with Tolerance `1e-6`(default) and `1e-7` ![SMEE_DOL1e_6_vs_1e_7_MWORKS](https://github.com/modelica/ModelicaStandardLibrary/assets/153701357/bbda140e-ffa6-49d2-b9d6-57279f6f77dd) #### Dymola with Tolerance `1e-6`(default) and `1e-7` ![SMEE_DOL1e_6_vs_1e_7_Dymola](https://github.com/modelica/ModelicaStandardLibrary/assets/153701357/14000c18-e58b-414b-9e02-6283293ac019) #### OpenModelica with Tolerance `1e-6`(default) and `1e-7` ![SMEE_DOL1e_6_vs_1e_7_OpenModelica](https://github.com/modelica/ModelicaStandardLibrary/assets/153701357/2aab0f00-86e6-4441-a70c-833c318907e7) #### MWORKS, Dymola and OpenModelica with Tolerance `1e-6`(default) ![SMEE_DOL1e_6](https://github.com/modelica/ModelicaStandardLibrary/assets/153701357/9d71c2d0-cad6-488d-be08-a3013c672bbc) #### MWORKS, Dymola and OpenModelica with Tolerance `1e-7` ![SMEE_DOL1e_7](https://github.com/modelica/ModelicaStandardLibrary/assets/153701357/aaacbebc-f21b-4565-b40a-e9493a36f2d0)Simulation Result of SoftStarter by Dymola 2024x and OpenModelica 1.22.1
### Modelica.Electrical.PowerConverters.Examples.ACAC.SoftStarter (Modelica Standard Library 4.0) #### MWORKS with Tolerance `1e-6`(default) and `1e-7` ![SoftStarter1e_6_vs_1e_7_MWORKS](https://github.com/modelica/ModelicaStandardLibrary/assets/153701357/f9536bab-bfeb-4ba3-9622-19c905c04e8f) #### Dymola with Tolerance `1e-6`(default) and `1e-7` ![SoftStarter1e_6_vs_1e_7_Dymola](https://github.com/modelica/ModelicaStandardLibrary/assets/153701357/dc7eed84-7c95-4614-b1e4-add2e31ea7ba) #### OpenModelica with Tolerance `1e-6`(default) and `1e-7` ![SoftStarter1e_6_vs_1e_7_OpenModelica](https://github.com/modelica/ModelicaStandardLibrary/assets/153701357/170ef495-e0d5-41e8-9a97-ced3ecd1f465) #### MWORKS, Dymola and OpenModelica with Tolerance `1e-6`(default) ![SoftStarter1e_6](https://github.com/modelica/ModelicaStandardLibrary/assets/153701357/97c64e71-ec4f-489a-a969-52fa8e25006d) #### MWORKS, Dymola and OpenModelica with Tolerance `1e-7` ![SoftStarter1e_7](https://github.com/modelica/ModelicaStandardLibrary/assets/153701357/2e26726b-cc54-48f5-a743-2de1efe185a0)Could you give us some advice on dealing with such models?
atan2
andatan3
function when Modeling?HideResult
to avoid this phenomenon?