/[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 1801 by ksteube, Fri Sep 19 01:37:09 2008 UTC revision 2149 by caltinay, Wed Dec 10 05:08:17 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 24  Line 23 
23  #include "paso/Paso_MPI.h"  #include "paso/Paso_MPI.h"
24  #endif  #endif
25  extern "C" {  extern "C" {
26  #include "escript/blocktimer.h"  #include "esysUtils/blocktimer.h"
27  }  }
28  #include <vector>  #include <vector>
29    
# Line 87  int MeshAdapter::getMPIRank() const Line 86  int MeshAdapter::getMPIRank() const
86  {  {
87     return m_finleyMesh.get()->MPIInfo->rank;     return m_finleyMesh.get()->MPIInfo->rank;
88  }  }
89    void MeshAdapter::MPIBarrier() const
90    {
91    #ifdef PASO_MPI
92       MPI_Barrier(m_finleyMesh.get()->MPIInfo->comm);
93    #endif
94       return;
95    }
96    bool MeshAdapter::onMasterProcessor() const
97    {
98       return m_finleyMesh.get()->MPIInfo->rank == 0;
99    }
100    
101    
102  Finley_Mesh* MeshAdapter::getFinley_Mesh() const {  Finley_Mesh* MeshAdapter::getFinley_Mesh() const {
# Line 110  void MeshAdapter::Print_Mesh_Info(const Line 120  void MeshAdapter::Print_Mesh_Info(const
120  void MeshAdapter::dump(const std::string& fileName) const  void MeshAdapter::dump(const std::string& fileName) const
121  {  {
122  #ifdef USE_NETCDF  #ifdef USE_NETCDF
123     const NcDim* ncdims[12];     const NcDim* ncdims[12] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
124     NcVar *ids;     NcVar *ids;
125     int *int_ptr;     int *int_ptr;
126     Finley_Mesh *mesh = m_finleyMesh.get();     Finley_Mesh *mesh = m_finleyMesh.get();
# Line 636  int MeshAdapter::getDiracDeltaFunctionCo Line 646  int MeshAdapter::getDiracDeltaFunctionCo
646  //  //
647  int MeshAdapter::getDim() const  int MeshAdapter::getDim() const
648  {  {
649     int numDim=Finley_Mesh_getDim(m_finleyMesh.get());     Finley_Mesh* mesh=m_finleyMesh.get();
650       int numDim=Finley_Mesh_getDim(mesh);
651     checkFinleyError();     checkFinleyError();
652     return numDim;     return numDim;
653  }  }
# Line 861  void MeshAdapter::addPDEToTransportProbl Line 872  void MeshAdapter::addPDEToTransportProbl
872  //  //
873  void MeshAdapter::interpolateOnDomain(escript::Data& target,const escript::Data& in) const  void MeshAdapter::interpolateOnDomain(escript::Data& target,const escript::Data& in) const
874  {  {
875     const MeshAdapter& inDomain=dynamic_cast<const MeshAdapter&>(in.getFunctionSpace().getDomain());     const MeshAdapter& inDomain=dynamic_cast<const MeshAdapter&>(*(in.getFunctionSpace().getDomain()));
876     const MeshAdapter& targetDomain=dynamic_cast<const MeshAdapter&>(target.getFunctionSpace().getDomain());     const MeshAdapter& targetDomain=dynamic_cast<const MeshAdapter&>(*(target.getFunctionSpace().getDomain()));
877     if (inDomain!=*this)       if (inDomain!=*this)  
878        throw FinleyAdapterException("Error - Illegal domain of interpolant.");        throw FinleyAdapterException("Error - Illegal domain of interpolant.");
879     if (targetDomain!=*this)     if (targetDomain!=*this)
# Line 1146  void MeshAdapter::interpolateOnDomain(es Line 1157  void MeshAdapter::interpolateOnDomain(es
1157  //  //
1158  void MeshAdapter::setToX(escript::Data& arg) const  void MeshAdapter::setToX(escript::Data& arg) const
1159  {  {
1160     const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(arg.getFunctionSpace().getDomain());     const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(*(arg.getFunctionSpace().getDomain()));
1161     if (argDomain!=*this)     if (argDomain!=*this)
1162        throw FinleyAdapterException("Error - Illegal domain of data point locations");        throw FinleyAdapterException("Error - Illegal domain of data point locations");
1163     Finley_Mesh* mesh=m_finleyMesh.get();     Finley_Mesh* mesh=m_finleyMesh.get();
# Line 1169  void MeshAdapter::setToX(escript::Data& Line 1180  void MeshAdapter::setToX(escript::Data&
1180  //  //
1181  void MeshAdapter::setToNormal(escript::Data& normal) const  void MeshAdapter::setToNormal(escript::Data& normal) const
1182  {  {
1183     const MeshAdapter& normalDomain=dynamic_cast<const MeshAdapter&>(normal.getFunctionSpace().getDomain());  /*   const MeshAdapter& normalDomain=dynamic_cast<const MeshAdapter&>(normal.getFunctionSpace().getDomain());*/
1184       const MeshAdapter& normalDomain=dynamic_cast<const MeshAdapter&>(*(normal.getFunctionSpace().getDomain()));
1185     if (normalDomain!=*this)     if (normalDomain!=*this)
1186        throw FinleyAdapterException("Error - Illegal domain of normal locations");        throw FinleyAdapterException("Error - Illegal domain of normal locations");
1187     Finley_Mesh* mesh=m_finleyMesh.get();     Finley_Mesh* mesh=m_finleyMesh.get();
# Line 1224  void MeshAdapter::setToNormal(escript::D Line 1236  void MeshAdapter::setToNormal(escript::D
1236  //  //
1237  void MeshAdapter::interpolateACross(escript::Data& target,const escript::Data& source) const  void MeshAdapter::interpolateACross(escript::Data& target,const escript::Data& source) const
1238  {  {
1239     const MeshAdapter& targetDomain=dynamic_cast<const MeshAdapter&>(target.getFunctionSpace().getDomain());     const_Domain_ptr targetDomain_p=target.getFunctionSpace().getDomain();
1240     if (targetDomain!=*this)     const MeshAdapter* targetDomain=dynamic_cast<const MeshAdapter*>(targetDomain_p.get());
1241       if (targetDomain!=this)
1242        throw FinleyAdapterException("Error - Illegal domain of interpolation target");        throw FinleyAdapterException("Error - Illegal domain of interpolation target");
1243    
1244     throw FinleyAdapterException("Error - Finley does not allow interpolation across domains yet.");     throw FinleyAdapterException("Error - Finley does not allow interpolation across domains yet.");
# Line 1236  void MeshAdapter::interpolateACross(escr Line 1249  void MeshAdapter::interpolateACross(escr
1249  //  //
1250  void MeshAdapter::setToIntegrals(std::vector<double>& integrals,const escript::Data& arg) const  void MeshAdapter::setToIntegrals(std::vector<double>& integrals,const escript::Data& arg) const
1251  {  {
1252     const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(arg.getFunctionSpace().getDomain());     const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(*(arg.getFunctionSpace().getDomain()));
1253     if (argDomain!=*this)     if (argDomain!=*this)
1254        throw FinleyAdapterException("Error - Illegal domain of integration kernel");        throw FinleyAdapterException("Error - Illegal domain of integration kernel");
1255    
# Line 1247  void MeshAdapter::setToIntegrals(std::ve Line 1260  void MeshAdapter::setToIntegrals(std::ve
1260     escriptDataC _arg=arg.getDataC();     escriptDataC _arg=arg.getDataC();
1261     switch(arg.getFunctionSpace().getTypeCode()) {     switch(arg.getFunctionSpace().getTypeCode()) {
1262     case(Nodes):     case(Nodes):
1263     temp=escript::Data( arg, function(asAbstractContinuousDomain()) );     temp=escript::Data( arg, escript::function(asAbstractContinuousDomain()) );
1264     _temp=temp.getDataC();     _temp=temp.getDataC();
1265     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1266     break;     break;
1267     case(ReducedNodes):     case(ReducedNodes):
1268     temp=escript::Data( arg, function(asAbstractContinuousDomain()) );     temp=escript::Data( arg, escript::function(asAbstractContinuousDomain()) );
1269     _temp=temp.getDataC();     _temp=temp.getDataC();
1270     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1271     break;     break;
# Line 1284  void MeshAdapter::setToIntegrals(std::ve Line 1297  void MeshAdapter::setToIntegrals(std::ve
1297     Finley_Assemble_integrate(mesh->Nodes,mesh->ContactElements,&_arg,&integrals[0]);     Finley_Assemble_integrate(mesh->Nodes,mesh->ContactElements,&_arg,&integrals[0]);
1298     break;     break;
1299     case(DegreesOfFreedom):     case(DegreesOfFreedom):
1300     temp=escript::Data( arg, function(asAbstractContinuousDomain()) );     temp=escript::Data( arg, escript::function(asAbstractContinuousDomain()) );
1301     _temp=temp.getDataC();     _temp=temp.getDataC();
1302     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1303     break;     break;
1304     case(ReducedDegreesOfFreedom):     case(ReducedDegreesOfFreedom):
1305     temp=escript::Data( arg, function(asAbstractContinuousDomain()) );     temp=escript::Data( arg, escript::function(asAbstractContinuousDomain()) );
1306     _temp=temp.getDataC();     _temp=temp.getDataC();
1307     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1308     break;     break;
# Line 1308  void MeshAdapter::setToIntegrals(std::ve Line 1321  void MeshAdapter::setToIntegrals(std::ve
1321  //  //
1322  void MeshAdapter::setToGradient(escript::Data& grad,const escript::Data& arg) const  void MeshAdapter::setToGradient(escript::Data& grad,const escript::Data& arg) const
1323  {  {
1324     const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(arg.getFunctionSpace().getDomain());     const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(*(arg.getFunctionSpace().getDomain()));
1325     if (argDomain!=*this)     if (argDomain!=*this)
1326        throw FinleyAdapterException("Error - Illegal domain of gradient argument");        throw FinleyAdapterException("Error - Illegal domain of gradient argument");
1327     const MeshAdapter& gradDomain=dynamic_cast<const MeshAdapter&>(grad.getFunctionSpace().getDomain());     const MeshAdapter& gradDomain=dynamic_cast<const MeshAdapter&>(*(grad.getFunctionSpace().getDomain()));
1328     if (gradDomain!=*this)     if (gradDomain!=*this)
1329        throw FinleyAdapterException("Error - Illegal domain of gradient");        throw FinleyAdapterException("Error - Illegal domain of gradient");
1330    
# Line 1438  void MeshAdapter::setNewX(const escript: Line 1451  void MeshAdapter::setNewX(const escript:
1451  {  {
1452     Finley_Mesh* mesh=m_finleyMesh.get();     Finley_Mesh* mesh=m_finleyMesh.get();
1453     escriptDataC tmp;     escriptDataC tmp;
1454     const MeshAdapter& newDomain=dynamic_cast<const MeshAdapter&>(new_x.getFunctionSpace().getDomain());     const MeshAdapter& newDomain=dynamic_cast<const MeshAdapter&>(*(new_x.getFunctionSpace().getDomain()));
1455     if (newDomain!=*this)     if (newDomain!=*this)
1456        throw FinleyAdapterException("Error - Illegal domain of new point locations");        throw FinleyAdapterException("Error - Illegal domain of new point locations");
1457     tmp = new_x.getDataC();     tmp = new_x.getDataC();
# Line 1465  void MeshAdapter::saveDX(const std::stri Line 1478  void MeshAdapter::saveDX(const std::stri
1478     for (int i=0;i<num_data;++i) {     for (int i=0;i<num_data;++i) {
1479        std::string n=boost::python::extract<std::string>(keys[i]);        std::string n=boost::python::extract<std::string>(keys[i]);
1480        escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);        escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);
1481        if (dynamic_cast<const MeshAdapter&>(d.getFunctionSpace().getDomain()) !=*this)        if (dynamic_cast<const MeshAdapter&>(*(d.getFunctionSpace().getDomain())) !=*this)
1482           throw FinleyAdapterException("Error  in saveVTK: Data must be defined on same Domain");           throw FinleyAdapterException("Error in saveDX: Data must be defined on same Domain");
1483        data[i]=d.getDataC();        data[i]=d.getDataC();
1484        ptr_data[i]= &(data[i]);        ptr_data[i]= &(data[i]);
1485        if (n.length()>MAX_namelength-1) {        if (n.length()>MAX_namelength-1) {
# Line 1510  void MeshAdapter::saveVTK(const std::str Line 1523  void MeshAdapter::saveVTK(const std::str
1523     for (int i=0;i<num_data;++i) {     for (int i=0;i<num_data;++i) {
1524        std::string n=boost::python::extract<std::string>(keys[i]);        std::string n=boost::python::extract<std::string>(keys[i]);
1525        escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);        escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);
1526        if (dynamic_cast<const MeshAdapter&>(d.getFunctionSpace().getDomain()) !=*this)        if (dynamic_cast<const MeshAdapter&>(*(d.getFunctionSpace().getDomain())) !=*this)
1527           throw FinleyAdapterException("Error  in saveVTK: Data must be defined on same Domain");           throw FinleyAdapterException("Error in saveVTK: Data must be defined on same Domain");
1528        data[i]=d.getDataC();        data[i]=d.getDataC();
1529        ptr_data[i]=&(data[i]);        ptr_data[i]=&(data[i]);
1530        if (n.length()>MAX_namelength-1) {        if (n.length()>MAX_namelength-1) {
# Line 1548  SystemMatrixAdapter MeshAdapter::newSyst Line 1561  SystemMatrixAdapter MeshAdapter::newSyst
1561     int reduceRowOrder=0;     int reduceRowOrder=0;
1562     int reduceColOrder=0;     int reduceColOrder=0;
1563     // is the domain right?     // is the domain right?
1564     const MeshAdapter& row_domain=dynamic_cast<const MeshAdapter&>(row_functionspace.getDomain());     const MeshAdapter& row_domain=dynamic_cast<const MeshAdapter&>(*(row_functionspace.getDomain()));
1565     if (row_domain!=*this)     if (row_domain!=*this)
1566        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.");
1567     const MeshAdapter& col_domain=dynamic_cast<const MeshAdapter&>(column_functionspace.getDomain());     const MeshAdapter& col_domain=dynamic_cast<const MeshAdapter&>(*(column_functionspace.getDomain()));
1568     if (col_domain!=*this)     if (col_domain!=*this)
1569        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.");
1570     // is the function space type right     // is the function space type right
# Line 1596  TransportProblemAdapter MeshAdapter::new Line 1609  TransportProblemAdapter MeshAdapter::new
1609  {  {
1610     int reduceOrder=0;     int reduceOrder=0;
1611     // is the domain right?     // is the domain right?
1612     const MeshAdapter& domain=dynamic_cast<const MeshAdapter&>(functionspace.getDomain());     const MeshAdapter& domain=dynamic_cast<const MeshAdapter&>(*(functionspace.getDomain()));
1613     if (domain!=*this)     if (domain!=*this)
1614        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.");
1615     // is the function space type right     // is the function space type right
# Line 1827  bool MeshAdapter::operator!=(const Abstr Line 1840  bool MeshAdapter::operator!=(const Abstr
1840     return !(operator==(other));     return !(operator==(other));
1841  }  }
1842    
1843  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
1844  {  {
1845     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);
1846       checkPasoError();
1847       return out;
1848    }
1849    int MeshAdapter::getTransportTypeId(const int solver, const int preconditioner, const int package, const bool symmetry) const
1850    {
1851       int out=Paso_FCTransportProblem_getTypeId(SystemMatrixAdapter::mapOptionToPaso(solver),SystemMatrixAdapter::mapOptionToPaso(preconditioner), SystemMatrixAdapter::mapOptionToPaso(package),symmetry?1:0);
1852     checkPasoError();     checkPasoError();
1853     return out;     return out;
1854  }  }
# Line 1846  escript::Data MeshAdapter::getNormal() c Line 1865  escript::Data MeshAdapter::getNormal() c
1865    
1866  escript::Data MeshAdapter::getSize() const  escript::Data MeshAdapter::getSize() const
1867  {  {
1868     return function(asAbstractContinuousDomain()).getSize();     return escript::function(asAbstractContinuousDomain()).getSize();
1869  }  }
1870    
1871  int* MeshAdapter::borrowSampleReferenceIDs(int functionSpaceType) const  int* MeshAdapter::borrowSampleReferenceIDs(int functionSpaceType) const
# Line 2129  int* MeshAdapter::borrowListOfTagsInUse( Line 2148  int* MeshAdapter::borrowListOfTagsInUse(
2148  }  }
2149    
2150    
2151    bool MeshAdapter::canTag(int functionSpaceCode) const
2152    {
2153      switch(functionSpaceCode) {
2154       case(Nodes):
2155       case(Elements):
2156       case(ReducedElements):
2157       case(FaceElements):
2158       case(ReducedFaceElements):
2159       case(Points):
2160       case(ContactElementsZero):
2161       case(ReducedContactElementsZero):
2162       case(ContactElementsOne):
2163       case(ReducedContactElementsOne):
2164              return true;
2165       case(ReducedNodes):
2166       case(DegreesOfFreedom):
2167       case(ReducedDegreesOfFreedom):
2168          return false;
2169       default:
2170        return false;
2171      }
2172    }
2173    
2174    
2175  }  // end of namespace  }  // end of namespace

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

  ViewVC Help
Powered by ViewVC 1.1.26