1 |
tim |
1722 |
/* |
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/NVE.hpp" |
35 |
|
|
namespace oopse { |
36 |
|
|
|
37 |
|
|
//register the creator to IntegratorFactory |
38 |
|
|
REGISTER_CREATOR(IntegratorFactory, "NVE", NVE); |
39 |
|
|
|
40 |
tim |
1756 |
NVE::NVE(SimInfo* info) : VelocityVerletIntegrator(info){ |
41 |
tim |
1722 |
|
42 |
|
|
} |
43 |
|
|
|
44 |
tim |
1756 |
void NVE::moveA(){ |
45 |
tim |
1726 |
typename SimInfo::MoleculeIterator i; |
46 |
tim |
1722 |
std::vector<StuntDouble*>::iterator j; |
47 |
|
|
Molecule* mol; |
48 |
|
|
StuntDouble* integrableObject; |
49 |
|
|
Vector3d vel; |
50 |
|
|
Vector3d pos; |
51 |
|
|
Vector3d frc; |
52 |
|
|
Vector3d Tb; |
53 |
|
|
Vector3d ji; |
54 |
|
|
double mass; |
55 |
|
|
|
56 |
tim |
1756 |
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
57 |
tim |
1722 |
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
58 |
|
|
integrableObject = mol->nextIntegrableObject(j)) { |
59 |
|
|
|
60 |
|
|
vel =integrableObject->getVel(); |
61 |
|
|
pos = integrableObject->getPos(); |
62 |
|
|
frc = integrableObject->getFrc(); |
63 |
|
|
mass = integrableObject->getMass(); |
64 |
|
|
|
65 |
|
|
// velocity half step |
66 |
|
|
vel += (halfStep /mass * UnitConstant::eConvert) * frc; |
67 |
|
|
|
68 |
|
|
// position whole step |
69 |
|
|
pos += fullStep * vel; |
70 |
|
|
|
71 |
|
|
integrableObject->setVel(vel); |
72 |
|
|
integrableObject->setPos(pos); |
73 |
|
|
|
74 |
|
|
if (integrableObject->isDirectional()){ |
75 |
|
|
|
76 |
|
|
// get and convert the torque to body frame |
77 |
|
|
|
78 |
|
|
Tb = integrableObject->lab2Body(integrableObject->getTrq()); |
79 |
|
|
|
80 |
|
|
// get the angular momentum, and propagate a half step |
81 |
|
|
|
82 |
|
|
ji = integrableObject->getJ(); |
83 |
|
|
|
84 |
|
|
ji += (halfStep * UnitConstant::eConvert) * Tb; |
85 |
|
|
|
86 |
|
|
this->rotationPropagation( integrableObject, ji ); |
87 |
|
|
|
88 |
|
|
integrableObject->setJ(ji); |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
|
92 |
|
|
} |
93 |
tim |
1756 |
} //end for(mol = info_->beginMolecule(i)) |
94 |
tim |
1722 |
|
95 |
|
|
constraintAlgorithm->doConstrainA(); |
96 |
|
|
|
97 |
|
|
} |
98 |
|
|
|
99 |
tim |
1756 |
void NVE::moveB(){ |
100 |
tim |
1726 |
typename SimInfo::MoleculeIterator i; |
101 |
tim |
1722 |
std::vector<StuntDouble*>::iterator j; |
102 |
|
|
Molecule* mol; |
103 |
|
|
StuntDouble* integrableObject; |
104 |
|
|
Vector3d vel; |
105 |
|
|
Vector3d frc; |
106 |
|
|
Vector3d Tb; |
107 |
|
|
Vector3d ji; |
108 |
|
|
double mass; |
109 |
|
|
|
110 |
tim |
1756 |
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
111 |
tim |
1722 |
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
112 |
|
|
integrableObject = mol->nextIntegrableObject(j)) { |
113 |
|
|
|
114 |
|
|
vel =integrableObject->getVel(); |
115 |
|
|
frc = integrableObject->getFrc(); |
116 |
|
|
mass = integrableObject->getMass(); |
117 |
|
|
|
118 |
|
|
// velocity half step |
119 |
|
|
vel += (halfStep /mass * UnitConstant::eConvert) * frc; |
120 |
|
|
|
121 |
|
|
integrableObject->setVel(vel); |
122 |
|
|
|
123 |
|
|
if (integrableObject->isDirectional()){ |
124 |
|
|
|
125 |
|
|
// get and convert the torque to body frame |
126 |
|
|
|
127 |
|
|
Tb = integrableObject->lab2Body(integrableObject->getTrq()); |
128 |
|
|
|
129 |
|
|
// get the angular momentum, and propagate a half step |
130 |
|
|
|
131 |
|
|
ji = integrableObject->getJ(); |
132 |
|
|
|
133 |
|
|
ji += (halfStep * UnitConstant::eConvert) * Tb; |
134 |
|
|
|
135 |
|
|
integrableObject->setJ(ji); |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
|
139 |
|
|
} |
140 |
tim |
1756 |
} //end for(mol = info_->beginMolecule(i)) |
141 |
tim |
1722 |
|
142 |
|
|
|
143 |
|
|
constraintAlgorithm->doConstrainB(); |
144 |
|
|
|
145 |
|
|
} |
146 |
|
|
|
147 |
tim |
1756 |
|
148 |
|
|
void NVE::calcConservedQuantity() { |
149 |
|
|
|
150 |
|
|
} |
151 |
|
|
|
152 |
tim |
1722 |
} //end namespace oopse |