SphereGeometryBoundaryCondition.cpp

00001 /*
00002 
00003 Copyright (c) 2005-2015, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #include "SphereGeometryBoundaryCondition.hpp"
00037 #include "NodeBasedCellPopulation.hpp"
00038 
00039 template<unsigned DIM>
00040 SphereGeometryBoundaryCondition<DIM>::SphereGeometryBoundaryCondition(AbstractCellPopulation<DIM>* pCellPopulation,
00041                                                                       c_vector<double, DIM> centre,
00042                                                                       double radius,
00043                                                                       double distance)
00044     : AbstractCellPopulationBoundaryCondition<DIM>(pCellPopulation),
00045       mCentreOfSphere(centre),
00046       mRadiusOfSphere(radius),
00047       mMaximumDistance(distance)
00048 {
00049     assert(mRadiusOfSphere > 0.0);
00050     assert(mMaximumDistance > 0.0);
00051 
00052     if (dynamic_cast<NodeBasedCellPopulation<DIM>*>(this->mpCellPopulation) == NULL)
00053     {
00054         EXCEPTION("A NodeBasedCellPopulation must be used with this boundary condition object.");
00055     }
00056     if (DIM == 1)
00057     {
00058         EXCEPTION("This boundary condition is not implemented in 1D.");
00059     }
00060 }
00061 
00062 template<unsigned DIM>
00063 const c_vector<double, DIM>& SphereGeometryBoundaryCondition<DIM>::rGetCentreOfSphere() const
00064 {
00065     return mCentreOfSphere;
00066 }
00067 
00068 template<unsigned DIM>
00069 double SphereGeometryBoundaryCondition<DIM>::GetRadiusOfSphere() const
00070 {
00071     return mRadiusOfSphere;
00072 }
00073 
00074 template<unsigned DIM>
00075 void SphereGeometryBoundaryCondition<DIM>::ImposeBoundaryCondition(const std::map<Node<DIM>*, c_vector<double, DIM> >& rOldLocations)
00076 {
00077     // Iterate over the cell population
00078     for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
00079          cell_iter != this->mpCellPopulation->End();
00080          ++cell_iter)
00081     {
00082         // Find the radial distance between this cell and the surface of the sphere
00083         c_vector<double,DIM> cell_location = this->mpCellPopulation->GetLocationOfCellCentre(*cell_iter);
00084         double radius = norm_2(cell_location - mCentreOfSphere);
00085         assert(radius != 0.0); //Can't project the centre to anywhere sensible
00086 
00087         // If the cell is too far from the surface of the sphere...
00088         if (fabs(radius - mRadiusOfSphere) > mMaximumDistance)
00089         {
00090             // ...move the cell back onto the surface of the sphere
00091             c_vector<double, DIM> location_on_sphere =
00092                 mCentreOfSphere + mRadiusOfSphere*(cell_location - mCentreOfSphere)/radius;
00093 
00094             unsigned node_index = this->mpCellPopulation->GetLocationIndexUsingCell(*cell_iter);
00095             Node<DIM>* p_node = this->mpCellPopulation->GetNode(node_index);
00096 
00097             p_node->rGetModifiableLocation() = location_on_sphere;
00098         }
00099     }
00100 }
00101 
00102 template<unsigned DIM>
00103 bool SphereGeometryBoundaryCondition<DIM>::VerifyBoundaryCondition()
00104 {
00105     bool condition_satisfied = true;
00106 
00107     // Iterate over the cell population
00108     for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
00109          cell_iter != this->mpCellPopulation->End();
00110          ++cell_iter)
00111     {
00112         // Find the radial distance between this cell and the surface of the sphere
00113         c_vector<double,DIM> cell_location = this->mpCellPopulation->GetLocationOfCellCentre(*cell_iter);
00114         double radius = norm_2(cell_location - mCentreOfSphere);
00115 
00116         // If the cell is too far from the surface of the sphere...
00117         if (fabs(radius - mRadiusOfSphere) > mMaximumDistance)
00118         {
00119             // ...then the boundary condition is not satisfied
00120             condition_satisfied = false;
00121             break;
00122         }
00123     }
00124     return condition_satisfied;
00125 }
00126 
00127 template<unsigned DIM>
00128 void SphereGeometryBoundaryCondition<DIM>::OutputCellPopulationBoundaryConditionParameters(out_stream& rParamsFile)
00129 {
00130     *rParamsFile << "\t\t\t<CentreOfSphere>";
00131     for (unsigned index=0; index != DIM-1U; index++) // Note: inequality avoids testing index < 0U when DIM=1
00132     {
00133         *rParamsFile << mCentreOfSphere[index] << ",";
00134     }
00135     *rParamsFile << mCentreOfSphere[DIM-1] << "</CentreOfSphere>\n";
00136 
00137     *rParamsFile << "\t\t\t<RadiusOfSphere>" << mRadiusOfSphere << "</RadiusOfSphere>\n";
00138     *rParamsFile << "\t\t\t<MaximumDistance>" << mMaximumDistance << "</MaximumDistance>\n";
00139 
00140     // Call method on direct parent class
00141     AbstractCellPopulationBoundaryCondition<DIM>::OutputCellPopulationBoundaryConditionParameters(rParamsFile);
00142 }
00143 
00145 // Explicit instantiation
00147 
00148 template class SphereGeometryBoundaryCondition<1>;
00149 template class SphereGeometryBoundaryCondition<2>;
00150 template class SphereGeometryBoundaryCondition<3>;
00151 
00152 // Serialization for Boost >= 1.36
00153 #include "SerializationExportWrapperForCpp.hpp"
00154 EXPORT_TEMPLATE_CLASS_SAME_DIMS(SphereGeometryBoundaryCondition)

Generated by  doxygen 1.6.2