1 |
/* |
2 |
* Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project |
3 |
* |
4 |
* Contact: oopse@oopse.org |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or |
7 |
* modify it under the terms of the GNU Lesser General Public License |
8 |
* as published by the Free Software Foundation; either version 2.1 |
9 |
* of the License, or (at your option) any later version. |
10 |
* All we ask is that proper credit is given for our work, which includes |
11 |
* - but is not limited to - adding the above copyright notice to the beginning |
12 |
* of your source code files, and to any copyright notice that you may distribute |
13 |
* with programs based on this work. |
14 |
* |
15 |
* This program 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 |
18 |
* GNU Lesser General Public License for more details. |
19 |
* |
20 |
* You should have received a copy of the GNU Lesser General Public License |
21 |
* along with this program; if not, write to the Free Software |
22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 |
* |
24 |
*/ |
25 |
|
26 |
/** |
27 |
* @file NVE.cpp |
28 |
* @author tlin |
29 |
* @date 11/08/2004 |
30 |
* @time 15:13am |
31 |
* @version 1.0 |
32 |
*/ |
33 |
|
34 |
#include "integrators/IntegratorFactory.hpp" |
35 |
#include "integrators/NVE.hpp" |
36 |
#include "primitives/Molecule.hpp" |
37 |
#include "utils/OOPSEConstant.hpp" |
38 |
|
39 |
namespace oopse { |
40 |
|
41 |
Integrator* createNVE(SimInfo* info) { |
42 |
return new NVE(info); |
43 |
} |
44 |
|
45 |
//register the creator to IntegratorFactory |
46 |
bool registerNVEStatus = IntegratorFactory::getInstance()->registerIntegrator("NVE", createNVE); |
47 |
|
48 |
NVE::NVE(SimInfo* info) : VelocityVerletIntegrator(info){ |
49 |
|
50 |
} |
51 |
|
52 |
void NVE::moveA(){ |
53 |
SimInfo::MoleculeIterator i; |
54 |
Molecule::IntegrableObjectIterator j; |
55 |
Molecule* mol; |
56 |
StuntDouble* integrableObject; |
57 |
Vector3d vel; |
58 |
Vector3d pos; |
59 |
Vector3d frc; |
60 |
Vector3d Tb; |
61 |
Vector3d ji; |
62 |
double mass; |
63 |
|
64 |
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
65 |
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
66 |
integrableObject = mol->nextIntegrableObject(j)) { |
67 |
|
68 |
vel =integrableObject->getVel(); |
69 |
pos = integrableObject->getPos(); |
70 |
frc = integrableObject->getFrc(); |
71 |
mass = integrableObject->getMass(); |
72 |
|
73 |
// velocity half step |
74 |
vel += (dt2 /mass * OOPSEConstant::energyConvert) * frc; |
75 |
|
76 |
// position whole step |
77 |
pos += dt * vel; |
78 |
|
79 |
integrableObject->setVel(vel); |
80 |
integrableObject->setPos(pos); |
81 |
|
82 |
if (integrableObject->isDirectional()){ |
83 |
|
84 |
// get and convert the torque to body frame |
85 |
|
86 |
Tb = integrableObject->lab2Body(integrableObject->getTrq()); |
87 |
|
88 |
// get the angular momentum, and propagate a half step |
89 |
|
90 |
ji = integrableObject->getJ(); |
91 |
|
92 |
ji += (dt2 * OOPSEConstant::energyConvert) * Tb; |
93 |
|
94 |
rotAlgo->rotate(integrableObject, ji, dt); |
95 |
|
96 |
integrableObject->setJ(ji); |
97 |
} |
98 |
|
99 |
|
100 |
} |
101 |
} //end for(mol = info_->beginMolecule(i)) |
102 |
|
103 |
//constraintAlgorithm->doConstrainA(); |
104 |
|
105 |
} |
106 |
|
107 |
void NVE::moveB(){ |
108 |
SimInfo::MoleculeIterator i; |
109 |
Molecule::IntegrableObjectIterator j; |
110 |
Molecule* mol; |
111 |
StuntDouble* integrableObject; |
112 |
Vector3d vel; |
113 |
Vector3d frc; |
114 |
Vector3d Tb; |
115 |
Vector3d ji; |
116 |
double mass; |
117 |
|
118 |
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
119 |
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
120 |
integrableObject = mol->nextIntegrableObject(j)) { |
121 |
|
122 |
vel =integrableObject->getVel(); |
123 |
frc = integrableObject->getFrc(); |
124 |
mass = integrableObject->getMass(); |
125 |
|
126 |
// velocity half step |
127 |
vel += (dt2 /mass * OOPSEConstant::energyConvert) * frc; |
128 |
|
129 |
integrableObject->setVel(vel); |
130 |
|
131 |
if (integrableObject->isDirectional()){ |
132 |
|
133 |
// get and convert the torque to body frame |
134 |
|
135 |
Tb = integrableObject->lab2Body(integrableObject->getTrq()); |
136 |
|
137 |
// get the angular momentum, and propagate a half step |
138 |
|
139 |
ji = integrableObject->getJ(); |
140 |
|
141 |
ji += (dt2 * OOPSEConstant::energyConvert) * Tb; |
142 |
|
143 |
integrableObject->setJ(ji); |
144 |
} |
145 |
|
146 |
|
147 |
} |
148 |
} //end for(mol = info_->beginMolecule(i)) |
149 |
|
150 |
|
151 |
//constraintAlgorithm->doConstrainB(); |
152 |
|
153 |
} |
154 |
|
155 |
|
156 |
double NVE::calcConservedQuantity() { |
157 |
return thermo.getTotalE(); |
158 |
} |
159 |
|
160 |
} //end namespace oopse |