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