SphereGeometryBoundaryCondition.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 "SphereGeometryBoundaryCondition.hpp"
00030 #include "NodeBasedCellPopulation.hpp"
00031 
00032 template<unsigned DIM>
00033 SphereGeometryBoundaryCondition<DIM>::SphereGeometryBoundaryCondition(AbstractCellPopulation<DIM>* pCellPopulation,
00034                                                                       c_vector<double, DIM> centre,
00035                                                                       double radius,
00036                                                                       double distance)
00037     : AbstractCellPopulationBoundaryCondition<DIM>(pCellPopulation),
00038       mCentreOfSphere(centre),
00039       mRadiusOfSphere(radius),
00040       mMaximumDistance(distance)
00041 {
00042     assert(mRadiusOfSphere > 0.0);
00043     assert(mMaximumDistance > 0.0);
00044 
00045     if (dynamic_cast<NodeBasedCellPopulation<DIM>*>(this->mpCellPopulation) == NULL)
00046     {
00047         EXCEPTION("A NodeBasedCellPopulation must be used with this boundary condition object.");
00048     }
00049     if (DIM == 1)
00050     {
00051         EXCEPTION("This boundary condition is not implemented in 1D.");
00052     }
00053 }
00054 
00055 template<unsigned DIM>
00056 const c_vector<double, DIM>& SphereGeometryBoundaryCondition<DIM>::rGetCentreOfSphere() const
00057 {
00058     return mCentreOfSphere;
00059 }
00060 
00061 template<unsigned DIM>
00062 double SphereGeometryBoundaryCondition<DIM>::GetRadiusOfSphere() const
00063 {
00064     return mRadiusOfSphere;
00065 }
00066 
00067 template<unsigned DIM>
00068 void SphereGeometryBoundaryCondition<DIM>::ImposeBoundaryCondition(const std::vector<c_vector<double, DIM> >& rOldLocations)
00069 {
00070     // Iterate over the cell population
00071     for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
00072          cell_iter != this->mpCellPopulation->End();
00073          ++cell_iter)
00074     {
00075         // Find the radial distance between this cell and the surface of the sphere
00076         c_vector<double,DIM> cell_location = this->mpCellPopulation->GetLocationOfCellCentre(*cell_iter);
00077         double radius = norm_2(cell_location - mCentreOfSphere);
00078 
00079         // If the cell is too far from the surface of the sphere...
00080         if (fabs(radius - mRadiusOfSphere) > mMaximumDistance)
00081         {
00082             // ...move the cell back onto the surface of the sphere
00083             c_vector<double, DIM> location_on_sphere =
00084                 mCentreOfSphere + mRadiusOfSphere*(cell_location - mCentreOfSphere)/radius;
00085 
00086             unsigned node_index = this->mpCellPopulation->GetLocationIndexUsingCell(*cell_iter);
00087             Node<DIM>* p_node = this->mpCellPopulation->GetNode(node_index);
00088 
00089             p_node->rGetModifiableLocation() = location_on_sphere;
00090         }
00091     }
00092 }
00093 
00094 template<unsigned DIM>
00095 bool SphereGeometryBoundaryCondition<DIM>::VerifyBoundaryCondition()
00096 {
00097     bool condition_satisfied = true;
00098 
00099     // Iterate over the cell population
00100     for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
00101          cell_iter != this->mpCellPopulation->End();
00102          ++cell_iter)
00103     {
00104         // Find the radial distance between this cell and the surface of the sphere
00105         c_vector<double,DIM> cell_location = this->mpCellPopulation->GetLocationOfCellCentre(*cell_iter);
00106         double radius = norm_2(cell_location - mCentreOfSphere);
00107 
00108         // If the cell is too far from the surface of the sphere...
00109         if (fabs(radius - mRadiusOfSphere) > mMaximumDistance)
00110         {
00111             // ...then the boundary condition is not satisfied
00112             condition_satisfied = false;
00113             break;
00114         }
00115     }
00116     return condition_satisfied;
00117 }
00118 
00119 template<unsigned DIM>
00120 void SphereGeometryBoundaryCondition<DIM>::OutputCellPopulationBoundaryConditionParameters(out_stream& rParamsFile)
00121 {
00122     *rParamsFile << "\t\t\t<CentreOfSphere>";
00123     for (unsigned index=0; index != DIM-1U; index++) // Note: inequality avoids testing index < 0U when DIM=1
00124     {
00125         *rParamsFile << mCentreOfSphere[index] << ",";
00126     }
00127     *rParamsFile << mCentreOfSphere[DIM-1] << "</CentreOfSphere>\n";
00128 
00129     *rParamsFile << "\t\t\t<RadiusOfSphere>" << mRadiusOfSphere << "</RadiusOfSphere>\n";
00130     *rParamsFile << "\t\t\t<MaximumDistance>" << mMaximumDistance << "</MaximumDistance>\n";
00131 
00132     // Call method on direct parent class
00133     AbstractCellPopulationBoundaryCondition<DIM>::OutputCellPopulationBoundaryConditionParameters(rParamsFile);
00134 }
00135 
00137 // Explicit instantiation
00139 
00140 template class SphereGeometryBoundaryCondition<1>;
00141 template class SphereGeometryBoundaryCondition<2>;
00142 template class SphereGeometryBoundaryCondition<3>;
00143 
00144 // Serialization for Boost >= 1.36
00145 #include "SerializationExportWrapperForCpp.hpp"
00146 EXPORT_TEMPLATE_CLASS_SAME_DIMS(SphereGeometryBoundaryCondition)
Generated on Thu Dec 22 13:00:04 2011 for Chaste by  doxygen 1.6.3