Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
LimaUtils.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/* LimaUtils.cc (C) 2000-2026 */
9/* */
10/* Utility functions for Lima. */
11/*---------------------------------------------------------------------------*/
12
13#include "arcane/lima/internal/LimaUtils.h"
14
15#include "arcane/utils/CheckedConvert.h"
16#include "arcane/utils/ITraceMng.h"
17
18#include "arcane/core/IItemFamily.h"
19#include "arcane/core/IMeshReader.h"
20#include "arcane/core/ItemGroup.h"
21
22#include "arcane/lima/internal/LimaMalippT.h"
23
24#include <algorithm>
25
26#ifdef ARCANE_LIMA_HAS_MLI
27#include <Lima/malipp.h>
28#endif
29#ifdef ARCANE_LIMA_HAS_MLI2
30#include <Lima/malipp2.h>
31#endif
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
36namespace Arcane
37{
38
39/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
41
43createGroup(IItemFamily* family, const String& name, Int32ArrayView local_ids)
44{
45 ITraceMng* tm = family->traceMng();
46 if (!local_ids.empty())
47 std::sort(std::begin(local_ids), std::end(local_ids));
48 Integer nb_item = local_ids.size();
49 Integer nb_duplicated = 0;
50 // Detects duplicates
51 for (Integer i = 1; i < nb_item; ++i)
52 if (local_ids[i] == local_ids[i - 1]) {
53 ++nb_duplicated;
54 }
55 if (nb_duplicated != 0) {
56 tm->warning() << "Duplicated items in group name=" << name
57 << " nb_duplicated=" << nb_duplicated;
58 auto xbegin = std::begin(local_ids);
59 auto xend = std::end(local_ids);
60 Integer new_size = CheckedConvert::toInteger(std::unique(xbegin, xend) - xbegin);
61 tm->info() << "NEW_SIZE=" << new_size << " old=" << nb_item;
62 local_ids = local_ids.subView(0, new_size);
63 }
64
65 family->createGroup(name, local_ids, true);
66}
67
68/*---------------------------------------------------------------------------*/
69/*---------------------------------------------------------------------------*/
70
72LimaUtils::_directLimaPartitionMalipp(ITimerMng* timer_mng, IPrimaryMesh* mesh,
73 const String& filename, Real length_multiplier)
74{
75#ifdef ARCANE_LIMA_HAS_MLI
77 IMeshReader::eReturnType rt = reader.readMeshFromFile(timer_mng, mesh, filename, length_multiplier);
78 return rt;
79#else
80 ARCANE_UNUSED(timer_mng);
81 ARCANE_UNUSED(mesh);
82 ARCANE_UNUSED(filename);
83 ARCANE_UNUSED(length_multiplier);
85#endif
86}
87
88/*---------------------------------------------------------------------------*/
89/*---------------------------------------------------------------------------*/
90
92LimaUtils::_directLimaPartitionMalipp2(ITimerMng* timer_mng, IPrimaryMesh* mesh,
93 const String& filename, Real length_multiplier)
94{
95#ifdef ARCANE_LIMA_HAS_MLI2
96 LimaMalippReader<Lima::MaliPPReader2> reader(mesh->traceMng());
97 auto rt = reader.readMeshFromFile(timer_mng, mesh, filename, length_multiplier);
98 return rt;
99#else
100 ARCANE_UNUSED(timer_mng);
101 ARCANE_UNUSED(mesh);
102 ARCANE_UNUSED(filename);
103 ARCANE_UNUSED(length_multiplier);
105#endif
106}
107
108/*---------------------------------------------------------------------------*/
109/*---------------------------------------------------------------------------*/
110
111} // namespace Arcane
112
113/*---------------------------------------------------------------------------*/
114/*---------------------------------------------------------------------------*/
constexpr ArrayView< T > subView(Integer abegin, Integer asize) noexcept
Sub-view starting from element abegin and containing asize elements.
constexpr Integer size() const noexcept
Returns the size of the array.
constexpr bool empty() const noexcept
Returns true if the array is empty (zero dimension).
Interface of an entity family.
Definition IItemFamily.h:83
virtual ItemGroup createGroup(const String &name, Int32ConstArrayView local_ids, bool do_override=false)=0
Creates an entity group named name containing the entities local_ids.
virtual ITraceMng * traceMng() const =0
Associated trace manager.
eReturnType
Types of return codes for a read or write operation.
Definition IMeshReader.h:38
@ RTIrrelevant
Not relevant to the operation. This means that the file format does not match this reader or that the...
Definition IMeshReader.h:46
Interface of a timer manager.
Definition ITimerMng.h:50
virtual TraceMessage warning()=0
Stream for a warning message.
virtual TraceMessage info()=0
Stream for an information message.
Mesh file reader via the LIMA library.
static void createGroup(IItemFamily *family, const String &name, Int32ArrayView local_ids)
Creates a group of entities.
Definition LimaUtils.cc:43
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
ArrayView< Int32 > Int32ArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:453
double Real
Type representing a real number.