transfer_device.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 
36 
37 
39 
40 
41 
42 //
43 // PUBLIC MEMBER FUNCTIONS:
44 //
45 
47 {
48  additiveNoise = 0;
49 
51 }
52 
53 
55  BlockName _name,
56  double _samplingTime
57  ) : SimulationBlock( _name,_samplingTime )
58 {
59  lastSignal.init( _dim,1 );
60 
61  additiveNoise = new Noise*[_dim];
62  for( uint i=0; i<_dim; ++i )
63  additiveNoise[i] = 0;
64 
65  noiseSamplingTimes.init( _dim );
67 
68  deadTimes.init( _dim );
69  deadTimes.setAll( 0.0 );
70 
72 }
73 
74 
76 {
77  lastSignal = rhs.lastSignal;
78 
79  if ( rhs.additiveNoise != 0 )
80  {
81  additiveNoise = new Noise*[rhs.getDim( )];
82 
83  for( uint i=0; i<getDim( ); ++i )
84  if ( rhs.additiveNoise[i] != 0 )
85  additiveNoise[i] = (rhs.additiveNoise[i])->clone( );
86  else
87  additiveNoise[i] = 0;
88  }
89  else
90  additiveNoise = 0;
91 
93 
94  deadTimes = rhs.deadTimes;
95 }
96 
97 
99 {
100  if ( additiveNoise != 0 )
101  {
102  for( uint i=0; i<getDim( ); ++i )
103  if ( additiveNoise[i] != 0 )
104  delete additiveNoise[i];
105 
106  delete[] additiveNoise;
107  }
108 }
109 
110 
112 {
113  if ( this != &rhs )
114  {
116 
117  if ( additiveNoise != 0 )
118  {
119  for( uint i=0; i<getDim( ); ++i )
120  if ( additiveNoise[i] != 0 )
121  delete additiveNoise[i];
122 
123  delete[] additiveNoise;
124  }
125 
126 
127  lastSignal = rhs.lastSignal;
128 
129  if ( rhs.additiveNoise != 0 )
130  {
131  additiveNoise = new Noise*[rhs.getDim( )];
132 
133  for( uint i=0; i<getDim( ); ++i )
134  if ( rhs.additiveNoise[i] != 0 )
135  additiveNoise[i] = (rhs.additiveNoise[i])->clone( );
136  else
137  additiveNoise[i] = 0;
138  }
139  else
140  additiveNoise = 0;
141 
143 
144  deadTimes = rhs.deadTimes;
145  }
146 
147  return *this;
148 }
149 
150 
151 
152 
153 //
154 // PROTECTED MEMBER FUNCTIONS:
155 //
156 
157 
159  const DVector& _startValue
160  )
161 {
162  // initialise lastSignal
163  lastSignal.init( getDim( ),1 );
164 
165  lastSignal.setTime( 0,_startTime );
166 
167  if ( _startValue.getDim( ) == getDim( ) )
168  {
169  lastSignal.setVector( 0,_startValue );
170  }
171  else
172  {
173  DVector tmp( getDim( ) );
174  tmp.setAll( 0.0 );
175  lastSignal.setVector( 0,tmp );
176  }
177 
178  // initialise additive noise
179  if ( additiveNoise != 0 )
180  {
181  for( uint i=0; i<getDim( ); ++i )
182  {
183  if ( additiveNoise[i] != 0 )
184  additiveNoise[i]->init( );
185  }
186  }
187 
188  setStatus( BS_READY );
189 
190  return SUCCESSFUL_RETURN;
191 }
192 
193 
195  double endTime,
196  VariablesGrid& currentNoise
197  ) const
198 {
199  double horizonLength = endTime - startTime;
200  if ( horizonLength <= 0.0 )
202 
203  // generate noise grid
204  Grid noiseGrid;
205 
207  {
208  for( uint i=0; i<=floor( horizonLength/noiseSamplingTimes(0) ); ++i )
209  noiseGrid.addTime( ((double)i) * noiseSamplingTimes(0) );
210 
211  if ( acadoIsInteger( horizonLength/noiseSamplingTimes(0) ) == BT_FALSE )
212  noiseGrid.addTime( endTime );
213 
214  noiseGrid.shiftTimes( startTime );
215  }
216  else
217  {
218  noiseGrid.init( startTime,endTime );
219  }
220 
221  // generate current noise
222  DVector noiseVector( 1 );
223 
224  currentNoise.init( getDim( ),noiseGrid );
225  currentNoise.setZero( );
226 
227  if ( additiveNoise != 0 )
228  {
229  // generate noise
230  for( uint i=0; i<getDim( ); ++i )
231  {
232  if ( additiveNoise[i] != 0 )
233  {
234  for( uint j=0; j<currentNoise.getNumPoints( )-1; ++j )
235  {
236  additiveNoise[i]->step( noiseVector );
237  currentNoise( j,i ) = noiseVector( 0 );
238  }
239  currentNoise( currentNoise.getNumPoints( )-1,i ) = noiseVector( 0 );
240  }
241  }
242  }
243 
244  return SUCCESSFUL_RETURN;
245 }
246 
247 
248 
250 
251 /*
252  * end of file
253  */
returnValue setTime(double _time)
Definition: grid.cpp:307
virtual returnValue init(uint seed=0)=0
returnValue setStatus(BlockStatus _status)
virtual ~TransferDevice()
void init(unsigned _dim=0)
Definition: vector.hpp:155
Provides a time grid consisting of vector-valued optimization variables at each grid point...
Allows to pass back messages to the calling function.
virtual returnValue step(DVector &_w)=0
Base class for generating pseudo-random noise for simulating the Process.
Definition: noise.hpp:56
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Definition: acado_types.hpp:42
Allows to conveniently handle (one-dimensional) grids consisting of time points.
Definition: grid.hpp:58
BlockName
#define CLOSE_NAMESPACE_ACADO
uint getDim() const
VariablesGrid lastSignal
returnValue setVector(uint pointIdx, const DVector &_values)
BEGIN_NAMESPACE_ACADO BooleanType acadoIsInteger(double x)
Definition: acado_utils.cpp:37
unsigned getDim() const
Definition: vector.hpp:172
virtual returnValue generateNoise(double startTime, double endTime, VariablesGrid &currentNoise) const
virtual returnValue init(double _startTime=0.0, const DVector &_startValue=emptyConstVector)
returnValue init()
returnValue init(uint _nPoints=0, const double *const _times=0)
Definition: grid.cpp:107
BooleanType acadoIsPositive(double x, double TOL)
void rhs(const real_t *x, real_t *f)
#define BT_TRUE
Definition: acado_types.hpp:47
Grid & shiftTimes(double timeShift)
Definition: grid.cpp:449
returnValue addTime(double _time)
Definition: grid.cpp:339
uint getNumPoints() const
Base class for building-blocks of the SimulationEnvironment.
void setAll(const T &_value)
Definition: vector.hpp:160
DVector noiseSamplingTimes
#define BEGIN_NAMESPACE_ACADO
#define BT_FALSE
Definition: acado_types.hpp:49
SimulationBlock & operator=(const SimulationBlock &rhs)
TransferDevice & operator=(const TransferDevice &rhs)
#define ACADOERROR(retval)
Base class for simulating Actuator and Sensor behaviour wihtin the Process.


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