/[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 3675 by jfenwick, Thu Nov 17 00:53:38 2011 UTC revision 4346 by jfenwick, Tue Apr 2 04:46:45 2013 UTC
# Line 1  Line 1 
1    
2  /*******************************************************  /*****************************************************************************
3  *  *
4  * Copyright (c) 2003-2010 by University of Queensland  * Copyright (c) 2003-2013 by University of Queensland
5  * Earth Systems Science Computational Center (ESSCC)  * http://www.uq.edu.au
 * http://www.uq.edu.au/esscc  
6  *  *
7  * Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
8  * Licensed under the Open Software License version 3.0  * Licensed under the Open Software License version 3.0
9  * http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
10  *  *
11  *******************************************************/  * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12    * Development since 2012 by School of Earth Sciences
13    *
14    *****************************************************************************/
15    
16  #include <pasowrap/PasoException.h>  #include <pasowrap/PasoException.h>
17  #include <pasowrap/TransportProblemAdapter.h>  #include <pasowrap/TransportProblemAdapter.h>
# Line 19  Line 21 
21  #ifdef USE_NETCDF  #ifdef USE_NETCDF
22  #include <netcdfcpp.h>  #include <netcdfcpp.h>
23  #endif  #endif
 extern "C" {  
24  #include "esysUtils/blocktimer.h"  #include "esysUtils/blocktimer.h"
 }  
25    
26  #include <boost/python/import.hpp>  #include <boost/python/import.hpp>
27    
# Line 779  void MeshAdapter::addPDEToSystem( Line 779  void MeshAdapter::addPDEToSystem(
779     SystemMatrixAdapter* smat=dynamic_cast<SystemMatrixAdapter*>(&mat);     SystemMatrixAdapter* smat=dynamic_cast<SystemMatrixAdapter*>(&mat);
780     if (smat==0)     if (smat==0)
781     {     {
782      throw FinleyAdapterException("finley only supports its own system matrices.");      throw FinleyAdapterException("finley only supports Paso system matrices.");
783     }     }
784     escriptDataC _rhs=rhs.getDataC();     escriptDataC _rhs=rhs.getDataC();
785     escriptDataC _A  =A.getDataC();     escriptDataC _A  =A.getDataC();
# Line 874  void MeshAdapter::addPDEToTransportProbl Line 874  void MeshAdapter::addPDEToTransportProbl
874                                             const escript::Data& d_contact,const escript::Data& y_contact,                                             const escript::Data& d_contact,const escript::Data& y_contact,
875                                             const escript::Data& d_dirac, const escript::Data& y_dirac) const                                             const escript::Data& d_dirac, const escript::Data& y_dirac) const
876  {  {
877     paso::TransportProblemAdapter* tpa=dynamic_cast<paso::TransportProblemAdapter*>(&tp);     TransportProblemAdapter* tpa=dynamic_cast<TransportProblemAdapter*>(&tp);
878     if (tpa==0)     if (tpa==0)
879     {     {
880      throw FinleyAdapterException("finley only supports its own transport problems.");      throw FinleyAdapterException("finley only supports Paso transport problems.");
881     }     }
882    
883    
# Line 1512  void MeshAdapter::setNewX(const escript: Line 1512  void MeshAdapter::setNewX(const escript:
1512         tmp = new_x.getDataC();         tmp = new_x.getDataC();
1513         Finley_Mesh_setCoordinates(mesh,&tmp);         Finley_Mesh_setCoordinates(mesh,&tmp);
1514     } else {     } else {
1515         escript::Data new_x_inter=escript::Data( new_x,  continuousFunction(*this) );         throw FinleyAdapterException("As of version escript3.3 - SetNewX only accepts ContinuousFunction arguments please interpolate.");    
1516    /*       escript::Data new_x_inter=escript::Data( new_x,  continuousFunction(*this) );
1517         tmp = new_x_inter.getDataC();         tmp = new_x_inter.getDataC();
1518         Finley_Mesh_setCoordinates(mesh,&tmp);         Finley_Mesh_setCoordinates(mesh,&tmp);*/
1519     }     }
1520     checkFinleyError();     checkFinleyError();
1521  }  }
1522    
 //  
 // Helper for the save* methods. Extracts optional data variable names and the  
 // corresponding pointers from python dictionary. Caller must free arrays.  
 //  
 void MeshAdapter::extractArgsFromDict(const boost::python::dict& arg, int& numData, char**& names, escriptDataC*& data, escriptDataC**& dataPtr) const  
 {  
    numData = boost::python::extract<int>(arg.attr("__len__")());  
    /* win32 refactor */  
    names = (numData>0) ? TMPMEMALLOC(numData, char*) : (char**)NULL;  
    data = (numData>0) ? TMPMEMALLOC(numData,escriptDataC) : (escriptDataC*)NULL;  
    dataPtr = (numData>0) ? TMPMEMALLOC(numData,escriptDataC*) : (escriptDataC**)NULL;  
   
    boost::python::list keys=arg.keys();  
    for (int i=0; i<numData; ++i) {  
       string n=boost::python::extract<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: Data must be defined on same Domain");  
       data[i] = d.getDataC();  
       dataPtr[i] = &(data[i]);  
       names[i] = TMPMEMALLOC(n.length()+1, char);  
       strcpy(names[i], n.c_str());  
    }  
 }  
   
 //  
 // saves mesh and optionally data arrays in openDX format  
 //  
 void MeshAdapter::saveDX(const string& filename,const boost::python::dict& arg) const  
 {  
    int num_data;  
    char **names;  
    escriptDataC *data;  
    escriptDataC **ptr_data;  
   
    extractArgsFromDict(arg, num_data, names, data, ptr_data);  
    Finley_Mesh_saveDX(filename.c_str(), m_finleyMesh.get(), num_data, names, ptr_data);  
    checkFinleyError();  
   
    /* win32 refactor */  
    TMPMEMFREE(data);  
    TMPMEMFREE(ptr_data);  
    for(int i=0; i<num_data; i++)  
    {  
       TMPMEMFREE(names[i]);  
    }  
    TMPMEMFREE(names);  
   
    return;  
 }  
   
 //  
 // saves mesh and optionally data arrays in VTK format  
 //  
 void MeshAdapter::saveVTK(const string& filename,const boost::python::dict& arg,  const string& metadata, const string& metadata_schema) const  
 {  
     boost::python::object pySaveVTK = boost::python::import("esys.weipa").attr("_saveVTK");  
     pySaveVTK(filename, const_cast<MeshAdapter*>(this)->getPtr(),  
               metadata, metadata_schema, arg);  
 }  
   
1523  bool MeshAdapter::ownSample(int fs_code, index_t id) const  bool MeshAdapter::ownSample(int fs_code, index_t id) const
1524  {  {
1525        if (getMPISize() > 1) {
1526  #ifdef ESYS_MPI  #ifdef ESYS_MPI
1527      index_t myFirstNode=0, myLastNode=0, k=0;          index_t myFirstNode=0, myLastNode=0, k=0;
1528      index_t* globalNodeIndex=0;          index_t* globalNodeIndex=0;
1529      Finley_Mesh* mesh_p=m_finleyMesh.get();          Finley_Mesh* mesh_p=m_finleyMesh.get();
1530      if (fs_code == FINLEY_REDUCED_NODES)          /*
1531      {           * this method is only used by saveDataCSV which would use the returned
1532      myFirstNode = Finley_NodeFile_getFirstReducedNode(mesh_p->Nodes);           * values for reduced nodes wrongly so this case is disabled for now
1533      myLastNode = Finley_NodeFile_getLastReducedNode(mesh_p->Nodes);          if (fs_code == FINLEY_REDUCED_NODES)
1534      globalNodeIndex = Finley_NodeFile_borrowGlobalReducedNodesIndex(mesh_p->Nodes);          {
1535      }              myFirstNode = Finley_NodeFile_getFirstReducedNode(mesh_p->Nodes);
1536      else              myLastNode = Finley_NodeFile_getLastReducedNode(mesh_p->Nodes);
1537      {              globalNodeIndex = Finley_NodeFile_borrowGlobalReducedNodesIndex(mesh_p->Nodes);
1538      myFirstNode = Finley_NodeFile_getFirstNode(mesh_p->Nodes);          }
1539      myLastNode = Finley_NodeFile_getLastNode(mesh_p->Nodes);          else
1540      globalNodeIndex = Finley_NodeFile_borrowGlobalNodesIndex(mesh_p->Nodes);          */
1541      }          if (fs_code == FINLEY_NODES)
1542      k=globalNodeIndex[id];          {
1543      return static_cast<bool>( (myFirstNode <= k) && (k < myLastNode) );              myFirstNode = Finley_NodeFile_getFirstNode(mesh_p->Nodes);
1544                myLastNode = Finley_NodeFile_getLastNode(mesh_p->Nodes);
1545                globalNodeIndex = Finley_NodeFile_borrowGlobalNodesIndex(mesh_p->Nodes);
1546            }
1547            else
1548            {
1549                throw FinleyAdapterException("Unsupported function space type for ownSample()");
1550            }
1551    
1552            k=globalNodeIndex[id];
1553            return static_cast<bool>( (myFirstNode <= k) && (k < myLastNode) );
1554  #endif  #endif
1555        }
1556      return true;      return true;
1557  }  }
1558    
1559    
   
1560  //  //
1561  // creates a SystemMatrixAdapter stiffness matrix an initializes it with zeros  // creates a SystemMatrixAdapter stiffness matrix an initializes it with zeros
1562  //  //
# Line 1624  ASM_ptr MeshAdapter::newSystemMatrix( Line 1575  ASM_ptr MeshAdapter::newSystemMatrix(
1575        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.");
1576     const MeshAdapter& col_domain=dynamic_cast<const MeshAdapter&>(*(column_functionspace.getDomain()));     const MeshAdapter& col_domain=dynamic_cast<const MeshAdapter&>(*(column_functionspace.getDomain()));
1577     if (col_domain!=*this)     if (col_domain!=*this)
1578        throw FinleyAdapterException("Error - domain of columnn function space does not match the domain of matrix generator.");        throw FinleyAdapterException("Error - domain of column function space does not match the domain of matrix generator.");
1579     // is the function space type right     // is the function space type right
1580     if (row_functionspace.getTypeCode()==DegreesOfFreedom) {     if (row_functionspace.getTypeCode()==DegreesOfFreedom) {
1581        reduceRowOrder=0;        reduceRowOrder=0;
# Line 1665  ASM_ptr MeshAdapter::newSystemMatrix( Line 1616  ASM_ptr MeshAdapter::newSystemMatrix(
1616  // creates a TransportProblemAdapter  // creates a TransportProblemAdapter
1617  //  //
1618  ATP_ptr MeshAdapter::newTransportProblem(  ATP_ptr MeshAdapter::newTransportProblem(
                                                          const bool useBackwardEuler,  
1619                                                           const int blocksize,                                                           const int blocksize,
1620                                                           const escript::FunctionSpace& functionspace,                                                           const escript::FunctionSpace& functionspace,
1621                                                           const int type) const                                                           const int type) const
# Line 1688  ATP_ptr MeshAdapter::newTransportProblem Line 1638  ATP_ptr MeshAdapter::newTransportProblem
1638     Paso_SystemMatrixPattern* fsystemMatrixPattern=Finley_getPattern(getFinley_Mesh(),reduceOrder,reduceOrder);     Paso_SystemMatrixPattern* fsystemMatrixPattern=Finley_getPattern(getFinley_Mesh(),reduceOrder,reduceOrder);
1639     checkFinleyError();     checkFinleyError();
1640     Paso_TransportProblem* transportProblem;     Paso_TransportProblem* transportProblem;
1641     transportProblem=Paso_TransportProblem_alloc(useBackwardEuler,fsystemMatrixPattern,blocksize);     transportProblem=Paso_TransportProblem_alloc(fsystemMatrixPattern,blocksize);
1642     checkPasoError();     checkPasoError();
1643     Paso_SystemMatrixPattern_free(fsystemMatrixPattern);     Paso_SystemMatrixPattern_free(fsystemMatrixPattern);
1644     TransportProblemAdapter* tpa=new TransportProblemAdapter(transportProblem,useBackwardEuler,blocksize,functionspace);     TransportProblemAdapter* tpa=new TransportProblemAdapter(transportProblem,blocksize,functionspace);
1645     return ATP_ptr(tpa);     return ATP_ptr(tpa);
1646  //   return TransportProblemAdapter(transportProblem,useBackwardEuler,blocksize,functionspace);  //   return TransportProblemAdapter(transportProblem, blocksize,functionspace);
1647  }  }
1648    
1649  //  //
# Line 2029  bool MeshAdapter::probeInterpolationOnDo Line 1979  bool MeshAdapter::probeInterpolationOnDo
1979     return false;     return false;
1980  }  }
1981    
1982    signed char MeshAdapter::preferredInterpolationOnDomain(int functionSpaceType_source,int functionSpaceType_target) const
1983    {
1984        if (probeInterpolationOnDomain(functionSpaceType_source, functionSpaceType_target))
1985        {
1986            return 1;
1987        }
1988        else if (probeInterpolationOnDomain(functionSpaceType_target, functionSpaceType_source))
1989        {
1990            return -1;
1991        }
1992        return 0;
1993    }  
1994      
1995  bool MeshAdapter::probeInterpolationACross(int functionSpaceType_source,const AbstractDomain& targetDomain, int functionSpaceType_target) const  bool MeshAdapter::probeInterpolationACross(int functionSpaceType_source,const AbstractDomain& targetDomain, int functionSpaceType_target) const
1996  {  {
1997     return false;     return false;
# Line 2052  bool MeshAdapter::operator!=(const Abstr Line 2015  bool MeshAdapter::operator!=(const Abstr
2015  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
2016  {  {
2017     Finley_Mesh* mesh=m_finleyMesh.get();     Finley_Mesh* mesh=m_finleyMesh.get();
2018     int out=Paso_SystemMatrix_getSystemMatrixTypeId(SystemMatrixAdapter::mapOptionToPaso(solver),SystemMatrixAdapter::mapOptionToPaso(preconditioner), SystemMatrixAdapter::mapOptionToPaso(package),symmetry?1:0, mesh->MPIInfo);     return SystemMatrixAdapter::getSystemMatrixTypeId(solver, preconditioner,
2019     checkPasoError();             package, symmetry, mesh->MPIInfo);
    return out;  
2020  }  }
2021    
2022  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
2023  {  {
2024     Finley_Mesh* mesh=m_finleyMesh.get();     Finley_Mesh* mesh=m_finleyMesh.get();
2025     int out=Paso_TransportProblem_getTypeId(SystemMatrixAdapter::mapOptionToPaso(solver),SystemMatrixAdapter::mapOptionToPaso(preconditioner), SystemMatrixAdapter::mapOptionToPaso(package),symmetry?1:0, mesh->MPIInfo);     return TransportProblemAdapter::getTransportTypeId(solver, preconditioner,
2026     checkPasoError();             package, symmetry, mesh->MPIInfo);
    return out;  
2027  }  }
2028    
2029  escript::Data MeshAdapter::getX() const  escript::Data MeshAdapter::getX() const
# Line 2242  void MeshAdapter::setTagMap(const string Line 2204  void MeshAdapter::setTagMap(const string
2204  {  {
2205     Finley_Mesh* mesh=m_finleyMesh.get();     Finley_Mesh* mesh=m_finleyMesh.get();
2206     Finley_Mesh_addTagMap(mesh, name.c_str(),tag);     Finley_Mesh_addTagMap(mesh, name.c_str(),tag);
2207     checkPasoError();     checkFinleyError();
2208     // throwStandardException("MeshAdapter::set TagMap is not implemented.");     // throwStandardException("MeshAdapter::set TagMap is not implemented.");
2209  }  }
2210    
# Line 2251  int MeshAdapter::getTag(const string& na Line 2213  int MeshAdapter::getTag(const string& na
2213     Finley_Mesh* mesh=m_finleyMesh.get();     Finley_Mesh* mesh=m_finleyMesh.get();
2214     int tag=0;     int tag=0;
2215     tag=Finley_Mesh_getTag(mesh, name.c_str());     tag=Finley_Mesh_getTag(mesh, name.c_str());
2216     checkPasoError();     checkFinleyError();
2217     // throwStandardException("MeshAdapter::getTag is not implemented.");     // throwStandardException("MeshAdapter::getTag is not implemented.");
2218     return tag;     return tag;
2219  }  }
# Line 2466  void MeshAdapter:: addDiracPoints(const Line 2428  void MeshAdapter:: addDiracPoints(const
2428        }        }
2429                
2430        Finley_Mesh_addPoints(mesh, numPoints, points_ptr, tags_ptr);        Finley_Mesh_addPoints(mesh, numPoints, points_ptr, tags_ptr);
2431        checkPasoError();        checkFinleyError();
2432                
2433        TMPMEMFREE(points_ptr);        TMPMEMFREE(points_ptr);
2434        TMPMEMFREE(tags_ptr);        TMPMEMFREE(tags_ptr);

Legend:
Removed from v.3675  
changed lines
  Added in v.4346

  ViewVC Help
Powered by ViewVC 1.1.26