diff --git a/Configuration.cpp b/Configuration.cpp index 258ce8170aadd486d702fe7ff01ac721cb0fcb97..c74fac5c527d1fb3c397606def72c684be41e2a4 100644 --- a/Configuration.cpp +++ b/Configuration.cpp @@ -777,7 +777,17 @@ int Configuration::readParameters(const char * config_file) { rigidBody[currRB].addDensityGrid(value); else if (param == String("potentialGrid")) rigidBody[currRB].addPotentialGrid(value); - + else if (param == String("densityGridScale")) + rigidBody[currRB].scaleDensityGrid(value); + else if (param == String("potentialGridScale")) + rigidBody[currRB].scalePotentialGrid(value); + else if (param == String("pmfScale")) + rigidBody[currRB].scalePMF(value); + else if (param == String("position")) + rigidBody[currRB].initPos = stringToVector3( value ); + else if (param == String("orientation")) + rigidBody[currRB].initRot = stringToMatrix3( value ); + // COMMON else if (param == String("num")) { if (currPartClass == partClassPart) @@ -817,6 +827,26 @@ Vector3 Configuration::stringToVector3(String s) { (float) strtod(token[2], NULL) ); return v; } +Matrix3 Configuration::stringToMatrix3(String s) { + // tokenize and return + int numTokens = s.tokenCount(); + if (numTokens != 9) { + printf("ERROR: could not convert input to Matrix3.\n"); // TODO improve this message + exit(1); + } + String* token = new String[numTokens]; + s.tokenize(token); + Matrix3 m( (float) strtod(token[0], NULL), + (float) strtod(token[1], NULL), + (float) strtod(token[2], NULL), + (float) strtod(token[3], NULL), + (float) strtod(token[4], NULL), + (float) strtod(token[5], NULL), + (float) strtod(token[6], NULL), + (float) strtod(token[7], NULL), + (float) strtod(token[8], NULL) ); + return m; +} void Configuration::readAtoms() { // Open the file diff --git a/Configuration.h b/Configuration.h index cb255b12fd4b9dd0a785f7c963b3db02c494f50f..b9143b7eceb4ee7160c3ad39acf1b7423ba226c4 100644 --- a/Configuration.h +++ b/Configuration.h @@ -44,7 +44,7 @@ class Configuration { void setDefaults(); Vector3 stringToVector3(String s); - + Matrix3 stringToMatrix3(String s); int readParameters(const char* config_file); void readAngles(); diff --git a/RigidBody.cu b/RigidBody.cu index 2a6347876e12c5b7e735f6773ab6f940b8740e4d..0477a2771521de361b764433068770dd78bd8b99 100644 --- a/RigidBody.cu +++ b/RigidBody.cu @@ -19,10 +19,10 @@ RigidBody::RigidBody(const Configuration& cref, RigidBodyType& tref) Temp = 295; // tempgrid = c->temperatureGrid; - position = Vector3(); + position = t->initPos; // Vector3(); // Orientation matrix that brings vector from the RB frame to the lab frame - orientation = Matrix3(1.0f); + orientation = t->initRot; //Matrix3(1.0f); momentum = Vector3() * t->mass; // lab frame /* DebugM(4, "velocity " << rbParams->velocity << "\n" << endi); */ diff --git a/RigidBodyType.cu b/RigidBodyType.cu index bf0f416793c8f7b9c9e1aa33eafd37220a26607e..88720bb77679655e89a3e7b119f408f14b459e68 100644 --- a/RigidBodyType.cu +++ b/RigidBodyType.cu @@ -94,25 +94,29 @@ void RigidBodyType::setDampingCoeffs(float timestep) { /* MUST ONLY BE CALLED ON transDamping = 2.3900574 * transDamping; rotDamping = 2.3900574 * rotDamping; - -} -void RigidBodyType::addPotentialGrid(String s) { - // tokenize and return - int numTokens = s.tokenCount(); - if (numTokens != 2) { - printf("ERROR: could not add Grid.\n"); // TODO improve this message - exit(1); + // Also apply scale factors + applyScaleFactors(); +} +void RigidBodyType::applyScaleFactors() { /* currently this is called before raw is updated */ + applyScaleFactor(potentialGridScaleKeys, potentialGridScale, potentialGridKeys, potentialGrids); + applyScaleFactor(densityGridScaleKeys, densityGridScale, densityGridKeys, densityGrids); + applyScaleFactor(pmfScaleKeys, pmfScale, pmfKeys, pmfs); +} +void RigidBodyType::applyScaleFactor( + const std::vector<String> &scaleKeys, const std::vector<float> &scaleFactors, + const std::vector<String> &gridKeys, std::vector<BaseGrid> &grids) { + for (int i = 0; i < scaleKeys.size(); i++) { + const String &k1 = scaleKeys[i]; + for (int j = 0; j < gridKeys.size(); j++) { + const String &k2 = gridKeys[j]; + if ( k1 == k2 ) + grids[j].scale( scaleFactors[i] ); + } } - String* token = new String[numTokens]; - s.tokenize(token); - String key = token[0]; - BaseGrid g(token[1]); - - potentialGrids.push_back( g ); - potentialGridKeys.push_back( key ); } -void RigidBodyType::addDensityGrid(String s) { + +void RigidBodyType::addGrid(String s, std::vector<String> &keys, std::vector<BaseGrid> &grids) { // tokenize and return int numTokens = s.tokenCount(); if (numTokens != 2) { @@ -123,12 +127,21 @@ void RigidBodyType::addDensityGrid(String s) { s.tokenize(token); String key = token[0]; BaseGrid g(token[1]); - - densityGrids.push_back( g ); - densityGridKeys.push_back( key ); + keys.push_back( key ); + grids.push_back( g ); +} +void RigidBodyType::addPotentialGrid(String s) { + addGrid(s, potentialGridKeys, potentialGrids); +} +void RigidBodyType::addDensityGrid(String s) { + addGrid(s, densityGridKeys, densityGrids); } void RigidBodyType::addPMF(String s) { + addGrid(s, pmfKeys, pmfs); +} + +void RigidBodyType::addScaleFactor(String s, std::vector<String> &keys, std::vector<float> &vals) { // tokenize and return int numTokens = s.tokenCount(); if (numTokens != 2) { @@ -138,10 +151,18 @@ void RigidBodyType::addPMF(String s) { String* token = new String[numTokens]; s.tokenize(token); String key = token[0]; - BaseGrid g(token[1]); - - pmfs.push_back( g ); - pmfKeys.push_back( key ); + float v = (float) strtod(token[1], NULL); + keys.push_back( key ); + vals.push_back( v ); +} +void RigidBodyType::scalePotentialGrid(String s) { + addScaleFactor(s, potentialGridScaleKeys, potentialGridScale); +} +void RigidBodyType::scaleDensityGrid(String s) { + addScaleFactor(s, densityGridScaleKeys, densityGridScale); +} +void RigidBodyType::scalePMF(String s) { + addScaleFactor(s, pmfScaleKeys, pmfScale); } void RigidBodyType::updateRaw() { @@ -176,7 +197,6 @@ void RigidBodyType::updateRaw() { rawDensityOrigins[i] = densityGrids[i].getOrigin(); } for (int i=0; i < numPmfs; i++) - rawPmfs[i] = pmfs[i]; - + rawPmfs[i] = pmfs[i]; } diff --git a/RigidBodyType.h b/RigidBodyType.h index c9e32586aa84b09b9c45c8ebaa2544182df0d708..389d27cf6ffe4adc99879bcc107e3b57aa020b5a 100644 --- a/RigidBodyType.h +++ b/RigidBodyType.h @@ -18,6 +18,13 @@ private: void clear(); // void copy(const RigidBodyType& src); + void addGrid(String s, std::vector<String> &keys, std::vector<BaseGrid> &grids); + void addScaleFactor(String s, std::vector<String> &keys, std::vector<float> &vals); + void applyScaleFactors(); + void applyScaleFactor( + const std::vector<String> &scaleKeys, const std::vector<float> &scaleFactors, + const std::vector<String> &gridKeys, std::vector<BaseGrid> &grids); + public: /* RigidBodyType(const String& name = "") : */ /* name(name), num(0), */ @@ -27,8 +34,9 @@ public: RigidBodyType(const String& name = "") : name(name), num(0), - reservoir(NULL), mass(1.0f), inertia(), transDamping(), - rotDamping(), numPotGrids(0), numDenGrids(0), numPmfs(0) { } + reservoir(NULL), mass(1.0f), inertia(), transDamping(), + rotDamping(), numPotGrids(0), numDenGrids(0), numPmfs(0), + initPos(), initRot(Matrix3(1.0f)) { } /* RigidBodyType(const RigidBodyType& src) { copy(src); } */ ~RigidBodyType() { clear(); } @@ -38,6 +46,10 @@ RigidBodyType(const String& name = "") : void addPotentialGrid(String s); void addDensityGrid(String s); void addPMF(String s); + void scalePotentialGrid(String s); + void scaleDensityGrid(String s); + void scalePMF(String s); + void updateRaw(); void setDampingCoeffs(float timestep); @@ -56,6 +68,9 @@ public: Vector3 transForceCoeff; Vector3 rotTorqueCoeff; + Vector3 initPos; + Matrix3 initRot; + std::vector<String> potentialGridKeys; std::vector<String> densityGridKeys; std::vector<String> pmfKeys; @@ -64,6 +79,15 @@ public: std::vector<BaseGrid> densityGrids; std::vector<BaseGrid> pmfs; + std::vector<String> potentialGridScaleKeys; + std::vector<String> densityGridScaleKeys; + std::vector<String> pmfScaleKeys; + + std::vector<float> potentialGridScale; + std::vector<float> densityGridScale; + std::vector<float> pmfScale; + + // RBTODO: clear std::vectors after initialization // duplicates of std::vector grids for device int numPotGrids;