MEDgro2famCr.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2015  EDF R&D, CEA/DEN
00004  *  MED is free software: you can redistribute it and/or modify
00005  *  it under the terms of the GNU Lesser General Public License as published by
00006  *  the Free Software Foundation, either version 3 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  MED is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Lesser General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Lesser General Public License
00015  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 
00019 #include <med.h>
00020 #include <med_config.h>
00021 #include <med_outils.h>
00022 
00023 #include <string.h>
00024 #include <stdlib.h>
00025 
00026 med_err 
00027 MEDgro2famCr(med_idt fid,char *maillage,char *groupes,med_int *index,med_int ngroup,med_int *entites,
00028              med_int nent,med_entite_maillage type_ent,med_geometrie_element *type_geo,med_int *indexgeo,
00029              med_int ngeo)
00030 {
00031   med_err ret = 0;
00032   med_int nfam = 0;
00033   int i,j,k,l,m;
00034   int col,bit,som;
00035   int est_egale, trouvee;
00036   unsigned char ajout,tmp;
00037   unsigned char *groupes_par_entite;
00038   med_int *numfam;
00039   med_int numgro;
00040   char nom[MED_TAILLE_NOM+1];
00041   char nomgro[MED_TAILLE_LNOM+1];
00042   char *gro;
00043   med_int num,ngro,natt;
00044   med_int *nummai;
00045   med_entite_maillage _type_ent=type_ent;
00046 
00047   if ( type_ent == MED_NOEUD_MAILLE ) _type_ent=MED_NOEUD ;
00048 
00049   /* Premiere phase : on etablit la liste des groupes
00050      pour chaque entite */
00051   groupes_par_entite = (unsigned char *) malloc(sizeof(unsigned char)*nent*(ngroup/8+1));
00052   for (i=0;i<nent;i++)
00053     for (j=0;j<ngroup/8+1;j++)
00054       *(groupes_par_entite+i*(ngroup/8+1)+j) = 0;
00055   for (i=0;i<ngroup;i++) {
00056     col = i/8;
00057     bit = 7-i%8;
00058     for (j=*(index+i)-1;j<*(index+i+1)-1;j++) {
00059       ajout = 1;
00060       for (k=0;k<bit;k++) 
00061         ajout = ajout*2;
00062       *(groupes_par_entite + (*(entites+j)-1)*(ngroup/8+1) + col) += ajout;
00063     }
00064   }
00065 
00066   /* 
00067    * Deuxieme phase : on construit la liste des numeros de familles 
00068    */
00069   numfam = (med_int *) malloc(sizeof(med_int)*nent);
00070   for (i=0;i<nent;i++) {
00071 
00072     som = 0;
00073     for (j=0;j<ngroup/8+1;j++) 
00074       som += (int) *(groupes_par_entite+i*(ngroup/8+1)+j);
00075 
00076     if (som == 0) 
00077       /* si som == 0 => famille 0 */
00078       *(numfam+i) = 0;
00079     else {
00080       /* on regarde si l'entite appartient a une famille existante :
00081          - Si c'est le cas, on enrgistre le numero correspondant
00082          - Si ce n'est pas le cas, on cree un nouveau numero 
00083       */
00084       trouvee = 0;
00085       for (j=0;j<i;j++)
00086         if (*(numfam+j) != 0) {
00087           est_egale = 1;
00088           for (k=0;k<ngroup/8+1;k++)
00089             if (*(groupes_par_entite+i*(ngroup/8+1)+k) != *(groupes_par_entite+j*(ngroup/8+1)+k))
00090               est_egale = 0;
00091           if (est_egale) {
00092             *(numfam+i) = *(numfam+j);
00093             trouvee = 1;
00094             break;
00095           }
00096         }
00097 
00098       if (! trouvee) {
00099         nfam ++;
00100         if (_type_ent == MED_NOEUD)
00101           *(numfam+i) = nfam;
00102         else
00103           *(numfam+i) = -nfam;
00104       }
00105     }
00106   }
00107 
00108   /* 
00109    * Troisieme phase : on construit chaque famille 
00110    *  et on la stocke dans le fichier MED 
00111    */
00112   natt = 0;
00113   gro = (char *) malloc(sizeof(char)*(MED_TAILLE_LNOM*ngroup+1));
00114   for (i=1;i<nfam+1;i++) {
00115     trouvee = 0;
00116     for (j=0;j<nent;j++)
00117       if ((*(numfam+j) == -i) || (*(numfam+j) == i)) {
00118         trouvee = 1;
00119         /* on definit, le nom, le numero, la liste des noms de groupes 
00120            de la famille */
00121         num = *(numfam+j);
00122         if (_type_ent == MED_NOEUD)
00123           sprintf(nom,"FAMILLE_NOEUD_%d",i);
00124         else 
00125           sprintf(nom,"FAMILLE_ELEMENT_%d",i);
00126         ngro = 0;
00127         for (k=0;k<ngroup/8+1;k++)
00128           if (*(groupes_par_entite+j*(ngroup/8+1)+k) != 0) {
00129             tmp = *(groupes_par_entite+j*(ngroup/8+1)+k);
00130             for (l=0;l<ngroup;l++) {
00131               col = l/8;
00132               bit = 7-l%8;
00133               ajout = 1;
00134               for (m=0;m<bit;m++)
00135                 ajout = ajout*2;
00136               if (ajout & tmp) {
00137                 numgro = col + (7 - bit);
00138                 ngro++;
00139                 strncpy(nomgro,groupes+numgro*MED_TAILLE_LNOM,MED_TAILLE_LNOM);
00140                 nomgro[MED_TAILLE_LNOM] = '\0';
00141                 if (ngro == 1) 
00142                   strcpy(gro,nomgro);
00143                 else
00144                   strcat(gro+(ngro-1)*MED_TAILLE_LNOM,nomgro);
00145               }
00146             }
00147           }
00148 
00149         ret = MEDfamCr(fid,maillage,nom,num,NULL,NULL,NULL,natt,gro,ngro);
00150 
00151         break;
00152       }
00153   }
00154 
00155   /* 
00156    * Quatrieme phase : on ecrit les numeros de familles 
00157    */
00158   if (ret == 0) {
00159     if (_type_ent == MED_NOEUD) 
00160       ret = MEDfamEcr(fid,maillage,numfam,nent,MED_NOEUD,(med_geometrie_element) 0);
00161     if (_type_ent == MED_MAILLE || _type_ent == MED_FACE || _type_ent == MED_ARETE) {
00162       som = 0;
00163       for (i=0;i<ngeo;i++) {
00164         if (ret == 0) {
00165           /* m = le nombre de mailles d'un type geometrique donne */
00166           m = *(indexgeo+i+1)-*(indexgeo+i);
00167           nummai = (med_int *) malloc(sizeof(med_int)*m);
00168           for(j=0;j<m;j++)
00169             *(nummai+j) = *(numfam+som+j);
00170           ret = MEDfamEcr(fid,maillage,nummai,m,_type_ent,*(type_geo+i));
00171           free(nummai);
00172           som += m;
00173         }
00174       }
00175     }
00176   }
00177 
00178 
00179   /* 
00180    * Derniere phase : on nettoie la memoire 
00181    */
00182   free(groupes_par_entite);
00183   free(numfam);
00184   free(gro);
00185 
00186   return ret; 
00187 }

Généré le Thu Oct 8 14:26:16 2015 pour MED fichier par  doxygen 1.6.1