15#include "arcane/utils/ArgumentException.h"
17#include "arcane/core/IMesh.h"
18#include "arcane/core/IMeshFactoryMng.h"
19#include "arcane/core/IMeshMng.h"
20#include "arcane/core/IMeshModifier.h"
21#include "arcane/core/IPrimaryMesh.h"
22#include "arcane/core/MeshBuildInfo.h"
23#include "arcane/core/IMeshSection.h"
24#include "arcane/core/IVariableMng.h"
25#include "arcane/core/VariableMetaData.h"
27#include "arcane/core/internal/IVariableInternal.h"
28#include "arcane/core/internal/IVariableMngInternal.h"
30#include "arcane/std/MeshSection_axl.h"
47 UniqueArray<ArrayView<T>> dim1;
48 UniqueArray<Array2View<T>> dim2;
52struct VariableGroupType
54 bool isUnknownUsed() {
return !(unknown.dim1.empty() && unknown.dim2.empty()); }
55 bool isCellsUsed() {
return !(cells.dim1.empty() && cells.dim2.empty()); }
56 bool isFacesUsed() {
return !(faces.dim1.empty() && faces.dim2.empty()); }
57 bool isNodesUsed() {
return !(nodes.dim1.empty() && nodes.dim2.empty()); }
59 VariableGroup<T> unknown;
60 VariableGroup<T> cells;
61 VariableGroup<T> faces;
62 VariableGroup<T> nodes;
66struct VariableOriClone
68 VariableGroupType<T> ori;
69 VariableGroupType<T> clone;
84class MeshSectionService
105 return m_cloned_mesh->handle();
111 void _createVariables();
120 void _updateArrayVariable(
UniqueArray<Cell>& ori_cells, T, VariableOriClone<T>& voc);
128 Int32 m_mesh_uid = -1;
135ARCANE_REGISTER_SERVICE_MESHSECTION(MeshSection, MeshSectionService);
164 return m_variables_cloned;
173 m_mesh_uid = unique_id;
189void MeshSectionService::
192 if (m_cloned_mesh !=
nullptr) {
196 IMeshMng* mm = subDomain()->
meshMng();
198 if (m_mesh_uid == -1) {
200 m_mesh_uid =
options()->getUniqueIdServiceMesh();
207 String service_mesh_name = mesh()->name() +
"_MeshSection" + m_mesh_uid;
209 MeshHandle* mesh_handle = mm->
findMeshHandle(service_mesh_name,
false);
211 if (mesh_handle ==
nullptr) {
212 IParallelMng* pm = subDomain()->parallelMng();
213 MeshBuildInfo mbi(service_mesh_name);
214 mbi.addParallelMng(
makeRef(pm));
215 m_cloned_mesh = mm->meshFactoryMng()->createMesh(mbi);
216 m_cloned_mesh->modifier()->setDynamic(
true);
217 m_cloned_mesh->setDimension(mesh()->dimension());
218 m_cloned_mesh->endAllocate();
221 m_cloned_mesh = mesh_handle->mesh()->toPrimaryMesh();
222 m_cloned_mesh->modifier()->clearItems();
230void MeshSectionService::
233 IVariableMng* variable_mng = m_cloned_mesh->variableMng();
234 for (VariableCollection::Enumerator i(m_variables_ori); ++i;) {
236 Ref vmd(var->createMetaDataRef());
237 const String& mesh_name = vmd->meshName();
238 if (mesh_name.null()) {
239 ARCANE_FATAL(
"Only variables with support are supported.");
241 if (vmd->isPartial()) {
244 const String& full_type = vmd->fullType();
245 const String& base_name = vmd->baseName();
246 Integer property = vmd->property();
247 const String& family_name = vmd->itemFamilyName();
251 VariableBuildInfo vbi(m_cloned_mesh, base_name, family_name, property);
252 VariableRef* variable_ref = variable_mng->_internalApi()->createVariableFromType(full_type, vbi);
255 m_variables_cloned.add(variable_ref->variable());
262void MeshSectionService::
268 is_added.fill(
false);
273 for (Node node : icell->nodes()) {
274 b += node_coord[node];
276 b /= icell->nbNode();
279 for (
auto& [p0, normal] : m_plans) {
291 ori_cells.add(*icell);
293 Int16 cell_type = icell->itemTypeId();
294 cells_infos.add(cell_type);
296 Int64 cell_uid = icell->uniqueId().asInt64();
297 cells_infos.add(cell_uid);
299 for (Node node : icell->nodes()) {
300 Int64 node_uid = node.uniqueId().asInt64();
301 cells_infos.add(node_uid);
302 pos_node[node.uniqueId()] = node_coord[node];
306 for (Face face : icell->faces()) {
307 if (is_added[face])
continue;
308 is_added[face] =
true;
310 Int16 face_type = face.itemTypeId();
311 faces_infos.add(face_type);
313 Int64 face_uid = face.uniqueId().asInt64();
314 faces_infos.add(face_uid);
316 for (Node node : face.nodes()) {
317 Int64 node_uid = node.uniqueId().asInt64();
318 faces_infos.add(node_uid);
319 pos_node[node.uniqueId()] = node_coord[node];
329void MeshSectionService::
332 UniqueArray<Int64> cells_infos;
333 cells_infos.reserve(10000);
335 UniqueArray<Int64> faces_infos;
336 faces_infos.reserve(10000);
338 UniqueArray<Cell> ori_cells;
340 std::unordered_map<Int64, Real3> coord_map;
345 _createCells(nb_cell, cells_infos, nb_face, faces_infos, coord_map, ori_cells);
347 m_cloned_mesh->modifier()->addFaces(nb_face, faces_infos);
348 m_cloned_mesh->modifier()->addCells(nb_cell, cells_infos);
349 m_cloned_mesh->modifier()->endUpdate();
353 ENUMERATE_ (Node, inode, m_cloned_mesh->allNodes()) {
354 node_coords[inode] = coord_map[inode->uniqueId()];
358 _updateVariables(ori_cells);
360 info() <<
"New mesh -- NbNode : " << m_cloned_mesh->nbNode() <<
" -- NbCells : " << m_cloned_mesh->nbCell();
366void MeshSectionService::
369 for (
Int32 type = 0; type < NB_ARCANE_DATA_TYPE; ++type) {
372 _updateVariablesT(ori_cells, type,
Byte());
375 _updateVariablesT(ori_cells, type,
Real());
378 _updateVariablesT(ori_cells, type, Real2());
381 _updateVariablesT(ori_cells, type, Real2x2());
384 _updateVariablesT(ori_cells, type, Real3());
387 _updateVariablesT(ori_cells, type, Real3x3());
390 _updateVariablesT(ori_cells, type,
Int8());
393 _updateVariablesT(ori_cells, type,
Int16());
396 _updateVariablesT(ori_cells, type,
Int32());
399 _updateVariablesT(ori_cells, type,
Int64());
402 _updateVariablesT(ori_cells, type,
Float32());
405 _updateVariablesT(ori_cells, type,
Float16());
408 _updateVariablesT(ori_cells, type,
BFloat16());
420void MeshSectionService::
423 VariableOriClone<T> voc;
425 if (m_variables_cloned.count() != m_variables_ori.count()) {
429 VariableCollection::Enumerator iclone(m_variables_cloned);
430 VariableCollection::Enumerator iori(m_variables_ori);
432 while (++iclone && ++iori) {
433 IVariable* ori = *iori;
434 if (ori->dataType() == type) {
435 IVariable* clone = *iclone;
436 if (ori->dimension() == 1) {
441 voc.ori.unknown.dim1.add(ori_data->view());
442 voc.clone.unknown.dim1.add(clo_data->view());
444 else if (ori->itemKind() ==
IK_Cell) {
445 voc.ori.cells.dim1.add(ori_data->view());
446 voc.clone.cells.dim1.add(clo_data->view());
448 else if (ori->itemKind() ==
IK_Face) {
449 voc.ori.faces.dim1.add(ori_data->view());
450 voc.clone.faces.dim1.add(clo_data->view());
452 else if (ori->itemKind() ==
IK_Node) {
453 voc.ori.nodes.dim1.add(ori_data->view());
454 voc.clone.nodes.dim1.add(clo_data->view());
457 ARCANE_FATAL(
"Variable type not supported -- Type : {0}", ori->itemKind());
460 else if (ori->dimension() == 2) {
470 if (ori->itemKind() ==
IK_Cell) {
471 VariableResizeArgs vra(-1);
472 vra.setNewSizeDim2(ori->nbElement() / mesh()->
nbCell());
473 clone->_internalApi()->resize(vra);
476 voc.ori.cells.dim2.add(ori_data->view());
477 voc.clone.cells.dim2.add(clo_data->view());
479 else if (ori->itemKind() ==
IK_Face) {
480 VariableResizeArgs vra(-1);
481 vra.setNewSizeDim2(ori->nbElement() / mesh()->
nbFace());
482 clone->_internalApi()->resize(vra);
485 voc.ori.faces.dim2.add(ori_data->view());
486 voc.clone.faces.dim2.add(clo_data->view());
488 else if (ori->itemKind() ==
IK_Node) {
489 VariableResizeArgs vra(-1);
490 vra.setNewSizeDim2(ori->nbElement() / mesh()->
nbNode());
491 clone->_internalApi()->resize(vra);
494 voc.ori.nodes.dim2.add(ori_data->view());
495 voc.clone.nodes.dim2.add(clo_data->view());
499 ARCANE_FATAL(
"Variable dim not supported -- Dim : {0}", ori->dimension());
504 _updateArrayVariable(ori_cells, T(), voc);
511void MeshSectionService::
514 if (voc.ori.isUnknownUsed()) {
515 for (
Int32 i = 0; i < voc.ori.unknown.dim1.size(); ++i) {
516 voc.clone.unknown.dim1[i].copy(voc.ori.unknown.dim1[i]);
518 for (
Int32 i = 0; i < voc.ori.unknown.dim2.size(); ++i) {
519 for (
Int32 j = 0; j < voc.ori.unknown.dim2[i].dim2Size(); ++j) {
520 voc.clone.unknown.dim2[i][j].copy(voc.ori.unknown.dim2[i][j]);
526 Cell ori_cell = ori_cells[icell.localId()];
527 if (voc.ori.isCellsUsed()) {
528 for (
Int32 i = 0; i < voc.ori.cells.dim1.size(); ++i) {
529 voc.clone.cells.dim1[i][icell.localId()] = voc.ori.cells.dim1[i][ori_cell.localId()];
531 for (
Int32 i = 0; i < voc.ori.cells.dim2.size(); ++i) {
532 voc.clone.cells.dim2[i][icell.localId()].copy(voc.ori.cells.dim2[i][ori_cell.localId()]);
536 if (voc.ori.isNodesUsed()) {
537 for (
Int32 i = 0; i < icell->nbNode(); ++i) {
538 Node ori_node = ori_cell.node(i);
539 Node cloned_node = icell->node(i);
541 for (
Int32 j = 0; j < voc.ori.nodes.dim1.size(); ++j) {
542 voc.clone.nodes.dim1[j][cloned_node.localId()] = voc.ori.nodes.dim1[j][ori_node.localId()];
544 for (
Int32 j = 0; j < voc.ori.nodes.dim2.size(); ++j) {
545 voc.clone.nodes.dim2[j][cloned_node.localId()].copy(voc.ori.nodes.dim2[j][ori_node.localId()]);
550 if (voc.ori.isFacesUsed()) {
551 for (
Int32 i = 0; i < icell->nbFace(); ++i) {
552 Face ori_face = ori_cell.face(i);
553 Face cloned_face = icell->face(i);
555 for (
Int32 j = 0; j < voc.ori.faces.dim1.size(); ++j) {
556 voc.clone.faces.dim1[j][cloned_face.localId()] = voc.ori.faces.dim1[j][ori_face.localId()];
558 for (
Int32 j = 0; j < voc.ori.faces.dim2.size(); ++j) {
559 voc.clone.faces.dim2[j][cloned_face.localId()].copy(voc.ori.faces.dim2[j][ori_face.localId()]);
#define ARCANE_CHECK_POINTER(ptr)
Macro retournant le pointeur ptr s'il est non nul ou lancant une exception s'il est nul.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
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.
Integer nbNode() const
Retourne le nombre de noeuds du maillage.
Integer nbCell() const
Retourne le nombre de mailles du maillage.
Integer nbFace() const
Retourne le nombre de faces du maillage.
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).
__host__ __device__ Real dot(Real2 u, Real2 v)
Produit scalaire de u par v dans .
__host__ __device__ Real3 normalizeReal3(Real3 v)
Normalisation d'un Real3.
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::int8_t Int8
Type entier signé sur 8 bits.
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
@ Float16
Donnée de type Float16.
eServiceType
Type du service.
@ ST_CaseOption
Le service s'utilise au niveau du jeu de données.
@ IK_Node
Entité de maillage de genre noeud.
@ IK_Cell
Entité de maillage de genre maille.
@ IK_Unknown
Entité de maillage de genre inconnu ou non initialisé
@ IK_Face
Entité de maillage de genre face.
std::int16_t Int16
Type entier signé sur 16 bits.
double Real
Type représentant un réel.
unsigned char Byte
Type d'un octet.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Créé une référence sur un pointeur.
float Float32
Type flottant IEEE-753 simple précision.
@ DT_Float32
Donnée de type 'Float32'.
@ DT_Real2x2
Donnée de type tenseur 3x3.
@ DT_Int16
Donnée de type entier 16 bits.
@ DT_Int8
Donnée de type entier sur 8 bits.
@ DT_Real3x3
Donnée de type tenseur 3x3.
@ DT_Int32
Donnée de type entier 32 bits.
@ DT_Real3
Donnée de type vecteur 3.
@ DT_Float16
Donnée de type 'Float16'.
@ DT_Int64
Donnée de type entier 64 bits.
@ DT_BFloat16
Donnée de type 'BFloat16'.
@ DT_Real2
Donnée de type vecteur 2.
@ DT_Real
Donnée de type réel.
@ DT_Byte
Donnée de type octet.
@ Cell
Le maillage est AMR par maille.
std::int32_t Int32
Type entier signé sur 32 bits.
Arcane::BFloat16 BFloat16
Type 'Brain Float16'.