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( Real, DiffusionCoeff );
00077
00078 PROPERTYSLOT_SET_GET( Integer, Fixed );
00079
00080 PROPERTYSLOT_NO_LOAD_SAVE( Real, Velocity,
00081 NOMETHOD,
00082 &Variable::getVelocity );
00083
00084 PROPERTYSLOT_LOAD_SAVE( Real, MolarConc,
00085 &Variable::setMolarConc,
00086 &Variable::getMolarConc,
00087 &Variable::loadMolarConc,
00088 NOMETHOD );
00089
00090
00091
00092
00093 PROPERTYSLOT_NO_LOAD_SAVE( Real, NumberConc,
00094 &Variable::setNumberConc,
00095 &Variable::getNumberConc );
00096 }
00097
00098
00099 Variable();
00100 virtual ~Variable();
00101
00102 virtual const EntityType getEntityType() const
00103 {
00104 return EntityType( EntityType::VARIABLE );
00105 }
00106
00107
00108
00109
00110
00111
00112 virtual void initialize();
00113
00114
00115
00116
00117
00118
00119 virtual const bool isIntegrationNeeded() const
00120 {
00121 return ! theInterpolantVector.empty();
00122 }
00123
00124
00125
00126
00127
00128 virtual void integrate( RealParam aTime )
00129 {
00130 if( isFixed() == false )
00131 {
00132 updateValue( aTime );
00133 }
00134 else
00135 {
00136 theLastTime = aTime;
00137 }
00138 }
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 void interIntegrate( RealParam aCurrentTime )
00149 {
00150 const Real anInterval( aCurrentTime - theLastTime );
00151
00152 if ( anInterval > 0.0 )
00153 {
00154 Real aVelocitySum( calculateDifferenceSum( aCurrentTime,
00155 anInterval ) );
00156 loadValue( getValue() + aVelocitySum );
00157 }
00158 }
00159
00160
00161
00162
00163
00164
00165
00166
00167 virtual SET_METHOD( Real, Value )
00168 {
00169 if ( !isFixed() )
00170 {
00171 loadValue( value );
00172 }
00173 }
00174
00175
00176
00177
00178
00179 GET_METHOD( Real, Value )
00180 {
00181 return saveValue();
00182 }
00183
00184 void addValue( RealParam aValue )
00185 {
00186 setValue( getValue() + aValue );
00187 }
00188
00189 void loadValue( RealParam aValue )
00190 {
00191 theValue = aValue;
00192 }
00193
00194 const Real saveValue() const
00195 {
00196 return theValue;
00197 }
00198
00199
00200
00201
00202
00203 GET_METHOD( Real, Velocity )
00204 {
00205 Real aVelocitySum( 0.0 );
00206 FOR_ALL( InterpolantVector, theInterpolantVector )
00207 {
00208 InterpolantPtr const anInterpolantPtr( *i );
00209 aVelocitySum += anInterpolantPtr->getVelocity( theLastTime );
00210 }
00211
00212 return aVelocitySum;
00213 }
00214
00215
00216
00217
00218
00219
00220
00221 void setFixed( const bool aValue )
00222 {
00223 theFixed = aValue;
00224 }
00225
00226
00227
00228
00229
00230 const bool isFixed() const
00231 {
00232 return theFixed;
00233 }
00234
00235
00236
00237 SET_METHOD( Integer, Fixed )
00238 {
00239 theFixed = static_cast<bool>( value );
00240 }
00241
00242 GET_METHOD( Integer, Fixed )
00243 {
00244 return theFixed;
00245 }
00246
00247 SET_METHOD( Real, DiffusionCoeff )
00248 {
00249 theDiffusionCoeff = value;
00250 }
00251
00252 GET_METHOD( Real, DiffusionCoeff )
00253 {
00254 return theDiffusionCoeff;
00255 }
00256
00257
00258
00259
00260
00261
00262
00263 GET_METHOD( Real, MolarConc )
00264 {
00265
00266 return getNumberConc() * N_A_R;
00267 }
00268
00269
00270
00271
00272
00273
00274
00275 SET_METHOD( Real, MolarConc )
00276 {
00277 setNumberConc( value * N_A );
00278 }
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 LOAD_METHOD( Real, MolarConc )
00289 {
00290 loadNumberConc( value * N_A );
00291 }
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301 GET_METHOD( Real, NumberConc )
00302 {
00303 return getValue() / getSizeOfSuperSystem();
00304
00305
00306
00307
00308 }
00309
00310
00311
00312
00313
00314
00315
00316 SET_METHOD( Real, NumberConc )
00317 {
00318 setValue( value * getSizeOfSuperSystem() );
00319
00320
00321
00322
00323 }
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343 LOAD_METHOD( Real, NumberConc );
00344
00345 void registerInterpolant( InterpolantPtr const anInterpolant );
00346
00347
00348
00349 protected:
00350
00351 const Real calculateDifferenceSum( RealParam aCurrentTime,
00352 RealParam anInterval ) const
00353 {
00354 Real aVelocitySum( 0.0 );
00355 FOR_ALL( InterpolantVector, theInterpolantVector )
00356 {
00357 InterpolantPtr const anInterpolantPtr( *i );
00358 aVelocitySum += anInterpolantPtr->getDifference( aCurrentTime,
00359 anInterval );
00360 }
00361
00362 return aVelocitySum;
00363 }
00364
00365
00366 void updateValue( RealParam aCurrentTime )
00367 {
00368 const Real anInterval( aCurrentTime - theLastTime );
00369
00370 if( anInterval == 0.0 )
00371 {
00372 return;
00373 }
00374
00375 const Real aVelocitySum( calculateDifferenceSum( aCurrentTime,
00376 anInterval ) );
00377 loadValue( getValue() + aVelocitySum );
00378
00379 theLastTime = aCurrentTime;
00380 }
00381
00382
00383
00384 void clearInterpolantVector();
00385
00386 private:
00387
00388 const Real getSizeOfSuperSystem() const
00389 {
00390 return getSuperSystem()->getSizeVariable()->getValue();
00391 }
00392
00393 protected:
00394
00395 Real theValue;
00396
00397 Real theLastTime;
00398
00399 Real theDiffusionCoeff;
00400
00401 InterpolantVector theInterpolantVector;
00402
00403 bool theFixed;
00404 };
00405
00406
00407
00408
00409 }
00410
00411
00412 #endif
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423