User's Guide of Med Memory V 3.2
User's Guide of Med Memory V 3.2
Patrick Goldbronn
Eric Fayolle
Jerome Roy
Nicolas Crouzet
Contents
1 Introduction
1.1 Rationale for Med Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2 Outline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.3 Naming conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.4 Limitations and advantages regarding Med-File . . . . . . . . . . . . . . . . . . .
2 Med Memory API
2 2 3 4
5
5 5 5 7
10
10
11
4.1 General Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.1.1 Full C++ example : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2 Information about nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2.1 Full C++ example : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3 Information about cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3.1 Full C++ example : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4 Information about FAMILY and GROUP . . . . . . . . . . . . . . . . . . . . . .
5 How to use SUPPORT object
11 11 12 13 14 15 18
19
5.1 Create a SUPPORT object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2 Use a SUPPORT object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3 Case of FAMILY object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4 Case of GROUP object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
19 20 20 21
22
6.1 Introduction . . . . . . . . . 6.1.1 Full C++ example : 6.2 Create a Field . . . . . . . . 6.2.1 Full C++ example :
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
22 23 24 25
27
7.1 Build a MESHING . . . . . 7.1.1 Coordinates . . . . . 7.1.2 Connectivities . . . . 7.2 Dened a GROUP object . 7.2.1 WARNING . . . . . 7.2.2 Full C++ example :
8 Using drivers
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
27 27 27 28 28 28
35
8.1 Invoking a driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.1.1 Invoking a driver at creation object time . . . . . . . . . . . . . 8.1.2 Full C++ example : . . . . . . . . . . . . . . . . . . . . . . . . 8.1.3 Invoking a driver from the standard driver method of an object 8.1.4 Full C++ example : . . . . . . . . . . . . . . . . . . . . . . . . 8.1.5 Invoking a driver and attaching it to an existing object . . . . . 8.1.6 Full C++ example : . . . . . . . . . . . . . . . . . . . . . . . . 8.2 Using the MED driver . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2.1 Exploring les . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2.1.1 Adding existing MESHes/FIELDs objects . . . . . . . 8.3 Using the VTK driver . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.4 Using the GIBI driver . . . . . . . . . . . . . . . . . . . . . . . . . . .
9 Appendix: Python example scripts.
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
35 35 35 37 37 38 39 40 41 41 41 42
43
Full Python example for 4.1.1 : Full Python example for 4.2.1 : Full Python example for 4.3.1 : Full Python example for 6.1.1 : Full Python example for 6.2.1 : Full Python example for 7.2.2 : Full Python example for 8.1.2 : Full Python example for 8.1.4 : Full Python example for 8.1.6 :
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . . 2
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
43 44 45 48 49 51 61 62 63
References Bibliography
65 65
Chapter 1
Introduction
memory. Memory
Python API generated using SWIG which wraps the complete C++ API of the MED CORBA API to simplify distributed computation inside SALOME (Server Side). MED Client classes to simplify and optimize interaction of distant objects within the local
solver.
Thanks to Med Memory, any component can access a distant mesh or eld object. Two codes running on dierent machines can thus exchange meshes and elds. These meshes and elds can easily be read/written in a Med le format, enabling access to the whole Salome suite of tools (CAD, meshing, Visualization, other components).
1.2 Outline
In this document, we describe the API of the Med Memory library (available in C++ and in Python). This document is intended for developers who are in charge of integrating existing applications in the Salome platform. As will be seen in section 2, the API consists of very few classes:
a general MED container,
meshes, supports and derived classes, elds drivers for reading and writing in MED, GIBI and VTK les.
All these are detailed in the following sections. The C++ formalism will be used for the description in these sections. Python syntax is very similar and is given in appendix 9.
group support with additional access to parent families. iteration number information attached to a eld that expresses the number of the time step in the computation (1 is its default value). name information attached to a mesh, support or eld to name it and access to it. node entity of dimension 0. order number information attached to a eld that expresses the number of an internal iteration inside a time step in the computation (1 is its default value). support list of elements of the same entity. type category of an entity (triangle, segment, quadrangle, tetrahedron, hexahedron, etc...).
The eld notion in Med File and Med Memory is quite dierent. In Med memory a eld is of course its name, but as well its iteration number, its order number and nally its corresponding sot of values. But in Med File a eld is only agged by its name.
Chapter 2
Med Memory API
2.1 Conventions
In this document, one refers to the main user documentation [2] where the variable $MED_ROOT_DIR (resp. $MED_SRC_DIR) is the Med Memory directory installation (resp.
sources directory).
All numberings start at one (take care of array index !). When one gets a C (resp. C++) type array (resp. container) using a get... method,
one should not replace some value of it. Access is in read only. Other use may product an impredicable result. To modify a such array (resp. container) use a set... method. plural). The plural method returns an array and the singular one returns one particular value in this array (see method double getCoordinate(int i) and method double* getCoordinates() for example).
There are many couple of methods that have similar syntaxes (one singular and one
Dierence between local and global number in mesh element connectivity list : when one talks about an element number, one could see ith quadrangle (ith in quadrangles array : local numbering) or j th element (j th in all elements array : global numbering). These two
numbering are equivalent only if one has only one geometric type ;
2.2 Namespaces
Med Memory uses two namespaces : MEDMEM which is the general namespace where the main classes are dened and MED_EN which denes enums that can be used by an English-speaking programer.
2.3 Classes
At a basic usage level, the API consists in few classes which are located in the MEDMEM C++ namespace (consult gure 2.1 which gives an UML diagram view of the main Med Memory classes :
MED the global container;
The API of those classes is quite sucient for most of the component integrations in the Salome platform. The use of the Med Memory libraries may make easier the code coupling in the Salome framework. With these classes, it is possible to :
read/write meshes and elds from MED-les; create elds containing scalar or vectorial values on list of elements of the mesh; communicate these elds between dierent components; read/write such elds.
Note that on the gure 2.1 as well as 2.2 that the MED container controls the life cycle of all the objects it contains : its destructor will destroy all the objects it aggregates. On the other hand, the life cycle of mesh, support and eld objects are independent. Destroying a support (resp. a mesh) will have no eect on the elds (resp. on the support) which refer to it. But the user has to maintain the link : a mesh agregates a support which agregates a eld. If the user has to delete Med Memory objects, the eld has to be deleted rst, then the support and nally the mesh. A more advanced usage of the Med Memory is possible through other classes. Figure 2.2 gives a complete view of the Med Memory API. It includes :
GROUP a class inherited from the SUPPORT class used to create supports linked to mesh groups. It stores restricted list of elements used to set boundary conditions, initial values.
2.4 Enums
A few enums are dened in the MED_EN namespace :
The medGeometryElement enum which denes geometry types. The available types are lin-
ear and quadratic elements (consult [2]). The entries of the enum are quite self-explanatory :
MED_NONE MED_POINT1 MED_SEG2 MED_SEG3
MED_TRIA3 MED_QUAD4 MED_TRIA6 MED_QUAD8 MED_TETRA4 MED_PYRA5 MED_PENTA6 MED_HEXA8 MED_TETRA10 MED_PYRA13 MED_PENTA15 MED_HEXA20 MED_POLYGON MED_POLYHEDRA MED_ALL_ELEMENTS
an enum which contains the dierent mesh entities, medEntityMesh, the entries of which
being :
an enum which describes the way node coordinates or eld values are stored,
MED_FULL_INTERLACE for arrays such that x1 , y1 , z1 , x2 , y2 , z2 , . . . , xn , yn , zn ; MED_NO_INTERLACE for arrays such that x1 , x2 , . . . , xn , y1 , y2 , . . . , yn , z1 , z2 , . . . , zn ; MED_UNDEFINED_INTERLACE, the undened interlacing mode.
an enum which describes the type of connectivity
10
Chapter 3
How to use MED object
The destructor of this object will destruct itself all FIELD, SUPPORT and MESH objects; via its get method you will have a pointer on this object and you should never delete it. One can add as well some MESH or FIELD object via the method addMesh and the method addField respectively. To write a complete MED object in an available writing format, on may use method addDriver and then method write. For an example using these methods, one may see the Python scripts in the directory $MED_ROOT_DIR/bin/salome/,testMedObj.py, or C++ example program in the directory $MED_SRC_DIR/src/MEDMEM, duplicateMED.cxx.
11
Chapter 4
How to use MESH object
Here is a small C++ example program which the Python version may be found in 9.1.
12
// See http://www.salome-platform.org/ or email : [email protected] // using namespace std; #include "MEDMEM_Mesh.hxx" using namespace MEDMEM ; int main (int argc, char ** argv) { const string MedFile = "pointe.med" ; const string MeshName = "maa1" ; // create a MESH object by reading it on file : MESH myMesh(MED_DRIVER,MedFile,MeshName) ; string Name = myMesh.getName() ; if (Name != MeshName) { cout << "Error when reading mesh name : We ask for mesh #" << MeshName <<"# and we get mesh #"<< Name <<"#"<< endl << endl ; return -1; } cout << "Mesh name : " << Name << endl << endl ; int SpaceDimension = myMesh.getSpaceDimension() ; int MeshDimension = myMesh.getMeshDimension() ; cout << "Space Dimension : " << SpaceDimension << endl << endl ; cout << "Mesh Dimension : " << MeshDimension << endl << endl ; } return 0 ;
When we get coordinates in MED_NO_INTERLACE mode, we get an array where values are ordered like (X1,X2,X..., Y1,Y..., Z1,Z...). When we get coordinates in MED_FULL_INTERLACE mode, we get an array where values are ordered like (X1,Y1,Z1, X2,Y2,Z2, ...).
6. I want to get one particular value of coordinate : use method getCoordinate which returns the value of ith node and j th axis. Here is a small C++ example program which the Python version may be found in 9.2.
#include "MEDMEM_Mesh.hxx" using namespace MEDMEM ; using namespace MED_EN ; int main (int argc, char ** argv) { const string MedFile = "pointe.med" ; const string MeshName = "maa1" ; MESH myMesh(MED_DRIVER,MedFile,MeshName) ; cout << "Mesh name : " << myMesh.getName() << endl << endl ; int SpaceDimension = myMesh.getSpaceDimension() ; int NumberOfNodes = myMesh.getNumberOfNodes() ;
14
cout << "Space dimension : " << SpaceDimension << endl << endl ; cout << "Number of nodes : " << NumberOfNodes << endl << endl ; cout << "Show Nodes Coordinates : " << endl ; // coordinates names : cout << "Name :" << endl ; const string * CoordinatesNames = myMesh.getCoordinatesNames() ; for(int i=0; i<SpaceDimension ; i++) { cout << " - " << CoordinatesNames[i] << endl ; } // coordinates unit : cout << "Unit :" << endl ; const string * CoordinatesUnits = myMesh.getCoordinatesUnits() ; for(int i=0; i<SpaceDimension ; i++) { cout << " - " << CoordinatesUnits[i] << endl ; } // coordinates value const double * Coordinates = myMesh.getCoordinates(MED_FULL_INTERLACE) ; for(int i=0; i<NumberOfNodes ; i++) { cout << "Nodes " << i+1 << " : " ; for (int j=0; j<SpaceDimension ; j++) cout << Coordinates[i*SpaceDimension+j] << " " ; cout << endl ; } } return 0 ;
use method
2. I want to get all geometric type for a mesh entity : use method getTypes to get an array of medGeometryElement (to use directly in others methods). C++ Example :
const medGeometryElement * Types = myMesh.getTypes(MED_CELL);
(array is of size NumberOfCellsTypes) 3. I want to get the number of cells : use method getNumberOfElements which return this information. You must give the mesh entity (MED_CELL, MED_FACE, MED_EDGE or MED_NODE) and a geometric type of this entity. C++ Example :
int NumberOfTriangle = myMesh.getNumberOfElements(MED_FACE,MED_TRIA3);
15
4. I want to get the geometric type of one element : use method getElementType which return a medGeometryElement. C++ Example :
medGeometryElement myType = myMesh.getElementType(MED_FACE,10);
Return the medGeometryElement of 10th face. 5. I want to get a connectivity : use method getConnectivity which return an array with connectivity values. C++ Example :
int NumberOfTetrahedron = myMesh.getNumberOfElements(MED_CELL,MED_TETRA4); const int * TetrahedronConnectivity = myMesh.getConnectivity(MED_FULL_ENTERLACE, MED_NODAL, MED_CELL, MED_TETRA4); TetrahedronConnectivity contain nodal connectivity of tetrahedron in mesh. It is arranged in full enterlace mode and its size is NumberOfTetrahedron x 4.
If you want to get connectivity of all elements (with Type=MED_ALL_ELEMENTS), you must use the index array (return by method getConnectivityIndex) to get connectivity for each elements (see example 4.3.1, page 15). 6. I want to get an element number from a connectivity : use method getElementNumber which return the global number of a given connectivity. C++ Example :
int * myElementConnectivity = {2,10,12,14}; int myNumber = myMesh.getElementNumber(MED_NODAL,MED_CELL, myElementConnectivity);
Here is a small C++ example program which the Python version may be found in 9.3.
16
// // // // // // // // // //
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA See http://www.salome-platform.org/ or email : [email protected]
#include "MEDMEM_Mesh.hxx" using namespace MEDMEM ; using namespace MED_EN ; int main (int argc, char ** argv) { // const string MedFile = "polyedres.med" ; // const string MeshName = "Erreur orientation" ; // const string MedFile = "polygones.med" ; // const string MeshName = "Bord" ; const string MedFile = "pointe.med" ; const string MeshName = "maa1" ; MESH myMesh(MED_DRIVER,MedFile,MeshName) ; cout << "Mesh name : " << myMesh.getName() << endl << endl ;
// we get all type for cell entity : int NumberOfTypes = myMesh.getNumberOfTypes(MED_CELL) ; cout << "Show Connectivity (Nodal) :" << endl ; // this example use access with a specified medGeometryElement array const medGeometryElement * Types = myMesh.getTypes(MED_CELL); string * cellTypeNames = myMesh.getCellTypeNames(MED_CELL); for (int i=0; i<NumberOfTypes; i++) { cout << "For type " << cellTypeNames[i] << " : " << endl ; medGeometryElement myType = Types[i] ; int NumberOfElements = myMesh.getNumberOfElements(MED_CELL,myType); int NomberOfNodesPerCell = Types[i]%100 ; const int * Connectivity = myMesh.getConnectivity(MED_NODAL,MED_CELL,myType); for (int j=0; j<NumberOfElements; j++){ cout << "Element "<< j+1 <<" : " ; for (int k=0; k<NomberOfNodesPerCell; k++) cout << Connectivity[j*NomberOfNodesPerCell+k]<<" "; cout << endl ; } } cout << "Show Reverse Nodal Connectivity :" << endl ; // this example use global access with index array int NumberOfNodes = myMesh.getNumberOfNodes() ;
17
const int * ReverseNodalConnectivity = myMesh.getReverseConnectivity(MED_NODAL) ; const int * ReverseNodalConnectivityIndex = myMesh.getReverseConnectivityIndex(MED_NODAL) ; for (int i=0; i<NumberOfNodes; i++) { cout << "Node "<<i+1<<" : " ; int IndexBegin = ReverseNodalConnectivityIndex[i] ; int IndexEnd = ReverseNodalConnectivityIndex[i+1] ; for (int j=IndexBegin; j<IndexEnd; j++) // Index value begin at 1 so use j-1 cout << ReverseNodalConnectivity[j-1] << " " ; cout << endl ; } cout << "Show Connectivity (Descending) :" << endl ; // this example use global access with index array int NumberOfElements = myMesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS); const int * DescendingConnectivity = myMesh.getConnectivity(MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS); const int * DescendingConnectivityIndex = myMesh.getConnectivityIndex(MED_DESCENDING,MED_CELL); for (int i=0; i<NumberOfElements; i++) { cout << "Element "<<i+1<<" : " ; int IndexBegin = DescendingConnectivityIndex[i] ; int IndexEnd = DescendingConnectivityIndex[i+1] ; for (int j=IndexBegin; j<IndexEnd; j++) // Index value begin at 1 so use j-1 cout << DescendingConnectivity[j-1] << " " ; cout << endl ; } cout << "Show Reverse Descending Connectivity :" << endl ; // this example use global access with Index array const int * ReverseDescendingConnectivity = myMesh.getReverseConnectivity(MED_DESCENDING) ; const int * ReverseDescendingConnectivityIndex = myMesh.getReverseConnectivityIndex(MED_DESCENDING) ; int MeshDimension = myMesh.getMeshDimension() ; int NumberOfConstituents = 0; string Constituent ; medEntityMesh ConstituentEntity ; // test if we have face (3D) or edge (2D) if (MeshDimension==3) { Constituent = "Face" ; ConstituentEntity = MED_FACE ; } if (MeshDimension==2) { Constituent = "Edge" ; ConstituentEntity = MED_EDGE ;
18
} NumberOfConstituents = myMesh.getNumberOfElements(ConstituentEntity,MED_ALL_ELEMENTS); if (MeshDimension==1) { MESSAGE_MED("ERROR : MeshDimension = 1 !"); MESSAGE_MED("We could not see Reverse Descending Connectivity.") ; } else { for (int i=0; i<NumberOfConstituents; i++) { cout << Constituent << " " << i+1 << " : " ; int IndexBegin = ReverseDescendingConnectivityIndex[i] ; int IndexEnd = ReverseDescendingConnectivityIndex[i+1] ; for (int j=IndexBegin;j<IndexEnd;j++) // Index value begin at 1 so use j-1 cout << ReverseDescendingConnectivity[j-1] << " " ; cout << endl ; } } cout << "Show "<< Constituent <<" Connectivity (Nodal) :" << endl ; // this example use global access with index array const int * ConstituentConnectivity = myMesh.getConnectivity(MED_NODAL,ConstituentEntity,MED_ALL_ELEMENTS); const int * ConstituentConnectivityIndex = myMesh.getConnectivityIndex(MED_NODAL,ConstituentEntity); for (int i=0; i<NumberOfConstituents; i++) { cout << Constituent << " " << i+1 << " : " ; int IndexBegin = ConstituentConnectivityIndex[i] ; int IndexEnd = ConstituentConnectivityIndex[i+1] ; for (int j=IndexBegin; j<IndexEnd; j++) // Index value begin at 1 so use j-1 cout << ConstituentConnectivity[j-1]<<" "; cout << endl ; } } return 0 ;
19
Chapter 5
How to use SUPPORT object
C++ example :
If you want a restricted SUPPORT, you must add manualy information about what do you want :
is not on all elements : mySupport.setAll(false); on how many geometric type : mySupport.setNumberOfGeometricType(myNumberOfGeometricType); on which geometric type : mySupport.setGeometricType(myGeometricType); Temporary : the Gauss point number for each geometric type : mySupport.setNumberOfGaussPoint(myNumberOfGaussPoint); the number of elements for each geometric type : mySupport.setNumberOfEntities(myNumberOfEntities); the total number of elements : mySupport.setTotalNumberOfEntities(myTotalNumberOfEntities); the array which contains elements for each geometric type : mySupport.setNumber(myNumber);
You could also use method setpartial which set all you need. 20
For details about this methods, see the reference manual [1]. The use of method getNumber and method getNumberIndex are the same as method getConnectivity and method getConnectivityIndex (see item 5, page 15 There is another particular method to blend another SUPPORT object into it. For example in C++ :
SUPPORT mySupport ; SUPPORT myOtherSupport ; ... mySupport.blending(myOtherSupport) ; mySupport contain now all elements dened originally in it, more those dened in myOtherSupport.
method getNumberOfGroups return the number of groups which it belog to. method getGroupsNames and method getGroupName return a string array or a string
method getFamilies and method getFamily return a FAMILY array or a FAMILY that
22
Chapter 6
How to use Field
6.1 Introduction
A eld is characterized by its name (method getName) and an optional description (method getDescription). It is also characterized by this calculating moment :
an iteration number (time step number) an order number (use if there are internal iteration in a time step) the time that correspond to this iteration number.
By default, there are no iteration and order number dened (value MED_NOPDT and MED_NONOR). A eld contain values which apply on some nodes or elements (cell, face or edge). We nd these informations from a SUPPORT object (see method getSupport). Each eld have a number of components (method getNumberOfComponents) and all these components have a name (method getComponentsNames and method getComponentName), a description (method getComponentsDescriptions and method getComponentDescription) and an unit (method getMEDComponentsUnits and method getMEDComponentUnit). To get values of a FIELD, you could use method getValue, method getValueI and method getValueIJ :
First return a reference to all values in the given mode (full or no interlace). Second return a reference to ith element values or component values (in accordance with
Here is a small C++ example program which the Python version may be found in 9.4.
23
using namespace std; #include "MEDMEM_Mesh.hxx" #include "MEDMEM_Field.hxx" using namespace MEDMEM; using namespace MED_EN ; int main (int argc, char ** argv) { const string MedFile = "pointe.med" ; const string MeshName = "maa1" ; const string FieldName = "fieldcelldoublevector" ; /* read MESH */ MESH * myMesh = new MESH(MED_DRIVER,MedFile,MeshName) ; // myMesh->read() ; /* read FIELD */ // we need a support : const SUPPORT * mySupport = myMesh->getSupportOnAll(MED_CELL); FIELD<double> myField(mySupport,MED_DRIVER,MedFile,FieldName) ; // myField.read() ; /* what in Field ? */ // How many components int NumberOfCompoennts = myField.getNumberOfComponents() ;
24
const string * ComponentsNames = myField.getComponentsNames(); const string * ComponentsDescriptions = myField.getComponentsDescriptions(); const string * ComponentsUnits = myField.getMEDComponentsUnits(); for(int i=0;i<NumberOfCompoennts; i++) { cout << "Component " << i << " :" <<endl ; cout << " - name : " << ComponentsNames[i] << endl ; cout << " - description : " << ComponentsDescriptions[i] << endl ; cout << " - unit : " << ComponentsUnits[i] << endl ; } // Which iteration : int IterationNumber = myField.getIterationNumber() ; // negative mean undefined int OrderNumber = myField.getOrderNumber() ; // internal iteration at this time iteration, negative mean undefined double Time = myField.getTime() ; cout << "Iteration " << IterationNumber << " at time " << Time << " (and order number " << OrderNumber << ")" << endl ; // How many Value : int NumberOfValue = mySupport->getNumberOfElements(MED_ALL_ELEMENTS); // Value const double * Value = myField.getValue(); for(int i=0; i<NumberOfValue; i++) { for(int j=0; j<NumberOfCompoennts; j++) cout << Value[i*NumberOfCompoennts+j] << " " ; cout << endl ; } myMesh->removeReference(); } return 0 ;
You must now set a name (method setName) and optionaly a description (method setDescription). By default there are no iteration and order number (negative values) and time is null. You could change this by using method setIterationNumber, method setOrderNumber and method setTime. You SHOULD also set unit of your components with method setMEDComponentUnit To set value, use method setValueIJ to put new value of eld. 25
Here is a small C++ example program which the Python version may be found in 9.5.
using namespace std; #include "MEDMEM_Mesh.hxx" #include "MEDMEM_Field.hxx" using namespace MEDMEM; using namespace MED_EN ; int main (int argc, char ** argv) { const string MedFile = "pointe.med" ; const string MeshName = "maa1" ; /* read MESH */ MESH * myMesh = new MESH(MED_DRIVER,MedFile,MeshName) ; // we need a support : const SUPPORT * mySupport = myMesh->getSupportOnAll(MED_CELL); /* create FIELD on mySupport, with 3 components */ int NumberOfCompoennts = 3 ; FIELD<double> myField(mySupport,NumberOfCompoennts) ; const string FieldName = "fieldcelldouble" ; myField.setName(FieldName) ;
26
// Components information string * ComponentsNames = new string[NumberOfCompoennts] ; ComponentsNames[0] = "Vx" ; ComponentsNames[1] = "Vy" ; ComponentsNames[2] = "Vz" ; myField.setComponentsNames(ComponentsNames) ; string * ComponentsDescriptions = new string[NumberOfCompoennts] ; ComponentsDescriptions[0] = "vitesse selon x" ; ComponentsDescriptions[1] = "vitesse selon y" ; ComponentsDescriptions[2] = "vitesse selon z" ; myField.setComponentsDescriptions(ComponentsDescriptions) ; string * ComponentsUnits = new string[NumberOfCompoennts] ; ComponentsUnits[0] = "m.s-1" ; ComponentsUnits[1] = "m.s-1" ; ComponentsUnits[2] = "m.s-1" ; myField.setMEDComponentsUnits(ComponentsUnits) ; // Iteration information : int IterationNumber = 10 ; // set value to MED_NOPDT if undefined (default) myField.setIterationNumber(IterationNumber) ; int OrderNumber = 1 ; // set value to MED_NONOR if undefined (default) myField.setOrderNumber(OrderNumber) ; double Time = 3.435678 ; // in second myField.setTime(Time) ; // Value : int NumberOfValue = mySupport->getNumberOfElements(MED_ALL_ELEMENTS); for(int i=1; i<=NumberOfValue; i++) // i^th element for (int j=1; j<=NumberOfCompoennts; j++) { // j^th component double myValue = (i+j) * 0.1 ; myField.setValueIJ(i,j,myValue); } // save this new field myField.write(MED_DRIVER,filename) ; } return 0 ;
27
Chapter 7
How to use MESHING object
This class is a derivated class of MESH class to build a MESH object from scratch (use of set methods). All verications are under user responsability : If arrays values or arrays dimensions are wrongs, results are impredicable. All arrays in arguments in set methods are duplicated in MESHING object.
Then you could set the coordinates names and units (with method setCoordinatesNames and method setCoordinatesUnits).
7.1.2 Connectivities
When coordinates are dened, we could dened connectivities. First we must dened connectivity of MED_CELL elements. After, we could dened constituent connectivity if necesary (MED_FACE and/or MED_EDGE). For each connectivities, you could use some methods in the following order :
method setNumberOfTypes to set the number of dierents geometrics types (3 for ex-
ample). This method allocates all arrays which size is this number ; 28
method
setTypes to set the dierents geometrics types (MED_TETRA4,MED_PYRA5,MED_HEXA8 for example). Types should be given in increasing order of number of nodes for this type ;
method setNumberOfElements to set the number of elements for each geometric type.
C++ Example :
MESHING myMeshing ; myMeshing.setCoordinates(SpaceDimension,NumberOfNodes,Coordinates,System,Mode); myMeshing.setNumberOfTypes(2,MED_CELL); myMeshing.setTypes({MED_TRIA3,MED_QUAD4},MED_CELL); myMeshing.setNumberOfElements({3,2},MED_CELL); // 3 MED_TRIA3 and 2 MED_QUAD4 myMeshing.setConnectivity({1,2,3,6,8,9,4,5,6},MED_CELL,MED_TRIA3); myMeshing.setConnectivity({1,3,4,5,4,5,7,8},MED_CELL,MED_QUAD4);
7.2.1 WARNING
For instance, translation from GROUP objects to FAMILY objects are not completed ! You MUST set GROUP objects as if they are FAMILY objects. This feature will be fully implemented in next release of med memory. Here is a small C++ example program which the Python version may be found in 9.6.
29
// // // // // // // // // // //
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA See http://www.salome-platform.org/ or email : [email protected]
#include "MEDMEM_Meshing.hxx" #include "MEDMEM_Group.hxx" using namespace MEDMEM ; using namespace MED_EN ; using namespace std; int main (int argc, char ** argv) { // filename to save the generated MESH string filename = "meshing.med" ; MESHING* myMeshing = new MESHING; myMeshing->setName("meshing") ; // define coordinates int SpaceDimension = 3 ; int NumberOfNodes = 19 ; double Coordinates[57] = { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 0.0, 1.0, 0.0, 2.0, 1.0, -2.0, 0.0, 1.0, 0.0, -2.0, 1.0, 1.0, 1.0, 2.0, -1.0, 1.0, 2.0, -1.0, -1.0, 2.0, 1.0, -1.0, 2.0, 1.0, 1.0, 3.0, -1.0, 1.0, 3.0, -1.0, -1.0, 3.0, 1.0, -1.0, 3.0, 1.0, 1.0, 4.0, -1.0, 1.0, 4.0, -1.0, -1.0, 4.0,
30
myMeshing->setCoordinates(SpaceDimension,NumberOfNodes,Coordinates,"CARTESIAN",MED_FULL_INT string Names[3] = { "X","Y","Z" } ; myMeshing->setCoordinatesNames(Names); string Units[3] = { "cm","cm","cm" } ; myMeshing->setCoordinatesUnits(Units) ; // define conectivities // cell part const int NumberOfTypes = 3 ; medGeometryElement Types[NumberOfTypes] = {MED_TETRA4,MED_PYRA5,MED_HEXA8} ; const int NumberOfElements[NumberOfTypes] = {12,2,2} ; myMeshing->setNumberOfTypes(NumberOfTypes,MED_CELL); myMeshing->setTypes(Types,MED_CELL); myMeshing->setNumberOfElements(NumberOfElements,MED_CELL); const int sizeTetra = 12*4 ; int ConnectivityTetra[sizeTetra]= { 1,2,3,6, 1,2,4,3, 1,2,5,4, 1,2,6,5, 2,7,4,3, 2,8,5,4, 2,9,6,5, 2,10,3,6, 2,7,3,10, 2,8,4,7, 2,9,5,8, 2,10,6,9 }; myMeshing->setConnectivity(MED_CELL,MED_TETRA4,ConnectivityTetra); int ConnectivityPyra[2*5]= { 7,8,9,10,2, 15,18,17,16,19 }; myMeshing->setConnectivity(MED_CELL,MED_PYRA5,ConnectivityPyra);
31
int ConnectivityHexa[2*8]= { 11,12,13,14,7,8,9,10, 15,16,17,18,11,12,13,14 }; myMeshing->setConnectivity(MED_CELL,MED_HEXA8,ConnectivityHexa); // face part const int NumberOfFacesTypes = 2 ; medGeometryElement FacesTypes[NumberOfFacesTypes] = {MED_TRIA3,MED_QUAD4} ; const int NumberOfFacesElements[NumberOfFacesTypes] = {4,4} ; myMeshing->setNumberOfTypes(NumberOfFacesTypes,MED_FACE); myMeshing->setTypes(FacesTypes,MED_FACE); myMeshing->setNumberOfElements(NumberOfFacesElements,MED_FACE); const int sizeTria = 3*4 ; int ConnectivityTria[sizeTria]= { 1,4,3, 1,5,4, 1,6,5, 1,3,6 }; myMeshing->setConnectivity(MED_FACE,MED_TRIA3,ConnectivityTria); int ConnectivityQua[4*4]= { 7,8,9,10, 11,12,13,14, 11,7,8,12, 12,8,9,13 }; myMeshing->setConnectivity(MED_FACE,MED_QUAD4,ConnectivityQua); // edge part // not yet implemented : if set, results are unpredictable. // Some groups : // Node : { GROUP* myGroup = new GROUP; myGroup->setName("SomeNodes");
32
myGroup->setMesh(myMeshing); myGroup->setEntity(MED_NODE); myGroup->setNumberOfGeometricType(1); medGeometryElement myTypes[1] = {MED_NONE}; myGroup->setGeometricType(myTypes); const int myNumberOfElements[1] = {4} ; myGroup->setNumberOfElements(myNumberOfElements); const int index[1+1] = {1,5} ; const int value[4]= { 1,4,5,7} ; myGroup->setNumber(index,value); myMeshing->addGroup(*myGroup); myGroup->removeReference(); GROUP* myGroup = new GROUP; myGroup->setName("OtherNodes"); myGroup->setMesh(myMeshing); myGroup->setEntity(MED_NODE); myGroup->setNumberOfGeometricType(1); medGeometryElement myTypes[1] = {MED_NONE}; myGroup->setGeometricType(myTypes); const int myNumberOfElements[1] = {3} ; myGroup->setNumberOfElements(myNumberOfElements); const int index[1+1] = {1,4} ; const int value[3]= { 2,3,6} ; myGroup->setNumber(index,value); myMeshing->addGroup(*myGroup); myGroup->removeReference();
} {
// Cell : { GROUP* myGroup = new GROUP; myGroup->setName("SomeCells"); myGroup->setMesh(myMeshing); myGroup->setEntity(MED_CELL); myGroup->setNumberOfGeometricType(3); medGeometryElement myTypes[3] = {MED_TETRA4,MED_PYRA5,MED_HEXA8}; myGroup->setGeometricType(myTypes); const int myNumberOfElements[3] = {4,1,2} ; myGroup->setNumberOfElements(myNumberOfElements); const int index[3+1] = {1,5,6,8} ; const int value[4+1+2]= { 2,7,8,12, 13, 15,16 };
33
myGroup->setNumber(index,value); myMeshing->addGroup(*myGroup); myGroup->removeReference(); GROUP* myGroup = new GROUP; myGroup->setName("OtherCells"); myGroup->setMesh(myMeshing); myGroup->setEntity(MED_CELL); myGroup->setNumberOfGeometricType(2); medGeometryElement myTypes[] = {MED_TETRA4,MED_PYRA5}; myGroup->setGeometricType(myTypes); const int myNumberOfElements[] = {4,1} ; myGroup->setNumberOfElements(myNumberOfElements); const int index[3+1] = {1,5,6} ; const int value[4+1]= { 3,4,5,9, 14 }; myGroup->setNumber(index,value); myMeshing->addGroup(*myGroup); myGroup->removeReference();
} {
// Face : { GROUP* myGroup = new GROUP; myGroup->setName("SomeFaces"); myGroup->setMesh(myMeshing); myGroup->setEntity(MED_FACE); myGroup->setNumberOfGeometricType(2); medGeometryElement myTypes[2] = {MED_TRIA3,MED_QUAD4}; myGroup->setGeometricType(myTypes); const int myNumberOfElements[2] = {2,3} ; myGroup->setNumberOfElements(myNumberOfElements); const int index[2+1] = {1,3,6} ; const int value[2+3]= { 2,4, 5,6,8 } ; myGroup->setNumber(index,value); myMeshing->addGroup(*myGroup); myGroup->removeReference();
} {
34
GROUP* myGroup = new GROUP; myGroup->setName("OtherFaces"); myGroup->setMesh(myMeshing); myGroup->setEntity(MED_FACE); myGroup->setNumberOfGeometricType(1); medGeometryElement myTypes[1] = {MED_TRIA3}; myGroup->setGeometricType(myTypes); const int myNumberOfElements[1] = {2} ; myGroup->setNumberOfElements(myNumberOfElements); const int index[1+1] = {1,3} ; const int value[2]= { 1,3 } ; myGroup->setNumber(index,value); myMeshing->addGroup(*myGroup); myGroup->removeReference();
35
Chapter 8
Using drivers
The generic driver mecanism gives users the possibility to write/read the content of an object according to a specied le format. The semantic remains the same whatever the object is (MESH, FIELD, MED). By the way it allows using several le formats for writting an object.
36
// // // // // // // // // // // // // // // // //
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA See http://www.salome-platform.org/ or email : [email protected]
#include "MEDMEM_Exception.hxx" #include "MEDMEM_define.hxx" #include "MEDMEM_Field.hxx" #include "MEDMEM_Mesh.hxx" using namespace MEDMEM ; using namespace MED_EN ; main () { const char * fileName = "pointe.med"; const char * fieldName = "fieldcelldoublescalar"; const char * meshName = "maa1"; try { // Test creation of drivers at object Creation time FIELD<double> myField (MED_DRIVER,fileName,fieldName); MESH myMesh (MED_DRIVER,fileName,meshName); // Test removal of drivers myField.rmDriver(); myMesh.rmDriver (); } catch (MEDEXCEPTION& ex){ MESSAGE_MED(ex.what()) ; }
37
#include "MEDMEM_Exception.hxx" #include "MEDMEM_define.hxx" #include "MEDMEM_Field.hxx" #include "MEDMEM_Mesh.hxx" using namespace MEDMEM ; using namespace MED_EN ; main () {
38
* * * *
= = = =
try { // Test creation of drivers from the standard driver method of an object FIELD<double> * myField = new FIELD<double>(); int myDriver1 = myField->addDriver(MED_DRIVER, fileName, fieldName); myField->read(); //This test failed due to inadequate Support implementation myField->rmDriver(); // TESTER LA VALIDITE DE myDriver2 !!!! int myDriver2 = myField->addDriver(MED_DRIVER, fileName2, fieldName); myField->write(myDriver2); //This test failed due to inadequate Support implementation myField->rmDriver(myDriver2); MESH * myMesh = new MESH(); int myDriver3 = myMesh->addDriver(MED_DRIVER, fileName, meshName); myMesh->read(); myMesh->rmDriver(); myMesh->removeReference(); myField->removeReference(); } catch (MEDEXCEPTION& ex){ MESSAGE_MED(ex.what()) ; }
#include "MEDMEM_Exception.hxx" #include "MEDMEM_define.hxx" #include "MEDMEM_Field.hxx" #include "MEDMEM_Mesh.hxx" #include "MEDMEM_MedMeshDriver.hxx" using namespace MEDMEM ; using namespace MED_EN ; main () { const const const const const char char char char char * * * * * fileName fileName2 fileName3 fieldName meshName = = = = = "pointe.med"; "Field&MeshGeneratedPointe.med"; "MedGeneratedPointe.med"; "fieldcelldoublescalar"; "maa1";
try { // Test creation of drivers from the standard driver method of an object { FIELD<double> * myField = new FIELD<double>(); MED_FIELD_RDONLY_DRIVER<double> myRdOnlyDriver(fileName,myField); myRdOnlyDriver.setFieldName(fieldName); myRdOnlyDriver.open(); myRdOnlyDriver.read();
40
} {
// try { myRdOnlyDriver.write(); } catch (MEDEXCEPTION& ex) // { MESSAGE(ex.what()); } MED_FIELD_WRONLY_DRIVER<double> myWrOnlyDriver(fileName2,myField); myWrOnlyDriver.open(); myWrOnlyDriver.write(); // try myWrOnlyDriver.read(); catch (MEDEXCEPTION& ex) // { MESSAGE(ex.what()); } myRdOnlyDriver.close(); myWrOnlyDriver.close(); delete myField;
MESH * myMesh = new MESH(); MED_MESH_RDONLY_DRIVER myRdOnlyDriver(fileName,myMesh); myRdOnlyDriver.setMeshName(meshName); myRdOnlyDriver.open(); myRdOnlyDriver.read(); myRdOnlyDriver.close(); // try { myRdOnlyDriver.write(); } catch (MEDEXCEPTION& ex) // { MESSAGE(ex.what()); } MED_MESH_WRONLY_DRIVER myWrOnlyDriver(fileName2,myMesh); myWrOnlyDriver.setMeshName(meshName); myWrOnlyDriver.open(); myWrOnlyDriver.write(); // try myWrOnlyDriver.read(); catch (MEDEXCEPTION& ex) // { MESSAGE(ex.what()); } myRdOnlyDriver.close(); myWrOnlyDriver.close(); delete myMesh;
} catch (MEDEXCEPTION& ex){ cout << "MAIN BLOCK EXCEPTION" << endl; MESSAGE_MED(ex.what()) ; }
42
43
Chapter 9
Appendix: Python example scripts.
from libMEDMEM_Swig import * MedFile = "pointe.med" meshName = "maa1" myMesh = MESH(MED_DRIVER,MedFile,meshName) name = myMesh.getName() if (name != meshName) :
44
print "Error when reading mesh name : We ask for mesh #",meshName,"#" print "and we get mesh #",name else : print "Mesh name : ",name spaceDimension = myMesh.getSpaceDimension() meshDimension = myMesh.getMeshDimension() print "Space Dimension : ",spaceDimension print "Mesh Dimension : ",meshDimension
from libMEDMEM_Swig import * MedFile = "pointe.med" meshName = "maa1" myMesh = MESH(MED_DRIVER,MedFile,meshName) name = myMesh.getName() print "Mesh name : ",name spaceDimension = myMesh.getSpaceDimension() numberOfNodes = myMesh.getNumberOfNodes() print "Space Dimension : ",spaceDimension print "Number of Nodes : ",numberOfNodes
45
print "Show Nodes Coordinates :" print "Name :" coordinatesNames = myMesh.getCoordinatesNames() for i in range(spaceDimension): coordinateName = coordinatesNames[i] print " - ",coordinateName print "Unit :" coordinatesUnits = myMesh.getCoordinatesUnits() for i in range(spaceDimension): coordinateUnit = coordinatesUnits[i] print " - ",coordinateUnit coordinates = myMesh.getCoordinates(MED_FULL_INTERLACE) for i in range(numberOfNodes): print "Node ",(i+1)," : ",coordinates[i*spaceDimension:(i+1)*spaceDimension]
from libMEDMEM_Swig import * MedFile = "pointe.med" #MedFile = "carre_quad4_3.med" #MedFile = "polyedres.med" #MedFile = "polygones.med" meshName = "maa1"
46
#meshName = "CARRE_EN_QUAD4" #meshName = "Erreur orientation" #meshName = "Bord" myMesh = MESH(MED_DRIVER,MedFile,meshName) myMesh.read() nameMesh = myMesh.getName() print "Mesh name : ",nameMesh numberOfTypes = myMesh.getNumberOfTypes(MED_CELL) print "Show Connectivity (Nodal) : " # This example use access with a specified medGeometryElement through # CELLMODEL class for i in range(numberOfTypes): cellType = myMesh.getCellType(MED_CELL,i) nameType = cellType.getName() type = cellType.getType() numberOfElements = myMesh.getNumberOfElements(MED_CELL,type) numberOfNodesPerCell = cellType.getNumberOfNodes() connectivity = myMesh.getConnectivity(MED_NODAL,MED_CELL,type) print "For Type ",nameType," : " for j in range(numberOfElements): print "Element ",(j+1)," : ",connectivity[j*numberOfNodesPerCell: (j+1)*numberOfNodesPerCell] print "Show Reverse Nodal Connectivity :" # This example use global access with index array numberOfNodes = myMesh.getNumberOfNodes() reverseNodalConnectivity = myMesh.getReverseConnectivity(MED_NODAL) reverseNodalConnectivityIndex = myMesh.getReverseConnectivityIndex(MED_NODAL) for i in range(numberOfNodes): indexBegin = reverseNodalConnectivityIndex[i] indexEnd = reverseNodalConnectivityIndex[i+1] # Index value begin at 1 so (index-1) is in fact used here print "Node ",(i+1)," : ",reverseNodalConnectivity[(indexBegin-1): (indexEnd-1)] print "Show Connectivity (Descending) :" # This example use global access with index array
47
numberOfElements = myMesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS) descendingConnectivity = myMesh.getConnectivity(MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS) descendingConnectivityIndex = myMesh.getConnectivityIndex(MED_DESCENDING,MED_CELL) for i in range(numberOfElements): indexBegin = descendingConnectivityIndex[i] indexEnd = descendingConnectivityIndex[i+1] # Index value begin at 1 so (index-1) is in fact used here print "Element ",(i+1)," : ",descendingConnectivity[(indexBegin-1): (indexEnd-1)] print "Show Reverse Descending Connectivity :" # This example use global access with index array meshDimension = myMesh.getMeshDimension() if (meshDimension == 1): print "ERROR : Mesh Dimension = 1" print "Then the Reverse Descending Connectivity could not be seen" else: if (meshDimension == 2): constituent = "Edge" constituentEntity = MED_EDGE if (meshDimension == 3): constituent = "Face" constituentEntity = MED_FACE numberOfConstituents = myMesh.getNumberOfElements(constituentEntity, MED_ALL_ELEMENTS) reverseDescendingConnectivity = myMesh.getReverseConnectivity( MED_DESCENDING) reverseDescendingConnectivityIndex = myMesh.getReverseConnectivityIndex( MED_DESCENDING) for i in range(numberOfConstituents): indexBegin = reverseDescendingConnectivityIndex[i] indexEnd = reverseDescendingConnectivityIndex[i+1] # Index value begin at 1 so (index-1) is in fact used here print constituent," : ",(i+1)," : ",reverseDescendingConnectivity[ (indexBegin-1):(indexEnd-1)] print "Show ",constituent," Connectivity (Nodal) :"
48
constituentConnectivity = myMesh.getConnectivity(MED_NODAL,constituentEntity,MED_ALL_ELEM constituentConnectivityIndex = myMesh.getConnectivityIndex(MED_NODAL,constituentEntity) for i in range(numberOfConstituents): indexBegin = constituentConnectivityIndex[i] indexEnd = constituentConnectivityIndex[i+1] # Index value begin at 1 so (index-1) is in fact used here print constituent," : ",(i+1)," : ",constituentConnectivity[ (indexBegin-1):(indexEnd-1)] pass pass
###################################################################### # This Python script should be executed when the shared library is # # generated using SWIG 1.3 (or higher) due to the fact that older # # version could not handle the wrapping of several class constructor # ###################################################################### # from libMEDMEM_Swig import * MedFile = "pointe.med"
49
meshName = "maa1" fieldName = "fieldcelldoublescalar" myMesh = MESH(MED_DRIVER,MedFile,meshName) mySupport = myMesh.getSupportOnAll(MED_CELL) myField = FIELDDOUBLE(mySupport,MED_DRIVER,MedFile,fieldName,-1,-1) numberOfComponents = myField.getNumberOfComponents() for i in range(numberOfComponents): ip1 = i+1 name = myField.getComponentName(ip1) desc = myField.getComponentDescription(ip1) unit = myField.getMEDComponentUnit(ip1) print print print print "Component ",ip1 " - name : ",name " - decription : ",desc " - unit : ", unit
iterationNumber = myField.getIterationNumber() orderNumber = myField.getOrderNumber() time = myField.getTime() print "Iteration ",iterationNumber," at time ",time,\ " (and order number ",orderNumber,")" numberOfValue = mySupport.getNumberOfElements(MED_ALL_ELEMENTS) value = myField.getValue() for i in range(numberOfValue): print " * ",value[i*numberOfComponents:(i+1)*numberOfComponents]
50
# # # # # # # # #
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA See http://www.salome-platform.org/ or email : [email protected]
###################################################################### # This Python script should be executed when the shared library is # # generated using SWIG 1.3 (or higher) due to the fact that older # # version could not handle the wrapping of several class constructor # ###################################################################### # from libMEDMEM_Swig import * MedFile = "pointe.med" meshName = "maa1" myMesh = MESH(MED_DRIVER,MedFile,meshName) mySupport = myMesh.getSupportOnAll(MED_CELL) numberOfComponents = 3 myField = FIELDDOUBLE(mySupport,numberOfComponents) fieldName = "fieldcelldouble" myField.setName(fieldName) for i in range(numberOfComponents): if (i == 0): name = "Vx" desc = "vitesse selon x" elif (i == 1): name = "Vy" desc = "vitesse selon y" else: name = "Vz" desc = "vitesse selon z" unit = "m. s-1" ip1 = i+1 myField.setComponentName(ip1,name) myField.setComponentDescription(ip1,desc) myField.setMEDComponentUnit(ip1,unit) iterationNumber = 10 myField.setIterationNumber(iterationNumber) orderNumber = 1
51
myField.setOrderNumber(orderNumber) time = 3.435678 myField.setTime(time) numberOfValue = mySupport.getNumberOfElements(MED_ALL_ELEMENTS) for i in range(numberOfValue): ip1 = i+1 for j in range(numberOfComponents): jp1 = j+1 value = (ip1+jp1)*0.1 myField.setValueIJ(ip1,jp1,value) id = myField.addDriver(MED_DRIVER)
################################################################################### # This Python script uses the wrapped C++ class MESHING to buid a mesh from only # primitive data like coordinates (Pythoin double array) and connectivity (Python # integer arrays). It is the Python equivalent of the C++ program # test_MEDMEM_Meshing.cxx in the ../MEDMEM directory of the SALOME distribution ################################################################################### # from libMEDMEM_Swig import *
52
# files name to save the generated MESH(ING) in different format # Med V2.1 Med V2.2 and vtk med21FileName = "toto21.med" med22FileName = "toto22.med" vtkFileName = "toto.vtk" myMeshing = MESHING() myMeshing.setName("meshing") # definition of the coordinates spaceDimension = 3 numberOfNodes = 19 coordinates = [ 0.0, 0.0, 0.0 , 0.0, 0.0, 1.0 , 2.0, 0.0, 1.0 , 0.0, 2.0, 1.0 , -2.0, 0.0, 1.0 , 0.0, -2.0, 1.0 , 1.0, 1.0, 2.0 , -1.0, 1.0, 2.0 , -1.0, -1.0, 2.0, 1.0, -1.0, 2.0 , 1.0, 1.0, 3.0 , -1.0, 1.0, 3.0 , -1.0, -1.0, 3.0, 1.0, -1.0, 3.0 , 1.0, 1.0, 4.0 , -1.0, 1.0, 4.0 , -1.0, -1.0, 4.0, 1.0, -1.0, 4.0 , 0.0, 0.0, 5.0]
myMeshing.setCoordinates(spaceDimension,numberOfNodes,coordinates,"CARTESIAN",MED_FULL_INTERL for i in range(spaceDimension): unit = "cm " if (i == 0): name = "X " elif (i == 1): name = "Y " elif (i == 2):
53
name = "Z
"
myMeshing.setCoordinateName(name,i) myMeshing.setCoordinateUnit(unit,i) # definition of connectivities # cell part numberOfTypes = 3 entity = MED_CELL types = [] numberOfElements = [] types.append(MED_TETRA4) numberOfElements.append(12) types.append(MED_PYRA5) numberOfElements.append(2) types.append(MED_HEXA8) numberOfElements.append(2) myMeshing.setNumberOfTypes(numberOfTypes,entity) myMeshing.setTypes(types,entity) myMeshing.setNumberOfElements(numberOfElements,entity) connectivityTetra = [ 1,2,3,6 , 1,2,4,3 , 1,2,5,4 , 1,2,6,5 , 2,7,4,3 , 2,8,5,4 , 2,9,6,5 , 2,10,3,6, 2,7,3,10, 2,8,4,7 , 2,9,5,8 , 2,10,6,9] myMeshing.setConnectivity(entity,types[0],connectivityTetra) connectivityPyra = [ 7,8,9,10,2, 15,18,17,16,19] myMeshing.setConnectivity(entity,types[1],connectivityPyra) connectivityHexa = [
54
11,12,13,14,7,8,9,10, 15,16,17,18,11,12,13,14] myMeshing.setConnectivity(entity,types[2],connectivityPyra) # face part numberOfTypes = 2 entity = MED_FACE types = [] numberOfElements = [] types.append(MED_TRIA3) numberOfElements.append(4) types.append(MED_QUAD4) numberOfElements.append(4) myMeshing.setNumberOfTypes(numberOfTypes,entity) myMeshing.setTypes(types,entity) myMeshing.setNumberOfElements(numberOfElements,entity) connectivityTria = [ 1,4,3, 1,5,4, 1,6,5, 1,3,6] myMeshing.setConnectivity(entity,types[0],connectivityPyra) connectivityQuad = [ 7,8,9,10 , 11,12,13,14, 11,7,8,12 , 12,8,9,13] myMeshing.setConnectivity(entity,types[1],connectivityQuad) # edge part # adding GROUPs # on Node myGroup = GROUP() myGroup.setName("SomeNodes") myGroup.setMesh(myMeshing) myGroup.setEntity(MED_NODE) myGroup.setNumberOfGeometricType(1)
55
myTypes = [MED_NONE] myGroup.setGeometricType(myTypes) myNumberOfElements = [4] myGroup.setNumberOfElements(myNumberOfElements) index = [1,5] values = [1,4,5,7] myGroup.setNumber(index,values) myMeshing.addGroup(myGroup) myGroup = GROUP() myGroup.setName("OtherNodes") myGroup.setMesh(myMeshing) myGroup.setEntity(MED_NODE) myGroup.setNumberOfGeometricType(1) myTypes = [MED_NONE] myGroup.setGeometricType(myTypes) myNumberOfElements = [3] myGroup.setNumberOfElements(myNumberOfElements) index = [1,4] values = [2,3,6] myGroup.setNumber(index,values) myMeshing.addGroup(myGroup) # on Cell myGroup = GROUP() myGroup.setName("SomeCells") myGroup.setMesh(myMeshing) myGroup.setEntity(MED_CELL) myGroup.setNumberOfGeometricType(3) myTypes = [MED_TETRA4,MED_PYRA5,MED_HEXA8] myGroup.setGeometricType(myTypes) myNumberOfElements = [4,1,2] myGroup.setNumberOfElements(myNumberOfElements) index = [1,5,6,8] values = [ 2,7,8,12, 13, 15,16 ]
56
myGroup.setNumber(index,values) myMeshing.addGroup(myGroup) myGroup = GROUP() myGroup.setName("OtherCells") myGroup.setMesh(myMeshing) myGroup.setEntity(MED_CELL) myGroup.setNumberOfGeometricType(2) myTypes = [MED_TETRA4,MED_PYRA5] myGroup.setGeometricType(myTypes) myNumberOfElements = [4,1] myGroup.setNumberOfElements(myNumberOfElements) index = [1,5,6] values = [ 3,4,5,9, 14 ] myGroup.setNumber(index,values) myMeshing.addGroup(myGroup) # on Face myGroup = GROUP() myGroup.setName("SomeFaces") myGroup.setMesh(myMeshing) myGroup.setEntity(MED_FACE) myGroup.setNumberOfGeometricType(2) myTypes = [MED_TRIA3,MED_QUAD4] myGroup.setGeometricType(myTypes) myNumberOfElements = [2,3] myGroup.setNumberOfElements(myNumberOfElements) index = [1,3,6] values = [ 2,4, 5,6,8 ] myGroup.setNumber(index,values) myMeshing.addGroup(myGroup) myGroup = GROUP() myGroup.setName("OtherFaces")
57
myGroup.setMesh(myMeshing) myGroup.setEntity(MED_FACE) myGroup.setNumberOfGeometricType(1) myTypes = [MED_TRIA3] myGroup.setGeometricType(myTypes) myNumberOfElements = [2] myGroup.setNumberOfElements(myNumberOfElements) index = [1,3] values = [ 1,3 ] myGroup.setNumber(index,values) myMeshing.addGroup(myGroup) # saving of the generated mesh in MED and VTK format myMeshing.write(MED_DRIVER,med22FileName) myMeshing.write(VTK_DRIVER,vtkFileName) # we build now 8 fields : 4 fields double (integer) : # 2 fields on nodes (cells) : # 1 scalar (vector) supportOnNodes = myMeshing.getSupportOnAll(MED_NODE) numberOfNodes = supportOnNodes.getNumberOfElements(MED_ALL_ELEMENTS) supportOnCells = myMeshing.getSupportOnAll(MED_CELL) numberOfCells = supportOnCells.getNumberOfElements(MED_ALL_ELEMENTS) fieldDoubleScalarOnNodes = FIELDDOUBLE(supportOnNodes,1) fieldDoubleScalarOnNodes.setName("fieldScalarDoubleNode") fieldDoubleScalarOnNodes.setIterationNumber(-1) fieldDoubleScalarOnNodes.setOrderNumber(-1) fieldDoubleScalarOnNodes.setTime(0.0) fieldDoubleScalarOnNodes.setComponentName(1,"Vx") fieldDoubleScalarOnNodes.setComponentDescription(1,"comp1") fieldDoubleScalarOnNodes.setMEDComponentUnit(1,"unit1") fieldDoubleVectorOnNodes = FIELDDOUBLE(supportOnNodes,spaceDimension) fieldDoubleVectorOnNodes.setName("fieldVectorDoubleNode") fieldDoubleVectorOnNodes.setIterationNumber(-1) fieldDoubleVectorOnNodes.setOrderNumber(-1) fieldDoubleVectorOnNodes.setTime(0.0)
58
fieldDoubleVectorOnNodes.setComponentName(1,"Vx") fieldDoubleVectorOnNodes.setComponentDescription(1,"comp1") fieldDoubleVectorOnNodes.setMEDComponentUnit(1,"unit1") fieldDoubleVectorOnNodes.setComponentName(2,"Vy") fieldDoubleVectorOnNodes.setComponentDescription(2,"comp2") fieldDoubleVectorOnNodes.setMEDComponentUnit(2,"unit2") fieldDoubleVectorOnNodes.setComponentName(3,"Vz") fieldDoubleVectorOnNodes.setComponentDescription(3,"comp3") fieldDoubleVectorOnNodes.setMEDComponentUnit(3,"unit3") fieldDoubleScalarOnCells = FIELDDOUBLE(supportOnCells,1) fieldDoubleScalarOnCells.setName("fieldScalarDoubleCell") fieldDoubleScalarOnCells.setIterationNumber(-1) fieldDoubleScalarOnCells.setOrderNumber(-1) fieldDoubleScalarOnCells.setTime(0.0) fieldDoubleScalarOnCells.setComponentName(1,"Vx") fieldDoubleScalarOnCells.setComponentDescription(1,"comp1") fieldDoubleScalarOnCells.setMEDComponentUnit(1,"unit1") fieldDoubleVectorOnCells = FIELDDOUBLE(supportOnCells,spaceDimension) fieldDoubleVectorOnCells.setName("fieldVectorrDoubleCell") fieldDoubleVectorOnCells.setIterationNumber(-1) fieldDoubleVectorOnCells.setOrderNumber(-1) fieldDoubleVectorOnCells.setTime(0.0) fieldDoubleVectorOnCells.setComponentName(1,"Vx") fieldDoubleVectorOnCells.setComponentDescription(1,"comp1") fieldDoubleVectorOnCells.setMEDComponentUnit(1,"unit1") fieldDoubleVectorOnCells.setComponentName(2,"Vy") fieldDoubleVectorOnCells.setComponentDescription(2,"comp2") fieldDoubleVectorOnCells.setMEDComponentUnit(2,"unit2") fieldDoubleVectorOnCells.setComponentName(3,"Vz") fieldDoubleVectorOnCells.setComponentDescription(3,"comp3") fieldDoubleVectorOnCells.setMEDComponentUnit(3,"unit3") fieldIntScalarOnNodes = FIELDINT(supportOnNodes,1) fieldIntScalarOnNodes.setName("fieldScalarIntNode") fieldIntScalarOnNodes.setIterationNumber(-1) fieldIntScalarOnNodes.setOrderNumber(-1) fieldIntScalarOnNodes.setTime(0.0) fieldIntScalarOnNodes.setComponentName(1,"Vx") fieldIntScalarOnNodes.setComponentDescription(1,"comp1") fieldIntScalarOnNodes.setMEDComponentUnit(1,"unit1") fieldIntVectorOnNodes = FIELDINT(supportOnNodes,spaceDimension) fieldIntVectorOnNodes.setName("fieldVectorIntNode") fieldIntVectorOnNodes.setIterationNumber(-1) fieldIntVectorOnNodes.setOrderNumber(-1)
59
fieldIntVectorOnNodes.setTime(0.0) fieldIntVectorOnNodes.setComponentName(1,"Vx") fieldIntVectorOnNodes.setComponentDescription(1,"comp1") fieldIntVectorOnNodes.setMEDComponentUnit(1,"unit1") fieldIntVectorOnNodes.setComponentName(2,"Vy") fieldIntVectorOnNodes.setComponentDescription(2,"comp2") fieldIntVectorOnNodes.setMEDComponentUnit(2,"unit2") fieldIntVectorOnNodes.setComponentName(3,"Vz") fieldIntVectorOnNodes.setComponentDescription(3,"comp3") fieldIntVectorOnNodes.setMEDComponentUnit(3,"unit3") fieldIntScalarOnCells = FIELDINT(supportOnCells,1) fieldIntScalarOnCells.setName("fieldScalarIntCell") fieldIntScalarOnCells.setIterationNumber(-1) fieldIntScalarOnCells.setOrderNumber(-1) fieldIntScalarOnCells.setTime(0.0) fieldIntScalarOnCells.setComponentName(1,"Vx") fieldIntScalarOnCells.setComponentDescription(1,"comp1") fieldIntScalarOnCells.setMEDComponentUnit(1,"unit1") fieldIntVectorOnCells = FIELDINT(supportOnCells,spaceDimension) fieldIntVectorOnCells.setName("fieldVectorrIntCell") fieldIntVectorOnCells.setIterationNumber(-1) fieldIntVectorOnCells.setOrderNumber(-1) fieldIntVectorOnCells.setTime(0.0) fieldIntVectorOnCells.setComponentName(1,"Vx") fieldIntVectorOnCells.setComponentDescription(1,"comp1") fieldIntVectorOnCells.setMEDComponentUnit(1,"unit1") fieldIntVectorOnCells.setComponentName(2,"Vy") fieldIntVectorOnCells.setComponentDescription(2,"comp2") fieldIntVectorOnCells.setMEDComponentUnit(2,"unit2") fieldIntVectorOnCells.setComponentName(3,"Vz") fieldIntVectorOnCells.setComponentDescription(3,"comp3") fieldIntVectorOnCells.setMEDComponentUnit(3,"unit3") for i in range(numberOfNodes): valueInt1 = i+1 valueInt2 = i+2 valueInt3 = i+3 valueDbl1 = valueInt1*0.1 valueDbl2 = valueInt2*0.1 valueDbl3 = valueInt3*0.1 fieldDoubleScalarOnNodes.setValueIJ(i+1,1,valueDbl1) fieldIntScalarOnNodes.setValueIJ(i+1,1,valueInt1) fieldDoubleVectorOnNodes.setValueIJ(i+1,1,valueDbl1)
60
fieldDoubleVectorOnNodes.setValueIJ(i+1,2,valueDbl2) fieldDoubleVectorOnNodes.setValueIJ(i+1,3,valueDbl3) fieldIntVectorOnNodes.setValueIJ(i+1,1,valueInt1) fieldIntVectorOnNodes.setValueIJ(i+1,2,valueInt2) fieldIntVectorOnNodes.setValueIJ(i+1,3,valueInt3) for i in range(numberOfCells): valueInt1 = i+1 valueInt2 = i+2 valueInt3 = i+3 valueDbl1 = valueInt1*0.1 valueDbl2 = valueInt2*0.1 valueDbl3 = valueInt3*0.1 fieldDoubleScalarOnCells.setValueIJ(i+1,1,valueDbl1) fieldIntScalarOnCells.setValueIJ(i+1,1,valueInt1) fieldDoubleVectorOnCells.setValueIJ(i+1,1,valueDbl1) fieldDoubleVectorOnCells.setValueIJ(i+1,2,valueDbl2) fieldDoubleVectorOnCells.setValueIJ(i+1,3,valueDbl3) fieldIntVectorOnCells.setValueIJ(i+1,1,valueInt1) fieldIntVectorOnCells.setValueIJ(i+1,2,valueInt2) fieldIntVectorOnCells.setValueIJ(i+1,3,valueInt3) fieldIntScalarOnNodes.write(MED_DRIVER,med21FileName) fieldDoubleVectorOnNodes.write(MED_DRIVER,med21FileName) fieldIntVectorOnNodes.write(MED_DRIVER,med21FileName) fieldDoubleScalarOnCells.write(MED_DRIVER,med21FileName) fieldIntScalarOnCells.write(MED_DRIVER,med21FileName) fieldDoubleVectorOnCells.write(MED_DRIVER,med21FileName) fieldIntVectorOnCells.write(MED_DRIVER,med21FileName)
61
###################################################################### # This Python script should be executed when the shared library is # # generated using SWIG 1.3 (or higher) due to the fact that older # # version could not handle the wrapping of several class constructor # ###################################################################### # from libMEDMEM_Swig import * medFile = "pointe.med" fieldName = "fieldcelldouble" meshName = "maa1" try: print "Creation of MESH object" myMesh = MESH(MED_DRIVER,medFile,meshName)
62
print "Test the driver removal for MESH" myMesh.rmDriver() print "End of Python script" except: print "There is a problem somewhere !!" print "Consult the error standart output of the python execution !!"
###################################################################### # This Python script should be executed when the shared library is # # generated using SWIG 1.3 (or higher) due to the fact that older # # version could not handle the wrapping of several class constructor # ###################################################################### # from libMEDMEM_Swig import * medFile = "pointe.med" medFile2 = "fieldCellDoubleOfpointe.med" fieldName = "fieldcelldoublescalar" meshName = "maa1" try:
63
myField = FIELDDOUBLE() myDriver1 = myField.addDriver(MED_DRIVER,medFile,fieldName) myField.rmDriver() myDriver2 = myField.addDriver(MED_DRIVER,medFile2,fieldName) myField.rmDriver(myDriver2) myMesh = MESH() myDriver3 = myMesh.addDriver(MED_DRIVER,medFile,meshName) myMesh.read() myMesh.rmDriver() except: print "There is a problem somewhere !!" print "Please consult the error standart output of the python execution !!"
###################################################################### # This Python script should be executed when the shared library is # # generated using SWIG 1.3 (or higher) due to the fact that older # # version could not handle the wrapping of several class constructor # ###################################################################### # from libMEDMEM_Swig import *
64
medFile = "pointe.med" medFile2 = "Field&MeshGeneratedPointe.med" fieldName = "fieldcelldoublescalar" meshName = "maa1" try: myField = FIELDDOUBLE() myRdOnlyDriver = MED_FIELDDOUBLE_RDONLY_DRIVER(medFile,myField) myRdOnlyDriver.setFieldName(fieldName) myRdOnlyDriver.open() myWrOnlyDriver = MED_FIELDDOUBLE_WRONLY_DRIVER(medFile2,myField) myWrOnlyDriver.open() myRdOnlyDriver.close() myWrOnlyDriver.close() print "Invoking field drivers OK" except : print "there is a problem in invoking field drivers !!" print "Please consult the error standart output of the python execution !!" try: myMesh = MESH() myRdOnlyDriver = MED_MESH_RDONLY_DRIVER(medFile,myMesh) myRdOnlyDriver.setMeshName(meshName) myRdOnlyDriver.open() myRdOnlyDriver.read() myRdOnlyDriver.close() myWrOnlyDriver = MED_MESH_WRONLY_DRIVER(medFile2,myMesh) myWrOnlyDriver.setMeshName(meshName) myWrOnlyDriver.open() myWrOnlyDriver.write() myWrOnlyDriver.close() print "Invoking mesh drivers OK" except : print "there is a problem in invoking mesh drivers !!" print "Please consult the error standart output of the python execution !!"
65
Bibliography
Projet PAL: Dnition du modle d'change de donnes MED V2.2 EDF/SINETICS HI-26-03-012/A
http://www-drn2.cea.fr/MED/MEDMEM/DOC/html/index.html
Note technique
file:://$MED_ROOT_DIR/share/salome/doc/html_ref_user/index.html $MED_ROOT_DIR/share/salome/doc/MedMemory_user_2on1.pdf
66