From c342db717eb8c43e05c7a5bf52932ff91d5830e9 Mon Sep 17 00:00:00 2001 From: Chris Maffeo <cmaffeo2@illinois.edu> Date: Fri, 6 Nov 2015 17:38:03 -0600 Subject: [PATCH] --amend --- Configuration.cpp | 3 +++ RigidBodyType.cpp | 26 ++++++++++++++++++++-- RigidBodyType.h | 55 +++++++++++++++++++++++++---------------------- 3 files changed, 56 insertions(+), 28 deletions(-) diff --git a/Configuration.cpp b/Configuration.cpp index d523a06..c1f1a43 100644 --- a/Configuration.cpp +++ b/Configuration.cpp @@ -408,6 +408,9 @@ void Configuration::copyToCUDA() { // TODO: The above line fails when there is not enough memory. If it fails, stop. // TODO: what's going on here? + // pmf_h is made as a copy of *part[i].pmf, which is then asynchronously copied to Device, and + // is not deleted + // seems like bad code, but not 100% sure for (int i = 0; i < numParts; i++) { BaseGrid *pmf = NULL, *diffusionGrid = NULL; BrownianParticleType *b = new BrownianParticleType(part[i]); diff --git a/RigidBodyType.cpp b/RigidBodyType.cpp index 2dec83a..90581e6 100644 --- a/RigidBodyType.cpp +++ b/RigidBodyType.cpp @@ -52,8 +52,30 @@ KeyGrid RigidBodyType::createKeyGrid(String s) { return g; } void RigidBodyType::addPotentialGrid(String s) { - potentialGrids.push_back( createKeyGrid(s) ); + // tokenize and return + int numTokens = s.tokenCount(); + if (numTokens != 2) { + printf("ERROR: could not add Grid.\n"); // TODO improve this message + exit(1); + } + String* token = new String[numTokens]; + s.tokenize(token); + String key = token[0]; + BaseGrid g(token[1]); + + potentialGrids.push_back( g ); } void RigidBodyType::addDensityGrid(String s) { - densityGrids.push_back( createKeyGrid(s) ); + // tokenize and return + int numTokens = s.tokenCount(); + if (numTokens != 2) { + printf("ERROR: could not add Grid.\n"); // TODO improve this message + exit(1); + } + String* token = new String[numTokens]; + s.tokenize(token); + String key = token[0]; + BaseGrid g(token[1]); + + densityGrids.push_back( g ); } diff --git a/RigidBodyType.h b/RigidBodyType.h index 571ae8a..645422c 100644 --- a/RigidBodyType.h +++ b/RigidBodyType.h @@ -9,41 +9,47 @@ #include "useful.h" #include "BaseGrid.h" -// Stores particle type's potential grid and other information -struct KeyGrid { - String key; - BaseGrid grid; -KeyGrid() : - key(NULL), grid() { } -}; - class RigidBodyType { private: // Deletes all members void clear(); // void copy(const RigidBodyType& src); - KeyGrid createKeyGrid(String s); - public: +/* RigidBodyType(const String& name = "") : */ +/* name(name), num(0), */ +/* reservoir(NULL), mass(1.0f), inertia(), transDamping(), */ +/* rotDamping(), potentialGrids(NULL), densityGrids(NULL), */ +/* potentialGrids_D(NULL), densityGrids_D(NULL) { } */ + RigidBodyType(const String& name = "") : name(name), num(0), reservoir(NULL), mass(1.0f), inertia(), transDamping(), - rotDamping(), potentialGrids(NULL), densityGrids(NULL), - potentialGrids_D(NULL), densityGrids_D(NULL) { } + rotDamping() { + /* potentialGrids = *(new thrust::host_vector<BaseGrid>()); */ + /* densityGrids = *(new thrust::host_vector<BaseGrid>()); */ + /* potentialGrids = *(new thrust::host_vector<BaseGrid>()); */ + /* densityGrids = *(new thrust::host_vector<BaseGrid>()); */ + + /* thrust::host_vector<BaseGrid> potentialGrids; */ + /* thrust::host_vector<BaseGrid> densityGrids; */ + /* thrust::device_vector<BaseGrid> potentialGrids_D; */ + /* thrust::device_vector<BaseGrid> densityGrids_D; */ + + potentialGrids = thrust::host_vector<BaseGrid>(); + densityGrids = thrust::host_vector<BaseGrid>(); + potentialGrids = thrust::host_vector<BaseGrid>(); + densityGrids = thrust::host_vector<BaseGrid>(); + + } + + /* RigidBodyType(const RigidBodyType& src) { copy(src); } */ ~RigidBodyType() { clear(); } /* RigidBodyType& operator=(const RigidBodyType& src); */ - // crop - // Crops all BaseGrid members - // @param boundries to crop to (x0, y0, z0) -> (x1, y1, z1); - // whether to change the origin - // @return success of function (if false nothing was done) - /* bool crop(int x0, int y0, int z0, int x1, int y1, int z1, bool keep_origin); */ - void addPotentialGrid(String s); void addDensityGrid(String s); @@ -52,17 +58,14 @@ public: int num; // number of particles of this type Reservoir* reservoir; - /* BaseGrid* pmf; */ float mass; Vector3 inertia; Vector3 transDamping; Vector3 rotDamping; - /* std::vector<KeyGrid> potentialGrids; */ - /* std::vector<KeyGrid> densityGrids; */ - thrust::host_vector<KeyGrid> potentialGrids; - thrust::device_vector<KeyGrid> potentialGrids_D; - thrust::host_vector<KeyGrid> densityGrids; - thrust::device_vector<KeyGrid> densityGrids_D; + thrust::host_vector<BaseGrid> potentialGrids; + thrust::host_vector<BaseGrid> densityGrids; + thrust::device_vector<BaseGrid> potentialGrids_D; + thrust::device_vector<BaseGrid> densityGrids_D; }; -- GitLab