BrookVelocityCenterOfMassRemoval.cpp 18.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* -------------------------------------------------------------------------- *
 *                                   OpenMM                                   *
 * -------------------------------------------------------------------------- *
 * This is part of the OpenMM molecular simulation toolkit originating from   *
 * Simbios, the NIH National Center for Physics-Based Simulation of           *
 * Biological Structures at Stanford, funded under the NIH Roadmap for        *
 * Medical Research, grant U54 GM072970. See https://simtk.org.               *
 *                                                                            *
 * Portions copyright (c) 2008 Stanford University and the Authors.           *
 * Authors: Mark Friedrichs                                                   *
 * Contributors:                                                              *
 *                                                                            *
 * Permission is hereby granted, free of charge, to any person obtaining a    *
 * copy of this software and associated documentation files (the "Software"), *
 * to deal in the Software without restriction, including without limitation  *
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
 * and/or sell copies of the Software, and to permit persons to whom the      *
 * Software is furnished to do so, subject to the following conditions:       *
 *                                                                            *
 * The above copyright notice and this permission notice shall be included in *
 * all copies or substantial portions of the Software.                        *
 *                                                                            *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
 * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
 * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
 * -------------------------------------------------------------------------- */

#include <sstream>
#include "BrookVelocityCenterOfMassRemoval.h"
#include "BrookPlatform.h"
#include "OpenMMException.h"
#include "BrookStreamImpl.h"
#include "gpu/kcom.h"

using namespace OpenMM;
using namespace std;

/** 
 *
 * Constructor
 * 
 */

BrookVelocityCenterOfMassRemoval::BrookVelocityCenterOfMassRemoval( ){

// ---------------------------------------------------------------------------------------

   //static const std::string methodName      = "BrookVelocityCenterOfMassRemoval::BrookVelocityCenterOfMassRemoval";

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
54
   BrookOpenMMFloat zero                    = static_cast<BrookOpenMMFloat>( 0.0 );
55
56
57

// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
58
   _numberOfParticles           = -1;
59
60
61

   // mark stream dimension variables as unset

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
62
63
64
   _particleStreamWidth         = -1;
   _particleStreamHeight        = -1;
   _particleStreamSize          = -1;
65

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
66
   _totalInverseMass            = zero;
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

   for( int ii = 0; ii < LastStreamIndex; ii++ ){
      _streams[ii]   = NULL;
   }

}   
 
/** 
 * Destructor
 * 
 */

BrookVelocityCenterOfMassRemoval::~BrookVelocityCenterOfMassRemoval( ){

// ---------------------------------------------------------------------------------------

   //static const std::string methodName      = "BrookVelocityCenterOfMassRemoval::~BrookVelocityCenterOfMassRemoval";

// ---------------------------------------------------------------------------------------

   for( int ii = 0; ii < LastStreamIndex; ii++ ){
      delete _streams[ii];
   }

}

/** 
 * Get inverse of total mass
 * 
 * @return  inverse of total mass
 *
 */

BrookOpenMMFloat BrookVelocityCenterOfMassRemoval::getTotalInverseMass( void ) const {
   return _totalInverseMass;
}

/** 
 * Get inverse mass stream 
 *
 * @return  inverse mass stream
 *
 */

BrookFloatStreamInternal* BrookVelocityCenterOfMassRemoval::getMassStream( void ) const {
   return _streams[MassStream];
}

/** 
 * Get work stream 
 *
 * @return  work stream
 *
 */

BrookFloatStreamInternal* BrookVelocityCenterOfMassRemoval::getWorkStream( void ) const {
   return _streams[WorkStream];
}

/** 
 * Get linear momentum stream
 *
 * @return   linear momentum stream
 *
 */

BrookFloatStreamInternal* BrookVelocityCenterOfMassRemoval::getLinearMomentumStream( void ) const {
   return _streams[LinearMomentumStream];
}

137
138
139
140
141
142
143
144
145
146
/**
 * Get velocity-COM
 *
 * @param velocities velocities
 * @param  velocityCom                 output velocity com
 *
 * @return DefaultReturnValue
 *
 */
   
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
147
int BrookVelocityCenterOfMassRemoval::getVelocityCenterOfMass( BrookStreamImpl& vStream, BrookOpenMMFloat velocityCom[3], BrookOpenMMFloat* ke ){
148
149
150

   // ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
151
   // static const std::string methodName  = "\nBrookVelocityCenterOfMassRemoval::getVelocityCenterOfMass";
152

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
153
   BrookOpenMMFloat zero    = static_cast<BrookOpenMMFloat>( 0.0 );
154
155
156
157
158
159

   // ---------------------------------------------------------------------------------------

   // calculate linear momentum via reduction
   // subtract it (/totalMass) from velocities

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
160
   BrookStreamInternal* velocityStream  = dynamic_cast<BrookStreamInternal*> (vStream.getBrookStreamInternal());
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
161
   *ke                                  = zero;
162
163

   void* velV                           = velocityStream->getData( 1 );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
164
   const float* vArray                  = static_cast<float*>( velV );
165

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
166
   void* massV                          = getMassStream()->getData( 1 );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
167
   const float* mArray                  = static_cast<float*>( massV );
168

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
169
   int numberOfParticles                = getNumberOfParticles();
170
171
172
173
   int index                            = 0;

   velocityCom[0] = velocityCom[1] = velocityCom[2] = zero;

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
174
   for( int ii = 0; ii < numberOfParticles; ii++, index += 3 ){
175
176
177
      velocityCom[0] += mArray[ii]*vArray[index];
      velocityCom[1] += mArray[ii]*vArray[index+1];
      velocityCom[2] += mArray[ii]*vArray[index+2];
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
178
                 *ke += mArray[ii]*( vArray[index]*vArray[index] + vArray[index+1]*vArray[index+1] + vArray[index+2]*vArray[index+2] );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
179
if( 0 && ii < 3 ){
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
180
fprintf( stderr, "getVelocityCenterOfMass %5d %5d m=%15.6e v[%15.6e %15.6e %15.6e ] %d\n", ii, index, mArray[ii], vArray[index], vArray[index+1], vArray[index+2], numberOfParticles );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
181
}
182
183
   }

184
185
186
187
   return DefaultReturnValue;
}

/** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
188
 * Get Particle stream size
189
 *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
190
 * @return  Particle stream size
191
192
193
 *
 */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
194
195
int BrookVelocityCenterOfMassRemoval::getComParticleStreamSize( void ) const {
   return _particleStreamSize;
196
197
198
}

/** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
199
 * Get particle stream width
200
 *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
201
 * @return  particle stream width
202
203
204
 *
 */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
205
206
int BrookVelocityCenterOfMassRemoval::getComParticleStreamWidth( void ) const {
   return _particleStreamWidth;
207
208
209
}

/** 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
210
 * Get particle stream height
211
 *
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
212
 * @return particle stream height
213
214
 */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
215
216
int BrookVelocityCenterOfMassRemoval::getComParticleStreamHeight( void ) const {
   return _particleStreamHeight;
217
218
219
220
221
}

/** 
 * Initialize stream dimensions
 * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
222
 * @param numberOfParticles             number of particles
223
224
225
226
227
228
 * @param platform                  platform
 *      
 * @return ErrorReturnValue if error, else DefaultReturnValue
 *
 */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
229
int BrookVelocityCenterOfMassRemoval::_initializeStreamSizes( int numberOfParticles, const Platform& platform ){
230
231
232
233
234
235
236

// ---------------------------------------------------------------------------------------

   //static const std::string methodName      = "BrookVelocityCenterOfMassRemoval::_initializeStreamSizes";

// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
237
238
239
   _particleStreamSize     = getParticleStreamSize( platform );
   _particleStreamWidth    = getParticleStreamWidth( platform );
   _particleStreamHeight   = getParticleStreamHeight( platform );
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258

   return DefaultReturnValue;
}

/** 
 * Initialize streams
 * 
 * @param platform                  platform
 *
 * @return ErrorReturnValue if error, else DefaultReturnValue
 *
 */

int BrookVelocityCenterOfMassRemoval::_initializeStreams( const Platform& platform ){

// ---------------------------------------------------------------------------------------

   //static const std::string methodName      = "BrookVelocityCenterOfMassRemoval::_initializeStreams";

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
259
   BrookOpenMMFloat dangleValue     = static_cast<BrookOpenMMFloat>( 0.0 );
260
261
262

// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
263
264
   int particleStreamSize           = getComParticleStreamSize();
   int particleStreamWidth          = getComParticleStreamWidth();
265
266

    _streams[WorkStream]            = new BrookFloatStreamInternal( BrookCommon::BrookVelocityCenterOfMassRemovalWorkStream,
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
267
                                                                    particleStreamSize, particleStreamWidth,
268
                                                                    BrookStreamInternal::Float3, dangleValue );
269
270
271


    _streams[MassStream]            = new BrookFloatStreamInternal( BrookCommon::BrookVelocityCenterOfMassRemovalMassStream,
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
272
                                                                    particleStreamSize, particleStreamWidth,
273
274
275
276
                                                                    BrookStreamInternal::Float, dangleValue );


    _streams[LinearMomentumStream]  = new BrookFloatStreamInternal( "LinearMomentumStream",
277
                                                                    1, 1, BrookStreamInternal::Float3, dangleValue );
278
279
280
281
282
283


   return DefaultReturnValue;
}

/** 
284
 * Set masses & _totalInverseMass 
285
 * 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
286
 * @param masses             particle masses
287
288
289
290
291
292
293
294
295
 *
 */

int BrookVelocityCenterOfMassRemoval::_setMasses( const std::vector<double>& masses ){

// ---------------------------------------------------------------------------------------

   static const std::string methodName      = "BrookVelocityCenterOfMassRemoval::_setMasses";

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
296
297
   BrookOpenMMFloat zero                    = static_cast<BrookOpenMMFloat>( 0.0 );
   BrookOpenMMFloat one                     = static_cast<BrookOpenMMFloat>( 1.0 );
298
299
300

// ---------------------------------------------------------------------------------------

301
302
   // check that masses vector is not larger than expected

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
303
   if( (int) masses.size() > getComParticleStreamSize() ){
304
      std::stringstream message;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
305
      message << methodName << " mass array size=" << masses.size() << " is larger than stream size=" << getComParticleStreamSize();
306
307
308
      throw OpenMMException( message.str() );
   }

309
   // setup masses
310

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
311
312
   BrookOpenMMFloat* localMasses = new BrookOpenMMFloat[getComParticleStreamSize()];
   memset( localMasses, 0, sizeof( BrookOpenMMFloat )*getComParticleStreamSize() );
313
314

   int index          = 0;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
315
   _totalInverseMass  = zero;
316
317
318
   for( std::vector<double>::const_iterator ii = masses.begin(); ii != masses.end(); ii++, index++ ){
      if( *ii != 0.0 ){
         BrookOpenMMFloat value    = static_cast<BrookOpenMMFloat>(*ii);
319
         localMasses[index]        = value;
320
321
322
         _totalInverseMass        += value;
      }
   }
323
324
325

   // 1/Sum[masses]

326
327
328
329
   if( _totalInverseMass > zero ){
      _totalInverseMass = one/_totalInverseMass;
   }

330
331
332
   // write masses to board

   _streams[MassStream]->loadFromArray( localMasses );
333

334
   delete[] localMasses;
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359

   return DefaultReturnValue;
}   
 
/*  
 * Setup of StochasticDynamics parameters
 *
 * @param masses                masses
 * @param platform              Brook platform
 *
 * @return nonzero value if error
 *
 * */
    
int BrookVelocityCenterOfMassRemoval::setup( const std::vector<double>& masses, const Platform& platform ){
    
// ---------------------------------------------------------------------------------------

   static const std::string methodName      = "BrookVelocityCenterOfMassRemoval::setup";

// ---------------------------------------------------------------------------------------

   const BrookPlatform brookPlatform        = dynamic_cast<const BrookPlatform&> (platform);
   setLog( brookPlatform.getLog() );

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
360
   int numberOfParticles                    = (int) masses.size();
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
361
   setNumberOfParticles( numberOfParticles );
362
363
364

   // set stream sizes and then create streams

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
365
   _initializeStreamSizes( numberOfParticles, platform );
366
367
368
369
   _initializeStreams( platform );

   _setMasses( masses );

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
370
371
372
   if( 1 && getLog() ){
      FILE* log             = getLog();
      std::string contents  = getContentsString( 0 );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
373
374
      (void) fprintf( log, "%s contents:\n%s\n", methodName.c_str(), contents.c_str() );
      (void) fflush( log );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
375
376
   }
   
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
   return DefaultReturnValue;
}

/* 
 * Get contents of object
 *
 * @param level   level of dump
 *
 * @return string containing contents
 *
 * */

std::string BrookVelocityCenterOfMassRemoval::getContentsString( int level ) const {

// ---------------------------------------------------------------------------------------

   static const std::string methodName      = "BrookVelocityCenterOfMassRemoval::getContentsString";

   static const unsigned int MAX_LINE_CHARS = 256;
   char value[MAX_LINE_CHARS];
   static const char* Set                   = "Set";
   static const char* NotSet                = "Not set";

// ---------------------------------------------------------------------------------------

   std::stringstream message;
   std::string tab   = "   ";

#ifdef WIN32
#define LOCAL_SPRINTF(a,b,c) sprintf_s( (a), MAX_LINE_CHARS, (b), (c) );   
#else
#define LOCAL_SPRINTF(a,b,c) sprintf( (a), (b), (c) );   
#endif

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
411
412
   (void) LOCAL_SPRINTF( value, "%d", getNumberOfParticles() );
   message << _getLine( tab, "Number of particles:", value ); 
413

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
414
415
   (void) LOCAL_SPRINTF( value, "%d", getComParticleStreamWidth() );
   message << _getLine( tab, "Particle stream width:", value ); 
416

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
417
418
   (void) LOCAL_SPRINTF( value, "%d", getComParticleStreamHeight() );
   message << _getLine( tab, "Particle stream height:", value ); 
419

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
420
421
   (void) LOCAL_SPRINTF( value, "%d", getComParticleStreamSize() );
   message << _getLine( tab, "Particle stream size:", value ); 
422

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
423
   (void) LOCAL_SPRINTF( value, "%.5e", getTotalInverseMass() );
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
   message << _getLine( tab, "TotalInverseMass:", value ); 

   message << _getLine( tab, "Log:",                  (getLog()                  ? Set : NotSet) ); 

   message << _getLine( tab, "Mass:",                 (getMassStream()           ? Set : NotSet) ); 
   message << _getLine( tab, "Work:",                 (getWorkStream()           ? Set : NotSet) ); 
   message << _getLine( tab, "LinearMomentum:",       (getLinearMomentumStream() ? Set : NotSet) ); 
 
   for( int ii = 0; ii < LastStreamIndex; ii++ ){
      message << std::endl;
      if( _streams[ii] ){
         message << _streams[ii]->getContentsString( );
      }
   }

#undef LOCAL_SPRINTF

   return message.str();
}
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
443
444
445
446
447
448
449
450
451
452
453
454
455
456
/**
 * Remove velocity-COM
 *
 * @param velocities velocities
 *
 * @return DefaultReturnValue
 *
 */
   
int BrookVelocityCenterOfMassRemoval::removeVelocityCenterOfMass( BrookStreamImpl& velocityStream ){

   // ---------------------------------------------------------------------------------------

   static const std::string methodName  = "BrookVelocityCenterOfMassRemoval::removeVelocityCenterOfMass";
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
457
   static       int printOn             = 0;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
458
   static const double boltz            = 8.3145112119486e-03;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
459
   FILE* log;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
460
   BrookOpenMMFloat ke;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
461
462
463

   // ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
464
465
466
467
468
469
470
471
472
473
474
//setLog( stderr );
   if( printOn && getLog() ){
      log = getLog();
   } else {
      printOn = 0;
   }

   // diagnostics

   if( printOn ){

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
475
      BrookOpenMMFloat com[3];
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
476
      getVelocityCenterOfMass( velocityStream, com, &ke );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
477
478
479

      BrookOpenMMFloat denomiator = static_cast<float>( 3*getNumberOfParticles())*static_cast<float>( boltz );
      (void) fprintf( log, "%s Pre removal com: [%12.5e %12.5e %12.5e] ke=%.3f ~T=%.3f\n", 
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
480
481
                      methodName.c_str(), com[0], com[1], com[2], ke, ke/denomiator );
      BrookStreamInternal* outputVelocityStream = dynamic_cast<BrookStreamInternal*> (velocityStream.getBrookStreamInternal());
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
482
483

      void* velV                       = outputVelocityStream->getData( 1 );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
484
      const float* vArray              = static_cast<float*>( velV );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
485
486

      int index                        = 0;
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
487
      if( printOn > 1 ){
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
488
         for( int ii = 0; ii < getNumberOfParticles(); ii++, index += 3 ){
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
489
            (void) fprintf( log, "V %d [%12.5e %12.5e %12.5e]\n", ii, vArray[index], vArray[index+1], vArray[index+2] );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
490
491
         }
      }
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
492
      (void) fflush( log );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
493
494
495
496
497
498
499
500
501
502
   }

   // calculate linear momentum via reduction
   // subtract it (/totalMass) from velocities

   kCalculateLinearMomentum( getMassStream()->getBrookStream(), velocityStream.getBrookStream(), getWorkStream()->getBrookStream() );
   kSumLinearMomentum( (float) getComParticleStreamWidth(), (float) getNumberOfParticles(), (float) getTotalInverseMass(),
                        getWorkStream()->getBrookStream(), getLinearMomentumStream()->getBrookStream() );
   kRemoveLinearMomentum( getLinearMomentumStream()->getBrookStream(), velocityStream.getBrookStream(), velocityStream.getBrookStream() );

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
503
504
505
506
   // diagnostics

   if( printOn ){

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
507
      BrookOpenMMFloat com[3];
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
508

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
509
      getVelocityCenterOfMass( velocityStream, com, &ke );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
510
511
512
      BrookOpenMMFloat denomiator = static_cast<float>( 3*getNumberOfParticles() )*static_cast<float>( boltz );

      (void) fprintf( log, "%s strW=%d iatm=%d invMass=%.4e\n   Post removal com: [%12.5e %12.5e %12.5e]  ke=%.3f ~T=%.3f\n",
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
513
514
515
                      methodName.c_str(),
                      getComParticleStreamWidth(), getNumberOfParticles(), getTotalInverseMass(),  com[0], com[1], com[2],
                      ke, ke/denomiator );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
516
517

      void* linMoV = getLinearMomentumStream()->getData( 1 );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
518
519
      float* linMo = static_cast<float*>( linMoV );
      (void) fprintf( log, "   LM [%12.5e %12.5e %12.5e]\n", linMo[0], linMo[1], linMo[2] );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
520

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
521
      BrookStreamInternal* outputVelocityStream = dynamic_cast<BrookStreamInternal*> (velocityStream.getBrookStreamInternal());
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
522

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
523
524
      void* velV                      = outputVelocityStream->getData( 1 );
      const float* vArray             = static_cast<float*>( velV );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
525
526

      void* w1                        = getWorkStream()->getData( 1 );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
527
      const float* w2                 = static_cast<float*>( w1 );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
528

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
529
      if( printOn > 1 ){
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
530
531
         int index                        = 0;
         for( int ii = 0; ii < getNumberOfParticles(); ii++, index += 3 ){
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
532
            (void) fprintf( log, "V %d [%12.5e %12.5e %12.5e] [%12.5e %12.5e %12.5e]\n", ii,
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
533
534
535
536
                            vArray[index], vArray[index+1], vArray[index+2], w2[index], w2[index+1], w2[index+2] );
   
         }
      }
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
537
      (void) fflush( log );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
538
539
540
541
542
543
544

//exit(0);
   }

   return DefaultReturnValue;
}