Commit e8dd7731 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#954 Make sure the numbering of volumes is done mesh by mesh.

parent 2c48fb54
......@@ -10,13 +10,38 @@
#include "Geometry/Interfaces/Instances/Volume.hpp"
#include "Geometry/GeometricElt/GeometricElt.hpp"
#include "Geometry/Mesh/Internal/GeometricMeshRegionManager.hpp"
namespace HappyHeart
{
unsigned int Volume::Nvolume_ = 0u;
namespace // anonymous
{
/*!
* \brief Add a new volume to a mesh, and increment accordingly NvolumePerMesh().
*
* \param[in] mesh_identifier Identifier of the mesh to which the Volume is added.
*
* \return Index of the newly added volume. This index is 0 for first volume, then 1, and so forth...
*/
unsigned int AddVolume(unsigned int mesh_identifier,
std::map<unsigned int, unsigned int>& Nvolume_per_mesh);
} // namespace anonymous
std::map<unsigned int, unsigned int>& Volume::NvolumePerMesh()
{
static std::map<unsigned int, unsigned int> ret;
return ret;
}
Volume::Volume(const GeometricElt::shared_ptr& geometric_elt)
......@@ -24,7 +49,9 @@ namespace HappyHeart
geometric_elt_(geometric_elt)
{
assert(!(!geometric_elt));
SetIndex(Nvolume_++);
decltype(auto) mesh_id = geometric_elt->GetMeshIdentifier();
SetIndex(AddVolume(mesh_id, NvolumePerMesh()));
}
......@@ -39,7 +66,29 @@ namespace HappyHeart
return shared_ptr->GetCoordsList();
}
namespace // anonymous
{
unsigned int AddVolume(unsigned int mesh_identifier,
std::map<unsigned int, unsigned int>& Nvolume_per_mesh)
{
auto it = Nvolume_per_mesh.find(mesh_identifier);
if (it == Nvolume_per_mesh.cend())
{
Nvolume_per_mesh.insert({mesh_identifier, 1u});
return 0u;
}
else
return it->second++;
}
} // namespace anonymous
} // namespace HappyHeart
......@@ -107,15 +107,19 @@ namespace HappyHeart
//! Get the list of coords that belongs to the interface.
const Coords::vector_shared_ptr& GetVertexCoordsList() const noexcept override;
private:
/*!
* \brief Number of volumes built so far.
* \brief Number of volumes built so far for each mesh.
*
* \internal <b><tt>[internal]</tt></b> This is a purely internal attribute used in volume creation; should not
* be used outside of Volume.cpp!
*
* \internal <b><tt>[internal]</tt></b> This is a purely internal attribute used in volume creation; should not be used outside of
* Volume.cpp!
* Key is the identifier of the mesh.
* Value if the number of volumes built so far for each mesh.
*/
static unsigned int Nvolume_;
static std::map<unsigned int, unsigned int>& NvolumePerMesh();
/*!
* \brief Pointer to the geometric element in which the Volume is built.
......
......@@ -121,7 +121,7 @@ namespace HappyHeart
*/
void SetIndex(unsigned int id) noexcept;
//! Get the identifier associated to this interface.
//! Get the identifier associated to this interface. This index is assumed to be in [0, Ninterface of same type[.
unsigned int GetIndex() const noexcept;
//! Get the list of coords that belongs to the interface.
......@@ -183,6 +183,8 @@ namespace HappyHeart
* Identifier is unique for all interfaces of the same nature: there should be for instance only
* one edge with id = 124.
*
* This index is assumed to be in [0, Ninterface of same type[.
*
*/
unsigned int id_ = NumericNS::UninitializedIndex<unsigned int>();
......
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