Commit 1ede21b0 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#1529 Coords: use shared_ptr instead of a combination of pointers and unique_ptr.

parent 29ccd9ad
......@@ -148,7 +148,7 @@ namespace MoReFEM
}
void MovemeshHelper::MoveCoords(const Coords::vector_unique_ptr& coords_list,
void MovemeshHelper::MoveCoords(const Coords::vector_shared_ptr& coords_list,
const ::MoReFEM::Wrappers::Petsc
::AccessVectorContent<Utilities::Access::read_only>& vector_content,
From from) const
......
......@@ -196,7 +196,7 @@ namespace MoReFEM
* of the mesh.
*
*/
void MoveCoords(const Coords::vector_unique_ptr& coords_list,
void MoveCoords(const Coords::vector_shared_ptr& coords_list,
const ::MoReFEM::Wrappers::Petsc
::AccessVectorContent<Utilities::Access::read_only>& vector_content,
From from) const;
......
......@@ -166,7 +166,7 @@ namespace MoReFEM
void CoordsListHelper(const NodeBearer::vector_shared_ptr& node_bearer_list,
Coords::vector_raw_ptr& reduced_coords_list)
Coords::vector_shared_ptr& reduced_coords_list)
{
for (const auto& node_bearer_ptr : node_bearer_list)
{
......@@ -221,19 +221,19 @@ namespace MoReFEM
Utilities::PointerComparison::Equal<GeometricElt::shared_ptr>());
// Extract the list of \a Coords from the node bearer lists.
Coords::vector_raw_ptr processor_wise_coords_list;
Coords::vector_raw_ptr ghosted_coords_list;
Coords::vector_shared_ptr processor_wise_coords_list;
Coords::vector_shared_ptr ghosted_coords_list;
CoordsListHelper(processor_wise_node_bearer_list, processor_wise_coords_list);
CoordsListHelper(ghost_node_bearer_list, ghosted_coords_list);
Utilities::EliminateDuplicate(processor_wise_coords_list,
Utilities::PointerComparison::Less<Coords*>(),
Utilities::PointerComparison::Equal<Coords*>());
Utilities::PointerComparison::Less<Coords::shared_ptr>(),
Utilities::PointerComparison::Equal<Coords::shared_ptr>());
Utilities::EliminateDuplicate(ghosted_coords_list,
Utilities::PointerComparison::Less<Coords*>(),
Utilities::PointerComparison::Equal<Coords*>());
Utilities::PointerComparison::Less<Coords::shared_ptr>(),
Utilities::PointerComparison::Equal<Coords::shared_ptr>());
const auto proc_wise_coords_list_begin = processor_wise_coords_list.cbegin();
const auto proc_wise_coords_list_end = processor_wise_coords_list.cend();
......@@ -241,12 +241,12 @@ namespace MoReFEM
const auto it_partition =
std::partition(ghosted_coords_list.begin(),
ghosted_coords_list.end(),
[&proc_wise_coords_list_begin, &proc_wise_coords_list_end](const Coords* coords)
[&proc_wise_coords_list_begin, &proc_wise_coords_list_end](const Coords::shared_ptr coords)
{
return !std::binary_search(proc_wise_coords_list_begin,
proc_wise_coords_list_end,
coords,
Utilities::PointerComparison::Less<const Coords*>());
Utilities::PointerComparison::Less<const Coords::shared_ptr>());
});
ghosted_coords_list.erase(it_partition, ghosted_coords_list.end());
......
......@@ -120,18 +120,10 @@ namespace MoReFEM
*
* By design all \a Coords object should be stored there.
*/
using unique_ptr = std::unique_ptr<self>;
using shared_ptr = std::shared_ptr<self>;
//! Vector of unique_ptr.
using vector_unique_ptr = std::vector<unique_ptr>;
/*!
* \brief Vector of raw pointers.
*
* By design all \a Coords object should be stored in \a Mesh; when other objects (e.g.
* \a Interface) needs them they should point to the underlying pointer (given by std::unique_ptr::get()).
*/
using vector_raw_ptr = std::vector<self*>;
//! Vector of shared_ptr.
using vector_shared_ptr = std::vector<shared_ptr>;
//! Friendship to Mesh so that it can update position index.
friend Mesh;
......
......@@ -27,24 +27,24 @@ namespace MoReFEM
{
Coords::unique_ptr Factory::Origin()
Coords::shared_ptr Factory::Origin()
{
auto ptr = new Coords;
return Coords::unique_ptr(ptr);
return Coords::shared_ptr(ptr);
}
Coords::unique_ptr Factory::FromComponents(double x, double y, double z, const double space_unit)
Coords::shared_ptr Factory::FromComponents(double x, double y, double z, const double space_unit)
{
auto ptr = new Coords(x, y, z, space_unit);
return Coords::unique_ptr(ptr);
return Coords::shared_ptr(ptr);
}
Coords::unique_ptr Factory::FromStream(unsigned int Ncoor, std::istream& stream, const double space_unit)
Coords::shared_ptr Factory::FromStream(unsigned int Ncoor, std::istream& stream, const double space_unit)
{
auto ptr = new Coords(Ncoor, stream, space_unit);
return Coords::unique_ptr(ptr);
return Coords::shared_ptr(ptr);
}
......
......@@ -46,7 +46,7 @@ namespace MoReFEM
*
* \return Pointer to newly created \a Coords.
*/
static Coords::unique_ptr Origin();
static Coords::shared_ptr Origin();
/*!
* \brief Create a \a Coords objets from its three components.
......@@ -55,7 +55,7 @@ namespace MoReFEM
*
* \return Pointer to newly created \a Coords.
*/
static Coords::unique_ptr FromComponents(double x, double y, double z, const double space_unit);
static Coords::shared_ptr FromComponents(double x, double y, double z, const double space_unit);
/*!
* \brief Create a \a Coords objets from its three components.
......@@ -64,7 +64,7 @@ namespace MoReFEM
*
* \return Pointer to newly created \a Coords.
*/
static Coords::unique_ptr FromStream(unsigned int Ncoor, std::istream& stream, const double space_unit);
static Coords::shared_ptr FromStream(unsigned int Ncoor, std::istream& stream, const double space_unit);
/*!
* \brief Create a \a Coords objets from a 3D array.
......@@ -74,7 +74,7 @@ namespace MoReFEM
* \return Pointer to newly created \a Coords.
*/
template<typename T>
static Coords::unique_ptr FromArray(T&& value, const double space_unit);
static Coords::shared_ptr FromArray(T&& value, const double space_unit);
};
......
......@@ -29,10 +29,10 @@ namespace MoReFEM
template<typename T>
Coords::unique_ptr Factory::FromArray(T&& value, const double space_unit)
Coords::shared_ptr Factory::FromArray(T&& value, const double space_unit)
{
auto ptr = new Coords(value, space_unit);
return Coords::unique_ptr(ptr);
return Coords::shared_ptr(ptr);
}
......
......@@ -114,8 +114,8 @@ namespace MoReFEM
//
// double det;
//
// Coords::unique_ptr buf_ptr = Internal::CoordsNS::Factory::Origin();
// Coords::unique_ptr coords_from_guess_ptr = Internal::CoordsNS::Factory::Origin();
// Coords::shared_ptr buf_ptr = Internal::CoordsNS::Factory::Origin();
// Coords::shared_ptr coords_from_guess_ptr = Internal::CoordsNS::Factory::Origin();
//
// auto& buf = *buf_ptr;
// auto& coords_from_guess = *coords_from_guess_ptr;
......
......@@ -55,7 +55,7 @@ namespace MoReFEM
GeometricElt::unique_ptr GeometricEltFactory
::CreateFromEnsightName(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
const std::string& geometric_elt_name,
std::istream& stream) const
{
......
......@@ -61,7 +61,7 @@ namespace MoReFEM
//! Alias for a function which will create a 'GeometricElt' out of a constructor with istream argument.
using CreateGeometricEltCallBackIstream = std::function<GeometricElt::unique_ptr(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::istream&)>;
......@@ -157,7 +157,7 @@ namespace MoReFEM
* returned.
*/
GeometricElt::unique_ptr CreateFromEnsightName(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
const std::string& geometric_elt_name,
std::istream& stream) const;
......
......@@ -93,7 +93,7 @@ namespace MoReFEM
//! \copydoc doxygen_hide_geom_elt_stream_constructor
explicit TGeometricElt(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::istream& stream);
......@@ -106,7 +106,7 @@ namespace MoReFEM
* Vector should be the NcoordsT-long
*/
explicit TGeometricElt(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
unsigned int index,
std::vector<unsigned int>&& coords_indexes);
......@@ -119,7 +119,7 @@ namespace MoReFEM
* Index should be specified through dedicated method.
*/
explicit TGeometricElt(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::vector<unsigned int>&& coords_indexes);
......@@ -296,7 +296,7 @@ namespace MoReFEM
//! \copydoc doxygen_hide_geometric_elt_read_medit_method
virtual void ReadMeditFormat(const Coords::vector_unique_ptr& mesh_coords_list,
virtual void ReadMeditFormat(const Coords::vector_shared_ptr& mesh_coords_list,
libmeshb_int libmesh_mesh_index,
unsigned int Ncoord_in_mesh,
int& reference_index) override final;
......
......@@ -42,7 +42,7 @@ namespace MoReFEM
template<class TraitsRefGeomEltT>
TGeometricElt<TraitsRefGeomEltT>::TGeometricElt(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
unsigned int index,
std::vector<unsigned int>&& coords)
: GeometricElt(mesh_unique_id, mesh_coords_list, index, std::move(coords))
......@@ -53,7 +53,7 @@ namespace MoReFEM
template<class TraitsRefGeomEltT>
TGeometricElt<TraitsRefGeomEltT>::TGeometricElt(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::vector<unsigned int>&& coords)
: GeometricElt(mesh_unique_id, mesh_coords_list, std::move(coords))
{
......@@ -63,7 +63,7 @@ namespace MoReFEM
template<class TraitsRefGeomEltT>
TGeometricElt<TraitsRefGeomEltT>::TGeometricElt(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::istream& stream)
: GeometricElt(mesh_unique_id)
{
......@@ -265,7 +265,7 @@ namespace MoReFEM
template<class TraitsRefGeomEltT>
void TGeometricElt<TraitsRefGeomEltT>::ReadMeditFormat(const Coords::vector_unique_ptr& mesh_coords_list,
void TGeometricElt<TraitsRefGeomEltT>::ReadMeditFormat(const Coords::vector_shared_ptr& mesh_coords_list,
libmeshb_int libmesh_mesh_index,
unsigned int Ncoord_in_mesh,
int& label_index)
......
......@@ -32,7 +32,7 @@ namespace MoReFEM
GeometricElt::GeometricElt(const unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
unsigned int index,
std::vector<unsigned int>&& coords)
: GeometricElt(mesh_unique_id)
......@@ -43,7 +43,7 @@ namespace MoReFEM
GeometricElt::GeometricElt(const unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::vector<unsigned int>&& coords)
: GeometricElt(mesh_unique_id,
mesh_coords_list,
......@@ -52,11 +52,11 @@ namespace MoReFEM
{ }
void GeometricElt::SetCoordsList(const Coords::vector_unique_ptr& mesh_coords_list,
void GeometricElt::SetCoordsList(const Coords::vector_shared_ptr& mesh_coords_list,
std::vector<unsigned int>&& coords_list)
{
assert(!mesh_coords_list.empty());
using difference_type = Coords::vector_unique_ptr::difference_type;
using difference_type = Coords::vector_shared_ptr::difference_type;
for (auto coord_index : coords_list)
{
......@@ -91,7 +91,7 @@ namespace MoReFEM
assert(it != end);
assert(*it);
coords_list_.push_back(it->get()); // Store raw pointer.
coords_list_.push_back(*it);
}
}
......
......@@ -126,7 +126,7 @@ namespace MoReFEM
* \copydoc doxygen_hide_geom_elt_mesh_coords_list_and_coord_indexes_constructor_arg
*/
explicit GeometricElt(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
unsigned int index,
std::vector<unsigned int>&& coords_indexes);
......@@ -139,7 +139,7 @@ namespace MoReFEM
* Index should be specified through dedicated method #SetIndex
*/
explicit GeometricElt(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::vector<unsigned int>&& coords_indexes);
//! Destructor
......@@ -219,7 +219,7 @@ namespace MoReFEM
MeshLabel::const_shared_ptr GetMeshLabelPtr() const noexcept;
//! Get the coords as a vector.
const Coords::vector_raw_ptr& GetCoordsList() const noexcept;
const Coords::vector_shared_ptr& GetCoordsList() const noexcept;
//! Get the ith coords index.
//! \param i Index of the sought \a Coords object used to define the geometric element.
......@@ -473,7 +473,7 @@ namespace MoReFEM
*/
//! \copydoc doxygen_hide_geometric_elt_read_medit_method
virtual void ReadMeditFormat(const Coords::vector_unique_ptr& mesh_coords_list,
virtual void ReadMeditFormat(const Coords::vector_shared_ptr& mesh_coords_list,
libmeshb_int libmesh_mesh_index,
unsigned int Ncoord_in_mesh,
int& reference_index) = 0;
......@@ -491,7 +491,7 @@ namespace MoReFEM
* Beware: an error will be raised if the input vector size is not what is expected !
* Note: it is not passed by reference of purpose, to let compiler optimize it by copy elision
*/
void SetCoordsList(const Coords::vector_unique_ptr& mesh_coords_list,
void SetCoordsList(const Coords::vector_shared_ptr& mesh_coords_list,
std::vector<unsigned int>&& coords_indexes);
......@@ -529,7 +529,7 @@ namespace MoReFEM
MeshLabel::const_shared_ptr mesh_label_ = nullptr;
//! Coords that belong to the geometric element.
Coords::vector_raw_ptr coords_list_;
Coords::vector_shared_ptr coords_list_;
//! List of vertice.
Vertex::vector_shared_ptr vertex_list_;
......
......@@ -21,7 +21,7 @@ namespace MoReFEM
{
inline const Coords::vector_raw_ptr& GeometricElt::GetCoordsList() const noexcept
inline const Coords::vector_shared_ptr& GeometricElt::GetCoordsList() const noexcept
{
return coords_list_;
}
......
......@@ -26,7 +26,7 @@ namespace MoReFEM
auto CreateEnsight(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::istream& in)
{
return std::make_unique<Hexahedron20>(mesh_unique_id, mesh_coords_list, in);
......@@ -57,14 +57,14 @@ namespace MoReFEM
Hexahedron20::Hexahedron20(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::istream& stream)
: Internal::GeomEltNS::TGeometricElt<RefGeomEltNS::Traits::Hexahedron20>(mesh_unique_id, mesh_coords_list, stream)
{ }
Hexahedron20::Hexahedron20(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::vector<unsigned int>&& coords)
: Internal::GeomEltNS::TGeometricElt<RefGeomEltNS::Traits::Hexahedron20>(mesh_unique_id, mesh_coords_list, std::move(coords))
{ }
......
......@@ -42,12 +42,12 @@ namespace MoReFEM
//! \copydoc doxygen_hide_geom_elt_stream_constructor
explicit Hexahedron20(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::istream& stream);
//! \copydoc doxygen_hide_geom_elt_vector_coords_constructor
explicit Hexahedron20(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::vector<unsigned int>&& coords_index_list);
//! Destructor.
......
......@@ -48,14 +48,14 @@ namespace MoReFEM
Hexahedron27::Hexahedron27(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::istream& stream)
: Internal::GeomEltNS::TGeometricElt<RefGeomEltNS::Traits::Hexahedron27>(mesh_unique_id, mesh_coords_list, stream)
{ }
Hexahedron27::Hexahedron27(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::vector<unsigned int>&& coords)
: Internal::GeomEltNS::TGeometricElt<RefGeomEltNS::Traits::Hexahedron27>(mesh_unique_id, mesh_coords_list, std::move(coords))
{ }
......
......@@ -42,12 +42,12 @@ namespace MoReFEM
//! \copydoc doxygen_hide_geom_elt_stream_constructor
explicit Hexahedron27(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::istream& stream);
//! \copydoc doxygen_hide_geom_elt_vector_coords_constructor
explicit Hexahedron27(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::vector<unsigned int>&& coords_index_list);
//! Destructor.
......
......@@ -26,7 +26,7 @@ namespace MoReFEM
auto CreateEnsight(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::istream& in)
{
return std::make_unique<Hexahedron8>(mesh_unique_id, mesh_coords_list, in);
......@@ -57,14 +57,14 @@ namespace MoReFEM
Hexahedron8::Hexahedron8(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::istream& stream)
: Internal::GeomEltNS::TGeometricElt<RefGeomEltNS::Traits::Hexahedron8>(mesh_unique_id, mesh_coords_list, stream)
{ }
Hexahedron8::Hexahedron8(unsigned int mesh_unique_id,
const Coords::vector_unique_ptr& mesh_coords_list,
const Coords::vector_shared_ptr& mesh_coords_list,
std::vector<unsigned int>&& coords)
: Internal::GeomEltNS::TGeometricElt<RefGeomEltNS::Traits::Hexahedron8>(mesh_unique_id, mesh_coords_list, std::move(coords))
{ }
......
Markdown is supported
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