/[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 1748 by ksteube, Wed Sep 3 06:10:39 2008 UTC revision 1859 by gross, Wed Oct 8 03:03:37 2008 UTC
# Line 1  Line 1 
1    
 /* $Id$ */  
   
2  /*******************************************************  /*******************************************************
3   *  *
4   *           Copyright 2003-2007 by ACceSS MNRF  * Copyright (c) 2003-2008 by University of Queensland
5   *       Copyright 2007 by University of Queensland  * Earth Systems Science Computational Center (ESSCC)
6   *  * http://www.uq.edu.au/esscc
7   *                http://esscc.uq.edu.au  *
8   *        Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
9   *  Licensed under the Open Software License version 3.0  * Licensed under the Open Software License version 3.0
10   *     http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
11   *  *
12   *******************************************************/  *******************************************************/
13    
14    
15  #include "MeshAdapter.h"  #include "MeshAdapter.h"
16  #include "escript/Data.h"  #include "escript/Data.h"
# Line 19  Line 18 
18  #ifdef USE_NETCDF  #ifdef USE_NETCDF
19  #include <netcdfcpp.h>  #include <netcdfcpp.h>
20  #endif  #endif
21    #ifdef PASO_MPI
22    #include <mpi.h>
23    #include "paso/Paso_MPI.h"
24    #endif
25  extern "C" {  extern "C" {
26  #include "escript/blocktimer.h"  #include "escript/blocktimer.h"
27  }  }
# Line 123  void MeshAdapter::dump(const std::string Line 126  void MeshAdapter::dump(const std::string
126     int num_Elements_numNodes        = mesh->Elements->numNodes;     int num_Elements_numNodes        = mesh->Elements->numNodes;
127     int num_FaceElements_numNodes    = mesh->FaceElements->numNodes;     int num_FaceElements_numNodes    = mesh->FaceElements->numNodes;
128     int num_ContactElements_numNodes = mesh->ContactElements->numNodes;     int num_ContactElements_numNodes = mesh->ContactElements->numNodes;
129    #ifdef PASO_MPI
130       MPI_Status status;
131    #endif
132    
133    /* Incoming token indicates it's my turn to write */
134    #ifdef PASO_MPI
135       if (mpi_rank>0) MPI_Recv(&num_Tags, 0, MPI_INT, mpi_rank-1, 81800, mesh->MPIInfo->comm, &status);
136    #endif
137    
138     char *newFileName = Paso_MPI_appendRankToFileName(fileName.c_str(),     char *newFileName = Paso_MPI_appendRankToFileName(fileName.c_str(),
139                                                       mpi_size, mpi_rank);                                                       mpi_size, mpi_rank);
140    
141     /* Figure out how much storage is required for tags */     /* Figure out how much storage is required for tags */
142     tag_map = mesh->TagMap;     tag_map = mesh->TagMap;
143       num_Tags = 0;
144     if (tag_map) {     if (tag_map) {
145        while (tag_map) {        while (tag_map) {
146           num_Tags++;           num_Tags++;
# Line 276  void MeshAdapter::dump(const std::string Line 288  void MeshAdapter::dump(const std::string
288        if (! (ids->put(int_ptr, mpi_size+1)) )        if (! (ids->put(int_ptr, mpi_size+1)) )
289           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);
290    
291          // Nodes nodeDistribution
292          if (! ( ids = dataFile.add_var("Nodes_NodeDistribution", ncInt, ncdims[2])) )
293             throw DataException("Error - MeshAdapter::dump: appending Nodes_NodeDistribution to netCDF file failed: " + *newFileName);
294          int_ptr = &mesh->Nodes->nodesDistribution->first_component[0];
295          if (! (ids->put(int_ptr, mpi_size+1)) )
296             throw DataException("Error - MeshAdapter::dump: copy Nodes_NodeDistribution to netCDF buffer failed: " + *newFileName);
297    
298     }     }
299    
300     // // // // // Elements // // // // //     // // // // // Elements // // // // //
301    
302     if (num_Elements>0) {     if (num_Elements>0) {
303    
       // Temp storage to gather node IDs  
       int *Elements_Nodes = TMPMEMALLOC(num_Elements*num_Elements_numNodes,int);  
   
304        // Elements_Id        // Elements_Id
305        if (! ( ids = dataFile.add_var("Elements_Id", ncInt, ncdims[3])) )        if (! ( ids = dataFile.add_var("Elements_Id", ncInt, ncdims[3])) )
306           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 314  void MeshAdapter::dump(const std::string Line 330  void MeshAdapter::dump(const std::string
330           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);
331    
332        // 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)]];  
333        if (! ( ids = dataFile.add_var("Elements_Nodes", ncInt, ncdims[3], ncdims[7]) ) )        if (! ( ids = dataFile.add_var("Elements_Nodes", ncInt, ncdims[3], ncdims[7]) ) )
334           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);
335        if (! (ids->put(&(Elements_Nodes[0]), num_Elements, num_Elements_numNodes)) )        if (! (ids->put(&(mesh->Elements->Nodes[0]), num_Elements, num_Elements_numNodes)) )
336           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);
337    
       TMPMEMFREE(Elements_Nodes);  
   
338     }     }
339    
340     // // // // // Face_Elements // // // // //     // // // // // Face_Elements // // // // //
341    
342     if (num_FaceElements>0) {     if (num_FaceElements>0) {
343    
       // Temp storage to gather node IDs  
       int *FaceElements_Nodes = TMPMEMALLOC(num_FaceElements*num_FaceElements_numNodes,int);  
   
344        // FaceElements_Id        // FaceElements_Id
345        if (! ( ids = dataFile.add_var("FaceElements_Id", ncInt, ncdims[4])) )        if (! ( ids = dataFile.add_var("FaceElements_Id", ncInt, ncdims[4])) )
346           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 362  void MeshAdapter::dump(const std::string Line 370  void MeshAdapter::dump(const std::string
370           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);
371    
372        // 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)]];  
373        if (! ( ids = dataFile.add_var("FaceElements_Nodes", ncInt, ncdims[4], ncdims[8]) ) )        if (! ( ids = dataFile.add_var("FaceElements_Nodes", ncInt, ncdims[4], ncdims[8]) ) )
374           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);
375        if (! (ids->put(&(FaceElements_Nodes[0]), num_FaceElements, num_FaceElements_numNodes)) )        if (! (ids->put(&(mesh->FaceElements->Nodes[0]), num_FaceElements, num_FaceElements_numNodes)) )
376           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);
377    
       TMPMEMFREE(FaceElements_Nodes);  
   
378     }     }
379    
380     // // // // // Contact_Elements // // // // //     // // // // // Contact_Elements // // // // //
381    
382     if (num_ContactElements>0) {     if (num_ContactElements>0) {
383    
       // Temp storage to gather node IDs  
       int *ContactElements_Nodes = TMPMEMALLOC(num_ContactElements*num_ContactElements_numNodes,int);  
   
384        // ContactElements_Id        // ContactElements_Id
385        if (! ( ids = dataFile.add_var("ContactElements_Id", ncInt, ncdims[5])) )        if (! ( ids = dataFile.add_var("ContactElements_Id", ncInt, ncdims[5])) )
386           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 410  void MeshAdapter::dump(const std::string Line 410  void MeshAdapter::dump(const std::string
410           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);
411    
412        // 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)]];  
413        if (! ( ids = dataFile.add_var("ContactElements_Nodes", ncInt, ncdims[5], ncdims[9]) ) )        if (! ( ids = dataFile.add_var("ContactElements_Nodes", ncInt, ncdims[5], ncdims[9]) ) )
414           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);
415        if (! (ids->put(&(ContactElements_Nodes[0]), num_ContactElements, num_ContactElements_numNodes)) )        if (! (ids->put(&(mesh->ContactElements->Nodes[0]), num_ContactElements, num_ContactElements_numNodes)) )
416           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);
417    
       TMPMEMFREE(ContactElements_Nodes);  
   
418     }     }
419    
420     // // // // // Points // // // // //     // // // // // Points // // // // //
# Line 428  void MeshAdapter::dump(const std::string Line 423  void MeshAdapter::dump(const std::string
423    
424        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");
425    
       // Temp storage to gather node IDs  
       int *Points_Nodes = TMPMEMALLOC(num_Points,int);  
   
426        // Points_Id        // Points_Id
427        if (! ( ids = dataFile.add_var("Points_Id", ncInt, ncdims[6])) )        if (! ( ids = dataFile.add_var("Points_Id", ncInt, ncdims[6])) )
428           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 461  void MeshAdapter::dump(const std::string Line 453  void MeshAdapter::dump(const std::string
453    
454        // Points_Nodes        // Points_Nodes
455        // 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)]];  
456        if (! ( ids = dataFile.add_var("Points_Nodes", ncInt, ncdims[6]) ) )        if (! ( ids = dataFile.add_var("Points_Nodes", ncInt, ncdims[6]) ) )
457           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);
458        if (! (ids->put(&(Points_Nodes[0]), num_Points)) )        if (! (ids->put(&(mesh->Points->Nodes[0]), num_Points)) )
459           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);
460    
       TMPMEMFREE(Points_Nodes);  
   
461     }     }
462    
463     // // // // // TagMap // // // // //     // // // // // TagMap // // // // //
# Line 516  void MeshAdapter::dump(const std::string Line 504  void MeshAdapter::dump(const std::string
504    
505     }     }
506    
507    /* Send token to next MPI process so he can take his turn */
508    #ifdef PASO_MPI
509       if (mpi_rank<mpi_size-1) MPI_Send(&num_Tags, 0, MPI_INT, mpi_rank+1, 81800, mesh->MPIInfo->comm);
510    #endif
511    
512     // NetCDF file is closed by destructor of NcFile object     // NetCDF file is closed by destructor of NcFile object
513    
514  #else  #else
515     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.");
516  #endif  /* USE_NETCDF */  #endif  /* USE_NETCDF */
# Line 648  int MeshAdapter::getDim() const Line 641  int MeshAdapter::getDim() const
641  }  }
642    
643  //  //
644    // Return the number of data points summed across all MPI processes
645    //
646    int MeshAdapter::getNumDataPointsGlobal() const
647    {
648       return Finley_NodeFile_getGlobalNumNodes(m_finleyMesh.get()->Nodes);
649    }
650    
651    //
652  // 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
653  // needed to represent data on a parts of the mesh.  // needed to represent data on a parts of the mesh.
654  //  //
# Line 823  void MeshAdapter::addPDEToTransportProbl Line 824  void MeshAdapter::addPDEToTransportProbl
824                                             const escript::Data& d, const escript::Data& y,                                             const escript::Data& d, const escript::Data& y,
825                                             const escript::Data& d_contact,const escript::Data& y_contact) const                                             const escript::Data& d_contact,const escript::Data& y_contact) const
826  {  {
827     DataArrayView::ShapeType shape;     DataTypes::ShapeType shape;
828     source.expand();     source.expand();
829     escriptDataC _source=source.getDataC();     escriptDataC _source=source.getDataC();
830     escriptDataC _M=M.getDataC();     escriptDataC _M=M.getDataC();
# Line 1825  bool MeshAdapter::operator!=(const Abstr Line 1826  bool MeshAdapter::operator!=(const Abstr
1826     return !(operator==(other));     return !(operator==(other));
1827  }  }
1828    
1829  int MeshAdapter::getSystemMatrixTypeId(const int solver, const int package, const bool symmetry) const  int MeshAdapter::getSystemMatrixTypeId(const int solver, const int preconditioner, const int package, const bool symmetry) const
1830  {  {
1831     int out=Paso_SystemMatrix_getSystemMatrixTypeId(SystemMatrixAdapter::mapOptionToPaso(solver),SystemMatrixAdapter::mapOptionToPaso(package),symmetry?1:0);     int out=Paso_SystemMatrix_getSystemMatrixTypeId(SystemMatrixAdapter::mapOptionToPaso(solver),SystemMatrixAdapter::mapOptionToPaso(preconditioner), SystemMatrixAdapter::mapOptionToPaso(package),symmetry?1:0);
1832       checkPasoError();
1833       return out;
1834    }
1835    int MeshAdapter::getTransportTypeId(const int solver, const int preconditioner, const int package, const bool symmetry) const
1836    {
1837       int out=Paso_FCTransportProblem_getTypeId(SystemMatrixAdapter::mapOptionToPaso(solver),SystemMatrixAdapter::mapOptionToPaso(preconditioner), SystemMatrixAdapter::mapOptionToPaso(package),symmetry?1:0);
1838     checkPasoError();     checkPasoError();
1839     return out;     return out;
1840  }  }
# Line 2127  int* MeshAdapter::borrowListOfTagsInUse( Line 2134  int* MeshAdapter::borrowListOfTagsInUse(
2134  }  }
2135    
2136    
2137    bool MeshAdapter::canTag(int functionSpaceCode) const
2138    {
2139      switch(functionSpaceCode) {
2140       case(Nodes):
2141       case(Elements):
2142       case(ReducedElements):
2143       case(FaceElements):
2144       case(ReducedFaceElements):
2145       case(Points):
2146       case(ContactElementsZero):
2147       case(ReducedContactElementsZero):
2148       case(ContactElementsOne):
2149       case(ReducedContactElementsOne):
2150              return true;
2151       case(ReducedNodes):
2152       case(DegreesOfFreedom):
2153       case(ReducedDegreesOfFreedom):
2154          return false;
2155       default:
2156        return false;
2157      }
2158    }
2159    
2160    
2161  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.1748  
changed lines
  Added in v.1859

  ViewVC Help
Powered by ViewVC 1.1.26