-
Notifications
You must be signed in to change notification settings - Fork 50
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
Implement Kinsol as non-linear solver for non-linear loops over components #815
Conversation
1bdcaac
to
9ab230f
Compare
fa192dd
to
9d26c4a
Compare
I need some test case to verify that everything is correct. Currently I'm using loadModel(Modelica);
loadString("model loopsOverFMUsA
Real a, b, c;
Modelica.Blocks.Interfaces.RealOutput a_out;
Modelica.Blocks.Interfaces.RealOutput b_out;
Modelica.Blocks.Interfaces.RealInput c_in;
equation
c = c_in;
// Eq. 1 and 2 of loop
a + b + c=0;
2*a - 3*b + 2*c=9;
a_out = a;
b_out = b;
end loopsOverFMUsA;
"); getErrorString();
loadString("model loopsOverFMUsB
Real a, b, c;
Modelica.Blocks.Interfaces.RealInput a_in;
Modelica.Blocks.Interfaces.RealInput b_in;
Modelica.Blocks.Interfaces.RealOutput c_out;
equation
a = a_in;
b = b_in;
// Equation 3 of loop
a*a + b*b + c*c=5;
c_out = c;
end loopsOverFMUsB;
"); getErrorString();
buildModelFMU(loopsOverFMUsA, fmuType="me"); getErrorString();
buildModelFMU(loopsOverFMUsB, fmuType="me"); getErrorString();
system("rm -rf FMU_A && unzip -qq loopsOverFMUsA.fmu -d FMU_A"); getErrorString();
system("rm -rf FMU_B && unzip -qq loopsOverFMUsB.fmu -d FMU_B"); getErrorString();
writeFile("loopsOverFMUs.lua","
oms_setTempDirectory(\"./temp/\")
oms_newModel(\"loopsOverFMUs\")
oms_addSystem(\"loopsOverFMUs.root\", oms_system_sc)
-- instantiate FMUs
oms_addSubModel(\"loopsOverFMUs.root.A1\", \"loopsOverFMUsA.fmu\")
oms_addSubModel(\"loopsOverFMUs.root.B1\", \"loopsOverFMUsB.fmu\")
oms_addSubModel(\"loopsOverFMUs.root.A2\", \"loopsOverFMUsA.fmu\")
oms_addSubModel(\"loopsOverFMUs.root.B2\", \"loopsOverFMUsB.fmu\")
-- connections: A1 -> B1
oms_addConnection(\"loopsOverFMUs.root.A1.a_out\", \"loopsOverFMUs.root.B1.a_in\")
oms_addConnection(\"loopsOverFMUs.root.A1.b_out\", \"loopsOverFMUs.root.B1.b_in\")
oms_addConnection(\"loopsOverFMUs.root.A1.c_in\", \"loopsOverFMUs.root.B1.c_out\")
-- connections: A2 -> B2
oms_addConnection(\"loopsOverFMUs.root.A2.a_out\", \"loopsOverFMUs.root.B2.a_in\")
oms_addConnection(\"loopsOverFMUs.root.A2.b_out\", \"loopsOverFMUs.root.B2.b_in\")
oms_addConnection(\"loopsOverFMUs.root.A2.c_in\", \"loopsOverFMUs.root.B2.c_out\")
-- simulation settings
oms_setResultFile(\"loopsOverFMUs\", \"loopsOverFMUs.csv\")
oms_setStartTime(\"loopsOverFMUs\", 0)
oms_setStopTime(\"loopsOverFMUs\", 0.1)
oms_instantiate(\"loopsOverFMUs\")
oms_setReal(\"loopsOverFMUs.root.B1.a_in\", 0.635425)
oms_setReal(\"loopsOverFMUs.root.B1.b_in\", -1.8)
oms_setReal(\"loopsOverFMUs.root.A1.c_in\", 1.16458)
--oms_setReal(\"loopsOverFMUs.root.B2.a_in\", 0.635425)
--oms_setReal(\"loopsOverFMUs.root.B2.b_in\", -1.8)
--oms_setReal(\"loopsOverFMUs.root.A2.c_in\", 1.16458)
oms_initialize(\"loopsOverFMUs\")
oms_simulate(\"loopsOverFMUs\")
oms_terminate(\"loopsOverFMUs\")
oms_delete(\"loopsOverFMUs\")
"); getErrorString();
system("OMSimulator loopsOverFMUs.lua --algLoopSolver=kinsol --logLevel=2"); getErrorString(); But it is a bit to simple to solve for a good test. Also I'm not sure how to change values for |
Okay, here comes an example that is ridiculous simple but impossible to solve for the fixed-point iteration. Just connect model FMUA
Modelica.Blocks.Interfaces.RealInput x_in;
Modelica.Blocks.Interfaces.RealOutput x_out;
Real y(fixed=true, start=2);
parameter Real a = 2;
equation
der(y) = a*y;
x_out = 2*x_in-y;
end FMUA;
model FMUB
Modelica.Blocks.Interfaces.RealInput x_in;
Modelica.Blocks.Interfaces.RealOutput x_out;
equation
x_out = x_in;
end FMUB; But we have a remaining problem: The equation system during initialization warning: Alg. loop (size 2) debug: debug: Create new KinsolSolver object for algebraic loop number 0
debug: Solving algebraic loop formed by connections
A.x_out <-> B.x_in
B.x_out <-> A.x_in
debug: Using solver KINSOL
debug: Solving system 0 is solved correctly, but after initialization the graph or SCC changes and we get a "new" system warning: Alg. loop (size 2)
debug: Solving algebraic loop formed by connections
A.y <-> B.x_in
B.x_out <->
debug: Using solver Kinsol
debug: Solving system 0 which seems a bit odd and results in a segmentation fault. |
fd36d17
to
809a48e
Compare
I will add a test case to Documentation will follow in a separate PR. |
- Collected some duplicant code and moved it to System.cpp / System.h
Added debug log to display alg. loop
- Added enums for different alg solver methods - Added debug print to display loops - Create object for each alg loop bundled with solver
- Added KINSOL solver to AlgLoop class. - Added a new flag `--algLoopSolver` to choose alg. solver method. Defaults to fixed-point-iteration. Use "kinsol" for KINSOL. - Also added a new type oms_ssc_t for strong connected components.
809a48e
to
68469a7
Compare
…er components (OpenModelica#815)" This reverts commit 784af99.
…nents (OpenModelica#815) * Reduce redundant code - Collected some duplicant code and moved it to System.cpp / System.h * Move alg loop solver to own file Added debug log to display alg. loop * Capsulate fixed-point iteration - Added enums for different alg solver methods - Added debug print to display loops - Create object for each alg loop bundled with solver * Added algebraic solver KINSOL for non-linear loops over components. - Added KINSOL solver to AlgLoop class. - Added a new flag `--algLoopSolver` to choose alg. solver method. Defaults to fixed-point-iteration. Use "kinsol" for KINSOL. - Also added a new type oms_ssc_t for strong connected components. * Bug fix for wrong index of alg loops
…nents (OpenModelica#815) * Reduce redundant code - Collected some duplicant code and moved it to System.cpp / System.h * Move alg loop solver to own file Added debug log to display alg. loop * Capsulate fixed-point iteration - Added enums for different alg solver methods - Added debug print to display loops - Create object for each alg loop bundled with solver * Added algebraic solver KINSOL for non-linear loops over components. - Added KINSOL solver to AlgLoop class. - Added a new flag `--algLoopSolver` to choose alg. solver method. Defaults to fixed-point-iteration. Use "kinsol" for KINSOL. - Also added a new type oms_ssc_t for strong connected components. * Bug fix for wrong index of alg loops
…nents (OpenModelica#815) * Reduce redundant code - Collected some duplicant code and moved it to System.cpp / System.h * Move alg loop solver to own file Added debug log to display alg. loop * Capsulate fixed-point iteration - Added enums for different alg solver methods - Added debug print to display loops - Create object for each alg loop bundled with solver * Added algebraic solver KINSOL for non-linear loops over components. - Added KINSOL solver to AlgLoop class. - Added a new flag `--algLoopSolver` to choose alg. solver method. Defaults to fixed-point-iteration. Use "kinsol" for KINSOL. - Also added a new type oms_ssc_t for strong connected components. * Bug fix for wrong index of alg loops
…loops over components (OpenModelica#815)" (OpenModelica#847)" This reverts commit 839c272.
Related Issues
#812, #808
Purpose
A fixed-point iterations is currently the only solver available to solve algebraic loops over components but not suitable for all problems.
Implementing KINSOL as alternative to the fixed-point iteration will enable more FMUs connected to run smoothly.