Arcane  4.2.1.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
MeshSectionService.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/* MeshSectionService.cc (C) 2000-2026 */
9/* */
10/* Service permettant la création d'un maillage avec une section d'un */
11/* autre maillage. */
12/*---------------------------------------------------------------------------*/
13/*---------------------------------------------------------------------------*/
14
15#include "arcane/core/IMesh.h"
16#include "arcane/core/IMeshFactoryMng.h"
17#include "arcane/core/IMeshMng.h"
18#include "arcane/core/IMeshModifier.h"
19#include "arcane/core/IPrimaryMesh.h"
20#include "arcane/core/MeshBuildInfo.h"
21
22#include "arcane/core/IMeshSection.h"
23#include "arcane/std/MeshSection_axl.h"
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
42class MeshSectionService
44{
45 public:
46
47 explicit MeshSectionService(const ServiceBuildInfo& sbi)
49 , m_creation_type(sbi.creationType())
50 {}
51
52 public:
53
54 void addPlane(const Real3& p0, const Real3& normal) override;
55
57 VariableCollection variables() override { return {}; }
58 void setServiceMeshUniqueId(Int32 unique_id) override;
59 void updateSection() override;
60
62 {
63 return m_cloned_mesh->handle();
64 }
65
66 private:
67
68 void _createMesh();
69 void _createCells(Int32& nb_cell, UniqueArray<Int64>& cells_infos, Int32& nb_face, UniqueArray<Int64>& faces_infos, std::unordered_map<Int64, Real3>& pos_node);
70 void _compute();
71
72 private:
73
74 // VariableCollection m_variables_ori;
75 IPrimaryMesh* m_cloned_mesh = nullptr;
77 Int32 m_mesh_uid = -1;
78 eServiceType m_creation_type;
79};
80
81/*---------------------------------------------------------------------------*/
82/*---------------------------------------------------------------------------*/
83
84ARCANE_REGISTER_SERVICE_MESHSECTION(MeshSection, MeshSectionService);
85
86/*---------------------------------------------------------------------------*/
87/*---------------------------------------------------------------------------*/
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
93addPlane(const Real3& p0, const Real3& normal)
94{
95 m_plans.add({ p0, math::normalizeReal3(normal) });
96}
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100
103{
104 ARCANE_UNUSED(variables);
105 ARCANE_NOT_YET_IMPLEMENTED("Not supported yet");
106 // m_variables_ori = variables;
107}
108
109/*---------------------------------------------------------------------------*/
110/*---------------------------------------------------------------------------*/
111
114{
115 m_mesh_uid = unique_id;
116}
117
118/*---------------------------------------------------------------------------*/
119/*---------------------------------------------------------------------------*/
120
123{
124 _createMesh();
125 _compute();
126}
127
128/*---------------------------------------------------------------------------*/
129/*---------------------------------------------------------------------------*/
130
131void MeshSectionService::
132_createMesh()
133{
134 if (m_cloned_mesh != nullptr) {
135 m_cloned_mesh->modifier()->clearItems();
136 }
137
138 IMeshMng* mm = subDomain()->meshMng();
139
140 if (m_mesh_uid == -1) {
141 if (m_creation_type == ST_CaseOption) {
142 m_mesh_uid = options()->getUniqueIdServiceMesh();
143 }
144 else {
145 m_mesh_uid = 0;
146 }
147 }
148
149 String service_mesh_name = mesh()->name() + "_MeshSection" + m_mesh_uid;
150
151 MeshHandle* mesh_handle = mm->findMeshHandle(service_mesh_name, false);
152
153 if (mesh_handle == nullptr) {
154 IParallelMng* pm = subDomain()->parallelMng();
155 MeshBuildInfo mbi(service_mesh_name);
156 mbi.addParallelMng(makeRef(pm));
157 m_cloned_mesh = mm->meshFactoryMng()->createMesh(mbi);
158 m_cloned_mesh->modifier()->setDynamic(true);
159 m_cloned_mesh->setDimension(mesh()->dimension());
160 m_cloned_mesh->endAllocate();
161 }
162 else {
163 m_cloned_mesh = mesh_handle->mesh()->toPrimaryMesh();
164 m_cloned_mesh->modifier()->clearItems();
165 }
166}
167
168/*---------------------------------------------------------------------------*/
169/*---------------------------------------------------------------------------*/
170
171void MeshSectionService::
172_createCells(Int32& sd_nb_cell, UniqueArray<Int64>& cells_infos, Int32& sd_nb_face, UniqueArray<Int64>& faces_infos, std::unordered_map<Int64, Real3>& pos_node)
173{
174 VariableNodeReal3& node_coord = mesh()->nodesCoordinates();
175
176 VariableFaceBool is_added(VariableBuildInfo(mesh(), "IsAdded"));
177 is_added.fill(false);
178
179 ENUMERATE_ (Cell, icell, ownCells()) {
180 {
181 Real3 b{ 0 };
182 for (Node node : icell->nodes()) {
183 b += node_coord[node];
184 }
185 b /= icell->nbNode();
186
187 bool in_plan = true;
188 for (auto& [p0, normal] : m_plans) {
189 const Real dist = math::dot({ b - p0 }, normal);
190 if (dist < 0) {
191 in_plan = false;
192 break;
193 }
194 }
195
196 if (!in_plan)
197 continue;
198 }
199
200 Int16 cell_type = icell->itemTypeId();
201 cells_infos.add(cell_type);
202
203 Int64 cell_uid = icell->uniqueId().asInt64();
204 cells_infos.add(cell_uid);
205
206 for (Node node : icell->nodes()) {
207 Int64 node_uid = node.uniqueId().asInt64();
208 cells_infos.add(node_uid);
209 pos_node[node.uniqueId()] = node_coord[node];
210 }
211 ++sd_nb_cell;
212
213 for (Face face : icell->faces()) {
214 if (is_added[face]) continue;
215 is_added[face] = true;
216
217 Int16 face_type = face.itemTypeId();
218 faces_infos.add(face_type);
219
220 Int64 face_uid = face.uniqueId().asInt64();
221 faces_infos.add(face_uid);
222
223 for (Node node : face.nodes()) {
224 Int64 node_uid = node.uniqueId().asInt64();
225 faces_infos.add(node_uid);
226 pos_node[node.uniqueId()] = node_coord[node];
227 }
228 ++sd_nb_face;
229 }
230 }
231}
232
233/*---------------------------------------------------------------------------*/
234/*---------------------------------------------------------------------------*/
235
236void MeshSectionService::
237_compute()
238{
239 UniqueArray<Int64> cells_infos;
240 cells_infos.reserve(10000);
241
242 UniqueArray<Int64> faces_infos;
243 faces_infos.reserve(10000);
244
245 std::unordered_map<Int64, Real3> coord_map;
246
247 Int32 nb_cell = 0;
248 Int32 nb_face = 0;
249
250 _createCells(nb_cell, cells_infos, nb_face, faces_infos, coord_map);
251
252 m_cloned_mesh->modifier()->addFaces(nb_face, faces_infos);
253 m_cloned_mesh->modifier()->addCells(nb_cell, cells_infos);
254 m_cloned_mesh->modifier()->endUpdate();
255
256 {
257 VariableNodeReal3& node_coords(m_cloned_mesh->nodesCoordinates());
258 ENUMERATE_ (Node, inode, m_cloned_mesh->allNodes()) {
259 node_coords[inode] = coord_map[inode->uniqueId()];
260 }
261 }
262
263 info() << "New mesh -- NbNode : " << m_cloned_mesh->nbNode() << " -- NbCells : " << m_cloned_mesh->nbCell();
264}
265
266/*---------------------------------------------------------------------------*/
267/*---------------------------------------------------------------------------*/
268
269} // namespace Arcane
270
271/*---------------------------------------------------------------------------*/
272/*---------------------------------------------------------------------------*/
#define ENUMERATE_(type, name, group)
Enumérateur générique d'un groupe d'entité
ArcaneMeshSectionObject(const Arcane::ServiceBuildInfo &sbi)
Constructeur.
CaseOptionsMeshSection * options() const
Options du jeu de données du service.
virtual MeshHandle * findMeshHandle(const String &name, bool throw_exception)=0
Recherche le maillage de nom name.
virtual void clearItems()=0
Supprime toutes les entitées de toutes les familles de ce maillage.
virtual IMeshModifier * modifier()=0
Interface de modification associée.
virtual IMeshMng * meshMng() const =0
Retourne le gestionnaire de maillage.
CellGroup ownCells() const
Retourne le groupe contenant toutes les mailles propres à ce domaine.
Handle sur un maillage.
Definition MeshHandle.h:47
void addPlane(const Real3 &p0, const Real3 &normal) override
Méthode permettant d'ajouter un plan au service de coupe. L'utilisation de ces plans dépend du servic...
void updateSection() override
Méthode permettant de mettre à jour la section du maillage avec tous les plans.
MeshHandle meshSection() override
Méthode permettant d'obtenir la section du maillage.
VariableCollection variables() override
Méthode permettant d'obtenir un ensemble de variables copiées sur le nouveau maillage.
void setVariables(VariableCollection variables) override
Méthode permettant d'ajouter un ensemble de variables à copier sur le nouveau maillage.
void setServiceMeshUniqueId(Int32 unique_id) override
Méthode permettant de définir un identifiant unique pour créer plusieurs services de section pour un ...
Classe gérant un vecteur réel de 3 dimensions.
eServiceType creationType() const
Type du service pouvant être créé par cette instance.
Structure contenant les informations pour créer un service.
TraceMessage info() const
Flot pour un message d'information.
Vecteur 1D de données avec sémantique par valeur (style STL).
Collection de variables.
__host__ __device__ Real dot(Real2 u, Real2 v)
Produit scalaire de u par v dans .
Definition MathUtils.h:94
__host__ __device__ Real3 normalizeReal3(Real3 v)
Normalisation d'un Real3.
Definition MathUtils.h:777
MeshVariableScalarRefT< Face, Byte > VariableFaceBool
Grandeur aux faces de type booléen.
MeshVariableScalarRefT< Node, Real3 > VariableNodeReal3
Grandeur au noeud de type coordonnées.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Type entier signé sur 64 bits.
eServiceType
Type du service.
@ ST_CaseOption
Le service s'utilise au niveau du jeu de données.
std::int16_t Int16
Type entier signé sur 16 bits.
double Real
Type représentant un réel.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Créé une référence sur un pointeur.
@ Cell
Le maillage est AMR par maille.
Definition MeshKind.h:52
std::int32_t Int32
Type entier signé sur 32 bits.