Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
LimaCutInfosReader.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/* LimaCutInfosReader.cc (C) 2000-2026 */
9/* */
10/* Reader for cut information using Lima files. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/lima/LimaCutInfosReader.h"
15
16#include "arcane/utils/ArcanePrecomp.h"
17
18#include "arcane/utils/ScopedPtr.h"
19#include "arcane/utils/StringBuilder.h"
20#include "arcane/utils/FatalErrorException.h"
21
22#include "arcane/core/ItemGroup.h"
23#include "arcane/core/Item.h"
24#include "arcane/core/IXmlDocumentHolder.h"
25#include "arcane/core/XmlNode.h"
26#include "arcane/core/XmlNodeList.h"
27#include "arcane/core/IParallelMng.h"
28#include "arcane/core/IIOMng.h"
29#include "arcane/core/Timer.h"
30#include "arcane/core/IMesh.h"
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35namespace Arcane
36{
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
41//Just to create the .lib under Windows.
42class ARCANE_EXPORT LimaTest
43{
44};
45
46/*---------------------------------------------------------------------------*/
47/*---------------------------------------------------------------------------*/
48
49LimaCutInfosReader::
50LimaCutInfosReader(IParallelMng* parallel_mng)
51: TraceAccessor(parallel_mng->traceMng())
52, m_parallel_mng(parallel_mng)
53{
54}
55
56/*---------------------------------------------------------------------------*/
57/*---------------------------------------------------------------------------*/
64static Integer
65_readList(Int64ArrayView& int_list, const char* buf)
66{
67 std::istringstream istr(buf);
68 Integer index = 0;
69 while (!istr.eof()) {
70 Int64 v = 0;
71 istr >> v;
72 if (istr.eof())
73 break;
74 int_list[index] = v;
75 ++index;
76 }
77 return index;
78}
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
87 const String& dir_name)
88{
89 _readUniqueIndex(nodes_id, cells_id, dir_name);
90}
91
92/*---------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
110 const String& dir_name)
111{
112 Timer time_to_read(m_parallel_mng->timerMng(), "ReadCorrespondance", Timer::TimerReal);
113 IParallelMng* pm = m_parallel_mng;
114
115 // If the case is parallel, read the correspondence file.
116 bool is_parallel = pm->isParallel();
117 Int32 comm_rank = pm->commRank();
118 Int32 nb_rank = pm->commSize();
119 // If we are in the case where Arcane is trimmed to one core
120 if ((!is_parallel) || (is_parallel && nb_rank == 1)) {
121 for (Integer i = 0, n = nodes_id.size(); i < n; ++i)
122 nodes_id[i] = i;
123 for (Integer i = 0, n = cells_id.size(); i < n; ++i)
124 cells_id[i] = i;
125 return;
126 }
127
129 StringBuilder correspondance_filename;
130 if (!dir_name.empty()) {
131 correspondance_filename += dir_name;
132 correspondance_filename += "/";
133 }
134 correspondance_filename += "Correspondances";
135
136 if (comm_rank == 0) {
137 {
138 Timer::Sentry sentry(&time_to_read);
139 IXmlDocumentHolder* doc = pm->ioMng()->parseXmlFile(correspondance_filename);
140 doc_holder = doc;
141 }
142 if (!doc_holder.get())
143 ARCANE_FATAL("Invalid correspondance file '{0}'", correspondance_filename);
144
145 info() << "Time to read (unit: second) 'Correspondances' file: "
146 << time_to_read.lastActivationTime();
147
148 XmlNode root_element = doc_holder->documentNode().documentElement();
149
150 // First, the subdomain reads its values.
151 _readUniqueIndexFromXml(nodes_id, cells_id, root_element, 0);
152
153 {
154 Timer::Sentry sentry(&time_to_read);
155 // Then loop over the other subdomains.
156 Int64UniqueArray other_nodes_id;
157 Int64UniqueArray other_cells_id;
158 UniqueArray<Integer> other_sizes(2);
159 for (Int32 i = 1; i < nb_rank; ++i) {
160 pm->recv(other_sizes, i);
161 other_nodes_id.resize(other_sizes[0]);
162 other_cells_id.resize(other_sizes[1]);
163 _readUniqueIndexFromXml(other_nodes_id, other_cells_id, root_element, i);
164 pm->send(other_nodes_id, i);
165 pm->send(other_cells_id, i);
166 }
167 }
168 info() << "Time to transfert values: "
169 << time_to_read.lastActivationTime();
170 }
171 else {
172 // Receive the values sent by subdomain 0
173 Integer mes[2];
174 IntegerArrayView mesh_element_size(2, mes);
175 mesh_element_size[0] = nodes_id.size();
176 mesh_element_size[1] = cells_id.size();
177 pm->send(mesh_element_size, 0);
178 pm->recv(nodes_id, 0);
179 pm->recv(cells_id, 0);
180 }
181 // Check that all messages are sent and received before destroying
182 // the XML document.
183 pm->barrier();
184}
185
186/*---------------------------------------------------------------------------*/
187/*---------------------------------------------------------------------------*/
197 XmlNode root_element, Int32 comm_rank)
198{
199 XmlNode cpu_elem;
200 XmlNodeList cpu_list = root_element.children(String("cpu"));
201
202 String ustr_buf(String::fromNumber(comm_rank));
203
204 String us_id("id");
205 for (Integer i = 0, s = cpu_list.size(); i < s; ++i) {
206 String id_str = cpu_list[i].attrValue(us_id);
207 if (id_str.null())
208 continue;
209 if (id_str == ustr_buf) {
210 cpu_elem = cpu_list[i];
211 break;
212 }
213 }
214 if (cpu_elem.null())
215 ARCANE_FATAL("No element <cpu[@id=\"{0}\"]>", comm_rank);
216 XmlNode node_elem = cpu_elem.child("noeuds");
217 if (node_elem.null())
218 ARCANE_FATAL("No element <noeuds>");
219 XmlNode cell_elem = cpu_elem.child("mailles");
220 if (cell_elem.null())
221 ARCANE_FATAL("No element <mailles>");
222
223 // Node correspondence array
224 {
225 String ustr_value = node_elem.value();
226 Integer nb_read = _readList(nodes_id, ustr_value.localstr());
227 Integer expected_size = nodes_id.size();
228 if (nb_read != expected_size)
229 ARCANE_FATAL("Bad number of nodes rank={0} nb_read={1} expected={2}",
230 comm_rank, nb_read, expected_size);
231 }
232
233 // Cell correspondence array
234 {
235 String ustr_value = cell_elem.value();
236 Integer nb_read = _readList(cells_id, ustr_value.localstr());
237 Integer expected_size = cells_id.size();
238 if (nb_read != expected_size)
239 ARCANE_FATAL("Bad number of cells rank={0} nb_read={1} expected={2}",
240 comm_rank, nb_read, expected_size);
241 }
242}
243
244/*---------------------------------------------------------------------------*/
245/*---------------------------------------------------------------------------*/
246
247} // namespace Arcane
248
249/*---------------------------------------------------------------------------*/
250/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
constexpr Integer size() const noexcept
Returns the size of the array.
void resize(Int64 s)
Changes the number of elements in the array to s.
virtual IXmlDocumentHolder * parseXmlFile(const String &filename, const String &schemaname=String{})=0
Reads and parses the XML file filename.
Interface of the parallelism manager for a subdomain.
virtual Int32 commRank() const =0
Rank of this instance in the communicator.
virtual void recv(ArrayView< char > values, Int32 rank)=0
virtual Int32 commSize() const =0
Number of instances in the communicator.
virtual IIOMng * ioMng() const =0
I/O manager.
virtual bool isParallel() const =0
Returns true if the execution is parallel.
virtual void barrier()=0
Performs a barrier.
Manager of a DOM document.
void _readUniqueIndex(Int64ArrayView nodes_id, Int64ArrayView cells_id, const String &dir_name)
Retrieval of unique entity indices.
void readItemsUniqueId(Int64ArrayView nodes_id, Int64ArrayView cells_id, const String &dir_name)
Constructs the internal mesh structures.
void _readUniqueIndexFromXml(Int64ArrayView nodes_id, Int64ArrayView cells_id, XmlNode root_element, Int32 rank)
Reading unique indices from an XML correspondence file.
T * get() const
Returns the object referenced by the instance.
Definition Ptr.h:122
Encapsulation of an automatically destructing pointer.
Definition ScopedPtr.h:44
Unicode character string constructor.
bool null() const
Returns true if the string is null.
Definition String.cc:306
const char * localstr() const
Returns the conversion of the instance into UTF-8 encoding.
Definition String.cc:229
bool empty() const
True if the string is empty (null or "").
Definition String.cc:317
Sentinel for the timer. The sentinel associated with a timer allows it to be triggered upon its const...
Definition Timer.h:90
Management of a timer.
Definition Timer.h:63
@ TimerReal
Timer using real time.
Definition Timer.h:77
Real lastActivationTime() const
Returns the time (in seconds) spent during the last activation of the timer.
Definition Timer.h:243
TraceMessage info() const
Flow for an information message.
1D data vector with value semantics (STL style).
List of nodes of a DOM tree.
Definition XmlNodeList.h:36
Node of a DOM tree.
Definition XmlNode.h:51
XmlNode child(const String &name) const
Child node of this node with name name.
Definition XmlNode.cc:73
String value() const
Node value.
Definition XmlNode.cc:208
XmlNodeList children(const String &name) const
Set of child nodes of this node having the name name.
Definition XmlNode.cc:102
bool null() const
True if the node is null.
Definition XmlNode.h:303
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
ArrayView< Int64 > Int64ArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:451
UniqueArray< Int64 > Int64UniqueArray
Dynamic 1D array of 64-bit integers.
Definition UtilsTypes.h:339
Int32 Integer
Type representing an integer.
ArrayView< Integer > IntegerArrayView
C equivalent of a 1D array of integers.
Definition UtilsTypes.h:457
std::int32_t Int32
Signed integer type of 32 bits.