00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef __VARIABLE_HPP
00032 #define __VARIABLE_HPP
00033
00034 #include <utility>
00035
00036 #include "libecs.hpp"
00037 #include "Entity.hpp"
00038 #include "Interpolant.hpp"
00039 #include "System.hpp"
00040
00041
00042 namespace libecs
00043 {
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 LIBECS_DM_CLASS( Variable, Entity )
00059 {
00060
00061 public:
00062
00063 LIBECS_DM_BASECLASS( Variable );
00064
00065 LIBECS_DM_OBJECT( Variable, Variable )
00066 {
00067 INHERIT_PROPERTIES( Entity );
00068
00069 PROPERTYSLOT_LOAD_SAVE( Real, Value,
00070 &Variable::setValue,
00071 &Variable::getValue,
00072 &Variable::loadValue,
00073 &Variable::saveValue );
00074
00075
00076 PROPERTYSLOT_SET_GET( Integer, Fixed );
00077
00078 PROPERTYSLOT_NO_LOAD_SAVE( Real, Velocity,
00079 NOMETHOD,
00080 &Variable::getVelocity );
00081
00082 PROPERTYSLOT_LOAD_SAVE( Real, MolarConc,
00083 &Variable::setMolarConc,
00084 &Variable::getMolarConc,
00085 &Variable::loadMolarConc,
00086 NOMETHOD );
00087
00088
00089
00090
00091 PROPERTYSLOT_NO_LOAD_SAVE( Real, NumberConc,
00092 &Variable::setNumberConc,
00093 &Variable::getNumberConc );
00094 }
00095
00096
00097 Variable();
00098 virtual ~Variable();
00099
00100 virtual const EntityType getEntityType() const
00101 {
00102 return EntityType( EntityType::VARIABLE );
00103 }
00104
00105
00106
00107
00108
00109
00110 virtual void initialize();
00111
00112
00113
00114
00115
00116
00117 virtual const bool isIntegrationNeeded() const
00118 {
00119 return ! theInterpolantVector.empty();
00120 }
00121
00122
00123
00124
00125
00126 virtual void integrate( RealParam aTime )
00127 {
00128 if( isFixed() == false )
00129 {
00130 updateValue( aTime );
00131 }
00132 else
00133 {
00134 theLastTime = aTime;
00135 }
00136 }
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 void interIntegrate( RealParam aCurrentTime )
00147 {
00148 const Real anInterval( aCurrentTime - theLastTime );
00149
00150 if ( anInterval > 0.0 )
00151 {
00152 Real aVelocitySum( calculateDifferenceSum( aCurrentTime,
00153 anInterval ) );
00154 loadValue( getValue() + aVelocitySum );
00155 }
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165 virtual SET_METHOD( Real, Value )
00166 {
00167 if ( !isFixed() )
00168 {
00169 loadValue( value );
00170 }
00171 }
00172
00173
00174
00175
00176
00177 GET_METHOD( Real, Value )
00178 {
00179 return saveValue();
00180 }
00181
00182 void addValue( RealParam aValue )
00183 {
00184 setValue( getValue() + aValue );
00185 }
00186
00187 void loadValue( RealParam aValue )
00188 {
00189 theValue = aValue;
00190 }
00191
00192 const Real saveValue() const
00193 {
00194 return theValue;
00195 }
00196
00197
00198
00199
00200
00201 GET_METHOD( Real, Velocity )
00202 {
00203 Real aVelocitySum( 0.0 );
00204 FOR_ALL( InterpolantVector, theInterpolantVector )
00205 {
00206 InterpolantPtr const anInterpolantPtr( *i );
00207 aVelocitySum += anInterpolantPtr->getVelocity( theLastTime );
00208 }
00209
00210 return aVelocitySum;
00211 }
00212
00213
00214
00215
00216
00217
00218
00219 void setFixed( const bool aValue )
00220 {
00221 theFixed = aValue;
00222 }
00223
00224
00225
00226
00227
00228 const bool isFixed() const
00229 {
00230 return theFixed;
00231 }
00232
00233
00234
00235 SET_METHOD( Integer, Fixed )
00236 {
00237 theFixed = static_cast<bool>( value );
00238 }
00239
00240 GET_METHOD( Integer, Fixed )
00241 {
00242 return theFixed;
00243 }
00244
00245
00246
00247
00248
00249
00250
00251
00252 GET_METHOD( Real, MolarConc )
00253 {
00254
00255 return getNumberConc() * N_A_R;
00256 }
00257
00258
00259
00260
00261
00262
00263
00264 SET_METHOD( Real, MolarConc )
00265 {
00266 setNumberConc( value * N_A );
00267 }
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 LOAD_METHOD( Real, MolarConc )
00278 {
00279 loadNumberConc( value * N_A );
00280 }
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290 GET_METHOD( Real, NumberConc )
00291 {
00292 return getValue() / getSizeOfSuperSystem();
00293
00294
00295
00296
00297 }
00298
00299
00300
00301
00302
00303
00304
00305 SET_METHOD( Real, NumberConc )
00306 {
00307 setValue( value * getSizeOfSuperSystem() );
00308
00309
00310
00311
00312 }
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 LOAD_METHOD( Real, NumberConc );
00333
00334 void registerInterpolant( InterpolantPtr const anInterpolant );
00335
00336
00337
00338 protected:
00339
00340 const Real calculateDifferenceSum( RealParam aCurrentTime,
00341 RealParam anInterval ) const
00342 {
00343 Real aVelocitySum( 0.0 );
00344 FOR_ALL( InterpolantVector, theInterpolantVector )
00345 {
00346 InterpolantPtr const anInterpolantPtr( *i );
00347 aVelocitySum += anInterpolantPtr->getDifference( aCurrentTime,
00348 anInterval );
00349 }
00350
00351 return aVelocitySum;
00352 }
00353
00354
00355 void updateValue( RealParam aCurrentTime )
00356 {
00357 const Real anInterval( aCurrentTime - theLastTime );
00358
00359 if( anInterval == 0.0 )
00360 {
00361 return;
00362 }
00363
00364 const Real aVelocitySum( calculateDifferenceSum( aCurrentTime,
00365 anInterval ) );
00366 loadValue( getValue() + aVelocitySum );
00367
00368 theLastTime = aCurrentTime;
00369 }
00370
00371
00372
00373 void clearInterpolantVector();
00374
00375 private:
00376
00377 const Real getSizeOfSuperSystem() const
00378 {
00379 return getSuperSystem()->getSizeVariable()->getValue();
00380 }
00381
00382 protected:
00383
00384 Real theValue;
00385
00386 Real theLastTime;
00387
00388 InterpolantVector theInterpolantVector;
00389
00390 bool theFixed;
00391 };
00392
00393
00394
00395
00396 }
00397
00398
00399 #endif
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410