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 #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
00071 for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
00072 cell_iter != this->mpCellPopulation->End();
00073 ++cell_iter)
00074 {
00075
00076 c_vector<double,DIM> cell_location = this->mpCellPopulation->GetLocationOfCellCentre(*cell_iter);
00077 double radius = norm_2(cell_location - mCentreOfSphere);
00078
00079
00080 if (fabs(radius - mRadiusOfSphere) > mMaximumDistance)
00081 {
00082
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
00100 for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
00101 cell_iter != this->mpCellPopulation->End();
00102 ++cell_iter)
00103 {
00104
00105 c_vector<double,DIM> cell_location = this->mpCellPopulation->GetLocationOfCellCentre(*cell_iter);
00106 double radius = norm_2(cell_location - mCentreOfSphere);
00107
00108
00109 if (fabs(radius - mRadiusOfSphere) > mMaximumDistance)
00110 {
00111
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++)
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
00133 AbstractCellPopulationBoundaryCondition<DIM>::OutputCellPopulationBoundaryConditionParameters(rParamsFile);
00134 }
00135
00137
00139
00140 template class SphereGeometryBoundaryCondition<1>;
00141 template class SphereGeometryBoundaryCondition<2>;
00142 template class SphereGeometryBoundaryCondition<3>;
00143
00144
00145 #include "SerializationExportWrapperForCpp.hpp"
00146 EXPORT_TEMPLATE_CLASS_SAME_DIMS(SphereGeometryBoundaryCondition)