/[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 1632 by trankine, Sat Jul 12 07:17:50 2008 UTC revision 1777 by ksteube, Tue Sep 9 06:39:37 2008 UTC
# Line 124  void MeshAdapter::dump(const std::string Line 124  void MeshAdapter::dump(const std::string
124     int num_FaceElements_numNodes    = mesh->FaceElements->numNodes;     int num_FaceElements_numNodes    = mesh->FaceElements->numNodes;
125     int num_ContactElements_numNodes = mesh->ContactElements->numNodes;     int num_ContactElements_numNodes = mesh->ContactElements->numNodes;
126    
    // I don't think the strdup is needed since Paso_MPI_appendRankToFileName  
    // does it's own allocation.  
    // char *newFileName = Paso_MPI_appendRankToFileName(strdup(fileName.c_str()), mpi_size, mpi_rank);  
   
127     char *newFileName = Paso_MPI_appendRankToFileName(fileName.c_str(),     char *newFileName = Paso_MPI_appendRankToFileName(fileName.c_str(),
128                                                       mpi_size, mpi_rank);                                                       mpi_size, mpi_rank);
129    
# Line 280  void MeshAdapter::dump(const std::string Line 276  void MeshAdapter::dump(const std::string
276        if (! (ids->put(int_ptr, mpi_size+1)) )        if (! (ids->put(int_ptr, mpi_size+1)) )
277           throw DataException("Error - MeshAdapter::dump: copy Nodes_DofDistribution to netCDF buffer failed: " + *newFileName);           throw DataException("Error - MeshAdapter::dump: copy Nodes_DofDistribution to netCDF buffer failed: " + *newFileName);
278    
279          // Nodes nodeDistribution
280          if (! ( ids = dataFile.add_var("Nodes_NodeDistribution", ncInt, ncdims[2])) )
281             throw DataException("Error - MeshAdapter::dump: appending Nodes_NodeDistribution to netCDF file failed: " + *newFileName);
282          int_ptr = &mesh->Nodes->nodesDistribution->first_component[0];
283          if (! (ids->put(int_ptr, mpi_size+1)) )
284             throw DataException("Error - MeshAdapter::dump: copy Nodes_NodeDistribution to netCDF buffer failed: " + *newFileName);
285    
286     }     }
287    
288     // // // // // Elements // // // // //     // // // // // Elements // // // // //
289    
290     if (num_Elements>0) {     if (num_Elements>0) {
291    
       // Temp storage to gather node IDs  
       int *Elements_Nodes = TMPMEMALLOC(num_Elements*num_Elements_numNodes,int);  
   
292        // Elements_Id        // Elements_Id
293        if (! ( ids = dataFile.add_var("Elements_Id", ncInt, ncdims[3])) )        if (! ( ids = dataFile.add_var("Elements_Id", ncInt, ncdims[3])) )
294           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 318  void MeshAdapter::dump(const std::string Line 318  void MeshAdapter::dump(const std::string
318           throw DataException("Error - MeshAdapter::dump: copy Elements_Color to netCDF buffer failed: " + *newFileName);           throw DataException("Error - MeshAdapter::dump: copy Elements_Color to netCDF buffer failed: " + *newFileName);
319    
320        // Elements_Nodes        // Elements_Nodes
       for (int i=0; i<num_Elements; i++)  
          for (int j=0; j<num_Elements_numNodes; j++)  
             Elements_Nodes[INDEX2(j,i,num_Elements_numNodes)] = mesh->Nodes->Id[mesh->Elements->Nodes[INDEX2(j,i,num_Elements_numNodes)]];  
321        if (! ( ids = dataFile.add_var("Elements_Nodes", ncInt, ncdims[3], ncdims[7]) ) )        if (! ( ids = dataFile.add_var("Elements_Nodes", ncInt, ncdims[3], ncdims[7]) ) )
322           throw DataException("Error - MeshAdapter::dump: appending Elements_Nodes to netCDF file failed: " + *newFileName);           throw DataException("Error - MeshAdapter::dump: appending Elements_Nodes to netCDF file failed: " + *newFileName);
323        if (! (ids->put(&(Elements_Nodes[0]), num_Elements, num_Elements_numNodes)) )        if (! (ids->put(&(mesh->Elements->Nodes[0]), num_Elements, num_Elements_numNodes)) )
324           throw DataException("Error - MeshAdapter::dump: copy Elements_Nodes to netCDF buffer failed: " + *newFileName);           throw DataException("Error - MeshAdapter::dump: copy Elements_Nodes to netCDF buffer failed: " + *newFileName);
325    
       TMPMEMFREE(Elements_Nodes);  
   
326     }     }
327    
328     // // // // // Face_Elements // // // // //     // // // // // Face_Elements // // // // //
329    
330     if (num_FaceElements>0) {     if (num_FaceElements>0) {
331    
       // Temp storage to gather node IDs  
       int *FaceElements_Nodes = TMPMEMALLOC(num_FaceElements*num_FaceElements_numNodes,int);  
   
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 366  void MeshAdapter::dump(const std::string Line 358  void MeshAdapter::dump(const std::string
358           throw DataException("Error - MeshAdapter::dump: copy FaceElements_Color to netCDF buffer failed: " + *newFileName);           throw DataException("Error - MeshAdapter::dump: copy FaceElements_Color to netCDF buffer failed: " + *newFileName);
359    
360        // FaceElements_Nodes        // FaceElements_Nodes
       for (int i=0; i<num_FaceElements; i++)  
          for (int j=0; j<num_FaceElements_numNodes; j++)  
             FaceElements_Nodes[INDEX2(j,i,num_FaceElements_numNodes)] = mesh->Nodes->Id[mesh->FaceElements->Nodes[INDEX2(j,i,num_FaceElements_numNodes)]];  
361        if (! ( ids = dataFile.add_var("FaceElements_Nodes", ncInt, ncdims[4], ncdims[8]) ) )        if (! ( ids = dataFile.add_var("FaceElements_Nodes", ncInt, ncdims[4], ncdims[8]) ) )
362           throw DataException("Error - MeshAdapter::dump: appending FaceElements_Nodes to netCDF file failed: " + *newFileName);           throw DataException("Error - MeshAdapter::dump: appending FaceElements_Nodes to netCDF file failed: " + *newFileName);
363        if (! (ids->put(&(FaceElements_Nodes[0]), num_FaceElements, num_FaceElements_numNodes)) )        if (! (ids->put(&(mesh->FaceElements->Nodes[0]), num_FaceElements, num_FaceElements_numNodes)) )
364           throw DataException("Error - MeshAdapter::dump: copy FaceElements_Nodes to netCDF buffer failed: " + *newFileName);           throw DataException("Error - MeshAdapter::dump: copy FaceElements_Nodes to netCDF buffer failed: " + *newFileName);
365    
       TMPMEMFREE(FaceElements_Nodes);  
   
366     }     }
367    
368     // // // // // Contact_Elements // // // // //     // // // // // Contact_Elements // // // // //
369    
370     if (num_ContactElements>0) {     if (num_ContactElements>0) {
371    
       // Temp storage to gather node IDs  
       int *ContactElements_Nodes = TMPMEMALLOC(num_ContactElements*num_ContactElements_numNodes,int);  
   
372        // ContactElements_Id        // ContactElements_Id
373        if (! ( ids = dataFile.add_var("ContactElements_Id", ncInt, ncdims[5])) )        if (! ( ids = dataFile.add_var("ContactElements_Id", ncInt, ncdims[5])) )
374           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 414  void MeshAdapter::dump(const std::string Line 398  void MeshAdapter::dump(const std::string
398           throw DataException("Error - MeshAdapter::dump: copy ContactElements_Color to netCDF buffer failed: " + *newFileName);           throw DataException("Error - MeshAdapter::dump: copy ContactElements_Color to netCDF buffer failed: " + *newFileName);
399    
400        // ContactElements_Nodes        // ContactElements_Nodes
       for (int i=0; i<num_ContactElements; i++)  
          for (int j=0; j<num_ContactElements_numNodes; j++)  
             ContactElements_Nodes[INDEX2(j,i,num_ContactElements_numNodes)] = mesh->Nodes->Id[mesh->ContactElements->Nodes[INDEX2(j,i,num_ContactElements_numNodes)]];  
401        if (! ( ids = dataFile.add_var("ContactElements_Nodes", ncInt, ncdims[5], ncdims[9]) ) )        if (! ( ids = dataFile.add_var("ContactElements_Nodes", ncInt, ncdims[5], ncdims[9]) ) )
402           throw DataException("Error - MeshAdapter::dump: appending ContactElements_Nodes to netCDF file failed: " + *newFileName);           throw DataException("Error - MeshAdapter::dump: appending ContactElements_Nodes to netCDF file failed: " + *newFileName);
403        if (! (ids->put(&(ContactElements_Nodes[0]), num_ContactElements, num_ContactElements_numNodes)) )        if (! (ids->put(&(mesh->ContactElements->Nodes[0]), num_ContactElements, num_ContactElements_numNodes)) )
404           throw DataException("Error - MeshAdapter::dump: copy ContactElements_Nodes to netCDF buffer failed: " + *newFileName);           throw DataException("Error - MeshAdapter::dump: copy ContactElements_Nodes to netCDF buffer failed: " + *newFileName);
405    
       TMPMEMFREE(ContactElements_Nodes);  
   
406     }     }
407    
408     // // // // // Points // // // // //     // // // // // Points // // // // //
# Line 432  void MeshAdapter::dump(const std::string Line 411  void MeshAdapter::dump(const std::string
411    
412        fprintf(stderr, "\n\n\nWARNING: MeshAdapter::dump has not been tested with Point elements\n\n\n");        fprintf(stderr, "\n\n\nWARNING: MeshAdapter::dump has not been tested with Point elements\n\n\n");
413    
       // Temp storage to gather node IDs  
       int *Points_Nodes = TMPMEMALLOC(num_Points,int);  
   
414        // Points_Id        // Points_Id
415        if (! ( ids = dataFile.add_var("Points_Id", ncInt, ncdims[6])) )        if (! ( ids = dataFile.add_var("Points_Id", ncInt, ncdims[6])) )
416           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 465  void MeshAdapter::dump(const std::string Line 441  void MeshAdapter::dump(const std::string
441    
442        // Points_Nodes        // Points_Nodes
443        // mesh->Nodes->Id[mesh->Points->Nodes[INDEX2(0,i,1)]]        // mesh->Nodes->Id[mesh->Points->Nodes[INDEX2(0,i,1)]]
       for (int i=0; i<num_Points; i++)  
          Points_Nodes[i] = mesh->Nodes->Id[mesh->Points->Nodes[INDEX2(0,i,1)]];  
444        if (! ( ids = dataFile.add_var("Points_Nodes", ncInt, ncdims[6]) ) )        if (! ( ids = dataFile.add_var("Points_Nodes", ncInt, ncdims[6]) ) )
445           throw DataException("Error - MeshAdapter::dump: appending Points_Nodes to netCDF file failed: " + *newFileName);           throw DataException("Error - MeshAdapter::dump: appending Points_Nodes to netCDF file failed: " + *newFileName);
446        if (! (ids->put(&(Points_Nodes[0]), num_Points)) )        if (! (ids->put(&(mesh->Points->Nodes[0]), num_Points)) )
447           throw DataException("Error - MeshAdapter::dump: copy Points_Nodes to netCDF buffer failed: " + *newFileName);           throw DataException("Error - MeshAdapter::dump: copy Points_Nodes to netCDF buffer failed: " + *newFileName);
448    
       TMPMEMFREE(Points_Nodes);  
   
449     }     }
450    
451     // // // // // TagMap // // // // //     // // // // // TagMap // // // // //
# Line 652  int MeshAdapter::getDim() const Line 624  int MeshAdapter::getDim() const
624  }  }
625    
626  //  //
627    // Return the number of data points summed across all MPI processes
628    //
629    int MeshAdapter::getNumDataPointsGlobal() const
630    {
631       return Finley_NodeFile_getGlobalNumNodes(m_finleyMesh.get()->Nodes);
632    }
633    
634    //
635  // return the number of data points per sample and the number of samples  // return the number of data points per sample and the number of samples
636  // needed to represent data on a parts of the mesh.  // needed to represent data on a parts of the mesh.
637  //  //
# Line 2047  std::string MeshAdapter::showTagNames() Line 2027  std::string MeshAdapter::showTagNames()
2027     return temp.str();     return temp.str();
2028  }  }
2029    
2030    int MeshAdapter::getNumberOfTagsInUse(int functionSpaceCode) const
2031    {
2032      Finley_Mesh* mesh=m_finleyMesh.get();
2033      dim_t numTags=0;
2034      switch(functionSpaceCode) {
2035       case(Nodes):
2036              numTags=mesh->Nodes->numTagsInUse;
2037              break;
2038       case(ReducedNodes):
2039              throw FinleyAdapterException("Error - ReducedNodes does not support tags");
2040              break;
2041       case(DegreesOfFreedom):
2042              throw FinleyAdapterException("Error - DegreesOfFreedom does not support tags");
2043              break;
2044       case(ReducedDegreesOfFreedom):
2045              throw FinleyAdapterException("Error - ReducedDegreesOfFreedom does not support tags");
2046              break;
2047       case(Elements):
2048       case(ReducedElements):
2049              numTags=mesh->Elements->numTagsInUse;
2050              break;
2051       case(FaceElements):
2052       case(ReducedFaceElements):
2053              numTags=mesh->FaceElements->numTagsInUse;
2054              break;
2055       case(Points):
2056              numTags=mesh->Points->numTagsInUse;
2057              break;
2058       case(ContactElementsZero):
2059       case(ReducedContactElementsZero):
2060       case(ContactElementsOne):
2061       case(ReducedContactElementsOne):
2062              numTags=mesh->ContactElements->numTagsInUse;
2063              break;
2064       default:
2065          stringstream temp;
2066          temp << "Error - Finley does not know anything about function space type " << functionSpaceCode;
2067          throw FinleyAdapterException(temp.str());
2068      }
2069      return numTags;
2070    }
2071    int* MeshAdapter::borrowListOfTagsInUse(int functionSpaceCode) const
2072    {
2073      Finley_Mesh* mesh=m_finleyMesh.get();
2074      index_t* tags=NULL;
2075      switch(functionSpaceCode) {
2076       case(Nodes):
2077              tags=mesh->Nodes->tagsInUse;
2078              break;
2079       case(ReducedNodes):
2080              throw FinleyAdapterException("Error - ReducedNodes does not support tags");
2081              break;
2082       case(DegreesOfFreedom):
2083              throw FinleyAdapterException("Error - DegreesOfFreedom does not support tags");
2084              break;
2085       case(ReducedDegreesOfFreedom):
2086              throw FinleyAdapterException("Error - ReducedDegreesOfFreedom does not support tags");
2087              break;
2088       case(Elements):
2089       case(ReducedElements):
2090              tags=mesh->Elements->tagsInUse;
2091              break;
2092       case(FaceElements):
2093       case(ReducedFaceElements):
2094              tags=mesh->FaceElements->tagsInUse;
2095              break;
2096       case(Points):
2097              tags=mesh->Points->tagsInUse;
2098              break;
2099       case(ContactElementsZero):
2100       case(ReducedContactElementsZero):
2101       case(ContactElementsOne):
2102       case(ReducedContactElementsOne):
2103              tags=mesh->ContactElements->tagsInUse;
2104              break;
2105       default:
2106          stringstream temp;
2107          temp << "Error - Finley does not know anything about function space type " << functionSpaceCode;
2108          throw FinleyAdapterException(temp.str());
2109      }
2110      return tags;
2111    }
2112    
2113    
2114  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.1632  
changed lines
  Added in v.1777

  ViewVC Help
Powered by ViewVC 1.1.26