36 #include "NodeBasedCellPopulationWithParticles.hpp"
37 #include "VtkMeshWriter.hpp"
38 #include "CellAgesWriter.hpp"
39 #include "CellAncestorWriter.hpp"
40 #include "CellProliferativePhasesWriter.hpp"
41 #include "CellProliferativeTypesWriter.hpp"
42 #include "CellVolumesWriter.hpp"
43 #include "CellMutationStatesCountWriter.hpp"
45 template<
unsigned DIM>
47 std::vector<CellPtr>& rCells,
48 const std::vector<unsigned> locationIndices,
53 if (!locationIndices.empty())
56 std::set<unsigned> node_indices;
57 std::set<unsigned> location_indices;
58 std::set<unsigned> particle_indices;
64 node_indices.insert(node_iter->GetIndex());
66 for (
unsigned i=0; i<locationIndices.size(); i++)
68 location_indices.insert(locationIndices[i]);
71 std::set_difference(node_indices.begin(), node_indices.end(),
72 location_indices.begin(), location_indices.end(),
73 std::inserter(particle_indices, particle_indices.begin()));
84 (*node_iter).SetIsParticle(
false);
90 template<
unsigned DIM>
96 template<
unsigned DIM>
99 return this->GetNode(index)->IsParticle();
102 template<
unsigned DIM>
105 std::set<unsigned> particle_indices;
108 node_iter != this->mrMesh.GetNodeIteratorEnd();
111 if (node_iter->IsParticle())
113 particle_indices.insert(node_iter->GetIndex());
117 return particle_indices;
120 template<
unsigned DIM>
124 node_iter != this->mrMesh.GetNodeIteratorEnd();
127 if (rParticleIndices.find(node_iter->GetIndex()) != rParticleIndices.end())
129 node_iter->SetIsParticle(
true);
135 template<
unsigned DIM>
139 std::vector<c_vector<double, DIM> > drdt(this->GetNumNodes());
140 for (
unsigned i=0; i<drdt.size(); i++)
142 drdt[i] = zero_vector<double>(DIM);
146 double damping_constant = this->GetDampingConstantNormal();
147 for (
unsigned i=0; i<drdt.size(); i++)
149 drdt[i] = this->GetNode(i)->rGetAppliedForce()/damping_constant;
153 node_iter != this->mrMesh.GetNodeIteratorEnd();
156 if (node_iter->IsParticle())
158 ChastePoint<DIM> new_point(node_iter->rGetLocation() + dt*drdt[node_iter->GetIndex()]);
159 node_iter->SetPoint(new_point);
164 template<
unsigned DIM>
169 template<
unsigned DIM>
176 assert(p_created_cell == pNewCell);
179 unsigned node_index = this->GetLocationIndexUsingCell(p_created_cell);
180 this->GetNode(node_index)->SetRadius(0.5);
181 this->GetNode(node_index)->SetIsParticle(
false);
184 return p_created_cell;
187 template<
unsigned DIM>
190 std::map<unsigned, bool> validated_nodes;
192 node_iter != this->mrMesh.GetNodeIteratorEnd();
195 validated_nodes[node_iter->GetIndex()] = node_iter->IsParticle();
201 unsigned node_index = this->GetLocationIndexUsingCell((*cell_iter));
204 if (this->GetNode(node_index)->IsParticle())
206 EXCEPTION(
"Node " << node_index <<
" is labelled as a particle and has a cell attached");
208 validated_nodes[node_index] =
true;
211 for (std::map<unsigned, bool>::iterator map_iter = validated_nodes.begin();
212 map_iter != validated_nodes.end();
215 if (!map_iter->second)
217 EXCEPTION(
"Node " << map_iter->first <<
" does not appear to be a particle or has a cell associated with it");
222 template<
unsigned DIM>
226 UpdateParticlePositions(dt);
232 template<
unsigned DIM>
240 if (! this->IsParticle(node_iter->GetIndex()))
243 cell_writer_iter != this->mCellWriters.end();
246 CellPtr cell_from_node = this->GetCellUsingLocationIndex(node_iter->GetIndex());
247 this->AcceptCellWriter(*cell_writer_iter, cell_from_node);
254 template<
unsigned DIM>
259 std::stringstream time;
263 NodeMap map(1 + this->mpNodesOnlyMesh->GetMaximumNodeIndex());
264 this->mpNodesOnlyMesh->ReMesh(map);
267 unsigned num_nodes = this->GetNumNodes();
268 std::vector<double> rank(num_nodes);
269 std::vector<double> particles(num_nodes);
271 unsigned num_cell_data_items = 0;
272 std::vector<std::string> cell_data_names;
277 num_cell_data_items = this->Begin()->GetCellData()->GetNumItems();
278 cell_data_names = this->Begin()->GetCellData()->GetKeys();
281 std::vector<std::vector<double> > cell_data;
282 for (
unsigned var=0; var<num_cell_data_items; var++)
284 std::vector<double> cell_data_var(num_nodes);
285 cell_data.push_back(cell_data_var);
294 cell_writer_iter != this->mCellWriters.end();
298 std::vector<double> vtk_cell_data(num_nodes);
302 node_iter != this->mrMesh.GetNodeIteratorEnd();
305 unsigned node_index = node_iter->GetIndex();
308 if (this->IsParticle(node_index))
310 vtk_cell_data[node_index] = -2.0;
315 CellPtr p_cell = this->GetCellUsingLocationIndex(node_index);
316 vtk_cell_data[node_index] = (*cell_writer_iter)->GetCellDataForVtkOutput(p_cell,
this);
320 mesh_writer.AddPointData((*cell_writer_iter)->GetVtkCellDataName(), vtk_cell_data);
325 cell_iter != this->End();
329 unsigned global_index = this->GetLocationIndexUsingCell(*cell_iter);
330 unsigned node_index = this->rGetMesh().SolveNodeMapping(global_index);
332 for (
unsigned var=0; var<num_cell_data_items; var++)
334 cell_data[var][node_index] = cell_iter->GetCellData()->GetItem(cell_data_names[var]);
340 mesh_writer.AddPointData(
"Process rank", rank);
344 node_iter != this->mrMesh.GetNodeIteratorEnd();
347 unsigned node_index = node_iter->GetIndex();
348 particles[node_index] = (
double) (this->IsParticle(node_index));
351 mesh_writer.AddPointData(
"Non-particles", particles);
353 if (num_cell_data_items > 0)
355 for (
unsigned var=0; var<cell_data.size(); var++)
357 mesh_writer.AddPointData(cell_data_names[var], cell_data[var]);
361 mesh_writer.WriteFilesUsingMesh(*(this->mpNodesOnlyMesh));
363 *(this->mpVtkMetaFile) <<
" <DataSet timestep=\"";
365 *(this->mpVtkMetaFile) <<
"\" group=\"\" part=\"0\" file=\"results_";
369 *(this->mpVtkMetaFile) <<
".vtu\"/>\n";
378 template<
unsigned DIM>
void UpdateParticlesAfterReMesh(NodeMap &rMap)
void OutputCellPopulationParameters(out_stream &rParamsFile)
void UpdateNodeLocations(double dt)
NodeBasedCellPopulationWithParticles(NodesOnlyMesh< DIM > &rMesh, std::vector< CellPtr > &rCells, const std::vector< unsigned > locationIndices=std::vector< unsigned >(), bool deleteMesh=false)
#define EXCEPTION(message)
static SimulationTime * Instance()
void SetParallelFiles(AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > &rMesh)
NodeIterator GetNodeIteratorEnd()
unsigned GetTimeStepsElapsed() const
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
bool IsParticle(unsigned index)
#define EXCEPT_IF_NOT(test)
NodeIterator GetNodeIteratorBegin(bool skipDeletedNodes=true)
std::set< unsigned > GetParticleIndices()
virtual void WriteVtkResultsToFile(const std::string &rDirectory)
void UpdateParticlePositions(double dt)
CellPtr AddCell(CellPtr pNewCell, const c_vector< double, SPACE_DIM > &rCellDivisionVector, CellPtr pParentCell=CellPtr())
virtual void UpdateNodeLocations(double dt)
virtual void AcceptCellWritersAcrossPopulation()
CellPtr AddCell(CellPtr pNewCell, const c_vector< double, DIM > &rCellDivisionVector, CellPtr pParentCell)
void OutputCellPopulationParameters(out_stream &rParamsFile)
void SetParticles(const std::set< unsigned > &rParticleIndices)