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