1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
#include "AdunKernel/AdunBerendsenThermostat.h"
@implementation AdBerendsenThermostat
- (id) init
{
return [self initWithTargetTemperature: 300.0
couplingFactor: 100.0];
}
- (id) initWithTargetTemperature: (double) doubleOne
couplingFactor: (double) doubleTwo
{
if((self = [super init]))
{
[self setTargetTemperature: doubleOne];
couplingFactor = doubleTwo;
timeStep = 1;
timePerCouplingFactor = (double)timeStep/couplingFactor;
}
return self;
}
- (NSString*) description
{
NSMutableString* description = [NSMutableString string];
[description appendFormat: @"%@. Target temperature %5.2lf. Coupling factor %5.2lf",
NSStringFromClass([self class]), targetTemperature, couplingFactor];
return description;
}
- (void) simulator: (AdSimulator*) aSimulator
willBeginProductionWithSystems: (AdSystemCollection*) aSystemCollection
forceFields: (AdForceFieldCollection*) aForceFieldCollection
{
timeStep = [aSimulator timeStep];
timePerCouplingFactor = (double)timeStep/couplingFactor;
}
- (void) simulatorDidPerformSecondVelocityUpdateForSystem: (AdSystem*) system
{
int j,k;
double temperature, factor;
AdMatrix* velocities;
temperature = [system temperature];
if(temperature == 0)
{
factor = 0;
}
else
{
factor = 1 - timePerCouplingFactor*(1 - (targetTemperature/temperature));
factor = sqrt(factor);
}
velocities = [system velocities];
[system object: self willBeginWritingToMatrix: velocities];
for(j=0; j < velocities->no_rows; j++)
for(k=0; k<3; k++)
velocities->matrix[j][k] *= factor;
[system object: self didFinishWritingToMatrix: velocities];
}
- (void) setTargetTemperature: (double) aDouble
{
if(aDouble < 0)
[NSException raise: NSInvalidArgumentException
format: @"Temperature cannot be less than 0"];
targetTemperature = aDouble;
}
- (double) targetTemperature
{
return targetTemperature;
}
- (void) setCouplingFactor: (double) aDouble
{
couplingFactor = aDouble;
timePerCouplingFactor = (double)timeStep/couplingFactor;
}
- (double) couplingFactor
{
return couplingFactor;
}
- (void) simulatorWillPerformFirstVelocityUpdateForSystem: (AdSystem*) aSystem
{
//Does nothing here
}
- (void) simulatorWillPerformPositionUpdateForSystem: (AdSystem*) aSystem
{
//Does nothing here
}
- (void) simulatorDidPerformPositionUpdateForSystem: (AdSystem*) aSystem
{
//Does nothing here
}
- (void) simulatorWillPerformSecondVelocityUpdateForSystem: (AdSystem*) aSystem
{
//Does nothing here
}
- (void) simulatorDidFinishProduction: (AdSimulator*) aSimulator
{
//Does nothing here
}
@end
|