/[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 2149 by caltinay, Wed Dec 10 05:08:17 2008 UTC revision 2315 by gross, Wed Mar 18 00:38:48 2009 UTC
# Line 25  Line 25 
25  extern "C" {  extern "C" {
26  #include "esysUtils/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 1446  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();
# Line 1459  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 saveDX: 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 1504  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 1600  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 1842  bool MeshAdapter::operator!=(const Abstr Line 1830  bool MeshAdapter::operator!=(const Abstr
1830    
1831  int MeshAdapter::getSystemMatrixTypeId(const int solver, const int preconditioner, 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(preconditioner), 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();     checkPasoError();
1836     return out;     return out;
1837  }  }
1838  int MeshAdapter::getTransportTypeId(const int solver, const int preconditioner, const int package, const bool symmetry) const  int MeshAdapter::getTransportTypeId(const int solver, const int preconditioner, const int package, const bool symmetry) const
1839  {  {
1840     int out=Paso_FCTransportProblem_getTypeId(SystemMatrixAdapter::mapOptionToPaso(solver),SystemMatrixAdapter::mapOptionToPaso(preconditioner), SystemMatrixAdapter::mapOptionToPaso(package),symmetry?1:0);     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  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26