/[escript]/branches/domexper/dudley/src/CPPAdapter/MeshAdapter.cpp
ViewVC logotype

Diff of /branches/domexper/dudley/src/CPPAdapter/MeshAdapter.cpp

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

revision 1628 by phornby, Fri Jul 11 13:12:46 2008 UTC revision 1800 by ksteube, Thu Sep 18 05:28:20 2008 UTC
# Line 19  Line 19 
19  #ifdef USE_NETCDF  #ifdef USE_NETCDF
20  #include <netcdfcpp.h>  #include <netcdfcpp.h>
21  #endif  #endif
22    #ifdef PASO_MPI
23    #include <mpi.h>
24    #include "paso/Paso_MPI.h"
25    #endif
26  extern "C" {  extern "C" {
27  #include "escript/blocktimer.h"  #include "escript/blocktimer.h"
28  }  }
# Line 83  int MeshAdapter::getMPIRank() const Line 87  int MeshAdapter::getMPIRank() const
87  {  {
88     return m_finleyMesh.get()->MPIInfo->rank;     return m_finleyMesh.get()->MPIInfo->rank;
89  }  }
90    MPI_Comm MeshAdapter::getMPIComm() const
91    {
92       return m_finleyMesh.get()->MPIInfo->comm;
93    }
94    
95    
96  Finley_Mesh* MeshAdapter::getFinley_Mesh() const {  Finley_Mesh* MeshAdapter::getFinley_Mesh() const {
# Line 107  void MeshAdapter::dump(const std::string Line 115  void MeshAdapter::dump(const std::string
115  {  {
116  #ifdef USE_NETCDF  #ifdef USE_NETCDF
117     const NcDim* ncdims[12];     const NcDim* ncdims[12];
118     NcVar *ids, *data;     NcVar *ids;
119     int *int_ptr;     int *int_ptr;
120     Finley_Mesh *mesh = m_finleyMesh.get();     Finley_Mesh *mesh = m_finleyMesh.get();
121     Finley_TagMap* tag_map;     Finley_TagMap* tag_map;
# Line 123  void MeshAdapter::dump(const std::string Line 131  void MeshAdapter::dump(const std::string
131     int num_Elements_numNodes        = mesh->Elements->numNodes;     int num_Elements_numNodes        = mesh->Elements->numNodes;
132     int num_FaceElements_numNodes    = mesh->FaceElements->numNodes;     int num_FaceElements_numNodes    = mesh->FaceElements->numNodes;
133     int num_ContactElements_numNodes = mesh->ContactElements->numNodes;     int num_ContactElements_numNodes = mesh->ContactElements->numNodes;
134    #ifdef PASO_MPI
135       MPI_Status status;
136    #endif
137    
138     // I don't think the strdup is needed since Paso_MPI_appendRankToFileName  /* Incoming token indicates it's my turn to write */
139     // does it's own allocation.  #ifdef PASO_MPI
140     // char *newFileName = Paso_MPI_appendRankToFileName(strdup(fileName.c_str()), mpi_size, mpi_rank);     if (mpi_rank>0) MPI_Recv(&num_Tags, 0, MPI_INT, mpi_rank-1, 81800, mesh->MPIInfo->comm, &status);
141    #endif
142    
143     char *newFileName = Paso_MPI_appendRankToFileName(fileName.c_str(),     char *newFileName = Paso_MPI_appendRankToFileName(fileName.c_str(),
144                                                       mpi_size, mpi_rank);                                                       mpi_size, mpi_rank);
145    
146     /* Figure out how much storage is required for tags */     /* Figure out how much storage is required for tags */
147     tag_map = mesh->TagMap;     tag_map = mesh->TagMap;
148       num_Tags = 0;
149     if (tag_map) {     if (tag_map) {
150        while (tag_map) {        while (tag_map) {
151           num_Tags++;           num_Tags++;
# Line 280  void MeshAdapter::dump(const std::string Line 293  void MeshAdapter::dump(const std::string
293        if (! (ids->put(int_ptr, mpi_size+1)) )        if (! (ids->put(int_ptr, mpi_size+1)) )
294           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);
295    
296          // Nodes nodeDistribution
297          if (! ( ids = dataFile.add_var("Nodes_NodeDistribution", ncInt, ncdims[2])) )
298             throw DataException("Error - MeshAdapter::dump: appending Nodes_NodeDistribution to netCDF file failed: " + *newFileName);
299          int_ptr = &mesh->Nodes->nodesDistribution->first_component[0];
300          if (! (ids->put(int_ptr, mpi_size+1)) )
301             throw DataException("Error - MeshAdapter::dump: copy Nodes_NodeDistribution to netCDF buffer failed: " + *newFileName);
302    
303     }     }
304    
305     // // // // // Elements // // // // //     // // // // // Elements // // // // //
306    
307     if (num_Elements>0) {     if (num_Elements>0) {
308    
       // Temp storage to gather node IDs  
       int *Elements_Nodes = TMPMEMALLOC(num_Elements*num_Elements_numNodes,int);  
   
309        // Elements_Id        // Elements_Id
310        if (! ( ids = dataFile.add_var("Elements_Id", ncInt, ncdims[3])) )        if (! ( ids = dataFile.add_var("Elements_Id", ncInt, ncdims[3])) )
311           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 335  void MeshAdapter::dump(const std::string
335           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);
336    
337        // 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)]];  
338        if (! ( ids = dataFile.add_var("Elements_Nodes", ncInt, ncdims[3], ncdims[7]) ) )        if (! ( ids = dataFile.add_var("Elements_Nodes", ncInt, ncdims[3], ncdims[7]) ) )
339           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);
340        if (! (ids->put(&(Elements_Nodes[0]), num_Elements, num_Elements_numNodes)) )        if (! (ids->put(&(mesh->Elements->Nodes[0]), num_Elements, num_Elements_numNodes)) )
341           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);
342    
       TMPMEMFREE(Elements_Nodes);  
   
343     }     }
344    
345     // // // // // Face_Elements // // // // //     // // // // // Face_Elements // // // // //
346    
347     if (num_FaceElements>0) {     if (num_FaceElements>0) {
348    
       // Temp storage to gather node IDs  
       int *FaceElements_Nodes = TMPMEMALLOC(num_FaceElements*num_FaceElements_numNodes,int);  
   
349        // FaceElements_Id        // FaceElements_Id
350        if (! ( ids = dataFile.add_var("FaceElements_Id", ncInt, ncdims[4])) )        if (! ( ids = dataFile.add_var("FaceElements_Id", ncInt, ncdims[4])) )
351           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 375  void MeshAdapter::dump(const std::string
375           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);
376    
377        // 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)]];  
378        if (! ( ids = dataFile.add_var("FaceElements_Nodes", ncInt, ncdims[4], ncdims[8]) ) )        if (! ( ids = dataFile.add_var("FaceElements_Nodes", ncInt, ncdims[4], ncdims[8]) ) )
379           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);
380        if (! (ids->put(&(FaceElements_Nodes[0]), num_FaceElements, num_FaceElements_numNodes)) )        if (! (ids->put(&(mesh->FaceElements->Nodes[0]), num_FaceElements, num_FaceElements_numNodes)) )
381           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);
382    
       TMPMEMFREE(FaceElements_Nodes);  
   
383     }     }
384    
385     // // // // // Contact_Elements // // // // //     // // // // // Contact_Elements // // // // //
386    
387     if (num_ContactElements>0) {     if (num_ContactElements>0) {
388    
       // Temp storage to gather node IDs  
       int *ContactElements_Nodes = TMPMEMALLOC(num_ContactElements*num_ContactElements_numNodes,int);  
   
389        // ContactElements_Id        // ContactElements_Id
390        if (! ( ids = dataFile.add_var("ContactElements_Id", ncInt, ncdims[5])) )        if (! ( ids = dataFile.add_var("ContactElements_Id", ncInt, ncdims[5])) )
391           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 415  void MeshAdapter::dump(const std::string
415           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);
416    
417        // 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)]];  
418        if (! ( ids = dataFile.add_var("ContactElements_Nodes", ncInt, ncdims[5], ncdims[9]) ) )        if (! ( ids = dataFile.add_var("ContactElements_Nodes", ncInt, ncdims[5], ncdims[9]) ) )
419           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);
420        if (! (ids->put(&(ContactElements_Nodes[0]), num_ContactElements, num_ContactElements_numNodes)) )        if (! (ids->put(&(mesh->ContactElements->Nodes[0]), num_ContactElements, num_ContactElements_numNodes)) )
421           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);
422    
       TMPMEMFREE(ContactElements_Nodes);  
   
423     }     }
424    
425     // // // // // Points // // // // //     // // // // // Points // // // // //
# Line 432  void MeshAdapter::dump(const std::string Line 428  void MeshAdapter::dump(const std::string
428    
429        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");
430    
       // Temp storage to gather node IDs  
       int *Points_Nodes = TMPMEMALLOC(num_Points,int);  
   
431        // Points_Id        // Points_Id
432        if (! ( ids = dataFile.add_var("Points_Id", ncInt, ncdims[6])) )        if (! ( ids = dataFile.add_var("Points_Id", ncInt, ncdims[6])) )
433           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 458  void MeshAdapter::dump(const std::string
458    
459        // Points_Nodes        // Points_Nodes
460        // 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)]];  
461        if (! ( ids = dataFile.add_var("Points_Nodes", ncInt, ncdims[6]) ) )        if (! ( ids = dataFile.add_var("Points_Nodes", ncInt, ncdims[6]) ) )
462           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);
463        if (! (ids->put(&(Points_Nodes[0]), num_Points)) )        if (! (ids->put(&(mesh->Points->Nodes[0]), num_Points)) )
464           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);
465    
       TMPMEMFREE(Points_Nodes);  
   
466     }     }
467    
468     // // // // // TagMap // // // // //     // // // // // TagMap // // // // //
# Line 520  void MeshAdapter::dump(const std::string Line 509  void MeshAdapter::dump(const std::string
509    
510     }     }
511    
512    /* Send token to next MPI process so he can take his turn */
513    #ifdef PASO_MPI
514       if (mpi_rank<mpi_size-1) MPI_Send(&num_Tags, 0, MPI_INT, mpi_rank+1, 81800, mesh->MPIInfo->comm);
515    #endif
516    
517     // NetCDF file is closed by destructor of NcFile object     // NetCDF file is closed by destructor of NcFile object
518    
519  #else  #else
520     Finley_setError(IO_ERROR, "MeshAdapter::dump: not configured with NetCDF. Please contact your installation manager.");     Finley_setError(IO_ERROR, "MeshAdapter::dump: not configured with NetCDF. Please contact your installation manager.");
521  #endif  /* USE_NETCDF */  #endif  /* USE_NETCDF */
# Line 652  int MeshAdapter::getDim() const Line 646  int MeshAdapter::getDim() const
646  }  }
647    
648  //  //
649    // Return the number of data points summed across all MPI processes
650    //
651    int MeshAdapter::getNumDataPointsGlobal() const
652    {
653       return Finley_NodeFile_getGlobalNumNodes(m_finleyMesh.get()->Nodes);
654    }
655    
656    //
657  // 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
658  // needed to represent data on a parts of the mesh.  // needed to represent data on a parts of the mesh.
659  //  //
# Line 827  void MeshAdapter::addPDEToTransportProbl Line 829  void MeshAdapter::addPDEToTransportProbl
829                                             const escript::Data& d, const escript::Data& y,                                             const escript::Data& d, const escript::Data& y,
830                                             const escript::Data& d_contact,const escript::Data& y_contact) const                                             const escript::Data& d_contact,const escript::Data& y_contact) const
831  {  {
832     DataArrayView::ShapeType shape;     DataTypes::ShapeType shape;
833     source.expand();     source.expand();
834     escriptDataC _source=source.getDataC();     escriptDataC _source=source.getDataC();
835     escriptDataC _M=M.getDataC();     escriptDataC _M=M.getDataC();
# Line 2047  std::string MeshAdapter::showTagNames() Line 2049  std::string MeshAdapter::showTagNames()
2049     return temp.str();     return temp.str();
2050  }  }
2051    
2052    int MeshAdapter::getNumberOfTagsInUse(int functionSpaceCode) const
2053    {
2054      Finley_Mesh* mesh=m_finleyMesh.get();
2055      dim_t numTags=0;
2056      switch(functionSpaceCode) {
2057       case(Nodes):
2058              numTags=mesh->Nodes->numTagsInUse;
2059              break;
2060       case(ReducedNodes):
2061              throw FinleyAdapterException("Error - ReducedNodes does not support tags");
2062              break;
2063       case(DegreesOfFreedom):
2064              throw FinleyAdapterException("Error - DegreesOfFreedom does not support tags");
2065              break;
2066       case(ReducedDegreesOfFreedom):
2067              throw FinleyAdapterException("Error - ReducedDegreesOfFreedom does not support tags");
2068              break;
2069       case(Elements):
2070       case(ReducedElements):
2071              numTags=mesh->Elements->numTagsInUse;
2072              break;
2073       case(FaceElements):
2074       case(ReducedFaceElements):
2075              numTags=mesh->FaceElements->numTagsInUse;
2076              break;
2077       case(Points):
2078              numTags=mesh->Points->numTagsInUse;
2079              break;
2080       case(ContactElementsZero):
2081       case(ReducedContactElementsZero):
2082       case(ContactElementsOne):
2083       case(ReducedContactElementsOne):
2084              numTags=mesh->ContactElements->numTagsInUse;
2085              break;
2086       default:
2087          stringstream temp;
2088          temp << "Error - Finley does not know anything about function space type " << functionSpaceCode;
2089          throw FinleyAdapterException(temp.str());
2090      }
2091      return numTags;
2092    }
2093    int* MeshAdapter::borrowListOfTagsInUse(int functionSpaceCode) const
2094    {
2095      Finley_Mesh* mesh=m_finleyMesh.get();
2096      index_t* tags=NULL;
2097      switch(functionSpaceCode) {
2098       case(Nodes):
2099              tags=mesh->Nodes->tagsInUse;
2100              break;
2101       case(ReducedNodes):
2102              throw FinleyAdapterException("Error - ReducedNodes does not support tags");
2103              break;
2104       case(DegreesOfFreedom):
2105              throw FinleyAdapterException("Error - DegreesOfFreedom does not support tags");
2106              break;
2107       case(ReducedDegreesOfFreedom):
2108              throw FinleyAdapterException("Error - ReducedDegreesOfFreedom does not support tags");
2109              break;
2110       case(Elements):
2111       case(ReducedElements):
2112              tags=mesh->Elements->tagsInUse;
2113              break;
2114       case(FaceElements):
2115       case(ReducedFaceElements):
2116              tags=mesh->FaceElements->tagsInUse;
2117              break;
2118       case(Points):
2119              tags=mesh->Points->tagsInUse;
2120              break;
2121       case(ContactElementsZero):
2122       case(ReducedContactElementsZero):
2123       case(ContactElementsOne):
2124       case(ReducedContactElementsOne):
2125              tags=mesh->ContactElements->tagsInUse;
2126              break;
2127       default:
2128          stringstream temp;
2129          temp << "Error - Finley does not know anything about function space type " << functionSpaceCode;
2130          throw FinleyAdapterException(temp.str());
2131      }
2132      return tags;
2133    }
2134    
2135    
2136  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.1628  
changed lines
  Added in v.1800

  ViewVC Help
Powered by ViewVC 1.1.26