ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/OOPSEMinimizerBase.cpp
Revision: 1035
Committed: Fri Feb 6 21:37:59 2004 UTC (20 years, 5 months ago) by tim
File size: 3130 byte(s)
Log Message:
Single version of energy minimization for argon is working, need to add constraint

File Contents

# Content
1 #include "Integrator.hpp"
2
3 OOPSEMinimizerBase::OOPSEMinimizerBase(SimInfo* theInfo, ForceFields* the_ff)
4 : RealIntegrator( theInfo, the_ff ){
5 tStats = new Thermo(info);
6 dumpOut = new DumpWriter(info);
7 statOut = new StatWriter(info);
8 calcDim();
9 }
10
11 OOPSEMinimizerBase::~OOPSEMinimizerBase(){
12 delete tStats;
13 delete dumpOut;
14 delete statOut;
15 }
16
17 /**
18 *
19 */
20
21
22 double OOPSEMinimizerBase::calcGradient(vector<double>& x, vector<double>& grad){
23 Atom** atoms;
24 DirectionalAtom* dAtom;
25 int index;
26 double force[3];
27 double dAtomGrad[6];
28
29 setCoor(x);
30 calcForce(1, 1);
31
32 atoms = info->atoms;
33 index = 0;
34
35 for(int i = 0; i < nAtoms; i++){
36
37 if(atoms[i]->isDirectional()){
38 dAtom = (DirectionalAtom*) atoms[i];
39 dAtom->getGrad(dAtomGrad);
40
41 //gradient = du/dx = -f
42 grad[index++] = -dAtomGrad[0];
43 grad[index++] = -dAtomGrad[1];
44 grad[index++] = -dAtomGrad[2];
45 grad[index++] = dAtomGrad[3];
46 grad[index++] = dAtomGrad[4];
47 grad[index++] = dAtomGrad[5];
48
49 }
50 else{
51 atoms[i]->getFrc(force);
52
53 grad[index++] = -force[0];
54 grad[index++] = -force[1];
55 grad[index++] = -force[2];
56
57 }
58
59 }
60
61 return tStats->getPotential();
62
63 }
64
65 /**
66 *
67 */
68
69 void OOPSEMinimizerBase::setCoor(vector<double>& x){
70 Atom** atoms;
71 DirectionalAtom* dAtom;
72 int index;
73 double position[3];
74 double eulerAngle[3];
75
76 atoms = info->atoms;
77 index = 0;
78
79 for(int i = 0; i < nAtoms; i++){
80
81 position[0] = x[index++];
82 position[1] = x[index++];
83 position[2] = x[index++];
84
85 atoms[i]->setPos(position);
86
87 if (atoms[i]->isDirectional()){
88 dAtom = (DirectionalAtom*) atoms[i];
89
90 eulerAngle[0] = x[index++];
91 eulerAngle[1] = x[index++];
92 eulerAngle[2] = x[index++];
93
94 dAtom->setEuler(eulerAngle[0], eulerAngle[1], eulerAngle[2]);
95
96 }
97
98 }
99
100 }
101
102 /**
103 *
104 */
105 vector<double> OOPSEMinimizerBase::getCoor(){
106 Atom** atoms;
107 DirectionalAtom* dAtom;
108 int index;
109 double position[3];
110 double eulerAngle[3];
111 vector<double> x;
112
113 x.resize(getDim());
114 atoms = info->atoms;
115 index = 0;
116
117 for(int i = 0; i < nAtoms; i++){
118 atoms[i]->getPos(position);
119
120 x[index++] = position[0];
121 x[index++] = position[1];
122 x[index++] = position[2];
123
124 if (atoms[i]->isDirectional()){
125 dAtom = (DirectionalAtom*) atoms[i];
126 dAtom->getEulerAngles(eulerAngle);
127
128 x[index++] = eulerAngle[0];
129 x[index++] = eulerAngle[1];
130 x[index++] = eulerAngle[2];
131
132 }
133
134 }
135
136 return x;
137
138 }
139
140 void OOPSEMinimizerBase::calcDim(){
141 Atom** atoms;
142 DirectionalAtom* dAtom;
143
144 dim = 0;
145
146 atoms = info->atoms;
147
148 for(int i = 0; i < nAtoms; i++){
149 dim += 3;
150 if (atoms[i]->isDirectional())
151 dim += 3;
152 }
153
154 }
155
156 void OOPSEMinimizerBase::output(vector<double>& x, int iteration){
157 setCoor(x);
158 calcForce(1, 1);
159 dumpOut->writeDump(iteration);
160 statOut->writeStat(iteration);
161 }

Properties

Name Value
svn:executable *