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

Comparing branches/development/src/brains/ForceManager.cpp (file contents):
Revision 1545 by gezelter, Fri Apr 8 21:25:19 2011 UTC vs.
Revision 1570 by gezelter, Thu May 26 21:56:04 2011 UTC

# Line 49 | Line 49
49  
50   #include "brains/ForceManager.hpp"
51   #include "primitives/Molecule.hpp"
52 #include "UseTheForce/doForces_interface.h"
52   #define __OPENMD_C
54 #include "UseTheForce/DarkSide/fInteractionMap.h"
53   #include "utils/simError.h"
54   #include "primitives/Bond.hpp"
55   #include "primitives/Bend.hpp"
56   #include "primitives/Torsion.hpp"
57   #include "primitives/Inversion.hpp"
58 < #include "parallel/ForceDecomposition.hpp"
59 < //#include "parallel/SerialDecomposition.hpp"
58 > #include "nonbonded/NonBondedInteraction.hpp"
59 > #include "parallel/ForceMatrixDecomposition.hpp"
60  
61   using namespace std;
62   namespace OpenMD {
# Line 66 | Line 64 | namespace OpenMD {
64    ForceManager::ForceManager(SimInfo * info) : info_(info) {
65  
66   #ifdef IS_MPI
67 <    decomp_ = new ForceDecomposition(info_);
67 >    fDecomp_ = new ForceMatrixDecomposition(info_);
68   #else
69 <    // decomp_ = new SerialDecomposition(info);
69 >    // fDecomp_ = new ForceSerialDecomposition(info);
70   #endif
71    }
72    
73    void ForceManager::calcForces() {
74      
75 <    if (!info_->isFortranInitialized()) {
75 >    if (!info_->isTopologyDone()) {
76        info_->update();
77 <      nbiMan_->setSimInfo(info_);
78 <      nbiMan_->initialize();
79 <      swfun_ = nbiMan_->getSwitchingFunction();
80 <      decomp_->distributeInitialData();
81 <      info_->setupFortran();
77 >      interactionMan_->setSimInfo(info_);
78 >      interactionMan_->initialize();
79 >      swfun_ = interactionMan_->getSwitchingFunction();
80 >      fDecomp_->distributeInitialData();
81 >      info_->prepareTopology();
82      }
83      
84      preCalculation();  
85 <    calcShortRangeInteraction();
86 <    calcLongRangeInteraction();
85 >    shortRangeInteractions();
86 >    longRangeInteractions();
87      postCalculation();
88      
89    }
# Line 128 | Line 126 | namespace OpenMD {
126      
127    }
128    
129 <  void ForceManager::calcShortRangeInteraction() {
129 >  void ForceManager::shortRangeInteractions() {
130      Molecule* mol;
131      RigidBody* rb;
132      Bond* bond;
# Line 245 | Line 243 | namespace OpenMD {
243      curSnapshot->statData[Stats::INVERSION_POTENTIAL] = inversionPotential;    
244    }
245    
246 <  void ForceManager::calcLongRangeInteraction() {
246 >  void ForceManager::longRangeInteractions() {
247  
248      // some of this initial stuff will go away:
249      Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
# Line 268 | Line 266 | namespace OpenMD {
266      }
267      
268      //initialize data before passing to fortran
269 <    RealType longRangePotential[LR_POT_TYPES];
269 >    RealType longRangePotential[N_INTERACTION_FAMILIES];
270      RealType lrPot = 0.0;
271      int isError = 0;
272  
273 <    for (int i=0; i<LR_POT_TYPES;i++){
273 >    // dangerous to iterate over enums, but we'll live on the edge:
274 >    for (int i = NO_FAMILY; i != N_INTERACTION_FAMILIES; ++i){
275        longRangePotential[i]=0.0; //Initialize array
276      }
277  
278      // new stuff starts here:
279  
280 <    decomp_->distributeData();
280 >    fDecomp_->distributeData();
281  
282 <    int cg1, cg2;
283 <    Vector3d d_grp;
282 >    int cg1, cg2, atom1, atom2;
283 >    Vector3d d_grp, dag;
284      RealType rgrpsq, rgrp;
285      RealType vij;
286      Vector3d fij, fg;
# Line 289 | Line 288 | namespace OpenMD {
288      RealType rCutSq;
289      bool in_switching_region;
290      RealType sw, dswdr, swderiv;
291 <    vector<int> atomListI;
293 <    vector<int> atomListJ;
291 >    vector<int> atomListColumn, atomListRow, atomListLocal;
292      InteractionData idat;
293 +    SelfData sdat;
294 +    RealType mf;
295  
296      int loopStart, loopEnd;
297  
298      loopEnd = PAIR_LOOP;
299 <    if (info_->requiresPrepair_) {
299 >    if (info_->requiresPrepair() ) {
300        loopStart = PREPAIR_LOOP;
301      } else {
302        loopStart = PAIR_LOOP;
# Line 305 | Line 305 | namespace OpenMD {
305      for (int iLoop = loopStart; iLoop < loopEnd; iLoop++) {
306        
307        if (iLoop == loopStart) {
308 <        bool update_nlist = decomp_->checkNeighborList();
308 >        bool update_nlist = fDecomp_->checkNeighborList();
309          if (update_nlist)
310 <          neighborList = decomp_->buildNeighborList();
310 >          neighborList = fDecomp_->buildNeighborList();
311        }
312  
313        for (vector<pair<int, int> >::iterator it = neighborList.begin();
# Line 316 | Line 316 | namespace OpenMD {
316          cg1 = (*it).first;
317          cg2 = (*it).second;
318  
319 <        gtypes = decomp_->getGroupTypes(cg1, cg2);
320 <        d_grp  = decomp_->getIntergroupVector(cg1, cg2);
319 >        gtypes = fDecomp_->getGroupTypes(cg1, cg2);
320 >        d_grp  = fDecomp_->getIntergroupVector(cg1, cg2);
321          curSnapshot->wrapVector(d_grp);        
322          rgrpsq = d_grp.lengthSquare();
323 <        rCutSq = groupCutoffMap(gtypes).first;
323 >        rCutSq = groupCutoffMap[gtypes].first;
324  
325          if (rgrpsq < rCutSq) {
326 <          idat.rcut = groupCutoffMap(gtypes).second;
326 >          *(idat.rcut) = groupCutoffMap[gtypes].second;
327            if (iLoop == PAIR_LOOP) {
328 <            vij = 0.0;
328 >            vij *= 0.0;
329              fij = V3Zero;
330            }
331            
332 <          in_switching_region = swfun_->getSwitch(rgrpsq, idat.sw, idat.dswdr, rgrp);    
333 <          
334 <          atomListI = decomp_->getAtomsInGroupI(cg1);
335 <          atomListJ = decomp_->getAtomsInGroupJ(cg2);
332 >          in_switching_region = swfun_->getSwitch(rgrpsq, *(idat.sw), dswdr,
333 >                                                  rgrp);              
334 >          atomListRow = fDecomp_->getAtomsInGroupRow(cg1);
335 >          atomListColumn = fDecomp_->getAtomsInGroupColumn(cg2);
336  
337 <          for (vector<int>::iterator ia = atomListI.begin();
338 <               ia != atomListI.end(); ++ia) {            
337 >          for (vector<int>::iterator ia = atomListRow.begin();
338 >               ia != atomListRow.end(); ++ia) {            
339              atom1 = (*ia);
340              
341 <            for (vector<int>::iterator jb = atomListJ.begin();
342 <                 jb != atomListJ.end(); ++jb) {              
341 >            for (vector<int>::iterator jb = atomListColumn.begin();
342 >                 jb != atomListColumn.end(); ++jb) {              
343                atom2 = (*jb);
344                
345 <              if (!decomp_->skipAtomPair(atom1, atom2)) {
345 >              if (!fDecomp_->skipAtomPair(atom1, atom2)) {
346                  
347 <                if (atomListI.size() == 1 && atomListJ.size() == 1) {
348 <                  idat.d = d_grp;
349 <                  idat.r2 = rgrpsq;
347 >                idat = fDecomp_->fillInteractionData(atom1, atom2);
348 >
349 >                if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
350 >                  *(idat.d) = d_grp;
351 >                  *(idat.r2) = rgrpsq;
352                  } else {
353 <                  idat.d = decomp_->getInteratomicVector(atom1, atom2);
354 <                  curSnapshot->wrapVector(idat.d);
355 <                  idat.r2 = idat.d.lengthSquare();
353 >                  *(idat.d) = fDecomp_->getInteratomicVector(atom1, atom2);
354 >                  curSnapshot->wrapVector( *(idat.d) );
355 >                  *(idat.r2) = idat.d->lengthSquare();
356                  }
357                  
358 <                idat.r = sqrt(idat.r2);
359 <                decomp_->fillInteractionData(atom1, atom2, idat);
358 <                
358 >                *(idat.rij) = sqrt( *(idat.r2) );
359 >              
360                  if (iLoop == PREPAIR_LOOP) {
361                    interactionMan_->doPrePair(idat);
362                  } else {
363                    interactionMan_->doPair(idat);
364 <                  vij += idat.vpair;
365 <                  fij += idat.f1;
366 <                  tau -= outProduct(idat.d, idat.f);
364 >                  vij += *(idat.vpair);
365 >                  fij += *(idat.f1);
366 >                  tau -= outProduct( *(idat.d), *(idat.f1));
367                  }
368                }
369              }
# Line 375 | Line 376 | namespace OpenMD {
376  
377                fij += fg;
378  
379 <              if (atomListI.size() == 1 && atomListJ.size() == 1) {
380 <                tau -= outProduct(idat.d, fg);
379 >              if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
380 >                tau -= outProduct( *(idat.d), fg);
381                }
382            
383 <              for (vector<int>::iterator ia = atomListI.begin();
384 <                   ia != atomListI.end(); ++ia) {            
383 >              for (vector<int>::iterator ia = atomListRow.begin();
384 >                   ia != atomListRow.end(); ++ia) {            
385                  atom1 = (*ia);                
386 <                mf = decomp_->getMfactI(atom1);
386 >                mf = fDecomp_->getMassFactorRow(atom1);
387                  // fg is the force on atom ia due to cutoff group's
388                  // presence in switching region
389                  fg = swderiv * d_grp * mf;
390 <                decomp_->addForceToAtomI(atom1, fg);
390 >                fDecomp_->addForceToAtomRow(atom1, fg);
391  
392 <                if (atomListI.size() > 1) {
393 <                  if (info_->usesAtomicVirial_) {
392 >                if (atomListRow.size() > 1) {
393 >                  if (info_->usesAtomicVirial()) {
394                      // find the distance between the atom
395                      // and the center of the cutoff group:
396 <                    dag = decomp_->getAtomToGroupVectorI(atom1, cg1);
396 >                    dag = fDecomp_->getAtomToGroupVectorRow(atom1, cg1);
397                      tau -= outProduct(dag, fg);
398                    }
399                  }
400                }
401 <              for (vector<int>::iterator jb = atomListJ.begin();
402 <                   jb != atomListJ.end(); ++jb) {              
401 >              for (vector<int>::iterator jb = atomListColumn.begin();
402 >                   jb != atomListColumn.end(); ++jb) {              
403                  atom2 = (*jb);
404 <                mf = decomp_->getMfactJ(atom2);
404 >                mf = fDecomp_->getMassFactorColumn(atom2);
405                  // fg is the force on atom jb due to cutoff group's
406                  // presence in switching region
407                  fg = -swderiv * d_grp * mf;
408 <                decomp_->addForceToAtomJ(atom2, fg);
408 >                fDecomp_->addForceToAtomColumn(atom2, fg);
409  
410 <                if (atomListJ.size() > 1) {
411 <                  if (info_->usesAtomicVirial_) {
410 >                if (atomListColumn.size() > 1) {
411 >                  if (info_->usesAtomicVirial()) {
412                      // find the distance between the atom
413                      // and the center of the cutoff group:
414 <                    dag = decomp_->getAtomToGroupVectorJ(atom2, cg2);
414 >                    dag = fDecomp_->getAtomToGroupVectorColumn(atom2, cg2);
415                      tau -= outProduct(dag, fg);
416                    }
417                  }
# Line 424 | Line 425 | namespace OpenMD {
425        }
426  
427        if (iLoop == PREPAIR_LOOP) {
428 <        if (info_->requiresPrepair_) {            
429 <          decomp_->collectIntermediateData();
430 <          atomList = decomp_->getAtomList();
431 <          for (vector<int>::iterator ia = atomList.begin();
432 <               ia != atomList.end(); ++ia) {              
432 <            atom1 = (*ia);            
433 <            decomp_->populateSelfData(atom1, SelfData sdat);
428 >        if (info_->requiresPrepair()) {            
429 >          fDecomp_->collectIntermediateData();
430 >
431 >          for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {
432 >            sdat = fDecomp_->fillSelfData(atom1);
433              interactionMan_->doPreForce(sdat);
434            }
435 <          decomp_->distributeIntermediateData();        
435 >
436 >          fDecomp_->distributeIntermediateData();        
437          }
438        }
439  
440      }
441      
442 <    decomp_->collectData();
442 >    fDecomp_->collectData();
443      
444 <    if (info_->requiresSkipCorrection_ || info_->requiresSelfCorrection_) {
445 <      atomList = decomp_->getAtomList();
446 <      for (vector<int>::iterator ia = atomList.begin();
447 <           ia != atomList.end(); ++ia) {              
448 <        atom1 = (*ia);    
444 >    if ( info_->requiresSkipCorrection() ) {
445 >      
446 >      for (int atom1 = 0; atom1 < fDecomp_->getNAtomsInRow(); atom1++) {
447  
448 <        if (info_->requiresSkipCorrection_) {
449 <          vector<int> skipList = decomp_->getSkipsForAtom(atom1);
450 <          for (vector<int>::iterator jb = skipList.begin();
451 <               jb != skipList.end(); ++jb) {              
452 <            atom2 = (*jb);
453 <            decomp_->populateSkipData(atom1, atom2, InteractionData idat);
454 <            interactionMan_->doSkipCorrection(idat);
455 <          }
448 >        vector<int> skipList = fDecomp_->getSkipsForRowAtom( atom1 );
449 >        
450 >        for (vector<int>::iterator jb = skipList.begin();
451 >             jb != skipList.end(); ++jb) {        
452 >    
453 >          atom2 = (*jb);
454 >          idat = fDecomp_->fillSkipData(atom1, atom2);
455 >          interactionMan_->doSkipCorrection(idat);
456 >
457          }
459          
460        if (info_->requiresSelfCorrection_) {
461          decomp_->populateSelfData(atom1, SelfData sdat);
462          interactionMan_->doSelfCorrection(sdat);
458        }
464      
465      
459      }
460 +    
461 +    if (info_->requiresSelfCorrection()) {
462  
463 <    for (int i=0; i<LR_POT_TYPES;i++){
463 >      for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {          
464 >        sdat = fDecomp_->fillSelfData(atom1);
465 >        interactionMan_->doSelfCorrection(sdat);
466 >      }
467 >
468 >    }
469 >
470 >    // dangerous to iterate over enums, but we'll live on the edge:
471 >    for (int i = NO_FAMILY; i != N_INTERACTION_FAMILIES; ++i){
472        lrPot += longRangePotential[i]; //Quick hack
473      }
474          
475      //store the tau and long range potential    
476      curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot;
477 <    curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VDW_POT];
478 <    curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_POT];
477 >    curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VANDERWAALS_FAMILY];
478 >    curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_FAMILY];
479    }
480  
481    

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines