MED fichier
Test_MEDmeshNodeCoordinateTrsfWr.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2  *
3  * COPYRIGHT (C) 1999 - 2021 EDF R&D, CEA/DEN
4  * MED is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * MED is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with MED. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 
19 #include <med.h>
20 #define MESGERR 1
21 #include <med_utils.h>
22 #include <math.h>
23 
24 #ifndef M_PI_2
25 # define M_PI_2 1.57079632679489661923 /* pi/2 */
26 #endif
27 
28 #ifndef M_PI_4
29 # define M_PI_4 0.78539816339744830962 /* pi/4 */
30 #endif
31 
32 #ifdef DEF_LECT_ECR
33 #define MODE_ACCES MED_ACC_RDWR
34 #elif DEF_LECT_AJOUT
35 #define MODE_ACCES MED_ACC_RDEXT
36 #else
37 #define MODE_ACCES MED_ACC_CREAT
38 #endif
39 
40 int main (int argc, char **argv)
41 
42 
43 {
44  med_err ret = 0;
45  med_idt fid;
46  /* la dimension du maillage */
47  med_int mdim = 2;
48  /* nom du maillage de longueur maxi MED_NAME_SIZE */
49  char maa[MED_NAME_SIZE+1] = "maa1";
50  /* le nombre de noeuds */
51  med_int nnoe = 4;
52  /* table des coordonnees
53  (dimension * nombre de noeuds) */
54  med_float coo[8] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0};
55  med_float coo_2[8] = {0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0};
56  /* tables des noms et des unites des coordonnees
57  (dimension*MED_SNAME_SIZE+1) */
58  /* 12345678901234561234567890123456*/
59  char nomcoo[2*MED_SNAME_SIZE+1] = "x y ";
60  char unicoo[2*MED_SNAME_SIZE+1] = "cm cm ";
61  /* tables des noms, numeros, numeros de familles des noeuds
62  autant d'elements que de noeuds - les noms ont pout longueur
63  MED_SNAME_SIZE */
64  /* 1234567890123456123456789012345612345678901234561234567890123456*/
65  char nomnoe[4*MED_SNAME_SIZE+1] = "nom1 nom2 nom3 nom4 ";
66  med_int numnoe[4] = {1,2,3,4};
67  med_int nufano[4] = {0,1,2,2};
68  const med_float phi1=0;
69  const med_float phi2=M_PI_4;
70  const med_float phi3=M_PI_2;
71  med_float trsf1[7]= {0,0,0, cos(phi1/2), 0, sin(phi1/2), 0 };
72  med_float trsf2[7]= {0,0,0, cos(phi2/2), 0, sin(phi2/2), 0 };
73  med_float trsf3[7]= {0,0,0, cos(phi3/2), 0, sin(phi3/2), 0 };
74 
75  /* ouverture du fichier */
76  if ((fid = MEDfileOpen("Test_MEDmeshNodeCoordinateTrsfWr.med",MODE_ACCES)) < 0){
77  MESSAGE("Erreur à l'ouverture du fichier : ");
78  return -1;
79  }
80 
81  /* Creation du maillage "maa" de type MED_NON_STRUCURE
82  et de dimension 2 */
83  if (MEDmeshCr( fid, maa, mdim, mdim, MED_UNSTRUCTURED_MESH,
84  "un maillage pour Test_MEDmeshNodeCoordinateTrsfWr","s", MED_SORT_DTIT,
85  MED_CARTESIAN, nomcoo, unicoo) < 0) {
86  MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(maa);
87  ret = -1;
88  }
89 
90  /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE :
91  (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */
93  MED_FULL_INTERLACE,nnoe, coo) < 0) {
94  MESSAGE("Erreur a l'ecriture des coordonnees des noeuds");
95  ret = -1;
96  }
97 
98  /* Ecriture des noms des noeuds (optionnel dans un maillage MED) */
99  if (MEDmeshEntityNameWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,nomnoe) < 0) {
100  MESSAGE("Erreur a l'ecriture des noms des noeuds");
101  ret = -1;
102  }
103 
104  /* Ecriture des numeros des noeuds (optionnel dans un maillage MED) */
105  if (MEDmeshEntityNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,numnoe) < 0) {
106  MESSAGE("Erreur a l'ecriture des numeros des noeuds");
107  ret = -1;
108  }
109 
110  /* Ecriture des numeros de famille des noeuds */
111  if (MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,nufano) < 0) {
112  MESSAGE("Erreur a l'ecriture des numeros de familles des noeuds");
113  ret = -1;
114  }
115 
116  /* Transformation des coordonnees des noeuds coo_1 :
117  */
118  fprintf(stdout,"Un message d'erreur est attendu: \n");
119  if ( MEDmeshNodeCoordinateTrsfWr(fid,maa,MED_NO_DT,MED_NO_IT,0.4,trsf1) >= 0) {
120  MESSAGE("Erreur a l'ecriture de la transformation géométrique n°1");
121  MESSAGE("Aucune transformation géométrique à la séquence de calcul MED_NO_DT,MED_NO_IT n'est possible.");
122  }
123  fprintf(stdout,"Fin du message d'erreur attendu\n :");
124 
125  /* Transformation des coordonnees des noeuds coo_1 :
126  */
127  if ( MEDmeshNodeCoordinateTrsfWr(fid,maa,1,1,0.4,trsf1) < 0) {
128  MESSAGE("Erreur a l'ecriture de la transformation géométrique n°1");
129  ret = -1;
130  }
131 
132  /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE :
133  (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */
134  fprintf(stdout,"Un message d'erreur est attendu : \n");
135  if (MEDmeshNodeCoordinateWr(fid,maa,1,1, 0.5,
136  MED_FULL_INTERLACE,nnoe, coo_2) >= 0) {
137  MESSAGE("Erreur a l'ecriture des coordonnees des noeuds");
138  MESSAGE("Aucune ecriture des coordonnees des noeuds n'est possible sur une séquence de calcul comportant "\
139  "une transformation géométrique.");
140  }
141  fprintf(stdout,"Fin du message d'erreur attendu :\n");
142 
143  /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE :
144  (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */
145  if (MEDmeshNodeCoordinateWr(fid,maa,2,1, 0.5,
146  MED_FULL_INTERLACE,nnoe, coo_2) < 0) {
147  MESSAGE("Erreur a l'ecriture des coordonnees des noeuds");
148  ret = -1;
149  }
150 
151  /* Transformation des coordonnees des noeuds coo_2 :
152  */
153  fprintf(stdout,"Un message d'erreur est attendu\n :");
154  if ( MEDmeshNodeCoordinateTrsfWr(fid,maa,2,1,0.5,trsf2) >= 0) {
155  MESSAGE("Erreur a l'ecriture de la transformation géométrique n°2");
156  MESSAGE("Aucune transformation géométrique à une séquence de calcul comportant de nouvelles coordonnées n'est possible.");
157  }
158  fprintf(stdout,"Fin du message d'erreur attendu\n :");
159 
160  /* Transformation des coordonnees des noeuds coo_2 :
161  */
162  if ( MEDmeshNodeCoordinateTrsfWr(fid,maa,2,2,0.6,trsf2) < 0) {
163  MESSAGE("Erreur a l'ecriture de la transformation géométrique n°2");
164  ret = -1;
165  }
166 
167  /* Transformation des coordonnees des noeuds coo_3 :
168  */
169  if ( MEDmeshNodeCoordinateTrsfWr(fid,maa,3,2,0.7,trsf3) < 0) {
170  MESSAGE("Erreur a l'ecriture de la transformation géométrique n°3");
171  ret = -1;
172  }
173 
174  if ( MEDmeshComputationStepCr(fid,maa, 3,2, 3,3, 3.3) < 0) {
175  MESSAGE("Erreur a la creation d'un pas de temps du maillage maa");
176  }
177 
178  /* Modification des numeros des noeuds (optionnel dans un maillage MED) */
179  numnoe[2]=200;
180  if (MEDmeshEntityNumberWr(fid,maa,3,3,MED_NODE,MED_NONE,nnoe,numnoe) < 0) {
181  MESSAGE("Erreur a l'ecriture des numeros des noeuds");
182  ret = -1;
183  }
184 
185  if ( MEDmeshComputationStepCr(fid,maa, 3,3, 3,4, 3.4) < 0) {
186  MESSAGE("Erreur a la creation d'un pas de temps du maillage maa");
187  }
188 
189  /*TODO : Ecrire un test de comparaison interne next prev et ordre de découverte itératif */
190 
191  /* Fermeture du fichier */
192  if (MEDfileClose(fid) < 0) {
193  MESSAGE("Erreur a la fermeture du fichier test4.med");
194  return -1;
195  }
196  return ret;
197 }
198 
199 
200 
201 
MED_CARTESIAN
Definition: med.h:258
MEDmeshEntityNumberWr
MEDC_EXPORT med_err MEDmeshEntityNumberWr(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 d'écrire les numéros d'un type d'entité d'un maillage.
Definition: MEDmeshEntityNumberWr.c:39
MED_FULL_INTERLACE
Definition: med.h:96
MED_SORT_DTIT
Definition: med.h:309
M_PI_4
#define M_PI_4
Definition: Test_MEDmeshNodeCoordinateTrsfWr.c:29
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
MODE_ACCES
#define MODE_ACCES
Definition: Test_MEDmeshNodeCoordinateTrsfWr.c:37
med_idt
hid_t med_idt
Definition: med.h:331
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
med_err
herr_t med_err
Definition: med.h:332
MEDmeshComputationStepCr
MEDC_EXPORT med_err MEDmeshComputationStepCr(const med_idt fid, const char *const meshname, const med_int numdt1, const med_int numit1, const med_int numdt2, const med_int numit2, const med_float dt2)
Cette routine permet de créer une nouvelle étape de calcul dans un maillage.
Definition: MEDmeshComputationStepCr.c:40
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
med_int
int med_int
Definition: med.h:342
med.h
main
int main(int argc, char **argv)
Definition: Test_MEDmeshNodeCoordinateTrsfWr.c:40
med_float
double med_float
Definition: med.h:336
M_PI_2
#define M_PI_2
Definition: Test_MEDmeshNodeCoordinateTrsfWr.c:25
MED_NO_DT
#define MED_NO_DT
Definition: med.h:320
MED_NONE
#define MED_NONE
Definition: med.h:231
MED_NODE
Definition: med.h:143
MEDmeshNodeCoordinateTrsfWr
MEDC_EXPORT med_err MEDmeshNodeCoordinateTrsfWr(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_float dt, const med_float *const coordinatetrsf)
Cette routine définit les paramètres de translation rotation à appliquer aux noeuds de l'étape de cal...
Definition: MEDmeshNodeCoordinateTrsfWr.c:41
SSCRUTE
#define SSCRUTE(chaine)
Definition: med_utils.h:323
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
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:81
MED_UNSTRUCTURED_MESH
Definition: med.h:131
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MED_UNDEF_DT
#define MED_UNDEF_DT
Definition: med.h:322
MED_NO_IT
#define MED_NO_IT
Definition: med.h:321
med_utils.h