Back to index

salome-med  6.5.0
MEDCoupling Arrays

Introduction

This page will try to describe data arrays in MEDCoupling. Presently, in MEDCoupling it exists two types of arrays :

Basics concepts

It will be presented in this section common concept shared by the two classes to DataArrayDouble and DataArrayInt.

Building an array from scratch in Python

arrayDouble=DataArrayDouble.New();
dataDouble=[0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.]
arrayDouble.setValues(dataDouble,5,3);# 5 tuples containing each 3 components
#####
arrayInt=DataArrayInt.New();
dataInt=[0, 10, 20, 1, 11, 21, 2, 12, 22, 3, 13, 23, 4, 14, 24]
arrayInt.setValues(dataInt,5,3);# 5 tuples containing each 3 components

Building an array from scratch in C++

All of exemples given here make the assumption that the ParaMEDMEM namespace is visible ( by calling for example using namespace ParaMEDMEM; ).

Here a description of typical usages to use MEDCoupling arrays.
In this example we will create arrays with 12 tuples constituted each of 3 components. These arrays will be created using different ways.

The following code is only based using DataArrayDouble but the use of DataArrayInt is strictly equivalent.

const int nbOfNodes=12;
double coords[3*nbOfNodes]={ ... };

DataArrayDouble *myCoords=0;
double *tmp=0;

Array renumbering

Here is presented all it is necessary to know concerning renumbering. Renumbering is intensely required in MEDLoader in ParaMEDMEM. One of the user of renumbering is MED file for I/O where cells are sorted by type. But it is also used on operations of node cell merging. It is also used in parallel mode when splitting of mesh is needed...

Formally a renumbering is a mathematical application that can be surjective, injective or bijective. This application is defined using an instance of DataArrayInt. There are different ways to define this application.

Old to new mode

The old to new mode is particulary recommanded for surjective and bijective application. This is typically the case of MEDCouplingUMesh::mergeNodes method. Let's consider a call to mergeNodes that reduces the number of nodes from 5 nodes to 3 nodes.
In old to new mode the array MySurjection that specifies this surjection will have 5 tuples and 1 component. The content of the 5*1 values will be in {0,1,2}.

If MySujection equals [2,1,0,1,2], it means that :

This is the most common mode of renumbering in MEDCoupling because there is more methods implying renumbering that reduce the number of entities than method that increase number of entities.

Method in old to new mode that works on bijective applications :

Method in old to new mode that works on surjective applications :

Sometimes the format old to new for sujections can be replaced by another format with 2 arrays. Less compact in memory. The DataArrayInt::changeSurjectiveFormat method performs that.

New to old mode

The new to old mode is particulary recommanded for strictly injective and bijective permutations. This is particulary usefull for methods that increase the number of entities like for example MEDCouplingUMesh::simplexize.
All non static methods in DataArrayDouble or DataArrayInt having as last letter R (meaning Reversed) in capital works with the mode new to old. Let's consider a call to simplexize that increases the number of cell from 4 cells to 6 cells.
In new to old mode the array MyInjection that specifies this injection will have 6 tuples and 1 component. The content of the 5*1 values will be in {0,1,2,3}.
If MyInjection equals [2,0,1,1,3,0] it means that :

Method in new to old mode that works on bijective applications :

Method in new to old mode that works on surjective applications :