ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/brains/DataStorage.cpp
(Generate patch)

Comparing:
trunk/src/brains/DataStorage.cpp (file contents), Revision 155 by tim, Tue Oct 26 22:19:22 2004 UTC vs.
branches/development/src/brains/DataStorage.cpp (file contents), Revision 1584 by gezelter, Fri Jun 17 20:16:35 2011 UTC

# Line 1 | Line 1
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.
2 > * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3   *
4 + * The University of Notre Dame grants you ("Licensee") a
5 + * non-exclusive, royalty free, license to use, modify and
6 + * redistribute this software in source and binary code form, provided
7 + * that the following conditions are met:
8 + *
9 + * 1. Redistributions of source code must retain the above copyright
10 + *    notice, this list of conditions and the following disclaimer.
11 + *
12 + * 2. Redistributions in binary form must reproduce the above copyright
13 + *    notice, this list of conditions and the following disclaimer in the
14 + *    documentation and/or other materials provided with the
15 + *    distribution.
16 + *
17 + * This software is provided "AS IS," without a warranty of any
18 + * kind. All express or implied conditions, representations and
19 + * warranties, including any implied warranty of merchantability,
20 + * fitness for a particular purpose or non-infringement, are hereby
21 + * excluded.  The University of Notre Dame and its licensors shall not
22 + * be liable for any damages suffered by licensee as a result of
23 + * using, modifying or distributing the software or its
24 + * derivatives. In no event will the University of Notre Dame or its
25 + * licensors be liable for any lost revenue, profit or data, or for
26 + * direct, indirect, special, consequential, incidental or punitive
27 + * damages, however caused and regardless of the theory of liability,
28 + * arising out of the use of or inability to use software, even if the
29 + * University of Notre Dame has been advised of the possibility of
30 + * such damages.
31 + *
32 + * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your
33 + * research, please cite the appropriate papers when you publish your
34 + * work.  Good starting points are:
35 + *                                                                      
36 + * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37 + * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 + * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
39 + * [4]  Vardeman & Gezelter, in progress (2009).                        
40   */
41  
42 < /**
43 <  * @file DataStorage.cpp
44 <  * @author tlin
45 <  * @date 10/26/2004
46 <  * @time 11:56am
47 <  * @version 1.0
48 <  */
42 > /**
43 > * @file DataStorage.cpp
44 > * @author tlin
45 > * @date 10/26/2004
46 > * @time 11:56am
47 > * @version 1.0
48 > */
49  
50   #include "brains/DataStorage.hpp"
51  
52 + namespace OpenMD {
53  
54 < DataStorage::DataStorage() : size_(0), storageLayout_(0){
54 >  DataStorage::DataStorage() : size_(0), storageLayout_(0){
55  
56 < }
56 >  }
57  
58 < DataStorage::DataStorage(int size, int storageLayout) : size_(size){
58 >  DataStorage::DataStorage(int size, int storageLayout) : size_(size){
59      setStorageLayout(storageLayout);
60      resize(size);
61 < }
61 >  }
62  
63 < int DataStorage::getSize() {
63 >  int DataStorage::getSize() {
64  
65      if (storageLayout_ & dslPosition && position.size() != size_) {
66 <        //error
67 <        std::cerr << "size does not match"<< std::endl;
66 >      //error
67 >      std::cerr << "size does not match"<< std::endl;
68      }
69  
70      if (storageLayout_ & dslVelocity && velocity.size() != size_) {
71 <        //error
72 <        std::cerr << "size does not match"<< std::endl;        
71 >      //error
72 >      std::cerr << "size does not match"<< std::endl;        
73      }
74  
75      if (storageLayout_ & dslAmat && aMat.size() != size_) {
76 <        //error
77 <        std::cerr << "size does not match"<< std::endl;        
76 >      //error
77 >      std::cerr << "size does not match"<< std::endl;        
78      }
79  
80      if (storageLayout_ & dslAngularMomentum && angularMomentum.size() != size_) {
81 <        //error
82 <        std::cerr << "size does not match"<< std::endl;        
81 >      //error
82 >      std::cerr << "size does not match"<< std::endl;        
83      }
84  
85 <    if (storageLayout_ & dslUnitVector && unitVector.size() != size_) {
86 <        //error
87 <        std::cerr << "size does not match"<< std::endl;        
85 >    if (storageLayout_ & dslElectroFrame && electroFrame.size() != size_) {
86 >      //error
87 >      std::cerr << "size does not match"<< std::endl;        
88      }
89  
90      if (storageLayout_ & dslZAngle && zAngle.size() != size_) {
91 <        //error
92 <        std::cerr << "size does not match"<< std::endl;        
91 >      //error
92 >      std::cerr << "size does not match"<< std::endl;        
93      }
94  
95      if (storageLayout_ & dslForce && force.size() != size_) {
96 <        //error
97 <        std::cerr << "size does not match"<< std::endl;        
96 >      //error
97 >      std::cerr << "size does not match"<< std::endl;        
98      }
99  
100      if (storageLayout_ & dslTorque && torque.size() != size_) {
101 <        //error
102 <        std::cerr << "size does not match"<< std::endl;        
101 >      //error
102 >      std::cerr << "size does not match"<< std::endl;        
103      }
104  
105 +    if (storageLayout_ & dslParticlePot && particlePot.size() != size_) {
106 +      //error
107 +      std::cerr << "size does not match"<< std::endl;        
108 +    }
109 +
110 +    if (storageLayout_ & dslDensity && density.size() != size_) {
111 +      //error
112 +      std::cerr << "size does not match"<< std::endl;        
113 +    }
114 +
115 +    if (storageLayout_ & dslFunctional && functional.size() != size_) {
116 +      //error
117 +      std::cerr << "size does not match"<< std::endl;        
118 +    }
119 +
120 +    if (storageLayout_ & dslFunctionalDerivative && functionalDerivative.size() != size_) {
121 +      //error
122 +      std::cerr << "size does not match"<< std::endl;        
123 +    }
124 +
125 +    if (storageLayout_ & dslElectricField && electricField.size() != size_) {
126 +      //error
127 +      std::cerr << "size does not match"<< std::endl;        
128 +    }
129 +
130 +    if (storageLayout_ & dslSkippedCharge && skippedCharge.size() != size_) {
131 +      //error
132 +      std::cerr << "size does not match"<< std::endl;        
133 +    }
134 +    
135      return size_;
136  
137 < }
137 >  }
138  
139 < void DataStorage::resize(int newSize) {
139 >  void DataStorage::resize(int newSize) {
140  
141      if (storageLayout_ & dslPosition) {
142 <        internalResize(position, newSize);
142 >      internalResize(position, newSize);
143      }
144  
145      if (storageLayout_ & dslVelocity) {
146 <        internalResize(velocity, newSize);
146 >      internalResize(velocity, newSize);
147      }
148  
149      if (storageLayout_ & dslAmat) {
150 <        internalResize(aMat, newSize);
150 >      internalResize(aMat, newSize);
151      }
152  
153      if (storageLayout_ & dslAngularMomentum) {
154 <        internalResize(angularMomentum, newSize);
154 >      internalResize(angularMomentum, newSize);
155      }
156  
157 <    if (storageLayout_ & dslUnitVector) {
158 <        internalResize(unitVector, newSize);
157 >    if (storageLayout_ & dslElectroFrame) {
158 >      internalResize(electroFrame, newSize);
159      }
160      
161      if (storageLayout_ & dslZAngle) {
162 <        internalResize(zAngle, newSize);
162 >      internalResize(zAngle, newSize);
163      }
164  
165      if (storageLayout_ & dslForce) {
166 <        internalResize(force, newSize);
166 >      internalResize(force, newSize);
167      }
168  
169      if (storageLayout_ & dslTorque) {
170 <        internalResize(torque, newSize);
170 >      internalResize(torque, newSize);
171      }
172  
173 +    if (storageLayout_ & dslParticlePot) {
174 +      internalResize(particlePot, newSize);
175 +    }
176 +
177 +    if (storageLayout_ & dslDensity) {
178 +      internalResize(density, newSize);
179 +    }
180 +
181 +    if (storageLayout_ & dslFunctional) {
182 +      internalResize(functional, newSize);
183 +    }
184 +
185 +    if (storageLayout_ & dslFunctionalDerivative) {
186 +      internalResize(functionalDerivative, newSize);
187 +    }
188 +
189 +    if (storageLayout_ & dslElectricField) {
190 +      internalResize(electricField, newSize);
191 +    }
192 +
193 +    if (storageLayout_ & dslSkippedCharge) {
194 +      internalResize(skippedCharge, newSize);
195 +    }
196 +
197      size_ = newSize;
198 < }
198 >  }
199  
200 < void DataStorage::reserve(int size) {
200 >  void DataStorage::reserve(int size) {
201      if (storageLayout_ & dslPosition) {
202 <        position.reserve(size);
202 >      position.reserve(size);
203      }
204  
205      if (storageLayout_ & dslVelocity) {
206 <        velocity.reserve(size);
206 >      velocity.reserve(size);
207      }
208  
209      if (storageLayout_ & dslAmat) {
210 <        aMat.reserve(size);
210 >      aMat.reserve(size);
211      }
212  
213      if (storageLayout_ & dslAngularMomentum) {
214 <        angularMomentum.reserve(size);
214 >      angularMomentum.reserve(size);
215      }
216  
217 <    if (storageLayout_ & dslUnitVector) {
218 <        unitVector.reserve(size);
217 >    if (storageLayout_ & dslElectroFrame) {
218 >      electroFrame.reserve(size);
219      }
220      
221      if (storageLayout_ & dslZAngle) {
222 <        zAngle.reserve(size);
222 >      zAngle.reserve(size);
223      }
224  
225      if (storageLayout_ & dslForce) {
226 <        force.reserve(size);
226 >      force.reserve(size);
227      }
228  
229      if (storageLayout_ & dslTorque) {
230 <        torque.reserve(size);
230 >      torque.reserve(size);
231      }
232 +    
233 +    if (storageLayout_ & dslParticlePot) {
234 +      particlePot.reserve(size);
235 +    }
236  
237 < }
237 >    if (storageLayout_ & dslDensity) {
238 >      density.reserve(size);
239 >    }
240  
241 < void DataStorage::copy(int source, int num, int target) {
241 >    if (storageLayout_ & dslFunctional) {
242 >      functional.reserve(size);
243 >    }
244 >
245 >    if (storageLayout_ & dslFunctionalDerivative) {
246 >      functionalDerivative.reserve(size);
247 >    }
248 >
249 >    if (storageLayout_ & dslElectricField) {
250 >      electricField.reserve(size);
251 >    }
252 >
253 >    if (storageLayout_ & dslSkippedCharge) {
254 >      skippedCharge.reserve(size);
255 >    }
256 >
257 >  }
258 >
259 >  void DataStorage::copy(int source, int num, int target) {
260      if (num + target > size_ ) {
261 <        //error
261 >      //error
262      }
263      
264      if (storageLayout_ & dslPosition) {
265 <        interalCopy(position, source, num, target);
265 >      internalCopy(position, source, num, target);
266      }
267  
268      if (storageLayout_ & dslVelocity) {
269 <        interalCopy(velocity, source, num, target);
270 <  }
269 >      internalCopy(velocity, source, num, target);
270 >    }
271  
272      if (storageLayout_ & dslAmat) {
273 <        interalCopy(aMat, source, num, target);
274 <   }
273 >      internalCopy(aMat, source, num, target);
274 >    }
275  
276      if (storageLayout_ & dslAngularMomentum) {
277 <        interalCopy(angularMomentum, source, num, target);
277 >      internalCopy(angularMomentum, source, num, target);
278      }
279  
280 <    if (storageLayout_ & dslUnitVector) {
281 <        interalCopy(unitVector, source, num, target);
280 >    if (storageLayout_ & dslElectroFrame) {
281 >      internalCopy(electroFrame, source, num, target);
282      }
283      
284      if (storageLayout_ & dslZAngle) {
285 <        interalCopy(zAngle, source, num, target);
285 >      internalCopy(zAngle, source, num, target);
286      }
287  
288      if (storageLayout_ & dslForce) {
289 <        interalCopy(force, source, num, target);
289 >      internalCopy(force, source, num, target);
290      }
291  
292      if (storageLayout_ & dslTorque) {
293 <        interalCopy(torque, source, num, target);
293 >      internalCopy(torque, source, num, target);
294      }
200    
295  
296 < }
297 <
298 < int DataStorage::getStorageLayout() {
205 <    return storageLayout_;
206 < }
296 >    if (storageLayout_ & dslParticlePot) {
297 >      internalCopy(particlePot, source, num, target);
298 >    }
299  
300 < void DataStorage::setStorageLayout(int layout) {
300 >    if (storageLayout_ & dslDensity) {
301 >      internalCopy(density, source, num, target);
302 >    }
303 >
304 >    if (storageLayout_ & dslFunctional) {
305 >      internalCopy(functional, source, num, target);
306 >    }
307 >
308 >    if (storageLayout_ & dslFunctionalDerivative) {
309 >      internalCopy(functionalDerivative, source, num, target);
310 >    }
311 >
312 >    if (storageLayout_ & dslElectricField) {
313 >      internalCopy(electricField, source, num, target);
314 >    }
315 >
316 >    if (storageLayout_ & dslSkippedCharge) {
317 >      internalCopy(skippedCharge, source, num, target);
318 >    }
319 >  }
320 >
321 >  int DataStorage::getStorageLayout() {
322 >    return storageLayout_;
323 >  }
324 >
325 >  void DataStorage::setStorageLayout(int layout) {
326      storageLayout_ = layout;
327      resize(size_);
328 < }
328 >  }
329  
330 < double* DataStorage::getArrayPointer(int whichArray) {
330 >  RealType* DataStorage::getArrayPointer(int whichArray) {
331  
332      switch (whichArray) {
333 <        case dslPosition:
334 <            return internalGetArrayPointer(torque);
335 <            break;
333 >    case dslPosition:
334 >      return internalGetArrayPointer(position);
335 >      break;
336              
337 <        case dslVelocity:
338 <            return internalGetArrayPointer(velocity);
339 <            break;
337 >    case dslVelocity:
338 >      return internalGetArrayPointer(velocity);
339 >      break;
340              
341 <        case dslAmat:
342 <            return internalGetArrayPointer(aMat);
343 <            break;            
341 >    case dslAmat:
342 >      return internalGetArrayPointer(aMat);
343 >      break;            
344              
345 <        case dslAngularMomentum:
346 <            return internalGetArrayPointer(angularMomentum);
347 <            break;
345 >    case dslAngularMomentum:
346 >      return internalGetArrayPointer(angularMomentum);
347 >      break;
348              
349 <        case dslUnitVector:
350 <            return internalGetArrayPointer(unitVector);
351 <            break;
349 >    case dslElectroFrame:
350 >      return internalGetArrayPointer(electroFrame);
351 >      break;
352              
353 <        case dslZAngle:
354 <            return internalGetArrayPointer(zAngle);
355 <            break;
353 >    case dslZAngle:
354 >      return internalGetArrayPointer(zAngle);
355 >      break;
356  
357 <        case dslForce:
358 <            return internalGetArrayPointer(force);
359 <            break;            
357 >    case dslForce:
358 >      return internalGetArrayPointer(force);
359 >      break;            
360  
361 <        case dslTorque:
362 <            return internalGetArrayPointer(torque);
363 <            break;  
247 <            
248 <        default:
249 <            //error message
250 <            return NULL;
361 >    case dslTorque:
362 >      return internalGetArrayPointer(torque);
363 >      break;
364  
365 +    case dslParticlePot:
366 +      return internalGetArrayPointer(particlePot);
367 +      break;
368 +
369 +    case dslDensity:
370 +      return internalGetArrayPointer(density);
371 +      break;
372 +
373 +    case dslFunctional:
374 +      return internalGetArrayPointer(functional);
375 +      break;
376 +
377 +    case dslFunctionalDerivative:
378 +      return internalGetArrayPointer(functionalDerivative);
379 +      break;
380 +
381 +    case dslElectricField:
382 +      return internalGetArrayPointer(electricField);
383 +      break;
384 +
385 +    case dslSkippedCharge:
386 +      return internalGetArrayPointer(skippedCharge);
387 +      break;
388 +          
389 +    default:
390 +      //error message
391 +      return NULL;
392 +
393      }
394 < }    
394 >  }    
395  
396 < double* DataStorage::internalGetArrayPointer(std::vector<Vector3d>& v) {
396 >  RealType* DataStorage::internalGetArrayPointer(std::vector<Vector3d>& v) {
397      if (v.size() == 0) {
398 <        return NULL;
398 >      return NULL;
399      } else {
400 <        return v[0].getArrayPointer();
400 >      return v[0].getArrayPointer();
401      }
402 < }
402 >  }
403  
404 < double* DataStorage::internalGetArrayPointer(std::vector<RotMat3x3d>& v) {
404 >  RealType* DataStorage::internalGetArrayPointer(std::vector<RotMat3x3d>& v) {
405      if (v.size() == 0) {
406 <        return NULL;
406 >      return NULL;
407      } else {
408 <        return v[0].getArrayPointer();
408 >      return v[0].getArrayPointer();
409      }
410  
411 < }
411 >  }
412  
413 < double* DataStorage::internalGetArrayPointer(std::vector<double>& v) {
413 >  RealType* DataStorage::internalGetArrayPointer(std::vector<RealType>& v) {
414      if (v.size() == 0) {
415 <        return NULL;
415 >      return NULL;
416      } else {
417 <        return &(v[0]);
417 >      return &(v[0]);
418      }
419  
420 < }    
420 >  }    
421  
422 < template<typename T>
423 < void DataStorage::internalResize(std::vector<T>& v, int newSize){
422 >  template<typename T>
423 >  void DataStorage::internalResize(std::vector<T>& v, int newSize){
424      int oldSize = v.size();
425  
426      if (oldSize == newSize) {
427 <        return;
427 >      return;
428      } else if (oldSize < newSize) {
429 <        v.insert(v.end(), newSize-oldSize, T());
429 >      v.insert(v.end(), newSize-oldSize, T());
430      } else {
431 <        typename std::vector<T>::iterator i;
432 <        i = v.begin();
433 <        std::advance(i, newSize);        
434 <        v.erase(i, v.end());
431 >      typename std::vector<T>::iterator i;
432 >      i = v.begin();
433 >      std::advance(i, newSize);        
434 >      v.erase(i, v.end());
435      }
436 < }
436 >  }
437  
438 < template<typename T>
439 < void DataStorage::interalCopy(std::vector<T>& v, int source,  int num, int target) {
438 >  template<typename T>
439 >  void DataStorage::internalCopy(std::vector<T>& v, int source,  int num, int target) {
440      typename std::vector<T>::iterator first;
441      typename std::vector<T>::iterator last;
442      typename std::vector<T>::iterator result;
# Line 310 | Line 451 | void DataStorage::interalCopy(std::vector<T>& v, int s
451      std::advance(result, target );
452  
453      std::copy(first, last, result);
454 +  }
455 +
456 +  int DataStorage::getBytesPerStuntDouble(int layout) {
457 +    int bytes = 0;
458 +    if (layout & dslPosition) {
459 +      bytes += sizeof(Vector3d);
460 +    }
461 +    if (layout & dslVelocity) {
462 +      bytes += sizeof(Vector3d);
463 +    }
464 +    if (layout & dslAmat) {
465 +      bytes += sizeof(RotMat3x3d);    
466 +    }
467 +    if (layout & dslAngularMomentum) {
468 +      bytes += sizeof(Vector3d);
469 +    }
470 +    if (layout & dslElectroFrame) {
471 +      bytes += sizeof(Mat3x3d);
472 +    }
473 +    if (layout & dslZAngle) {
474 +      bytes += sizeof(RealType);
475 +    }
476 +    if (layout & dslForce) {
477 +      bytes += sizeof(Vector3d);
478 +    }
479 +    if (layout & dslTorque) {
480 +      bytes += sizeof(Vector3d);
481 +    }
482 +    if (layout & dslParticlePot) {
483 +      bytes += sizeof(RealType);
484 +    }
485 +    if (layout & dslDensity) {
486 +      bytes += sizeof(RealType);
487 +    }
488 +    if (layout & dslFunctional) {
489 +      bytes += sizeof(RealType);
490 +    }
491 +    if (layout & dslFunctionalDerivative) {
492 +      bytes += sizeof(RealType);
493 +    }
494 +    if (layout & dslElectricField) {
495 +      bytes += sizeof(Vector3d);
496 +    }
497 +    if (layout & dslSkippedCharge) {
498 +      bytes += sizeof(RealType);
499 +    }
500 +
501 +    return bytes;
502 +  }
503 +
504   }

Comparing:
trunk/src/brains/DataStorage.cpp (property svn:keywords), Revision 155 by tim, Tue Oct 26 22:19:22 2004 UTC vs.
branches/development/src/brains/DataStorage.cpp (property svn:keywords), Revision 1584 by gezelter, Fri Jun 17 20:16:35 2011 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines