Skip to content
Snippets Groups Projects
Commit c78e3428 authored by Sebastian Eibl's avatar Sebastian Eibl
Browse files

replaced memory allocation in factories with smart pointers

parent 8af18103
No related merge requests found
...@@ -65,7 +65,7 @@ ConvexPolyhedronID createConvexPolyhedron( BodyStorage& globalStorage, BlockStor ...@@ -65,7 +65,7 @@ ConvexPolyhedronID createConvexPolyhedron( BodyStorage& globalStorage, BlockStor
{ {
WALBERLA_ASSERT_UNEQUAL( ConvexPolyhedron::getStaticTypeID(), std::numeric_limits<id_t>::max(), "ConvexPolyhedron TypeID not initalized!"); WALBERLA_ASSERT_UNEQUAL( ConvexPolyhedron::getStaticTypeID(), std::numeric_limits<id_t>::max(), "ConvexPolyhedron TypeID not initalized!");
ConvexPolyhedronID poly = NULL; ConvexPolyhedronID poly = nullptr;
Vec3 centroid = toWalberla( computeCentroid( mesh ) ); Vec3 centroid = toWalberla( computeCentroid( mesh ) );
translate( mesh, -centroid ); translate( mesh, -centroid );
...@@ -78,25 +78,24 @@ ConvexPolyhedronID createConvexPolyhedron( BodyStorage& globalStorage, BlockStor ...@@ -78,25 +78,24 @@ ConvexPolyhedronID createConvexPolyhedron( BodyStorage& globalStorage, BlockStor
WALBERLA_CHECK_EQUAL(communicating, false, "Global bodies can not be communicating!" ); WALBERLA_CHECK_EQUAL(communicating, false, "Global bodies can not be communicating!" );
WALBERLA_CHECK_EQUAL(infiniteMass, true, "Global bodies must have infinite mass!" ); WALBERLA_CHECK_EQUAL(infiniteMass, true, "Global bodies must have infinite mass!" );
poly = new ConvexPolyhedron(sid, uid, gpos, Vec3(0,0,0), Quat(), mesh, material, global, false, true); auto cp = std::make_unique<ConvexPolyhedron>(sid, uid, gpos, Vec3(0,0,0), Quat(), mesh, material, global, false, true);
globalStorage.add(poly); poly = static_cast<ConvexPolyhedronID>(&globalStorage.add(std::move(cp)));
} else } else
{ {
for (auto it = blocks.begin(); it != blocks.end(); ++it){ for (auto& block : blocks){
IBlock* block = (&(*it)); if (block.getAABB().contains(gpos))
if (block->getAABB().contains(gpos))
{ {
const id_t sid( UniqueID<RigidBody>::create() ); const id_t sid( UniqueID<RigidBody>::create() );
Storage* bs = block->getData<Storage>(storageID); BodyStorage& bs = (*block.getData<Storage>(storageID))[0];
poly = new ConvexPolyhedron(sid, uid, gpos, Vec3(0,0,0), Quat(), mesh, material, global, communicating, infiniteMass); auto cp = std::make_unique<ConvexPolyhedron>(sid, uid, gpos, Vec3(0,0,0), Quat(), mesh, material, global, communicating, infiniteMass);
poly->MPITrait.setOwner(Owner(MPIManager::instance()->rank(), block->getId().getID())); cp->MPITrait.setOwner(Owner(MPIManager::instance()->rank(), block.getId().getID()));
(*bs)[0].add(poly); poly = static_cast<ConvexPolyhedronID>(&bs.add( std::move(cp) ) );
} }
} }
} }
if (poly != NULL) if (poly != nullptr)
{ {
// Logging the successful creation of the box // Logging the successful creation of the box
WALBERLA_LOG_DETAIL( WALBERLA_LOG_DETAIL(
......
...@@ -43,32 +43,31 @@ BoxID createBox( BodyStorage& globalStorage, BlockStorage& blocks, BlockDa ...@@ -43,32 +43,31 @@ BoxID createBox( BodyStorage& globalStorage, BlockStorage& blocks, BlockDa
if( lengths[0] <= real_t(0) || lengths[1] <= real_t(0) || lengths[2] <= real_t(0) ) if( lengths[0] <= real_t(0) || lengths[1] <= real_t(0) || lengths[2] <= real_t(0) )
throw std::invalid_argument( "Invalid side length" ); throw std::invalid_argument( "Invalid side length" );
BoxID box = NULL; BoxID box = nullptr;
if (global) if (global)
{ {
const id_t sid = UniqueID<RigidBody>::createGlobal(); const id_t sid = UniqueID<RigidBody>::createGlobal();
WALBERLA_ASSERT_EQUAL(communicating, false); WALBERLA_ASSERT_EQUAL(communicating, false);
WALBERLA_ASSERT_EQUAL(infiniteMass, true); WALBERLA_ASSERT_EQUAL(infiniteMass, true);
box = new Box(sid, uid, gpos, Vec3(0,0,0), Quat(), lengths, material, global, false, true); BoxPtr bx = std::make_unique<Box>(sid, uid, gpos, Vec3(0,0,0), Quat(), lengths, material, global, false, true);
globalStorage.add(box); box = static_cast<BoxID>(&globalStorage.add(std::move(bx)));
} else } else
{ {
for (auto it = blocks.begin(); it != blocks.end(); ++it){ for (auto& block : blocks){
IBlock* block = (&(*it)); if (block.getAABB().contains(gpos))
if (block->getAABB().contains(gpos))
{ {
const id_t sid( UniqueID<RigidBody>::create() ); const id_t sid( UniqueID<RigidBody>::create() );
Storage* bs = block->getData<Storage>(storageID); BodyStorage& bs = (*block.getData<Storage>(storageID))[0];
box = new Box(sid, uid, gpos, Vec3(0,0,0), Quat(), lengths, material, global, communicating, infiniteMass); BoxPtr bx = std::make_unique<Box>(sid, uid, gpos, Vec3(0,0,0), Quat(), lengths, material, global, communicating, infiniteMass);
box->MPITrait.setOwner(Owner(MPIManager::instance()->rank(), block->getId().getID())); bx->MPITrait.setOwner(Owner(MPIManager::instance()->rank(), block.getId().getID()));
(*bs)[0].add(box); box = static_cast<BoxID>(&bs.add(std::move(bx)));
} }
} }
} }
if (box != NULL) if (box != nullptr)
{ {
// Logging the successful creation of the box // Logging the successful creation of the box
WALBERLA_LOG_DETAIL( WALBERLA_LOG_DETAIL(
......
...@@ -43,32 +43,31 @@ CapsuleID createCapsule( BodyStorage& globalStorage, BlockStorage& blocks, Blo ...@@ -43,32 +43,31 @@ CapsuleID createCapsule( BodyStorage& globalStorage, BlockStorage& blocks, Blo
WALBERLA_ASSERT_GREATER( radius, real_t(0), "Invalid capsule radius" ); WALBERLA_ASSERT_GREATER( radius, real_t(0), "Invalid capsule radius" );
WALBERLA_ASSERT_GREATER( length, real_t(0), "Invalid capsule length" ); WALBERLA_ASSERT_GREATER( length, real_t(0), "Invalid capsule length" );
CapsuleID capsule = NULL; CapsuleID capsule = nullptr;
if (global) if (global)
{ {
const id_t sid = UniqueID<RigidBody>::createGlobal(); const id_t sid = UniqueID<RigidBody>::createGlobal();
WALBERLA_ASSERT_EQUAL(communicating, false); WALBERLA_ASSERT_EQUAL(communicating, false);
WALBERLA_ASSERT_EQUAL(infiniteMass, true); WALBERLA_ASSERT_EQUAL(infiniteMass, true);
capsule = new Capsule(sid, uid, gpos, Vec3(0,0,0), Quat(), radius, length, material, global, false, true); CapsulePtr cp = std::make_unique<Capsule>(sid, uid, gpos, Vec3(0,0,0), Quat(), radius, length, material, global, false, true);
globalStorage.add(capsule); capsule = static_cast<CapsuleID>(&globalStorage.add(std::move(cp)));
} else } else
{ {
for (auto it = blocks.begin(); it != blocks.end(); ++it){ for (auto& block : blocks){
IBlock* block = (&(*it)); if (block.getAABB().contains(gpos))
if (block->getAABB().contains(gpos))
{ {
const id_t sid( UniqueID<RigidBody>::create() ); const id_t sid( UniqueID<RigidBody>::create() );
Storage* bs = block->getData<Storage>(storageID); BodyStorage& bs = (*block.getData<Storage>(storageID))[0];
capsule = new Capsule(sid, uid, gpos, Vec3(0,0,0), Quat(), radius, length, material, global, communicating, infiniteMass); CapsulePtr cp = std::make_unique<Capsule>(sid, uid, gpos, Vec3(0,0,0), Quat(), radius, length, material, global, communicating, infiniteMass);
capsule->MPITrait.setOwner(Owner(MPIManager::instance()->rank(), block->getId().getID())); cp->MPITrait.setOwner(Owner(MPIManager::instance()->rank(), block.getId().getID()));
(*bs)[0].add(capsule); capsule = static_cast<CapsuleID>(&bs.add( std::move(cp) ));
} }
} }
} }
if (capsule != NULL) if (capsule != nullptr)
{ {
// Logging the successful creation of the box // Logging the successful creation of the box
WALBERLA_LOG_DETAIL( WALBERLA_LOG_DETAIL(
......
...@@ -38,9 +38,9 @@ CylindricalBoundaryID createCylindricalBoundary( BodyStorage& globalStorage, ...@@ -38,9 +38,9 @@ CylindricalBoundaryID createCylindricalBoundary( BodyStorage& globalStorage,
const id_t sid( UniqueID<RigidBody>::createGlobal() ); const id_t sid( UniqueID<RigidBody>::createGlobal() );
CylindricalBoundaryID cb = new CylindricalBoundary( sid, uid, gpos, radius, material ); CylindricalBoundaryPtr cbPtr = std::make_unique<CylindricalBoundary>( sid, uid, gpos, radius, material );
globalStorage.add(cb); CylindricalBoundaryID cb = static_cast<CylindricalBoundaryID>(&globalStorage.add(std::move(cbPtr)));
// Logging the successful creation of the plane // Logging the successful creation of the plane
WALBERLA_LOG_DETAIL( "Created cylindrical boundary " << sid << "\n" << cb); WALBERLA_LOG_DETAIL( "Created cylindrical boundary " << sid << "\n" << cb);
......
...@@ -32,36 +32,35 @@ namespace walberla { ...@@ -32,36 +32,35 @@ namespace walberla {
namespace pe { namespace pe {
EllipsoidID createEllipsoid( BodyStorage& globalStorage, BlockStorage& blocks, BlockDataID storageID, EllipsoidID createEllipsoid( BodyStorage& globalStorage, BlockStorage& blocks, BlockDataID storageID,
id_t uid, const Vec3& gpos, const Vec3& semiAxes, id_t uid, const Vec3& gpos, const Vec3& semiAxes,
MaterialID material, MaterialID material,
bool global, bool communicating, bool infiniteMass ) bool global, bool communicating, bool infiniteMass )
{ {
WALBERLA_ASSERT_UNEQUAL( Ellipsoid::getStaticTypeID(), std::numeric_limits<id_t>::max(), "Ellipsoid TypeID not initalized!"); WALBERLA_ASSERT_UNEQUAL( Ellipsoid::getStaticTypeID(), std::numeric_limits<id_t>::max(), "Ellipsoid TypeID not initalized!");
// Checking the semiAxes // Checking the semiAxes
if( semiAxes[0] <= real_c(0) || semiAxes[1] <= real_c(0) || semiAxes[2] <= real_c(0) ) if( semiAxes[0] <= real_c(0) || semiAxes[1] <= real_c(0) || semiAxes[2] <= real_c(0) )
throw std::invalid_argument( "Invalid Ellipsoid semi-axes" ); throw std::invalid_argument( "Invalid Ellipsoid semi-axes" );
EllipsoidID ellipsoid = NULL; EllipsoidID ellipsoid = nullptr;
if (global) if (global)
{ {
const id_t sid = UniqueID<RigidBody>::createGlobal(); const id_t sid = UniqueID<RigidBody>::createGlobal();
WALBERLA_ASSERT_EQUAL(communicating, false); WALBERLA_ASSERT_EQUAL(communicating, false);
WALBERLA_ASSERT_EQUAL(infiniteMass, true); WALBERLA_ASSERT_EQUAL(infiniteMass, true);
ellipsoid = new Ellipsoid(sid, uid, gpos, Vec3(0,0,0), Quat(), semiAxes, material, global, false, true); EllipsoidPtr el = std::make_unique<Ellipsoid>(sid, uid, gpos, Vec3(0,0,0), Quat(), semiAxes, material, global, false, true);
globalStorage.add(ellipsoid); ellipsoid = static_cast<EllipsoidID>(&globalStorage.add(std::move(el)));
} else } else
{ {
for (auto it = blocks.begin(); it != blocks.end(); ++it){ for (auto& block : blocks){
IBlock* block = (&(*it)); if (block.getAABB().contains(gpos))
if (block->getAABB().contains(gpos))
{ {
const id_t sid( UniqueID<RigidBody>::create() ); const id_t sid( UniqueID<RigidBody>::create() );
Storage* bs = block->getData<Storage>(storageID); BodyStorage& bs = (*block.getData<Storage>(storageID))[0];
ellipsoid = new Ellipsoid(sid, uid, gpos, Vec3(0,0,0), Quat(), semiAxes, material, global, communicating, infiniteMass); EllipsoidPtr el = std::make_unique<Ellipsoid>(sid, uid, gpos, Vec3(0,0,0), Quat(), semiAxes, material, global, communicating, infiniteMass);
ellipsoid->MPITrait.setOwner(Owner(MPIManager::instance()->rank(), block->getId().getID())); el->MPITrait.setOwner(Owner(MPIManager::instance()->rank(), block.getId().getID()));
(*bs)[0].add(ellipsoid); ellipsoid = static_cast<EllipsoidID>(&bs.add(std::move(el)));
} }
} }
} }
...@@ -70,12 +69,12 @@ EllipsoidID createEllipsoid( BodyStorage& globalStorage, BlockStorage& blocks, B ...@@ -70,12 +69,12 @@ EllipsoidID createEllipsoid( BodyStorage& globalStorage, BlockStorage& blocks, B
{ {
// Logging the successful creation of the Ellipsoid // Logging the successful creation of the Ellipsoid
WALBERLA_LOG_DETAIL( WALBERLA_LOG_DETAIL(
"Created Ellipsoid " << ellipsoid->getSystemID() << "\n" "Created Ellipsoid " << ellipsoid->getSystemID() << "\n"
<< " User-ID = " << uid << "\n" << " User-ID = " << uid << "\n"
<< " Global position = " << gpos << "\n" << " Global position = " << gpos << "\n"
<< " Semi-axes = " << semiAxes << "\n" << " Semi-axes = " << semiAxes << "\n"
<< " LinVel = " << ellipsoid->getLinearVel() << "\n" << " LinVel = " << ellipsoid->getLinearVel() << "\n"
<< " Material = " << Material::getName( material ) << " Material = " << Material::getName( material )
); );
} }
......
...@@ -45,9 +45,8 @@ PlaneID createPlane( BodyStorage& globalStorage, id_t uid, Vec3 normal, const Ve ...@@ -45,9 +45,8 @@ PlaneID createPlane( BodyStorage& globalStorage, id_t uid, Vec3 normal, const Ve
const id_t sid( UniqueID<RigidBody>::createGlobal() ); const id_t sid( UniqueID<RigidBody>::createGlobal() );
PlaneID plane = new Plane( sid, uid, gpos, normal, normal*gpos, material ); PlanePtr pl = std::make_unique<Plane>( sid, uid, gpos, normal, normal*gpos, material );
PlaneID plane = static_cast<PlaneID>(&globalStorage.add(std::move(pl)));
globalStorage.add(plane);
// Logging the successful creation of the plane // Logging the successful creation of the plane
WALBERLA_LOG_DETAIL( "Created plane " << sid << "\n" WALBERLA_LOG_DETAIL( "Created plane " << sid << "\n"
......
...@@ -42,32 +42,31 @@ SphereID createSphere( BodyStorage& globalStorage, BlockStorage& blocks, BlockDa ...@@ -42,32 +42,31 @@ SphereID createSphere( BodyStorage& globalStorage, BlockStorage& blocks, BlockDa
if( radius <= real_c(0) ) if( radius <= real_c(0) )
throw std::invalid_argument( "Invalid sphere radius" ); throw std::invalid_argument( "Invalid sphere radius" );
SphereID sphere = NULL; SphereID sphere = nullptr;
if (global) if (global)
{ {
const id_t sid = UniqueID<RigidBody>::createGlobal(); const id_t sid = UniqueID<RigidBody>::createGlobal();
WALBERLA_ASSERT_EQUAL(communicating, false); WALBERLA_ASSERT_EQUAL(communicating, false);
WALBERLA_ASSERT_EQUAL(infiniteMass, true); WALBERLA_ASSERT_EQUAL(infiniteMass, true);
sphere = new Sphere(sid, uid, gpos, Vec3(0,0,0), Quat(), radius, material, global, false, true); SpherePtr sp = std::make_unique<Sphere>(sid, uid, gpos, Vec3(0,0,0), Quat(), radius, material, global, false, true);
globalStorage.add(sphere); sphere = static_cast<SphereID>(&globalStorage.add( std::move(sp) ));
} else } else
{ {
for (auto it = blocks.begin(); it != blocks.end(); ++it){ for (auto& block : blocks){
IBlock* block = (&(*it)); if (block.getAABB().contains(gpos))
if (block->getAABB().contains(gpos))
{ {
const id_t sid( UniqueID<RigidBody>::create() ); const id_t sid( UniqueID<RigidBody>::create() );
Storage* bs = block->getData<Storage>(storageID); BodyStorage& bs = (*block.getData<Storage>(storageID))[0];
sphere = new Sphere(sid, uid, gpos, Vec3(0,0,0), Quat(), radius, material, global, communicating, infiniteMass); SpherePtr sp = std::make_unique<Sphere>(sid, uid, gpos, Vec3(0,0,0), Quat(), radius, material, global, communicating, infiniteMass);
sphere->MPITrait.setOwner(Owner(MPIManager::instance()->rank(), block->getId().getID())); sp->MPITrait.setOwner(Owner(MPIManager::instance()->rank(), block.getId().getID()));
(*bs)[0].add(sphere); sphere = static_cast<SphereID>(&bs.add( std::move(sp) ));
} }
} }
} }
if (sphere != NULL) if (sphere != nullptr)
{ {
// Logging the successful creation of the sphere // Logging the successful creation of the sphere
WALBERLA_LOG_DETAIL( WALBERLA_LOG_DETAIL(
......
...@@ -41,32 +41,31 @@ SquirmerID createSquirmer( BodyStorage& globalStorage, BlockStorage& blocks, Blo ...@@ -41,32 +41,31 @@ SquirmerID createSquirmer( BodyStorage& globalStorage, BlockStorage& blocks, Blo
if( radius <= real_c(0) ) if( radius <= real_c(0) )
throw std::invalid_argument( "Invalid squirmer radius" ); throw std::invalid_argument( "Invalid squirmer radius" );
SquirmerID squirmer = NULL; SquirmerID squirmer = nullptr;
if (global) if (global)
{ {
const id_t sid = UniqueID<RigidBody>::createGlobal(); const id_t sid = UniqueID<RigidBody>::createGlobal();
WALBERLA_ASSERT_EQUAL(communicating, false); WALBERLA_ASSERT_EQUAL(communicating, false);
WALBERLA_ASSERT_EQUAL(infiniteMass, true); WALBERLA_ASSERT_EQUAL(infiniteMass, true);
squirmer = new Squirmer(sid, uid, gpos, Vec3(0,0,0), Quat(), radius, squirmerVelocity, squirmerBeta, material, global, false, true); SquirmerPtr sq = std::make_unique<Squirmer>(sid, uid, gpos, Vec3(0,0,0), Quat(), radius, squirmerVelocity, squirmerBeta, material, global, false, true);
globalStorage.add(squirmer); squirmer = static_cast<SquirmerID>(&globalStorage.add(std::move(sq)));
} else } else
{ {
for (auto it = blocks.begin(); it != blocks.end(); ++it){ for (auto& block : blocks){
IBlock* block = (&(*it)); if (block.getAABB().contains(gpos))
if (block->getAABB().contains(gpos))
{ {
const id_t sid( UniqueID<RigidBody>::create() ); const id_t sid( UniqueID<RigidBody>::create() );
Storage* bs = block->getData<Storage>(storageID); BodyStorage& bs = (*block.getData<Storage>(storageID))[0];
squirmer = new Squirmer(sid, uid, gpos, Vec3(0,0,0), Quat(), radius, squirmerVelocity, squirmerBeta, material, global, communicating, infiniteMass); SquirmerPtr sq = std::make_unique<Squirmer>(sid, uid, gpos, Vec3(0,0,0), Quat(), radius, squirmerVelocity, squirmerBeta, material, global, communicating, infiniteMass);
squirmer->MPITrait.setOwner(Owner(MPIManager::instance()->rank(), block->getId().getID())); sq->MPITrait.setOwner(Owner(MPIManager::instance()->rank(), block.getId().getID()));
(*bs)[0].add(squirmer); squirmer = static_cast<SquirmerID>(&bs.add( std::move(sq) ));
} }
} }
} }
if (squirmer != NULL) if (squirmer != nullptr)
{ {
// Logging the successful creation of the squirmer // Logging the successful creation of the squirmer
WALBERLA_LOG_DETAIL( WALBERLA_LOG_DETAIL(
......
...@@ -75,32 +75,31 @@ Union<BodyTypeTuple>* createUnion( BodyStorage& globalStorage, BlockStorage& b ...@@ -75,32 +75,31 @@ Union<BodyTypeTuple>* createUnion( BodyStorage& globalStorage, BlockStorage& b
if (Union<BodyTypeTuple>::getStaticTypeID() == std::numeric_limits<id_t>::max()) if (Union<BodyTypeTuple>::getStaticTypeID() == std::numeric_limits<id_t>::max())
throw std::runtime_error("Union TypeID not initalized!"); throw std::runtime_error("Union TypeID not initalized!");
Union<BodyTypeTuple>* bd = NULL; Union<BodyTypeTuple>* bd = nullptr;
if (global) if (global)
{ {
const id_t sid = UniqueID<RigidBody>::createGlobal(); const id_t sid = UniqueID<RigidBody>::createGlobal();
WALBERLA_ASSERT_EQUAL(communicating, false); WALBERLA_ASSERT_EQUAL(communicating, false);
WALBERLA_ASSERT_EQUAL(infiniteMass, true); WALBERLA_ASSERT_EQUAL(infiniteMass, true);
bd = new Union<BodyTypeTuple>(sid, uid, gpos, Vec3(0,0,0), Quat(), global, false, true); auto un = std::make_unique<Union<BodyTypeTuple>>(sid, uid, gpos, Vec3(0,0,0), Quat(), global, false, true);
globalStorage.add(bd); bd = static_cast<Union<BodyTypeTuple>*>(&globalStorage.add(std::move(un)));
} else } else
{ {
for (auto it = blocks.begin(); it != blocks.end(); ++it){ for (auto& block : blocks){
IBlock* block = (&(*it)); if (block.getAABB().contains(gpos))
if (block->getAABB().contains(gpos))
{ {
const id_t sid( UniqueID<RigidBody>::create() ); const id_t sid( UniqueID<RigidBody>::create() );
Storage* bs = block->getData<Storage>(storageID); BodyStorage& bs = (*block.getData<Storage>(storageID))[0];
bd = new Union<BodyTypeTuple>(sid, uid, gpos, Vec3(0,0,0), Quat(), global, communicating, infiniteMass); auto un = std::make_unique<Union<BodyTypeTuple>>(sid, uid, gpos, Vec3(0,0,0), Quat(), global, communicating, infiniteMass);
bd->MPITrait.setOwner(Owner(MPIManager::instance()->rank(), block->getId().getID())); un->MPITrait.setOwner(Owner(MPIManager::instance()->rank(), block.getId().getID()));
(*bs)[0].add(bd); bd = static_cast<Union<BodyTypeTuple>*>(&bs.add(std::move(un)));
} }
} }
} }
if (bd != NULL) if (bd != nullptr)
{ {
// Logging the successful creation of the box // Logging the successful creation of the box
WALBERLA_LOG_DETAIL( WALBERLA_LOG_DETAIL(
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment