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"
43#include "NodesOnlyMesh.hpp"
45#include "CellVolumesWriter.hpp"
46#include "CellPopulationElementWriter.hpp"
47#include "VoronoiDataWriter.hpp"
48#include "NodeVelocityWriter.hpp"
49#include "CellPopulationAreaWriter.hpp"
51template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
53 std::vector<CellPtr>& rCells,
54 const std::vector<unsigned> locationIndices,
58 mpVoronoiTessellation(nullptr),
59 mDeleteMesh(deleteMesh),
60 mUseAreaBasedDampingConstant(false),
61 mAreaBasedDampingConstantParameter(0.1),
62 mWriteVtkAsPoints(false),
63 mBoundVoronoiTessellation(false),
64 mScaleBoundByEdgeLength(false),
65 mBoundedVoroniTesselationLengthCutoff(DBL_MAX),
66 mOffsetNewBoundaryNodes(false),
67 mHasVariableRestLength(false)
71 assert(this->
mCells.size() <= this->mrMesh.GetNumNodes());
80 node_iter != this->
rGetMesh().GetNodeIteratorEnd();
83 node_iter->ClearAppliedForce();
87template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
96template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
99 delete mpVoronoiTessellation;
103 delete &this->mrMesh;
107template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
110 return mUseAreaBasedDampingConstant;
113template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
115 [[maybe_unused]]
bool useAreaBasedDampingConstant)
117 if constexpr (SPACE_DIM == 2)
119 mUseAreaBasedDampingConstant = useAreaBasedDampingConstant;
127template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
130 return mpMutableMesh->AddNode(pNewNode);
133template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
139template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
149 if (mUseAreaBasedDampingConstant)
159 if constexpr (SPACE_DIM == 2)
161 double rest_length = 1.0;
162 double d0 = mAreaBasedDampingConstantParameter;
169 double d1 = 2.0*(1.0 - d0)/(sqrt(3.0)*rest_length*rest_length);
171 double area_cell = GetVolumeOfVoronoiElement(nodeIndex);
178 assert(area_cell < 1000);
180 damping_multiplier = d0 + area_cell*d1;
188 return damping_multiplier;
191template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
194 std::vector<bool> validated_node = std::vector<bool>(this->GetNumNodes(),
false);
198 unsigned node_index = this->GetLocationIndexUsingCell(*cell_iter);
199 validated_node[node_index] =
true;
202 for (
unsigned i=0; i<validated_node.size(); i++)
204 if (!validated_node[i])
211template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
214 return *mpMutableMesh;
217template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
220 return *mpMutableMesh;
223template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
226 return mpMutableMesh;
229template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
232 unsigned num_removed = 0;
233 for (std::list<CellPtr>::iterator it = this->mCells.begin();
234 it != this->mCells.end();
240 std::vector<const std::pair<CellPtr,CellPtr>*> pairs_to_remove;
241 for (std::set<std::pair<CellPtr,CellPtr> >::iterator it1 = this->mMarkedSprings.begin();
242 it1 != this->mMarkedSprings.end();
245 const std::pair<CellPtr,CellPtr>& r_pair = *it1;
247 for (
unsigned i=0; i<2; i++)
249 CellPtr p_cell = (i==0 ? r_pair.first : r_pair.second);
254 pairs_to_remove.push_back(&r_pair);
261 for (std::vector<
const std::pair<CellPtr,CellPtr>* >::iterator pair_it = pairs_to_remove.begin();
262 pair_it != pairs_to_remove.end();
265 this->mMarkedSprings.erase(**pair_it);
273 unsigned location_index_of_removed_node = this->GetLocationIndexUsingCell((*it));
274 this->RemoveCellUsingLocationIndex(location_index_of_removed_node, (*it));
277 it = this->mCells.erase(it);
288template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
292 bool output_node_velocities = (this->
template HasWriter<NodeVelocityWriter>());
304 std::map<unsigned, double> old_node_radius_map;
305 old_node_radius_map.clear();
306 if (this->mrMesh.GetNodeIteratorBegin()->HasNodeAttributes())
308 if (this->mrMesh.GetNodeIteratorBegin()->GetRadius() > 0.0)
311 node_iter != this->mrMesh.GetNodeIteratorEnd();
314 unsigned node_index = node_iter->GetIndex();
315 old_node_radius_map[node_index] = node_iter->GetRadius();
320 std::map<unsigned, c_vector<double, SPACE_DIM> > old_node_applied_force_map;
321 old_node_applied_force_map.clear();
322 if (output_node_velocities)
330 node_iter != this->mrMesh.GetNodeIteratorEnd();
333 unsigned node_index = node_iter->GetIndex();
334 old_node_applied_force_map[node_index] = node_iter->rGetAppliedForce();
338 NodeMap node_map(this->mrMesh.GetNumAllNodes());
343 if (!node_map.IsIdentityMap())
345 UpdateGhostNodesAfterReMesh(node_map);
348 std::map<Cell*, unsigned> old_cell_location_map = this->mCellLocationMap;
351 this->mLocationCellMap.clear();
352 this->mCellLocationMap.clear();
354 for (std::list<CellPtr>::iterator it = this->mCells.begin(); it != this->mCells.end(); ++it)
356 unsigned old_node_index = old_cell_location_map[(*it).get()];
359 assert(!node_map.IsDeleted(old_node_index));
361 unsigned new_node_index = node_map.GetNewIndex(old_node_index);
362 this->SetCellUsingLocationIndex(new_node_index,*it);
364 if (old_node_radius_map[old_node_index] > 0.0)
366 this->GetNode(new_node_index)->SetRadius(old_node_radius_map[old_node_index]);
368 if (output_node_velocities)
370 this->GetNode(new_node_index)->AddAppliedForceContribution(old_node_applied_force_map[old_node_index]);
378 if (old_node_radius_map[this->mCellLocationMap[(*(this->mCells.begin())).get()]] > 0.0)
380 for (std::list<CellPtr>::iterator it = this->mCells.begin(); it != this->mCells.end(); ++it)
382 unsigned node_index = this->mCellLocationMap[(*it).get()];
383 this->GetNode(node_index)->SetRadius(old_node_radius_map[node_index]);
386 if (output_node_velocities)
388 for (std::list<CellPtr>::iterator it = this->mCells.begin(); it != this->mCells.end(); ++it)
390 unsigned node_index = this->mCellLocationMap[(*it).get()];
391 this->GetNode(node_index)->AddAppliedForceContribution(old_node_applied_force_map[node_index]);
397 std::vector<const std::pair<CellPtr,CellPtr>*> springs_to_remove;
398 for (std::set<std::pair<CellPtr,CellPtr> >::iterator spring_it = this->mMarkedSprings.begin();
399 spring_it != this->mMarkedSprings.end();
402 CellPtr p_cell_1 = spring_it->first;
403 CellPtr p_cell_2 = spring_it->second;
405 Node<SPACE_DIM>* p_node_2 = this->GetNodeCorrespondingToCell(p_cell_2);
415 if (node2_elements.find(*elem_iter) != node2_elements.end())
425 springs_to_remove.push_back(&(*spring_it));
430 for (std::vector<
const std::pair<CellPtr,CellPtr>* >::iterator spring_it = springs_to_remove.begin();
431 spring_it != springs_to_remove.end();
434 this->mMarkedSprings.erase(**spring_it);
438 TessellateIfNeeded();
443template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
446 if ((SPACE_DIM==2 || SPACE_DIM==3)&&(ELEMENT_DIM==SPACE_DIM))
449 if (mUseAreaBasedDampingConstant ||
450 this->
template HasWriter<VoronoiDataWriter>() ||
451 this->
template HasWriter<CellPopulationAreaWriter>() ||
452 this->
template HasWriter<CellVolumesWriter>())
454 CreateVoronoiTessellation();
460template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
464 if constexpr (ELEMENT_DIM == 2)
466 std::vector<c_vector<unsigned, 5> > new_nodes;
467 new_nodes = rGetMesh().SplitLongEdges(springDivisionThreshold);
470 for (
unsigned index=0; index<new_nodes.size(); index++)
473 unsigned new_node_index = new_nodes[index][0];
474 unsigned node_a_index = new_nodes[index][1];
475 unsigned node_b_index = new_nodes[index][2];
477 CellPtr p_neighbour_cell = this->GetCellUsingLocationIndex(node_a_index);
485 CellPtr p_new_cell(
new Cell(p_neighbour_cell->GetMutationState(),
486 p_neighbour_cell->GetCellCycleModel()->CreateCellCycleModel(),
487 p_neighbour_cell->GetSrnModel()->CreateSrnModel(),
489 daughter_property_collection));
492 this->mCells.push_back(p_new_cell);
493 this->AddCellUsingLocationIndex(new_node_index,p_new_cell);
498 std::pair<unsigned,unsigned> node_pair = this->CreateOrderedPair(node_a_index, node_b_index);
499 double old_rest_length = mSpringRestLengths[node_pair];
501 std::map<std::pair<unsigned,unsigned>,
double>::iterator iter = mSpringRestLengths.find(node_pair);
502 mSpringRestLengths.erase(iter);
505 node_pair = this->CreateOrderedPair(node_a_index, new_node_index);
506 mSpringRestLengths[node_pair] = 0.5*old_rest_length;
508 node_pair = this->CreateOrderedPair(node_b_index, new_node_index);
509 mSpringRestLengths[node_pair] = 0.5*old_rest_length;
512 for (
unsigned pair_index=3; pair_index<5; pair_index++)
514 unsigned other_node_index = new_nodes[index][pair_index];
518 node_pair = this->CreateOrderedPair(other_node_index, new_node_index);
519 double new_rest_length = rGetMesh().GetDistanceBetweenNodes(new_node_index, other_node_index);
520 mSpringRestLengths[node_pair] = new_rest_length;
531template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
534 return this->mrMesh.GetNode(index);
537template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
540 return this->mrMesh.GetNumAllNodes();
543template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
548template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
556 assert(p_created_cell == pNewCell);
559 std::pair<CellPtr,CellPtr> cell_pair = this->CreateCellPair(pParentCell, p_created_cell);
560 this->MarkSpring(cell_pair);
563 return p_created_cell;
570template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
573 if (this->mOutputResultsForChasteVisualizer)
575 if (!this->
template HasWriter<CellPopulationElementWriter>())
577 this->
template AddPopulationWriter<CellPopulationElementWriter>();
584template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
589 TessellateIfNeeded();
595template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
598 pPopulationWriter->Visit(
this);
601template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
604 pPopulationCountWriter->Visit(
this);
607template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
610 pPopulationEventWriter->Visit(
this);
613template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
616 pCellWriter->VisitCell(pCell,
this);
619template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
625 std::stringstream time;
626 time << num_timesteps;
629 unsigned num_cells_from_mesh = GetNumNodes();
632 unsigned num_cell_data_items = this->Begin()->GetCellData()->GetNumItems();
633 std::vector<std::string> cell_data_names = this->Begin()->GetCellData()->GetKeys();
635 std::vector<std::vector<double> > cell_data;
636 for (
unsigned var=0; var<num_cell_data_items; var++)
638 std::vector<double> cell_data_var(num_cells_from_mesh);
639 cell_data.push_back(cell_data_var);
642 if (mWriteVtkAsPoints)
648 unsigned num_cells = this->GetNumAllCells();
650 cell_writer_iter != this->mCellWriters.end();
654 std::vector<double> vtk_cell_data(num_cells);
658 cell_iter != this->End();
662 unsigned node_index = this->GetLocationIndexUsingCell(*cell_iter);
665 vtk_cell_data[node_index] = (*cell_writer_iter)->GetCellDataForVtkOutput(*cell_iter,
this);
668 cells_writer.
AddPointData((*cell_writer_iter)->GetVtkCellDataName(), vtk_cell_data);
673 cell_iter != this->End();
677 unsigned node_index = this->GetLocationIndexUsingCell(*cell_iter);
679 for (
unsigned var=0; var<num_cell_data_items; var++)
681 cell_data[var][node_index] = cell_iter->GetCellData()->GetItem(cell_data_names[var]);
684 for (
unsigned var=0; var<num_cell_data_items; var++)
686 cells_writer.
AddPointData(cell_data_names[var], cell_data[var]);
691 *(this->mpVtkMetaFile) <<
" <DataSet timestep=\"";
692 *(this->mpVtkMetaFile) << num_timesteps;
693 *(this->mpVtkMetaFile) <<
"\" group=\"\" part=\"0\" file=\"mesh_results_";
694 *(this->mpVtkMetaFile) << num_timesteps;
695 *(this->mpVtkMetaFile) <<
".vtu\"/>\n";
697 if (mpVoronoiTessellation !=
nullptr)
701 std::vector<double> cell_volumes(num_cells_from_mesh);
704 unsigned num_cells = this->GetNumAllCells();
706 cell_writer_iter != this->mCellWriters.end();
710 std::vector<double> vtk_cell_data(num_cells);
714 elem_iter != mpVoronoiTessellation->GetElementIteratorEnd();
718 unsigned elem_index = elem_iter->GetIndex();
721 unsigned node_index = mpVoronoiTessellation->GetDelaunayNodeIndexCorrespondingToVoronoiElementIndex(elem_index);
722 CellPtr p_cell = this->GetCellUsingLocationIndex(node_index);
725 vtk_cell_data[elem_index] = (*cell_writer_iter)->GetCellDataForVtkOutput(p_cell,
this);
728 mesh_writer.AddCellData((*cell_writer_iter)->GetVtkCellDataName(), vtk_cell_data);
733 elem_iter != mpVoronoiTessellation->GetElementIteratorEnd();
737 unsigned elem_index = elem_iter->GetIndex();
740 unsigned node_index = mpVoronoiTessellation->GetDelaunayNodeIndexCorrespondingToVoronoiElementIndex(elem_index);
741 CellPtr p_cell = this->GetCellUsingLocationIndex(node_index);
743 for (
unsigned var=0; var<num_cell_data_items; var++)
745 cell_data[var][elem_index] = p_cell->GetCellData()->GetItem(cell_data_names[var]);
749 for (
unsigned var=0; var<cell_data.size(); var++)
751 mesh_writer.AddCellData(cell_data_names[var], cell_data[var]);
754 mesh_writer.WriteVtkUsingMesh(*mpVoronoiTessellation, time.str());
755 *(this->mpVtkMetaFile) <<
" <DataSet timestep=\"";
756 *(this->mpVtkMetaFile) << num_timesteps;
757 *(this->mpVtkMetaFile) <<
"\" group=\"\" part=\"0\" file=\"voronoi_results_";
758 *(this->mpVtkMetaFile) << num_timesteps;
759 *(this->mpVtkMetaFile) <<
".vtu\"/>\n";
764template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
767 double cell_volume = 0;
769 if (ELEMENT_DIM == SPACE_DIM)
772 if (mpVoronoiTessellation ==
nullptr)
774 CreateVoronoiTessellation();
778 unsigned node_index = this->GetLocationIndexUsingCell(pCell);
783 unsigned element_index = mpVoronoiTessellation->GetVoronoiElementIndexCorrespondingToDelaunayNodeIndex(node_index);
786 cell_volume = mpVoronoiTessellation->GetVolumeOfElement(element_index);
791 cell_volume = DBL_MAX;
794 else if (SPACE_DIM==3 && ELEMENT_DIM==2)
796 unsigned node_index = this->GetLocationIndexUsingCell(pCell);
808 c_matrix<double, SPACE_DIM, ELEMENT_DIM> jacob;
813 cell_volume += fabs(p_element->
GetVolume(det));
828template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
831 mWriteVtkAsPoints = writeVtkAsPoints;
834template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
837 return mWriteVtkAsPoints;
840template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
843 mBoundVoronoiTessellation = boundVoronoiTessellation;
846template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
849 return mBoundVoronoiTessellation;
852template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
855 mScaleBoundByEdgeLength = scaleBoundByEdgeLength;
858template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
861 return mScaleBoundByEdgeLength;
864template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
867 assert(boundedVoroniTesselationLengthCutoff>0);
868 mBoundedVoroniTesselationLengthCutoff = boundedVoroniTesselationLengthCutoff;
871template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
874 return mBoundedVoroniTesselationLengthCutoff;
877template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
880 mOffsetNewBoundaryNodes = offsetNewBoundaryNodes;
883template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
886 return mOffsetNewBoundaryNodes;
891template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
896 *pVizSetupFile <<
"MeshWidth\t" << this->GetWidth(0) <<
"\n";
900 *pVizSetupFile <<
"MeshWidth\t" << this->GetWidth(0) <<
"\n";
901 *pVizSetupFile <<
"MeshHeight\t" << this->GetWidth(1) <<
"\n";
905template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
908 if constexpr (ELEMENT_DIM == 1)
913 else if constexpr (ELEMENT_DIM == 2 && SPACE_DIM == 2)
915 delete mpVoronoiTessellation;
918 bool is_mesh_periodic =
false;
921 if(mScaleBoundByEdgeLength || mBoundedVoroniTesselationLengthCutoff<DBL_MAX || mOffsetNewBoundaryNodes)
926 is_mesh_periodic =
true;
931 if(mScaleBoundByEdgeLength || mBoundedVoroniTesselationLengthCutoff<DBL_MAX || mOffsetNewBoundaryNodes)
936 is_mesh_periodic =
true;
941 mpVoronoiTessellation =
new VertexMesh<2, 2>(
static_cast<MutableMesh<2, 2>&
>((this->mrMesh)), is_mesh_periodic, mBoundVoronoiTessellation, mScaleBoundByEdgeLength, mBoundedVoroniTesselationLengthCutoff, mOffsetNewBoundaryNodes);
944 else if constexpr (ELEMENT_DIM == 3)
949 delete mpVoronoiTessellation;
962template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
968template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
971 return mEdgeIter.GetNodeB();
974template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
977 assert((*
this) != mrCellPopulation.SpringsEnd());
978 return mrCellPopulation.GetCellUsingLocationIndex(mEdgeIter.GetNodeA()->GetIndex());
981template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
984 assert((*
this) != mrCellPopulation.SpringsEnd());
985 return mrCellPopulation.GetCellUsingLocationIndex(mEdgeIter.GetNodeB()->GetIndex());
988template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
994template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
997 bool edge_is_ghost =
false;
1002 if (*
this != mrCellPopulation.SpringsEnd())
1004 bool a_is_ghost = mrCellPopulation.IsGhostNode(mEdgeIter.GetNodeA()->GetIndex());
1005 bool b_is_ghost = mrCellPopulation.IsGhostNode(mEdgeIter.GetNodeB()->GetIndex());
1007 edge_is_ghost = (a_is_ghost || b_is_ghost);
1010 while (*
this!=mrCellPopulation.SpringsEnd() && edge_is_ghost);
1015template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1019 : mrCellPopulation(rCellPopulation),
1027 if (a_is_ghost || b_is_ghost)
1034template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1040template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1046template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1053template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1056 unsigned element_index =
mpVoronoiTessellation->GetVoronoiElementIndexCorrespondingToDelaunayNodeIndex(index);
1061template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1064 unsigned element_index =
mpVoronoiTessellation->GetVoronoiElementIndexCorrespondingToDelaunayNodeIndex(index);
1066 return surface_area;
1069template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1072 unsigned element_index1 =
mpVoronoiTessellation->GetVoronoiElementIndexCorrespondingToDelaunayNodeIndex(index1);
1073 unsigned element_index2 =
mpVoronoiTessellation->GetVoronoiElementIndexCorrespondingToDelaunayNodeIndex(index2);
1082 EXCEPTION(
"Spring iterator tried to calculate interaction between degenerate cells on the boundary of the mesh. Have you set ghost layers correctly?");
1086template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1090 for (std::list<CellPtr>::iterator it=this->
mCells.begin();
1094 CellPtr p_cell = *it;
1101 std::cout <<
"Cell at node " << node_index <<
" addr " << p_cell << std::endl << std::flush;
1104 if (p_cell_in_cell_population != p_cell)
1106 std::cout <<
" Mismatch with cell population" << std::endl << std::flush;
1111 if (p_model->
GetCell() != p_cell)
1113 std::cout <<
" Mismatch with cycle model" << std::endl << std::flush;
1122 for (std::set<std::pair<CellPtr,CellPtr> >::iterator it1 = this->
mMarkedSprings.begin();
1126 const std::pair<CellPtr,CellPtr>& r_pair = *it1;
1128 for (
unsigned i=0; i<2; i++)
1130 CellPtr p_cell = (i==0 ? r_pair.first : r_pair.second);
1136 std::cout <<
"Cell at node " << node_index <<
" addr " << p_cell << std::endl << std::flush;
1140 if (p_cell->IsDead())
1142 std::cout <<
" Cell is dead" << std::endl << std::flush;
1148 if (p_cell_in_cell_population != p_cell)
1150 std::cout <<
" Mismatch with cell population" << std::endl << std::flush;
1155 if (p_model->
GetCell() != p_cell)
1157 std::cout <<
" Mismatch with cycle model" << std::endl << std::flush;
1166template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1172template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1175 assert(areaBasedDampingConstantParameter >= 0.0);
1180template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1189template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1194 *rParamsFile <<
"\t\t<WriteVtkAsPoints>" <<
mWriteVtkAsPoints <<
"</WriteVtkAsPoints>\n";
1202template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1206 double width = this->
mrMesh.GetWidth(rDimension);
1210template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1217 std::set<unsigned> neighbouring_node_indices;
1226 for (
unsigned i=0; i<p_element->
GetNumNodes(); i++)
1230 if (node_index != index)
1232 neighbouring_node_indices.insert(node_index);
1236 return neighbouring_node_indices;
1239template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1253 unsigned nodeA_global_index = p_nodeA->
GetIndex();
1254 unsigned nodeB_global_index = p_nodeB->
GetIndex();
1257 double separation =
rGetMesh().GetDistanceBetweenNodes(nodeA_global_index, nodeB_global_index);
1260 std::pair<unsigned,unsigned> node_pair = this->
CreateOrderedPair(nodeA_global_index, nodeB_global_index);
1267template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1272 std::pair<unsigned,unsigned> node_pair = this->
CreateOrderedPair(indexA, indexB);
1273 std::map<std::pair<unsigned,unsigned>,
double>::const_iterator iter =
mSpringRestLengths.find(node_pair);
1278 return iter->second;
1282 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.");
1291template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
1296 std::pair<unsigned,unsigned> node_pair = this->
CreateOrderedPair(indexA, indexB);
1297 std::map<std::pair<unsigned,unsigned>,
double>::iterator iter =
mSpringRestLengths.find(node_pair);
1302 iter->second = restLength;
1306 EXCEPTION(
"Tried to set the rest length of an edge not in the mesh.");
1311 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()
std::vector< std::pair< Node< SPACE_DIM > *, Node< SPACE_DIM > * > > mNodePairs
double GetBoundedVoroniTesselationLengthCutoff()
std::vector< std::pair< Node< SPACE_DIM > *, Node< SPACE_DIM > * > > & rGetNodePairs()
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
void AddPointData(std::string name, std::vector< double > data)
void WriteFilesUsingMesh(AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > &rMesh, bool keepOriginalElementIndexing=true)