14#include "arcane/utils/ArgumentException.h"
16#include "arcane/core/IMesh.h"
17#include "arcane/core/IMeshFactoryMng.h"
18#include "arcane/core/IMeshMng.h"
19#include "arcane/core/IMeshModifier.h"
20#include "arcane/core/IPrimaryMesh.h"
21#include "arcane/core/MeshBuildInfo.h"
22#include "arcane/core/IMeshSection.h"
23#include "arcane/core/IVariableMng.h"
24#include "arcane/core/VariableMetaData.h"
26#include "arcane/core/internal/IVariableInternal.h"
27#include "arcane/core/internal/IVariableMngInternal.h"
29#include "arcane/std/MeshSection_axl.h"
46 UniqueArray<ArrayView<T>> dim1;
47 UniqueArray<Array2View<T>> dim2;
51struct VariableGroupType
53 bool isUnknownUsed() {
return !(unknown.dim1.empty() && unknown.dim2.empty()); }
54 bool isCellsUsed() {
return !(cells.dim1.empty() && cells.dim2.empty()); }
55 bool isFacesUsed() {
return !(faces.dim1.empty() && faces.dim2.empty()); }
56 bool isNodesUsed() {
return !(nodes.dim1.empty() && nodes.dim2.empty()); }
58 VariableGroup<T> unknown;
59 VariableGroup<T> cells;
60 VariableGroup<T> faces;
61 VariableGroup<T> nodes;
65struct VariableOriClone
67 VariableGroupType<T> ori;
68 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 returning the pointer ptr if it is not null or throwing an exception if it is null.
#define ARCANE_FATAL(...)
Macro throwing a 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
Searches for the mesh with name name.
virtual void clearItems()=0
Deletes all entities of all families in this mesh.
virtual IMeshModifier * modifier()=0
Associated modifier interface.
virtual IMeshMng * meshMng() const =0
Returns the mesh manager.
CellGroup ownCells() const
Returns the group containing all cells specific to this domain.
Integer nbNode() const
Returns the number of nodes in the mesh.
Integer nbCell() const
Returns the number of cells in the mesh.
Integer nbFace() const
Returns the number of faces in the mesh.
void addPlane(const Real3 &p0, const Real3 &normal) override
Method allowing to add a plane to the cut service. The use of these planes depends on the service.
void updateSection() override
Method allowing to update the mesh section with all planes.
MeshHandle meshSection() override
Méthod allowing to get the mesh section.
VariableCollection variables() override
Method allowing to get a set of variables copied on the new mesh.
void setVariables(VariableCollection variables) override
Method allowing to add a set of variables to copy on the new mesh.
void setServiceMeshUniqueId(Int32 unique_id) override
Method allowing to set a unique id allowing to create multiple section services for a mesh.
Class managing a 3-dimensional real vector.
eServiceType creationType() const
Type of service that can be created by this instance.
Structure containing the information to create a service.
TraceMessage info() const
Flow for an information message.
1D data vector with value semantics (STL style).
__host__ __device__ Real dot(Real2 u, Real2 v)
Dot product of u by v in .
__host__ __device__ Real3 normalizeReal3(Real3 v)
Normalization of a Real3.
MeshVariableScalarRefT< Face, Byte > VariableFaceBool
Quantity at the face of boolean type.
MeshVariableScalarRefT< Node, Real3 > VariableNodeReal3
Coordinate type quantity at node.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int8_t Int8
Signed integer type of 8 bits.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
@ Float16
Float16 data type.
eServiceType
Service type.
@ ST_CaseOption
The service is used at the dataset level.
@ IK_Node
Node mesh entity.
@ IK_Cell
Cell mesh entity.
@ IK_Unknown
Unknown or uninitialized mesh entity.
@ IK_Face
Face mesh entity.
std::int16_t Int16
Signed integer type of 16 bits.
double Real
Type representing a real number.
unsigned char Byte
Type of a byte.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
float Float32
IEEE-753 single-precision floating-point type.
@ DT_Float32
'Float32' data type
@ DT_Real2x2
2x2 tensor data type
@ DT_Int16
16-bit integer data type
@ DT_Int8
8-bit integer data type
@ DT_Real3x3
3x3 tensor data type
@ DT_Int32
32-bit integer data type
@ DT_Real3
Vector 3 data type.
@ DT_Float16
'Float16' data type
@ DT_Int64
64-bit integer data type
@ DT_BFloat16
'BFloat16' data type
@ DT_Real2
Vector 2 data type.
@ Cell
The mesh is AMR by cell.
std::int32_t Int32
Signed integer type of 32 bits.
Arcane::BFloat16 BFloat16
Type 'Brain Float16'.