AbstractMesh.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
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 "AbstractMesh.hpp"
00030 
00032 // Implementation
00034 
00035 
00036 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00037 AbstractMesh<ELEMENT_DIM, SPACE_DIM>::AbstractMesh()
00038     : mpDistributedVectorFactory(NULL),
00039       mMeshFileBaseName(""),
00040       mMeshChangesDuringSimulation(false)
00041 {
00042 }
00043 
00044 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00045 AbstractMesh<ELEMENT_DIM, SPACE_DIM>::~AbstractMesh()
00046 {
00047     // Iterate over nodes and free the memory
00048     for (unsigned i=0; i<mNodes.size(); i++)
00049     {
00050         delete mNodes[i];
00051     }
00052     if (mpDistributedVectorFactory)
00053     {
00054         delete mpDistributedVectorFactory;
00055     }
00056 }
00057 
00058 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00059 unsigned AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetNumNodes() const
00060 {
00061     return mNodes.size();
00062 }
00063 
00064 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00065 unsigned AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetNumBoundaryNodes() const
00066 {
00067     return mBoundaryNodes.size();
00068 }
00069 
00070 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00071 unsigned AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetNumAllNodes() const
00072 {
00073     return mNodes.size();
00074 }
00075 
00076 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00077 Node<SPACE_DIM>* AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetNode(unsigned index) const
00078 {
00079     unsigned local_index = SolveNodeMapping(index);
00080     return mNodes[local_index];
00081 }
00082 
00083 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00084 void AbstractMesh<ELEMENT_DIM, SPACE_DIM>::ReadNodesPerProcessorFile(const std::string& rNodesPerProcessorFile)
00085 {
00086     NEVER_REACHED;
00087 }
00088 
00089 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00090 DistributedVectorFactory* AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetDistributedVectorFactory()
00091 {
00092     if (mpDistributedVectorFactory == NULL)
00093     {
00094         mpDistributedVectorFactory=new DistributedVectorFactory(GetNumNodes());
00095     }
00096     return mpDistributedVectorFactory;
00097 }
00098 
00099 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00100 void AbstractMesh<ELEMENT_DIM, SPACE_DIM>::PermuteNodes()
00101 {
00102     NEVER_REACHED;
00103 }
00104 
00105 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00106 typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::BoundaryNodeIterator AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetBoundaryNodeIteratorBegin() const
00107 {
00108     return mBoundaryNodes.begin();
00109 }
00110 
00111 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00112 typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::BoundaryNodeIterator AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetBoundaryNodeIteratorEnd() const
00113 {
00114     return mBoundaryNodes.end();
00115 }
00116 
00117 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00118 std::string AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetMeshFileBaseName() const
00119 {
00120     if (mMeshFileBaseName == "")
00121     {
00122         EXCEPTION("This mesh was not constructed from a file.");
00123     }
00124 
00125     return mMeshFileBaseName;
00126 }
00127 
00128 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00129 const std::vector<unsigned>& AbstractMesh<ELEMENT_DIM, SPACE_DIM>::rGetNodePermutation() const
00130 {
00131     return mNodesPermutation;
00132 }
00133 
00134 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00135 c_vector<double, SPACE_DIM> AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetVectorFromAtoB(
00136     const c_vector<double, SPACE_DIM>& rLocationA, const c_vector<double, SPACE_DIM>& rLocationB)
00137 {
00138     c_vector<double, SPACE_DIM> vector = rLocationB - rLocationA;
00139     return vector;
00140 }
00141 
00142 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00143 double AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetDistanceBetweenNodes(unsigned indexA, unsigned indexB)
00144 {
00145     c_vector<double, SPACE_DIM> vector = GetVectorFromAtoB(mNodes[indexA]->rGetLocation(),
00146                                                            mNodes[indexB]->rGetLocation());
00147     return norm_2(vector);
00148 }
00149 
00150 
00151 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00152 double AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetWidth(const unsigned& rDimension) const
00153 {
00154     assert(rDimension < SPACE_DIM);
00155     c_vector<double,2> extremes = GetWidthExtremes(rDimension);
00156     return extremes[1] - extremes[0];
00157 }
00158 
00159 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00160 c_vector<double,2> AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetWidthExtremes(const unsigned& rDimension) const
00161 {
00162     assert(rDimension < SPACE_DIM);
00163 
00164     double max = -1e200;
00165     double min = 1e200;
00166 
00167     assert(GetNumAllNodes() > 0u);
00168 
00170     for (unsigned i=0; i<GetNumAllNodes(); i++)
00171     {
00172         if (!mNodes[i]->IsDeleted())
00173         {
00174             double this_node_value = mNodes[i]->rGetLocation()[rDimension];
00175             if (this_node_value>max)
00176             {
00177                 max = this_node_value;
00178             }
00179             if (this_node_value < min)
00180             {
00181                 min = this_node_value;
00182             }
00183         }
00184     }
00185     c_vector<double,2> extremes;
00186     extremes[0] = min;
00187     extremes[1] = max;
00188     return extremes;
00189 }
00190 
00191 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00192 void AbstractMesh<ELEMENT_DIM, SPACE_DIM>::Scale(const double xScale, const double yScale, const double zScale)
00193 {
00194     unsigned num_nodes = GetNumAllNodes();
00195 
00196     for (unsigned i=0; i<num_nodes; i++)
00197     {
00198         c_vector<double, SPACE_DIM>& r_location = mNodes[i]->rGetModifiableLocation();
00199         if (SPACE_DIM>=3)
00200         {
00201             r_location[2] *= zScale;
00202         }
00203         if (SPACE_DIM>=2)
00204         {
00205             r_location[1] *= yScale;
00206         }
00207         r_location[0] *= xScale;
00208     }
00209 
00210     RefreshMesh();
00211 }
00212 
00213 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00214 void AbstractMesh<ELEMENT_DIM, SPACE_DIM>::RefreshMesh()
00215 {
00216 }
00217 
00218 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00219 bool AbstractMesh<ELEMENT_DIM, SPACE_DIM>::IsMeshChanging() const
00220 {
00221     return mMeshChangesDuringSimulation;
00222 }
00223 
00225 // Explicit instantiation
00227 
00228 template class AbstractMesh<1,1>;
00229 template class AbstractMesh<1,2>;
00230 template class AbstractMesh<1,3>;
00231 template class AbstractMesh<2,2>;
00232 template class AbstractMesh<2,3>;
00233 template class AbstractMesh<3,3>;

Generated on Tue Aug 4 16:10:22 2009 for Chaste by  doxygen 1.5.5