integration_algorithm/wave_energy.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
35 #include <acado_gnuplot.hpp>
36 
37 using namespace std;
38 
40 
41 int main( )
42 {
43  // Parameters
44  double h_hw = 10; // water level
45  double A_hw = 1.0; // amplitude of the waves
46  double T_hw = 5.0; // duration of a wave
47  double rho = 1000; // density of water
48  double A = 1.0; // bottom area of the buoy
49  double m = 100; // mass of the buoy
50  double g = 9.81; // gravitational constant
51 
52  // Free varameter
53  double a = 1.0; // take to be constant here
54 
55  // Variables
56  DifferentialState h; // Position of the buoy
57  DifferentialState v; // Velocity of the buoy
58  DifferentialState w; // Produced wave energy
59  TIME t;
60 
61  // Differential equation
63 
64  // Height of the wave
66  hw = h_hw + A_hw*sin(2*M_PI*t/T_hw);
67  f << dot(h) == v;
68  f << dot(v) == rho*A*(hw-h)/m - g - a*v;
69  f << dot(w) == a*v*v;
70 
71  // Define an initial value:
72  // ------------------------
73  DVector xStart( 3 );
74  xStart(0) = h_hw - 2.0*A_hw;
75  xStart(1) = 0.0;
76  xStart(2) = 0.0;
77 
78  Grid timeHorizon( 0.0,25.0 );
79 
80  // DEFINE AN INTEGRATOR:
81  // ---------------------
82 
83  IntegrationAlgorithm intAlg;
84 
85  intAlg.addStage( f, timeHorizon, INT_RK45 );
86 
87  intAlg.set( INTEGRATOR_PRINTLEVEL, MEDIUM );
88  intAlg.set( PLOT_RESOLUTION, HIGH );
89  intAlg.set( FREEZE_INTEGRATOR, NO );
90 
91  GnuplotWindow window;
92  window.addSubplot( h );
93  window.addSubplot( v );
94  window.addSubplot( w );
95 
96  intAlg << window;
97 
98  // START THE INTEGRATION:
99  // ----------------------
100 
101  intAlg.integrate( timeHorizon, xStart );
102 
103  return 0;
104 }
105 
106 
107 
USING_NAMESPACE_ACADO IntermediateState sin(const Expression &arg)
USING_NAMESPACE_ACADO int main()
#define USING_NAMESPACE_ACADO
Allows to conveniently handle (one-dimensional) grids consisting of time points.
Definition: grid.hpp:58
returnValue integrate(VariablesGrid *x, VariablesGrid *xa, VariablesGrid *p, VariablesGrid *u, VariablesGrid *w)
returnValue addSubplot(PlotWindowSubplot &_subplot)
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
#define M_PI
Definition: acado_utils.hpp:54
User-interface to integrate a DynamicSystem, possibly over multiple stages.
#define NO
Definition: acado_types.hpp:53
#define v
Expression dot(const Expression &arg)
virtual returnValue addStage(const DynamicSystem &dynamicSystem_, const Grid &stageIntervals, const IntegratorType &integratorType_=INT_UNKNOWN)
Provides an interface to Gnuplot for plotting algorithmic outputs.
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:35:16