ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/SimState.cpp
Revision: 1452
Committed: Mon Aug 23 15:11:36 2004 UTC (19 years, 10 months ago) by tim
File size: 3031 byte(s)
Log Message:
*** empty log message ***

File Contents

# Content
1 #include <iostream>
2
3 #include <stdlib.h>
4 #include <stdio.h>
5
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
41 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 quat = new double[nElements*4];
60
61 // init directional values to zero
62
63 for( i=0; i<nElements; i++){
64 index3 = i*3;
65 index9 = i*9;
66
67 trq[index3+0] = 0.0;
68 trq[index3+1] = 0.0;
69 trq[index3+2] = 0.0;
70
71 Amat[index9+0] = 1.0;
72 Amat[index9+1] = 0.0;
73 Amat[index9+2] = 0.0;
74
75 Amat[index9+3] = 0.0;
76 Amat[index9+4] = 1.0;
77 Amat[index9+5] = 0.0;
78
79 Amat[index9+6] = 0.0;
80 Amat[index9+7] = 0.0;
81 Amat[index9+8] = 1.0;
82
83 mu[i] = 0.0;
84
85 ul[index3+0] = 1.0;
86 ul[index3+1] = 0.0;
87 ul[index3+2] = 0.0;
88
89 quat[i*4] = 1.0;
90 quat[i*4+1] = 0.0;
91 quat[i*4+2] = 0.0;
92 quat[i*4+3] = 0.0;
93
94 }
95
96 arraysAllocated = true;
97 }
98
99 void SimState::destroyArrays( void ){
100
101 if(pos != NULL) delete[] pos;
102 if(vel != NULL) delete[] vel;
103 if(frc != NULL) delete[] frc;
104 if(trq != NULL) delete[] trq;
105 if(Amat != NULL) delete[] Amat;
106 if(mu != NULL) delete[] mu;
107 if(ul != NULL) delete[] ul;
108
109 pos = NULL;
110 vel = NULL;
111 frc = NULL;
112 trq = NULL;
113 Amat = NULL;
114 mu = NULL;
115 ul = NULL;
116 quat = NULL;
117
118
119 arraysAllocated = false;
120 nElements = 0;
121 }
122
123 void SimState::getAtomPointers( int index,
124 double** the_pos,
125 double** the_vel,
126 double** the_frc,
127 double** the_trq,
128 double** the_Amat,
129 double** the_mu,
130 double** the_ul,
131 double** the_quat){
132 int index3, index9;
133
134 if( arraysAllocated ){
135
136 index3 = index*3;
137 index9 = index*9;
138
139 *the_pos = &(pos[index3]);
140 *the_vel = &(vel[index3]);
141 *the_frc = &(frc[index3]);
142 *the_trq = &(trq[index3]);
143 *the_Amat = &(Amat[index9]);
144 *the_mu = &(mu[index]);
145 *the_ul = &(ul[index3]);
146 *the_quat = &(quat[index*4]);
147 }
148 else{
149
150 sprintf( painCave.errMsg,
151 "Atom %d attempted to access its arrays before they had been"
152 " allocated\n",
153 index );
154 painCave.isFatal = 1;
155 simError();
156 }
157 }