MixedDimensionMesh.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "MixedDimensionMesh.hpp"
00030 #include "Exception.hpp"
00031
00032 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00033 MixedDimensionMesh<ELEMENT_DIM, SPACE_DIM>::MixedDimensionMesh(DistributedTetrahedralMeshPartitionType::type partitioningMethod)
00034 : DistributedTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::DistributedTetrahedralMesh(partitioningMethod)
00035 {
00036 }
00037
00038 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00039 MixedDimensionMesh<ELEMENT_DIM, SPACE_DIM>::~MixedDimensionMesh()
00040 {
00041 for (unsigned i=0; i<mCableElements.size(); i++)
00042 {
00043 delete mCableElements[i];
00044 }
00045 }
00046
00047 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00048 void MixedDimensionMesh<ELEMENT_DIM, SPACE_DIM>::ConstructFromMeshReader(AbstractMeshReader<ELEMENT_DIM,SPACE_DIM>& rMeshReader)
00049 {
00050 DistributedTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>::ConstructFromMeshReader(rMeshReader);
00051
00052
00053
00054
00055 mNumCableElements = rMeshReader.GetNumCableElements();
00056
00057
00058 for (unsigned element_index=0; element_index < mNumCableElements; element_index++)
00059 {
00060 ElementData element_data = rMeshReader.GetNextCableElementData();
00061
00062 if ( this->mNodesPermutation.empty() == false)
00063 {
00064 for (unsigned j=0; j<2; j++)
00065 {
00066 element_data.NodeIndices[j] = this->mNodesPermutation[ element_data.NodeIndices[j] ];
00067 }
00068 }
00069
00070
00071 bool node_owned = false;
00072 for (unsigned j=0; j<2; j++)
00073 {
00074 try
00075 {
00076 this->SolveNodeMapping(element_data.NodeIndices[j]);
00077 node_owned = true;
00078 break;
00079 }
00080 catch (Exception &e)
00081 {
00082
00083 }
00084 }
00085
00086
00087 if (node_owned)
00088 {
00089 std::vector<Node<SPACE_DIM>*> nodes;
00090 nodes.reserve(2u);
00091
00092 for (unsigned j=0; j<2; j++)
00093 {
00094
00095
00096
00097 try
00098 {
00099 nodes.push_back(this->GetNodeOrHaloNode(element_data.NodeIndices[j]) );
00100 }
00101 catch (Exception& e)
00102 {
00103 NEVER_REACHED;
00104 }
00105 }
00106
00107 Element<1u, SPACE_DIM>* p_element = new Element<1u,SPACE_DIM>(element_index, nodes);
00108 RegisterCableElement(element_index);
00109 this->mCableElements.push_back(p_element);
00110
00111 if (rMeshReader.GetNumCableElementAttributes() > 0)
00112 {
00113 assert(rMeshReader.GetNumCableElementAttributes() == 1);
00114 p_element->SetRegion(element_data.AttributeValue);
00115 }
00116 }
00117 }
00118
00119 rMeshReader.Reset();
00120 }
00121 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00122 void MixedDimensionMesh<ELEMENT_DIM, SPACE_DIM>::RegisterCableElement(unsigned index)
00123 {
00124 mCableElementsMapping[index] = this->mCableElements.size();
00125 }
00126
00127 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00128 unsigned MixedDimensionMesh<ELEMENT_DIM, SPACE_DIM>::GetNumCableElements() const
00129 {
00130 return mNumCableElements;
00131 }
00132 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00133 unsigned MixedDimensionMesh<ELEMENT_DIM, SPACE_DIM>::GetNumLocalCableElements() const
00134 {
00135 return mCableElements.size();
00136 }
00137
00138 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00139 Element<1u, SPACE_DIM>* MixedDimensionMesh<ELEMENT_DIM, SPACE_DIM>::GetCableElement(unsigned globalElementIndex) const
00140 {
00141 std::map<unsigned, unsigned>::const_iterator element_position = mCableElementsMapping.find(globalElementIndex);
00142
00143 if (element_position == mCableElementsMapping.end())
00144 {
00145 EXCEPTION("Requested cable element " << globalElementIndex << " does not belong to processor " << PetscTools::GetMyRank());
00146 }
00147
00148 unsigned index = element_position->second;
00149
00150 return mCableElements[index];
00151 }
00152
00153 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00154 bool MixedDimensionMesh<ELEMENT_DIM, SPACE_DIM>::CalculateDesignatedOwnershipOfCableElement( unsigned elementIndex )
00155 {
00156
00157 try
00158 {
00159 unsigned tie_break_index = this->GetCableElement(elementIndex)->GetNodeGlobalIndex(0);
00160
00161
00162 if (this->GetDistributedVectorFactory()->IsGlobalIndexLocal(tie_break_index))
00163 {
00164 return true;
00165 }
00166 else
00167 {
00168 return false;
00169 }
00170 }
00171 catch (Exception &e)
00172 {
00173
00174 return false;
00175 }
00176 }
00177
00178
00179
00180 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00181 typename MixedDimensionMesh<ELEMENT_DIM, SPACE_DIM>::CableElementIterator MixedDimensionMesh<ELEMENT_DIM, SPACE_DIM>::GetCableElementIteratorBegin() const
00182 {
00183 return mCableElements.begin();
00184 }
00185
00186 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00187 typename MixedDimensionMesh<ELEMENT_DIM, SPACE_DIM>::CableElementIterator MixedDimensionMesh<ELEMENT_DIM, SPACE_DIM>::GetCableElementIteratorEnd() const
00188 {
00189 return mCableElements.end();
00190 }
00191
00192
00193
00195
00197
00198 template class MixedDimensionMesh<1,1>;
00199 template class MixedDimensionMesh<1,2>;
00200 template class MixedDimensionMesh<1,3>;
00201 template class MixedDimensionMesh<2,2>;
00202 template class MixedDimensionMesh<2,3>;
00203 template class MixedDimensionMesh<3,3>;
00204
00205
00206 #include "SerializationExportWrapperForCpp.hpp"
00207 EXPORT_TEMPLATE_CLASS_ALL_DIMS(MixedDimensionMesh)