36#include "MeshBasedCellPopulation.hpp"
37#include "VtkMeshWriter.hpp"
38#include "CellBasedEventHandler.hpp"
39#include "Cylindrical2dMesh.hpp"
40#include "Cylindrical2dVertexMesh.hpp"
41#include "Toroidal2dMesh.hpp"
42#include "Toroidal2dVertexMesh.hpp"
44#include "CellVolumesWriter.hpp"
45#include "CellPopulationElementWriter.hpp"
46#include "VoronoiDataWriter.hpp"
47#include "NodeVelocityWriter.hpp"
48#include "CellPopulationAreaWriter.hpp"
50template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
52 std::vector<CellPtr>& rCells,
53 const std::vector<unsigned> locationIndices,
57 mpVoronoiTessellation(nullptr),
58 mDeleteMesh(deleteMesh),
59 mUseAreaBasedDampingConstant(false),
60 mAreaBasedDampingConstantParameter(0.1),
61 mWriteVtkAsPoints(false),
62 mBoundVoronoiTessellation(false),
63 mScaleBoundByEdgeLength(false),
64 mBoundedVoroniTesselationLengthCutoff(DBL_MAX),
65 mOffsetNewBoundaryNodes(false),
66 mHasVariableRestLength(false)
70 assert(this->
mCells.size() <= this->mrMesh.GetNumNodes());
81 node_iter != this->
rGetMesh().GetNodeIteratorEnd();
84 node_iter->ClearAppliedForce();
88template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
98template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
101 delete mpVoronoiTessellation;
105 delete &this->mrMesh;
109template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
112 return mUseAreaBasedDampingConstant;
115template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
117 [[maybe_unused]]
bool useAreaBasedDampingConstant)
119 if constexpr (SPACE_DIM == 2)
121 mUseAreaBasedDampingConstant = useAreaBasedDampingConstant;
129template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
132 return mpMutableMesh->AddNode(pNewNode);
135template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
141template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
151 if (mUseAreaBasedDampingConstant)
161 if constexpr (SPACE_DIM == 2)
163 double rest_length = 1.0;
164 double d0 = mAreaBasedDampingConstantParameter;
171 double d1 = 2.0*(1.0 - d0)/(sqrt(3.0)*rest_length*rest_length);
173 double area_cell = GetVolumeOfVoronoiElement(nodeIndex);
180 assert(area_cell < 1000);
182 damping_multiplier = d0 + area_cell*d1;
190 return damping_multiplier;
193template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
196 std::vector<bool> validated_node = std::vector<bool>(this->GetNumNodes(),
false);
200 unsigned node_index = this->GetLocationIndexUsingCell(*cell_iter);
201 validated_node[node_index] =
true;
204 for (
unsigned i=0; i<validated_node.size(); i++)
206 if (!validated_node[i])
213template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
216 return *mpMutableMesh;
219template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
222 return *mpMutableMesh;
225template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
228 return mpMutableMesh;
231template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
234 unsigned num_removed = 0;
235 for (std::list<CellPtr>::iterator it = this->mCells.begin();
236 it != this->mCells.end();
242 std::vector<const std::pair<CellPtr,CellPtr>*> pairs_to_remove;
243 for (std::set<std::pair<CellPtr,CellPtr> >::iterator it1 = this->mMarkedSprings.begin();
244 it1 != this->mMarkedSprings.end();
247 const std::pair<CellPtr,CellPtr>& r_pair = *it1;
249 for (
unsigned i=0; i<2; i++)
251 CellPtr p_cell = (i==0 ? r_pair.first : r_pair.second);
256 pairs_to_remove.push_back(&r_pair);
263 for (std::vector<
const std::pair<CellPtr,CellPtr>* >::iterator pair_it = pairs_to_remove.begin();
264 pair_it != pairs_to_remove.end();
267 this->mMarkedSprings.erase(**pair_it);
275 unsigned location_index_of_removed_node = this->GetLocationIndexUsingCell((*it));
276 this->RemoveCellUsingLocationIndex(location_index_of_removed_node, (*it));
279 it = this->mCells.erase(it);
290template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
293 this->mNodePairs.clear();
294 for (
SpringIterator spring_it = SpringsBegin(); spring_it != SpringsEnd(); ++spring_it)
296 this->mNodePairs.emplace_back(spring_it.GetNodeA(), spring_it.GetNodeB());
300template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
304 bool output_node_velocities = (this->
template HasWriter<NodeVelocityWriter>());
316 std::map<unsigned, double> old_node_radius_map;
317 old_node_radius_map.clear();
318 if (this->mrMesh.GetNodeIteratorBegin()->HasNodeAttributes())
320 if (this->mrMesh.GetNodeIteratorBegin()->GetRadius() > 0.0)
323 node_iter != this->mrMesh.GetNodeIteratorEnd();
326 unsigned node_index = node_iter->GetIndex();
327 old_node_radius_map[node_index] = node_iter->GetRadius();
332 std::map<unsigned, c_vector<double, SPACE_DIM> > old_node_applied_force_map;
333 old_node_applied_force_map.clear();
334 if (output_node_velocities)
342 node_iter != this->mrMesh.GetNodeIteratorEnd();
345 unsigned node_index = node_iter->GetIndex();
346 old_node_applied_force_map[node_index] = node_iter->rGetAppliedForce();
350 NodeMap node_map(this->mrMesh.GetNumAllNodes());
355 if (!node_map.IsIdentityMap())
357 UpdateGhostNodesAfterReMesh(node_map);
360 std::map<Cell*, unsigned> old_cell_location_map = this->mCellLocationMap;
363 this->mLocationCellMap.clear();
364 this->mCellLocationMap.clear();
366 for (std::list<CellPtr>::iterator it = this->mCells.begin(); it != this->mCells.end(); ++it)
368 unsigned old_node_index = old_cell_location_map[(*it).get()];
371 assert(!node_map.IsDeleted(old_node_index));
373 unsigned new_node_index = node_map.GetNewIndex(old_node_index);
374 this->SetCellUsingLocationIndex(new_node_index,*it);
376 if (old_node_radius_map[old_node_index] > 0.0)
378 this->GetNode(new_node_index)->SetRadius(old_node_radius_map[old_node_index]);
380 if (output_node_velocities)
382 this->GetNode(new_node_index)->AddAppliedForceContribution(old_node_applied_force_map[old_node_index]);
390 if (old_node_radius_map[this->mCellLocationMap[(*(this->mCells.begin())).get()]] > 0.0)
392 for (std::list<CellPtr>::iterator it = this->mCells.begin(); it != this->mCells.end(); ++it)
394 unsigned node_index = this->mCellLocationMap[(*it).get()];
395 this->GetNode(node_index)->SetRadius(old_node_radius_map[node_index]);
398 if (output_node_velocities)
400 for (std::list<CellPtr>::iterator it = this->mCells.begin(); it != this->mCells.end(); ++it)
402 unsigned node_index = this->mCellLocationMap[(*it).get()];
403 this->GetNode(node_index)->AddAppliedForceContribution(old_node_applied_force_map[node_index]);
409 std::vector<const std::pair<CellPtr,CellPtr>*> springs_to_remove;
410 for (std::set<std::pair<CellPtr,CellPtr> >::iterator spring_it = this->mMarkedSprings.begin();
411 spring_it != this->mMarkedSprings.end();
414 CellPtr p_cell_1 = spring_it->first;
415 CellPtr p_cell_2 = spring_it->second;
416 Node<SPACE_DIM>* p_node_1 = this->GetNodeCorrespondingToCell(p_cell_1);
417 Node<SPACE_DIM>* p_node_2 = this->GetNodeCorrespondingToCell(p_cell_2);
427 if (node2_elements.find(*elem_iter) != node2_elements.end())
437 springs_to_remove.push_back(&(*spring_it));
442 for (std::vector<
const std::pair<CellPtr,CellPtr>* >::iterator spring_it = springs_to_remove.begin();
443 spring_it != springs_to_remove.end();
446 this->mMarkedSprings.erase(**spring_it);
453 TessellateIfNeeded();
458template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
461 if ((SPACE_DIM==2 || SPACE_DIM==3)&&(ELEMENT_DIM==SPACE_DIM))
464 if (mUseAreaBasedDampingConstant ||
465 this->
template HasWriter<VoronoiDataWriter>() ||
466 this->
template HasWriter<CellPopulationAreaWriter>() ||
467 this->
template HasWriter<CellVolumesWriter>())
469 CreateVoronoiTessellation();
475template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
479 if constexpr (ELEMENT_DIM == 2)
481 std::vector<c_vector<unsigned, 5> > new_nodes;
482 new_nodes = rGetMesh().SplitLongEdges(springDivisionThreshold);
485 for (
unsigned index=0; index<new_nodes.size(); index++)
488 unsigned new_node_index = new_nodes[index][0];
489 unsigned node_a_index = new_nodes[index][1];
490 unsigned node_b_index = new_nodes[index][2];
492 CellPtr p_neighbour_cell = this->GetCellUsingLocationIndex(node_a_index);
500 CellPtr p_new_cell(
new Cell(p_neighbour_cell->GetMutationState(),
501 p_neighbour_cell->GetCellCycleModel()->CreateCellCycleModel(),
502 p_neighbour_cell->GetSrnModel()->CreateSrnModel(),
504 daughter_property_collection));
507 this->mCells.push_back(p_new_cell);
508 this->AddCellUsingLocationIndex(new_node_index,p_new_cell);
513 std::pair<unsigned,unsigned> node_pair = this->CreateOrderedPair(node_a_index, node_b_index);
514 double old_rest_length = mSpringRestLengths[node_pair];
516 std::map<std::pair<unsigned,unsigned>,
double>::iterator iter = mSpringRestLengths.find(node_pair);
517 mSpringRestLengths.erase(iter);
520 node_pair = this->CreateOrderedPair(node_a_index, new_node_index);
521 mSpringRestLengths[node_pair] = 0.5*old_rest_length;
523 node_pair = this->CreateOrderedPair(node_b_index, new_node_index);
524 mSpringRestLengths[node_pair] = 0.5*old_rest_length;
527 for (
unsigned pair_index=3; pair_index<5; pair_index++)
529 unsigned other_node_index = new_nodes[index][pair_index];
533 node_pair = this->CreateOrderedPair(other_node_index, new_node_index);
534 double new_rest_length = rGetMesh().GetDistanceBetweenNodes(new_node_index, other_node_index);
535 mSpringRestLengths[node_pair] = new_rest_length;
546template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
549 return this->mrMesh.GetNode(index);
552template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
555 return this->mrMesh.GetNumAllNodes();
558template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
563template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
571 assert(p_created_cell == pNewCell);
574 std::pair<CellPtr,CellPtr> cell_pair = this->CreateCellPair(pParentCell, p_created_cell);
575 this->MarkSpring(cell_pair);
578 return p_created_cell;
585template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
588 if (this->mOutputResultsForChasteVisualizer)
590 if (!this->
template HasWriter<CellPopulationElementWriter>())
592 this->
template AddPopulationWriter<CellPopulationElementWriter>();
599template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
604 TessellateIfNeeded();
610template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
613 pPopulationWriter->Visit(
this);
616template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
619 pPopulationCountWriter->Visit(
this);
622template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
625 pPopulationEventWriter->Visit(
this);
628template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
631 pCellWriter->VisitCell(pCell,
this);
634template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
640 std::stringstream time;
641 time << num_timesteps;
644 unsigned num_cells_from_mesh = GetNumNodes();
647 unsigned num_cell_data_items = this->Begin()->GetCellData()->GetNumItems();
648 std::vector<std::string> cell_data_names = this->Begin()->GetCellData()->GetKeys();
650 std::vector<std::vector<double> > cell_data;
651 for (
unsigned var=0; var<num_cell_data_items; var++)
653 std::vector<double> cell_data_var(num_cells_from_mesh);
654 cell_data.push_back(cell_data_var);
657 if (mWriteVtkAsPoints)
663 unsigned num_cells = this->GetNumAllCells();
665 cell_writer_iter != this->mCellWriters.end();
669 std::vector<double> vtk_cell_data(num_cells);
673 cell_iter != this->End();
677 unsigned node_index = this->GetLocationIndexUsingCell(*cell_iter);
680 vtk_cell_data[node_index] = (*cell_writer_iter)->GetCellDataForVtkOutput(*cell_iter,
this);
683 cells_writer.AddPointData((*cell_writer_iter)->GetVtkCellDataName(), vtk_cell_data);
688 cell_iter != this->End();
692 unsigned node_index = this->GetLocationIndexUsingCell(*cell_iter);
694 for (
unsigned var=0; var<num_cell_data_items; var++)
696 cell_data[var][node_index] = cell_iter->GetCellData()->GetItem(cell_data_names[var]);
699 for (
unsigned var=0; var<num_cell_data_items; var++)
701 cells_writer.AddPointData(cell_data_names[var], cell_data[var]);
705 cells_writer.WriteFilesUsingMesh(rGetMesh());
706 *(this->mpVtkMetaFile) <<
" <DataSet timestep=\"";
707 *(this->mpVtkMetaFile) << num_timesteps;
708 *(this->mpVtkMetaFile) <<
"\" group=\"\" part=\"0\" file=\"mesh_results_";
709 *(this->mpVtkMetaFile) << num_timesteps;
710 *(this->mpVtkMetaFile) <<
".vtu\"/>\n";
712 if (mpVoronoiTessellation !=
nullptr)
716 std::vector<double> cell_volumes(num_cells_from_mesh);
719 unsigned num_cells = this->GetNumAllCells();
721 cell_writer_iter != this->mCellWriters.end();
725 std::vector<double> vtk_cell_data(num_cells);
729 elem_iter != mpVoronoiTessellation->GetElementIteratorEnd();
733 unsigned elem_index = elem_iter->GetIndex();
736 unsigned node_index = mpVoronoiTessellation->GetDelaunayNodeIndexCorrespondingToVoronoiElementIndex(elem_index);
737 CellPtr p_cell = this->GetCellUsingLocationIndex(node_index);
740 vtk_cell_data[elem_index] = (*cell_writer_iter)->GetCellDataForVtkOutput(p_cell,
this);
743 mesh_writer.AddCellData((*cell_writer_iter)->GetVtkCellDataName(), vtk_cell_data);
748 elem_iter != mpVoronoiTessellation->GetElementIteratorEnd();
752 unsigned elem_index = elem_iter->GetIndex();
755 unsigned node_index = mpVoronoiTessellation->GetDelaunayNodeIndexCorrespondingToVoronoiElementIndex(elem_index);
756 CellPtr p_cell = this->GetCellUsingLocationIndex(node_index);
758 for (
unsigned var=0; var<num_cell_data_items; var++)
760 cell_data[var][elem_index] = p_cell->GetCellData()->GetItem(cell_data_names[var]);
764 for (
unsigned var=0; var<cell_data.size(); var++)
766 mesh_writer.AddCellData(cell_data_names[var], cell_data[var]);
769 mesh_writer.WriteVtkUsingMesh(*mpVoronoiTessellation, time.str());
770 *(this->mpVtkMetaFile) <<
" <DataSet timestep=\"";
771 *(this->mpVtkMetaFile) << num_timesteps;
772 *(this->mpVtkMetaFile) <<
"\" group=\"\" part=\"0\" file=\"voronoi_results_";
773 *(this->mpVtkMetaFile) << num_timesteps;
774 *(this->mpVtkMetaFile) <<
".vtu\"/>\n";
779template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
782 double cell_volume = 0;
784 if (ELEMENT_DIM == SPACE_DIM)
787 if (mpVoronoiTessellation ==
nullptr)
789 CreateVoronoiTessellation();
793 unsigned node_index = this->GetLocationIndexUsingCell(pCell);
798 unsigned element_index = mpVoronoiTessellation->GetVoronoiElementIndexCorrespondingToDelaunayNodeIndex(node_index);
801 cell_volume = mpVoronoiTessellation->GetVolumeOfElement(element_index);
806 cell_volume = DBL_MAX;
809 else if (SPACE_DIM==3 && ELEMENT_DIM==2)
811 unsigned node_index = this->GetLocationIndexUsingCell(pCell);
823 c_matrix<double, SPACE_DIM, ELEMENT_DIM> jacob;
828 cell_volume += fabs(p_element->
GetVolume(det));
843template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
846 mWriteVtkAsPoints = writeVtkAsPoints;
849template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
852 return mWriteVtkAsPoints;
855template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
858 mBoundVoronoiTessellation = boundVoronoiTessellation;
861template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
864 return mBoundVoronoiTessellation;
867template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
870 mScaleBoundByEdgeLength = scaleBoundByEdgeLength;
873template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
876 return mScaleBoundByEdgeLength;
879template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
882 assert(boundedVoroniTesselationLengthCutoff>0);
883 mBoundedVoroniTesselationLengthCutoff = boundedVoroniTesselationLengthCutoff;
886template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
889 return mBoundedVoroniTesselationLengthCutoff;
892template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
895 mOffsetNewBoundaryNodes = offsetNewBoundaryNodes;
898template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
901 return mOffsetNewBoundaryNodes;
906template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
911 *pVizSetupFile <<
"MeshWidth\t" << this->GetWidth(0) <<
"\n";
915 *pVizSetupFile <<
"MeshWidth\t" << this->GetWidth(0) <<
"\n";
916 *pVizSetupFile <<
"MeshHeight\t" << this->GetWidth(1) <<
"\n";
920template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
923 if constexpr (ELEMENT_DIM == 1)
928 else if constexpr (ELEMENT_DIM == 2 && SPACE_DIM == 2)
930 delete mpVoronoiTessellation;
933 bool is_mesh_periodic =
false;
936 if(mScaleBoundByEdgeLength || mBoundedVoroniTesselationLengthCutoff<DBL_MAX || mOffsetNewBoundaryNodes)
941 is_mesh_periodic =
true;
946 if(mScaleBoundByEdgeLength || mBoundedVoroniTesselationLengthCutoff<DBL_MAX || mOffsetNewBoundaryNodes)
951 is_mesh_periodic =
true;
956 mpVoronoiTessellation =
new VertexMesh<2, 2>(
static_cast<MutableMesh<2, 2>&
>((this->mrMesh)), is_mesh_periodic, mBoundVoronoiTessellation, mScaleBoundByEdgeLength, mBoundedVoroniTesselationLengthCutoff, mOffsetNewBoundaryNodes);
959 else if constexpr (ELEMENT_DIM == 3)
964 delete mpVoronoiTessellation;
977template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
983template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
986 return mEdgeIter.GetNodeB();
989template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
992 assert((*
this) != mrCellPopulation.SpringsEnd());
993 return mrCellPopulation.GetCellUsingLocationIndex(mEdgeIter.GetNodeA()->GetIndex());
996template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
999 assert((*
this) != mrCellPopulation.SpringsEnd());
1000 return mrCellPopulation.GetCellUsingLocationIndex(mEdgeIter.GetNodeB()->GetIndex());
1003template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1009template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1012 bool edge_is_ghost =
false;
1017 if (*
this != mrCellPopulation.SpringsEnd())
1019 bool a_is_ghost = mrCellPopulation.IsGhostNode(mEdgeIter.GetNodeA()->GetIndex());
1020 bool b_is_ghost = mrCellPopulation.IsGhostNode(mEdgeIter.GetNodeB()->GetIndex());
1022 edge_is_ghost = (a_is_ghost || b_is_ghost);
1025 while (*
this!=mrCellPopulation.SpringsEnd() && edge_is_ghost);
1030template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1034 : mrCellPopulation(rCellPopulation),
1042 if (a_is_ghost || b_is_ghost)
1049template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1055template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1061template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1068template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1071 unsigned element_index =
mpVoronoiTessellation->GetVoronoiElementIndexCorrespondingToDelaunayNodeIndex(index);
1076template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1079 unsigned element_index =
mpVoronoiTessellation->GetVoronoiElementIndexCorrespondingToDelaunayNodeIndex(index);
1081 return surface_area;
1084template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1087 unsigned element_index1 =
mpVoronoiTessellation->GetVoronoiElementIndexCorrespondingToDelaunayNodeIndex(index1);
1088 unsigned element_index2 =
mpVoronoiTessellation->GetVoronoiElementIndexCorrespondingToDelaunayNodeIndex(index2);
1097 EXCEPTION(
"Spring iterator tried to calculate interaction between degenerate cells on the boundary of the mesh. Have you set ghost layers correctly?");
1101template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1105 for (std::list<CellPtr>::iterator it=this->
mCells.begin();
1109 CellPtr p_cell = *it;
1116 std::cout <<
"Cell at node " << node_index <<
" addr " << p_cell << std::endl << std::flush;
1119 if (p_cell_in_cell_population != p_cell)
1121 std::cout <<
" Mismatch with cell population" << std::endl << std::flush;
1126 if (p_model->
GetCell() != p_cell)
1128 std::cout <<
" Mismatch with cycle model" << std::endl << std::flush;
1137 for (std::set<std::pair<CellPtr,CellPtr> >::iterator it1 = this->
mMarkedSprings.begin();
1141 const std::pair<CellPtr,CellPtr>& r_pair = *it1;
1143 for (
unsigned i=0; i<2; i++)
1145 CellPtr p_cell = (i==0 ? r_pair.first : r_pair.second);
1151 std::cout <<
"Cell at node " << node_index <<
" addr " << p_cell << std::endl << std::flush;
1155 if (p_cell->IsDead())
1157 std::cout <<
" Cell is dead" << std::endl << std::flush;
1163 if (p_cell_in_cell_population != p_cell)
1165 std::cout <<
" Mismatch with cell population" << std::endl << std::flush;
1170 if (p_model->
GetCell() != p_cell)
1172 std::cout <<
" Mismatch with cycle model" << std::endl << std::flush;
1181template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1187template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1190 assert(areaBasedDampingConstantParameter >= 0.0);
1194template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1199 *rParamsFile <<
"\t\t<WriteVtkAsPoints>" <<
mWriteVtkAsPoints <<
"</WriteVtkAsPoints>\n";
1207template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1211 double width = this->
mrMesh.GetWidth(rDimension);
1215template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1222 std::set<unsigned> neighbouring_node_indices;
1231 for (
unsigned i=0; i<p_element->
GetNumNodes(); i++)
1235 if (node_index != index)
1237 neighbouring_node_indices.insert(node_index);
1241 return neighbouring_node_indices;
1244template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1258 unsigned nodeA_global_index = p_nodeA->
GetIndex();
1259 unsigned nodeB_global_index = p_nodeB->
GetIndex();
1262 double separation =
rGetMesh().GetDistanceBetweenNodes(nodeA_global_index, nodeB_global_index);
1265 std::pair<unsigned,unsigned> node_pair = this->
CreateOrderedPair(nodeA_global_index, nodeB_global_index);
1272template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1277 std::pair<unsigned,unsigned> node_pair = this->
CreateOrderedPair(indexA, indexB);
1278 std::map<std::pair<unsigned,unsigned>,
double>::const_iterator iter =
mSpringRestLengths.find(node_pair);
1283 return iter->second;
1287 EXCEPTION(
"Tried to get a rest length of an edge that doesn't exist. You can only use variable rest lengths if SetUpdateCellPopulationRule is set on the simulation.");
1296template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1301 std::pair<unsigned,unsigned> node_pair = this->
CreateOrderedPair(indexA, indexB);
1302 std::map<std::pair<unsigned,unsigned>,
double>::iterator iter =
mSpringRestLengths.find(node_pair);
1307 iter->second = restLength;
1311 EXCEPTION(
"Tried to set the rest length of an edge not in the mesh.");
1316 EXCEPTION(
"Tried to set a rest length in a simulation with fixed rest length. You can only use variable rest lengths if SetUpdateCellPopulationRule is set on the simulation.");
#define EXCEPTION(message)
const unsigned UNSIGNED_UNSET
#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
virtual void OpenWritersFiles(OutputFileHandler &rOutputFileHandler)
AbstractMesh< ELEMENT_DIM, SPACE_DIM > & mrMesh
std::list< CellPtr > mCells
unsigned GetLocationIndexUsingCell(CellPtr pCell)
virtual void WriteResultsToFiles(const std::string &rDirectory)
virtual CellPtr GetCellUsingLocationIndex(unsigned index)
std::pair< unsigned, unsigned > CreateOrderedPair(unsigned index1, unsigned index2)
std::set< std::pair< CellPtr, CellPtr > > mMarkedSprings
virtual void OutputCellPopulationParameters(out_stream &rParamsFile)
virtual double GetDampingConstant(unsigned nodeIndex)
CellPtr AddCell(CellPtr pNewCell, CellPtr pParentCell=CellPtr())
unsigned GetNumNodes() const
unsigned GetNodeGlobalIndex(unsigned localIndex) const
void SetMeshHasChangedSinceLoading()
double GetVolume(double determinant) const
void CalculateJacobian(c_matrix< double, SPACE_DIM, ELEMENT_DIM > &rJacobian, double &rJacobianDeterminant)
Element< ELEMENT_DIM, SPACE_DIM > * GetElement(unsigned index) const
static void BeginEvent(unsigned event)
static void EndEvent(unsigned event)
MutableMesh< ELEMENT_DIM, SPACE_DIM >::EdgeIterator mEdgeIter
MeshBasedCellPopulation< ELEMENT_DIM, SPACE_DIM > & mrCellPopulation
bool operator!=(const typename MeshBasedCellPopulation< ELEMENT_DIM, SPACE_DIM >::SpringIterator &rOther)
SpringIterator(MeshBasedCellPopulation< ELEMENT_DIM, SPACE_DIM > &rCellPopulation, typename MutableMesh< ELEMENT_DIM, SPACE_DIM >::EdgeIterator edgeIter)
SpringIterator & operator++()
Node< SPACE_DIM > * GetNodeA()
Node< SPACE_DIM > * GetNodeB()
bool UseAreaBasedDampingConstant()
virtual void OpenWritersFiles(OutputFileHandler &rOutputFileHandler)
bool GetOffsetNewBoundaryNodes()
virtual void UpdateNodePairs()
double GetBoundedVoroniTesselationLengthCutoff()
std::map< std::pair< unsigned, unsigned >, double > mSpringRestLengths
void TessellateIfNeeded()
void SetBoundedVoroniTesselationLengthCutoff(double boundedVoroniTesselationLengthCutoff)
void OutputCellPopulationParameters(out_stream &rParamsFile)
bool GetBoundVoronoiTessellation()
virtual void WriteResultsToFiles(const std::string &rDirectory)
bool mBoundVoronoiTessellation
virtual void Update(bool hasHadBirthsOrDeaths=true)
bool mUseAreaBasedDampingConstant
bool mHasVariableRestLength
bool GetScaleBoundByEdgeLength()
double GetVoronoiEdgeLength(unsigned index1, unsigned index2)
void SetScaleBoundByEdgeLength(bool scaleBoundByEdgeLength)
virtual void AcceptPopulationWriter(boost::shared_ptr< AbstractCellPopulationWriter< ELEMENT_DIM, SPACE_DIM > > pPopulationWriter)
double GetDampingConstant(unsigned nodeIndex)
virtual ~MeshBasedCellPopulation()
virtual void AcceptCellWriter(boost::shared_ptr< AbstractCellWriter< ELEMENT_DIM, SPACE_DIM > > pCellWriter, CellPtr pCell)
void SetWriteVtkAsPoints(bool writeVtkAsPoints)
double GetWidth(const unsigned &rDimension)
MeshBasedCellPopulation(MutableMesh< ELEMENT_DIM, SPACE_DIM > &rMesh, std::vector< CellPtr > &rCells, const std::vector< unsigned > locationIndices={}, bool deleteMesh=false, bool validate=true)
SpringIterator SpringsEnd()
void SetNode(unsigned nodeIndex, ChastePoint< SPACE_DIM > &rNewLocation)
virtual void AcceptPopulationEventWriter(boost::shared_ptr< AbstractCellPopulationEventWriter< ELEMENT_DIM, SPACE_DIM > > pPopulationEventWriter)
void SetAreaBasedDampingConstant(bool useAreaBasedDampingConstant)
virtual void WriteVtkResultsToFile(const std::string &rDirectory)
virtual TetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * GetTetrahedralMeshForPdeModifier()
SpringIterator SpringsBegin()
VertexMesh< ELEMENT_DIM, SPACE_DIM > * mpVoronoiTessellation
virtual CellPtr AddCell(CellPtr pNewCell, CellPtr pParentCell)
unsigned AddNode(Node< SPACE_DIM > *pNewNode)
double GetSurfaceAreaOfVoronoiElement(unsigned index)
void SetOffsetNewBoundaryNodes(bool offsetNewBoundaryNodes)
std::set< unsigned > GetNeighbouringNodeIndices(unsigned index)
Node< SPACE_DIM > * GetNode(unsigned index)
virtual void UpdateGhostNodesAfterReMesh(NodeMap &rMap)
void SetBoundVoronoiTessellation(bool boundVoronoiTessellation)
void CreateVoronoiTessellation()
virtual void AcceptPopulationCountWriter(boost::shared_ptr< AbstractCellPopulationCountWriter< ELEMENT_DIM, SPACE_DIM > > pPopulationCountWriter)
double GetVolumeOfVoronoiElement(unsigned index)
virtual unsigned RemoveDeadCells()
void SetRestLength(unsigned indexA, unsigned indexB, double restLength)
bool GetWriteVtkAsPoints()
double mAreaBasedDampingConstantParameter
virtual void WriteDataToVisualizerSetupFile(out_stream &pVizSetupFile)
VertexMesh< ELEMENT_DIM, SPACE_DIM > * GetVoronoiTessellation()
MutableMesh< ELEMENT_DIM, SPACE_DIM > * mpMutableMesh
void SetAreaBasedDampingConstantParameter(double areaBasedDampingConstantParameter)
void DivideLongSprings(double springDivisionThreshold)
double GetRestLength(unsigned indexA, unsigned indexB)
double GetVolumeOfCell(CellPtr pCell)
MutableMesh< ELEMENT_DIM, SPACE_DIM > & rGetMesh()
double GetAreaBasedDampingConstantParameter()
void CalculateRestLengths()
virtual void ReMesh(NodeMap &map)
void DeleteNodePriorToReMesh(unsigned index)
virtual void SetNode(unsigned index, ChastePoint< SPACE_DIM > point, bool concreteMove=true)
ContainingElementIterator ContainingElementsEnd() const
std::set< unsigned > & rGetContainingElementIndices()
ContainingElementIterator ContainingElementsBegin() const
unsigned GetIndex() const
static SimulationTime * Instance()
unsigned GetTimeStepsElapsed() const