[cig-commits] r7740 - in long/3D/Gale/trunk: . src/Underworld/plugins/Output/VTKOutput

walter at geodynamics.org walter at geodynamics.org
Tue Jul 24 11:20:15 PDT 2007


Author: walter
Date: 2007-07-24 11:20:14 -0700 (Tue, 24 Jul 2007)
New Revision: 7740

Modified:
   long/3D/Gale/trunk/
   long/3D/Gale/trunk/src/Underworld/plugins/Output/VTKOutput/VTKOutput.c
Log:
 r1898 at earth:  boo | 2007-07-24 00:24:20 -0700
 Output a parallel vtk control file for the fields and pressure.  It only is correct in serial



Property changes on: long/3D/Gale/trunk
___________________________________________________________________
Name: svk:merge
   - 3a629746-de10-0410-b17b-fd6ecaaa963e:/cig:1897
   + 3a629746-de10-0410-b17b-fd6ecaaa963e:/cig:1898

Modified: long/3D/Gale/trunk/src/Underworld/plugins/Output/VTKOutput/VTKOutput.c
===================================================================
--- long/3D/Gale/trunk/src/Underworld/plugins/Output/VTKOutput/VTKOutput.c	2007-07-24 18:20:08 UTC (rev 7739)
+++ long/3D/Gale/trunk/src/Underworld/plugins/Output/VTKOutput/VTKOutput.c	2007-07-24 18:20:14 UTC (rev 7740)
@@ -81,14 +81,15 @@
 void VTKOutput_particles(IntegrationPointsSwarm*  picswarm, 
                          double defaultDiffusivity,
                          int stepping,
-                         char *outputPath, int timeStep, int dim, int myRank);
-void VTKOutput_fields(void *context, int myRank);
+                         char *outputPath, int timeStep, int dim, int myRank,
+                         int nprocs);
+void VTKOutput_fields(void *context, int myRank, int nprocs);
 
 void VTKOutput( void* _context ) {
 	UnderworldContext*	context = (UnderworldContext*)_context;
 	Dictionary*             dictionary         = context->dictionary;
 
-        int myRank;
+        int myRank, nprocs;
         MPI_Comm comm;
 
         comm=CommTopology_GetComm
@@ -96,6 +97,7 @@
                                  MT_VERTEX));
                                  
 	MPI_Comm_rank( comm, (int*)&myRank );
+        MPI_Comm_size( comm, (int*)&nprocs );
 
         /* Only dump if at the right time step. */
         if(context->timeStep % context->dumpEvery != 0)
@@ -109,14 +111,14 @@
                             Dictionary_GetInt_WithDefault
                             (dictionary,"particleStepping",1),
                             context->outputPath, context->timeStep,
-                            context->dim,myRank);
-        VTKOutput_fields(context,myRank);
+                            context->dim,myRank,nprocs);
+        VTKOutput_fields(context,myRank,nprocs);
 }
 
 void VTKOutput_particles(IntegrationPointsSwarm*  picswarm,
                          double defaultDiffusivity,
                          int stepping, char *outputPath,
-                         int timeStep, int dim, int myRank) {
+                         int timeStep, int dim, int myRank, int nprocs) {
         double *coord;
         int iteration, i;
 	Particle_Index          num_particles = picswarm->particleLocalCount;
@@ -343,15 +345,16 @@
 /* Pressure is stored on cell centers, while everything else is stored
    on cell vertices.  So we have to make two different files, one for
    pressure, and one for everything else. */
-void VTKOutput_fields(void *context, int myRank) {
+void VTKOutput_fields(void *context, int myRank, int nprocs) {
   
   FiniteElementContext*     self = (FiniteElementContext*) context;
   Index var_I;
   int header_printed=0;
-  int nDims, pn;
+  int nDims, pn, i;
+  int nx, ny, nz, n, pnx, pny, pnz;
 
   Name field_filename, pressure_filename;
-  FILE *fp, *field_fp, *pressure_fp;
+  FILE *fp, *field_fp, *pressure_fp, *pfp, *pfield_fp, *ppressure_fp;
 
   /* Open the file */
 
@@ -364,6 +367,23 @@
   field_fp=fopen(field_filename,"w");
   pressure_fp=fopen(pressure_filename,"w");
 
+  Memory_Free( pressure_filename );
+  Memory_Free( field_filename );
+
+  /* Print out the parallel control files if rank==0 */
+  if(myRank==0)
+    {
+      Stg_asprintf( &pressure_filename, "%s/pressure.%05d.pvts",
+                    self->outputPath,
+                    self->timeStep);
+      Stg_asprintf( &field_filename, "%s/fields.%05d.pvts", self->outputPath,
+                    self->timeStep);
+      pfield_fp=fopen(field_filename,"w");
+      ppressure_fp=fopen(pressure_filename,"w");
+      Memory_Free( pressure_filename );
+      Memory_Free( field_filename );
+    }
+
   /* First, output the coordinates.  We have to do a huge song and
      dance just to get the extents of the mesh. */
 
@@ -380,7 +400,6 @@
       feVar=(FeVariable*)fieldVar;
       if(!header_printed)
         {
-          int nx, ny, nz, n, pnx, pny, pnz;
           Mesh *mesh;
           CartesianGenerator *gen;
 
@@ -425,11 +444,31 @@
   <StructuredGrid WholeExtent=\"0 %d 0 %d 0 %d\">\n\
     <Piece Extent=\"0 %d 0 %d 0 %d\">\n\
       <CellData></CellData>\n",pnx-1,pny-1,pnz-1,pnx-1,pny-1,pnz-1);
-          
-          /* Write the coordinates */
+
+          /* Write the coordinates for the fields, but not the pressure */
           VTKOutput_print_coords(field_fp, feVar->feMesh, nDims, n);
           fprintf(field_fp,"      <PointData Scalars=\"StrainRateInvariantField\" Vectors=\"VelocityField\" Tensors=\"Stress\">\n");
-
+          
+          /* Write out parallel control file headers. */
+          if(myRank==0)
+            {
+          fprintf(pfield_fp,"<?xml version=\"1.0\"?>\n\
+<VTKFile type=\"PStructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n\
+  <PStructuredGrid GhostLevel=\"0\" WholeExtent=\"0 %d 0 %d 0 %d\">\n\
+    <PCellData></PCellData>\n\
+    <PPoints>\n\
+      <PDataArray type=\"Float32\" NumberOfComponents=\"3\"/>\n\
+    </PPoints>\n\
+    <PPointData Scalars=\"StrainRateInvariantField\" Vectors=\"VelocityField\" Tensors=\"Stress\">\n",nx-1,ny-1,nz-1);
+          fprintf(ppressure_fp,"<?xml version=\"1.0\"?>\n\
+<VTKFile type=\"PStructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n\
+  <PStructuredGrid GhostLevel=\"0\" WholeExtent=\"0 %d 0 %d 0 %d\">\n\
+    <PCellData></PCellData>\n\
+    <PPoints>\n\
+      <PDataArray type=\"Float32\" NumberOfComponents=\"3\"/>\n\
+    </PPoints>\n\
+    <PPointData Scalars=\"Pressure\">\n",pnx-1,pny-1,pnz-1);
+            }
           header_printed=1;
         }
 
@@ -439,8 +478,10 @@
         VTKOutput_print_coords(pressure_fp, feVar->feMesh, nDims, pn);
         fprintf(pressure_fp,"      <PointData Scalars=\"Pressure\">\n");
         fp=pressure_fp;
+        pfp=ppressure_fp;
       } else {
         fp=field_fp;
+        pfp=pfield_fp;
       }
       
       /* Finally, output the fields.  For now, just output every field */
@@ -453,11 +494,15 @@
         case 2:
         case 3:
           fprintf(fp,"        <DataArray type=\"Float32\" Name=\"%s\" format=\"ascii\">\n",feVar->name);
+          if(myRank==0)
+            fprintf(pfp,"      <PDataArray type=\"Float32\" Name=\"%s\" format=\"ascii\"/>\n",feVar->name);
           break;
           /* Vectors */
         case 4:
         case 9:
           fprintf(fp,"        <DataArray type=\"Float32\" Name=\"%s\" format=\"ascii\" NumberOfComponents=\"3\">\n",feVar->name);
+          if(myRank==0)
+            fprintf(pfp,"      <PDataArray type=\"Float32\" Name=\"%s\" format=\"ascii\" NumberOfComponents=\"3\"/>\n",feVar->name);
           break;
           /* Rank 2 Tensors */
         case 6:
@@ -465,6 +510,8 @@
         case 18:
         case 27:
           fprintf(fp,"        <DataArray type=\"Float32\" Name=\"%s\" format=\"ascii\" NumberOfComponents=\"9\">\n",feVar->name);
+          if(myRank==0)
+            fprintf(pfp,"      <PDataArray type=\"Float32\" Name=\"%s\" format=\"ascii\" NumberOfComponents=\"9\"/>\n",feVar->name);
           break;
           /* Unknown */
         default:
@@ -527,8 +574,23 @@
   </StructuredGrid>\n\
 </VTKFile>\n");
   fclose(pressure_fp);
-  Memory_Free( pressure_filename );
   fclose(field_fp);
-  Memory_Free( field_filename );
+
+  fprintf(ppressure_fp,"      </PPointData>\n");
+  fprintf(pfield_fp,"      </PPointData>\n");
+  for(i=0;i<nprocs;++i)
+    {
+      fprintf(ppressure_fp,"    <Piece Extent=\"%d %d %d %d %d %d\"\n\
+             Source=\"pressure.%d.%05d.vts\"/>\n",0,pnx-1,0,pny-1,0,pnz-1,
+              i,self->timeStep);
+      fprintf(pfield_fp,"    <Piece Extent=\"%d %d %d %d %d %d\"\n\
+             Source=\"fields.%d.%05d.vts\"/>\n",0,nx-1,0,ny-1,0,nz-1,
+              i,self->timeStep);
+    }
+  fprintf(ppressure_fp,"  </PStructuredGrid>\n\
+</VTKFile>\n");
+  fprintf(pfield_fp,"  </PStructuredGrid>\n\
+</VTKFile>\n");
+
 }
      



More information about the cig-commits mailing list