Skip to content
Snippets Groups Projects
Verified Commit d94184df authored by Santiago Ospina De Los Ríos's avatar Santiago Ospina De Los Ríos
Browse files

Add RAII to ug domain creation/deletion

parent 1db7693c
Branches
Tags
1 merge request!754Add RAII to ug domain creation/deletion in grid factory
Pipeline #74384 passed
......@@ -299,9 +299,16 @@ createGrid()
grid_->numBoundarySegments_ = boundarySegments.size();
std::string domainName = grid_->name_ + "_Domain";
auto* ugDomain =UG_NS<dimworld>::CreateDomain(domainName.c_str(), // The domain name
auto ugDomainDeleter = [domainName](auto ptr){
std::destroy_at(ptr);
UG_NS<dimworld>::RemoveDomain(domainName.c_str());
};
auto* ugDomainRaw =UG_NS<dimworld>::CreateDomain(domainName.c_str(), // The domain name
grid_->numBoundarySegments_,
noOfBNodes);
using UGDomainPtr = std::unique_ptr<std::decay_t<decltype(*ugDomainRaw)>, decltype(ugDomainDeleter)>;
UGDomainPtr ugDomain{std::exchange(ugDomainRaw, nullptr), std::move(ugDomainDeleter)};
if (ugDomain == nullptr)
DUNE_THROW(GridError, "Calling UG::" << dimworld << "d::CreateDomain failed!");
......@@ -573,12 +580,6 @@ createBegin()
elementTypes_.resize(0);
elementVertices_.resize(0);
vertexPositions_.resize(0);
// //////////////////////////////////////////////////////////
// Delete the UG domain, if it exists
// //////////////////////////////////////////////////////////
std::string domainName = grid_->name_ + "_Domain";
UG_NS<dimworld>::RemoveDomain(domainName.c_str());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment