From fa51497b9103c56d4ee7eb69f6e5b8d3dda42a7c Mon Sep 17 00:00:00 2001 From: HOS Date: Tue, 12 Aug 2025 13:21:35 +0200 Subject: [PATCH 1/4] Declare these functions as impure. Since they may delete a file there is no real discussion as far as I can see. --- Modelica/Math/FastFourierTransform.mo | 2 +- .../Mechanics/MultiBody/Visualizers/Colors/colorMapToSvg.mo | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modelica/Math/FastFourierTransform.mo b/Modelica/Math/FastFourierTransform.mo index c2e3199bd7..06bab8c20c 100644 --- a/Modelica/Math/FastFourierTransform.mo +++ b/Modelica/Math/FastFourierTransform.mo @@ -535,7 +535,7 @@ which is a complete example where an FFT is computed during simulation and store ")); end realFFT; - function realFFTwriteToFile "Write real FFT computation to file" + impure function realFFTwriteToFile "Write real FFT computation to file" extends Modelica.Icons.Function; import Modelica.Utilities.Streams.print; import Modelica.Units.Conversions.to_deg; diff --git a/Modelica/Mechanics/MultiBody/Visualizers/Colors/colorMapToSvg.mo b/Modelica/Mechanics/MultiBody/Visualizers/Colors/colorMapToSvg.mo index 4e8a41ea7f..665e74e232 100644 --- a/Modelica/Mechanics/MultiBody/Visualizers/Colors/colorMapToSvg.mo +++ b/Modelica/Mechanics/MultiBody/Visualizers/Colors/colorMapToSvg.mo @@ -1,5 +1,5 @@ within Modelica.Mechanics.MultiBody.Visualizers.Colors; -function colorMapToSvg +impure function colorMapToSvg "Save a color map on file in svg (scalable vector graphics) format" extends Modelica.Icons.Function; encapsulated type HeaderType = enumeration( From 55e1a1938840b5c40631e32bba946f92ef90dd03 Mon Sep 17 00:00:00 2001 From: HOS Date: Tue, 12 Aug 2025 13:23:36 +0200 Subject: [PATCH 2/4] Declare example functions as impure when calling print. If we make an exception for print this could be skipped. But I don't see any problem with changing these examples as they should be _examples_, and their side-effect is what matters. --- Modelica/Math/Nonlinear.mo | 8 ++++---- Modelica/Math/package.mo | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Modelica/Math/Nonlinear.mo b/Modelica/Math/Nonlinear.mo index c827dba958..6de6840f00 100644 --- a/Modelica/Math/Nonlinear.mo +++ b/Modelica/Math/Nonlinear.mo @@ -5,7 +5,7 @@ package Nonlinear "Library of functions operating on nonlinear equations" "Examples demonstrating the usage of the functions in package Nonlinear" extends Modelica.Icons.ExamplesPackage; - function quadratureLobatto1 "Integrate integral with fixed inputs" + impure function quadratureLobatto1 "Integrate integral with fixed inputs" extends Modelica.Icons.Function; import Modelica.Utilities.Streams.print; @@ -87,7 +87,7 @@ The following integrals are computed: ")); end quadratureLobatto1; - function quadratureLobatto2 "Integrate integral with user dependent inputs" + impure function quadratureLobatto2 "Integrate integral with user dependent inputs" extends Modelica.Icons.Function; import Modelica.Utilities.Streams.print; @@ -159,7 +159,7 @@ The following integrals are computed: ")); end quadratureLobatto2; - function solveNonlinearEquations1 + impure function solveNonlinearEquations1 "Solve nonlinear equations with fixed inputs" extends Modelica.Icons.Function; import Modelica.Utilities.Streams.print; @@ -238,7 +238,7 @@ The following nonlinear equations are solved: ")); end solveNonlinearEquations1; - function solveNonlinearEquations2 + impure function solveNonlinearEquations2 "Solve nonlinear equations with user dependent inputs" extends Modelica.Icons.Function; import Modelica.Utilities.Streams.print; diff --git a/Modelica/Math/package.mo b/Modelica/Math/package.mo index 6a875a6082..c8ba6d2ae4 100644 --- a/Modelica/Math/package.mo +++ b/Modelica/Math/package.mo @@ -694,7 +694,7 @@ package Matrices "Library of functions operating on matrices" package Examples "Examples demonstrating the usage of the Math.Matrices functions" extends Modelica.Icons.ExamplesPackage; - function solveLinearEquations + impure function solveLinearEquations "Demonstrate the solution of linear equation systems" extends Modelica.Icons.Function; import Modelica.Utilities.Streams.print; From 5ad67037677177391d4b8386dd67927fdee49ab0 Mon Sep 17 00:00:00 2001 From: HOS Date: Tue, 12 Aug 2025 14:00:45 +0200 Subject: [PATCH 3/4] Seems cleaner to declare this as impure. --- Modelica/Math/Random.mo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modelica/Math/Random.mo b/Modelica/Math/Random.mo index f85b660349..6d3774a35b 100644 --- a/Modelica/Math/Random.mo +++ b/Modelica/Math/Random.mo @@ -1054,7 +1054,7 @@ path is provided. ")); end automaticLocalSeed; - function initializeImpureRandom + impure function initializeImpureRandom "Initializes the internal state of the impure random number generator" extends Modelica.Icons.Function; input Integer seed From a7de66c197ec51259505fdbff74797953be0e8d6 Mon Sep 17 00:00:00 2001 From: HOS Date: Wed, 12 Nov 2025 13:51:48 +0100 Subject: [PATCH 4/4] AdditionalImpact --- ModelicaTest/Math.mo | 4 ++-- ModelicaTest/package.mo | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ModelicaTest/Math.mo b/ModelicaTest/Math.mo index 26d07b7cc9..75ddd018a0 100644 --- a/ModelicaTest/Math.mo +++ b/ModelicaTest/Math.mo @@ -660,7 +660,7 @@ extends Modelica.Icons.ExamplesPackage; ok := true; end Vectors; - function colorMapToSvg "Store all predefined color maps in svg" + impure function colorMapToSvg "Store all predefined color maps in svg" extends Modelica.Icons.Function; import Modelica.Mechanics.MultiBody.Visualizers.Colors.colorMapToSvg; import Modelica.Mechanics.MultiBody.Visualizers.Colors.ColorMaps.{jet, hot, gray, spring, summer, autumn, winter}; @@ -762,7 +762,7 @@ extends Modelica.Icons.ExamplesPackage; model TestMatricesExamplesSolveLinearEquations extends Modelica.Icons.Example; - equation + initial equation Modelica.Math.Matrices.Examples.solveLinearEquations(); annotation (experiment(StopTime=0)); end TestMatricesExamplesSolveLinearEquations; diff --git a/ModelicaTest/package.mo b/ModelicaTest/package.mo index 3f79e3e59f..8f17ff8388 100644 --- a/ModelicaTest/package.mo +++ b/ModelicaTest/package.mo @@ -4,7 +4,7 @@ extends Modelica.Icons.Package; import Modelica.Units.SI; -function testAllFunctions "Runs all test cases for functions" +impure function testAllFunctions "Runs all test cases for functions" extends Modelica.Icons.Function; import Modelica.Utilities.Streams.print; input String logFile = "ModelicaTestLog.txt"