Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ItemPrinter.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ItemPrinter.cc (C) 2000-2026 */
9/* */
10/* Writing Item to stream. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/String.h"
15
16#include "arcane/core/ItemPrinter.h"
17#include "arcane/core/ItemInternalEnumerator.h"
18#include "arcane/core/IItemFamily.h"
19#include "arcane/core/IMesh.h"
20#include "arcane/core/MeshPartInfo.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25/*
26 * TODO: We should handle the display of the entity via IItemFamily.
27 *
28 * This would allow specializing the display by family.
29 */
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34namespace Arcane
35{
36using impl::ItemBase;
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
41struct ARCANE_CORE_EXPORT ItemPrinter::Internal
42{
43 //! Writes the basic information of the item
44 static void _printBasics(std::ostream& o, ItemBase item);
45 //! Writes the item flags explicitly
46 static void _printFlags(std::ostream& o, Integer flags);
47 //! Writes information about the parents
48 static void _printParents(std::ostream& o, ItemBase item);
49 //! Writes information about the parents
50 static void _printErrors(std::ostream& o, ItemBase item);
51 //! Writes the information of an item enumeration
52 static void _printItemSubItems(std::ostream& ostr, String name, const ItemVectorView& enumerator);
53};
54
55/*---------------------------------------------------------------------------*/
56/*---------------------------------------------------------------------------*/
57
59print(std::ostream& o) const
60{
61 if (m_item.null()) {
62 if (m_has_item_kind) {
63 o << "(null " << itemKindName(m_item_kind) << ")";
64 }
65 else {
66 o << "(null Item)";
67 }
68 }
69 else {
70 o << "(";
72 ItemPrinter::Internal::_printFlags(o, m_item.flags());
75 o << ")";
76 }
77}
78
79/*---------------------------------------------------------------------------*/
80/*---------------------------------------------------------------------------*/
81
83print(std::ostream& ostr) const
84{
85 if (m_item.null()) {
86 ostr << "(null Item)";
87 }
88 else {
89 eItemKind ik = m_item.kind();
90 ostr << "(";
92 ItemPrinter::Internal::_printFlags(ostr, m_item.flags());
95 ostr << ")";
96 ostr << "\n\t";
97 if (ik != IK_Node)
98 if (m_item.nbNode() != 0)
99 ItemPrinter::Internal::_printItemSubItems(ostr, "Nodes", m_item.nodeList());
100 ostr << "\n\t";
101 if (ik != IK_Edge)
102 if (m_item.nbEdge() != 0)
103 ItemPrinter::Internal::_printItemSubItems(ostr, "Edges", m_item.edgeList());
104 ostr << "\n\t";
105 if (m_item.nbFace() != 0)
106 ItemPrinter::Internal::_printItemSubItems(ostr, "Faces", m_item.faceList());
107 ostr << "\n\t";
108 if (ik != IK_Cell)
109 if (m_item.nbCell() != 0)
110 ItemPrinter::Internal::_printItemSubItems(ostr, "Cells", m_item.cellList());
111 }
112}
113
114/*---------------------------------------------------------------------------*/
115/*---------------------------------------------------------------------------*/
116
117void NeighborItemPrinter::
118_printSubItems(std::ostream& ostr, Integer level, Integer levelmax,
119 ItemVectorView sub_items, const char* name)
120{
121 indent(ostr, levelmax - level) << String::plural(sub_items.size(), name) << ":\n";
122 for (Item sub_item : sub_items) {
123 indent(ostr, levelmax - level) << "\t" << name;
124 print(ostr, sub_item, level - 1, levelmax);
125 ostr << "\n";
126 }
127}
128
129/*---------------------------------------------------------------------------*/
130/*---------------------------------------------------------------------------*/
131
133print(std::ostream& ostr, Item xitem, Integer level, Integer levelmax)
134{
135 impl::ItemBase item = xitem.itemBase();
136 if (xitem.null()) {
137 ostr << "(null Item)";
138 }
139 else {
140 eItemKind ik = item.kind();
141 ostr << "(";
143 ItemPrinter::Internal::_printFlags(ostr, item.flags());
146 ostr << ")";
147 if (level > 0) {
148 ostr << "\n";
149 if (ik != IK_Node)
150 if (item.nbNode() != 0)
151 _printSubItems(ostr, level, levelmax, item.nodeList(), "node");
152 if (item.nbEdge() != 0)
153 _printSubItems(ostr, level, levelmax, item.edgeList(), "edge");
154 if (item.nbFace() != 0)
155 _printSubItems(ostr, level, levelmax, item.faceList(), "face");
156 if (ik != IK_Cell)
157 if (item.nbCell() != 0)
158 _printSubItems(ostr, level, levelmax, item.cellList(), "cell");
159 }
160 }
161}
162
163std::ostream& NeighborItemPrinter::
164indent(std::ostream& ostr, Integer level)
165{
166 for (Integer l = 0; l < level; ++l)
167 ostr << "\t";
168 return ostr;
169}
170
171/*---------------------------------------------------------------------------*/
172/*---------------------------------------------------------------------------*/
173
174/*---------------------------------------------------------------------------*/
175/*---------------------------------------------------------------------------*/
176
178_printBasics(std::ostream& o, impl::ItemBase item)
179{
180 o << "uid=" << item.uniqueId()
181 << ",lid=" << item.localId()
182 << ",owner=" << item.owner()
183 << ",type=" << item.typeInfo()->typeName()
184 << ",kind=" << itemKindName(item.kind());
185}
186
187/*---------------------------------------------------------------------------*/
188/*---------------------------------------------------------------------------*/
189
191_printFlags(std::ostream& o, Integer flags)
192{
193 Integer position = 0;
194 o << ",flags=";
195 if (flags & ItemFlags::II_Boundary)
196 o << ((position++) ? "|" : "") << "Boundary";
197 if (flags & ItemFlags::II_HasFrontCell)
198 o << ((position++) ? "|" : "") << "HasFrontCell";
199 if (flags & ItemFlags::II_HasBackCell)
200 o << ((position++) ? "|" : "") << "HasBackCell";
202 o << ((position++) ? "|" : "") << "FrontCellIsFirst";
204 o << ((position++) ? "|" : "") << "BackCellIsFirst";
205 if (flags & ItemFlags::II_Own)
206 o << ((position++) ? "|" : "") << "Own";
207 if (flags & ItemFlags::II_Added)
208 o << ((position++) ? "|" : "") << "Added";
209 if (flags & ItemFlags::II_Suppressed)
210 o << ((position++) ? "|" : "") << "Suppressed";
211 if (flags & ItemFlags::II_Shared)
212 o << ((position++) ? "|" : "") << "Shared";
214 o << ((position++) ? "|" : "") << "SubDomainBoundary";
215 // if (flags & ItemFlags::II_JustRemoved)
216 // o << ((position++)?"|":"") << "JustRemoved";
217 if (flags & ItemFlags::II_JustAdded)
218 o << ((position++) ? "|" : "") << "JustAdded";
219 if (flags & ItemFlags::II_NeedRemove)
220 o << ((position++) ? "|" : "") << "NeedRemove";
221 if (flags & ItemFlags::II_SlaveFace)
222 o << ((position++) ? "|" : "") << "SlaveFace";
223 if (flags & ItemFlags::II_MasterFace)
224 o << ((position++) ? "|" : "") << "MasterFace";
225 if (flags & ItemFlags::II_Detached)
226 o << ((position++) ? "|" : "") << "Detached";
227 if (flags & ItemFlags::II_HasEdgeFor1DItems)
228 o << ((position++) ? "|" : "") << "HasEdgeFor1DItems";
229 if (flags & ItemFlags::II_Coarsen)
230 o << ((position++) ? "|" : "") << "Coarsen";
231 if (flags & ItemFlags::II_DoNothing)
232 o << ((position++) ? "|" : "") << "DoNothing";
233 if (flags & ItemFlags::II_Refine)
234 o << ((position++) ? "|" : "") << "Refine";
235 if (flags & ItemFlags::II_JustRefined)
236 o << ((position++) ? "|" : "") << "JustRefined";
237 if (flags & ItemFlags::II_JustCoarsened)
238 o << ((position++) ? "|" : "") << "JustCoarsened";
239 if (flags & ItemFlags::II_Inactive)
240 o << ((position++) ? "|" : "") << "Inactive";
242 o << ((position++) ? "|" : "") << "CoarsenInactive";
243 if (flags & ItemFlags::II_Overlap)
244 o << ((position++) ? "|" : "") << "Overlap";
245 if (flags & ItemFlags::II_InPatch)
246 o << ((position++) ? "|" : "") << "InPatch";
247 if (flags & ItemFlags::II_UserMark1)
248 o << ((position++) ? "|" : "") << "UserMark1";
249 if (flags & ItemFlags::II_UserMark2)
250 o << ((position++) ? "|" : "") << "UserMark2";
251 if (position == 0)
252 o << "0";
253}
254
255/*---------------------------------------------------------------------------*/
256/*---------------------------------------------------------------------------*/
257
259_printParents(std::ostream& o, ItemBase item)
260{
261 if (item.nbParent() > 0) {
262 ItemBase parent = item.parentBase(0);
263 o << ",parent uid/lid="
264 << parent.uniqueId()
265 << "/"
266 << parent.localId();
267 }
268}
269
270/*---------------------------------------------------------------------------*/
271/*---------------------------------------------------------------------------*/
272
274_printErrors(std::ostream& o, ItemBase item)
275{
276 if (item.isSuppressed())
277 return;
278 const char* str = ", error=";
279 Integer nerror = 0;
280 Int32 mesh_rank = item.family()->mesh()->meshPartInfo().partRank();
281 if (item.isOwn() != (mesh_rank == item.owner()))
282 o << ((nerror++ == 0) ? str : "|") << "WRONG ISOWN";
283 if (item.nbParent() > 0) {
284 // Errors are exclusive here because they invalidate the item
285 ItemBase parent = item.parentBase(0);
286 if (parent.uniqueId() != item.uniqueId())
287 o << ((nerror++ == 0) ? str : "|") << "PARENT UID MISMATCH";
288 else if (parent.isSuppressed())
289 o << ((nerror++ == 0) ? str : "|") << "SUPPRESSED PARENT";
290 else if (parent.owner() != item.owner())
291 o << ((nerror++ == 0) ? str : "|") << "PARENT OWNER MISMATCH";
292 }
293}
294
295/*---------------------------------------------------------------------------*/
296/*---------------------------------------------------------------------------*/
297
299_printItemSubItems(std::ostream& ostr, String name, const ItemVectorView& enumerator)
300{
301 ostr << " " << name << " count=" << enumerator.size();
302 ostr << " (uids=";
303 for (Item item : enumerator) {
304 if (item.localId() != NULL_ITEM_ID) {
305 if (!item.null())
306 ostr << " " << item.uniqueId();
307 else
308 ostr << " (null)";
309 }
310 else
311 ostr << " (null)";
312 }
313 ostr << ", lids=";
314 for (Item item : enumerator) {
315 if (item.localId() != NULL_ITEM_ID) {
316 if (!item.null())
317 ostr << " " << item.localId();
318 else
319 ostr << " (null)";
320 }
321 else
322 ostr << " (null)";
323 }
324 ostr << ")";
325}
326
327/*---------------------------------------------------------------------------*/
328/*---------------------------------------------------------------------------*/
329
330} // End namespace Arcane
331
332/*---------------------------------------------------------------------------*/
333/*---------------------------------------------------------------------------*/
void print(std::ostream &o) const
Write to stream of the current Item and its sub-items.
virtual IMesh * mesh() const =0
Associated mesh.
virtual const MeshPartInfo & meshPartInfo() const =0
Mesh part information.
Base class for mesh entities.
bool isSuppressed() const
True if the entity is suppressed.
ItemUniqueId uniqueId() const
Unique number of the entity.
eItemKind kind() const
Kind of the entity.
IItemFamily * family() const
Family the entity belongs to.
Int32 owner() const
Number of the owning subdomain of the entity.
ItemTypeInfo * typeInfo() const
Type of the entity.
bool isOwn() const
True if the entity belongs to the subdomain.
Integer nbParent() const
Number of parent for sub-meshes.
Int32 localId() const
Local number (in the subdomain) of the entity.
@ II_FrontCellIsFirst
The first cell of the entity is the front cell.
Definition ItemFlags.h:54
@ II_NeedRemove
The entity must be removed.
Definition ItemFlags.h:63
@ II_MasterFace
The entity is a master face of an interface.
Definition ItemFlags.h:65
@ II_Inactive
The entity is inactive //COARSEN_INACTIVE,.
Definition ItemFlags.h:80
@ II_Refine
The entity is marked for refinement.
Definition ItemFlags.h:77
@ II_Overlap
[AMR Patch] The entity is marked as overlapping with at least one AMR patch.
Definition ItemFlags.h:87
@ II_JustAdded
The entity has just been added.
Definition ItemFlags.h:62
@ II_InPatch
[AMR Patch] The entity is marked as being in an AMR patch.
Definition ItemFlags.h:92
@ II_Shared
The entity is shared by another subdomain.
Definition ItemFlags.h:59
@ II_HasBackCell
The entity has a back cell.
Definition ItemFlags.h:53
@ II_SubDomainBoundary
The entity is at the boundary of two subdomains.
Definition ItemFlags.h:60
@ II_JustRefined
The entity has just been refined.
Definition ItemFlags.h:78
@ II_Own
The entity is a domain-specific entity.
Definition ItemFlags.h:56
@ II_Suppressed
The entity has just been suppressed.
Definition ItemFlags.h:58
@ II_Detached
The entity is detached from the mesh.
Definition ItemFlags.h:66
@ II_Boundary
The entity is on the boundary.
Definition ItemFlags.h:51
@ II_Added
The entity has just been added.
Definition ItemFlags.h:57
@ II_SlaveFace
The entity is a slave face of an interface.
Definition ItemFlags.h:64
@ II_CoarsenInactive
The entity is inactive and has children tagged for coarsening.
Definition ItemFlags.h:81
@ II_UserMark2
User mark.
Definition ItemFlags.h:95
@ II_HasFrontCell
The entity has a front cell.
Definition ItemFlags.h:52
@ II_DoNothing
The entity is blocked.
Definition ItemFlags.h:76
@ II_BackCellIsFirst
The first cell of the entity is the back cell.
Definition ItemFlags.h:55
@ II_Coarsen
The entity is marked for coarsening.
Definition ItemFlags.h:75
@ II_JustCoarsened
The entity has just been coarsened.
Definition ItemFlags.h:79
@ II_UserMark1
User mark.
Definition ItemFlags.h:94
void print(std::ostream &o) const
Write to stream of the current Item.
String typeName() const
Type name.
View on a vector of entities.
Int32 size() const
Number of elements in the vector.
Base class for a mesh element.
Definition Item.h:84
void print(std::ostream &o) const
Write to stream of the current Item and its sub-items.
static String plural(const Integer n, const String &str, const bool with_number=true)
Standard plural form by adding an 's'.
Definition String.cc:1052
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
eItemKind
Mesh entity type.
@ IK_Node
Node mesh entity.
@ IK_Cell
Cell mesh entity.
@ IK_Edge
Edge mesh entity.
const char * itemKindName(eItemKind kind)
Entity kind name.
std::int32_t Int32
Signed integer type of 32 bits.
static void _printParents(std::ostream &o, ItemBase item)
Writes information about the parents.
static void _printBasics(std::ostream &o, ItemBase item)
Writes the basic information of the item.
static void _printFlags(std::ostream &o, Integer flags)
Writes the item flags explicitly.
static void _printErrors(std::ostream &o, ItemBase item)
Writes information about the parents.
static void _printItemSubItems(std::ostream &ostr, String name, const ItemVectorView &enumerator)
Writes the information of an item enumeration.