Skip to content
Snippets Groups Projects
Commit 74736cec authored by Dr. Felix Tobias Schindler's avatar Dr. Felix Tobias Schindler
Browse files

[spaces...fem] hold shared_ptr of grid part (again)

This fixes a segfault, since after a copy of the space the backend_ would
still hold a reference to the grid_part_ of other which is not guaranteed
to still exist. Thus we would need to make a copy of backend_ (not possible
with dune-fem) or create a new backend_ (which would mathematically
hopefully be a copy, but we do not know about dune-fems internals so we can
not be sure) or again hold a shared_ptr of the backend_ and the grid_part_
and the grid_view_, which I opted for.
parent 54a62a5e
Branches
No related tags found
No related merge requests found
......@@ -106,11 +106,11 @@ public:
typedef Dune::Stuff::LA::SparsityPatternDefault PatternType;
FemBased(GridPartType gridP)
: gridPart_(gridP)
, gridView_(gridPart_.gridView())
, backend_(std::make_shared<BackendType>(gridPart_))
, mapper_(std::make_shared<MapperType>(backend_->blockMapper()))
, communicator_(CommunicationChooserType::create(gridView_))
: gridPart_(new GridPartType(gridP))
, gridView_(new GridViewType(gridPart_->gridView()))
, backend_(new BackendType(*gridPart_))
, mapper_(new MapperType(backend_->blockMapper()))
, communicator_(CommunicationChooserType::create(*gridView_))
{
}
......@@ -132,12 +132,12 @@ public:
const GridPartType& grid_part() const
{
return gridPart_;
return *gridPart_;
}
const GridViewType& grid_view() const
{
return gridView_;
return *gridView_;
}
const BackendType& backend() const
......@@ -162,8 +162,8 @@ public:
}
private:
GridPartType gridPart_;
const GridViewType gridView_;
std::shared_ptr<GridPartType> gridPart_;
const std::shared_ptr<const GridViewType> gridView_;
const std::shared_ptr<const BackendType> backend_;
const std::shared_ptr<const MapperType> mapper_;
mutable std::shared_ptr<CommunicatorType> communicator_;
......
......@@ -109,47 +109,29 @@ public:
typedef Dune::Stuff::LA::SparsityPatternDefault PatternType;
FemBased(GridPartType gridP)
: gridPart_(gridP)
, gridView_(gridPart_.gridView())
, backend_(std::make_shared<const BackendType>(const_cast<GridPartType&>(gridPart_)))
, mapper_(backend_->blockMapper())
, communicator_(CommunicationChooserType::create(gridView_))
: gridPart_(new GridPartType(gridP))
, gridView_(new GridViewType(gridPart_->gridView()))
, backend_(new BackendType(*gridPart_))
, mapper_(new MapperType(backend_->blockMapper()))
, communicator_(CommunicationChooserType::create(*gridView_))
{
}
//! explicitly defaulted ctor was still implcitly deleted although no non-static members have reference type
FemBased(const ThisType& other)
: gridPart_(other.gridPart_)
, gridView_(other.gridView_)
, backend_(other.backend_)
, mapper_(other.mapper_)
, communicator_(DSC::make_unique<CommunicatorType>(*other.communicator_))
{
assert(communicator_);
}
//! explicitly defaulted ctor was still implcitly deleted although no non-static members have reference type
FemBased(ThisType&& other)
: gridPart_(other.gridPart_)
, gridView_(other.gridView_)
, backend_(other.backend_)
, mapper_(other.mapper_)
, communicator_(std::move(other.communicator_))
{
assert(communicator_);
}
FemBased(const ThisType& other) = default;
FemBased(ThisType&& source) = default;
ThisType& operator=(const ThisType& other) = delete;
ThisType& operator=(ThisType&& source) = delete;
const GridPartType& grid_part() const
{
return gridPart_;
return *gridPart_;
}
const GridViewType& grid_view() const
{
return gridView_;
return *gridView_;
}
const BackendType& backend() const
......@@ -159,7 +141,7 @@ public:
const MapperType& mapper() const
{
return mapper_;
return *mapper_;
}
BaseFunctionSetType base_function_set(const EntityType& entity) const
......@@ -174,11 +156,11 @@ public:
}
private:
const GridPartType gridPart_;
const GridViewType gridView_;
std::shared_ptr<GridPartType> gridPart_;
const std::shared_ptr<const GridViewType> gridView_;
const std::shared_ptr<const BackendType> backend_;
const MapperType mapper_;
mutable std::unique_ptr<CommunicatorType> communicator_;
const std::shared_ptr<const MapperType> mapper_;
mutable std::shared_ptr<CommunicatorType> communicator_;
}; // class FemBased< ..., 1 >
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment