diff --git a/Configuration.cpp b/Configuration.cpp index 5a818d26cd4ada1c4a4cb6e330c46a6775fe13bb..bc2905ea33cd5713667e678457efa8ce00a5666c 100644 --- a/Configuration.cpp +++ b/Configuration.cpp @@ -529,6 +529,7 @@ void Configuration::setDefaults() { // System parameters outputName = "out"; timestep = 1e-5f; + rigidBodyGridGridPeriod = 1; steps = 100; seed = 0; inputCoordinates = ""; @@ -635,6 +636,8 @@ int Configuration::readParameters(const char * config_file) { outputName = value; else if (param == String("timestep")) timestep = (float) strtod(value.val(), NULL); + else if (param == String("rigidBodyGridGridPeriod")) + rigidBodyGridGridPeriod = atoi(value.val()); else if (param == String("steps")) steps = atol(value.val()); else if (param == String("seed")) @@ -825,7 +828,8 @@ int Configuration::readParameters(const char * config_file) { } // UNKNOWN else { - printf("WARNING: Unrecognized keyword `%s'.\n", param.val()); + printf("ERROR: Unrecognized keyword `%s'.\n", param.val()); + exit(1); } } diff --git a/Configuration.h b/Configuration.h index 5ac0d179f7dc9dbff0605f23375490556108d73c..aa7e2ee3caa99415d4e0c71c757c971591b407cb 100644 --- a/Configuration.h +++ b/Configuration.h @@ -155,6 +155,7 @@ public: unsigned long randoSeed; // Other parameters. + int rigidBodyGridGridPeriod; float switchStart; float maxInitialPot; float initialZ; diff --git a/RigidBodyController.cu b/RigidBodyController.cu index fb9a26f773db33cc19eacfb622fdcc2d09113f7c..09f3430da7e4c2365e5d35aa74cef5d4ad6f989f 100644 --- a/RigidBodyController.cu +++ b/RigidBodyController.cu @@ -184,7 +184,7 @@ void RigidBodyController::initializeForcePairs() { RigidBody* rb2 = &(rbs2[j]); printf(" pushing RB force pair for %d:%d\n",i,j); - RigidBodyForcePair fp = RigidBodyForcePair(&(t1),&(t2),rb1,rb2,gridKeyId1,gridKeyId2, false); + RigidBodyForcePair fp = RigidBodyForcePair(&(t1),&(t2),rb1,rb2,gridKeyId1,gridKeyId2, false, conf.rigidBodyGridGridPeriod ); gpuErrchk(cudaDeviceSynchronize()); /* RBTODO: this should be extraneous */ forcePairs.push_back( fp ); printf(" done pushing RB force pair for %d:%d\n",i,j); @@ -221,7 +221,7 @@ void RigidBodyController::initializeForcePairs() { // Loop over rigid bodies of these types for (int i = 0; i < rbs1.size(); i++) { RigidBody* rb1 = &(rbs1[i]); - RigidBodyForcePair fp = RigidBodyForcePair(&(t1),&(t1),rb1,rb1,gridKeyId1,gridKeyId2, true); + RigidBodyForcePair fp = RigidBodyForcePair(&(t1),&(t1),rb1,rb1,gridKeyId1,gridKeyId2, true, conf.rigidBodyGridGridPeriod); gpuErrchk(cudaDeviceSynchronize()); /* RBTODO: this should be extraneous */ forcePairs.push_back( fp ); } @@ -246,17 +246,7 @@ void RigidBodyController::updateParticleLists(Vector3* pos_d) { void RigidBodyController::updateForces(Vector3* pos_d, Vector3* force_d, int s) { if (s <= 1) gpuErrchk( cudaProfilerStart() ); - - - // clear old forces - for (int i = 0; i < rigidBodyByType.size(); i++) { - for (int j = 0; j < rigidBodyByType[i].size(); j++) { - RigidBody& rb = rigidBodyByType[i][j]; - rb.clearForce(); - rb.clearTorque(); - } - } - + // Grid–particle forces for (int i = 0; i < rigidBodyByType.size(); i++) { for (int j = 0; j < rigidBodyByType[i].size(); j++) { @@ -266,8 +256,7 @@ void RigidBodyController::updateForces(Vector3* pos_d, Vector3* force_d, int s) } // Grid–Grid forces - if (forcePairs.size() > 0) { - + if ( (s % conf.rigidBodyGridGridPeriod) == 0 && forcePairs.size() > 0) { for (int i=0; i < forcePairs.size(); i++) { // TODO: performance: make this check occur less frequently if (forcePairs[i].isWithinPairlistDist()) @@ -347,6 +336,15 @@ void RigidBodyController::integrate(int step) { } } } + + // clear old forces + for (int i = 0; i < rigidBodyByType.size(); i++) { + for (int j = 0; j < rigidBodyByType[i].size(); j++) { + RigidBody& rb = rigidBodyByType[i][j]; + rb.clearForce(); + rb.clearTorque(); + } + } } // allocate and initialize an array of stream handles @@ -493,7 +491,10 @@ void RigidBodyForcePair::processGPUForces() { f = f + tmpF; t = t + tmpT; } - + + f *= updatePeriod; + t *= updatePeriod; + rb1->addForce( f ); rb1->addTorque( t ); diff --git a/RigidBodyController.h b/RigidBodyController.h index 40851e8d9870b6d5fdbd37d0058fdcf2ffe5440c..ad06f20c5c664deb7cdeb1785aeb7245d2a57ef3 100644 --- a/RigidBodyController.h +++ b/RigidBodyController.h @@ -26,8 +26,8 @@ class RigidBodyForcePair { public: RigidBodyForcePair(RigidBodyType* t1, RigidBodyType* t2, RigidBody* rb1, RigidBody* rb2, - std::vector<int> gridKeyId1, std::vector<int> gridKeyId2, bool isPmf) : - type1(t1), type2(t2), rb1(rb1), rb2(rb2), + std::vector<int> gridKeyId1, std::vector<int> gridKeyId2, bool isPmf, int updatePeriod) : + updatePeriod(updatePeriod), type1(t1), type2(t2), rb1(rb1), rb2(rb2), gridKeyId1(gridKeyId1), gridKeyId2(gridKeyId2), isPmf(isPmf) { printf(" Constructing RB force pair...\n"); @@ -35,7 +35,7 @@ public: // printf(" done constructing RB force pair\n"); } RigidBodyForcePair(const RigidBodyForcePair& o) : - type1(o.type1), type2(o.type2), rb1(o.rb1), rb2(o.rb2), + updatePeriod(o.updatePeriod), type1(o.type1), type2(o.type2), rb1(o.rb1), rb2(o.rb2), gridKeyId1(o.gridKeyId1), gridKeyId2(o.gridKeyId2), isPmf(o.isPmf) { printf(" Copying RB force pair...\n"); /* initialize(); */ @@ -52,6 +52,8 @@ public: private: int initialize(); void swap(RigidBodyForcePair& a, RigidBodyForcePair& b); + + int updatePeriod; static const int numThreads = NUMTHREADS; @@ -79,7 +81,7 @@ private: static int lastStreamID; static RigidBodyForcePair* lastRbForcePair; static int lastRbGridID; - + void callGridForceKernel(int pairId, int s); void retrieveForcesForGrid(const int i); void processGPUForces();