36 #include "Toroidal2dVertexMesh.hpp"
42 double cellRearrangementThreshold,
44 :
MutableVertexMesh<2,2>(nodes, vertexElements, cellRearrangementThreshold, t2Threshold),
70 c_vector<double, 2> vector = rLocation2 - rLocation1;
71 vector[0] = fmod(vector[0],
mWidth);
72 vector[1] = fmod(vector[1],
mHeight);
75 if (vector[0] > 0.5*
mWidth)
79 else if (vector[0] < -0.5*
mWidth)
89 else if (vector[1] < -0.5*
mHeight)
107 else if (x_coord < 0.0)
117 else if (y_coord < 0.0)
129 assert(rDimension==0 || rDimension==1);
158 SetNode(node_index, new_node_point);
167 std::vector<Node<2>*> temp_nodes(4*num_nodes);
168 std::vector<VertexElement<2, 2>*> elements;
171 for (
unsigned index=0; index<num_nodes; index++)
173 c_vector<double, 2> location;
174 location =
GetNode(index)->rGetLocation();
177 Node<2>* p_node =
new Node<2>(index,
false, location[0], location[1]);
178 temp_nodes[index] = p_node;
181 p_node =
new Node<2>(num_nodes + index,
false, location[0] +
mWidth, location[1]);
182 temp_nodes[num_nodes + index] = p_node;
185 p_node =
new Node<2>(2*num_nodes + index,
false, location[0], location[1] +
mHeight);
186 temp_nodes[2*num_nodes + index] = p_node;
190 temp_nodes[3*num_nodes + index] = p_node;
198 unsigned elem_index = elem_iter->
GetIndex();
199 unsigned num_nodes_in_elem = elem_iter->GetNumNodes();
201 std::vector<Node<2>*> elem_nodes;
204 bool element_straddles_left_right_boundary =
false;
205 bool element_straddles_top_bottom_boundary =
false;
207 const c_vector<double, 2>& r_this_node_location = elem_iter->GetNode(0)->rGetLocation();
208 for (
unsigned local_index=0; local_index<num_nodes_in_elem; local_index++)
210 const c_vector<double, 2>& r_next_node_location = elem_iter->GetNode((local_index+1)%num_nodes_in_elem)->rGetLocation();
211 c_vector<double, 2> vector;
212 vector = r_next_node_location - r_this_node_location;
214 if (fabs(vector[0]) > 0.5*
mWidth)
216 element_straddles_left_right_boundary =
true;
218 if (fabs(vector[1]) > 0.5*
mHeight)
220 element_straddles_top_bottom_boundary =
true;
225 for (
unsigned local_index=0; local_index<num_nodes_in_elem; local_index++)
227 unsigned this_node_index = elem_iter->GetNodeGlobalIndex(local_index);
230 if (element_straddles_left_right_boundary)
233 bool node_is_right_of_centre = (elem_iter->GetNode(local_index)->rGetLocation()[0] - 0.5*
mWidth > 0);
234 if (!node_is_right_of_centre)
237 this_node_index += num_nodes;
242 if (element_straddles_top_bottom_boundary)
245 bool node_is_above_centre = (elem_iter->GetNode(local_index)->rGetLocation()[1] - 0.5*
mHeight > 0);
246 if (!node_is_above_centre)
249 this_node_index += 2*num_nodes;
253 elem_nodes.push_back(temp_nodes[this_node_index]);
257 elements.push_back(p_element);
261 std::vector<Node<2>*> nodes;
263 for (
unsigned index=0; index<temp_nodes.size(); index++)
265 unsigned num_elems_containing_this_node = temp_nodes[index]->rGetContainingElementIndices().size();
267 if (num_elems_containing_this_node == 0)
270 delete temp_nodes[index];
275 nodes.push_back(temp_nodes[index]);
298 this->
mNodes.reserve(num_nodes);
303 std::vector<double> node_data;
304 for (
unsigned node_idx = 0 ; node_idx < num_nodes ; node_idx++)
307 node_data.pop_back();
308 this->
mNodes.push_back(
new Node<2>(node_idx, node_data,
false));
317 for (
unsigned elem_idx = 0 ; elem_idx < num_elements ; elem_idx++)
323 std::vector<Node<2>*> nodes;
324 unsigned num_nodes_in_element = element_data.
NodeIndices.size();
325 for (
unsigned j=0; j<num_nodes_in_element; j++)
327 assert(element_data.
NodeIndices[j] < this->mNodes.size());
349 double total_surface_area = 0.0;
350 for (
unsigned elem_idx = 0 ; elem_idx < num_elements ; elem_idx++)
357 EXCEPTION(
"Mesh width and height do not match sheet surface area.");
void SetAttribute(double attribute)
unsigned AddNode(Node< 2 > *pNewNode)
double GetWidth(const unsigned &rDimension) const
virtual ElementData GetNextElementData()=0
c_vector< double, DIM > & rGetLocation()
void SetIndex(unsigned index)
Node< SPACE_DIM > * GetNode(unsigned index) const
#define EXCEPTION(message)
c_vector< double, 2 > GetVectorFromAtoB(const c_vector< double, 2 > &rLocation1, const c_vector< double, 2 > &rLocation2)
unsigned AddNode(Node< SPACE_DIM > *pNewNode)
void ConstructFromMeshReader(AbstractMeshReader< 2, 2 > &rMeshReader, double width, double height)
double mCellRearrangementRatio
double mCellRearrangementThreshold
std::vector< unsigned > NodeIndices
virtual bool HasNodePermutation()
VertexMesh< 2, 2 > * mpMeshForVtk
bool mMeshChangesDuringSimulation
std::vector< Node< SPACE_DIM > * > mNodes
VertexElementIterator GetElementIteratorBegin(bool skipDeletedElements=true)
virtual unsigned GetNumElements() const =0
void SetCoordinate(unsigned i, double value)
virtual void SetNode(unsigned nodeIndex, ChastePoint< SPACE_DIM > point)
void SetHeight(double height)
unsigned GetNumNodes() const
virtual double GetVolumeOfElement(unsigned index)
virtual unsigned GetNumElementAttributes() const
std::vector< VertexElement< ELEMENT_DIM, SPACE_DIM > * > mElements
void SetNode(unsigned nodeIndex, ChastePoint< 2 > point)
void SetWidth(double width)
ChastePoint< SPACE_DIM > GetPoint() const
#define CHASTE_CLASS_EXPORT(T)
VertexMesh< 2, 2 > * GetMeshForVtk()
virtual std::vector< double > GetNextNode()=0
unsigned GetIndex() const
VertexElementIterator GetElementIteratorEnd()
virtual unsigned GetNumNodes() const =0