UsesCase_MEDstructElement_1.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/>.
*/
/*
* StructElement use case 1 : write struct elements model in a file
* STEP 1 : suppport mesh creation
* STEP 2 : struct element model creation
* STEP 3 : computation mesh creation
*/
#include <med.h>
#define MESGERR 1
#include <med_utils.h>
#include <string.h>
int main (int argc, char **argv) {
med_idt fid;
char elementname[MED_NAME_SIZE+1]="";
const char ballsupportname[MED_NAME_SIZE+1]="BALL_SUPPORT_MESH";
const char beamsupportname[MED_NAME_SIZE+1]="BEAM_SUPPORT_MESH";
const char computmeshname[MED_NAME_SIZE+1]="COMPUT_MESH";
const char beamsectionname[MED_NAME_SIZE+1]="BEAM_SECTION_MESH";
const med_int elementdim = 3;
med_int nnode;
med_geometry_type geotype=MED_NONE;
med_int ncomp;
const med_float ballmeshnodescoo[3] = {0.0, 0.0, 0.0 };
const med_float beammeshnodescoo[3*7] = {0.0,0.0,0.0,
0.0,0.0,2.0,
0.0,0.0,4.0,
0.0,0.0,5.0,
0.0,0.0,7.0,
0.0,0.0,10.0,
0.0,0.0,11.0 };
const med_float beamsectioncoo[9*3] = {-0.2,-0.2,0.0,
0.0,-0.2,0.0,
0.2,-0.2,0.0,
-0.2, 0.0,0.0,
0.0, 0.0,0.0,
0.2, 0.0,0.0,
-0.2, 0.2,0.0,
0.0, 0.2,0.0,
0.2, 0.2,0.0 };
const med_int seg2connectivity[2*6] = {1,2, 2,3, 3,4, 4,5, 5,6, 6,7};
med_int spacedim, meshdim,nseg2;
/* 123456789012345612345678901234561234567890123456 */
const char axisname[3*MED_SNAME_SIZE+1] = "x y z ";
const char unitname[3*MED_SNAME_SIZE+1] = "cm cm cm ";
const med_float attvalue[6] = {0.2,0.3,0.4,0.4,0.3,0.2};
/* 1234567890123456789012345678901234567890123456789012345678901234 */
const char attprovalue[2*MED_NAME_SIZE+1] = {"EXTREMITY_1_____________________________________________________" \
"EXTREMITY_2_____________________________________________________" };
const char profilename[MED_NAME_SIZE+1] = "EXTREMITY_PROFILE_NAME";
const med_int profilesize = 2;
const med_int profile[2] = {1,6};
const med_float meshcoo[3*12] = { 0.0, 0.0, 0.0,
1.1, 1.1, 1.1,
2.2, 2.2, 2.2,
10., 10., 10.,
12., 12., 12.,
60., 20., 20.,
70., 20., 20.,
80., 20., 20.,
90., 20., 20.,
100., 20., 20.,
110., 20., 20.,
120., 20., 20.
};
const med_int beamconnectivity[12] = { 6,7,
7,8,
8,9,
9,10,
10,11,
11,12 };
med_int nentity;
const med_int labels[3] = { 1, 2, 3 }; /* nodes numbers */
const med_int ballconnectivity[2] = { 4, 5 }; /* nodes numbers */
const med_float balldiameter[2] = { 2.0, 5.8 };
const med_int nquad4=4;
const med_int beamsectionconnectivity[4*4] = { 4,5,2,1,
5,6,3,2,
7,8,5,4,
8,9,6,5};
int ret=-1;
/* file creation */
fid = MEDfileOpen("UsesCase_MEDstructElement_1.med",MED_ACC_CREAT);
if (fid < 0) {
MESSAGE("ERROR : file creation");
goto ERROR;
}
/* STEP 1 : support meshes creation */
spacedim = 3;
meshdim = 3;
/* Mesh 1 : support mesh for ball model */
if (MEDsupportMeshCr(fid, ballsupportname, spacedim, meshdim, "Support mesh for a ball model",
MED_CARTESIAN, axisname, unitname) < 0) {
MESSAGE("ERROR : creating a support mesh ...");
goto ERROR;
}
/* 1 node and no cell in the mesh */
nnode = 1;
if (MEDmeshNodeCoordinateWr(fid, ballsupportname, MED_NO_DT, MED_NO_IT, 0.0,
MED_FULL_INTERLACE, nnode, ballmeshnodescoo) < 0) {
MESSAGE("ERROR : write nodes coordinates ...");
goto ERROR;
}
/* Mesh 2 :support mesh for beam model */
if (MEDsupportMeshCr(fid, beamsupportname, spacedim, meshdim, "Support mesh for a beam model",
MED_CARTESIAN, axisname, unitname) < 0) {
MESSAGE("ERROR : creating a support mesh ...");
goto ERROR;
}
/* 7 nodes and 6 MED_SEG2 */
nnode = 7;
if (MEDmeshNodeCoordinateWr(fid, beamsupportname, MED_NO_DT, MED_NO_IT, 0.0,
MED_FULL_INTERLACE, nnode, beammeshnodescoo) < 0) {
MESSAGE("ERROR : write nodes coordinates ...");
goto ERROR;
}
nseg2 = 6;
if (MEDmeshElementConnectivityWr(fid, beamsupportname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL, MED_SEG2,
MED_NODAL, MED_FULL_INTERLACE, nseg2, seg2connectivity) < 0) {
MESSAGE("ERROR : write cells connectivity ...");
goto ERROR;
}
/* Mesh 3 : support mesh to define a section for integration points of
a struct element */
if (MEDsupportMeshCr(fid, beamsectionname, spacedim, meshdim, "Support mesh for a section of the beam model",
MED_CARTESIAN, axisname, unitname) < 0) {
MESSAGE("ERROR : creating a support mesh ...");
goto ERROR;
}
nnode = 9;
if (MEDmeshNodeCoordinateWr(fid, beamsectionname, MED_NO_DT, MED_NO_IT, 0.0,
MED_FULL_INTERLACE, nnode, beamsectioncoo) < 0) {
MESSAGE("ERROR : write nodes coordinates ...");
goto ERROR;
}
if (MEDmeshElementConnectivityWr(fid, beamsectionname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL, MED_QUAD4,
MED_NODAL, MED_FULL_INTERLACE, nquad4, beamsectionconnectivity) < 0) {
MESSAGE("ERROR : write cells connectivity ...");
goto ERROR;
}
/* STEP 2 */
/* particle model creation : no support mesh */
strcpy(elementname,MED_PARTICLE_NAME);
if ((geotype = MEDstructElementCr(fid, elementname, elementdim, MED_NO_MESHNAME,
MED_NONE,MED_NONE)) < 0) {
MESSAGE("ERROR : creating struct element");
goto ERROR;
}
ncomp=1;
if (MEDstructElementVarAttCr(fid, elementname,
MED_PARTICLE_LABEL, MED_ATT_INT, ncomp) < 0) {
MESSAGE("ERROR : creating struct element");
goto ERROR;
}
/* ball model creation */
strcpy(elementname,MED_BALL_NAME);
if ((geotype = MEDstructElementCr(fid, elementname, elementdim, ballsupportname,
MED_NODE,MED_NONE)) < 0) {
MESSAGE("ERROR : creating struct element");
goto ERROR;
}
ncomp=1;
if (MEDstructElementVarAttCr(fid, elementname,
MED_BALL_DIAMETER, MED_ATT_FLOAT64, ncomp) < 0) {
MESSAGE("ERROR : creating struct element");
goto ERROR;
}
/* A beam */
strcpy(elementname,MED_BEAM_NAME);
if ((geotype = MEDstructElementCr(fid, elementname, elementdim, beamsupportname,
MED_CELL,MED_SEG2)) < 0) {
MESSAGE("ERROR : creating struct element");
goto ERROR;
}
ncomp=1;
/* a first constant attribute */
if (MEDstructElementConstAttWr(fid, elementname,
MED_BEAM_THICKNESS, MED_ATT_FLOAT64, ncomp,
MED_CELL,(void*) attvalue) < 0) {
MESSAGE("ERROR : creating struct element");
goto ERROR;
}
/* a second constant attribute defined with a profile for the first and the
last segment */
/* create the profile */
if (MEDprofileWr(fid, profilename, profilesize, profile ) < 0) {
MESSAGE("ERROR : create profile ...");
goto ERROR;
}
/* write the constant attribute */
if (MEDstructElementConstAttWithProfileWr(fid,
elementname,
"BEAM_EXTREMITIES_LABELS",
MED_ATT_NAME,
ncomp,
MED_CELL,
profilename,
(void*) attprovalue) < 0) {
MESSAGE("ERROR : creating struct element");
goto ERROR;
}
/* STEP 3 : Computation mesh creation */
/* mesh creation */
if (MEDmeshCr(fid, computmeshname, spacedim, meshdim, MED_UNSTRUCTURED_MESH,
"Computation mesh", "s", MED_SORT_DTIT,
MED_CARTESIAN, axisname, unitname) < 0) {
MESSAGE("ERROR : creating computation mesh ...");
goto ERROR;
}
/* mesh node creation */
nnode = 12;
if (MEDmeshNodeCoordinateWr(fid, computmeshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
MED_FULL_INTERLACE, nnode, meshcoo) < 0) {
MESSAGE("ERROR : writing nodes coordinates ...");
goto ERROR;
}
/* 1 beam */
nentity = 1;
SSCRUTE(elementname);
geotype = MEDstructElementGeotype(fid,elementname);
ISCRUTE_int(geotype);
if (MEDmeshElementConnectivityWr(fid,computmeshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
MED_STRUCT_ELEMENT, geotype, MED_NODAL,
MED_FULL_INTERLACE, nentity, beamconnectivity) < 0 ) {
MESSAGE("ERROR : beam connectivity ...");
goto ERROR;
}
/* Get the dynamic geometry type of each struct element model.
Then for each type, write the connectivity and variable(s) attribute(s) */
/* 3 particles in the mesh */
strcpy(elementname,MED_PARTICLE_NAME);
geotype = MEDstructElementGeotype(fid,elementname);
nentity = 3;
ISCRUTE_int(geotype);
if (MEDmeshElementConnectivityWr(fid, computmeshname, MED_NO_DT, MED_NO_IT, 0.0,
MED_STRUCT_ELEMENT, geotype , MED_NODAL, MED_FULL_INTERLACE,
nentity, 0) < 0) {
MESSAGE("ERROR : writing particles connectivity ...");
goto ERROR;
}
/* no support mesh => no connectivity, the particles are localized with an association between
the mesh nodes and the label attribute defined in the struct model */
if (MEDmeshStructElementVarAttWr(fid, computmeshname, MED_NO_DT, MED_NO_IT,
geotype, MED_PARTICLE_LABEL,
nentity, labels) < 0 ) {
MESSAGE("ERROR : writing variable attributes ...");
goto ERROR;
}
/* 2 balls */
strcpy(elementname,MED_BALL_NAME);
nentity = 2;
geotype = MEDstructElementGeotype(fid,elementname);
if (MEDmeshElementConnectivityWr(fid,computmeshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
MED_STRUCT_ELEMENT, geotype, MED_NODAL,
MED_FULL_INTERLACE, nentity, ballconnectivity) < 0 ) {
MESSAGE("ERROR : writing balls connectivity");
goto ERROR;
}
/* variable attribute : write ball diameter */
if (MEDmeshStructElementVarAttWr(fid, computmeshname, MED_NO_DT, MED_NO_IT,
geotype, MED_BALL_DIAMETER,
nentity, balldiameter) < 0 ) {
MESSAGE("ERROR : writing variable attributes ...");
goto ERROR;
}
ret=0;
ERROR:
/* close file */
if (MEDfileClose(fid) < 0) {
MESSAGE("ERROR : file closing");
ret=-1;
}
return ret;
}
main
int main(int argc, char **argv)
Definition UsesCase_MEDstructElement_1.c:31
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
MEDmeshElementConnectivityWr
MEDC_EXPORT med_err MEDmeshElementConnectivityWr(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_float dt, const med_entity_type entitype, const med_geometry_type geotype, const med_connectivity_mode cmode, const med_switch_mode switchmode, const med_int nentity, const med_int *const connectivity)
Cette routine permet d'écrire dans un maillage le tableau des connectivités pour un type géométrique ...
Definition MEDmeshElementConnectivityWr.c:42
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
MEDmeshNodeCoordinateWr
MEDC_EXPORT med_err MEDmeshNodeCoordinateWr(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_float dt, const med_switch_mode switchmode, const med_int nentity, const med_float *const coordinates)
Cette routine permet d'écrire dans un maillage le tableau des coordonnées des noeuds,...
Definition MEDmeshNodeCoordinateWr.c:45
MEDprofileWr
MEDC_EXPORT med_err MEDprofileWr(const med_idt fid, const char *const profilename, const med_int profilesize, const med_int *const profilearray)
Cette routine permet d'écrire un profil dans un fichier MED.
Definition MEDprofileWr.c:40
MEDstructElementCr
MEDC_EXPORT med_geometry_type MEDstructElementCr(const med_idt fid, const char *const modelname, const med_int modeldim, const char *const supportmeshname, const med_entity_type sentitytype, const med_geometry_type sgeotype)
Cette routine permet de créer un nouveau modèle d'éléments de structure dans un fichier MED.
Definition MEDstructElementCr.c:50
MEDstructElementConstAttWithProfileWr
MEDC_EXPORT med_err MEDstructElementConstAttWithProfileWr(const med_idt fid, const char *const modelname, const char *const constattname, const med_attribute_type constatttype, const med_int ncomponent, const med_entity_type sentitytype, const char *const profilename, const void *const value)
Cette routine définit un attribut caractéristique constant d'un modèle d'éléments de structure.
Definition MEDstructElementConstAttWithProfileWr.c:44
MEDstructElementConstAttWr
MEDC_EXPORT med_err MEDstructElementConstAttWr(const med_idt fid, const char *const modelname, const char *const constattname, const med_attribute_type constatttype, const med_int ncomponent, const med_entity_type sentitytype, const void *const value)
Cette routine définit un attribut caractéristique constant d'un modèle d'éléments de structure.
Definition MEDstructElementConstAttWr.c:43
MEDstructElementVarAttCr
MEDC_EXPORT med_err MEDstructElementVarAttCr(const med_idt fid, const char *const modelname, const char *const varattname, const med_attribute_type varatttype, const med_int ncomponent)
Cette routine déclare la présence d'un attribut caractéristique variable attaché aux éléments de type...
Definition MEDstructElementVarAttCr.c:42
MEDmeshStructElementVarAttWr
MEDC_EXPORT med_err MEDmeshStructElementVarAttWr(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, const med_int nentity, const void *const value)
Cette routine écrit les valeurs d'un attribut caractéristique variable sur les éléments de structure ...
Definition MEDmeshStructElementVarAttWr.c:42
MEDstructElementGeotype
MEDC_EXPORT med_geometry_type MEDstructElementGeotype(const med_idt fid, const char *const modelname)
Cette routine renvoie le type géométrique mgeotype associé au modèle d'éléments de structure de nom m...
Definition MEDstructElementGeotype.c:38
MEDsupportMeshCr
MEDC_EXPORT med_err MEDsupportMeshCr(const med_idt fid, const char *const supportmeshname, const med_int spacedim, const med_int meshdim, const char *const description, const med_axis_type axistype, const char *const axisname, const char *const axisunit)
Cette routine permet de créer un maillage support.
Definition MEDsupportMeshCr.c:46
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition med.h:81
MED_BALL_DIAMETER
#define MED_BALL_DIAMETER
Definition med.h:451
MED_FULL_INTERLACE
@ MED_FULL_INTERLACE
Definition med.h:96
med_geometry_type
int med_geometry_type
Definition med.h:194
MED_PARTICLE_LABEL
#define MED_PARTICLE_LABEL
Definition med.h:450
MED_SNAME_SIZE
#define MED_SNAME_SIZE
Definition med.h:82
MED_QUAD4
#define MED_QUAD4
Definition med.h:204
MED_SEG2
#define MED_SEG2
Definition med.h:200
MED_CARTESIAN
@ MED_CARTESIAN
Definition med.h:258
MED_SORT_DTIT
@ MED_SORT_DTIT
Definition med.h:300
MED_UNDEF_DT
#define MED_UNDEF_DT
Definition med.h:313
MED_BEAM_NAME
#define MED_BEAM_NAME
Definition med.h:447
MED_PARTICLE_NAME
#define MED_PARTICLE_NAME
Definition med.h:445
MED_UNSTRUCTURED_MESH
@ MED_UNSTRUCTURED_MESH
Definition med.h:131
med_int
int med_int
Definition med.h:333
MED_NO_DT
#define MED_NO_DT
Definition med.h:311
MED_NO_IT
#define MED_NO_IT
Definition med.h:312
MED_NONE
#define MED_NONE
Definition med.h:231
MED_BALL_NAME
#define MED_BALL_NAME
Definition med.h:446
MED_NODE
@ MED_NODE
Definition med.h:143
MED_CELL
@ MED_CELL
Definition med.h:143
MED_STRUCT_ELEMENT
@ MED_STRUCT_ELEMENT
Definition med.h:144
med_float
double med_float
Definition med.h:327
MED_ATT_FLOAT64
@ MED_ATT_FLOAT64
Definition med.h:173
MED_ATT_INT
@ MED_ATT_INT
Definition med.h:174
MED_ATT_NAME
@ MED_ATT_NAME
Definition med.h:175
MED_BEAM_THICKNESS
#define MED_BEAM_THICKNESS
Definition med.h:452
MED_ACC_CREAT
@ MED_ACC_CREAT
Definition med.h:123
med_idt
hid_t med_idt
Definition med.h:322
MED_NODAL
@ MED_NODAL
Definition med.h:255
MED_NO_MESHNAME
#define MED_NO_MESHNAME
Definition med.h:268
med.h
SSCRUTE
#define SSCRUTE(chaine)
Definition med_utils.h:323
MESSAGE
#define MESSAGE(chaine)
Definition med_utils.h:324
ISCRUTE_int
#define ISCRUTE_int(entier)
Definition med_utils.h:314
med_utils.h