/[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 2087 by jfenwick, Mon Nov 24 04:51:30 2008 UTC revision 2150 by caltinay, Wed Dec 10 05:57:12 2008 UTC
# Line 27  extern "C" { Line 27  extern "C" {
27  }  }
28  #include <vector>  #include <vector>
29    
 #define IS_THERE_A_REASON_FOR_THIS_MAGIC_NAME_LENGTH  256  
   
30  using namespace std;  using namespace std;
31  using namespace escript;  using namespace escript;
32    
# Line 646  int MeshAdapter::getDiracDeltaFunctionCo Line 644  int MeshAdapter::getDiracDeltaFunctionCo
644  //  //
645  int MeshAdapter::getDim() const  int MeshAdapter::getDim() const
646  {  {
647     int numDim=Finley_Mesh_getDim(m_finleyMesh.get());     Finley_Mesh* mesh=m_finleyMesh.get();
648       int numDim=Finley_Mesh_getDim(mesh);
649     checkFinleyError();     checkFinleyError();
650     return numDim;     return numDim;
651  }  }
# Line 1461  void MeshAdapter::setNewX(const escript: Line 1460  void MeshAdapter::setNewX(const escript:
1460  // saves a data array in openDX format:  // saves a data array in openDX format:
1461  void MeshAdapter::saveDX(const std::string& filename,const boost::python::dict& arg) const  void MeshAdapter::saveDX(const std::string& filename,const boost::python::dict& arg) const
1462  {  {
    unsigned int MAX_namelength=IS_THERE_A_REASON_FOR_THIS_MAGIC_NAME_LENGTH;  
1463     const int num_data=boost::python::extract<int>(arg.attr("__len__")());     const int num_data=boost::python::extract<int>(arg.attr("__len__")());
1464     /* win32 refactor */     /* win32 refactor */
1465     char* *names = (num_data>0) ? TMPMEMALLOC(num_data,char*) : (char**)NULL;     char **names = (num_data>0) ? TMPMEMALLOC(num_data, char*) : (char**)NULL;
    for(int i=0;i<num_data;i++)  
    {  
       names[i] = (MAX_namelength>0) ? TMPMEMALLOC(MAX_namelength,char) : (char*)NULL;  
    }  
1466    
1467     escriptDataC *data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC) : (escriptDataC*)NULL;     escriptDataC *data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC) : (escriptDataC*)NULL;
1468     escriptDataC* *ptr_data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC*) : (escriptDataC**)NULL;     escriptDataC* *ptr_data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC*) : (escriptDataC**)NULL;
1469    
1470     boost::python::list keys=arg.keys();     boost::python::list keys=arg.keys();
1471     for (int i=0;i<num_data;++i) {     for (int i=0; i<num_data; ++i) {
1472        std::string n=boost::python::extract<std::string>(keys[i]);        std::string n=boost::python::extract<std::string>(keys[i]);
1473        escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);        escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);
1474        if (dynamic_cast<const MeshAdapter&>(*(d.getFunctionSpace().getDomain())) !=*this)        if (dynamic_cast<const MeshAdapter&>(*(d.getFunctionSpace().getDomain())) !=*this)
1475           throw FinleyAdapterException("Error  in saveVTK: Data must be defined on same Domain");           throw FinleyAdapterException("Error in saveDX: Data must be defined on same Domain");
1476        data[i]=d.getDataC();        data[i]=d.getDataC();
1477        ptr_data[i]= &(data[i]);        ptr_data[i]= &(data[i]);
1478        if (n.length()>MAX_namelength-1) {        names[i] = TMPMEMALLOC(n.length()+1, char);
1479           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());  
       }  
1480     }     }
1481     Finley_Mesh_saveDX(filename.c_str(),m_finleyMesh.get(),num_data,names,ptr_data);     Finley_Mesh_saveDX(filename.c_str(),m_finleyMesh.get(),num_data,names,ptr_data);
1482     checkFinleyError();     checkFinleyError();
# Line 1494  void MeshAdapter::saveDX(const std::stri Line 1484  void MeshAdapter::saveDX(const std::stri
1484     /* win32 refactor */     /* win32 refactor */
1485     TMPMEMFREE(data);     TMPMEMFREE(data);
1486     TMPMEMFREE(ptr_data);     TMPMEMFREE(ptr_data);
1487     for(int i=0;i<num_data;i++)     for(int i=0; i<num_data; i++)
1488     {     {
1489        TMPMEMFREE(names[i]);        TMPMEMFREE(names[i]);
1490     }     }
# Line 1506  void MeshAdapter::saveDX(const std::stri Line 1496  void MeshAdapter::saveDX(const std::stri
1496  // saves a data array in openVTK format:  // saves a data array in openVTK format:
1497  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
1498  {  {
    unsigned int MAX_namelength=IS_THERE_A_REASON_FOR_THIS_MAGIC_NAME_LENGTH;  
1499     const int num_data=boost::python::extract<int>(arg.attr("__len__")());     const int num_data=boost::python::extract<int>(arg.attr("__len__")());
1500     /* win32 refactor */     /* win32 refactor */
1501     char* *names = (num_data>0) ? TMPMEMALLOC(num_data,char*) : (char**)NULL;     char **names = (num_data>0) ? TMPMEMALLOC(num_data, char*) : (char**)NULL;
    for(int i=0;i<num_data;i++)  
    {  
       names[i] = (MAX_namelength>0) ? TMPMEMALLOC(MAX_namelength,char) : (char*)NULL;  
    }  
1502    
1503     escriptDataC *data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC) : (escriptDataC*)NULL;     escriptDataC *data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC) : (escriptDataC*)NULL;
1504     escriptDataC* *ptr_data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC*) : (escriptDataC**)NULL;     escriptDataC* *ptr_data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC*) : (escriptDataC**)NULL;
# Line 1523  void MeshAdapter::saveVTK(const std::str Line 1508  void MeshAdapter::saveVTK(const std::str
1508        std::string n=boost::python::extract<std::string>(keys[i]);        std::string n=boost::python::extract<std::string>(keys[i]);
1509        escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);        escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);
1510        if (dynamic_cast<const MeshAdapter&>(*(d.getFunctionSpace().getDomain())) !=*this)        if (dynamic_cast<const MeshAdapter&>(*(d.getFunctionSpace().getDomain())) !=*this)
1511           throw FinleyAdapterException("Error  in saveVTK: Data must be defined on same Domain");           throw FinleyAdapterException("Error in saveVTK: Data must be defined on same Domain");
1512        data[i]=d.getDataC();        data[i]=d.getDataC();
1513        ptr_data[i]=&(data[i]);        ptr_data[i]=&(data[i]);
1514        if (n.length()>MAX_namelength-1) {        names[i] = TMPMEMALLOC(n.length()+1, char);
1515           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());  
       }  
1516     }     }
1517     Finley_Mesh_saveVTK(filename.c_str(),m_finleyMesh.get(),num_data,names,ptr_data);     Finley_Mesh_saveVTK(filename.c_str(),m_finleyMesh.get(),num_data,names,ptr_data);
1518    

Legend:
Removed from v.2087  
changed lines
  Added in v.2150

  ViewVC Help
Powered by ViewVC 1.1.26