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 <map>
00030 #include "NodesOnlyMesh.hpp"
00031
00033
00035
00036 template<unsigned SPACE_DIM>
00037 void NodesOnlyMesh<SPACE_DIM>::ConstructNodesWithoutMesh(const std::vector<Node<SPACE_DIM>*>& rNodes)
00038 {
00039 this->Clear();
00040 for (unsigned i=0; i<rNodes.size(); i++)
00041 {
00042 assert(!rNodes[i]->IsDeleted());
00043 bool boundary = rNodes[i]->IsBoundaryNode();
00044 c_vector<double, SPACE_DIM> location = rNodes[i]->rGetLocation();
00045
00046 Node<SPACE_DIM>* p_node_copy = new Node<SPACE_DIM>(i, location, boundary);
00047 this->mNodes.push_back(p_node_copy);
00048 mCellRadii.push_back(1.0);
00049 }
00050 }
00051
00052 template<unsigned SPACE_DIM>
00053 void NodesOnlyMesh<SPACE_DIM>::ConstructNodesWithoutMesh(const TetrahedralMesh<SPACE_DIM,SPACE_DIM>& rGeneratingMesh)
00054 {
00055 ConstructNodesWithoutMesh(rGeneratingMesh.mNodes);
00056 }
00057
00058 template<unsigned SPACE_DIM>
00059 double NodesOnlyMesh<SPACE_DIM>::GetCellRadius(unsigned index)
00060 {
00061 return mCellRadii[index];
00062 }
00063
00064 template<unsigned SPACE_DIM>
00065 void NodesOnlyMesh<SPACE_DIM>::SetCellRadius(unsigned index, double radius)
00066 {
00067 mCellRadii[index] = radius;
00068 }
00069
00070 template<unsigned SPACE_DIM>
00071 void NodesOnlyMesh<SPACE_DIM>::ReMesh(NodeMap& map)
00072 {
00073
00074 std::vector<c_vector<double, SPACE_DIM> > old_node_locations;
00075 unsigned new_index = 0;
00076 for (unsigned i=0; i<this->GetNumAllNodes(); i++)
00077 {
00078 if (this->mNodes[i]->IsDeleted())
00079 {
00080 map.SetDeleted(i);
00081 }
00082 else
00083 {
00084 map.SetNewIndex(i, new_index);
00085 old_node_locations.push_back(this->mNodes[i]->rGetLocation());
00086 new_index++;
00087 }
00088 }
00089
00090
00091 this->Clear();
00092
00093
00094 for (unsigned node_index=0; node_index<old_node_locations.size(); node_index++)
00095 {
00096 Node<SPACE_DIM>* p_node = new Node<SPACE_DIM>(node_index, old_node_locations[node_index], false);
00097 this->mNodes.push_back(p_node);
00098
00099
00100 if (node_index==0 || node_index==old_node_locations.size()-1)
00101 {
00102 this->mBoundaryNodes.push_back(p_node);
00103 }
00104 }
00105
00106
00107 std::map<double, unsigned> location_index_map;
00108 for (unsigned i=0; i<this->mNodes.size(); i++)
00109 {
00110 location_index_map[this->mNodes[i]->rGetLocation()[0]] = this->mNodes[i]->GetIndex();
00111 }
00112
00113
00114 std::vector<unsigned> node_indices_ordered_spatially;
00115 for (std::map<double, unsigned>::iterator iter = location_index_map.begin();
00116 iter != location_index_map.end();
00117 ++iter)
00118 {
00119 node_indices_ordered_spatially.push_back(iter->second);
00120 }
00121 }
00122
00123 template<unsigned SPACE_DIM>
00124 void NodesOnlyMesh<SPACE_DIM>::DeleteNode(unsigned index)
00125 {
00126 if (this->mNodes[index]->IsDeleted())
00127 {
00128 EXCEPTION("Trying to delete a deleted node");
00129 }
00130
00131 this->mNodes[index]->MarkAsDeleted();
00132 this->mDeletedNodeIndices.push_back(index);
00133 }
00134
00136
00138
00139 template class NodesOnlyMesh<1>;
00140 template class NodesOnlyMesh<2>;
00141 template class NodesOnlyMesh<3>;
00142
00143
00144 #include "SerializationExportWrapperForCpp.hpp"
00145 EXPORT_TEMPLATE_CLASS_SAME_DIMS(NodesOnlyMesh)