ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/SimState.cpp
Revision: 1136
Committed: Tue Apr 27 16:26:44 2004 UTC (20 years, 2 months ago) by tim
File size: 3125 byte(s)
Log Message:
add center of mass of the molecule and massRation into atom class

File Contents

# User Rev Content
1 mmeineke 707 #include <iostream>
2    
3 gezelter 829 #include <stdlib.h>
4     #include <stdio.h>
5 mmeineke 670
6     #include "simError.h"
7     #include "SimState.hpp"
8    
9    
10     SimState::SimState(){
11    
12     nElements = 0;
13     arraysAllocated = false;
14    
15     pos = NULL;
16     vel = NULL;
17     frc = NULL;
18     trq = NULL;
19     Amat = NULL;
20     mu = NULL;
21     ul = NULL;
22     }
23    
24    
25     SimState::~SimState(){
26    
27     if(pos != NULL) delete[] pos;
28     if(vel != NULL) delete[] vel;
29     if(frc != NULL) delete[] frc;
30     if(trq != NULL) delete[] trq;
31     if(Amat != NULL) delete[] Amat;
32     if(mu != NULL) delete[] mu;
33     if(ul != NULL) delete[] ul;
34    
35     }
36    
37    
38     void SimState::createArrays (int the_nElements) {
39     int i, index3, index9;
40 mmeineke 707
41 mmeineke 670 if( arraysAllocated ){
42    
43     sprintf( painCave.errMsg,
44     "Someone has attempted to allocate SimState arrays before "
45     "deallocating the previous arrays.\n" );
46     painCave.isFatal = 1;
47     simError();
48     }
49    
50     nElements = the_nElements;
51    
52     pos = new double[nElements*3];
53     vel = new double[nElements*3];
54     frc = new double[nElements*3];
55     trq = new double[nElements*3];
56     Amat = new double[nElements*9];
57     mu = new double[nElements];
58     ul = new double[nElements*3];
59 tim 1136 rc = new double[nElements*3];
60     massRatio = new double[nElements];
61 mmeineke 670
62     // init directional values to zero
63    
64     for( i=0; i<nElements; i++){
65     index3 = i*3;
66     index9 = i*9;
67    
68     trq[index3+0] = 0.0;
69     trq[index3+1] = 0.0;
70     trq[index3+2] = 0.0;
71    
72     Amat[index9+0] = 1.0;
73     Amat[index9+1] = 0.0;
74     Amat[index9+2] = 0.0;
75    
76     Amat[index9+3] = 0.0;
77     Amat[index9+4] = 1.0;
78     Amat[index9+5] = 0.0;
79    
80     Amat[index9+6] = 0.0;
81     Amat[index9+7] = 0.0;
82     Amat[index9+8] = 1.0;
83    
84     mu[i] = 0.0;
85    
86     ul[index3+0] = 1.0;
87     ul[index3+1] = 0.0;
88     ul[index3+2] = 0.0;
89     }
90    
91     arraysAllocated = true;
92     }
93    
94     void SimState::destroyArrays( void ){
95    
96     if(pos != NULL) delete[] pos;
97     if(vel != NULL) delete[] vel;
98     if(frc != NULL) delete[] frc;
99     if(trq != NULL) delete[] trq;
100     if(Amat != NULL) delete[] Amat;
101     if(mu != NULL) delete[] mu;
102     if(ul != NULL) delete[] ul;
103 tim 1136 if(rc != NULL) delete[] rc;
104     if(massRatio != NULL) delete[] massRatio;
105 mmeineke 670
106     pos = NULL;
107     vel = NULL;
108     frc = NULL;
109     trq = NULL;
110     Amat = NULL;
111     mu = NULL;
112     ul = NULL;
113 tim 1136 rc = NULL;
114     massRatio = NULL;
115 mmeineke 670
116     arraysAllocated = false;
117     nElements = 0;
118     }
119    
120     void SimState::getAtomPointers( int index,
121     double** the_pos,
122     double** the_vel,
123     double** the_frc,
124     double** the_trq,
125     double** the_Amat,
126     double** the_mu,
127 tim 1136 double** the_ul,
128     double** the_rc,
129     double** the_massRatio){
130 mmeineke 670 int index3, index9;
131    
132     if( arraysAllocated ){
133    
134     index3 = index*3;
135     index9 = index*9;
136    
137     *the_pos = &(pos[index3]);
138     *the_vel = &(vel[index3]);
139     *the_frc = &(frc[index3]);
140     *the_trq = &(trq[index3]);
141     *the_Amat = &(Amat[index9]);
142     *the_mu = &(mu[index]);
143     *the_ul = &(ul[index3]);
144 tim 1136 *the_rc = &(rc[index3]);
145     *the_massRatio = &(massRatio[index]);
146 mmeineke 670 }
147     else{
148    
149     sprintf( painCave.errMsg,
150     "Atom %d attempted to access its arrays before they had been"
151     " allocated\n",
152     index );
153     painCave.isFatal = 1;
154     simError();
155     }
156     }