/[escript]/branches/diaplayground/finley/src/CPPAdapter/MeshAdapter.cpp
ViewVC logotype

Diff of /branches/diaplayground/finley/src/CPPAdapter/MeshAdapter.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1346 by ksteube, Wed Nov 14 22:48:12 2007 UTC revision 1347 by ksteube, Fri Nov 16 05:37:07 2007 UTC
# Line 104  void MeshAdapter::Print_Mesh_Info(const Line 104  void MeshAdapter::Print_Mesh_Info(const
104  void MeshAdapter::dump(const std::string& fileName) const  void MeshAdapter::dump(const std::string& fileName) const
105  {  {
106  #ifdef USE_NETCDF  #ifdef USE_NETCDF
107     const NcDim* ncdims[25]; /* ksteube how big should ncdims be? */     const NcDim* ncdims[12];
108     NcVar *ids, *data;     NcVar *ids, *data;
109     int *int_ptr;     int *int_ptr;
110     Finley_Mesh *mesh = m_finleyMesh.get();     Finley_Mesh *mesh = m_finleyMesh.get();
111       Finley_TagMap* tag_map;
112       int num_Tags = 0;
113     int mpi_size             = mesh->MPIInfo->size;     int mpi_size             = mesh->MPIInfo->size;
114     int mpi_rank             = mesh->MPIInfo->rank;     int mpi_rank             = mesh->MPIInfo->rank;
115     int numDim               = mesh->Nodes->numDim;     int numDim               = mesh->Nodes->numDim;
# Line 121  void MeshAdapter::dump(const std::string Line 123  void MeshAdapter::dump(const std::string
123     int num_ContactElements_numNodes = mesh->ContactElements->numNodes;     int num_ContactElements_numNodes = mesh->ContactElements->numNodes;
124     char *newFileName = Paso_MPI_appendRankToFileName(strdup(fileName.c_str()), mpi_size, mpi_rank);     char *newFileName = Paso_MPI_appendRankToFileName(strdup(fileName.c_str()), mpi_size, mpi_rank);
125    
126       /* Figure out how much storage is required for tags */
127       tag_map = mesh->TagMap;
128       if (tag_map) {
129         while (tag_map) {
130        num_Tags++;
131            tag_map=tag_map->next;
132         }
133       }
134    
135     // NetCDF error handler     // NetCDF error handler
136     NcError err(NcError::verbose_nonfatal);     NcError err(NcError::verbose_nonfatal);
137     // Create the file.     // Create the file.
# Line 157  void MeshAdapter::dump(const std::string Line 168  void MeshAdapter::dump(const std::string
168     if (num_ContactElements>0)     if (num_ContactElements>0)
169        if (! (ncdims[9] = dataFile.add_dim("dim_ContactElements_numNodes", num_ContactElements_numNodes)) )        if (! (ncdims[9] = dataFile.add_dim("dim_ContactElements_numNodes", num_ContactElements_numNodes)) )
170          throw DataException("Error - MeshAdapter::dump: appending dimension dim_ContactElements_numNodes to netCDF file failed: " + *newFileName);          throw DataException("Error - MeshAdapter::dump: appending dimension dim_ContactElements_numNodes to netCDF file failed: " + *newFileName);
171       if (num_Tags>0)
172          if (! (ncdims[10] = dataFile.add_dim("dim_Tags", num_Tags)) )
173            throw DataException("Error - MeshAdapter::dump: appending dimension dim_Tags to netCDF file failed: " + *newFileName);
174    
175     // Attributes: MPI size, MPI rank, Name, order, reduced_order     // Attributes: MPI size, MPI rank, Name, order, reduced_order
176     if (!dataFile.add_att("mpi_size", mpi_size) )     if (!dataFile.add_att("mpi_size", mpi_size) )
# Line 187  void MeshAdapter::dump(const std::string Line 201  void MeshAdapter::dump(const std::string
201          throw DataException("Error - MeshAdapter::dump: appending num_FaceElements_numNodes to NetCDF file failed: " + *newFileName);          throw DataException("Error - MeshAdapter::dump: appending num_FaceElements_numNodes to NetCDF file failed: " + *newFileName);
202     if (!dataFile.add_att("num_ContactElements_numNodes",num_ContactElements_numNodes) )     if (!dataFile.add_att("num_ContactElements_numNodes",num_ContactElements_numNodes) )
203          throw DataException("Error - MeshAdapter::dump: appending num_ContactElements_numNodes to NetCDF file failed: " + *newFileName);          throw DataException("Error - MeshAdapter::dump: appending num_ContactElements_numNodes to NetCDF file failed: " + *newFileName);
204       if (!dataFile.add_att("Elements_TypeId", mesh->Elements->ReferenceElement->Type->TypeId) )
205          throw DataException("Error - MeshAdapter::dump: appending Elements_TypeId to NetCDF file failed: " + *newFileName);
206       if (!dataFile.add_att("FaceElements_TypeId", mesh->FaceElements->ReferenceElement->Type->TypeId) )
207          throw DataException("Error - MeshAdapter::dump: appending FaceElements_TypeId to NetCDF file failed: " + *newFileName);
208       if (!dataFile.add_att("ContactElements_TypeId", mesh->ContactElements->ReferenceElement->Type->TypeId) )
209          throw DataException("Error - MeshAdapter::dump: appending ContactElements_TypeId to NetCDF file failed: " + *newFileName);
210       if (!dataFile.add_att("Points_TypeId", mesh->Points->ReferenceElement->Type->TypeId) )
211          throw DataException("Error - MeshAdapter::dump: appending Points_TypeId to NetCDF file failed: " + *newFileName);
212       if (!dataFile.add_att("num_Tags", num_Tags) )
213          throw DataException("Error - MeshAdapter::dump: appending num_Tags to NetCDF file failed: " + *newFileName);
214    
215     // // // // // Nodes // // // // //     // // // // // Nodes // // // // //
216    
# Line 257  void MeshAdapter::dump(const std::string Line 281  void MeshAdapter::dump(const std::string
281       // Temp storage to gather node IDs       // Temp storage to gather node IDs
282       int *Elements_Nodes = TMPMEMALLOC(num_Elements*num_Elements_numNodes,int);       int *Elements_Nodes = TMPMEMALLOC(num_Elements*num_Elements_numNodes,int);
283    
      // Elements ReferenceElement->ElementTypeId  
      if (!dataFile.add_att("Elements_TypeId", mesh->Elements->ReferenceElement->Type->TypeId) )  
         throw DataException("Error - MeshAdapter::dump: appending Elements_TypeId to NetCDF file failed: " + *newFileName);  
   
284       // Elements_Id       // Elements_Id
285       if (! ( ids = dataFile.add_var("Elements_Id", ncInt, ncdims[3])) )       if (! ( ids = dataFile.add_var("Elements_Id", ncInt, ncdims[3])) )
286          throw DataException("Error - MeshAdapter::dump: appending Elements_Id to netCDF file failed: " + *newFileName);          throw DataException("Error - MeshAdapter::dump: appending Elements_Id to netCDF file failed: " + *newFileName);
# Line 309  void MeshAdapter::dump(const std::string Line 329  void MeshAdapter::dump(const std::string
329       // Temp storage to gather node IDs       // Temp storage to gather node IDs
330       int *FaceElements_Nodes = TMPMEMALLOC(num_FaceElements*num_FaceElements_numNodes,int);       int *FaceElements_Nodes = TMPMEMALLOC(num_FaceElements*num_FaceElements_numNodes,int);
331    
      // FaceElements ReferenceElement->ElementTypeId  
      if (!dataFile.add_att("FaceElements_TypeId", mesh->FaceElements->ReferenceElement->Type->TypeId) )  
         throw DataException("Error - MeshAdapter::dump: appending FaceElements_TypeId to NetCDF file failed: " + *newFileName);  
   
332       // FaceElements_Id       // FaceElements_Id
333       if (! ( ids = dataFile.add_var("FaceElements_Id", ncInt, ncdims[4])) )       if (! ( ids = dataFile.add_var("FaceElements_Id", ncInt, ncdims[4])) )
334          throw DataException("Error - MeshAdapter::dump: appending FaceElements_Id to netCDF file failed: " + *newFileName);          throw DataException("Error - MeshAdapter::dump: appending FaceElements_Id to netCDF file failed: " + *newFileName);
# Line 361  void MeshAdapter::dump(const std::string Line 377  void MeshAdapter::dump(const std::string
377       // Temp storage to gather node IDs       // Temp storage to gather node IDs
378       int *ContactElements_Nodes = TMPMEMALLOC(num_ContactElements*num_ContactElements_numNodes,int);       int *ContactElements_Nodes = TMPMEMALLOC(num_ContactElements*num_ContactElements_numNodes,int);
379    
      // ContactElements ReferenceElement->ElementTypeId  
      if (!dataFile.add_att("ContactElements_TypeId", mesh->ContactElements->ReferenceElement->Type->TypeId) )  
         throw DataException("Error - MeshAdapter::dump: appending ContactElements_TypeId to NetCDF file failed: " + *newFileName);  
   
380       // ContactElements_Id       // ContactElements_Id
381       if (! ( ids = dataFile.add_var("ContactElements_Id", ncInt, ncdims[5])) )       if (! ( ids = dataFile.add_var("ContactElements_Id", ncInt, ncdims[5])) )
382          throw DataException("Error - MeshAdapter::dump: appending ContactElements_Id to netCDF file failed: " + *newFileName);          throw DataException("Error - MeshAdapter::dump: appending ContactElements_Id to netCDF file failed: " + *newFileName);
# Line 415  void MeshAdapter::dump(const std::string Line 427  void MeshAdapter::dump(const std::string
427       // Temp storage to gather node IDs       // Temp storage to gather node IDs
428       int *Points_Nodes = TMPMEMALLOC(num_Points,int);       int *Points_Nodes = TMPMEMALLOC(num_Points,int);
429    
      // Points ReferenceElement->ElementTypeId  
      if (!dataFile.add_att("Points_TypeId", mesh->Points->ReferenceElement->Type->TypeId) )  
         throw DataException("Error - MeshAdapter::dump: appending Points_TypeId to NetCDF file failed: " + *newFileName);  
   
430       // Points_Id       // Points_Id
431       if (! ( ids = dataFile.add_var("Points_Id", ncInt, ncdims[6])) )       if (! ( ids = dataFile.add_var("Points_Id", ncInt, ncdims[6])) )
432          throw DataException("Error - MeshAdapter::dump: appending Points_Id to netCDF file failed: " + *newFileName);          throw DataException("Error - MeshAdapter::dump: appending Points_Id to netCDF file failed: " + *newFileName);
# Line 462  void MeshAdapter::dump(const std::string Line 470  void MeshAdapter::dump(const std::string
470    
471     // // // // // TagMap // // // // //     // // // // // TagMap // // // // //
472    
473       fprintf(stderr, "\n\n\nWARNING: MeshAdapter::dump does not save the TagMap yet\n\n\n");     if (num_Tags>0) {
474    
475         // Temp storage to gather node IDs
476         int *Tags_keys = TMPMEMALLOC(num_Tags, int);
477         char name_temp[4096];
478    
479         /* Copy tag data into temp arrays */
480         tag_map = mesh->TagMap;
481         if (tag_map) {
482           int i = 0;
483           while (tag_map) {
484        Tags_keys[i++] = tag_map->tag_key;
485            tag_map=tag_map->next;
486           }
487         }
488    
489         // Tags_keys
490         if (! ( ids = dataFile.add_var("Tags_keys", ncInt, ncdims[10])) )
491            throw DataException("Error - MeshAdapter::dump: appending Tags_keys to netCDF file failed: " + *newFileName);
492         int_ptr = &Tags_keys[0];
493         if (! (ids->put(int_ptr, num_Tags)) )
494            throw DataException("Error - MeshAdapter::dump: copy Tags_keys to netCDF buffer failed: " + *newFileName);
495    
496         // Tags_names_*
497         // This is an array of strings, it should be stored as an array but instead I have hacked in one attribute per string
498         // because the NetCDF manual doesn't tell how to do an array of strings
499         tag_map = mesh->TagMap;
500         if (tag_map) {
501           int i = 0;
502           while (tag_map) {
503             sprintf(name_temp, "Tags_name_%d", i);
504             if (!dataFile.add_att(name_temp, tag_map->name) )
505               throw DataException("Error - MeshAdapter::dump: appending Tags_names_ to NetCDF file failed: " + *newFileName);
506             tag_map=tag_map->next;
507         i++;
508           }
509         }
510    
511         TMPMEMFREE(Tags_keys);
512    
513       }
514    
515    
516     // NetCDF file is closed by destructor of NcFile object     // NetCDF file is closed by destructor of NcFile object
517  #else  #else

Legend:
Removed from v.1346  
changed lines
  Added in v.1347

  ViewVC Help
Powered by ViewVC 1.1.26