/[escript]/branches/domexper/dudley/src/CPPAdapter/MeshAdapter.cpp
ViewVC logotype

Diff of /branches/domexper/dudley/src/CPPAdapter/MeshAdapter.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1800 by ksteube, Thu Sep 18 05:28:20 2008 UTC revision 2087 by jfenwick, Mon Nov 24 04:51:30 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  MPI_Comm MeshAdapter::getMPIComm() const  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->comm;     return m_finleyMesh.get()->MPIInfo->rank == 0;
99  }  }
100    
101    
# Line 114  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 865  void MeshAdapter::addPDEToTransportProbl Line 871  void MeshAdapter::addPDEToTransportProbl
871  //  //
872  void MeshAdapter::interpolateOnDomain(escript::Data& target,const escript::Data& in) const  void MeshAdapter::interpolateOnDomain(escript::Data& target,const escript::Data& in) const
873  {  {
874     const MeshAdapter& inDomain=dynamic_cast<const MeshAdapter&>(in.getFunctionSpace().getDomain());     const MeshAdapter& inDomain=dynamic_cast<const MeshAdapter&>(*(in.getFunctionSpace().getDomain()));
875     const MeshAdapter& targetDomain=dynamic_cast<const MeshAdapter&>(target.getFunctionSpace().getDomain());     const MeshAdapter& targetDomain=dynamic_cast<const MeshAdapter&>(*(target.getFunctionSpace().getDomain()));
876     if (inDomain!=*this)       if (inDomain!=*this)  
877        throw FinleyAdapterException("Error - Illegal domain of interpolant.");        throw FinleyAdapterException("Error - Illegal domain of interpolant.");
878     if (targetDomain!=*this)     if (targetDomain!=*this)
# Line 1150  void MeshAdapter::interpolateOnDomain(es Line 1156  void MeshAdapter::interpolateOnDomain(es
1156  //  //
1157  void MeshAdapter::setToX(escript::Data& arg) const  void MeshAdapter::setToX(escript::Data& arg) const
1158  {  {
1159     const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(arg.getFunctionSpace().getDomain());     const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(*(arg.getFunctionSpace().getDomain()));
1160     if (argDomain!=*this)     if (argDomain!=*this)
1161        throw FinleyAdapterException("Error - Illegal domain of data point locations");        throw FinleyAdapterException("Error - Illegal domain of data point locations");
1162     Finley_Mesh* mesh=m_finleyMesh.get();     Finley_Mesh* mesh=m_finleyMesh.get();
# Line 1173  void MeshAdapter::setToX(escript::Data& Line 1179  void MeshAdapter::setToX(escript::Data&
1179  //  //
1180  void MeshAdapter::setToNormal(escript::Data& normal) const  void MeshAdapter::setToNormal(escript::Data& normal) const
1181  {  {
1182     const MeshAdapter& normalDomain=dynamic_cast<const MeshAdapter&>(normal.getFunctionSpace().getDomain());  /*   const MeshAdapter& normalDomain=dynamic_cast<const MeshAdapter&>(normal.getFunctionSpace().getDomain());*/
1183       const MeshAdapter& normalDomain=dynamic_cast<const MeshAdapter&>(*(normal.getFunctionSpace().getDomain()));
1184     if (normalDomain!=*this)     if (normalDomain!=*this)
1185        throw FinleyAdapterException("Error - Illegal domain of normal locations");        throw FinleyAdapterException("Error - Illegal domain of normal locations");
1186     Finley_Mesh* mesh=m_finleyMesh.get();     Finley_Mesh* mesh=m_finleyMesh.get();
# Line 1228  void MeshAdapter::setToNormal(escript::D Line 1235  void MeshAdapter::setToNormal(escript::D
1235  //  //
1236  void MeshAdapter::interpolateACross(escript::Data& target,const escript::Data& source) const  void MeshAdapter::interpolateACross(escript::Data& target,const escript::Data& source) const
1237  {  {
1238     const MeshAdapter& targetDomain=dynamic_cast<const MeshAdapter&>(target.getFunctionSpace().getDomain());     const_Domain_ptr targetDomain_p=target.getFunctionSpace().getDomain();
1239     if (targetDomain!=*this)     const MeshAdapter* targetDomain=dynamic_cast<const MeshAdapter*>(targetDomain_p.get());
1240       if (targetDomain!=this)
1241        throw FinleyAdapterException("Error - Illegal domain of interpolation target");        throw FinleyAdapterException("Error - Illegal domain of interpolation target");
1242    
1243     throw FinleyAdapterException("Error - Finley does not allow interpolation across domains yet.");     throw FinleyAdapterException("Error - Finley does not allow interpolation across domains yet.");
# Line 1240  void MeshAdapter::interpolateACross(escr Line 1248  void MeshAdapter::interpolateACross(escr
1248  //  //
1249  void MeshAdapter::setToIntegrals(std::vector<double>& integrals,const escript::Data& arg) const  void MeshAdapter::setToIntegrals(std::vector<double>& integrals,const escript::Data& arg) const
1250  {  {
1251     const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(arg.getFunctionSpace().getDomain());     const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(*(arg.getFunctionSpace().getDomain()));
1252     if (argDomain!=*this)     if (argDomain!=*this)
1253        throw FinleyAdapterException("Error - Illegal domain of integration kernel");        throw FinleyAdapterException("Error - Illegal domain of integration kernel");
1254    
# Line 1251  void MeshAdapter::setToIntegrals(std::ve Line 1259  void MeshAdapter::setToIntegrals(std::ve
1259     escriptDataC _arg=arg.getDataC();     escriptDataC _arg=arg.getDataC();
1260     switch(arg.getFunctionSpace().getTypeCode()) {     switch(arg.getFunctionSpace().getTypeCode()) {
1261     case(Nodes):     case(Nodes):
1262     temp=escript::Data( arg, function(asAbstractContinuousDomain()) );     temp=escript::Data( arg, escript::function(asAbstractContinuousDomain()) );
1263     _temp=temp.getDataC();     _temp=temp.getDataC();
1264     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1265     break;     break;
1266     case(ReducedNodes):     case(ReducedNodes):
1267     temp=escript::Data( arg, function(asAbstractContinuousDomain()) );     temp=escript::Data( arg, escript::function(asAbstractContinuousDomain()) );
1268     _temp=temp.getDataC();     _temp=temp.getDataC();
1269     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1270     break;     break;
# Line 1288  void MeshAdapter::setToIntegrals(std::ve Line 1296  void MeshAdapter::setToIntegrals(std::ve
1296     Finley_Assemble_integrate(mesh->Nodes,mesh->ContactElements,&_arg,&integrals[0]);     Finley_Assemble_integrate(mesh->Nodes,mesh->ContactElements,&_arg,&integrals[0]);
1297     break;     break;
1298     case(DegreesOfFreedom):     case(DegreesOfFreedom):
1299     temp=escript::Data( arg, function(asAbstractContinuousDomain()) );     temp=escript::Data( arg, escript::function(asAbstractContinuousDomain()) );
1300     _temp=temp.getDataC();     _temp=temp.getDataC();
1301     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1302     break;     break;
1303     case(ReducedDegreesOfFreedom):     case(ReducedDegreesOfFreedom):
1304     temp=escript::Data( arg, function(asAbstractContinuousDomain()) );     temp=escript::Data( arg, escript::function(asAbstractContinuousDomain()) );
1305     _temp=temp.getDataC();     _temp=temp.getDataC();
1306     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);     Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1307     break;     break;
# Line 1312  void MeshAdapter::setToIntegrals(std::ve Line 1320  void MeshAdapter::setToIntegrals(std::ve
1320  //  //
1321  void MeshAdapter::setToGradient(escript::Data& grad,const escript::Data& arg) const  void MeshAdapter::setToGradient(escript::Data& grad,const escript::Data& arg) const
1322  {  {
1323     const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(arg.getFunctionSpace().getDomain());     const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(*(arg.getFunctionSpace().getDomain()));
1324     if (argDomain!=*this)     if (argDomain!=*this)
1325        throw FinleyAdapterException("Error - Illegal domain of gradient argument");        throw FinleyAdapterException("Error - Illegal domain of gradient argument");
1326     const MeshAdapter& gradDomain=dynamic_cast<const MeshAdapter&>(grad.getFunctionSpace().getDomain());     const MeshAdapter& gradDomain=dynamic_cast<const MeshAdapter&>(*(grad.getFunctionSpace().getDomain()));
1327     if (gradDomain!=*this)     if (gradDomain!=*this)
1328        throw FinleyAdapterException("Error - Illegal domain of gradient");        throw FinleyAdapterException("Error - Illegal domain of gradient");
1329    
# Line 1442  void MeshAdapter::setNewX(const escript: Line 1450  void MeshAdapter::setNewX(const escript:
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 1469  void MeshAdapter::saveDX(const std::stri Line 1477  void MeshAdapter::saveDX(const std::stri
1477     for (int i=0;i<num_data;++i) {     for (int i=0;i<num_data;++i) {
1478        std::string n=boost::python::extract<std::string>(keys[i]);        std::string n=boost::python::extract<std::string>(keys[i]);
1479        escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);        escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);
1480        if (dynamic_cast<const MeshAdapter&>(d.getFunctionSpace().getDomain()) !=*this)        if (dynamic_cast<const MeshAdapter&>(*(d.getFunctionSpace().getDomain())) !=*this)
1481           throw FinleyAdapterException("Error  in saveVTK: Data must be defined on same Domain");           throw FinleyAdapterException("Error  in saveVTK: Data must be defined on same Domain");
1482        data[i]=d.getDataC();        data[i]=d.getDataC();
1483        ptr_data[i]= &(data[i]);        ptr_data[i]= &(data[i]);
# Line 1514  void MeshAdapter::saveVTK(const std::str Line 1522  void MeshAdapter::saveVTK(const std::str
1522     for (int i=0;i<num_data;++i) {     for (int i=0;i<num_data;++i) {
1523        std::string n=boost::python::extract<std::string>(keys[i]);        std::string n=boost::python::extract<std::string>(keys[i]);
1524        escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);        escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);
1525        if (dynamic_cast<const MeshAdapter&>(d.getFunctionSpace().getDomain()) !=*this)        if (dynamic_cast<const MeshAdapter&>(*(d.getFunctionSpace().getDomain())) !=*this)
1526           throw FinleyAdapterException("Error  in saveVTK: Data must be defined on same Domain");           throw FinleyAdapterException("Error  in saveVTK: Data must be defined on same Domain");
1527        data[i]=d.getDataC();        data[i]=d.getDataC();
1528        ptr_data[i]=&(data[i]);        ptr_data[i]=&(data[i]);
# Line 1552  SystemMatrixAdapter MeshAdapter::newSyst Line 1560  SystemMatrixAdapter MeshAdapter::newSyst
1560     int reduceRowOrder=0;     int reduceRowOrder=0;
1561     int reduceColOrder=0;     int reduceColOrder=0;
1562     // is the domain right?     // is the domain right?
1563     const MeshAdapter& row_domain=dynamic_cast<const MeshAdapter&>(row_functionspace.getDomain());     const MeshAdapter& row_domain=dynamic_cast<const MeshAdapter&>(*(row_functionspace.getDomain()));
1564     if (row_domain!=*this)     if (row_domain!=*this)
1565        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.");
1566     const MeshAdapter& col_domain=dynamic_cast<const MeshAdapter&>(column_functionspace.getDomain());     const MeshAdapter& col_domain=dynamic_cast<const MeshAdapter&>(*(column_functionspace.getDomain()));
1567     if (col_domain!=*this)     if (col_domain!=*this)
1568        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.");
1569     // is the function space type right     // is the function space type right
# Line 1600  TransportProblemAdapter MeshAdapter::new Line 1608  TransportProblemAdapter MeshAdapter::new
1608  {  {
1609     int reduceOrder=0;     int reduceOrder=0;
1610     // is the domain right?     // is the domain right?
1611     const MeshAdapter& domain=dynamic_cast<const MeshAdapter&>(functionspace.getDomain());     const MeshAdapter& domain=dynamic_cast<const MeshAdapter&>(*(functionspace.getDomain()));
1612     if (domain!=*this)     if (domain!=*this)
1613        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.");
1614     // is the function space type right     // is the function space type right
# Line 1831  bool MeshAdapter::operator!=(const Abstr Line 1839  bool MeshAdapter::operator!=(const Abstr
1839     return !(operator==(other));     return !(operator==(other));
1840  }  }
1841    
1842  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
1843  {  {
1844     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);
1845       checkPasoError();
1846       return out;
1847    }
1848    int MeshAdapter::getTransportTypeId(const int solver, const int preconditioner, const int package, const bool symmetry) const
1849    {
1850       int out=Paso_FCTransportProblem_getTypeId(SystemMatrixAdapter::mapOptionToPaso(solver),SystemMatrixAdapter::mapOptionToPaso(preconditioner), SystemMatrixAdapter::mapOptionToPaso(package),symmetry?1:0);
1851     checkPasoError();     checkPasoError();
1852     return out;     return out;
1853  }  }
# Line 1850  escript::Data MeshAdapter::getNormal() c Line 1864  escript::Data MeshAdapter::getNormal() c
1864    
1865  escript::Data MeshAdapter::getSize() const  escript::Data MeshAdapter::getSize() const
1866  {  {
1867     return function(asAbstractContinuousDomain()).getSize();     return escript::function(asAbstractContinuousDomain()).getSize();
1868  }  }
1869    
1870  int* MeshAdapter::borrowSampleReferenceIDs(int functionSpaceType) const  int* MeshAdapter::borrowSampleReferenceIDs(int functionSpaceType) const
# Line 2133  int* MeshAdapter::borrowListOfTagsInUse( Line 2147  int* MeshAdapter::borrowListOfTagsInUse(
2147  }  }
2148    
2149    
2150    bool MeshAdapter::canTag(int functionSpaceCode) const
2151    {
2152      switch(functionSpaceCode) {
2153       case(Nodes):
2154       case(Elements):
2155       case(ReducedElements):
2156       case(FaceElements):
2157       case(ReducedFaceElements):
2158       case(Points):
2159       case(ContactElementsZero):
2160       case(ReducedContactElementsZero):
2161       case(ContactElementsOne):
2162       case(ReducedContactElementsOne):
2163              return true;
2164       case(ReducedNodes):
2165       case(DegreesOfFreedom):
2166       case(ReducedDegreesOfFreedom):
2167          return false;
2168       default:
2169        return false;
2170      }
2171    }
2172    
2173    
2174  }  // end of namespace  }  // end of namespace

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

  ViewVC Help
Powered by ViewVC 1.1.26