PlaneBoundaryCondition.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 "PlaneBoundaryCondition.hpp"
00037 #include "AbstractCentreBasedCellPopulation.hpp"
00038 #include "VertexBasedCellPopulation.hpp"
00039 #include "RandomNumberGenerator.hpp"
00040
00041 template<unsigned DIM>
00042 PlaneBoundaryCondition<DIM>::PlaneBoundaryCondition(AbstractCellPopulation<DIM>* pCellPopulation,
00043 c_vector<double, DIM> point,
00044 c_vector<double, DIM> normal)
00045 : AbstractCellPopulationBoundaryCondition<DIM>(pCellPopulation),
00046 mPointOnPlane(point),
00047 mUseJiggledNodesOnPlane(false)
00048 {
00049 assert(norm_2(normal) > 0.0);
00050 mNormalToPlane = normal/norm_2(normal);
00051 }
00052
00053 template<unsigned DIM>
00054 const c_vector<double, DIM>& PlaneBoundaryCondition<DIM>::rGetPointOnPlane() const
00055 {
00056 return mPointOnPlane;
00057 }
00058
00059 template<unsigned DIM>
00060 const c_vector<double, DIM>& PlaneBoundaryCondition<DIM>::rGetNormalToPlane() const
00061 {
00062 return mNormalToPlane;
00063 }
00064
00065
00066 template<unsigned DIM>
00067 void PlaneBoundaryCondition<DIM>::SetUseJiggledNodesOnPlane(bool useJiggledNodesOnPlane)
00068 {
00069 mUseJiggledNodesOnPlane = useJiggledNodesOnPlane;
00070 }
00071
00072 template<unsigned DIM>
00073 bool PlaneBoundaryCondition<DIM>::GetUseJiggledNodesOnPlane()
00074 {
00075 return mUseJiggledNodesOnPlane;
00076 }
00077
00078 template<unsigned DIM>
00079 void PlaneBoundaryCondition<DIM>::ImposeBoundaryCondition(const std::map<Node<DIM>*, c_vector<double, DIM> >& rOldLocations)
00080 {
00082 if (dynamic_cast<AbstractOffLatticeCellPopulation<DIM>*>(this->mpCellPopulation)==NULL)
00083 {
00084 EXCEPTION("PlaneBoundaryCondition requires a subclass of AbstractOffLatticeCellPopulation.");
00085 }
00086
00087 assert((dynamic_cast<AbstractCentreBasedCellPopulation<DIM>*>(this->mpCellPopulation))
00088 || (dynamic_cast<VertexBasedCellPopulation<DIM>*>(this->mpCellPopulation)) );
00089
00090
00091 double max_jiggle = 1e-4;
00092
00093 if (DIM != 1)
00094 {
00095 if (dynamic_cast<AbstractCentreBasedCellPopulation<DIM>*>(this->mpCellPopulation))
00096 {
00097 for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
00098 cell_iter != this->mpCellPopulation->End();
00099 ++cell_iter)
00100 {
00101 unsigned node_index = this->mpCellPopulation->GetLocationIndexUsingCell(*cell_iter);
00102 Node<DIM>* p_node = this->mpCellPopulation->GetNode(node_index);
00103
00104 c_vector<double, DIM> node_location = p_node->rGetLocation();
00105
00106 double signed_distance = inner_prod(node_location - mPointOnPlane, mNormalToPlane);
00107 if (signed_distance > 0.0)
00108 {
00109
00110 c_vector<double, DIM> nearest_point;
00111 if (mUseJiggledNodesOnPlane)
00112 {
00113 nearest_point = node_location - (signed_distance+max_jiggle*RandomNumberGenerator::Instance()->ranf())*mNormalToPlane;
00114 }
00115 else
00116 {
00117 nearest_point = node_location - signed_distance*mNormalToPlane;
00118 }
00119 p_node->rGetModifiableLocation() = nearest_point;
00120 }
00121 }
00122 }
00123 else
00124 {
00125 assert(dynamic_cast<VertexBasedCellPopulation<DIM>*>(this->mpCellPopulation));
00126
00127 VertexBasedCellPopulation<DIM>* pStaticCastCellPopulation = static_cast<VertexBasedCellPopulation<DIM>*>(this->mpCellPopulation);
00128
00129
00130 unsigned num_nodes = pStaticCastCellPopulation->GetNumNodes();
00131 for (unsigned node_index=0; node_index<num_nodes; node_index++)
00132 {
00133 Node<DIM>* p_node = pStaticCastCellPopulation->GetNode(node_index);
00134 c_vector<double, DIM> node_location = p_node->rGetLocation();
00135
00136 double signed_distance = inner_prod(node_location - mPointOnPlane, mNormalToPlane);
00137 if (signed_distance > 0.0)
00138 {
00139
00140 c_vector<double, DIM> nearest_point;
00141 if (mUseJiggledNodesOnPlane)
00142 {
00143 nearest_point = node_location - (signed_distance+max_jiggle*RandomNumberGenerator::Instance()->ranf())*mNormalToPlane;
00144 }
00145 else
00146 {
00147 nearest_point = node_location - signed_distance*mNormalToPlane;
00148 }
00149 p_node->rGetModifiableLocation() = nearest_point;
00150 }
00151 }
00152 }
00153 }
00154 else
00155 {
00156
00157 NEVER_REACHED;
00158
00159 }
00160 }
00161
00162 template<unsigned DIM>
00163 bool PlaneBoundaryCondition<DIM>::VerifyBoundaryCondition()
00164 {
00165 bool condition_satisfied = true;
00166
00167 if (DIM == 1)
00168 {
00169 EXCEPTION("PlaneBoundaryCondition is not implemented in 1D");
00170 }
00171 else
00172 {
00173 for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
00174 cell_iter != this->mpCellPopulation->End();
00175 ++cell_iter)
00176 {
00177 c_vector<double, DIM> cell_location = this->mpCellPopulation->GetLocationOfCellCentre(*cell_iter);
00178
00179 if (inner_prod(cell_location - mPointOnPlane, mNormalToPlane) > 0.0)
00180 {
00181 condition_satisfied = false;
00182 break;
00183 }
00184 }
00185 }
00186
00187 return condition_satisfied;
00188 }
00189
00190 template<unsigned DIM>
00191 void PlaneBoundaryCondition<DIM>::OutputCellPopulationBoundaryConditionParameters(out_stream& rParamsFile)
00192 {
00193 *rParamsFile << "\t\t\t<PointOnPlane>";
00194 for (unsigned index=0; index != DIM-1U; index++)
00195 {
00196 *rParamsFile << mPointOnPlane[index] << ",";
00197 }
00198 *rParamsFile << mPointOnPlane[DIM-1] << "</PointOnPlane>\n";
00199
00200 *rParamsFile << "\t\t\t<NormalToPlane>";
00201 for (unsigned index=0; index != DIM-1U; index++)
00202 {
00203 *rParamsFile << mNormalToPlane[index] << ",";
00204 }
00205 *rParamsFile << mNormalToPlane[DIM-1] << "</NormalToPlane>\n";
00206 *rParamsFile << "\t\t\t<UseJiggledNodesOnPlane>" << mUseJiggledNodesOnPlane << "</UseJiggledNodesOnPlane>\n";
00207
00208
00209 AbstractCellPopulationBoundaryCondition<DIM>::OutputCellPopulationBoundaryConditionParameters(rParamsFile);
00210 }
00211
00213
00215
00216 template class PlaneBoundaryCondition<1>;
00217 template class PlaneBoundaryCondition<2>;
00218 template class PlaneBoundaryCondition<3>;
00219
00220
00221 #include "SerializationExportWrapperForCpp.hpp"
00222 EXPORT_TEMPLATE_CLASS_SAME_DIMS(PlaneBoundaryCondition)