SphereGeometryBoundaryCondition.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
00078 for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
00079 cell_iter != this->mpCellPopulation->End();
00080 ++cell_iter)
00081 {
00082
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);
00086
00087
00088 if (fabs(radius - mRadiusOfSphere) > mMaximumDistance)
00089 {
00090
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
00108 for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
00109 cell_iter != this->mpCellPopulation->End();
00110 ++cell_iter)
00111 {
00112
00113 c_vector<double,DIM> cell_location = this->mpCellPopulation->GetLocationOfCellCentre(*cell_iter);
00114 double radius = norm_2(cell_location - mCentreOfSphere);
00115
00116
00117 if (fabs(radius - mRadiusOfSphere) > mMaximumDistance)
00118 {
00119
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++)
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
00141 AbstractCellPopulationBoundaryCondition<DIM>::OutputCellPopulationBoundaryConditionParameters(rParamsFile);
00142 }
00143
00145
00147
00148 template class SphereGeometryBoundaryCondition<1>;
00149 template class SphereGeometryBoundaryCondition<2>;
00150 template class SphereGeometryBoundaryCondition<3>;
00151
00152
00153 #include "SerializationExportWrapperForCpp.hpp"
00154 EXPORT_TEMPLATE_CLASS_SAME_DIMS(SphereGeometryBoundaryCondition)