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