UsesCase_MEDmesh_12.c
Aller à la documentation de ce fichier.
/* 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/>.
*/
/*
* Use case 12 : read a 2D unstructured mesh with moving grid (generic approach)
*/
#include <med.h>
#define MESGERR 1
#include <med_utils.h>
#include <string.h>
int main (int argc, char **argv) {
med_idt fid;
med_int nmesh;
char meshname[MED_NAME_SIZE+1]="";
char meshdescription[MED_COMMENT_SIZE+1]="";
med_int meshdim;
med_int spacedim;
med_sorting_type sortingtype;
med_int nstep;
med_mesh_type meshtype;
med_axis_type axistype;
char *axisname;
char *unitname;
char dtunit[MED_SNAME_SIZE+1]="";
med_float *coordinates = NULL;
med_int ngeo = 0;
med_int nnodes = 0;
med_int *connectivity = NULL;
med_bool coordinatechangement;
med_bool geotransformation;
med_bool matrixtransformation;
med_int matrixsize;
med_float matrix[7]={ 0, 0, 0, 0, 0, 0, 0};
int i, it, j;
med_int profilesize;
char profilename[MED_NAME_SIZE+1]="";
med_int numdt, numit;
med_float dt;
med_geometry_type geotype;
med_geometry_type *geotypes = MED_GET_CELL_GEOMETRY_TYPE;
int ret=-1;
/* open MED file with READ ONLY access mode */
fid = MEDfileOpen("UsesCase_MEDmesh_9.med",MED_ACC_RDONLY);
if (fid < 0) {
MESSAGE("ERROR : open file in READ ONLY ACCESS mode ...");
goto ERROR;
}
/* read how many mesh in the file */
if ((nmesh = MEDnMesh(fid)) < 0) {
MESSAGE("ERROR : read how many mesh ...");
goto ERROR;
}
for (i=0;i<nmesh;i++) {
/* read computation space dimension */
if ((spacedim = MEDmeshnAxis(fid, i+1)) < 0) {
MESSAGE("ERROR : read computation space dimension ...");
goto ERROR;
}
/* memory allocation */
if ((axisname = (char*) malloc(MED_SNAME_SIZE*spacedim+1)) == NULL) {
MESSAGE("ERROR : memory allocation ...");
goto ERROR;
}
if ((unitname = (char*) malloc(MED_SNAME_SIZE*spacedim+1)) == NULL) {
MESSAGE("ERROR : memory allocation ...");
goto ERROR;
}
/* read mesh informations : meshname, mesh dimension, mesh type ... */
if (MEDmeshInfo(fid, i+1, meshname, &spacedim, &meshdim, &meshtype, meshdescription,
dtunit, &sortingtype, &nstep,
&axistype, axisname, unitname) < 0) {
MESSAGE("ERROR : mesh info ...");
free(axisname);
free(unitname);
goto ERROR;
}
free(axisname);
free(unitname);
/* read how many nodes in the mesh */
if ((nnodes = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NONE,
MED_COORDINATE, MED_NO_CMODE,&coordinatechangement,
&geotransformation)) < 0) {
MESSAGE("ERROR : number of nodes ...");
goto ERROR;
}
/* read mesh nodes coordinates */
if ((coordinates = (med_float*) malloc(sizeof(med_float)*nnodes*spacedim)) == NULL) {
MESSAGE("ERROR : memory allocation ...");
goto ERROR;
}
if (MEDmeshNodeCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE,
coordinates) < 0) {
MESSAGE("ERROR : nodes coordinates ...");
free(coordinates);
goto ERROR;
}
/* read all MED geometry cell types */
for (it=1; it<= MED_N_CELL_FIXED_GEO; it++) {
geotype = geotypes[it];
if ((ngeo = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL,geotype,
MED_CONNECTIVITY, MED_NODAL, &coordinatechangement,
&geotransformation)) < 0) {
MESSAGE("ERROR : number of cell ...");
ISCRUTE_int(geotype);
goto ERROR;
}
if (ngeo) {
/* read cells connectivity in the mesh */
if ((connectivity = (med_int *) malloc(sizeof(med_int)*ngeo*(geotype%100))) == NULL) {
MESSAGE("ERROR : memory allocation ...");
goto ERROR;
}
if (MEDmeshElementConnectivityRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL,
geotype, MED_NODAL, MED_FULL_INTERLACE, connectivity) < 0) {
MESSAGE("ERROR : cell connectivity ...");
ISCRUTE_int(geotype);
free(connectivity);
goto ERROR;
}
/* memory deallocation */
free(connectivity);
connectivity = NULL;
}
}
/* read nodes coordinates changements step by step */
for (it=1;it<nstep;it++) {
if (MEDmeshComputationStepInfo(fid, meshname, it+1,
&numdt, &numit, &dt) < 0) {
MESSAGE("ERROR : Computing step info ...");
SSCRUTE(meshname);
goto ERROR;
}
/* test changement : for nodes coordinates */
if ((nnodes = MEDmeshnEntityWithProfile(fid, meshname, numdt, numit,
MED_NODE, MED_NONE,
MED_COORDINATE, MED_NO_CMODE,
MED_GLOBAL_STMODE, profilename, &profilesize,
&coordinatechangement, &geotransformation)) < 0) {
MESSAGE("ERROR : number of nodes ...");
goto ERROR;
}
/* if only coordinates have changed, then read the new coordinates */
if (coordinatechangement && geotransformation) {
if (MEDmeshNodeCoordinateWithProfileRd(fid, meshname, numdt, numit,
MED_GLOBAL_STMODE,profilename,
MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,
coordinates) < 0) {
MESSAGE("ERROR : nodes coordinates ...");
free(coordinates);
goto ERROR;
}
}
if (coordinatechangement && ! geotransformation) {
matrixsize = MEDmeshnEntity(fid,meshname,numdt,numit,
MED_NODE,MED_NONE,MED_COORDINATE_TRSF,MED_NODAL,&coordinatechangement,
&matrixtransformation);
if (matrixsize < 0) {
MESSAGE("ERROR : matrix transformation ...");
goto ERROR;
}
if (matrixtransformation) {
if ( MEDmeshNodeCoordinateTrsfRd(fid, meshname, numdt, numit, matrix) < 0 ) {
MESSAGE("ERROR : read transformation matrix ...");
goto ERROR;
}
}
}
}
}
free(coordinates);
ret=0;
ERROR:
/* close MED file */
if (MEDfileClose(fid) < 0) {
MESSAGE("ERROR : close file");
ret=-1;
}
return ret;
}
MED_FULL_INTERLACE
Definition: med.h:96
MED_COMMENT_SIZE
#define MED_COMMENT_SIZE
Definition: med.h:79
MEDmeshnEntity
MEDC_EXPORT med_int MEDmeshnEntity(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_data_type datatype, const med_connectivity_mode cmode, med_bool *const changement, med_bool *const transformation)
Cette routine permet de lire le nombre d'entités dans un maillage pour une étape de calcul donnée.
Definition: MEDmeshnEntity.c:44
MEDmeshComputationStepInfo
MEDC_EXPORT med_err MEDmeshComputationStepInfo(const med_idt fid, const char *const meshname, const int csit, med_int *const numdt, med_int *const numit, med_float *const dt)
Cette routine permet de lire les informations relatives à une étape de calcul d'un maillage.
Definition: MEDmeshComputationStepInfo.c:38
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_geometry_type
int med_geometry_type
Definition: med.h:194
MED_SNAME_SIZE
#define MED_SNAME_SIZE
Definition: med.h:82
MED_NODAL
Definition: med.h:255
ISCRUTE_int
#define ISCRUTE_int(entier)
Definition: med_utils.h:314
med_idt
hid_t med_idt
Definition: med.h:331
MED_ACC_RDONLY
Definition: med.h:120
MEDmeshNodeCoordinateTrsfRd
MEDC_EXPORT med_err MEDmeshNodeCoordinateTrsfRd(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_float *const coordinatetrsf)
Cette routine lit les paramètres de translation rotation à appliquer aux noeuds de l'étape de calcul ...
Definition: MEDmeshNodeCoordinateTrsfRd.c:40
med_sorting_type
med_sorting_type
Definition: med.h:309
MED_NO_CMODE
Definition: med.h:255
MED_CELL
Definition: med.h:143
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
med_int
int med_int
Definition: med.h:342
MED_GET_CELL_GEOMETRY_TYPE
med_geometry_type MED_GET_CELL_GEOMETRY_TYPE[MED_N_CELL_FIXED_GEO+2]
Definition: MEDiterators.c:55
med.h
med_bool
med_bool
Definition: med.h:260
med_float
double med_float
Definition: med.h:336
MED_NO_DT
#define MED_NO_DT
Definition: med.h:320
MED_NONE
#define MED_NONE
Definition: med.h:231
MED_CONNECTIVITY
Definition: med.h:149
MEDmeshElementConnectivityRd
MEDC_EXPORT med_err MEDmeshElementConnectivityRd(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_connectivity_mode cmode, const med_switch_mode switchmode, med_int *const connectivity)
Cette routine permet de lire dans un maillage le tableau des connectivités pour un type géométrique d...
Definition: MEDmeshElementConnectivityRd.c:40
MED_NODE
Definition: med.h:143
MEDmeshnAxis
MEDC_EXPORT med_int MEDmeshnAxis(const med_idt fid, const int meshit)
Cette routine permet de lire dans un maillage le nombre d'axes du repère des coordonnées des noeuds.
Definition: MEDmeshnAxis.c:35
MED_N_CELL_FIXED_GEO
#define MED_N_CELL_FIXED_GEO
Definition: med.h:239
med_mesh_type
med_mesh_type
Definition: med.h:131
SSCRUTE
#define SSCRUTE(chaine)
Definition: med_utils.h:323
MED_GLOBAL_STMODE
Definition: med.h:109
MEDmeshNodeCoordinateRd
MEDC_EXPORT med_err MEDmeshNodeCoordinateRd(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_switch_mode switchmode, med_float *const coordinates)
Cette routine permet de lire dans un maillage le tableau des coordonnées des noeuds,...
Definition: MEDmeshNodeCoordinateRd.c:37
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:81
MEDnMesh
MEDC_EXPORT med_int MEDnMesh(const med_idt fid)
Cette routine permet de lire le nombre de maillages dans un fichier.
Definition: MEDnMesh.c:34
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MED_COORDINATE_TRSF
Definition: med.h:152
MED_ALL_CONSTITUENT
#define MED_ALL_CONSTITUENT
Definition: med.h:299
MEDmeshnEntityWithProfile
MEDC_EXPORT med_int MEDmeshnEntityWithProfile(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_data_type datatype, const med_connectivity_mode cmode, const med_storage_mode storagemode, char *const profilename, med_int *const profilesize, med_bool *const changement, med_bool *const transformation)
Cette routine permet de lire le nombre d'entités dans un maillage pour une étape de calcul et un prof...
Definition: MEDmeshnEntityWithProfile.c:47
med_axis_type
med_axis_type
Definition: med.h:258
main
int main(int argc, char **argv)
Definition: UsesCase_MEDmesh_12.c:28
MEDmeshInfo
MEDC_EXPORT med_err MEDmeshInfo(const med_idt fid, const int meshit, char *const meshname, med_int *const spacedim, med_int *const meshdim, med_mesh_type *const meshtype, char *const description, char *const dtunit, med_sorting_type *const sortingtype, med_int *const nstep, med_axis_type *const axistype, char *const axisname, char *const axisunit)
Cette routine permet de lire les informations relatives à un maillage dans un fichier.
Definition: MEDmeshInfo.c:43
MED_NO_IT
#define MED_NO_IT
Definition: med.h:321
MED_COORDINATE
Definition: med.h:149
MEDmeshNodeCoordinateWithProfileRd
MEDC_EXPORT med_err MEDmeshNodeCoordinateWithProfileRd(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_storage_mode storagemode, const char *const profilename, const med_switch_mode switchmode, const med_int dimselect, med_float *const coordinates)
Cette routine permet de lire dans un maillage le tableau des coordonnées des noeuds,...
Definition: MEDmeshNodeCoordinateWithProfileRd.c:40
med_utils.h