ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/primitives/Atom.cpp
(Generate patch)

Comparing branches/new_design/OOPSE-4/src/primitives/Atom.cpp (file contents):
Revision 1691, Thu Oct 28 22:34:02 2004 UTC vs.
Revision 1692 by tim, Mon Nov 1 20:15:58 2004 UTC

# Line 1 | Line 1
1 < #include <iostream>
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  
3 using namespace std;
4
5 #include "utils/simError.h"
26   #include "primitives/Atom.hpp"
27 + namespace oopse {
28  
29 < Atom::Atom(int theIndex, SimState* theConfig) {
29 > Atom::Atom(AtomType* at) : StuntDouble(otAtom, &Snapshot::atomData) ,atomType_(at) {
30  
10  objType = OT_ATOM;
11  myConfig = theConfig;
12  hasCoords = false;
13
14  has_dipole = 0;
15  has_charge = 0;
16  
17  index = theIndex;
18  offset = 0;
19  offsetX = offset;
20  offsetY = offset+1;
21  offsetZ = offset+2;
22  
23  Axx = 0;
24  Axy = Axx+1;
25  Axz = Axx+2;
26  
27  Ayx = Axx+3;
28  Ayy = Axx+4;
29  Ayz = Axx+5;
30  
31  Azx = Axx+6;
32  Azy = Axx+7;
33  Azz = Axx+8;
31   }
32  
33 < void Atom::setIndex(int theIndex) {
34 <  index = theIndex;
35 < }
33 > Mat3x3d Atom::getI() {
34 >    return Mat3x3d::identity();
35 > }    
36  
37 < void Atom::setCoords(void){
37 > std::vector<double> Atom::getGrad() {
38 >    vector<double> grad(3);
39 >    Vector3d force= getFrc();
40  
41 <  if( myConfig->isAllocated() ){
42 <
43 <    myConfig->getAtomPointers( index,
45 <                     &pos,
46 <                     &vel,
47 <                     &frc,
48 <                     &trq,
49 <                     &Amat,
50 <                     &mu,  
51 <                     &ul);
52 <  }
53 <  else{
54 <    sprintf( painCave.errMsg,
55 <             "Attempted to set Atom %d  coordinates with an unallocated "
56 <             "SimState object.\n", index );
57 <    painCave.isFatal = 1;
58 <    simError();
59 <  }
60 <  
61 <  hasCoords = true;
62 <  
63 < }
64 <
65 < void Atom::getPos( double theP[3] ){
66 <  
67 <  if( hasCoords ){
68 <    theP[0] = pos[offsetX];
69 <    theP[1] = pos[offsetY];
70 <    theP[2] = pos[offsetZ];
71 <  }
72 <  else{
73 <
74 <    sprintf( painCave.errMsg,
75 <             "Attempt to get Pos for atom %d before coords set.\n",
76 <             index );
77 <    painCave.isFatal = 1;
78 <    simError();
79 <  }
80 < }
81 <
82 < void Atom::setPos( double theP[3] ){
83 <
84 <  if( hasCoords ){
85 <    pos[offsetX] = theP[0];
86 <    pos[offsetY] = theP[1];
87 <    pos[offsetZ] = theP[2];
88 <  }
89 <  else{
90 <
91 <    sprintf( painCave.errMsg,
92 <             "Attempt to set Pos for atom %d before coords set.\n",
93 <             index );
94 <    painCave.isFatal = 1;
95 <    simError();
96 <  }
97 < }
98 <
99 < void Atom::getVel( double theV[3] ){
100 <  
101 <  if( hasCoords ){
102 <    theV[0] = vel[offsetX];
103 <    theV[1] = vel[offsetY];
104 <    theV[2] = vel[offsetZ];
105 <  }
106 <  else{
41 >    grad[0] = -force[0];
42 >    grad[1] = -force[1];
43 >    grad[2] = -force[2];
44      
45 <    sprintf( painCave.errMsg,
46 <             "Attempt to get vel for atom %d before coords set.\n",
110 <             index );
111 <    painCave.isFatal = 1;
112 <    simError();
113 <  }
45 >    return grad;
46 > }    
47  
48 < }
48 > void Atom::accept(BaseVisitor* v) {
49 >    v->visit(this);
50 > }    
51  
117 void Atom::setVel( double theV[3] ){
118  
119  if( hasCoords ){
120    vel[offsetX] = theV[0];
121    vel[offsetY] = theV[1];
122    vel[offsetZ] = theV[2];
123  }
124  else{
125    
126    sprintf( painCave.errMsg,
127             "Attempt to set vel for atom %d before coords set.\n",
128             index );
129    painCave.isFatal = 1;
130    simError();
131  }
52   }
133
134 void Atom::getFrc( double theF[3] ){
135  
136  if( hasCoords ){
137    theF[0] = frc[offsetX];
138    theF[1] = frc[offsetY];
139    theF[2] = frc[offsetZ];
140  }
141  else{
142    
143    sprintf( painCave.errMsg,
144             "Attempt to get frc for atom %d before coords set.\n",
145             index );
146    painCave.isFatal = 1;
147    simError();
148  }
149 }
150
151 void Atom::addFrc( double theF[3] ){
152  
153  if( hasCoords ){
154    frc[offsetX] += theF[0];
155    frc[offsetY] += theF[1];
156    frc[offsetZ] += theF[2];
157  }
158  else{
159    
160    sprintf( painCave.errMsg,
161             "Attempt to add frc for atom %d before coords set.\n",
162             index );
163    painCave.isFatal = 1;
164    simError();
165  }
166 }
167
168
169 void Atom::zeroForces( void ){
170  
171  if( hasCoords ){
172    frc[offsetX] = 0.0;
173    frc[offsetY] = 0.0;
174    frc[offsetZ] = 0.0;
175  }
176  else{
177    
178    sprintf( painCave.errMsg,
179             "Attempt to zero frc for atom %d before coords set.\n",
180             index );
181    painCave.isFatal = 1;
182    simError();
183  }
184 }
185

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines