[cig-commits] r4465 - in mc/3D/CitcomS/trunk: lib visual

luis at geodynamics.org luis at geodynamics.org
Sat Sep 2 03:11:53 PDT 2006


Author: luis
Date: 2006-09-02 03:11:53 -0700 (Sat, 02 Sep 2006)
New Revision: 4465

Modified:
   mc/3D/CitcomS/trunk/lib/Instructions.c
   mc/3D/CitcomS/trunk/lib/Output_h5.c
   mc/3D/CitcomS/trunk/lib/global_defs.h
   mc/3D/CitcomS/trunk/visual/estimate.py
Log:
Added connectivity datasets (per cap) to HDF5 optional output.


Modified: mc/3D/CitcomS/trunk/lib/Instructions.c
===================================================================
--- mc/3D/CitcomS/trunk/lib/Instructions.c	2006-09-02 09:31:15 UTC (rev 4464)
+++ mc/3D/CitcomS/trunk/lib/Instructions.c	2006-09-02 10:11:53 UTC (rev 4465)
@@ -976,6 +976,7 @@
     pos = 0;
     next = E->output.optional;
 
+    E->output.connectivity = 0;
     E->output.stress = 0;
     E->output.pressure = 0;
     E->output.surf = 0;
@@ -996,7 +997,9 @@
 	if (strlen(prev) == 0) continue;
 
 	/* fprintf(stderr, "### %s: %s\n", prev, next); */
-	if(strcmp(prev, "stress")==0)
+    if(strcmp(prev, "connectivity")==0)
+        E->output.connectivity = 1;
+	else if(strcmp(prev, "stress")==0)
 	    E->output.stress = 1;
 	else if(strcmp(prev, "pressure")==0)
 	    E->output.pressure = 1;

Modified: mc/3D/CitcomS/trunk/lib/Output_h5.c
===================================================================
--- mc/3D/CitcomS/trunk/lib/Output_h5.c	2006-09-02 09:31:15 UTC (rev 4464)
+++ mc/3D/CitcomS/trunk/lib/Output_h5.c	2006-09-02 10:11:53 UTC (rev 4465)
@@ -51,12 +51,13 @@
 /* constant data (only for first cycle) */
 void h5output_meta(struct All_variables *);
 void h5output_coord(struct All_variables *);
-void h5output_surf_botm_coord(struct All_variables *E);
+void h5output_surf_botm_coord(struct All_variables *);
 void h5output_have_coord(struct All_variables *);
 void h5output_material(struct All_variables *);
+void h5output_connectivity(struct All_variables *);
 
 /* time-varying data */
-void h5extend_time_dimension(struct All_variables *E);
+void h5extend_time_dimension(struct All_variables *);
 void h5output_velocity(struct All_variables *, int);
 void h5output_temperature(struct All_variables *, int);
 void h5output_viscosity(struct All_variables *, int);
@@ -75,6 +76,8 @@
 /* for creation of field and other dataset objects */
 static herr_t h5allocate_field(struct All_variables *E, enum field_class_t field_class, int nsd, int time, hid_t dtype, field_t **field);
 static herr_t h5create_field(hid_t loc_id, const char *name, const char *title, field_t *field);
+
+/* for creation of citcoms hdf5 datasets */
 static herr_t h5create_coord(hid_t loc_id, field_t *field);
 static herr_t h5create_velocity(hid_t loc_id, field_t *field);
 static herr_t h5create_stress(hid_t loc_id, field_t *field);
@@ -90,6 +93,7 @@
 static herr_t h5create_have_vxy_rms(hid_t loc_id, field_t *field);
 static herr_t h5create_have_vz_rms(hid_t loc_id, field_t *field);
 static herr_t h5create_time(hid_t loc_id);
+static herr_t h5create_connectivity(hid_t loc_id, int nel);
 
 /* for writing to datasets */
 static herr_t h5write_dataset(hid_t dset_id, hid_t mem_type_id, const void *data, int rank, hsize_t *memdims, hsize_t *offset, hsize_t *stride, hsize_t *count, hsize_t *block);
@@ -126,6 +130,8 @@
         h5output_surf_botm_coord(E);
         h5output_have_coord(E);
         h5output_material(E);
+        if(E->output.connectivity == 1)
+            h5output_connectivity(E);
     }
 
     h5extend_time_dimension(E);
@@ -201,6 +207,7 @@
 
     herr_t status;
 
+
     /*
      * Create HDF5 file using parallel I/O
      */
@@ -223,6 +230,7 @@
     /* save the file identifier for later use */
     E->hdf5.file_id = file_id;
 
+
     /*
      * Allocate field objects for use in dataset writes...
      * TODO: check E->output.* input parameters to decide which buffers to allocate
@@ -246,7 +254,7 @@
     h5allocate_field(E, SCALAR_FIELD, 1, 0, dtype, &(E->hdf5.const_scalar1d));
 
     h5allocate_field(E, TENSOR_FIELD, 3, 1, dtype, &(E->hdf5.tensor3d));
-        
+
     h5allocate_field(E, VECTOR_FIELD, 3, 1, dtype, &(E->hdf5.vector3d));
     h5allocate_field(E, VECTOR_FIELD, 2, 1, dtype, &(E->hdf5.vector2d));
 
@@ -254,12 +262,14 @@
     h5allocate_field(E, SCALAR_FIELD, 2, 1, dtype, &(E->hdf5.scalar2d));
     h5allocate_field(E, SCALAR_FIELD, 1, 1, dtype, &(E->hdf5.scalar1d));
 
+
     /*
      * Create time table (to store nondimensional and cpu times)
      */
 
     h5create_time(file_id);
 
+
     /*
      * Create necessary groups and arrays
      */
@@ -286,6 +296,12 @@
             h5create_stress(cap_group, E->hdf5.tensor3d);
 
         /********************************************************************
+         * Create connectivity dataset                                      *
+         ********************************************************************/
+        if (E->output.connectivity == 1)
+            h5create_connectivity(cap_group, E->mesh.nel);
+
+        /********************************************************************
          * Create /cap/surf/ group                                          *
          ********************************************************************/
         if (E->output.surf == 1)
@@ -872,12 +888,39 @@
     return 0;
 }
 
+static herr_t h5create_connectivity(hid_t loc_id, int nel)
+{
+    hid_t dataset;
+    hid_t dataspace;
+    herr_t status;
+
+    hsize_t dims[2];
+
+    dims[0] = nel;
+    dims[1] = 8;
+
+    /* Create the dataspace */
+    dataspace = H5Screate_simple(2, dims, NULL);
+
+    /* Create the dataset */
+    dataset = H5Dcreate(loc_id, "connectivity", H5T_NATIVE_INT, dataspace, H5P_DEFAULT);
+
+    /* Write necessary attributes for PyTables compatibility */
+    set_attribute_string(dataset, "TITLE", "Node connectivity");
+    set_attribute_string(dataset, "CLASS", "ARRAY");
+    set_attribute_string(dataset, "FLAVOR", "numpy");
+    set_attribute_string(dataset, "VERSION", "2.3");
+
+    status = H5Sclose(dataspace);
+    status = H5Dclose(dataset);
+    return 0;
+}
+
 static herr_t h5create_time(hid_t loc_id)
 {
     hid_t dataset;      /* dataset identifier */
     hid_t datatype;     /* row datatype identifier */
     hid_t dataspace;    /* memory dataspace */
-    hid_t filespace;    /* file dataspace */
     hid_t dcpl_id;      /* dataset creation property list identifier */
     herr_t status;
 
@@ -1044,11 +1087,11 @@
 void h5extend_time_dimension(struct All_variables *E)
 {
     int i;
-    field_t *field[6];
+    field_t *field[6];  /* TODO: add to hdf5_info struct */
 
     E->hdf5.count += 1;
 
-    field[0] = E->hdf5.tensor3d;
+    field[0] = E->hdf5.tensor3d;    /* TODO: initialize in h5output_open() */
     field[1] = E->hdf5.vector3d;
     field[2] = E->hdf5.vector2d;
     field[3] = E->hdf5.scalar3d;
@@ -1898,7 +1941,79 @@
     status = H5Dclose(dataset);
 }
 
+void h5output_connectivity(struct All_variables *E)
+{
+    hid_t dataset;
+    herr_t status;
 
+    int rank = 2;
+    hsize_t memdims[2];
+    hsize_t offset[2];
+    hsize_t stride[2];
+    hsize_t count[2];
+    hsize_t block[2];
+
+    int p;
+    int px = E->parallel.me_loc[1];
+    int py = E->parallel.me_loc[2];
+    int pz = E->parallel.me_loc[3];
+    int nprocx = E->parallel.nprocx;
+    int nprocy = E->parallel.nprocy;
+    int nprocz = E->parallel.nprocz;
+
+
+    int e;
+    int nel = E->lmesh.nel;
+    int *ien;
+
+    int *data;
+
+    /* process id (local to cap) */
+    p = pz + px*nprocz + py*nprocz*nprocx;
+
+    rank = 2;
+
+    memdims[0] = nel;
+    memdims[1] = 8;
+
+    offset[0] = nel * p;
+    offset[1] = 0;
+
+    stride[0] = 1;
+    stride[1] = 1;
+
+    count[0] = 1;
+    count[1] = 1;
+
+    block[0] = nel;
+    block[1] = 8;
+
+    data = (int *)malloc((nel*8) * sizeof(int));
+
+    for(e = 0; e < nel; e++)
+    {
+        ien = E->ien[1][e+1].node;
+        data[8*e+0] = ien[1]-1; /* TODO: subtract one? */
+        data[8*e+1] = ien[2]-1;
+        data[8*e+2] = ien[3]-1;
+        data[8*e+3] = ien[4]-1;
+        data[8*e+4] = ien[5]-1;
+        data[8*e+5] = ien[6]-1;
+        data[8*e+6] = ien[7]-1;
+        data[8*e+7] = ien[8]-1;
+    }
+
+    dataset = H5Dopen(E->hdf5.cap_group, "connectivity");
+
+    status = h5write_dataset(dataset, H5T_NATIVE_INT, data, rank, memdims,
+                             offset, stride, count, block);
+    
+    status = H5Dclose(dataset);
+    
+    free(data);
+}
+
+
 /****************************************************************************
  * Input parameters and other information                                   *
  ****************************************************************************/

Modified: mc/3D/CitcomS/trunk/lib/global_defs.h
===================================================================
--- mc/3D/CitcomS/trunk/lib/global_defs.h	2006-09-02 09:31:15 UTC (rev 4464)
+++ mc/3D/CitcomS/trunk/lib/global_defs.h	2006-09-02 10:11:53 UTC (rev 4465)
@@ -794,6 +794,7 @@
 struct Output {
     char format[10];  /* ascii or hdf5 */
     char optional[1000]; /* comma-delimited list of objects to output */
+    int connectivity; /* whether to output connectivity */
     int stress;       /* whether to output stress */
     int pressure;     /* whether to output pressure */
     int surf;         /* whether to output surface data */

Modified: mc/3D/CitcomS/trunk/visual/estimate.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/estimate.py	2006-09-02 09:31:15 UTC (rev 4464)
+++ mc/3D/CitcomS/trunk/visual/estimate.py	2006-09-02 10:11:53 UTC (rev 4465)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-"""\
+"""
 This script estimates the size of the output from CitcomS,
 assuming binary floating point data.
 
@@ -13,8 +13,9 @@
                 [ --nodez <number> | -z <number> ]
                 [ --caps  <number> | -c <number> | --full | --regional ]
                 [ --all | -a ]
+                [ --connectivity ]
+                [ --stress ]
                 [ --pressure ]
-                [ --stress ]
                 [ --surf ]
                 [ --botm ]
                 [ --average ]
@@ -70,8 +71,9 @@
     import getopt
 
     out = {
+        'connectivity': False,
+        'stress': False,
         'pressure': False,
-        'stress': False,
         'surf': False,
         'botm': False,
         'average': False,
@@ -84,7 +86,7 @@
 
     opts, args = getopt.getopt(sys.argv[1:], "hac:t:x:y:z:",
         ['help','full','regional','caps=','steps=','nodex=','nodey=','nodez=',
-         'all','pressure','stress','surf','botm','average'])
+         'all','connectivity','stress','pressure','surf','botm','average'])
     
     for opt,arg in opts:
         
@@ -111,10 +113,12 @@
         if opt in ('-a','--all'):
             for k in out:
                 out[k] = True
+        if opt == '--connectivity':
+            out['connectivity'] = True
+        if opt == '--stress':
+            out['stress'] = True
         if opt == '--pressure':
             out['pressure'] = True
-        if opt == '--stress':
-            out['stress'] = True
         if opt == '--surf':
             out['surf'] = True
         if opt == '--botm':
@@ -144,8 +148,12 @@
     nno = nodex * nodey * nodez
     nsf = nodex * nodey
 
+    elx = nodex - 1
+    ely = nodey - 1
+    elz = nodez - 1
+    nel = elx * ely * elz
 
-    # conversion factor (float = 4 bytes)
+    # conversion factor (double = 8 bytes, float = 4 bytes, int = 4 bytes)
     f = 4
 
 
@@ -156,9 +164,12 @@
     vector2d = f * nsf * 2
     scalar2d = f * nsf * 1
     scalar1d = f * nodez
-    buffer_total = tensor3d + vector3d + scalar3d + vector2d + scalar2d + \
+    buffer_total = tensor3d + vector3d + scalar3d + \
+                   vector2d + scalar2d + \
                    scalar1d
-    
+
+    connectivity = f * caps * nel * 8
+
     coord       = caps * scalar3d
     velocity    = steps * caps * vector3d
     temperature = steps * caps * scalar3d
@@ -182,10 +193,12 @@
 
     total  = coord + velocity + temperature + viscosity
 
+    if out['connectivity']:
+        total += connectivity
+    if out['stress']:
+        total += stress
     if out['pressure']:
         total += pressure
-    if out['stress']:
-        total += stress
     if out['surf']:
         total += surf_total
     if out['botm']:
@@ -208,27 +221,10 @@
     print "total            %s" % ps(buffer_total)
 
     print "\n"
-    print "By Percentage:"
-    print "=" * hr
-    if True:
-        print "coord        %s" % pc(coord,total)
-        print "velocity     %s" % pc(velocity,total)
-        print "temperature  %s" % pc(temperature,total)
-        print "viscosity    %s" % pc(viscosity,total)
-    if out['pressure']:
-        print "pressure     %s" % pc(pressure,total)
-    if out['stress']:
-        print "stress       %s" % pc(stress,total)
-    if out['surf']:
-        print "surf         %s" % pc(surf_total,total)
-    if out['botm']:
-        print "botm         %s" % pc(surf_total,total)
-    if out['average']:
-        print "average      %s" % pc(have_total,total)
-
-    print "\n"
     print "By Dataset:"
     print "=" * hr
+    if out['connectivity']:
+        print "connectivity         %s" % ps(connectivity)
     if True:
         print "coord                %s" % ps(coord)
         print "velocity             %s" % ps(velocity)
@@ -257,6 +253,27 @@
         print "-" * hr
         print "total                %s" % ps(total)
 
+    print "\n"
+    print "By Percentage:"
+    print "=" * hr
+    if out['connectivity']:
+        print "connectivity  %s" % pc(connectivity,total)
+    if True:
+        print "coord         %s" % pc(coord,total)
+        print "velocity      %s" % pc(velocity,total)
+        print "temperature   %s" % pc(temperature,total)
+        print "viscosity     %s" % pc(viscosity,total)
+    if out['pressure']:
+        print "pressure      %s" % pc(pressure,total)
+    if out['stress']:
+        print "stress        %s" % pc(stress,total)
+    if out['surf']:
+        print "surf          %s" % pc(surf_total,total)
+    if out['botm']:
+        print "botm          %s" % pc(surf_total,total)
+    if out['average']:
+        print "average       %s" % pc(have_total,total)
 
+
 if __name__ == '__main__':
     main()



More information about the cig-commits mailing list