UsesCase_MEDstructElement_3.c
Aller à la documentation de ce fichier.
/* This file is part of MED.
*
* COPYRIGHT (C) 1999 - 2020 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/>.
*/
#include <med.h>
#define MESGERR 1
#include <med_utils.h>
#include <string.h>
/*
* StructElement use case 3 : read struct element models in a file from a computation mesh
*/
int main (int argc, char **argv) {
med_idt fid;
med_int nmodels, nsmesh;
int i,j;
char elementname[MED_NAME_SIZE+1]="";
char supportmeshname[MED_NAME_SIZE+1]="";
const char computmeshname[MED_NAME_SIZE+1]="COMPUT_MESH";
med_geometry_type *geotype;
med_entity_type entitype;
med_int elementdim;
med_int nnode,ncell;
med_geometry_type geocelltype;
med_bool anyprofile=0;
med_int nconstatt, *nvaratt=NULL;
char attname[MED_NAME_SIZE+1]="";
char profilename[MED_NAME_SIZE+1]="";
med_attribute_type atttype;
med_int nattcomp;
med_entity_type attentitype;
med_int profilesize;
med_float *value=NULL;
med_int size=0;
med_int meshdim, spacedim;
char description[MED_COMMENT_SIZE+1]="";
char axisname[3*MED_SNAME_SIZE+1]="";
char axisunit[3*MED_SNAME_SIZE+1]="";
med_axis_type axistype;
med_float *coordinates=NULL;
med_bool coordinatechangement;
med_bool geotransformation;
med_int nseg2;
med_int *seg2connectivity=NULL;
med_int nentities=0;
med_sorting_type sortingtype;
med_mesh_type meshtype;
med_int nstep;
char dtunit[MED_SNAME_SIZE+1]="";
char unitname[2*MED_SNAME_SIZE+1]="";
int ret=-1;
/* open file */
fid = MEDfileOpen("UsesCase_MEDstructElement_1.med",MED_ACC_RDONLY);
if (fid < 0) {
MESSAGE("ERROR : file creation ...");
goto ERROR;
}
/*
* ... In this case, we know that the MED file has only one mesh,
* a real code would check ...
*/
/* read mesh informations : mesh dimension, space dimension ... */
if (MEDmeshInfoByName(fid, computmeshname, &spacedim, &meshdim, &meshtype, description,
dtunit, &sortingtype, &nstep, &axistype, axisname, unitname) < 0) {
MESSAGE("ERROR : mesh info ...");
goto ERROR;
}
/* read how many struct element models in the mesh ? */
if ((nmodels = MEDmeshnEntity(fid, computmeshname, MED_NO_DT, MED_NO_IT, MED_STRUCT_ELEMENT, MED_GEO_ALL,
MED_UNDEF_DATATYPE, MED_NO_CMODE,&coordinatechangement,
&geotransformation)) < 0) {
MESSAGE("ERROR : number of nodes ...");
goto ERROR;
}
geotype = (med_geometry_type *) malloc(sizeof(med_geometry_type)*nmodels);
nvaratt = (med_int *) malloc(sizeof(med_int)*nmodels);
/* Get the name and the geotype of each struct element model used in the computation mesh.
For each struct element geotype read the connectivity and the attribute(s)
The mesh support may be read if needed.
*/
for (i=0;i<nmodels;i++) {
/* read the geotype */
if (MEDmeshEntityInfo(fid, computmeshname, MED_NO_DT, MED_NO_IT, MED_STRUCT_ELEMENT,i+1,elementname,(geotype+i)) < 0) {
MESSAGE("ERROR : name and type of MED_STRUCT_ELEMENT ...");
goto ERROR;
}
/* read how many MED_STRUCT_ELEMENT of type *(geotype+i) there is in the mesh */
if ((nentities = MEDmeshnEntity(fid, computmeshname, MED_NO_DT, MED_NO_IT, MED_STRUCT_ELEMENT,*(geotype+i),
MED_CONNECTIVITY, MED_NODAL, &coordinatechangement,
&geotransformation)) < 0) {
MESSAGE("ERROR : number of MED_STRUCT_ELEMENT ...");
goto ERROR;
}
/* read informations about the model */
if (MEDstructElementInfoByName(fid, elementname, geotype+i, &elementdim,
supportmeshname, &entitype, &nnode, &ncell,
&geocelltype, &nconstatt, &anyprofile, nvaratt+i) < 0) {
MESSAGE("ERROR : struct element models information ...");
goto ERROR;
}
/* read support mesh */
/* TODO : Ceci est optionnel dans ce usescase */
if (strcmp(supportmeshname,"")) {
if ( MEDsupportMeshInfoByName(fid, supportmeshname, &spacedim, &meshdim, description,
&axistype, axisname, axisunit) < 0 ) {
MESSAGE("ERROR : read information about mesh support ...");
goto ERROR;
}
ISCRUTE(nnode);
/* read how many nodes in the support mesh */
/* Ceci est optionnel dans ce usescase */
if ((nnode = MEDmeshnEntity(fid, supportmeshname, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NONE,
MED_COORDINATE, MED_NO_CMODE,&coordinatechangement,
&geotransformation)) < 0) {
MESSAGE("ERROR : read number of nodes ...");
goto ERROR;
}
ISCRUTE(nnode);
/* read support mesh nodes coordinates */
/* Ceci est optionnel dans ce usescase */
coordinates = (med_float*) malloc(sizeof(med_float)*nnode*spacedim);
if (MEDmeshNodeCoordinateRd(fid, supportmeshname, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE,
coordinates) < 0) {
MESSAGE("ERROR : read nodes coordinates ...");
free(coordinates);
goto ERROR;
}
/* free memory */
free(coordinates);
/* read how many MED_SEG2 cells in the support mesh */
/* Ceci est optionnel dans ce usescase */
if ((nseg2 = MEDmeshnEntity(fid, supportmeshname, MED_NO_DT, MED_NO_IT, MED_CELL,geocelltype,
MED_CONNECTIVITY, MED_NODAL, &coordinatechangement,
&geotransformation)) < 0) {
MESSAGE("ERROR : number of MED_SEG2 ...");
goto ERROR;
}
ISCRUTE(nseg2);
ISCRUTE(ncell);
/* read MED_SEG2 connectivity in the support mesh */
if (nseg2 > 0) {
seg2connectivity = (med_int *) malloc(sizeof(med_int)*nseg2*2);
if (MEDmeshElementConnectivityRd(fid, supportmeshname, MED_NO_DT, MED_NO_IT, MED_CELL,
geocelltype, MED_NODAL, MED_FULL_INTERLACE, seg2connectivity) < 0) {
MESSAGE("ERROR : MED_SEG2 connectivity ...");
free(seg2connectivity);
goto ERROR;
}
free(seg2connectivity);
}
}
/* read constant attribute(s) */
/* Optionnel pour ce usescase (cf. usescase lecture modèle) */
for (j=0; j<nconstatt; j++) {
if ( MEDstructElementConstAttInfo(fid, elementname, j+1,
attname, &atttype, &nattcomp, &attentitype,
profilename, &profilesize) < 0) {
MESSAGE("ERROR : const attribute information ...");
goto ERROR;
}
/* if there is a profile => read the profile, see UsesCase_MEDprofile_2 */
/* memory allocation */
if (profilesize != 0)
size = profilesize*nattcomp*MEDstructElementAttSizeof(atttype);
else
if (attentitype== MED_NODE)
size = nnode*nattcomp*MEDstructElementAttSizeof(atttype);
else
size = ncell*nattcomp*MEDstructElementAttSizeof(atttype);
if ( atttype == MED_ATT_NAME) ++size;
ISCRUTE(size);
value = (med_float *) malloc(size);
/* read attribute(s) value(s) */
if ( MEDstructElementConstAttRd(fid, elementname, attname, (unsigned char *)value ) < 0 ) {
MESSAGE("ERROR : const attribute value ...");
free(value);
goto ERROR;
}
/* memory deallocation */
free(value);
}
/* read variable attribute(s) */
for (j=0; j<*(nvaratt+i); j++) {
/* read informations about the attribute */
if ( MEDstructElementVarAttInfo(fid, elementname, j+1,
attname, &atttype, &nattcomp) < 0) {
MESSAGE("ERROR : var attribute information ...");
goto ERROR;
}
/* memory allocation */
size = nentities*nattcomp*MEDstructElementAttSizeof(atttype);
if ( atttype == MED_ATT_NAME) ++size;
ISCRUTE(size);
value = (med_float *) malloc((size)*sizeof(char));
/* read attribute values */
if (MEDmeshStructElementVarAttRd(fid, computmeshname, MED_NO_DT, MED_NO_IT,
*(geotype+i), attname, value ) < 0) {
MESSAGE("ERROR : read variable attributes values ...");
free(value);
goto ERROR;
}
/* free memory */
free(value);
}
}
ret=0;
ERROR:
/* free memory */
free(geotype);
free(nvaratt);
/* close file */
if (MEDfileClose(fid) < 0) {
MESSAGE("ERROR : file closing ...");
ret=-1;
}
return ret;
}
main
int main(int argc, char **argv)
Definition UsesCase_MEDstructElement_3.c:28
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition build.python3.12/include/med.h:81
MED_FULL_INTERLACE
@ MED_FULL_INTERLACE
Definition build.python3.12/include/med.h:96
med_geometry_type
int med_geometry_type
Definition build.python3.12/include/med.h:194
MED_SNAME_SIZE
#define MED_SNAME_SIZE
Definition build.python3.12/include/med.h:82
med_bool
med_bool
Definition build.python3.12/include/med.h:260
MED_UNDEF_DATATYPE
@ MED_UNDEF_DATATYPE
Definition build.python3.12/include/med.h:152
MED_CONNECTIVITY
@ MED_CONNECTIVITY
Definition build.python3.12/include/med.h:149
MED_COORDINATE
@ MED_COORDINATE
Definition build.python3.12/include/med.h:149
med_axis_type
med_axis_type
Definition build.python3.12/include/med.h:258
med_sorting_type
med_sorting_type
Definition build.python3.12/include/med.h:300
med_mesh_type
med_mesh_type
Definition build.python3.12/include/med.h:131
med_int
int med_int
Definition build.python3.12/include/med.h:333
MED_NO_DT
#define MED_NO_DT
Definition build.python3.12/include/med.h:311
MED_NO_IT
#define MED_NO_IT
Definition build.python3.12/include/med.h:312
MED_NONE
#define MED_NONE
Definition build.python3.12/include/med.h:231
med_entity_type
med_entity_type
Definition build.python3.12/include/med.h:143
MED_NODE
@ MED_NODE
Definition build.python3.12/include/med.h:143
MED_CELL
@ MED_CELL
Definition build.python3.12/include/med.h:143
MED_STRUCT_ELEMENT
@ MED_STRUCT_ELEMENT
Definition build.python3.12/include/med.h:144
med_float
double med_float
Definition build.python3.12/include/med.h:327
med_attribute_type
med_attribute_type
Definition build.python3.12/include/med.h:173
MED_ATT_NAME
@ MED_ATT_NAME
Definition build.python3.12/include/med.h:175
MED_COMMENT_SIZE
#define MED_COMMENT_SIZE
Definition build.python3.12/include/med.h:79
MED_GEO_ALL
#define MED_GEO_ALL
Definition build.python3.12/include/med.h:236
MED_ACC_RDONLY
@ MED_ACC_RDONLY
Definition build.python3.12/include/med.h:120
med_idt
hid_t med_idt
Definition build.python3.12/include/med.h:322
MED_NO_CMODE
@ MED_NO_CMODE
Definition build.python3.12/include/med.h:255
MED_NODAL
@ MED_NODAL
Definition build.python3.12/include/med.h:255
MESSAGE
#define MESSAGE(chaine)
Definition build.python3.12/include/med_utils.h:324
ISCRUTE
#define ISCRUTE(entier)
Definition build.python3.12/include/med_utils.h:313
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition MEDfileClose.c:30
MEDfileOpen
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition MEDfileOpen.c:42
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
MEDmeshEntityInfo
MEDC_EXPORT med_err MEDmeshEntityInfo(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_entity_type entitype, const int geotypeit, char *const geotypename, med_geometry_type *const geotype)
Cette routine indique de façon itérative les types géométriques disponibles dans un maillage.
Definition MEDmeshEntityInfo.c:41
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
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
MEDmeshInfoByName
MEDC_EXPORT med_err MEDmeshInfoByName(const med_idt fid, const 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 en précisant son nom.
Definition MEDmeshInfoByName.c:42
MEDstructElementVarAttInfo
MEDC_EXPORT med_err MEDstructElementVarAttInfo(const med_idt fid, const char *const modelname, const int attit, char *const varattname, med_attribute_type *const varatttype, med_int *const ncomponent)
Cette routine décrit les caractéristiques d'un attribut variable de modèle d'élément de structure par...
Definition MEDstructElementVarAttInfo.c:41
MEDstructElementAttSizeof
MEDC_EXPORT int MEDstructElementAttSizeof(const med_attribute_type atttype)
Cette routine renvoie la taille en octets du type élémentaire atttype.
Definition MEDstructElementAttSizeof.c:36
MEDstructElementConstAttRd
MEDC_EXPORT med_err MEDstructElementConstAttRd(const med_idt fid, const char *const modelname, const char *const constattname, void *const value)
Cette routine lit la valeur d'un attribut caractéristique constant d'un modèle d'éléments de structur...
Definition MEDstructElementConstAttRd.c:42
MEDmeshStructElementVarAttRd
MEDC_EXPORT med_err MEDmeshStructElementVarAttRd(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_geometry_type mgeotype, const char *const varattname, void *const value)
Cette routine lit les valeurs d'un attribut caractéristique variable sur les éléments de structure d'...
Definition MEDmeshStructElementVarAttRd.c:43
MEDstructElementConstAttInfo
MEDC_EXPORT med_err MEDstructElementConstAttInfo(const med_idt fid, const char *const modelname, const int attit, char *const constattname, med_attribute_type *const constatttype, med_int *const ncomponent, med_entity_type *const sentitytype, char *const profilename, med_int *const profilesize)
Cette routine décrit les caractéristiques d'un attribut constant de modèle d'élément de structure par...
Definition MEDstructElementConstAttInfo.c:45
MEDstructElementInfoByName
MEDC_EXPORT med_err MEDstructElementInfoByName(const med_idt fid, const char *const modelname, med_geometry_type *const mgeotype, med_int *const modeldim, char *const supportmeshname, med_entity_type *const sentitytype, med_int *const snnode, med_int *const sncell, med_geometry_type *const sgeotype, med_int *const nconstantatribute, med_bool *const anyprofile, med_int *const nvariableattribute)
Cette routine décrit les caractéristiques d'un modèle d'élément de structure à partir de son nom.
Definition MEDstructElementInfoByName.c:49
MEDsupportMeshInfoByName
MEDC_EXPORT med_err MEDsupportMeshInfoByName(const med_idt fid, const char *const supportmeshname, med_int *const spacedim, med_int *const meshdim, char *const description, med_axis_type *const axistype, char *const axisname, char *const axisunit)
Cette routine permet de lire les informations relatives à un maillage support en précisant son nom.
Definition MEDsupportMeshInfoByName.c:39