Skip to content

Commit

Permalink
Don't change lambda when no homotpy should be used (#8109)
Browse files Browse the repository at this point in the history
* Don't change lambda when no homotpy should be used
* Updating tests
  * Disabeling MSL 3.2.2 Modelica.Fluid.Examples.PumpingSystem test
  * Different solution in homotopy4_solver test
Co-authored-by: phannebohm <phannebohm@fh-bielefeld.de>
  • Loading branch information
AnHeuermann committed Nov 11, 2021
1 parent 1250a38 commit c32c675
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 23 deletions.
Expand Up @@ -1074,7 +1074,6 @@ int solve_nonlinear_system(DATA *data, threadData_t *threadData, int sysNumber)
if (!homotopyDeactivated && !omc_flag[FLAG_HOMOTOPY_ON_FIRST_TRY])
infoStreamPrint(LOG_INIT_HOMOTOPY, 0, "Try to solve nonlinear initial system %d without homotopy first.", sysNumber);

data->simulationInfo->lambda = 1.0;
/* SOLVE! */
nonlinsys->solved = solveNLS(data, threadData, sysNumber);
}
Expand Down
2 changes: 1 addition & 1 deletion testsuite/simulation/libraries/msl32/Makefile
Expand Up @@ -276,12 +276,12 @@ Modelica.Mechanics.MultiBody.Examples.Elementary.UserDefinedGravityField.mos \
Modelica.Media.Examples.SolveOneNonlinearEquation.Inverse_sine.mos \
Modelica.Media.Examples.R134a.R134a1.mos \
Modelica.Media.Examples.R134a.R134a2.mos \
Modelica.Fluid.Examples.PumpingSystem.mos \
Modelica.Magnetic.FundamentalWave.Examples.BasicMachines.SMEE_Generator_MultiPhase.mos \

# Run make failingtest
FAILINGTESTFILES = \
Modelica.Electrical.QuasiStationary.Machines.Examples.TransformerTestbench.mos \
Modelica.Fluid.Examples.PumpingSystem.mos \

# Dependency files that are not .mo .mos or Makefile
# Add them here or they will be cleaned.
Expand Down
@@ -1,6 +1,6 @@
// name: Modelica.Fluid.Examples.PumpingSystem
// keywords: simulation MSL Examples
// status: correct
// status: erroneous
// cflags: -d=-newInst
//
// Simulation Results
Expand Down
1 change: 1 addition & 0 deletions testsuite/simulation/modelica/initialization/Makefile
Expand Up @@ -39,6 +39,7 @@ homotopy3.mos \
homotopy4.mos \
homotopy4_solver.mos \
homotopy5.mos \
homotopy6.mos \
initial_equation.mos \
parameters.mos \
parameterWithoutBinding.mos \
Expand Down
40 changes: 20 additions & 20 deletions testsuite/simulation/modelica/initialization/homotopy4_solver.mos
Expand Up @@ -635,19 +635,19 @@ readFile("homotopy4_solver_system.log"); remove("homotopy4_solver_system.log");
// | | | | | | [2] Real b(start=0, nominal=1) = -0.412118 (pre: 0)
// | | | | | | [3] Real c(start=0, nominal=1) = 0.169842 (pre: 0)
// | | | | | | [4] Real d(start=0, nominal=1) = -9 (pre: 0)
// | | | | | | [5] Real e(start=0, nominal=1) = -0.956376 (pre: 0)
// | | | | | | [6] Real f(start=0, nominal=1) = -23.1114 (pre: 0)
// | | | | | | [5] Real e(start=0, nominal=1) = 0.57364 (pre: 0)
// | | | | | | [6] Real f(start=0, nominal=1) = -27.1705 (pre: 0)
// | | | | | | [7] Real x(start=0, nominal=1) = -9 (pre: 0)
// | | | | | | [8] Real x1(start=0, nominal=1) = -9 (pre: 0)
// | | | | | | [9] Real x2(start=0, nominal=1) = 3 (pre: 0)
// | | | | | | [10] Real x3(start=0, nominal=1) = -6.95638 (pre: 0)
// | | | | | | [9] Real x2(start=0, nominal=1) = -2.16228 (pre: 0)
// | | | | | | [10] Real x3(start=0, nominal=1) = -5.42636 (pre: 0)
// | | | | | | [11] Real y(start=0, nominal=1) = 5 (pre: 0)
// | | | | | | [12] Real y1(start=0, nominal=1) = 4.16984 (pre: 0)
// | | | | | | [13] Real y2(start=0, nominal=1) = -3 (pre: 0)
// | | | | | | [14] Real y3(start=0, nominal=1) = 3.04362 (pre: 0)
// | | | | | | [13] Real y2(start=0, nominal=1) = -2.16228 (pre: 0)
// | | | | | | [14] Real y3(start=0, nominal=1) = 4.57364 (pre: 0)
// | | | | | | [15] Real z(start=0, nominal=1) = -5 (pre: 0)
// | | | | | | [16] Real z1(start=0, nominal=1) = -4.16984 (pre: 0)
// | | | | | | [17] Real z2(start=0, nominal=1) = 9 (pre: 0)
// | | | | | | [17] Real z2(start=0, nominal=1) = 4.67544 (pre: 0)
// | | | | | | [18] Real z3(start=0, nominal=1) = -1 (pre: 0)
// LOG_INIT | info | ### END INITIALIZATION ###
// LOG_SUCCESS | info | The initialization finished successfully with 3 homotopy steps.
Expand Down Expand Up @@ -687,19 +687,19 @@ readFile("homotopy4_solver_system.log"); remove("homotopy4_solver_system.log");
// | | | | | | [2] Real b(start=0, nominal=1) = -0.412118 (pre: 0)
// | | | | | | [3] Real c(start=0, nominal=1) = 0.169842 (pre: 0)
// | | | | | | [4] Real d(start=0, nominal=1) = -9 (pre: 0)
// | | | | | | [5] Real e(start=0, nominal=1) = -0.956376 (pre: 0)
// | | | | | | [6] Real f(start=0, nominal=1) = -23.1114 (pre: 0)
// | | | | | | [5] Real e(start=0, nominal=1) = 0.57364 (pre: 0)
// | | | | | | [6] Real f(start=0, nominal=1) = -27.1705 (pre: 0)
// | | | | | | [7] Real x(start=0, nominal=1) = -9 (pre: 0)
// | | | | | | [8] Real x1(start=0, nominal=1) = -9 (pre: 0)
// | | | | | | [9] Real x2(start=0, nominal=1) = 3 (pre: 0)
// | | | | | | [10] Real x3(start=0, nominal=1) = -6.95638 (pre: 0)
// | | | | | | [9] Real x2(start=0, nominal=1) = -2.16228 (pre: 0)
// | | | | | | [10] Real x3(start=0, nominal=1) = -5.42636 (pre: 0)
// | | | | | | [11] Real y(start=0, nominal=1) = 5 (pre: 0)
// | | | | | | [12] Real y1(start=0, nominal=1) = 4.16984 (pre: 0)
// | | | | | | [13] Real y2(start=0, nominal=1) = -3 (pre: 0)
// | | | | | | [14] Real y3(start=0, nominal=1) = 3.04362 (pre: 0)
// | | | | | | [13] Real y2(start=0, nominal=1) = -2.16228 (pre: 0)
// | | | | | | [14] Real y3(start=0, nominal=1) = 4.57364 (pre: 0)
// | | | | | | [15] Real z(start=0, nominal=1) = -5 (pre: 0)
// | | | | | | [16] Real z1(start=0, nominal=1) = -4.16984 (pre: 0)
// | | | | | | [17] Real z2(start=0, nominal=1) = 9 (pre: 0)
// | | | | | | [17] Real z2(start=0, nominal=1) = 4.67544 (pre: 0)
// | | | | | | [18] Real z3(start=0, nominal=1) = -1 (pre: 0)
// LOG_INIT | info | ### END INITIALIZATION ###
// LOG_SUCCESS | info | The initialization finished successfully with 3 homotopy steps.
Expand Down Expand Up @@ -845,16 +845,16 @@ readFile("homotopy4_solver_system.log"); remove("homotopy4_solver_system.log");
// | | | | | | [2] Real b(start=0, nominal=1) = -0.412118 (pre: 0)
// | | | | | | [3] Real c(start=0, nominal=1) = 0.169842 (pre: 0)
// | | | | | | [4] Real d(start=0, nominal=1) = -9 (pre: 0)
// | | | | | | [5] Real e(start=0, nominal=1) = -0.956376 (pre: 0)
// | | | | | | [5] Real e(start=0, nominal=1) = -0.956366 (pre: 0)
// | | | | | | [6] Real f(start=0, nominal=1) = -23.1114 (pre: 0)
// | | | | | | [7] Real x(start=0, nominal=1) = -9 (pre: 0)
// | | | | | | [8] Real x1(start=0, nominal=1) = -9 (pre: 0)
// | | | | | | [9] Real x2(start=0, nominal=1) = 3 (pre: 0)
// | | | | | | [10] Real x3(start=0, nominal=1) = -6.95638 (pre: 0)
// | | | | | | [10] Real x3(start=0, nominal=1) = -6.95637 (pre: 0)
// | | | | | | [11] Real y(start=0, nominal=1) = 5 (pre: 0)
// | | | | | | [12] Real y1(start=0, nominal=1) = 4.16984 (pre: 0)
// | | | | | | [13] Real y2(start=0, nominal=1) = -3 (pre: 0)
// | | | | | | [14] Real y3(start=0, nominal=1) = 3.04362 (pre: 0)
// | | | | | | [14] Real y3(start=0, nominal=1) = 3.04363 (pre: 0)
// | | | | | | [15] Real z(start=0, nominal=1) = -5 (pre: 0)
// | | | | | | [16] Real z1(start=0, nominal=1) = -4.16984 (pre: 0)
// | | | | | | [17] Real z2(start=0, nominal=1) = 9 (pre: 0)
Expand Down Expand Up @@ -897,16 +897,16 @@ readFile("homotopy4_solver_system.log"); remove("homotopy4_solver_system.log");
// | | | | | | [2] Real b(start=0, nominal=1) = -0.412118 (pre: 0)
// | | | | | | [3] Real c(start=0, nominal=1) = 0.169842 (pre: 0)
// | | | | | | [4] Real d(start=0, nominal=1) = -9 (pre: 0)
// | | | | | | [5] Real e(start=0, nominal=1) = -0.956376 (pre: 0)
// | | | | | | [5] Real e(start=0, nominal=1) = -0.956366 (pre: 0)
// | | | | | | [6] Real f(start=0, nominal=1) = -23.1114 (pre: 0)
// | | | | | | [7] Real x(start=0, nominal=1) = -9 (pre: 0)
// | | | | | | [8] Real x1(start=0, nominal=1) = -9 (pre: 0)
// | | | | | | [9] Real x2(start=0, nominal=1) = 3 (pre: 0)
// | | | | | | [10] Real x3(start=0, nominal=1) = -6.95638 (pre: 0)
// | | | | | | [10] Real x3(start=0, nominal=1) = -6.95637 (pre: 0)
// | | | | | | [11] Real y(start=0, nominal=1) = 5 (pre: 0)
// | | | | | | [12] Real y1(start=0, nominal=1) = 4.16984 (pre: 0)
// | | | | | | [13] Real y2(start=0, nominal=1) = -3 (pre: 0)
// | | | | | | [14] Real y3(start=0, nominal=1) = 3.04362 (pre: 0)
// | | | | | | [14] Real y3(start=0, nominal=1) = 3.04363 (pre: 0)
// | | | | | | [15] Real z(start=0, nominal=1) = -5 (pre: 0)
// | | | | | | [16] Real z1(start=0, nominal=1) = -4.16984 (pre: 0)
// | | | | | | [17] Real z2(start=0, nominal=1) = 9 (pre: 0)
Expand Down
61 changes: 61 additions & 0 deletions testsuite/simulation/modelica/initialization/homotopy6.mos
@@ -0,0 +1,61 @@
// name: homotopy6
// keywords: initialization, homotopy
// status: correct
// cflags:
// teardown_command: rm -rf initializationTests.homotopy6* _initializationTests.homotopy6* output.log TestTornHomotopy2*
// cflags: -d=-newInst
//
// Check if equation system actually goes through all steps in the global homotopy path.
// To prevent regressions like https://github.com/OpenModelica/OpenModelica/issues/8097
//

loadString("model TestTornHomotopy2
Real x,y,z;
equation
x = homotopy(y + 0.1*y^2 - 0.001*y^3, y);
y = 3*z;
z + 0.1*x = 1;
end TestTornHomotopy2;
"); getErrorString();

simulate(TestTornHomotopy2, simflags="-lv=LOG_INIT_HOMOTOPY -s=dassl");
getErrorString();

readFile("TestTornHomotopy2_equidistant_global_homotopy.csv")

// Result:
// true
// ""
// record SimulationResult
// resultFile = "TestTornHomotopy2_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'TestTornHomotopy2', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv=LOG_INIT_HOMOTOPY -s=dassl'",
// messages = "LOG_INIT_HOMOTOPY | info | Model contains homotopy operator: Use adaptive homotopy method to solve initialization problem. To disable initialization with homotopy operator use \"-noHomotopyOnFirstTry\".
// LOG_INIT_HOMOTOPY | info | Global homotopy with equidistant step size started.
// LOG_INIT_HOMOTOPY | info | The homotopy path will be exported to TestTornHomotopy2_equidistant_global_homotopy.csv.
// LOG_INIT_HOMOTOPY | info | homotopy process
// | | | | ---------------------------
// LOG_INIT_HOMOTOPY | info | homotopy parameter lambda = 0
// LOG_INIT_HOMOTOPY | info | homotopy parameter lambda = 0 done
// | | | | ---------------------------
// LOG_INIT_HOMOTOPY | info | homotopy parameter lambda = 0.333333
// LOG_INIT_HOMOTOPY | info | homotopy parameter lambda = 0.333333 done
// | | | | ---------------------------
// LOG_INIT_HOMOTOPY | info | homotopy parameter lambda = 0.666667
// LOG_INIT_HOMOTOPY | info | homotopy parameter lambda = 0.666667 done
// | | | | ---------------------------
// LOG_INIT_HOMOTOPY | info | homotopy parameter lambda = 1
// LOG_INIT_HOMOTOPY | info | homotopy parameter lambda = 1 done
// | | | | ---------------------------
// LOG_SUCCESS | info | The initialization finished successfully with 3 homotopy steps.
// LOG_SUCCESS | info | The simulation finished successfully.
// "
// end SimulationResult;
// "Warning: There are nonlinear iteration variables with default zero start attribute found in NLSJac0. For more information set -d=initialization. In OMEdit Tools->Options->Simulation->Show additional information from the initialization process, in OMNotebook call setCommandLineOptions(\"-d=initialization\").
// "
// "\"lambda\",\"x\",\"y\",\"z\"
// 0,2.307692307692307,2.307692307692308,0.7692307692307693
// 0.3333333333333333,2.436704982096462,2.268988505371062,0.7563295017903539
// 0.6666666666666666,2.557625806717175,2.232712257984848,0.7442374193282825
// 1,2.671349569180263,2.198595129245921,0.7328650430819735
// "
// endResult

0 comments on commit c32c675

Please sign in to comment.