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>
140 template<
unsigned DIM>
147 assert(p_created_cell == pNewCell);
150 unsigned node_index = this->GetLocationIndexUsingCell(p_created_cell);
151 this->GetNode(node_index)->SetRadius(0.5);
152 this->GetNode(node_index)->SetIsParticle(
false);
155 return p_created_cell;
158 template<
unsigned DIM>
161 std::map<unsigned, bool> validated_nodes;
163 node_iter != this->mrMesh.GetNodeIteratorEnd();
166 validated_nodes[node_iter->GetIndex()] = node_iter->IsParticle();
172 unsigned node_index = this->GetLocationIndexUsingCell((*cell_iter));
175 if (this->GetNode(node_index)->IsParticle())
177 EXCEPTION(
"Node " << node_index <<
" is labelled as a particle and has a cell attached");
179 validated_nodes[node_index] =
true;
182 for (std::map<unsigned, bool>::iterator map_iter = validated_nodes.begin();
183 map_iter != validated_nodes.end();
186 if (!map_iter->second)
188 EXCEPTION(
"Node " << map_iter->first <<
" does not appear to be a particle or has a cell associated with it");
193 template<
unsigned DIM>
201 if (! this->IsParticle(node_iter->GetIndex()))
204 cell_writer_iter != this->mCellWriters.end();
207 CellPtr cell_from_node = this->GetCellUsingLocationIndex(node_iter->GetIndex());
208 this->AcceptCellWriter(*cell_writer_iter, cell_from_node);
214 template<
unsigned DIM>
219 std::stringstream time;
223 NodeMap map(1 + this->mpNodesOnlyMesh->GetMaximumNodeIndex());
224 this->mpNodesOnlyMesh->ReMesh(map);
227 unsigned num_nodes = this->GetNumNodes();
228 std::vector<double> rank(num_nodes);
229 std::vector<double> particles(num_nodes);
231 unsigned num_cell_data_items = 0;
232 std::vector<std::string> cell_data_names;
237 num_cell_data_items = this->Begin()->GetCellData()->GetNumItems();
238 cell_data_names = this->Begin()->GetCellData()->GetKeys();
241 std::vector<std::vector<double> > cell_data;
242 for (
unsigned var=0; var<num_cell_data_items; var++)
244 std::vector<double> cell_data_var(num_nodes);
245 cell_data.push_back(cell_data_var);
254 cell_writer_iter != this->mCellWriters.end();
258 std::vector<double> vtk_cell_data(num_nodes);
262 node_iter != this->mrMesh.GetNodeIteratorEnd();
265 unsigned node_index = node_iter->GetIndex();
268 if (this->IsParticle(node_index))
270 vtk_cell_data[node_index] = -2.0;
275 CellPtr p_cell = this->GetCellUsingLocationIndex(node_index);
276 vtk_cell_data[node_index] = (*cell_writer_iter)->GetCellDataForVtkOutput(p_cell,
this);
280 mesh_writer.AddPointData((*cell_writer_iter)->GetVtkCellDataName(), vtk_cell_data);
285 cell_iter != this->End();
289 unsigned global_index = this->GetLocationIndexUsingCell(*cell_iter);
290 unsigned node_index = this->rGetMesh().SolveNodeMapping(global_index);
292 for (
unsigned var=0; var<num_cell_data_items; var++)
294 cell_data[var][node_index] = cell_iter->GetCellData()->GetItem(cell_data_names[var]);
300 mesh_writer.AddPointData(
"Process rank", rank);
304 node_iter != this->mrMesh.GetNodeIteratorEnd();
307 unsigned node_index = node_iter->GetIndex();
308 particles[node_index] = (
double) (this->IsParticle(node_index));
311 mesh_writer.AddPointData(
"Non-particles", particles);
313 if (num_cell_data_items > 0)
315 for (
unsigned var=0; var<cell_data.size(); var++)
317 mesh_writer.AddPointData(cell_data_names[var], cell_data[var]);
321 mesh_writer.WriteFilesUsingMesh(*(this->mpNodesOnlyMesh));
323 *(this->mpVtkMetaFile) <<
" <DataSet timestep=\"";
325 *(this->mpVtkMetaFile) <<
"\" group=\"\" part=\"0\" file=\"results_";
329 *(this->mpVtkMetaFile) <<
".vtu\"/>\n";
338 template<
unsigned DIM>
CellPtr AddCell(CellPtr pNewCell, CellPtr pParentCell)
void UpdateParticlesAfterReMesh(NodeMap &rMap)
void OutputCellPopulationParameters(out_stream &rParamsFile)
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)
CellPtr AddCell(CellPtr pNewCell, CellPtr pParentCell=CellPtr())
#define EXCEPT_IF_NOT(test)
NodeIterator GetNodeIteratorBegin(bool skipDeletedNodes=true)
std::set< unsigned > GetParticleIndices()
virtual void WriteVtkResultsToFile(const std::string &rDirectory)
virtual void AcceptCellWritersAcrossPopulation()
void OutputCellPopulationParameters(out_stream &rParamsFile)
void SetParticles(const std::set< unsigned > &rParticleIndices)