integrator/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 
34 #include <acado_integrators.hpp>
35 #include <acado_gnuplot.hpp>
36 
37 
38 int main( ){
39 
41 
42  // Parameters
43  double h_hw = 10; // water level
44  double A_hw = 1.0; // amplitude of the waves
45  double T_hw = 5.0; // duration of a wave
46  double rho = 1000; // density of water
47  double A = 1.0; // bottom area of the buoy
48  double m = 100; // mass of the buoy
49  double g = 9.81; // gravitational constant
50 
51  // Free varameter
52  double a = 1.0; // take to be constant here
53 
54  // Variables
55  DifferentialState h; // Position of the buoy
56  DifferentialState v; // Velocity of the buoy
57  DifferentialState w; // Produced wave energy
58  TIME t;
59 
60  // Differential equation
62 
63  // Height of the wave
65  hw = h_hw + A_hw*sin(2*M_PI*t/T_hw);
66  f << dot(h) == v;
67  f << dot(v) == rho*A*(hw-h)/m - g - a*v;
68  f << dot(w) == a*v*v;
69 
70  // Define an integrator:
71  // ---------------------
72  IntegratorRK45 integrator( f );
73 
74  // Define an initial value:
75  // ------------------------
76  double x_start[3];
77  x_start[0] = h_hw - 2*A_hw;
78  x_start[1] = 0;
79  x_start[2] = 0;
80 
81  Grid timeInterval( 0.0, 25.0, 200 );
82 
83  integrator.set( INTEGRATOR_PRINTLEVEL, MEDIUM );
84  integrator.integrate( timeInterval, x_start );
85 
86  VariablesGrid differentialStates;
87  VariablesGrid intermediateStates;
88 
89  integrator.getX ( differentialStates );
90  integrator.getI ( intermediateStates );
91 
92  GnuplotWindow window;
93  window.addSubplot( differentialStates(0) );
94  window.addSubplot( differentialStates(1) );
95  window.addSubplot( differentialStates(2) );
96 
97  window.plot();
98 
99  return 0;
100 }
101 
102 
103 
USING_NAMESPACE_ACADO IntermediateState sin(const Expression &arg)
returnValue getX(DVector &xEnd) const
int main()
virtual returnValue plot(PlotFrequency _frequency=PLOT_IN_ANY_CASE)
returnValue set(OptionsName name, int value)
#define USING_NAMESPACE_ACADO
Provides a time grid consisting of vector-valued optimization variables at each grid point...
Allows to conveniently handle (one-dimensional) grids consisting of time points.
Definition: grid.hpp:58
returnValue addSubplot(PlotWindowSubplot &_subplot)
returnValue getI(VariablesGrid &I) const
#define M_PI
Definition: acado_utils.hpp:54
#define v
Expression dot(const Expression &arg)
Implements the Runge-Kutta-45 scheme for integrating ODEs.
Provides an interface to Gnuplot for plotting algorithmic outputs.
returnValue integrate(double t0, double tend, double *x0, double *xa=0, double *p=0, double *u=0, double *w=0)
Definition: integrator.cpp:207
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