ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/SimState.cpp
Revision: 1150
Committed: Fri May 7 21:35:05 2004 UTC (20 years, 2 months ago) by gezelter
File size: 3248 byte(s)
Log Message:
Many changes to get group-based cutoffs to work

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