Chaste Commit::f2ff7ee04e70ac9d06c57344df8d017dbb12b97b
CellPopulationElementWriter.cpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14 * Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19 * Neither the name of the University of Oxford nor the names of its
20 contributors may be used to endorse or promote products derived from this
21 software without specific prior written permission.
22
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36#include "CellPopulationElementWriter.hpp"
37#include "AbstractCellPopulation.hpp"
38#include "MeshBasedCellPopulation.hpp"
39#include "CaBasedCellPopulation.hpp"
40#include "NodeBasedCellPopulation.hpp"
41#include "PottsBasedCellPopulation.hpp"
42#include "VertexBasedCellPopulation.hpp"
43#include "ImmersedBoundaryCellPopulation.hpp"
44
45template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
50
51template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
53{
55 elem_iter != static_cast<MutableMesh<ELEMENT_DIM,SPACE_DIM>&>((pCellPopulation->rGetMesh())).GetElementIteratorEnd();
56 ++elem_iter)
57 {
58 bool element_contains_dead_cells_or_deleted_nodes = false;
59
60 // Hack that covers the case where the element contains a node that is associated with a cell that has just been killed (#1129)
61 for (unsigned i=0; i<ELEMENT_DIM+1; i++)
62 {
63 unsigned node_index = elem_iter->GetNodeGlobalIndex(i);
64
65 if (pCellPopulation->GetNode(node_index)->IsDeleted())
66 {
67 element_contains_dead_cells_or_deleted_nodes = true;
68 break;
69 }
70 else if (pCellPopulation->IsCellAttachedToLocationIndex(node_index))
71 {
72 if (pCellPopulation->GetCellUsingLocationIndex(node_index)->IsDead())
73 {
74 element_contains_dead_cells_or_deleted_nodes = true;
75 break;
76 }
77 }
78 }
79 if (!element_contains_dead_cells_or_deleted_nodes)
80 {
81 for (unsigned i=0; i<ELEMENT_DIM+1; i++)
82 {
83 *this->mpOutStream << elem_iter->GetNodeGlobalIndex(i) << " ";
84 }
85 }
86 }
87}
88
89template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
91{
92 EXCEPTION("CellPopulationElementWriter cannot be used with a CaBasedCellPopulation");
93}
94
95template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
97{
98 EXCEPTION("CellPopulationElementWriter cannot be used with a NodeBasedCellPopulation");
99}
100
101template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
103{
104 // Loop over cells and find associated elements so in the same order as the cells in output files
105 for (typename AbstractCellPopulation<SPACE_DIM, SPACE_DIM>::Iterator cell_iter = pCellPopulation->Begin();
106 cell_iter != pCellPopulation->End();
107 ++cell_iter)
108 {
109 unsigned elem_index = pCellPopulation->GetLocationIndexUsingCell(*cell_iter);
110
111 // Hack that covers the case where the element is associated with a cell that has just been killed (#1129)
112 bool elem_corresponds_to_dead_cell = false;
113
114 if (pCellPopulation->IsCellAttachedToLocationIndex(elem_index))
115 {
116 elem_corresponds_to_dead_cell = pCellPopulation->GetCellUsingLocationIndex(elem_index)->IsDead();
117 }
118
119 // Write element data to file
120 if (!(pCellPopulation->GetElement(elem_index)->IsDeleted()) && !elem_corresponds_to_dead_cell)
121 {
122 PottsElement<SPACE_DIM>* p_element = pCellPopulation->rGetMesh().GetElement(elem_index);
123 unsigned num_nodes_in_element = p_element->GetNumNodes();
124
125 // First write the number of Nodes belonging to this VertexElement
126 *this->mpOutStream << num_nodes_in_element << " ";
127
128 // Then write the global index of each Node in this element
129 for (unsigned i=0; i<num_nodes_in_element; i++)
130 {
131 *this->mpOutStream << p_element->GetNodeGlobalIndex(i) << " ";
132 }
133 }
134 }
135}
136
137template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
139{
140 // Loop over cells and find associated elements so in the same order as the cells in output files
141 for (typename AbstractCellPopulation<SPACE_DIM, SPACE_DIM>::Iterator cell_iter = pCellPopulation->Begin();
142 cell_iter != pCellPopulation->End();
143 ++cell_iter)
144 {
145 unsigned elem_index = pCellPopulation->GetLocationIndexUsingCell(*cell_iter);
146
147 // Hack that covers the case where the element is associated with a cell that has just been killed (#1129)
148 bool elem_corresponds_to_dead_cell = false;
149
150 if (pCellPopulation->IsCellAttachedToLocationIndex(elem_index))
151 {
152 elem_corresponds_to_dead_cell = pCellPopulation->GetCellUsingLocationIndex(elem_index)->IsDead();
153 }
154
155 // Write element data to file
156 if (!(pCellPopulation->GetElement(elem_index)->IsDeleted()) && !elem_corresponds_to_dead_cell)
157 {
158 VertexElement<SPACE_DIM, SPACE_DIM>* p_element = pCellPopulation->rGetMesh().GetElement(elem_index);
159 unsigned num_nodes_in_element = p_element->GetNumNodes();
160
161 // First write the number of Nodes belonging to this VertexElement
162 *this->mpOutStream << num_nodes_in_element << " ";
163
164 // Then write the global index of each Node in this element
165 for (unsigned i=0; i<num_nodes_in_element; i++)
166 {
167 *this->mpOutStream << p_element->GetNodeGlobalIndex(i) << " ";
168 }
169 }
170 }
171}
172
173template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
175{
176 // Loop over cells and find associated elements so in the same order as the cells in output files
177 for (auto cell_iter = pCellPopulation->Begin(); cell_iter != pCellPopulation->End(); ++cell_iter)
178 {
179 const unsigned elem_index = pCellPopulation->GetLocationIndexUsingCell(*cell_iter);
180
181 // Hack that covers the case where the element is associated with a cell that has just been killed (#1129)
182 bool elem_corresponds_to_dead_cell = false;
183
184 if (pCellPopulation->IsCellAttachedToLocationIndex(elem_index))
185 {
186 elem_corresponds_to_dead_cell = pCellPopulation->GetCellUsingLocationIndex(elem_index)->IsDead();
187 }
188
189 // Write element data to file
190 if (!(pCellPopulation->GetElement(elem_index)->IsDeleted()) && !elem_corresponds_to_dead_cell)
191 {
192 ImmersedBoundaryElement<SPACE_DIM, SPACE_DIM>* const p_element = pCellPopulation->rGetMesh().GetElement(elem_index);
193 const unsigned num_nodes_in_element = p_element->GetNumNodes();
194
195 // First write the number of Nodes belonging to this VertexElement
196 *this->mpOutStream << num_nodes_in_element << " ";
197
198 // Then write the global index of each Node in this element
199 for (unsigned i=0; i<num_nodes_in_element; i++)
200 {
201 *this->mpOutStream << p_element->GetNodeGlobalIndex(i) << " ";
202 }
203 }
204 }
205}
206
207// Explicit instantiation
214
216// Declare identifier for the serializer
#define EXCEPTION(message)
#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
virtual bool IsCellAttachedToLocationIndex(unsigned index)
unsigned GetLocationIndexUsingCell(CellPtr pCell)
virtual CellPtr GetCellUsingLocationIndex(unsigned index)
unsigned GetNumNodes() const
unsigned GetNodeGlobalIndex(unsigned localIndex) const
ElementIterator GetElementIteratorBegin(bool skipDeletedElements=true)
virtual void Visit(MeshBasedCellPopulation< ELEMENT_DIM, SPACE_DIM > *pCellPopulation)
ImmersedBoundaryMesh< DIM, DIM > & rGetMesh()
ImmersedBoundaryElement< DIM, DIM > * GetElement(unsigned elementIndex)
ImmersedBoundaryElement< ELEMENT_DIM, SPACE_DIM > * GetElement(unsigned index) const
Node< SPACE_DIM > * GetNode(unsigned index)
MutableMesh< ELEMENT_DIM, SPACE_DIM > & rGetMesh()
PottsElement< DIM > * GetElement(unsigned elementIndex)
VertexElement< DIM, DIM > * GetElement(unsigned elementIndex)
MutableVertexMesh< DIM, DIM > & rGetMesh()
VertexElement< ELEMENT_DIM, SPACE_DIM > * GetElement(unsigned index) const