From f7384d1193abe3d5cf516ee9a78fd83d36e5c31a Mon Sep 17 00:00:00 2001 From: Konstantin Kutscher <kutscher@irmb.tu-bs.de> Date: Fri, 3 Aug 2018 14:56:06 +0200 Subject: [PATCH] clean up for update updateGeometry() --- source/Applications/Thermoplast/config.txt | 8 +-- .../Applications/Thermoplast/thermoplast.cpp | 38 +++++----- source/DemCoupling/DemCoProcessor.cpp | 69 +++++++++++-------- .../PhysicsEngineSolverAdapter.h | 3 - .../pe/PePhysicsEngineSolverAdapter.cpp | 41 ----------- .../pe/PePhysicsEngineSolverAdapter.h | 2 - 6 files changed, 65 insertions(+), 96 deletions(-) diff --git a/source/Applications/Thermoplast/config.txt b/source/Applications/Thermoplast/config.txt index b25b5012c..81b95d759 100644 --- a/source/Applications/Thermoplast/config.txt +++ b/source/Applications/Thermoplast/config.txt @@ -1,21 +1,21 @@ #simulation parameters #boundingBox = 0 0 0 300 1520 2320 -boundingBox = 60 1370 150 190 1530 320 #test bb +boundingBox = 60 1370 10 190 1530 320 #test bb #boundingBox = 60 0 10 190 1530 2320 #production bb blocknx = 10 10 10 #blocknx = 300 420 320 -endTime = 1000 -outTime = 10000 +endTime = 100 +outTime = 100 availMem = 25e9 uLB = 0.1 #PE parameters peMinOffset = 46 2 2 peMaxOffset = -8 -25 -2 -sphereTime = 100000 +sphereTime = 100 #geometry files pathGeo = d:/Projects/ThermoPlast/SimGeo diff --git a/source/Applications/Thermoplast/thermoplast.cpp b/source/Applications/Thermoplast/thermoplast.cpp index 9ca15b763..0ffd6c3e4 100644 --- a/source/Applications/Thermoplast/thermoplast.cpp +++ b/source/Applications/Thermoplast/thermoplast.cpp @@ -223,7 +223,7 @@ void thermoplast(string configname) UBLOG(logINFO, "Preprocess - start"); } - GbCuboid3DPtr geoInflow1(new GbCuboid3D(g_minX1-blockLength, g_maxX2-120.0, g_minX3+190.0-150.0, g_minX1+1, g_maxX2+20.0, g_minX3+320.0)); + GbCuboid3DPtr geoInflow1(new GbCuboid3D(g_minX1-blockLength, g_maxX2-120.0, g_minX3+190.0, g_minX1+1, g_maxX2+20.0, g_minX3+320.0)); if (myid == 0) GbSystem3D::writeGeoObject(geoInflow1.get(), pathOut + "/geo/geoInflow1", WbWriterVtkXmlASCII::getInstance()); if (!restart) @@ -381,28 +381,28 @@ void thermoplast(string configname) //sphere prototypes //UBLOG(logINFO, "sphere prototypes - start, rank="<<myid); double d = 2.0*radius; - Vector3D origin(g_minX1+peMinOffset[0]+radius, geoInflow1->getX2Minimum()+4.0*d, geoInflow1->getX3Minimum()+2.0*d); - for (int x3 = 0; x3 < 2; x3++) - for (int x2 = 0; x2 < 2; x2++) - for (int x1 = 0; x1 < 1; x1++) - { - //SPtr<GbObject3D> sphere(new GbSphere3D(origin[0]+x1*d, origin[1]+x2*2.0*d, origin[2]+x3*2.0*d, radius)); - SPtr<GbObject3D> sphere(new GbSphere3D(origin[0]+2.0*d, origin[1]+x2*1.5*d, origin[2]+x3*1.5*d, radius)); - if (myid == 0) GbSystem3D::writeGeoObject(sphere.get(), pathOut + "/geo/sphere"+UbSystem::toString(x1)+UbSystem::toString(x2)+UbSystem::toString(x3), WbWriterVtkXmlASCII::getInstance()); - createSphereCoProcessor->addGeoObject(sphere, Vector3D(uLB, 0.0, 0.0)); - } - //UBLOG(logINFO, "sphere prototypes - stop, rank="<<myid); - - //Vector3D origin(106+radius, 1372+radius, 12+radius); - //for (int x3 = 0; x3 < 28; x3++) - // for (int x2 = 0; x2 < 12; x2++) - // for (int x1 = 0; x1 < 7; x1++) + //Vector3D origin(g_minX1+peMinOffset[0]+radius, geoInflow1->getX2Minimum()+4.0*d, geoInflow1->getX3Minimum()+2.0*d); + //for (int x3 = 0; x3 < 2; x3++) + // for (int x2 = 0; x2 < 2; x2++) + // for (int x1 = 0; x1 < 1; x1++) // { // //SPtr<GbObject3D> sphere(new GbSphere3D(origin[0]+x1*d, origin[1]+x2*2.0*d, origin[2]+x3*2.0*d, radius)); - // SPtr<GbObject3D> sphere(new GbSphere3D(origin[0]+x1*1.1*d, origin[1]+x2*1.1*d, origin[2]+x3*1.1*d, radius)); - // //if (myid == 0) GbSystem3D::writeGeoObject(sphere.get(), pathOut + "/geo/sphere"+UbSystem::toString(x1)+UbSystem::toString(x2)+UbSystem::toString(x3), WbWriterVtkXmlASCII::getInstance()); + // SPtr<GbObject3D> sphere(new GbSphere3D(origin[0]+2.0*d, origin[1]+x2*1.5*d, origin[2]+x3*1.5*d, radius)); + // if (myid == 0) GbSystem3D::writeGeoObject(sphere.get(), pathOut + "/geo/sphere"+UbSystem::toString(x1)+UbSystem::toString(x2)+UbSystem::toString(x3), WbWriterVtkXmlASCII::getInstance()); // createSphereCoProcessor->addGeoObject(sphere, Vector3D(uLB, 0.0, 0.0)); // } + //UBLOG(logINFO, "sphere prototypes - stop, rank="<<myid); + + Vector3D origin(106+radius, 1372+radius, 12+radius); + for (int x3 = 0; x3 < 28; x3++) + for (int x2 = 0; x2 < 12; x2++) + for (int x1 = 0; x1 < 7; x1++) + { + //SPtr<GbObject3D> sphere(new GbSphere3D(origin[0]+x1*d, origin[1]+x2*2.0*d, origin[2]+x3*2.0*d, radius)); + SPtr<GbObject3D> sphere(new GbSphere3D(origin[0]+x1*1.1*d, origin[1]+x2*1.1*d, origin[2]+x3*1.1*d, radius)); + //if (myid == 0) GbSystem3D::writeGeoObject(sphere.get(), pathOut + "/geo/sphere"+UbSystem::toString(x1)+UbSystem::toString(x2)+UbSystem::toString(x3), WbWriterVtkXmlASCII::getInstance()); + createSphereCoProcessor->addGeoObject(sphere, Vector3D(uLB, 0.0, 0.0)); + } createSphereCoProcessor->process(0); diff --git a/source/DemCoupling/DemCoProcessor.cpp b/source/DemCoupling/DemCoProcessor.cpp index 5634027a9..88ea7f910 100644 --- a/source/DemCoupling/DemCoProcessor.cpp +++ b/source/DemCoupling/DemCoProcessor.cpp @@ -61,16 +61,8 @@ void DemCoProcessor::addInteractor(std::shared_ptr<MovableObjectInteractor> inte const int id = static_cast<int>(interactors.size()) - 1; interactor->setID(id); const auto peGeometry = this->createPhysicsEngineGeometryAdapter(interactor, physicsEngineMaterial); - if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(peGeometry)->isActive()) - { - peGeometry->setLinearVelolocity(initalVelocity); - physicsEngineGeometries.push_back(peGeometry); - } - else - { - physicsEngineGeometries.push_back(peGeometry); - } - //distributeIDs(); + if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(peGeometry)->isActive()) peGeometry->setLinearVelolocity(initalVelocity); + physicsEngineGeometries.push_back(peGeometry); } @@ -243,7 +235,6 @@ void DemCoProcessor::calculateDemTimeStep(double step) for (int i = 0; i < physicsEngineGeometries.size(); i++) { - //physicsEngineSolver->updateGeometry(physicsEngineGeometries[i]); if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometries[i])->isActive()) { interactors[i]->setPhysicsEngineGeometry(physicsEngineGeometries[i]); @@ -344,31 +335,55 @@ void DemCoProcessor::getObjectsPropertiesVector(std::vector<double>& p) void DemCoProcessor::addPeGeo(walberla::pe::RigidBody * peGeo) { //UBLOG(logINFO, "DemCoProcessor::addPeGeo()"); - for (int i = 0; i < physicsEngineGeometries.size(); i++) + //for (int i = 0; i < physicsEngineGeometries.size(); i++) + //{ + // auto geometry = std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometries[i]); + // if (geometry->getId() == peGeo->getID()) + // { + // geometry->setActive(); + // geometry->setGeometry(peGeo); + // return; + // } + //} + + if (peGeo->getID() < 0 || peGeo->getID() >= physicsEngineGeometries.size()) return; + + auto geometry = std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometries[peGeo->getID()]); + if (geometry->getId() == peGeo->getID()) { - auto geometry = std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometries[i]); - if (geometry->getId() == peGeo->getID()) - { - geometry->setActive(); - geometry->setGeometry(peGeo); - return; - } + geometry->setActive(); + geometry->setGeometry(peGeo); + return; } + else + throw UbException(UB_EXARGS, "PeGeo ID is not matching!"); } void DemCoProcessor::removePeGeo(walberla::pe::RigidBody * peGeo) { //UBLOG(logINFO, "DemCoProcessor::removePeGeo()"); - for (int i = 0; i < physicsEngineGeometries.size(); i++) + //for (int i = 0; i < physicsEngineGeometries.size(); i++) + //{ + // auto geometry = std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometries[i]); + // if (geometry->getId() == peGeo->getID()) + // { + // geometry->setInactive(); + // geometry->setGeometry(NULL); + // return; + // } + //} + + if (peGeo->getID() < 0 || peGeo->getID() >= physicsEngineGeometries.size()) return; + + auto geometry = std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometries[peGeo->getID()]); + if (geometry->getId() == peGeo->getID()) { - auto geometry = std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometries[i]); - if (geometry->getId() == peGeo->getID()) - { - geometry->setInactive(); - geometry->setGeometry(NULL); - return; - } + geometry->setInactive(); + geometry->setGeometry(NULL); + return; } + else + throw UbException(UB_EXARGS, "PeGeo ID is not matching!"); } void DemCoProcessor::distributeIDs() diff --git a/source/DemCoupling/physicsEngineAdapter/PhysicsEngineSolverAdapter.h b/source/DemCoupling/physicsEngineAdapter/PhysicsEngineSolverAdapter.h index 78e16a7e4..bb035ab31 100644 --- a/source/DemCoupling/physicsEngineAdapter/PhysicsEngineSolverAdapter.h +++ b/source/DemCoupling/physicsEngineAdapter/PhysicsEngineSolverAdapter.h @@ -18,9 +18,6 @@ public: virtual std::shared_ptr<PhysicsEngineGeometryAdapter> createPhysicsEngineGeometryAdapter(int id, const Vector3D& position, double radius, std::shared_ptr<PhysicsEngineMaterialAdapter> material) const = 0; virtual void runTimestep(double step) = 0; - - virtual void updateGeometry(std::shared_ptr<PhysicsEngineGeometryAdapter>) = 0; - }; diff --git a/source/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.cpp b/source/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.cpp index 7fdc9cae0..a58973c1d 100644 --- a/source/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.cpp +++ b/source/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.cpp @@ -136,47 +136,6 @@ void PePhysicsEngineSolverAdapter::initalPeChannel() const createPlane(*globalBodyStorage, 0, walberla::pe::Vec3( 0, 0,-1), maxCorner + maxX3_Offset, material); } -walberla::pe::RigidBody* PePhysicsEngineSolverAdapter::getPeGeoObject(walberla::id_t id) -{ - for (auto blockIt = forest->begin(); blockIt != forest->end(); ++blockIt) - { - for (auto bodyIt = walberla::pe::BodyIterator::begin(*blockIt, *storageId.get()); bodyIt != walberla::pe::BodyIterator::end(); ++bodyIt) - { - if(bodyIt->getID() == id) - { - walberla::pe::RigidBody* geo = *(bodyIt); - return geo; - } - } - } - return NULL; - - //return getBody(*globalBodyStorage.get(), *forest.get(), *storageId.get(), id, walberla::pe::StorageSelect::LOCAL); - -} - -void PePhysicsEngineSolverAdapter::updateGeometry(std::shared_ptr<PhysicsEngineGeometryAdapter> geometryAdapter) -{ - auto geometry = std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(geometryAdapter); - if (!geometry) - throw "PhysicsEngineGeometryAdapter has to be a PePhysicsEngineGeometryAdapter"; - - int id = geometry->getId(); - - walberla::pe::RigidBody* peGeoObject = this->getPeGeoObject(id); - if (peGeoObject) - { - //UBLOG(logINFO, "rank " << Communicator::getInstance()->getProcessID()); - geometry->setGeometry(peGeoObject); - geometry->setActive(); - //UBLOG(logINFO, "rank " << Communicator::getInstance()->getProcessID()<<" id="<<peGeoObject->getID()); - } - else - { - geometry->setInactive(); - } -} - std::shared_ptr< walberla::blockforest::BlockForest > PePhysicsEngineSolverAdapter::getForest() { return forest; diff --git a/source/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.h b/source/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.h index 6dbdda185..a7b699252 100644 --- a/source/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.h +++ b/source/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.h @@ -69,8 +69,6 @@ public: std::shared_ptr<PhysicsEngineGeometryAdapter> createPhysicsEngineGeometryAdapter(int id, const Vector3D& position, double radius, std::shared_ptr<PhysicsEngineMaterialAdapter> material) const override; void runTimestep(double step) override; - walberla::pe::RigidBody* getPeGeoObject(walberla::id_t id); - void updateGeometry(std::shared_ptr<PhysicsEngineGeometryAdapter>) override; std::shared_ptr< walberla::blockforest::BlockForest > getForest(); void saveToFile(const std::string& path); void loadFromFile(const std::string& path); -- GitLab