NodesOnlyMesh.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 #include <map>
00030 #include "NodesOnlyMesh.hpp"
00031 
00033 // Implementation
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     // Store the node locations
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     // Remove current data
00091     this->Clear();
00092 
00093     // Construct the nodes and boundary nodes
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         // As we're in 1D, the boundary nodes are simply at either end of the mesh
00100         if (node_index==0 || node_index==old_node_locations.size()-1)
00101         {
00102             this->mBoundaryNodes.push_back(p_node);
00103         }
00104     }
00105 
00106     // Create a map between node indices and node locations
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     // Use this map to generate a vector of node indices that are ordered spatially
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 // Explicit instantiation
00138 
00139 template class NodesOnlyMesh<1>;
00140 template class NodesOnlyMesh<2>;
00141 template class NodesOnlyMesh<3>;
00142 
00143 // Serialization for Boost >= 1.36
00144 #include "SerializationExportWrapperForCpp.hpp"
00145 EXPORT_TEMPLATE_CLASS_SAME_DIMS(NodesOnlyMesh)

Generated on Tue May 31 14:31:40 2011 for Chaste by  doxygen 1.5.5