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

Diff of /trunk/finley/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 2315 by gross, Wed Mar 18 00:38:48 2009 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 "esysUtils/blocktimer.h"
27  }  }
 #include <vector>  
   
 #define IS_THERE_A_REASON_FOR_THIS_MAGIC_NAME_LENGTH  256  
28    
29  using namespace std;  using namespace std;
30  using namespace escript;  using namespace escript;
# Line 83  int MeshAdapter::getMPIRank() const Line 83  int MeshAdapter::getMPIRank() const
83  {  {
84     return m_finleyMesh.get()->MPIInfo->rank;     return m_finleyMesh.get()->MPIInfo->rank;
85  }  }
86    void MeshAdapter::MPIBarrier() const
87    {
88    #ifdef PASO_MPI
89       MPI_Barrier(m_finleyMesh.get()->MPIInfo->comm);
90    #endif
91       return;
92    }
93    bool MeshAdapter::onMasterProcessor() const
94    {
95       return m_finleyMesh.get()->MPIInfo->rank == 0;
96    }
97    
98    
99  Finley_Mesh* MeshAdapter::getFinley_Mesh() const {  Finley_Mesh* MeshAdapter::getFinley_Mesh() const {
# Line 106  void MeshAdapter::Print_Mesh_Info(const Line 117  void MeshAdapter::Print_Mesh_Info(const
117  void MeshAdapter::dump(const std::string& fileName) const  void MeshAdapter::dump(const std::string& fileName) const
118  {  {
119  #ifdef USE_NETCDF  #ifdef USE_NETCDF
120     const NcDim* ncdims[12];     const NcDim* ncdims[12] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
121     NcVar *ids, *data;     NcVar *ids;
122     int *int_ptr;     int *int_ptr;
123     Finley_Mesh *mesh = m_finleyMesh.get();     Finley_Mesh *mesh = m_finleyMesh.get();
124     Finley_TagMap* tag_map;     Finley_TagMap* tag_map;
# Line 123  void MeshAdapter::dump(const std::string Line 134  void MeshAdapter::dump(const std::string
134     int num_Elements_numNodes        = mesh->Elements->numNodes;     int num_Elements_numNodes        = mesh->Elements->numNodes;
135     int num_FaceElements_numNodes    = mesh->FaceElements->numNodes;     int num_FaceElements_numNodes    = mesh->FaceElements->numNodes;
136     int num_ContactElements_numNodes = mesh->ContactElements->numNodes;     int num_ContactElements_numNodes = mesh->ContactElements->numNodes;
137    #ifdef PASO_MPI
138       MPI_Status status;
139    #endif
140    
141     // I don't think the strdup is needed since Paso_MPI_appendRankToFileName  /* Incoming token indicates it's my turn to write */
142     // does it's own allocation.  #ifdef PASO_MPI
143     // 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);
144    #endif
145    
146     char *newFileName = Paso_MPI_appendRankToFileName(fileName.c_str(),     char *newFileName = Paso_MPI_appendRankToFileName(fileName.c_str(),
147                                                       mpi_size, mpi_rank);                                                       mpi_size, mpi_rank);
148    
149     /* Figure out how much storage is required for tags */     /* Figure out how much storage is required for tags */
150     tag_map = mesh->TagMap;     tag_map = mesh->TagMap;
151       num_Tags = 0;
152     if (tag_map) {     if (tag_map) {
153        while (tag_map) {        while (tag_map) {
154           num_Tags++;           num_Tags++;
# Line 280  void MeshAdapter::dump(const std::string Line 296  void MeshAdapter::dump(const std::string
296        if (! (ids->put(int_ptr, mpi_size+1)) )        if (! (ids->put(int_ptr, mpi_size+1)) )
297           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);
298    
299          // Nodes nodeDistribution
300          if (! ( ids = dataFile.add_var("Nodes_NodeDistribution", ncInt, ncdims[2])) )
301             throw DataException("Error - MeshAdapter::dump: appending Nodes_NodeDistribution to netCDF file failed: " + *newFileName);
302          int_ptr = &mesh->Nodes->nodesDistribution->first_component[0];
303          if (! (ids->put(int_ptr, mpi_size+1)) )
304             throw DataException("Error - MeshAdapter::dump: copy Nodes_NodeDistribution to netCDF buffer failed: " + *newFileName);
305    
306     }     }
307    
308     // // // // // Elements // // // // //     // // // // // Elements // // // // //
309    
310     if (num_Elements>0) {     if (num_Elements>0) {
311    
       // Temp storage to gather node IDs  
       int *Elements_Nodes = TMPMEMALLOC(num_Elements*num_Elements_numNodes,int);  
   
312        // Elements_Id        // Elements_Id
313        if (! ( ids = dataFile.add_var("Elements_Id", ncInt, ncdims[3])) )        if (! ( ids = dataFile.add_var("Elements_Id", ncInt, ncdims[3])) )
314           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 338  void MeshAdapter::dump(const std::string
338           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);
339    
340        // 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)]];  
341        if (! ( ids = dataFile.add_var("Elements_Nodes", ncInt, ncdims[3], ncdims[7]) ) )        if (! ( ids = dataFile.add_var("Elements_Nodes", ncInt, ncdims[3], ncdims[7]) ) )
342           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);
343        if (! (ids->put(&(Elements_Nodes[0]), num_Elements, num_Elements_numNodes)) )        if (! (ids->put(&(mesh->Elements->Nodes[0]), num_Elements, num_Elements_numNodes)) )
344           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);
345    
       TMPMEMFREE(Elements_Nodes);  
   
346     }     }
347    
348     // // // // // Face_Elements // // // // //     // // // // // Face_Elements // // // // //
349    
350     if (num_FaceElements>0) {     if (num_FaceElements>0) {
351    
       // Temp storage to gather node IDs  
       int *FaceElements_Nodes = TMPMEMALLOC(num_FaceElements*num_FaceElements_numNodes,int);  
   
352        // FaceElements_Id        // FaceElements_Id
353        if (! ( ids = dataFile.add_var("FaceElements_Id", ncInt, ncdims[4])) )        if (! ( ids = dataFile.add_var("FaceElements_Id", ncInt, ncdims[4])) )
354           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 378  void MeshAdapter::dump(const std::string
378           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);
379    
380        // 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)]];  
381        if (! ( ids = dataFile.add_var("FaceElements_Nodes", ncInt, ncdims[4], ncdims[8]) ) )        if (! ( ids = dataFile.add_var("FaceElements_Nodes", ncInt, ncdims[4], ncdims[8]) ) )
382           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);
383        if (! (ids->put(&(FaceElements_Nodes[0]), num_FaceElements, num_FaceElements_numNodes)) )        if (! (ids->put(&(mesh->FaceElements->Nodes[0]), num_FaceElements, num_FaceElements_numNodes)) )
384           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);
385    
       TMPMEMFREE(FaceElements_Nodes);  
   
386     }     }
387    
388     // // // // // Contact_Elements // // // // //     // // // // // Contact_Elements // // // // //
389    
390     if (num_ContactElements>0) {     if (num_ContactElements>0) {
391    
       // Temp storage to gather node IDs  
       int *ContactElements_Nodes = TMPMEMALLOC(num_ContactElements*num_ContactElements_numNodes,int);  
   
392        // ContactElements_Id        // ContactElements_Id
393        if (! ( ids = dataFile.add_var("ContactElements_Id", ncInt, ncdims[5])) )        if (! ( ids = dataFile.add_var("ContactElements_Id", ncInt, ncdims[5])) )
394           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 418  void MeshAdapter::dump(const std::string
418           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);
419    
420        // 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)]];  
421        if (! ( ids = dataFile.add_var("ContactElements_Nodes", ncInt, ncdims[5], ncdims[9]) ) )        if (! ( ids = dataFile.add_var("ContactElements_Nodes", ncInt, ncdims[5], ncdims[9]) ) )
422           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);
423        if (! (ids->put(&(ContactElements_Nodes[0]), num_ContactElements, num_ContactElements_numNodes)) )        if (! (ids->put(&(mesh->ContactElements->Nodes[0]), num_ContactElements, num_ContactElements_numNodes)) )
424           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);
425    
       TMPMEMFREE(ContactElements_Nodes);  
   
426     }     }
427    
428     // // // // // Points // // // // //     // // // // // Points // // // // //
# Line 432  void MeshAdapter::dump(const std::string Line 431  void MeshAdapter::dump(const std::string
431    
432        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");
433    
       // Temp storage to gather node IDs  
       int *Points_Nodes = TMPMEMALLOC(num_Points,int);  
   
434        // Points_Id        // Points_Id
435        if (! ( ids = dataFile.add_var("Points_Id", ncInt, ncdims[6])) )        if (! ( ids = dataFile.add_var("Points_Id", ncInt, ncdims[6])) )
436           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 461  void MeshAdapter::dump(const std::string
461    
462        // Points_Nodes        // Points_Nodes
463        // 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)]];  
464        if (! ( ids = dataFile.add_var("Points_Nodes", ncInt, ncdims[6]) ) )        if (! ( ids = dataFile.add_var("Points_Nodes", ncInt, ncdims[6]) ) )
465           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);
466        if (! (ids->put(&(Points_Nodes[0]), num_Points)) )        if (! (ids->put(&(mesh->Points->Nodes[0]), num_Points)) )
467           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);
468    
       TMPMEMFREE(Points_Nodes);  
   
469     }     }
470    
471     // // // // // TagMap // // // // //     // // // // // TagMap // // // // //
# Line 520  void MeshAdapter::dump(const std::string Line 512  void MeshAdapter::dump(const std::string
512    
513     }     }
514    
515    /* Send token to next MPI process so he can take his turn */
516    #ifdef PASO_MPI
517       if (mpi_rank<mpi_size-1) MPI_Send(&num_Tags, 0, MPI_INT, mpi_rank+1, 81800, mesh->MPIInfo->comm);
518    #endif
519    
520     // NetCDF file is closed by destructor of NcFile object     // NetCDF file is closed by destructor of NcFile object
521    
522  #else  #else
523     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.");
524  #endif  /* USE_NETCDF */  #endif  /* USE_NETCDF */
# Line 646  int MeshAdapter::getDiracDeltaFunctionCo Line 643  int MeshAdapter::getDiracDeltaFunctionCo
643  //  //
644  int MeshAdapter::getDim() const  int MeshAdapter::getDim() const
645  {  {
646     int numDim=Finley_Mesh_getDim(m_finleyMesh.get());     Finley_Mesh* mesh=m_finleyMesh.get();
647       int numDim=Finley_Mesh_getDim(mesh);
648     checkFinleyError();     checkFinleyError();
649     return numDim;     return numDim;
650  }  }
651    
652  //  //
653    // Return the number of data points summed across all MPI processes
654    //
655    int MeshAdapter::getNumDataPointsGlobal() const
656    {
657       return Finley_NodeFile_getGlobalNumNodes(m_finleyMesh.get()->Nodes);
658    }
659    
660    //
661  // 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
662  // needed to represent data on a parts of the mesh.  // needed to represent data on a parts of the mesh.
663  //  //
# Line 827  void MeshAdapter::addPDEToTransportProbl Line 833  void MeshAdapter::addPDEToTransportProbl
833                                             const escript::Data& d, const escript::Data& y,                                             const escript::Data& d, const escript::Data& y,
834                                             const escript::Data& d_contact,const escript::Data& y_contact) const                                             const escript::Data& d_contact,const escript::Data& y_contact) const
835  {  {
836     DataArrayView::ShapeType shape;     DataTypes::ShapeType shape;
837     source.expand();     source.expand();
838     escriptDataC _source=source.getDataC();     escriptDataC _source=source.getDataC();
839     escriptDataC _M=M.getDataC();     escriptDataC _M=M.getDataC();
# Line 863  void MeshAdapter::addPDEToTransportProbl Line 869  void MeshAdapter::addPDEToTransportProbl
869  //  //
870  void MeshAdapter::interpolateOnDomain(escript::Data& target,const escript::Data& in) const  void MeshAdapter::interpolateOnDomain(escript::Data& target,const escript::Data& in) const
871  {  {
872     const MeshAdapter& inDomain=dynamic_cast<const MeshAdapter&>(in.getFunctionSpace().getDomain());     const MeshAdapter& inDomain=dynamic_cast<const MeshAdapter&>(*(in.getFunctionSpace().getDomain()));
873     const MeshAdapter& targetDomain=dynamic_cast<const MeshAdapter&>(target.getFunctionSpace().getDomain());     const MeshAdapter& targetDomain=dynamic_cast<const MeshAdapter&>(*(target.getFunctionSpace().getDomain()));
874     if (inDomain!=*this)       if (inDomain!=*this)  
875        throw FinleyAdapterException("Error - Illegal domain of interpolant.");        throw FinleyAdapterException("Error - Illegal domain of interpolant.");
876     if (targetDomain!=*this)     if (targetDomain!=*this)
# Line 1148  void MeshAdapter::interpolateOnDomain(es Line 1154  void MeshAdapter::interpolateOnDomain(es
1154  //  //
1155  void MeshAdapter::setToX(escript::Data& arg) const  void MeshAdapter::setToX(escript::Data& arg) const
1156  {  {
1157     const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(arg.getFunctionSpace().getDomain());     const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(*(arg.getFunctionSpace().getDomain()));
1158     if (argDomain!=*this)     if (argDomain!=*this)
1159        throw FinleyAdapterException("Error - Illegal domain of data point locations");        throw FinleyAdapterException("Error - Illegal domain of data point locations");
1160     Finley_Mesh* mesh=m_finleyMesh.get();     Finley_Mesh* mesh=m_finleyMesh.get();
# Line 1171  void MeshAdapter::setToX(escript::Data& Line 1177  void MeshAdapter::setToX(escript::Data&
1177  //  //
1178  void MeshAdapter::setToNormal(escript::Data& normal) const  void MeshAdapter::setToNormal(escript::Data& normal) const
1179  {  {
1180     const MeshAdapter& normalDomain=dynamic_cast<const MeshAdapter&>(normal.getFunctionSpace().getDomain());  /*   const MeshAdapter& normalDomain=dynamic_cast<const MeshAdapter&>(normal.getFunctionSpace().getDomain());*/
1181       const MeshAdapter& normalDomain=dynamic_cast<const MeshAdapter&>(*(normal.getFunctionSpace().getDomain()));
1182     if (normalDomain!=*this)     if (normalDomain!=*this)
1183        throw FinleyAdapterException("Error - Illegal domain of normal locations");        throw FinleyAdapterException("Error - Illegal domain of normal locations");
1184     Finley_Mesh* mesh=m_finleyMesh.get();     Finley_Mesh* mesh=m_finleyMesh.get();
# Line 1226  void MeshAdapter::setToNormal(escript::D Line 1233  void MeshAdapter::setToNormal(escript::D
1233  //  //
1234  void MeshAdapter::interpolateACross(escript::Data& target,const escript::Data& source) const  void MeshAdapter::interpolateACross(escript::Data& target,const escript::Data& source) const
1235  {  {
1236     const MeshAdapter& targetDomain=dynamic_cast<const MeshAdapter&>(target.getFunctionSpace().getDomain());     const_Domain_ptr targetDomain_p=target.getFunctionSpace().getDomain();
1237     if (targetDomain!=*this)     const MeshAdapter* targetDomain=dynamic_cast<const MeshAdapter*>(targetDomain_p.get());
1238       if (targetDomain!=this)
1239        throw FinleyAdapterException("Error - Illegal domain of interpolation target");        throw FinleyAdapterException("Error - Illegal domain of interpolation target");
1240    
1241     throw FinleyAdapterException("Error - Finley does not allow interpolation across domains yet.");     throw FinleyAdapterException("Error - Finley does not allow interpolation across domains yet.");
# Line 1238  void MeshAdapter::interpolateACross(escr Line 1246  void MeshAdapter::interpolateACross(escr
1246  //  //
1247  void MeshAdapter::setToIntegrals(std::vector<double>& integrals,const escript::Data& arg) const  void MeshAdapter::setToIntegrals(std::vector<double>& integrals,const escript::Data& arg) const
1248  {  {
1249     const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(arg.getFunctionSpace().getDomain());     const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(*(arg.getFunctionSpace().getDomain()));
1250     if (argDomain!=*this)     if (argDomain!=*this)
1251        throw FinleyAdapterException("Error - Illegal domain of integration kernel");        throw FinleyAdapterException("Error - Illegal domain of integration kernel");
1252    
# Line 1249  void MeshAdapter::setToIntegrals(std::ve Line 1257  void MeshAdapter::setToIntegrals(std::ve
1257     escriptDataC _arg=arg.getDataC();     escriptDataC _arg=arg.getDataC();
1258     switch(arg.getFunctionSpace().getTypeCode()) {     switch(arg.getFunctionSpace().getTypeCode()) {
1259     case(Nodes):     case(Nodes):
1260     temp=escript::Data( arg, function(asAbstractContinuousDomain()) );     temp=escript::Data( arg, escript::function(asAbstractContinuousDomain()) );
1261     _temp=temp.getDataC();     _temp=temp.getDataC();
1262     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1263     break;     break;
1264     case(ReducedNodes):     case(ReducedNodes):
1265     temp=escript::Data( arg, function(asAbstractContinuousDomain()) );     temp=escript::Data( arg, escript::function(asAbstractContinuousDomain()) );
1266     _temp=temp.getDataC();     _temp=temp.getDataC();
1267     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1268     break;     break;
# Line 1286  void MeshAdapter::setToIntegrals(std::ve Line 1294  void MeshAdapter::setToIntegrals(std::ve
1294     Finley_Assemble_integrate(mesh->Nodes,mesh->ContactElements,&_arg,&integrals[0]);     Finley_Assemble_integrate(mesh->Nodes,mesh->ContactElements,&_arg,&integrals[0]);
1295     break;     break;
1296     case(DegreesOfFreedom):     case(DegreesOfFreedom):
1297     temp=escript::Data( arg, function(asAbstractContinuousDomain()) );     temp=escript::Data( arg, escript::function(asAbstractContinuousDomain()) );
1298     _temp=temp.getDataC();     _temp=temp.getDataC();
1299     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1300     break;     break;
1301     case(ReducedDegreesOfFreedom):     case(ReducedDegreesOfFreedom):
1302     temp=escript::Data( arg, function(asAbstractContinuousDomain()) );     temp=escript::Data( arg, escript::function(asAbstractContinuousDomain()) );
1303     _temp=temp.getDataC();     _temp=temp.getDataC();
1304     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1305     break;     break;
# Line 1310  void MeshAdapter::setToIntegrals(std::ve Line 1318  void MeshAdapter::setToIntegrals(std::ve
1318  //  //
1319  void MeshAdapter::setToGradient(escript::Data& grad,const escript::Data& arg) const  void MeshAdapter::setToGradient(escript::Data& grad,const escript::Data& arg) const
1320  {  {
1321     const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(arg.getFunctionSpace().getDomain());     const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(*(arg.getFunctionSpace().getDomain()));
1322     if (argDomain!=*this)     if (argDomain!=*this)
1323        throw FinleyAdapterException("Error - Illegal domain of gradient argument");        throw FinleyAdapterException("Error - Illegal domain of gradient argument");
1324     const MeshAdapter& gradDomain=dynamic_cast<const MeshAdapter&>(grad.getFunctionSpace().getDomain());     const MeshAdapter& gradDomain=dynamic_cast<const MeshAdapter&>(*(grad.getFunctionSpace().getDomain()));
1325     if (gradDomain!=*this)     if (gradDomain!=*this)
1326        throw FinleyAdapterException("Error - Illegal domain of gradient");        throw FinleyAdapterException("Error - Illegal domain of gradient");
1327    
# Line 1435  void MeshAdapter::setToSize(escript::Dat Line 1443  void MeshAdapter::setToSize(escript::Dat
1443     checkFinleyError();     checkFinleyError();
1444  }  }
1445    
1446  // sets the location of nodes:  //
1447    // sets the location of nodes
1448    //
1449  void MeshAdapter::setNewX(const escript::Data& new_x)  void MeshAdapter::setNewX(const escript::Data& new_x)
1450  {  {
1451     Finley_Mesh* mesh=m_finleyMesh.get();     Finley_Mesh* mesh=m_finleyMesh.get();
1452     escriptDataC tmp;     escriptDataC tmp;
1453     const MeshAdapter& newDomain=dynamic_cast<const MeshAdapter&>(new_x.getFunctionSpace().getDomain());     const MeshAdapter& newDomain=dynamic_cast<const MeshAdapter&>(*(new_x.getFunctionSpace().getDomain()));
1454     if (newDomain!=*this)     if (newDomain!=*this)
1455        throw FinleyAdapterException("Error - Illegal domain of new point locations");        throw FinleyAdapterException("Error - Illegal domain of new point locations");
1456     tmp = new_x.getDataC();     tmp = new_x.getDataC();
# Line 1448  void MeshAdapter::setNewX(const escript: Line 1458  void MeshAdapter::setNewX(const escript:
1458     checkFinleyError();     checkFinleyError();
1459  }  }
1460    
1461  // saves a data array in openDX format:  //
1462  void MeshAdapter::saveDX(const std::string& filename,const boost::python::dict& arg) const  // Helper for the save* methods. Extracts optional data variable names and the
1463    // corresponding pointers from python dictionary. Caller must free arrays.
1464    //
1465    void MeshAdapter::extractArgsFromDict(const boost::python::dict& arg, int& numData, char**& names, escriptDataC*& data, escriptDataC**& dataPtr) const
1466  {  {
1467     unsigned int MAX_namelength=IS_THERE_A_REASON_FOR_THIS_MAGIC_NAME_LENGTH;     numData = boost::python::extract<int>(arg.attr("__len__")());
    const int num_data=boost::python::extract<int>(arg.attr("__len__")());  
1468     /* win32 refactor */     /* win32 refactor */
1469     char* *names = (num_data>0) ? TMPMEMALLOC(num_data,char*) : (char**)NULL;     names = (numData>0) ? TMPMEMALLOC(numData, char*) : (char**)NULL;
1470     for(int i=0;i<num_data;i++)     data = (numData>0) ? TMPMEMALLOC(numData,escriptDataC) : (escriptDataC*)NULL;
1471     {     dataPtr = (numData>0) ? TMPMEMALLOC(numData,escriptDataC*) : (escriptDataC**)NULL;
       names[i] = (MAX_namelength>0) ? TMPMEMALLOC(MAX_namelength,char) : (char*)NULL;  
    }  
   
    escriptDataC *data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC) : (escriptDataC*)NULL;  
    escriptDataC* *ptr_data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC*) : (escriptDataC**)NULL;  
1472    
1473     boost::python::list keys=arg.keys();     boost::python::list keys=arg.keys();
1474     for (int i=0;i<num_data;++i) {     for (int i=0; i<numData; ++i) {
1475        std::string n=boost::python::extract<std::string>(keys[i]);        std::string n=boost::python::extract<std::string>(keys[i]);
1476        escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);        escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);
1477        if (dynamic_cast<const MeshAdapter&>(d.getFunctionSpace().getDomain()) !=*this)        if (dynamic_cast<const MeshAdapter&>(*(d.getFunctionSpace().getDomain())) !=*this)
1478           throw FinleyAdapterException("Error  in saveVTK: Data must be defined on same Domain");           throw FinleyAdapterException("Error: Data must be defined on same Domain");
1479        data[i]=d.getDataC();        data[i] = d.getDataC();
1480        ptr_data[i]= &(data[i]);        dataPtr[i] = &(data[i]);
1481        if (n.length()>MAX_namelength-1) {        names[i] = TMPMEMALLOC(n.length()+1, char);
1482           strncpy(names[i],n.c_str(),MAX_namelength-1);        strcpy(names[i], n.c_str());
          names[i][MAX_namelength-1]='\0';  
       } else {  
          strcpy(names[i],n.c_str());  
       }  
1483     }     }
1484     Finley_Mesh_saveDX(filename.c_str(),m_finleyMesh.get(),num_data,names,ptr_data);  }
1485    
1486    //
1487    // saves mesh and optionally data arrays in openDX format
1488    //
1489    void MeshAdapter::saveDX(const std::string& filename,const boost::python::dict& arg) const
1490    {
1491       int num_data;
1492       char **names;
1493       escriptDataC *data;
1494       escriptDataC **ptr_data;
1495    
1496       extractArgsFromDict(arg, num_data, names, data, ptr_data);
1497       Finley_Mesh_saveDX(filename.c_str(), m_finleyMesh.get(), num_data, names, ptr_data);
1498     checkFinleyError();     checkFinleyError();
1499    
1500     /* win32 refactor */     /* win32 refactor */
1501     TMPMEMFREE(data);     TMPMEMFREE(data);
1502     TMPMEMFREE(ptr_data);     TMPMEMFREE(ptr_data);
1503     for(int i=0;i<num_data;i++)     for(int i=0; i<num_data; i++)
1504     {     {
1505        TMPMEMFREE(names[i]);        TMPMEMFREE(names[i]);
1506     }     }
# Line 1493  void MeshAdapter::saveDX(const std::stri Line 1509  void MeshAdapter::saveDX(const std::stri
1509     return;     return;
1510  }  }
1511    
1512  // saves a data array in openVTK format:  //
1513    // saves mesh and optionally data arrays in VTK format
1514    //
1515  void MeshAdapter::saveVTK(const std::string& filename,const boost::python::dict& arg) const  void MeshAdapter::saveVTK(const std::string& filename,const boost::python::dict& arg) const
1516  {  {
1517     unsigned int MAX_namelength=IS_THERE_A_REASON_FOR_THIS_MAGIC_NAME_LENGTH;     int num_data;
1518     const int num_data=boost::python::extract<int>(arg.attr("__len__")());     char **names;
1519     /* win32 refactor */     escriptDataC *data;
1520     char* *names = (num_data>0) ? TMPMEMALLOC(num_data,char*) : (char**)NULL;     escriptDataC **ptr_data;
    for(int i=0;i<num_data;i++)  
    {  
       names[i] = (MAX_namelength>0) ? TMPMEMALLOC(MAX_namelength,char) : (char*)NULL;  
    }  
   
    escriptDataC *data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC) : (escriptDataC*)NULL;  
    escriptDataC* *ptr_data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC*) : (escriptDataC**)NULL;  
   
    boost::python::list keys=arg.keys();  
    for (int i=0;i<num_data;++i) {  
       std::string n=boost::python::extract<std::string>(keys[i]);  
       escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);  
       if (dynamic_cast<const MeshAdapter&>(d.getFunctionSpace().getDomain()) !=*this)  
          throw FinleyAdapterException("Error  in saveVTK: Data must be defined on same Domain");  
       data[i]=d.getDataC();  
       ptr_data[i]=&(data[i]);  
       if (n.length()>MAX_namelength-1) {  
          strncpy(names[i],n.c_str(),MAX_namelength-1);  
          names[i][MAX_namelength-1]='\0';  
       } else {  
          strcpy(names[i],n.c_str());  
       }  
    }  
    Finley_Mesh_saveVTK(filename.c_str(),m_finleyMesh.get(),num_data,names,ptr_data);  
1521    
1522       extractArgsFromDict(arg, num_data, names, data, ptr_data);
1523       Finley_Mesh_saveVTK(filename.c_str(), m_finleyMesh.get(), num_data, names, ptr_data);
1524     checkFinleyError();     checkFinleyError();
1525    
1526     /* win32 refactor */     /* win32 refactor */
1527     TMPMEMFREE(data);     TMPMEMFREE(data);
1528     TMPMEMFREE(ptr_data);     TMPMEMFREE(ptr_data);
1529     for(int i=0;i<num_data;i++)     for(int i=0; i<num_data; i++)
1530     {     {
1531        TMPMEMFREE(names[i]);        TMPMEMFREE(names[i]);
1532     }     }
1533     TMPMEMFREE(names);     TMPMEMFREE(names);
   
    return;  
1534  }  }
1535                                                                                                                                                                        
1536                                                                                                                                                                        //
1537  // creates a SystemMatrixAdapter stiffness matrix an initializes it with zeros:  // creates a SystemMatrixAdapter stiffness matrix an initializes it with zeros
1538    //
1539  SystemMatrixAdapter MeshAdapter::newSystemMatrix(  SystemMatrixAdapter MeshAdapter::newSystemMatrix(
1540                                                   const int row_blocksize,                                                   const int row_blocksize,
1541                                                   const escript::FunctionSpace& row_functionspace,                                                   const escript::FunctionSpace& row_functionspace,
# Line 1550  SystemMatrixAdapter MeshAdapter::newSyst Line 1546  SystemMatrixAdapter MeshAdapter::newSyst
1546     int reduceRowOrder=0;     int reduceRowOrder=0;
1547     int reduceColOrder=0;     int reduceColOrder=0;
1548     // is the domain right?     // is the domain right?
1549     const MeshAdapter& row_domain=dynamic_cast<const MeshAdapter&>(row_functionspace.getDomain());     const MeshAdapter& row_domain=dynamic_cast<const MeshAdapter&>(*(row_functionspace.getDomain()));
1550     if (row_domain!=*this)     if (row_domain!=*this)
1551        throw FinleyAdapterException("Error - domain of row function space does not match the domain of matrix generator.");        throw FinleyAdapterException("Error - domain of row function space does not match the domain of matrix generator.");
1552     const MeshAdapter& col_domain=dynamic_cast<const MeshAdapter&>(column_functionspace.getDomain());     const MeshAdapter& col_domain=dynamic_cast<const MeshAdapter&>(*(column_functionspace.getDomain()));
1553     if (col_domain!=*this)     if (col_domain!=*this)
1554        throw FinleyAdapterException("Error - domain of columnn function space does not match the domain of matrix generator.");        throw FinleyAdapterException("Error - domain of columnn function space does not match the domain of matrix generator.");
1555     // is the function space type right     // is the function space type right
# Line 1589  SystemMatrixAdapter MeshAdapter::newSyst Line 1585  SystemMatrixAdapter MeshAdapter::newSyst
1585     Paso_SystemMatrixPattern_free(fsystemMatrixPattern);     Paso_SystemMatrixPattern_free(fsystemMatrixPattern);
1586     return SystemMatrixAdapter(fsystemMatrix,row_blocksize,row_functionspace,column_blocksize,column_functionspace);     return SystemMatrixAdapter(fsystemMatrix,row_blocksize,row_functionspace,column_blocksize,column_functionspace);
1587  }  }
1588    
1589    //
1590  // creates a TransportProblemAdapter  // creates a TransportProblemAdapter
1591    //
1592  TransportProblemAdapter MeshAdapter::newTransportProblem(  TransportProblemAdapter MeshAdapter::newTransportProblem(
1593                                                           const double theta,                                                           const double theta,
1594                                                           const int blocksize,                                                           const int blocksize,
# Line 1598  TransportProblemAdapter MeshAdapter::new Line 1597  TransportProblemAdapter MeshAdapter::new
1597  {  {
1598     int reduceOrder=0;     int reduceOrder=0;
1599     // is the domain right?     // is the domain right?
1600     const MeshAdapter& domain=dynamic_cast<const MeshAdapter&>(functionspace.getDomain());     const MeshAdapter& domain=dynamic_cast<const MeshAdapter&>(*(functionspace.getDomain()));
1601     if (domain!=*this)     if (domain!=*this)
1602        throw FinleyAdapterException("Error - domain of function space does not match the domain of transport problem generator.");        throw FinleyAdapterException("Error - domain of function space does not match the domain of transport problem generator.");
1603     // is the function space type right     // is the function space type right
# Line 1829  bool MeshAdapter::operator!=(const Abstr Line 1828  bool MeshAdapter::operator!=(const Abstr
1828     return !(operator==(other));     return !(operator==(other));
1829  }  }
1830    
1831  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
1832  {  {
1833     int out=Paso_SystemMatrix_getSystemMatrixTypeId(SystemMatrixAdapter::mapOptionToPaso(solver),SystemMatrixAdapter::mapOptionToPaso(package),symmetry?1:0);     Finley_Mesh* mesh=m_finleyMesh.get();
1834       int out=Paso_SystemMatrix_getSystemMatrixTypeId(SystemMatrixAdapter::mapOptionToPaso(solver),SystemMatrixAdapter::mapOptionToPaso(preconditioner), SystemMatrixAdapter::mapOptionToPaso(package),symmetry?1:0, mesh->MPIInfo);
1835       checkPasoError();
1836       return out;
1837    }
1838    int MeshAdapter::getTransportTypeId(const int solver, const int preconditioner, const int package, const bool symmetry) const
1839    {
1840       Finley_Mesh* mesh=m_finleyMesh.get();
1841       int out=Paso_FCTransportProblem_getTypeId(SystemMatrixAdapter::mapOptionToPaso(solver),SystemMatrixAdapter::mapOptionToPaso(preconditioner), SystemMatrixAdapter::mapOptionToPaso(package),symmetry?1:0, mesh->MPIInfo);
1842     checkPasoError();     checkPasoError();
1843     return out;     return out;
1844  }  }
# Line 1848  escript::Data MeshAdapter::getNormal() c Line 1855  escript::Data MeshAdapter::getNormal() c
1855    
1856  escript::Data MeshAdapter::getSize() const  escript::Data MeshAdapter::getSize() const
1857  {  {
1858     return function(asAbstractContinuousDomain()).getSize();     return escript::function(asAbstractContinuousDomain()).getSize();
1859  }  }
1860    
1861  int* MeshAdapter::borrowSampleReferenceIDs(int functionSpaceType) const  int* MeshAdapter::borrowSampleReferenceIDs(int functionSpaceType) const
# Line 2047  std::string MeshAdapter::showTagNames() Line 2054  std::string MeshAdapter::showTagNames()
2054     return temp.str();     return temp.str();
2055  }  }
2056    
2057    int MeshAdapter::getNumberOfTagsInUse(int functionSpaceCode) const
2058    {
2059      Finley_Mesh* mesh=m_finleyMesh.get();
2060      dim_t numTags=0;
2061      switch(functionSpaceCode) {
2062       case(Nodes):
2063              numTags=mesh->Nodes->numTagsInUse;
2064              break;
2065       case(ReducedNodes):
2066              throw FinleyAdapterException("Error - ReducedNodes does not support tags");
2067              break;
2068       case(DegreesOfFreedom):
2069              throw FinleyAdapterException("Error - DegreesOfFreedom does not support tags");
2070              break;
2071       case(ReducedDegreesOfFreedom):
2072              throw FinleyAdapterException("Error - ReducedDegreesOfFreedom does not support tags");
2073              break;
2074       case(Elements):
2075       case(ReducedElements):
2076              numTags=mesh->Elements->numTagsInUse;
2077              break;
2078       case(FaceElements):
2079       case(ReducedFaceElements):
2080              numTags=mesh->FaceElements->numTagsInUse;
2081              break;
2082       case(Points):
2083              numTags=mesh->Points->numTagsInUse;
2084              break;
2085       case(ContactElementsZero):
2086       case(ReducedContactElementsZero):
2087       case(ContactElementsOne):
2088       case(ReducedContactElementsOne):
2089              numTags=mesh->ContactElements->numTagsInUse;
2090              break;
2091       default:
2092          stringstream temp;
2093          temp << "Error - Finley does not know anything about function space type " << functionSpaceCode;
2094          throw FinleyAdapterException(temp.str());
2095      }
2096      return numTags;
2097    }
2098    int* MeshAdapter::borrowListOfTagsInUse(int functionSpaceCode) const
2099    {
2100      Finley_Mesh* mesh=m_finleyMesh.get();
2101      index_t* tags=NULL;
2102      switch(functionSpaceCode) {
2103       case(Nodes):
2104              tags=mesh->Nodes->tagsInUse;
2105              break;
2106       case(ReducedNodes):
2107              throw FinleyAdapterException("Error - ReducedNodes does not support tags");
2108              break;
2109       case(DegreesOfFreedom):
2110              throw FinleyAdapterException("Error - DegreesOfFreedom does not support tags");
2111              break;
2112       case(ReducedDegreesOfFreedom):
2113              throw FinleyAdapterException("Error - ReducedDegreesOfFreedom does not support tags");
2114              break;
2115       case(Elements):
2116       case(ReducedElements):
2117              tags=mesh->Elements->tagsInUse;
2118              break;
2119       case(FaceElements):
2120       case(ReducedFaceElements):
2121              tags=mesh->FaceElements->tagsInUse;
2122              break;
2123       case(Points):
2124              tags=mesh->Points->tagsInUse;
2125              break;
2126       case(ContactElementsZero):
2127       case(ReducedContactElementsZero):
2128       case(ContactElementsOne):
2129       case(ReducedContactElementsOne):
2130              tags=mesh->ContactElements->tagsInUse;
2131              break;
2132       default:
2133          stringstream temp;
2134          temp << "Error - Finley does not know anything about function space type " << functionSpaceCode;
2135          throw FinleyAdapterException(temp.str());
2136      }
2137      return tags;
2138    }
2139    
2140    
2141    bool MeshAdapter::canTag(int functionSpaceCode) const
2142    {
2143      switch(functionSpaceCode) {
2144       case(Nodes):
2145       case(Elements):
2146       case(ReducedElements):
2147       case(FaceElements):
2148       case(ReducedFaceElements):
2149       case(Points):
2150       case(ContactElementsZero):
2151       case(ReducedContactElementsZero):
2152       case(ContactElementsOne):
2153       case(ReducedContactElementsOne):
2154              return true;
2155       case(ReducedNodes):
2156       case(DegreesOfFreedom):
2157       case(ReducedDegreesOfFreedom):
2158          return false;
2159       default:
2160        return false;
2161      }
2162    }
2163    
2164    
2165  }  // end of namespace  }  // end of namespace

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

  ViewVC Help
Powered by ViewVC 1.1.26