PlaneBoundaryCondition.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 "PlaneBoundaryCondition.hpp"
00030 #include "AbstractCentreBasedCellPopulation.hpp"
00031 
00032 template <unsigned DIM>
00033 PlaneBoundaryCondition<DIM>::PlaneBoundaryCondition(AbstractCellPopulation<DIM>* pCellPopulation,
00034                                                     c_vector<double, DIM> point,
00035                                                     c_vector<double, DIM> normal)
00036         : AbstractCellPopulationBoundaryCondition<DIM>(pCellPopulation),
00037           mPointOnPlane(point)
00038 {
00039     assert( (dynamic_cast<AbstractCentreBasedCellPopulation<DIM>*>(this->mpCellPopulation)) || (this->mpCellPopulation == NULL));
00040 
00041     assert(norm_2(normal) > 0.0);
00042     mNormalToPlane = normal/norm_2(normal);
00043 }
00044 
00045 template <unsigned DIM>
00046 const c_vector<double, DIM>& PlaneBoundaryCondition<DIM>::rGetPointOnPlane() const
00047 {
00048     return mPointOnPlane;
00049 }
00050 
00051 template <unsigned DIM>
00052 const c_vector<double, DIM>& PlaneBoundaryCondition<DIM>::rGetNormalToPlane() const
00053 {
00054     return mNormalToPlane;
00055 }
00056 
00057 template<unsigned DIM>
00058 void PlaneBoundaryCondition<DIM>::ImposeBoundaryCondition()
00059 {
00060     if (DIM==2)
00061     {
00062         for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
00063              cell_iter != this->mpCellPopulation->End();
00064              ++cell_iter)
00065         {
00067             c_vector<double, DIM> cell_location = this->mpCellPopulation->GetLocationOfCellCentre(*cell_iter);
00068 
00069             unsigned node_index = this->mpCellPopulation->GetLocationIndexUsingCell(*cell_iter);
00070             Node<DIM>* p_node = this->mpCellPopulation->GetNode(node_index);
00071 
00072             if (inner_prod(cell_location - mPointOnPlane,mNormalToPlane) > 0.0)
00073             {
00074                 c_vector<double, 2> tangent;
00075                 tangent(0) = -mNormalToPlane(1);
00076                 tangent(1) = mNormalToPlane(0);
00077 
00078                 c_vector<double, 2> intersection = mPointOnPlane + inner_prod(tangent,cell_location- mPointOnPlane)*tangent;
00079 
00080                 p_node->rGetModifiableLocation() = intersection;
00081             }
00082         }
00083     }
00084     else
00085     {
00086         EXCEPTION("PlaneBoundaryCondition is not yet implemented in 1D or 3D");
00087     }
00088 }
00089 
00090 template<unsigned DIM>
00091 bool PlaneBoundaryCondition<DIM>::VerifyBoundaryCondition()
00092 {
00093     bool condition_satisfied = true;
00094 
00095     if (DIM==2)
00096     {
00097         for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
00098              cell_iter != this->mpCellPopulation->End();
00099              ++cell_iter)
00100         {
00101             c_vector<double, DIM> cell_location = this->mpCellPopulation->GetLocationOfCellCentre(*cell_iter);
00102 
00103             if ( inner_prod(cell_location - mPointOnPlane,mNormalToPlane) > 0.0 )
00104             {
00105                 condition_satisfied = false;
00106                 break;
00107             }
00108         }
00109     }
00110     else
00111     {
00112         EXCEPTION("PlaneBoundaryCondition is not yet implemented in 1D or 3D");
00113     }
00114 
00115     return condition_satisfied;
00116 }
00117 
00118 template<unsigned DIM>
00119 void PlaneBoundaryCondition<DIM>::OutputCellPopulationBoundaryConditionParameters(out_stream& rParamsFile)
00120 {
00121     *rParamsFile << "\t\t\t<PointOnPlane>";
00122     for (unsigned index=0; index != DIM-1U; index++) // Note: inequality avoids testing index < 0U when DIM=1
00123     {
00124         *rParamsFile << mPointOnPlane[index] << ",";
00125     }
00126     *rParamsFile << mPointOnPlane[DIM-1] << "</PointOnPlane> \n";
00127 
00128     *rParamsFile << "\t\t\t<NormalToPlane>";
00129      for (unsigned index=0; index != DIM-1U; index++) // Note: inequality avoids testing index < 0U when DIM=1
00130      {
00131          *rParamsFile << mNormalToPlane[index] << ",";
00132      }
00133      *rParamsFile << mNormalToPlane[DIM-1] << "</NormalToPlane> \n";
00134 
00135     // Call method on direct parent class
00136     AbstractCellPopulationBoundaryCondition<DIM>::OutputCellPopulationBoundaryConditionParameters(rParamsFile);
00137 }
00138 
00140 // Explicit instantiation
00142 
00143 template class PlaneBoundaryCondition<1>;
00144 template class PlaneBoundaryCondition<2>;
00145 template class PlaneBoundaryCondition<3>;
00146 
00147 // Serialization for Boost >= 1.36
00148 #include "SerializationExportWrapperForCpp.hpp"
00149 EXPORT_TEMPLATE_CLASS_SAME_DIMS(PlaneBoundaryCondition)

Generated on Mon Apr 18 11:35:27 2011 for Chaste by  doxygen 1.5.5