Changeset 7660


Ignore:
Timestamp:
03/18/11 15:54:45 (14 years ago)
Author:
jschierm
Message:

KML: added creation of nodal connectivity table to KMLMeshWritex.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/modules/KMLMeshWritex/KMLMeshWritex.cpp

    r7658 r7660  
    1919                                   FILE* fid){
    2020
    21         int     i,j,k,ipt=0,jpt=0;
     21        int     i,j,k,ipt=0,jpt=0,nnodes;
     22        int     mxepg=25;
    2223        int     lwidth=1;
    2324        double  popac=0.50;
    2425        char    indent[81]="  ";
    2526        double* edata=NULL;
     27        bool    ncfree=false,
     28                        edfree=false;
    2629        KML_Document*  kdoc=NULL;
    2730        KML_Style*     kstyle;
     
    112115//      kdoc->DeepEcho();
    113116
    114 /*  average nodal data to element data, if necessary  */
     117/*  create the node connectivity table, if necessary
     118        (noting that rows do not need to be sorted, since the elements
     119        are consecutively numbered)  */
     120
     121        if (!nodecon) {
     122                _printf_(true,"Creating the node connectivity table.\n");
     123                nncon=mxepg+1;
     124                nodecon=(int *) xcalloc(mncon*nncon,sizeof(int));
     125                ncfree=true;
     126
     127                jpt=0;
     128                for (i=0; i<melem; i++) {
     129                        for (j=0; j<nelem; j++) {
     130                                if (elem[jpt]) {
     131                                        ipt=(elem[jpt]-1)*nncon;
     132                                        if (nodecon[ipt+(nncon-1)] < mxepg) {
     133                                                nodecon[ipt+nodecon[ipt+(nncon-1)]]=i+1;
     134                                                nodecon[ipt+(nncon-1)]++;
     135                                        }
     136                                        else
     137                                                _error_("Nodal connectivity table needs more than specified %d columns.\n",mxepg);
     138                                }
     139                                jpt++;
     140                        }
     141                }
     142        }
     143
     144/*  average nodal data to element data, if necessary
     145        (noting that multiple columns of data are handled here, but not
     146        yet below)  */
    115147
    116148        if (data) {
    117149                if      (mdata == melem)
    118150                        edata=data;
     151
    119152                else if (mdata == mncon) {
    120153                        _printf_(true,"Averaging nodal data to element data.\n");
    121154                        edata=(double *) xcalloc(melem*ndata,sizeof(double));
     155                        edfree=true;
     156
    122157                        ipt=0;
    123158                        jpt=0;
    124159                        for (i=0; i<melem; i++) {
     160                                nnodes=0;
    125161                                for (j=0; j<nelem; j++) {
    126                                         for (k=0; k<ndata; k++)
    127                                                 edata[ipt+k]+=data[(elem[jpt]-1)*ndata+k];
     162                                        if (elem[jpt]) {
     163                                                for (k=0; k<ndata; k++)
     164                                                        edata[ipt+k]+=data[(elem[jpt]-1)*ndata+k];
     165                                                nnodes++;
     166                                        }
    128167                                        jpt++;
    129168                                }
    130                                 for (k=0; k<ndata; k++)
    131                                         edata[ipt+k]/=(double)nelem;
     169                                if (nnodes)
     170                                        for (k=0; k<ndata; k++)
     171                                                edata[ipt+k]/=(double)nnodes;
    132172                                ipt+=ndata;
    133173                        }
    134174                }
     175
    135176                else
    136                         _error_("Data has incorrect number of %d rows.\n",mdata);
     177                        _error_("Data matrix has incorrect number of %d rows.\n",mdata);
    137178        }
    138179
     
    145186                                                                                                                cmap,mcmap,ncmap));
    146187
    147         if (mdata == mncon) xfree((void**)&edata);
     188        if (edfree) xfree((void**)&edata);
     189        if (ncfree) xfree((void**)&nodecon);
    148190        clock0a=clock();
    149191        time0a =time(NULL);
     
    187229        double  alt=10000;
    188230        double  cmin= DBL_MAX,
    189                     cmax=-DBL_MAX;
     231                        cmax=-DBL_MAX;
    190232        int     imap;
    191233        KML_Folder*     kfold =NULL;
Note: See TracChangeset for help on using the changeset viewer.