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