summaryrefslogtreecommitdiff
path: root/modules/xcos/examples/solvers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/xcos/examples/solvers')
-rwxr-xr-xmodules/xcos/examples/solvers/DAE_Example.zcosbin0 -> 4307 bytes
-rwxr-xr-xmodules/xcos/examples/solvers/ODE_Example.zcosbin0 -> 3822 bytes
-rwxr-xr-xmodules/xcos/examples/solvers/Rootfinding.sce36
-rwxr-xr-xmodules/xcos/examples/solvers/RootfindingSimple.sce36
-rwxr-xr-xmodules/xcos/examples/solvers/benchBasic.sce41
-rwxr-xr-xmodules/xcos/examples/solvers/benchBouncing.sce44
-rwxr-xr-xmodules/xcos/examples/solvers/benchHydraulics.sce42
-rwxr-xr-xmodules/xcos/examples/solvers/benchKalman.sce45
-rwxr-xr-xmodules/xcos/examples/solvers/benchSine.sce39
-rwxr-xr-xmodules/xcos/examples/solvers/integCVode.sce25
-rwxr-xr-xmodules/xcos/examples/solvers/integDoPri.sce28
-rwxr-xr-xmodules/xcos/examples/solvers/integImpRK.sce29
-rwxr-xr-xmodules/xcos/examples/solvers/integLSodar.sce25
-rwxr-xr-xmodules/xcos/examples/solvers/integRK.sce29
-rwxr-xr-xmodules/xcos/examples/solvers/with_ZeroCrossing.zcosbin0 -> 4369 bytes
-rwxr-xr-xmodules/xcos/examples/solvers/with_ZeroCrossingSimple.zcosbin0 -> 4262 bytes
-rwxr-xr-xmodules/xcos/examples/solvers/without_ZeroCrossing.zcosbin0 -> 3757 bytes
-rwxr-xr-xmodules/xcos/examples/solvers/without_ZeroCrossingSimple.zcosbin0 -> 3699 bytes
18 files changed, 419 insertions, 0 deletions
diff --git a/modules/xcos/examples/solvers/DAE_Example.zcos b/modules/xcos/examples/solvers/DAE_Example.zcos
new file mode 100755
index 000000000..b48e5cc71
--- /dev/null
+++ b/modules/xcos/examples/solvers/DAE_Example.zcos
Binary files differ
diff --git a/modules/xcos/examples/solvers/ODE_Example.zcos b/modules/xcos/examples/solvers/ODE_Example.zcos
new file mode 100755
index 000000000..09b7bf18f
--- /dev/null
+++ b/modules/xcos/examples/solvers/ODE_Example.zcos
Binary files differ
diff --git a/modules/xcos/examples/solvers/Rootfinding.sce b/modules/xcos/examples/solvers/Rootfinding.sce
new file mode 100755
index 000000000..b995bb259
--- /dev/null
+++ b/modules/xcos/examples/solvers/Rootfinding.sce
@@ -0,0 +1,36 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - Scilab Enterprises - Paul Bignier
+//
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+
+// Import the "with-ZC" diagram and augment the ending time
+loadScicos();
+loadXcosLibs();
+importXcosDiagram("SCI/modules/xcos/examples/solvers/with_ZeroCrossing.zcos");
+scs_m.props.tf = 30000;
+
+// Set tolerances and select LSodar
+scs_m.props.tol(1) = 1d-13;
+scs_m.props.tol(2) = 1d-13;
+scs_m.props.tol(6) = 0;
+
+// Start the timer, launch the simulation and display time
+tic();
+try scicos_simulate(scs_m, "nw"); catch disp(lasterror()); end
+t = toc();
+disp(t, "Time with rootfinding:");
+
+// Import the "without-ZC" diagram and augment the ending time
+importXcosDiagram("SCI/modules/xcos/examples/solvers/without_ZeroCrossing.zcos");
+scs_m.props.tf = 30000;
+
+// Set tolerances and select LSodar
+scs_m.props.tol(1) = 1d-13;
+scs_m.props.tol(2) = 1d-13;
+scs_m.props.tol(6) = 0;
+
+// Start the timer, launch the simulation and display time
+tic();
+try scicos_simulate(scs_m, "nw"); catch disp(lasterror()); end
+t = toc();
+disp(t, "Time without rootfinding:");
diff --git a/modules/xcos/examples/solvers/RootfindingSimple.sce b/modules/xcos/examples/solvers/RootfindingSimple.sce
new file mode 100755
index 000000000..37f2353a8
--- /dev/null
+++ b/modules/xcos/examples/solvers/RootfindingSimple.sce
@@ -0,0 +1,36 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - Scilab Enterprises - Paul Bignier
+//
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+
+// Import the "with-ZC" diagram and augment the ending time
+loadScicos();
+loadXcosLibs();
+importXcosDiagram("SCI/modules/xcos/examples/solvers/with_ZeroCrossingSimple.zcos");
+scs_m.props.tf = 30;
+
+// Set tolerances and select LSodar
+scs_m.props.tol(1) = 1d-7;
+scs_m.props.tol(2) = 1d-7;
+scs_m.props.tol(6) = 0;
+
+// Start the timer, launch the simulation and display time
+tic();
+try scicos_simulate(scs_m, "nw"); catch disp(lasterror()); end
+t = toc();
+disp(t, "Time with rootfinding:");
+
+// Import the "without-ZC" diagram and augment the ending time
+importXcosDiagram("SCI/modules/xcos/examples/solvers/without_ZeroCrossingSimple.zcos");
+scs_m.props.tf = 30;
+
+// Set tolerances and select LSodar
+scs_m.props.tol(1) = 1d-7;
+scs_m.props.tol(2) = 1d-7;
+scs_m.props.tol(6) = 0;
+
+// Start the timer, launch the simulation and display time
+tic();
+try scicos_simulate(scs_m, "nw"); catch disp(lasterror()); end
+t = toc();
+disp(t, "Time without rootfinding:");
diff --git a/modules/xcos/examples/solvers/benchBasic.sce b/modules/xcos/examples/solvers/benchBasic.sce
new file mode 100755
index 000000000..f26cbae11
--- /dev/null
+++ b/modules/xcos/examples/solvers/benchBasic.sce
@@ -0,0 +1,41 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - Scilab Enterprises - Paul Bignier
+//
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+
+// Import the diagram, augment the ending time and store its compilation in Info()
+loadScicos();
+loadXcosLibs();
+importXcosDiagram("SCI/modules/xcos/demos/Controller.zcos");
+Info = scicos_simulate(scs_m, "nw");
+tf = 4000;
+tolerances = scs_m.props.tol;
+tolerances(1) = 1d-13;
+tolerances(2) = 1d-13;
+[%tcur, %cpr, alreadyran, needstart, needcompile, %state0] = Info(:);
+
+solverName = ["LSodar", "CVode BDF/Newton", "CVode BDF/Functional", "CVode Adams/Newton", "CVode Adams/Functional", "Dormand-Prince", "Runge-Kutta", "implicit Runge-Kutta"];
+
+disp("--------------------------------");
+for solver = 0:7
+
+ disp("Time for " + solverName(solver + 1) + ":");
+ tolerances(6) = solver;
+
+ // Modify 'Max step size' if RK-based solver
+ if (solver >= 5) then tolerances(7) = 0.03; end
+
+ // Start the solver
+ [state, t] = scicosim(%state0, 0.0, tf, %cpr.sim, "start", tolerances);
+
+ // Run until the end
+ tic();
+ [state, t] = scicosim(state, 0.0, tf, %cpr.sim, "run", tolerances);
+ t = toc();
+ disp(t);
+
+ // End the solver
+ [state, t] = scicosim(state, tf, tf, %cpr.sim, "finish", tolerances);
+
+end
+disp("--------------------------------");
diff --git a/modules/xcos/examples/solvers/benchBouncing.sce b/modules/xcos/examples/solvers/benchBouncing.sce
new file mode 100755
index 000000000..c6a670403
--- /dev/null
+++ b/modules/xcos/examples/solvers/benchBouncing.sce
@@ -0,0 +1,44 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+//
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+
+// Import the diagram, modify parameters, augment the ending time and store its compilation in Info()
+loadScicos();
+loadXcosLibs();
+importXcosDiagram("SCI/modules/xcos/demos/ModelicaBlocks/BouncingBall_Modelica.zcos");
+// Redefining messagebox() to avoid popup
+function messagebox(msg, title)
+ disp(title);
+ disp(msg);
+endfunction
+
+scs_m.objs(3).graphics.exprs.paramv(1) = 0.15; // Gravity
+scs_m.objs(3).graphics.exprs.paramv(2) = 0.99; // Floor stickiness
+Info = scicos_simulate(scs_m, "nw");
+tf = 2000; // Final time
+tolerances = scs_m.props.tol;
+[%tcur, %cpr, alreadyran, needstart, needcompile, %state0] = Info(:);
+
+solverName = ["IDA" "DDaskr - Newton" "DDaskr - GMRes"];
+
+disp("--------------------------------");
+for solver = 0:2
+
+ disp("Time for " + solverName(solver + 1) + ":");
+ tolerances(6) = solver+100;
+
+ // Start the solver
+ [state, t] = scicosim(%state0, 0.0, tf, %cpr.sim, "start", tolerances);
+
+ // Run until the end
+ tic();
+ [state, t] = scicosim(state, 0.0, tf, %cpr.sim, "run", tolerances);
+ t = toc();
+ disp(t);
+
+ // End the solver
+ [state, t] = scicosim(state, tf, tf, %cpr.sim, "finish", tolerances);
+
+end
+disp("--------------------------------");
diff --git a/modules/xcos/examples/solvers/benchHydraulics.sce b/modules/xcos/examples/solvers/benchHydraulics.sce
new file mode 100755
index 000000000..40f3dbd3e
--- /dev/null
+++ b/modules/xcos/examples/solvers/benchHydraulics.sce
@@ -0,0 +1,42 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+//
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+
+// Import the diagram, modify parameters, augment the ending time and store its compilation in Info()
+loadScicos();
+loadXcosLibs();
+importXcosDiagram("SCI/modules/xcos/demos/ModelicaBlocks/Hydraulics.zcos");
+// Redefining messagebox() to avoid popup
+function messagebox(msg, title)
+ disp(title);
+ disp(msg);
+endfunction
+
+Info = scicos_simulate(scs_m, "nw");
+tf = 50; // Final time
+tolerances = scs_m.props.tol;
+[%tcur, %cpr, alreadyran, needstart, needcompile, %state0] = Info(:);
+
+solverName = ["IDA" "DDaskr - Newton" "DDaskr - GMRes"];
+
+disp("--------------------------------");
+for solver = 0:2
+
+ disp("Time for " + solverName(solver + 1) + ":");
+ tolerances(6) = solver+100;
+
+ // Start the solver
+ [state, t] = scicosim(%state0, 0.0, tf, %cpr.sim, "start", tolerances);
+
+ // Run until the end
+ tic();
+ [state, t] = scicosim(state, 0.0, tf, %cpr.sim, "run", tolerances);
+ t = toc();
+ disp(t);
+
+ // End the solver
+ [state, t] = scicosim(state, tf, tf, %cpr.sim, "finish", tolerances);
+
+end
+disp("--------------------------------");
diff --git a/modules/xcos/examples/solvers/benchKalman.sce b/modules/xcos/examples/solvers/benchKalman.sce
new file mode 100755
index 000000000..043c832ab
--- /dev/null
+++ b/modules/xcos/examples/solvers/benchKalman.sce
@@ -0,0 +1,45 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - Scilab Enterprises - Paul Bignier
+//
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+
+// Import the diagram, augment the ending time and store its compilation in Info()
+loadScicos();
+loadXcosLibs();
+importXcosDiagram("SCI/modules/xcos/demos/Kalman.zcos");
+Info = scicos_simulate(scs_m, "nw");
+tf = 1050;
+tolerances = scs_m.props.tol;
+tolerances(1) = 1d-13;
+tolerances(2) = 1d-13;
+[%tcur, %cpr, alreadyran, needstart, needcompile, %state0] = Info(:);
+
+solverName = ["LSodar", "CVode BDF/Newton", "CVode BDF/Functional", "CVode Adams/Newton", "CVode Adams/Functional", "Dormand-Prince", "Runge-Kutta", "implicit Runge-Kutta"];
+
+disp("--------------------------------");
+for solver = 0:7
+
+ disp("Time for " + solverName(solver + 1) + ":");
+ tolerances(6) = solver;
+
+ // Modify 'Max step size' if RK-based solver
+ if (solver >= 5) then tolerances(7) = 0.03; end
+
+ // Implicit RK does not support tolerances above 10^-11 for this diagram
+ if (solver >= 7) then tolerances(1) = 1d-10; end
+ if (solver >= 7) then tolerances(2) = 1d-10; end
+
+ // Start the solver
+ [state, t] = scicosim(%state0, 0.0, tf, %cpr.sim, "start", tolerances);
+
+ // Run until the end
+ tic();
+ [state, t] = scicosim(state, 0.0, tf, %cpr.sim, "run", tolerances);
+ t = toc();
+ disp(t);
+
+ // End the solver
+ [state, t] = scicosim(state, tf, tf, %cpr.sim, "finish", tolerances);
+
+end
+disp("--------------------------------");
diff --git a/modules/xcos/examples/solvers/benchSine.sce b/modules/xcos/examples/solvers/benchSine.sce
new file mode 100755
index 000000000..4c1641596
--- /dev/null
+++ b/modules/xcos/examples/solvers/benchSine.sce
@@ -0,0 +1,39 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - Scilab Enterprises - Paul Bignier
+//
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+
+// Import the diagram, augment the ending time and store its compilation in Info()
+loadScicos();
+loadXcosLibs();
+importXcosDiagram("SCI/modules/xcos/examples/solvers/ODE_Example.zcos");
+Info = scicos_simulate(scs_m, "nw");
+tf = 50000;
+tolerances = scs_m.props.tol;
+[%tcur, %cpr, alreadyran, needstart, needcompile, %state0] = Info(:);
+
+solverName = ["LSodar", "CVode BDF/Newton", "CVode BDF/Functional", "CVode Adams/Newton", "CVode Adams/Functional", "Dormand-Prince", "Runge-Kutta", "implicit Runge-Kutta"];
+
+disp("--------------------------------");
+for solver = 0:7
+
+ disp("Time for " + solverName(solver + 1) + ":");
+ tolerances(6) = solver;
+
+ // Modify 'Max step size' if RK-based solver
+ if (solver >= 5) then tolerances(7) = 0.01; end
+
+ // Start the solver
+ [state, t] = scicosim(%state0, 0.0, tf, %cpr.sim, "start", tolerances);
+
+ // Run until the end
+ tic();
+ [state, t] = scicosim(state, 0.0, tf, %cpr.sim, "run", tolerances);
+ t = toc();
+ disp(t);
+
+ // End the solver
+ [state, t] = scicosim(state, tf, tf, %cpr.sim, "finish", tolerances);
+
+end
+disp("--------------------------------");
diff --git a/modules/xcos/examples/solvers/integCVode.sce b/modules/xcos/examples/solvers/integCVode.sce
new file mode 100755
index 000000000..808fd1df8
--- /dev/null
+++ b/modules/xcos/examples/solvers/integCVode.sce
@@ -0,0 +1,25 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - Scilab Enterprises - Paul Bignier
+//
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+
+// Import the diagram and augment the ending time
+loadScicos();
+loadXcosLibs();
+importXcosDiagram("SCI/modules/xcos/examples/solvers/ODE_Example.zcos");
+scs_m.props.tf = 30000;
+
+solverName=["BDF/Newton", "BDF/Functional", "Adams/Newton", "Adams/Functional"];
+
+for solver=1:4
+
+ // Select the solver
+ scs_m.props.tol(6) = solver;
+
+ // Start the timer, launch the simulation and display time
+ tic();
+ try scicos_simulate(scs_m, "nw"); catch disp(lasterror()); end;
+ t = toc();
+ disp(t, "Time for " + solverName(solver) + ":");
+
+end
diff --git a/modules/xcos/examples/solvers/integDoPri.sce b/modules/xcos/examples/solvers/integDoPri.sce
new file mode 100755
index 000000000..d17da1557
--- /dev/null
+++ b/modules/xcos/examples/solvers/integDoPri.sce
@@ -0,0 +1,28 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - Scilab Enterprises - Paul Bignier
+//
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+
+// Import the diagram and augment the ending time
+loadScicos();
+loadXcosLibs();
+importXcosDiagram("SCI/modules/xcos/examples/solvers/ODE_Example.zcos");
+scs_m.props.tf = 30000;
+
+solverName=["BDF/Newton", "BDF/Functional", "Adams/Newton", "Adams/Functional", "Dormand-Prince"];
+
+for solver=1:5
+
+ // Select the solver
+ scs_m.props.tol(6) = solver;
+
+ // Set max step size if DoPri
+ if (solver == 5) then scs_m.props.tol(7) = 0.01; end
+
+ // Start the timer, launch the simulation and display time
+ tic();
+ try scicos_simulate(scs_m, "nw"); catch disp(lasterror()); end;
+ t = toc();
+ disp(t, "Time for " + solverName(solver) + ":");
+
+end
diff --git a/modules/xcos/examples/solvers/integImpRK.sce b/modules/xcos/examples/solvers/integImpRK.sce
new file mode 100755
index 000000000..a2179183b
--- /dev/null
+++ b/modules/xcos/examples/solvers/integImpRK.sce
@@ -0,0 +1,29 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - Scilab Enterprises - Paul Bignier
+//
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+
+// Import the diagram and augment the ending time
+loadScicos();
+loadXcosLibs();
+importXcosDiagram("SCI/modules/xcos/examples/solvers/ODE_Example.zcos");
+scs_m.props.tf = 30000;
+
+solverName=["BDF/Newton", "BDF/Functional", "Adams/Newton", "Adams/Functional", "implicit Runge-Kutta"];
+
+for solver=1:5
+
+ // Select the solver (implicit Runge-Kutta is solver number 7)
+ scs_m.props.tol(6) = solver;
+ if (solver == 5) then scs_m.props.tol(6) = 7; end
+
+ // Set max step size and reltol if implicit Runge-Kutta
+ if (solver == 5) then scs_m.props.tol(7) = 0.01; scs_m.props.tol(2) = 1d-10; end
+
+ // Start the timer, launch the simulation and display time
+ tic();
+ try scicos_simulate(scs_m, "nw"); catch disp(lasterror()); end
+ t = toc();
+ disp(t, "Time for " + solverName(solver) + ":");
+
+end
diff --git a/modules/xcos/examples/solvers/integLSodar.sce b/modules/xcos/examples/solvers/integLSodar.sce
new file mode 100755
index 000000000..1f162a4a3
--- /dev/null
+++ b/modules/xcos/examples/solvers/integLSodar.sce
@@ -0,0 +1,25 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - Scilab Enterprises - Paul Bignier
+//
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+
+// Import the diagram and augment the ending time
+loadScicos();
+loadXcosLibs();
+importXcosDiagram("SCI/modules/xcos/examples/solvers/ODE_Example.zcos");
+scs_m.props.tf = 30000;
+
+solverName = ["LSodar", "BDF/Newton", "BDF/Functional", "Adams/Newton", "Adams/Functional"];
+
+for solver = 0:4
+
+ // Select the solver
+ scs_m.props.tol(6) = solver;
+
+ // Start the timer, launch the simulation and display time
+ tic();
+ try scicos_simulate(scs_m, "nw"); catch disp(lasterror()); end;
+ t = toc();
+ disp(t, "Time for " + solverName(solver+1) + ":");
+
+end
diff --git a/modules/xcos/examples/solvers/integRK.sce b/modules/xcos/examples/solvers/integRK.sce
new file mode 100755
index 000000000..3dd067267
--- /dev/null
+++ b/modules/xcos/examples/solvers/integRK.sce
@@ -0,0 +1,29 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - Scilab Enterprises - Paul Bignier
+//
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+
+// Import the diagram and augment the ending time
+loadScicos();
+loadXcosLibs();
+importXcosDiagram("SCI/modules/xcos/examples/solvers/ODE_Example.zcos");
+scs_m.props.tf = 30000;
+
+solverName=["BDF/Newton", "BDF/Functional", "Adams/Newton", "Adams/Functional", "Runge-Kutta"];
+
+for solver=1:5
+
+ // Select the solver (Runge-Kutta is solver number 6)
+ scs_m.props.tol(6) = solver;
+ if (solver == 5) then scs_m.props.tol(6) = 6; end
+
+ // Set max step size if Runge-Kutta is selected
+ if (solver == 5) then scs_m.props.tol(7) = 0.01; end
+
+ // Start the timer, launch the simulation and display time
+ tic();
+ try scicos_simulate(scs_m, "nw"); catch disp(lasterror()); end
+ t = toc();
+ disp(t, "Time for " + solverName(solver) + ":");
+
+end
diff --git a/modules/xcos/examples/solvers/with_ZeroCrossing.zcos b/modules/xcos/examples/solvers/with_ZeroCrossing.zcos
new file mode 100755
index 000000000..037a1e13a
--- /dev/null
+++ b/modules/xcos/examples/solvers/with_ZeroCrossing.zcos
Binary files differ
diff --git a/modules/xcos/examples/solvers/with_ZeroCrossingSimple.zcos b/modules/xcos/examples/solvers/with_ZeroCrossingSimple.zcos
new file mode 100755
index 000000000..0f3aa33fa
--- /dev/null
+++ b/modules/xcos/examples/solvers/with_ZeroCrossingSimple.zcos
Binary files differ
diff --git a/modules/xcos/examples/solvers/without_ZeroCrossing.zcos b/modules/xcos/examples/solvers/without_ZeroCrossing.zcos
new file mode 100755
index 000000000..21f06036d
--- /dev/null
+++ b/modules/xcos/examples/solvers/without_ZeroCrossing.zcos
Binary files differ
diff --git a/modules/xcos/examples/solvers/without_ZeroCrossingSimple.zcos b/modules/xcos/examples/solvers/without_ZeroCrossingSimple.zcos
new file mode 100755
index 000000000..5b0d2a722
--- /dev/null
+++ b/modules/xcos/examples/solvers/without_ZeroCrossingSimple.zcos
Binary files differ