/[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 97 by jgs, Tue Dec 14 05:39:33 2004 UTC revision 149 by jgs, Thu Sep 1 03:31:39 2005 UTC
# Line 28  extern "C" { Line 28  extern "C" {
28  #include "escript/Data/DataArrayView.h"  #include "escript/Data/DataArrayView.h"
29  #include "escript/Data/FunctionSpace.h"  #include "escript/Data/FunctionSpace.h"
30  #include "escript/Data/DataFactory.h"  #include "escript/Data/DataFactory.h"
31    
32  #include <iostream>  #include <iostream>
33  #include <vector>  #include <vector>
34  #include <sstream>  #include <sstream>
# Line 37  using namespace escript; Line 38  using namespace escript;
38    
39  namespace finley {  namespace finley {
40    
 struct null_deleter  
 {  
   void operator()(void const *ptr) const  
   {  
   }  
 };  
   
41  //  //
42  // define the statics  // define the static constants
43  MeshAdapter::FunctionSpaceNamesMapType MeshAdapter::m_functionSpaceTypeNames;  MeshAdapter::FunctionSpaceNamesMapType MeshAdapter::m_functionSpaceTypeNames;
44  const int MeshAdapter::DegreesOfFreedom=FINLEY_DEGREES_OF_FREEDOM;  const int MeshAdapter::DegreesOfFreedom=FINLEY_DEGREES_OF_FREEDOM;
45  const int MeshAdapter::ReducedDegreesOfFreedom=FINLEY_REDUCED_DEGREES_OF_FREEDOM;  const int MeshAdapter::ReducedDegreesOfFreedom=FINLEY_REDUCED_DEGREES_OF_FREEDOM;
# Line 64  MeshAdapter::MeshAdapter(Finley_Mesh* fi Line 58  MeshAdapter::MeshAdapter(Finley_Mesh* fi
58    // for us.    // for us.
59    m_finleyMesh.reset(finleyMesh,null_deleter());    m_finleyMesh.reset(finleyMesh,null_deleter());
60  }  }
61    
62  //  //
63  // The copy constructor should just increment the use count  // The copy constructor should just increment the use count
64  MeshAdapter::MeshAdapter(const MeshAdapter& in):  MeshAdapter::MeshAdapter(const MeshAdapter& in):
# Line 150  int MeshAdapter::getContinuousFunctionCo Line 145  int MeshAdapter::getContinuousFunctionCo
145  {  {
146    return Nodes;    return Nodes;
147  }  }
148    
149  int MeshAdapter::getFunctionCode() const  int MeshAdapter::getFunctionCode() const
150  {  {
151    return Elements;    return Elements;
152  }  }
153    
154  int MeshAdapter::getFunctionOnBoundaryCode() const  int MeshAdapter::getFunctionOnBoundaryCode() const
155  {  {
156    return FaceElements;    return FaceElements;
157  }  }
158    
159  int MeshAdapter::getFunctionOnContactZeroCode() const  int MeshAdapter::getFunctionOnContactZeroCode() const
160  {  {
161    return ContactElementsZero;    return ContactElementsZero;
162  }  }
163    
164  int MeshAdapter::getFunctionOnContactOneCode() const  int MeshAdapter::getFunctionOnContactOneCode() const
165  {  {
166    return ContactElementsOne;    return ContactElementsOne;
# Line 171  int MeshAdapter::getSolutionCode() const Line 170  int MeshAdapter::getSolutionCode() const
170  {  {
171    return DegreesOfFreedom;    return DegreesOfFreedom;
172  }  }
173    
174  int MeshAdapter::getReducedSolutionCode() const  int MeshAdapter::getReducedSolutionCode() const
175  {  {
176    return ReducedDegreesOfFreedom;    return ReducedDegreesOfFreedom;
177  }  }
178    
179  int MeshAdapter::getDiracDeltaFunctionCode() const  int MeshAdapter::getDiracDeltaFunctionCode() const
180  {  {
181    return Points;    return Points;
182  }  }
183    
 int MeshAdapter::getTagFromSampleNo(int functionSpaceType, int sampleNo) const  
 {  
   //  
   // It is assumed the sampleNo has been checked  
   // before calling this function.  
   int* tagList;  
   int numTags;  
   getTagList(functionSpaceType, &tagList, &numTags);  
   return tagList[sampleNo];  
 }  
   
184  //  //
185  // returns a pointer to the tag list of samples of functionSpaceType  // returns a pointer to the tag list of samples of functionSpaceType
186  //  //
# Line 256  void MeshAdapter::getTagList(int functio Line 246  void MeshAdapter::getTagList(int functio
246      throw FinleyAdapterException(temp.str());      throw FinleyAdapterException(temp.str());
247      break;      break;
248    }    }
249      if (*tagList==NULL) {
250        stringstream temp;
251        temp << "Error - no tags available for " << functionSpaceType << " for domain: " << getDescription();
252        throw FinleyAdapterException(temp.str());
253      }
254      return;
255    }
256    
257    //
258    // returns a pointer to the reference no list of samples of functionSpaceType
259    //
260    void MeshAdapter::getReferenceNoList(int functionSpaceType, int** referenceNoList,
261                     int* numReferenceNo) const
262    {
263      *referenceNoList=NULL;
264      *numReferenceNo=0;
265      Finley_Mesh* mesh=m_finleyMesh.get();
266      switch (functionSpaceType) {
267      case(Nodes):
268        if (mesh->Nodes!=NULL) {
269          *referenceNoList=mesh->Nodes->Id;
270          *numReferenceNo=mesh->Nodes->numNodes;
271        }
272        break;
273      case(Elements):
274        if (mesh->Elements!=NULL) {
275          *referenceNoList=mesh->Elements->Id;
276          *numReferenceNo=mesh->Elements->numElements;
277        }
278        break;
279      case(FaceElements):
280        if (mesh->FaceElements!=NULL) {
281          *referenceNoList=mesh->FaceElements->Id;
282          *numReferenceNo=mesh->FaceElements->numElements;
283        }
284        break;
285      case(Points):
286        if (mesh->Points!=NULL) {
287          *referenceNoList=mesh->Points->Id;
288          *numReferenceNo=mesh->Points->numElements;
289        }
290        break;
291      case(ContactElementsZero):
292        if (mesh->ContactElements!=NULL) {
293          *referenceNoList=mesh->ContactElements->Id;
294          *numReferenceNo=mesh->ContactElements->numElements;
295        }
296        break;
297      case(ContactElementsOne):
298        if (mesh->ContactElements!=NULL) {
299          *referenceNoList=mesh->ContactElements->Id;
300          *numReferenceNo=mesh->ContactElements->numElements;
301        }
302        break;
303      case(DegreesOfFreedom):
304        if (mesh->Nodes!=NULL) {
305          *referenceNoList=NULL;
306          *numReferenceNo=0;
307        }
308        break;
309      case(ReducedDegreesOfFreedom):
310        if (mesh->Nodes!=NULL) {
311          *referenceNoList=NULL;
312          *numReferenceNo=0;
313        }
314        break;
315      default:
316        stringstream temp;
317        temp << "Error - Invalid function space type: "
318         << functionSpaceType << " for domain: " << getDescription();
319        throw FinleyAdapterException(temp.str());
320        break;
321      }
322      if (*referenceNoList==NULL) {
323        stringstream temp;
324        temp << "Error - reference number list available for " << functionSpaceType << " for domain: " << getDescription();
325        throw FinleyAdapterException(temp.str());
326      }
327    return;    return;
328  }  }
329    
# Line 268  int MeshAdapter::getDim() const Line 336  int MeshAdapter::getDim() const
336    checkFinleyError();    checkFinleyError();
337    return numDim;    return numDim;
338  }  }
339    
340  //  //
341  // return the number of data points per sample and the number of samples  // return the number of data points per sample and the number of samples
342  // needed to represent data on a parts of the mesh.  // needed to represent data on a parts of the mesh.
# Line 333  pair<int,int> MeshAdapter::getDataShape( Line 402  pair<int,int> MeshAdapter::getDataShape(
402        }        }
403        return pair<int,int>(numDataPointsPerSample,numSamples);        return pair<int,int>(numDataPointsPerSample,numSamples);
404  }  }
405    
406  //  //
407  // adds linear PDE of second order into a given stiffness matrix and right hand side:  // adds linear PDE of second order into a given stiffness matrix and right hand side:
408  //  //
# Line 352  void MeshAdapter::addPDEToSystem( Line 422  void MeshAdapter::addPDEToSystem(
422                                    &(d.getDataC()),&(y.getDataC()),                                    &(d.getDataC()),&(y.getDataC()),
423                                    Finley_Assemble_handelShapeMissMatch_Mean_out);                                    Finley_Assemble_handelShapeMissMatch_Mean_out);
424     checkFinleyError();     checkFinleyError();
425     Finley_Assemble_RobinCondition(mesh->Nodes,mesh->FaceElements,     Finley_Assemble_RobinCondition(mesh->Nodes,mesh->ContactElements,
426                    mat.getFinley_SystemMatrix(),                    mat.getFinley_SystemMatrix(),
427                    &(rhs.getDataC()),                    &(rhs.getDataC()),
428                                    &(d_contact.getDataC()),                                    &(d_contact.getDataC()),
# Line 360  void MeshAdapter::addPDEToSystem( Line 430  void MeshAdapter::addPDEToSystem(
430                                    Finley_Assemble_handelShapeMissMatch_Step_out);                                    Finley_Assemble_handelShapeMissMatch_Step_out);
431     checkFinleyError();     checkFinleyError();
432  }  }
433    
434  //  //
435  // adds linear PDE of second order into the right hand side only  // adds linear PDE of second order into the right hand side only
436  //  //
# Line 367  void MeshAdapter::addPDEToRHS( Data& rhs Line 438  void MeshAdapter::addPDEToRHS( Data& rhs
438                       const  Data& X,const  Data& Y, const Data& y, const Data& y_contact) const                       const  Data& X,const  Data& Y, const Data& y, const Data& y_contact) const
439  {  {
440     Finley_Mesh* mesh=m_finleyMesh.get();     Finley_Mesh* mesh=m_finleyMesh.get();
441     Finley_Assemble_PDE(mesh->Nodes,mesh->Elements,0,&(rhs.getDataC()),0,0,0,0,&(X.getDataC()),&(Y.getDataC()));  
442       // Finley_Assemble_PDE_RHS(mesh->Nodes,mesh->Elements,&(rhs.getDataC()),&(X.getDataC()),&(Y.getDataC()));
443       Finley_Assemble_PDE(mesh->Nodes,mesh->Elements,0,&(rhs.getDataC()),0,0,0,0,&(X.getDataC()),&(Y.getDataC()));
444     checkFinleyError();     checkFinleyError();
445     Finley_Assemble_RobinCondition(mesh->Nodes,mesh->FaceElements,0,&(rhs.getDataC()),0,&(y.getDataC()),  
446                                    Finley_Assemble_handelShapeMissMatch_Mean_out);     // Finley_Assemble_RobinCondition_RHS(mesh->Nodes,mesh->FaceElements,&(rhs.getDataC()),&(y.getDataC()),Finley_Assemble_handelShapeMissMatch_Mean_out);
447  // cout << "Calling :addPDEToRHS." << endl;     Finley_Assemble_RobinCondition(mesh->Nodes,mesh->FaceElements,0,&(rhs.getDataC()),0,&(y.getDataC()),Finley_Assemble_handelShapeMissMatch_Mean_out);
448    
449     checkFinleyError();     checkFinleyError();
450     Finley_Assemble_RobinCondition(mesh->Nodes,mesh->FaceElements,0,&(rhs.getDataC()),0,&(y_contact.getDataC()),     Finley_Assemble_RobinCondition(mesh->Nodes,mesh->ContactElements,0,&(rhs.getDataC()),0,&(y_contact.getDataC()),Finley_Assemble_handelShapeMissMatch_Step_out);
451                                    Finley_Assemble_handelShapeMissMatch_Step_out);     // Finley_Assemble_RobinCondition_RHS(mesh->Nodes,mesh->ContactElements,&(rhs.getDataC()),&(y_contact.getDataC()),Finley_Assemble_handelShapeMissMatch_Step_out);
 // cout << "Calling :addPDEToRHS." << endl;  
452     checkFinleyError();     checkFinleyError();
453  }  }
454    
455  //  //
456  // interpolates data between different function spaces:  // interpolates data between different function spaces:
457  //  //
# Line 484  void MeshAdapter::interpolateOnDomain(Da Line 558  void MeshAdapter::interpolateOnDomain(Da
558       case(ReducedDegreesOfFreedom):       case(ReducedDegreesOfFreedom):
559         switch(target.getFunctionSpace().getTypeCode()) {         switch(target.getFunctionSpace().getTypeCode()) {
560            case(ReducedDegreesOfFreedom):            case(ReducedDegreesOfFreedom):
           case(Nodes):  
561               Finley_Assemble_CopyNodalData(mesh->Nodes,&(target.getDataC()),&(in.getDataC()));               Finley_Assemble_CopyNodalData(mesh->Nodes,&(target.getDataC()),&(in.getDataC()));
562               break;               break;
563            case(Elements):            case(Elements):
# Line 500  void MeshAdapter::interpolateOnDomain(Da Line 573  void MeshAdapter::interpolateOnDomain(Da
573            case(ContactElementsOne):            case(ContactElementsOne):
574               Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&(in.getDataC()),&(target.getDataC()));               Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&(in.getDataC()),&(target.getDataC()));
575               break;               break;
576              case(Nodes):
577                 Finley_ErrorCode=TYPE_ERROR;
578                 sprintf(Finley_ErrorMsg,"Finley does not support interpolation from reduced degrees of freedom to mesh nodes.");
579                 break;
580            case(DegreesOfFreedom):            case(DegreesOfFreedom):
581               Finley_ErrorCode=TYPE_ERROR;               Finley_ErrorCode=TYPE_ERROR;
582               sprintf(Finley_ErrorMsg,"Finley does not support interpolation from reduced degrees of freedom to degrees of freedom");               sprintf(Finley_ErrorMsg,"Finley does not support interpolation from reduced degrees of freedom to degrees of freedom");
# Line 538  void MeshAdapter::setToX(Data& arg) cons Line 615  void MeshAdapter::setToX(Data& arg) cons
615    }    }
616    checkFinleyError();    checkFinleyError();
617  }  }
618    
619  //  //
620  // return the normal vectors at the location of data points as a Data object:  // return the normal vectors at the location of data points as a Data object:
621  //  //
# Line 582  void MeshAdapter::setToNormal(Data& norm Line 660  void MeshAdapter::setToNormal(Data& norm
660    }    }
661    checkFinleyError();    checkFinleyError();
662  }  }
663    
664  //  //
665  // interpolates data to other domain:  // interpolates data to other domain:
666  //  //
# Line 595  void MeshAdapter::interpolateACross(Data Line 674  void MeshAdapter::interpolateACross(Data
674    sprintf(Finley_ErrorMsg,"Finley does not allow interpolation across domains yet.");    sprintf(Finley_ErrorMsg,"Finley does not allow interpolation across domains yet.");
675    checkFinleyError();    checkFinleyError();
676  }  }
677    
678  //  //
679  // calculates the integral of a function defined of arg:  // calculates the integral of a function defined of arg:
680  //  //
# Line 641  void MeshAdapter::setToIntegrals(std::ve Line 721  void MeshAdapter::setToIntegrals(std::ve
721    }    }
722    checkFinleyError();    checkFinleyError();
723  }  }
724    
725  //  //
726  // calculates the gradient of arg:  // calculates the gradient of arg:
727  //  //
# Line 690  void MeshAdapter::setToGradient(Data& gr Line 771  void MeshAdapter::setToGradient(Data& gr
771    }    }
772    checkFinleyError();    checkFinleyError();
773  }  }
774    
775  //  //
776  // returns the size of elements:  // returns the size of elements:
777  //  //
# Line 731  void MeshAdapter::setToSize(Data& size) Line 813  void MeshAdapter::setToSize(Data& size)
813    }    }
814    checkFinleyError();    checkFinleyError();
815  }  }
816    
817  // sets the location of nodes:  // sets the location of nodes:
818  void MeshAdapter::setNewX(const Data& new_x)  void MeshAdapter::setNewX(const Data& new_x)
819  {  {
# Line 741  void MeshAdapter::setNewX(const Data& ne Line 824  void MeshAdapter::setNewX(const Data& ne
824    Finley_NodeFile_setCoordinates(mesh->Nodes,&(new_x.getDataC()));    Finley_NodeFile_setCoordinates(mesh->Nodes,&(new_x.getDataC()));
825    checkFinleyError();    checkFinleyError();
826  }  }
827    
828  // saves a data array in openDX format:  // saves a data array in openDX format:
829  void MeshAdapter::saveDX(const std::string& filename,const Data& arg) const  void MeshAdapter::saveDX(const std::string& filename,const Data& arg) const
830  {  {
831    Finley_Mesh_saveDX(filename.c_str(),m_finleyMesh.get(),&(arg.getDataC()));    Finley_Mesh_saveDX(filename.c_str(),m_finleyMesh.get(),&(arg.getDataC()));
832    checkFinleyError();    checkFinleyError();
833  }  }
834    
835    // saves a data array in openVTK format:
836    void MeshAdapter::saveVTK(const std::string& filename,const Data& arg) const
837    {
838      Finley_Mesh_saveVTK(filename.c_str(),m_finleyMesh.get(),&(arg.getDataC()));
839      checkFinleyError();
840    }
841    
842  // creates a SystemMatrixAdapter stiffness matrix an initializes it with zeros:  // creates a SystemMatrixAdapter stiffness matrix an initializes it with zeros:
843  SystemMatrixAdapter MeshAdapter::newSystemMatrix(  SystemMatrixAdapter MeshAdapter::newSystemMatrix(
844                        const int row_blocksize,                        const int row_blocksize,
# Line 785  SystemMatrixAdapter MeshAdapter::newSyst Line 877  SystemMatrixAdapter MeshAdapter::newSyst
877      checkFinleyError();      checkFinleyError();
878      Finley_SystemMatrix* fsystemMatrix=Finley_SystemMatrix_alloc(type,fsystemMatrixPattern,row_blocksize,column_blocksize);      Finley_SystemMatrix* fsystemMatrix=Finley_SystemMatrix_alloc(type,fsystemMatrixPattern,row_blocksize,column_blocksize);
879      checkFinleyError();      checkFinleyError();
880        Finley_SystemMatrixPattern_dealloc(fsystemMatrixPattern);
881      return SystemMatrixAdapter(fsystemMatrix,row_blocksize,row_functionspace,column_blocksize,column_functionspace);      return SystemMatrixAdapter(fsystemMatrix,row_blocksize,row_functionspace,column_blocksize,column_functionspace);
882  }  }
883    
884  //  //
885  // vtkObject MeshAdapter::createVtkObject() const  // vtkObject MeshAdapter::createVtkObject() const
886  // TODO:  // TODO:
887  //  //
888    
889  //  //
890  // returns true if data at the atom_type is considered as being cell centered:  // returns true if data at the atom_type is considered as being cell centered:
891  bool MeshAdapter::isCellOriented(int functionSpaceCode) const  bool MeshAdapter::isCellOriented(int functionSpaceCode) const
# Line 816  bool MeshAdapter::isCellOriented(int fun Line 911  bool MeshAdapter::isCellOriented(int fun
911    checkFinleyError();    checkFinleyError();
912    return false;    return false;
913  }  }
914    
915  bool MeshAdapter::probeInterpolationOnDomain(int functionSpaceType_source,int functionSpaceType_target) const  bool MeshAdapter::probeInterpolationOnDomain(int functionSpaceType_source,int functionSpaceType_target) const
916  {  {
917    switch(functionSpaceType_source) {    switch(functionSpaceType_source) {
# Line 879  bool MeshAdapter::probeInterpolationOnDo Line 975  bool MeshAdapter::probeInterpolationOnDo
975       case(ReducedDegreesOfFreedom):       case(ReducedDegreesOfFreedom):
976         switch(functionSpaceType_target) {         switch(functionSpaceType_target) {
977            case(ReducedDegreesOfFreedom):            case(ReducedDegreesOfFreedom):
           case(Nodes):  
978            case(Elements):            case(Elements):
979            case(FaceElements):            case(FaceElements):
980            case(Points):            case(Points):
981            case(ContactElementsZero):            case(ContactElementsZero):
982            case(ContactElementsOne):            case(ContactElementsOne):
983                return true;                return true;
984              case(Nodes):
985            case(DegreesOfFreedom):            case(DegreesOfFreedom):
986               return false;               return false;
987            default:            default:
# Line 901  bool MeshAdapter::probeInterpolationOnDo Line 997  bool MeshAdapter::probeInterpolationOnDo
997    checkFinleyError();    checkFinleyError();
998    return false;    return false;
999  }  }
1000    
1001  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
1002  {  {
1003      return false;      return false;
1004  }  }
1005  bool MeshAdapter::operator==(const MeshAdapter& other) const  
1006    bool MeshAdapter::operator==(const AbstractDomain& other) const
1007  {  {
1008    return (m_finleyMesh==other.m_finleyMesh);    const MeshAdapter* temp=dynamic_cast<const MeshAdapter*>(&other);
1009      if (temp!=0) {
1010        return (m_finleyMesh==temp->m_finleyMesh);
1011      } else {
1012        return false;
1013      }
1014    }
1015    
1016    bool MeshAdapter::operator!=(const AbstractDomain& other) const
1017    {
1018      return !(operator==(other));
1019  }  }
1020    
1021  int MeshAdapter::getSystemMatrixTypeId(const int solver, const bool symmetry) const  int MeshAdapter::getSystemMatrixTypeId(const int solver, const bool symmetry) const
# Line 916  int MeshAdapter::getSystemMatrixTypeId(c Line 1024  int MeshAdapter::getSystemMatrixTypeId(c
1024     checkFinleyError();     checkFinleyError();
1025     return out;     return out;
1026  }  }
1027    
1028  Data MeshAdapter::getX() const  Data MeshAdapter::getX() const
1029  {  {
1030    return continuousFunction(asAbstractContinuousDomain()).getX();    return continuousFunction(asAbstractContinuousDomain()).getX();
1031  }  }
1032    
1033  Data MeshAdapter::getNormal() const  Data MeshAdapter::getNormal() const
1034  {  {
1035    return functionOnBoundary(asAbstractContinuousDomain()).getNormal();    return functionOnBoundary(asAbstractContinuousDomain()).getNormal();
1036  }  }
1037    
1038  Data MeshAdapter::getSize() const  Data MeshAdapter::getSize() const
1039  {  {
1040    return function(asAbstractContinuousDomain()).getSize();    return function(asAbstractContinuousDomain()).getSize();
1041  }  }
1042    
1043    int MeshAdapter::getTagFromSampleNo(int functionSpaceType, int sampleNo) const
1044    {
1045      int* tagList;
1046      int numTags;
1047      getTagList(functionSpaceType, &tagList, &numTags);
1048      return tagList[sampleNo];
1049    }
1050    
1051  bool MeshAdapter::operator!=(const MeshAdapter& other) const  int MeshAdapter::getReferenceNoFromSampleNo(int functionSpaceType, int sampleNo) const
1052  {  {
1053    return !operator==(other);    int* referenceNoList;
1054      int numReferenceNo;
1055      getReferenceNoList(functionSpaceType, &referenceNoList, &numReferenceNo);
1056      return referenceNoList[sampleNo];
1057  }  }
1058  // bool MeshAdapter::operator==(const AbstractDomain& other) const  
 // {  
   // try {  
     // const MeshAdapter& ref = dynamic_cast<const MeshAdapter&>(other);  
     // return (operator==(ref));  
   // }  
   // catch (bad_cast) {  
     // return false;  
   // }  
 // }  
1059  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.97  
changed lines
  Added in v.149

  ViewVC Help
Powered by ViewVC 1.1.26