From 31c3a3395c8f91cc57fcabc6be126e73cf52fa53 Mon Sep 17 00:00:00 2001 From: Gilles Grospellier Date: Fri, 23 Oct 2026 16:20:58 +0200 Subject: [PATCH 1/2] [arcane,core+mesh] Use a temporary buffer for node connectivity of polyhedron types. --- arcane/src/arcane/core/ItemTypeInfo.h | 10 ++-------- arcane/src/arcane/core/ItemTypeInfoBuilder.cc | 18 +++++++++++++---- arcane/src/arcane/core/ItemTypeInfoBuilder.h | 11 ++++++++++ arcane/src/arcane/core/ItemTypeMng.cc | 19 ++++++++++++++---- arcane/src/arcane/core/ItemTypeMng.h | 6 ++++-- .../core/internal/ItemTypeMngInternal.h | 20 +++++++++++++++---- arcane/src/arcane/mesh/OneMeshItemAdder.cc | 8 ++++++-- 7 files changed, 68 insertions(+), 24 deletions(-) diff --git a/arcane/src/arcane/core/ItemTypeInfo.h b/arcane/src/arcane/core/ItemTypeInfo.h index 0f35e1310..e9b635329 100644 --- a/arcane/src/arcane/core/ItemTypeInfo.h +++ b/arcane/src/arcane/core/ItemTypeInfo.h @@ -18,7 +18,8 @@ #include "arcane/utils/Array.h" #include "arcane/core/ItemTypeId.h" -// No longer used but keep for compatibility +// No longer used but keep for compatibility (October 2026) +// Remove this in future versions of Arcane #include "arcane/core/ItemTypeMng.h" /*---------------------------------------------------------------------------*/ @@ -30,7 +31,6 @@ class ItemTypeMng; /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ - /*! * \ingroup Mesh * \brief Info on a mesh entity type. @@ -39,11 +39,6 @@ class ItemTypeMng; * a hexahedral cell, a quadrilateral cell. * * \sa ItemTypeMng - * - * There should only be one instance per entity type. Creation of a - * type is done by the derived class ItemTypeInfoBuilder. Types must - * be created before any mesh creation (i.e. during - * the initialization of the architecture). */ class ItemTypeInfo { @@ -190,7 +185,6 @@ class ItemTypeInfo Integer m_first_item_index = 0; String m_type_name; const ItemTypeInfo* m_linear_type = this; - ItemTypeMng* m_mng = nullptr; Array* m_ids_buffer = nullptr; }; diff --git a/arcane/src/arcane/core/ItemTypeInfoBuilder.cc b/arcane/src/arcane/core/ItemTypeInfoBuilder.cc index 538124ae2..13d2c248e 100644 --- a/arcane/src/arcane/core/ItemTypeInfoBuilder.cc +++ b/arcane/src/arcane/core/ItemTypeInfoBuilder.cc @@ -42,13 +42,13 @@ _checkDimension(Int16 dim) /*---------------------------------------------------------------------------*/ void ItemTypeInfoBuilder:: -setInfos(ItemTypeMng* mng, ItemTypeId type_id, String type_name, - Dimension dimension, Int32 nb_node, Int32 nb_edge, Int32 nb_face) +_setInfos(Array* ids_buffer, ItemTypeId type_id, String type_name, Dimension dimension, + Int32 nb_node, Int32 nb_edge, Int32 nb_face) { - m_mng = mng; - m_ids_buffer = &mng->m_ids_buffer; + m_ids_buffer = ids_buffer; m_type_id = type_id; m_linear_type_id = type_id; + m_linear_type = this; m_dimension = static_cast(dimension); m_nb_node = nb_node; m_type_name = type_name; @@ -59,6 +59,16 @@ setInfos(ItemTypeMng* mng, ItemTypeId type_id, String type_name, /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ +void ItemTypeInfoBuilder:: +setInfos(ItemTypeMng* mng, ItemTypeId type_id, String type_name, + Dimension dimension, Int32 nb_node, Int32 nb_edge, Int32 nb_face) +{ + _setInfos(&mng->m_ids_buffer, type_id, type_name, dimension, nb_node, nb_edge, nb_face); +} + +/*---------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*/ + void ItemTypeInfoBuilder:: setInfos(ItemTypeMng* mng, ItemTypeId type_id, String type_name, Int32 nb_node, Int32 nb_edge, Int32 nb_face) diff --git a/arcane/src/arcane/core/ItemTypeInfoBuilder.h b/arcane/src/arcane/core/ItemTypeInfoBuilder.h index 3b5d24796..eb9c8d051 100644 --- a/arcane/src/arcane/core/ItemTypeInfoBuilder.h +++ b/arcane/src/arcane/core/ItemTypeInfoBuilder.h @@ -47,6 +47,8 @@ namespace Arcane class ItemTypeInfoBuilder : public ItemTypeInfo { + friend class ItemTypeMng; + public: //! Dimension of the type @@ -197,6 +199,15 @@ class ItemTypeInfoBuilder m_has_center_node = has_center_node; } + private: + + // Only for ItemTypeMng + /*! + * \brief Positions the information for a type. + */ + void _setInfos(Array* ids_buffer, ItemTypeId type_id, String type_name, Dimension dimension, + Int32 nb_node, Int32 nb_edge, Int32 nb_face); + private: void _setNbEdgeAndFace(Integer nb_edge, Integer nb_face); diff --git a/arcane/src/arcane/core/ItemTypeMng.cc b/arcane/src/arcane/core/ItemTypeMng.cc index 9ec77f0d8..adafb62c7 100644 --- a/arcane/src/arcane/core/ItemTypeMng.cc +++ b/arcane/src/arcane/core/ItemTypeMng.cc @@ -1565,16 +1565,27 @@ getPolygonType(Int16 nb_node) const /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ -// Create a custom type to handle the polyhedron -// The type is temporary +/*! + * \brief Create a custom temporary type for generic Polyhedron. + * + * \a ids_buffer will be used to store connectivities informations. + * It must remain valid until the type is no longer used. + * + * \param nb_node number of nodes of the polyhedron. + * \pram faces_nb_node number of nodes of each face. + * \param faces_nodes list of nodes of the faces. The elements + * from `0` to `faces_nb_node[0]-1` are the node index of the first face, + * the elements from `faces_nb_nodes[0]` to `face_nb_nodes[0]+faces_nb_node[1]-1` + * are the nodes index of the second face and so on. + */ ItemTypeInfo* ItemTypeMng:: -_findOrAddPolyhedron(Int16 nb_node, ConstArrayView faces_nb_nodes, ConstArrayView faces_nodes) +_getTemporaryPolyhedron(Array* ids_buffer, Int16 nb_node, ConstArrayView faces_nb_nodes, ConstArrayView faces_nodes) { // TODO: Remove the memory leak when adding information to this type. ItemTypeInfoBuilder* type = m_types_buffer->allocOne(); Int32 nb_face = faces_nb_nodes.size(); // TODO: need compute number of edges. - type->setInfos(this, IT_GenericPolyhedron, "Polyhedron", ItemTypeInfoBuilder::Dimension::Dim3, nb_node, 0, nb_face); + type->_setInfos(ids_buffer, ITI_GenericPolyhedron, "Polyhedron", ItemTypeInfoBuilder::Dimension::Dim3, nb_node, 0, nb_face); type->setIsValidForCell(true); Int32 index_in_face_node = 0; for (Int32 i = 0; i < nb_face; ++i) { diff --git a/arcane/src/arcane/core/ItemTypeMng.h b/arcane/src/arcane/core/ItemTypeMng.h index d3d4aece8..edf0e0b59 100644 --- a/arcane/src/arcane/core/ItemTypeMng.h +++ b/arcane/src/arcane/core/ItemTypeMng.h @@ -83,7 +83,7 @@ class ARCANE_CORE_EXPORT ItemTypeMng public: - /*! + /*! * \brief Effective constructor. * * This method should only be called before initializing @@ -224,7 +224,9 @@ class ARCANE_CORE_EXPORT ItemTypeMng //! Reads types from a file named filename void _readTypes(IParallelSuperMng* parallel_mng, const String& filename); void _addPolygonType(Int16 type_id, Int32 nb_node, const String& type_name); - ItemTypeInfo* _findOrAddPolyhedron(Int16 nb_node, ConstArrayView faces_nb_nodes, ConstArrayView faces_nodes); + ItemTypeInfo* _getTemporaryPolyhedron(Array* ids_buffer, Int16 nb_node, + ConstArrayView faces_nb_nodes, + ConstArrayView faces_nodes); }; /*---------------------------------------------------------------------------*/ diff --git a/arcane/src/arcane/core/internal/ItemTypeMngInternal.h b/arcane/src/arcane/core/internal/ItemTypeMngInternal.h index 364e808ba..a7068aa8f 100644 --- a/arcane/src/arcane/core/internal/ItemTypeMngInternal.h +++ b/arcane/src/arcane/core/internal/ItemTypeMngInternal.h @@ -39,11 +39,23 @@ class ARCANE_CORE_EXPORT ItemTypeMngInternal public: /*! - * \brief Find or add a type for a generic Polyhedron. - */ - ItemTypeInfo* findOrAddPolyhedron(Int16 nb_node, ConstArrayView faces_nb_nodes, ConstArrayView faces_nodes) + * \brief Create a temporary type for generic Polyhedron. + * + * \a ids_buffer will be used to store connectivities informations. + * It must remain valid until the type is no longer used. + * + * \param nb_node number of nodes of the polyhedron. + * \pram faces_nb_node number of nodes of each face. + * \param faces_nodes list of nodes of the faces. The elements + * from `0` to `faces_nb_node[0]-1` are the node index of the first face, + * the elements from `faces_nb_nodes[0]` to `face_nb_nodes[0]+faces_nb_node[1]-1` + * are the nodes index of the second face and so on. + */ + ItemTypeInfo* getTemporaryPolyhedron(Array* ids_buffer, Int16 nb_node, + ConstArrayView faces_nb_node, + ConstArrayView faces_nodes) { - return m_item_type_mng->_findOrAddPolyhedron(nb_node, faces_nb_nodes, faces_nodes); + return m_item_type_mng->_getTemporaryPolyhedron(ids_buffer, nb_node, faces_nb_node, faces_nodes); } private: diff --git a/arcane/src/arcane/mesh/OneMeshItemAdder.cc b/arcane/src/arcane/mesh/OneMeshItemAdder.cc index 18a9b78e3..676586683 100644 --- a/arcane/src/arcane/mesh/OneMeshItemAdder.cc +++ b/arcane/src/arcane/mesh/OneMeshItemAdder.cc @@ -818,6 +818,9 @@ _addOnePolyhedron(Int64 cell_uid, ConstArrayView connectivity_infos, Int3 info() << "AddNewPolyhedronCell nb_connectivity=" << connectivity_infos.size() << " c=" << connectivity_infos; + // TODO: Use a class to handle the creation of the type and store all the working + // buffer instead of re-allocating them for each polyhedron. + // Checks if the cell already exists (in which case nothing is done). // TODO: Search if a cell with same uniqueId() already exists. @@ -889,8 +892,9 @@ _addOnePolyhedron(Int64 cell_uid, ConstArrayView connectivity_infos, Int3 if (is_verbose) info() << "EndCreateTypeForPolyhedron nb_node=" << nodes_of_cell.size(); ItemTypeMngInternal* api = m_item_type_mng->_internalApi(); - ItemTypeInfo* cell_type_info = api->findOrAddPolyhedron(nodes_of_cell.size(), - arcane_faces_nb_node, arcane_faces_nodes); + SmallArray type_ids_buffer; + ItemTypeInfo* cell_type_info = api->getTemporaryPolyhedron(&type_ids_buffer,nodes_of_cell.size(), + arcane_faces_nb_node, arcane_faces_nodes); CellInfoProxy cell_info_proxy(ITI_GenericPolyhedron, cell_type_info, cell_uid, owner, nodes_of_cell, allow_build_face); return _addOneCell(cell_info_proxy); } From 1b5e93214939e2406ad13d5519af34c1c8ade6c9 Mon Sep 17 00:00:00 2001 From: Gilles Grospellier Date: Fri, 23 Oct 2026 16:51:56 +0200 Subject: [PATCH 2/2] [arcane,core+mesh] Fill the polyhedron type from a user instance instead of allocating it in the ItemTypeMng. --- arcane/src/arcane/core/ItemTypeMng.cc | 12 +++++------ arcane/src/arcane/core/ItemTypeMng.h | 6 +++--- .../core/internal/ItemTypeMngInternal.h | 21 ++++--------------- arcane/src/arcane/mesh/OneMeshItemAdder.cc | 12 ++++++----- 4 files changed, 20 insertions(+), 31 deletions(-) diff --git a/arcane/src/arcane/core/ItemTypeMng.cc b/arcane/src/arcane/core/ItemTypeMng.cc index adafb62c7..a59269099 100644 --- a/arcane/src/arcane/core/ItemTypeMng.cc +++ b/arcane/src/arcane/core/ItemTypeMng.cc @@ -1566,8 +1566,9 @@ getPolygonType(Int16 nb_node) const /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ /*! - * \brief Create a custom temporary type for generic Polyhedron. + * \brief Fill a type to create a custom temporary type for generic Polyhedron. * + * Fill \a type with information for a polyhedron. * \a ids_buffer will be used to store connectivities informations. * It must remain valid until the type is no longer used. * @@ -1578,11 +1579,11 @@ getPolygonType(Int16 nb_node) const * the elements from `faces_nb_nodes[0]` to `face_nb_nodes[0]+faces_nb_node[1]-1` * are the nodes index of the second face and so on. */ -ItemTypeInfo* ItemTypeMng:: -_getTemporaryPolyhedron(Array* ids_buffer, Int16 nb_node, ConstArrayView faces_nb_nodes, ConstArrayView faces_nodes) +void ItemTypeMng:: +_fillTemporaryTypeForPolyhedron(ItemTypeInfoBuilder* type, Array* ids_buffer, Int16 nb_node, + ConstArrayView faces_nb_nodes, + ConstArrayView faces_nodes) { - // TODO: Remove the memory leak when adding information to this type. - ItemTypeInfoBuilder* type = m_types_buffer->allocOne(); Int32 nb_face = faces_nb_nodes.size(); // TODO: need compute number of edges. type->_setInfos(ids_buffer, ITI_GenericPolyhedron, "Polyhedron", ItemTypeInfoBuilder::Dimension::Dim3, nb_node, 0, nb_face); @@ -1596,7 +1597,6 @@ _getTemporaryPolyhedron(Array* ids_buffer, Int16 nb_node, ConstArrayView< index_in_face_node += nb_node_in_face; } //type->computeFaceEdgeInfos(); - return type; } /*---------------------------------------------------------------------------*/ diff --git a/arcane/src/arcane/core/ItemTypeMng.h b/arcane/src/arcane/core/ItemTypeMng.h index edf0e0b59..c0f3b4df9 100644 --- a/arcane/src/arcane/core/ItemTypeMng.h +++ b/arcane/src/arcane/core/ItemTypeMng.h @@ -224,9 +224,9 @@ class ARCANE_CORE_EXPORT ItemTypeMng //! Reads types from a file named filename void _readTypes(IParallelSuperMng* parallel_mng, const String& filename); void _addPolygonType(Int16 type_id, Int32 nb_node, const String& type_name); - ItemTypeInfo* _getTemporaryPolyhedron(Array* ids_buffer, Int16 nb_node, - ConstArrayView faces_nb_nodes, - ConstArrayView faces_nodes); + void _fillTemporaryTypeForPolyhedron(ItemTypeInfoBuilder* type, Array* ids_buffer, Int16 nb_node, + ConstArrayView faces_nb_nodes, + ConstArrayView faces_nodes); }; /*---------------------------------------------------------------------------*/ diff --git a/arcane/src/arcane/core/internal/ItemTypeMngInternal.h b/arcane/src/arcane/core/internal/ItemTypeMngInternal.h index a7068aa8f..e98152b6d 100644 --- a/arcane/src/arcane/core/internal/ItemTypeMngInternal.h +++ b/arcane/src/arcane/core/internal/ItemTypeMngInternal.h @@ -38,24 +38,11 @@ class ARCANE_CORE_EXPORT ItemTypeMngInternal public: - /*! - * \brief Create a temporary type for generic Polyhedron. - * - * \a ids_buffer will be used to store connectivities informations. - * It must remain valid until the type is no longer used. - * - * \param nb_node number of nodes of the polyhedron. - * \pram faces_nb_node number of nodes of each face. - * \param faces_nodes list of nodes of the faces. The elements - * from `0` to `faces_nb_node[0]-1` are the node index of the first face, - * the elements from `faces_nb_nodes[0]` to `face_nb_nodes[0]+faces_nb_node[1]-1` - * are the nodes index of the second face and so on. - */ - ItemTypeInfo* getTemporaryPolyhedron(Array* ids_buffer, Int16 nb_node, - ConstArrayView faces_nb_node, - ConstArrayView faces_nodes) + void fillTemporaryTypeForPolyhedron(ItemTypeInfoBuilder* type, Array* ids_buffer, Int16 nb_node, + ConstArrayView faces_nb_node, + ConstArrayView faces_nodes) { - return m_item_type_mng->_getTemporaryPolyhedron(ids_buffer, nb_node, faces_nb_node, faces_nodes); + m_item_type_mng->_fillTemporaryTypeForPolyhedron(type, ids_buffer, nb_node, faces_nb_node, faces_nodes); } private: diff --git a/arcane/src/arcane/mesh/OneMeshItemAdder.cc b/arcane/src/arcane/mesh/OneMeshItemAdder.cc index 676586683..f360cf693 100644 --- a/arcane/src/arcane/mesh/OneMeshItemAdder.cc +++ b/arcane/src/arcane/mesh/OneMeshItemAdder.cc @@ -22,6 +22,7 @@ #include "arcane/core/MeshToMeshTransposer.h" #include "arcane/core/IParallelMng.h" #include "arcane/core/ItemPrinter.h" +#include "arcane/core/ItemTypeInfoBuilder.h" #include "arcane/core/internal/ItemTypeMngInternal.h" #include "arcane/mesh/DynamicMesh.h" @@ -847,10 +848,10 @@ _addOnePolyhedron(Int64 cell_uid, ConstArrayView connectivity_infos, Int3 // the next elements are nodes of face0, then node of face1, ... SmallArray cell_nodes_uid; - Int32 array_size = connectivity_infos[0]; + Int32 array_size = static_cast(connectivity_infos[0]); if (array_size != connectivity_infos.size()) ARCANE_FATAL("Incoherent size array_size={0} connectivity_info={1}", array_size, connectivity_infos.size()); - Int32 scheme_version = connectivity_infos[1]; + Int32 scheme_version = static_cast(connectivity_infos[1]); if (scheme_version != 1) ARCANE_FATAL("Insupported scheme version '{0}'. Only supported value is 1", scheme_version); const Int32 cell_nb_face = static_cast(connectivity_infos[2]); @@ -893,9 +894,10 @@ _addOnePolyhedron(Int64 cell_uid, ConstArrayView connectivity_infos, Int3 info() << "EndCreateTypeForPolyhedron nb_node=" << nodes_of_cell.size(); ItemTypeMngInternal* api = m_item_type_mng->_internalApi(); SmallArray type_ids_buffer; - ItemTypeInfo* cell_type_info = api->getTemporaryPolyhedron(&type_ids_buffer,nodes_of_cell.size(), - arcane_faces_nb_node, arcane_faces_nodes); - CellInfoProxy cell_info_proxy(ITI_GenericPolyhedron, cell_type_info, cell_uid, owner, nodes_of_cell, allow_build_face); + ItemTypeInfoBuilder cell_type_info; + api->fillTemporaryTypeForPolyhedron(&cell_type_info, &type_ids_buffer, nodes_of_cell.size(), + arcane_faces_nb_node, arcane_faces_nodes); + CellInfoProxy cell_info_proxy(ITI_GenericPolyhedron, &cell_type_info, cell_uid, owner, nodes_of_cell, allow_build_face); return _addOneCell(cell_info_proxy); }