/[escript]/branches/trilinos_from_5897/dudley/src/Mesh.cpp
ViewVC logotype

Diff of /branches/trilinos_from_5897/dudley/src/Mesh.cpp

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

revision 6078 by caltinay, Wed Mar 2 04:13:26 2016 UTC revision 6079 by caltinay, Mon Mar 21 12:22:38 2016 UTC
# Line 17  Line 17 
17    
18  namespace dudley {  namespace dudley {
19    
20  /*   allocates a Mesh with name name for elements of type id using an integration order. If order is negative, */  /// constructor
21  /*   the most appropriate order is selected independently. */  Mesh::Mesh(const std::string name, int numDim, escript::JMPI mpi_info) :
22        m_name(name),
23        // order of shapeFunctions is always 1 in Dudley
24        approximationOrder(1),
25        integrationOrder(2),
26        reducedIntegrationOrder(0),
27        Elements(NULL),
28        FaceElements(NULL),
29        Points(NULL),
30        MPIInfo(mpi_info)
31    {
32        // allocate node table
33        Nodes = new NodeFile(numDim, mpi_info);
34    }
35    
36  Dudley_Mesh *Dudley_Mesh_alloc(char *name, dim_t numDim, escript::JMPI& mpi_info)  /// destructor
37    Mesh::~Mesh()
38  {  {
39      Dudley_Mesh *out;      delete Nodes;
40        delete FaceElements;
41        delete Elements;
42        delete Points;
43    }
44    
45      /*  allocate the return value */  void Mesh::setElements(ElementFile* elements)
46    {
47        delete Elements;
48        Elements = elements;
49    }
50    
51      out = new Dudley_Mesh;  void Mesh::setFaceElements(ElementFile* elements)
52      out->Name = NULL;  {
53      out->Nodes = NULL;      delete FaceElements;
54      out->Elements = NULL;      FaceElements = elements;
     out->FaceElements = NULL;  
     out->Points = NULL;  
     out->TagMap = NULL;  
     out->reference_counter = 0;  
     out->MPIInfo = mpi_info;  
   
     /*   copy name: */  
     out->Name = new char[strlen(name) + 1];  
     strcpy(out->Name, name);  
   
     /*   allocate node table: */  
     out->Nodes = Dudley_NodeFile_alloc(numDim, mpi_info);  
     out->approximationOrder = -1;  
     out->reducedApproximationOrder = -1;  
     out->integrationOrder = -1;  
     out->reducedIntegrationOrder = -1;  
   
     out->Elements = NULL;  
     out->FaceElements = NULL;  
     out->Points = NULL;  
     out->reference_counter++;  
     return out;  
 }  
   
 /* returns a reference to Dudley_Mesh in */  
   
 Dudley_Mesh *Dudley_Mesh_reference(Dudley_Mesh * in)  
 {  
     if (in != NULL)  
         ++(in->reference_counter);  
     return in;  
 }  
   
 /*   frees a mesh: */  
   
 void Dudley_Mesh_free(Dudley_Mesh * in)  
 {  
     if (in != NULL)  
     {  
         in->reference_counter--;  
         if (in->reference_counter < 1)  
         {  
             delete[] in->Name;  
             Dudley_NodeFile_free(in->Nodes);  
             Dudley_ElementFile_free(in->FaceElements);  
             Dudley_ElementFile_free(in->Elements);  
             Dudley_ElementFile_free(in->Points);  
             Dudley_TagMap_free(in->TagMap);  
             delete in;  
         }  
     }  
55  }  }
56    
57  /************************************************************************************/  void Mesh::setPoints(ElementFile* elements)
58    {
59        delete Points;
60        Points = elements;
61    }
62    
63  /*  returns the spatial dimension of the mesh: */  void Mesh::createMappings(const std::vector<index_t>& dofDist,
64                              const std::vector<index_t>& nodeDist)
65    {
66        Nodes->createNodeMappings(dofDist, nodeDist);
67    }
68    
69  dim_t Dudley_Mesh_getDim(Dudley_Mesh * in)  void Mesh::markNodes(std::vector<short>& mask, index_t offset) const
70  {  {
71      return in->Nodes->numDim;      Elements->markNodes(mask, offset);
72        FaceElements->markNodes(mask, offset);
73        Points->markNodes(mask, offset);
74  }  }
75    
76  void Dudley_Mesh_setElements(Dudley_Mesh * self, Dudley_ElementFile * elements)  void Mesh::relabelElementNodes(const index_t* newNode, index_t offset)
77  {  {
78      Dudley_ElementFile_free(self->Elements);      Elements->relabelNodes(newNode, offset);
79      self->Elements = elements;      FaceElements->relabelNodes(newNode, offset);
80        Points->relabelNodes(newNode, offset);
81  }  }
82    
83  void Dudley_Mesh_setFaceElements(Dudley_Mesh * self, Dudley_ElementFile * elements)  void Mesh::setCoordinates(const escript::Data& newX)
84  {  {
85      Dudley_ElementFile_free(self->FaceElements);      Nodes->setCoordinates(newX);
     self->FaceElements = elements;  
86  }  }
87    
88  void Dudley_Mesh_setPoints(Dudley_Mesh * self, Dudley_ElementFile * elements)  void Mesh::addTagMap(const std::string& name, int tag_key)
89  {  {
90      Dudley_ElementFile_free(self->Points);      tagMap[name] = tag_key;
     self->Points = elements;  
91  }  }
92    
93  int Dudley_Mesh_getStatus(Dudley_Mesh * in)  int Mesh::getTag(const std::string& name) const
94  {  {
95      if (in == NULL)      TagMap::const_iterator it = tagMap.find(name);
96      {      if (it == tagMap.end()) {
97          return -1;          std::stringstream ss;
98      }          ss << "getTag: unknown tag name " << name << ".";
99      else if (in->Nodes == NULL)          const std::string errorMsg(ss.str());
100      {          throw escript::ValueError(errorMsg);
         return -1;  
     }  
     else  
     {  
         return in->Nodes->status;  
101      }      }
102        return it->second;
103  }  }
104    
105  void Dudley_Mesh_setOrders(Dudley_Mesh * in)  bool Mesh::isValidTagName(const std::string& name) const
106  {  {
107      in->approximationOrder = 1; /* order of shapeFunctions is always 1 in Dudley */      return (tagMap.count(name) > 0);
     in->reducedApproximationOrder = 1;  
     in->integrationOrder = 2;  
     in->reducedIntegrationOrder = 0;  
108  }  }
109    
110  } // namespace dudley  } // namespace dudley

Legend:
Removed from v.6078  
changed lines
  Added in v.6079

  ViewVC Help
Powered by ViewVC 1.1.26