Back to index

salome-med  6.5.0

Introduction

The MEDCoupling module is presented under the form of a library libmedcoupling and interfaces. This module MEDCoupling represents the DataStructure designed to be exchanged by processors as well in parallel case in SPMD paradigm ( ParaMEDMEM ), as in distributed paradigm using CORBA. This DataStructure is fully deconnected from MEDMEM. This DataStructure is light in order to minimize as much as possible the number of prerequisites needed to use it. The idea is that as this DataStructure is intended to be linked with all of code candidate for coupling ; the number of prerequisites of medcoupling has to be threfore tiny. MEDCoupling has been developped to comply with ICOCO API, conservative interpolators and VTK visualization DataStructure. The MEDCoupling DataStructures have been developped to be compatible with HPC constraints (compact structures, limitation of copies and launching of CPU consuming algorithms only when absolutely needed ).

Basics

One of the most basic concept mainly used all over MEDCoupling is MEDCoupling array. This concept is used all over MEDCoupling/ParaMEDMEM/MEDLoader modules so it should be correctly handled to play well with Meshes and Fields.

There are two types of arrays :

To learn more about arrays click here for arrays documentation.

Main Concepts

Building unstructured mesh from scratch

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

Here we will create a mesh with spacedim==2 and meshdim==2 too with 5 cells and 9 nodes.

You can notice that it is possible to mix cell types as long as the dimension of cell is exactly equal to meshDim to respect this rule.

double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 };
int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4};
MEDCouplingUMesh *mesh=MEDCouplingUMesh::New();
mesh->setName("My2DMesh");
mesh->setMeshDimension(2);
mesh->allocateCells(5);//You can put more than 5 if you want but not less.
mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn+4);
mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn+7);
mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10);
mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14);
mesh->finishInsertingCells();
DataArrayDouble *myCoords=DataArrayDouble::New();
myCoords->alloc(9,2);//here myCoords are declared to have 2 components, mesh will deduce that spaceDim==2
std::copy(coords,coords+18,myCoords->getPointer());
mesh->setCoords(myCoords);
myCoords->decrRef();
//mesh is now usable
...
//mesh is no more usefully here : release it
mesh->decrRef();  

Building a field from scratch

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

Here we will make the assumption that an instance of MEDCouplingMesh called mesh has been created.

Operations on Fields

Here we will make the assumption that an instance of MEDCouplingMesh called mesh has been created with spaceDim==2. Here some exemple of more advanced use of MEDCouplingFieldDouble.

MEDCouplingFieldDouble <em>f1=mesh->fillFromAnalytic(ON_NODES,1,"x*x+y*y*3+2.*x");//f1 is scalar
MEDCouplingFieldDouble *f2=mesh->fillFromAnalytic(ON_NODES,1,"cos(x+y/x)");//f2 is scalar too
MEDCouplingFieldDouble *f2bis=mesh->fillFromAnalytic(ON_NODES,2,"x*x*IVec+3*y*JVec");//f2bis is a vectors field
MEDCouplingFieldDouble *f3=(*f1)+(*f2);//f3 scalar
MEDCouplingFieldDouble *f4=(*f3)/(*f2);//f4 scalar
f2bis->applyFunc(1,"sqrt(x*x+y*y)");//f2bis becomes scalar
MEDCouplingFieldDouble *f5=(*f2bis)</em>(*f4);//f5 scalar
const double pos1[2]={0.25,0.};
double res;
f4->getValueOn(pos1,&res);//f4 is scalar so the returned value is of size 1.
//
...
//f1, f2, f2bis, f3, f4, f5 are no more usefully here : release them
f1->decrRef();
f2->decrRef();
f2bis->decrRef();
f3->decrRef();
f4->decrRef();
f5->decrRef();