MED fichier

usecases/c/UsesCase_MEDmesh_4.c
/* This file is part of MED.
*
* COPYRIGHT (C) 1999 - 2021 EDF R&D, CEA/DEN
* MED 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 3 of the License, or
* (at your option) any later version.
*
* MED 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 MED. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* How to create a structured mesh
*
* Use case 4 : write a 2D structured mesh (5x3 cartesian grid)
*/
#include <med.h>
#define MESGERR 1
#include <med_utils.h>
#include <string.h>
int main (int argc, char **argv) {
med_idt fid;
const char meshname[MED_NAME_SIZE+1] = "2D structured mesh";
const med_int spacedim = 2;
const med_int meshdim = 2;
const char axisname[2*MED_SNAME_SIZE+1] = "x y ";
const char unitname[2*MED_SNAME_SIZE+1] = "cm cm ";
med_int axis, size ;
const med_float cooXaxis[5] = {1.,2.,3.,4.,5.};
const med_float cooYaxis[3] = {1.,2.,3.};
const med_int nquad4 = 8;
/* 12345678901234561234567890123456123456789012345612345678901234561234567890123456123456789012345612345678901234561234567890123456 */
const char cellsnames[8*MED_SNAME_SIZE+1] = "CELL_1 CELL_2 CELL_3 CELL_4 CELL_5 CELL_6 CELL_7 CELL_8 ";
const char familyname [MED_NAME_SIZE+1] = "CART_GRID_QUAD_FAMILY";
const char groupname [MED_LNAME_SIZE+1] = "CART_GRID_GROUP";
const med_int familynumbers[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
int ret=-1;
/* MED file creation */
fid = MEDfileOpen("UsesCase_MEDmesh_4.med",MED_ACC_CREAT);
if (fid < 0) {
MESSAGE("ERROR : file creation ...");
goto ERROR;
}
/* create the structured mesh in the MED file */
if (MEDmeshCr(fid, meshname, spacedim, meshdim, MED_STRUCTURED_MESH,
"A 2D structured mesh","",MED_SORT_DTIT,
MED_CARTESIAN, axisname, unitname) < 0) {
MESSAGE("ERROR : mesh creation ...");
goto ERROR;
}
/* specify the grid type : MED_CARTESIAN_GRID */
if (MEDmeshGridTypeWr(fid,meshname, MED_CARTESIAN_GRID) < 0) {
MESSAGE("ERROR : write grid type ...");
goto ERROR;
}
/* write axis "X" and "Y" coordinates */
axis = 1;
size = 5;
if (MEDmeshGridIndexCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT,0.0,
axis, size, cooXaxis) < 0) {
MESSAGE("ERROR : write of axis X coordinates ...");
goto ERROR;
}
axis++;
size = 3;
if (MEDmeshGridIndexCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT,0.0,
axis, size, cooYaxis) < 0) {
MESSAGE("ERROR : write of axis Y coordinates ...");
goto ERROR;
}
/* optionnal : names for nodes or elements */
/* In this case, a name is given to the cells of the mesh */
if (MEDmeshEntityNameWr(fid, meshname, MED_NO_DT, MED_NO_IT,
MED_CELL, MED_QUAD4, nquad4, cellsnames) < 0) {
MESSAGE("ERROR : cells names ...");
goto ERROR;
}
/* We have to create family 0 : by default, all mesh entities family number is 0 */
if (MEDfamilyCr(fid, meshname, MED_NO_NAME, 0, 0, MED_NO_GROUP) < 0) {
MESSAGE("ERROR : family 0 creation ...");
goto ERROR;
}
/* We decide to create a family for boundary quad4 :
by convention a nodes family number is > 0 and an element family number is < 0 */
if (MEDfamilyCr(fid, meshname,familyname, 1, -1, groupname) < 0) {
MESSAGE("ERROR : family creation ...");
goto ERROR;
}
/* Then we write family number for quad4 */
if (MEDmeshEntityFamilyNumberWr(fid, meshname, MED_NO_DT, MED_NO_IT,
MED_CELL, MED_QUAD4, nquad4, familynumbers) < 0) {
MESSAGE("ERROR : nodes family numbers ...");
goto ERROR;
}
ret = 0;
ERROR:
/* close MED file */
if (MEDfileClose(fid) < 0) {
MESSAGE("ERROR : close file ...");
ret = -1;
}
return ret;
}
MED_CARTESIAN
Definition: med.h:258
MED_NO_GROUP
#define MED_NO_GROUP
Definition: med.h:289
MED_SORT_DTIT
Definition: med.h:309
MEDmeshCr
MEDC_EXPORT med_err MEDmeshCr(const med_idt fid, const char *const meshname, const med_int spacedim, const med_int meshdim, const med_mesh_type meshtype, const char *const description, const char *const dtunit, const med_sorting_type sortingtype, const med_axis_type axistype, const char *const axisname, const char *const axisunit)
Cette routine permet de créer un maillage dans un fichier.
Definition: MEDmeshCr.c:45
MEDfileOpen
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition: MEDfileOpen.c:42
MED_SNAME_SIZE
#define MED_SNAME_SIZE
Definition: med.h:82
med_idt
hid_t med_idt
Definition: med.h:331
MED_CARTESIAN_GRID
Definition: med.h:137
MEDmeshEntityNameWr
MEDC_EXPORT med_err MEDmeshEntityNameWr(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_entity_type entitype, const med_geometry_type geotype, const med_int nentity, const char *const name)
Cette routine permet d'écrire les noms d'un type d'entité d'un maillage.
Definition: MEDmeshEntityNameWr.c:39
MEDmeshEntityFamilyNumberWr
MEDC_EXPORT med_err MEDmeshEntityFamilyNumberWr(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_entity_type entitype, const med_geometry_type geotype, const med_int nentity, const med_int *const number)
Cette routine permet l'écriture des numéros de famille d'un type d'entité d'un maillage.
Definition: MEDmeshEntityFamilyNumberWr.c:39
MEDmeshGridTypeWr
MEDC_EXPORT med_err MEDmeshGridTypeWr(const med_idt fid, const char *const meshname, const med_grid_type gridtype)
Cette routine permet de définir le type d'un maillage structuré (MED_STRUCTURED_MESH).
Definition: MEDmeshGridTypeWr.c:37
MED_CELL
Definition: med.h:143
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
med_int
int med_int
Definition: med.h:342
MEDfamilyCr
MEDC_EXPORT med_err MEDfamilyCr(const med_idt fid, const char *const meshname, const char *const familyname, const med_int familynumber, const med_int ngroup, const char *const groupname)
Cette routine permet la création d'une famille portant sur les entités d'un maillage.
Definition: MEDfamilyCr.c:40
med.h
med_float
double med_float
Definition: med.h:336
MED_NO_DT
#define MED_NO_DT
Definition: med.h:320
MED_ACC_CREAT
Definition: med.h:123
MED_LNAME_SIZE
#define MED_LNAME_SIZE
Definition: med.h:83
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:81
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MEDmeshGridIndexCoordinateWr
MEDC_EXPORT med_err MEDmeshGridIndexCoordinateWr(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_float dt, const med_int axis, const med_int indexsize, const med_float *const gridindex)
Cette routine permet l'écriture des coordonnées des noeuds d'un maillage structuré selon un axe du re...
Definition: MEDmeshGridIndexCoordinateWr.c:43
MED_STRUCTURED_MESH
Definition: med.h:131
MED_NO_IT
#define MED_NO_IT
Definition: med.h:321
main
int main(int argc, char **argv)
Definition: 3.0.8/test10.c:50
med_utils.h
MED_QUAD4
#define MED_QUAD4
Definition: med.h:204
MED_NO_NAME
#define MED_NO_NAME
Definition: med.h:268