36 #include "Cylindrical2dVertexMesh.hpp" 37 #include "Cylindrical2dMesh.hpp" 42 double cellRearrangementThreshold,
44 :
MutableVertexMesh<2,2>(nodes, vertexElements, cellRearrangementThreshold, t2Threshold),
63 this->
mNodes.reserve(num_nodes);
68 for (
unsigned elem_index=0; elem_index<num_elements; elem_index++)
78 for (
unsigned i=0; i<num_nodes; i++)
80 double x_location =
mNodes[i]->rGetLocation()[0];
83 mNodes[i]->rGetModifiableLocation()[0] = x_location +
mWidth;
85 else if (x_location >
mWidth )
87 mNodes[i]->rGetModifiableLocation()[0] = x_location -
mWidth;
92 for (
unsigned i=0; i<num_nodes; i++)
96 for (
unsigned local_index=0; local_index<3; local_index++)
98 unsigned elem_index =
mpDelaunayMesh->GetElement(i)->GetNodeGlobalIndex(local_index);
99 unsigned num_nodes_in_elem =
mElements[elem_index]->GetNumNodes();
100 unsigned end_index = num_nodes_in_elem>0 ? num_nodes_in_elem-1 : 0;
107 for (
unsigned elem_index=0; elem_index<
mElements.size(); elem_index++)
114 std::vector<std::pair<double, unsigned> > index_angle_list;
115 for (
unsigned local_index=0; local_index<
mElements[elem_index]->GetNumNodes(); local_index++)
117 c_vector<double, 2> vectorA =
mpDelaunayMesh->GetNode(elem_index)->rGetLocation();
118 c_vector<double, 2> vectorB =
mElements[elem_index]->GetNodeLocation(local_index);
119 c_vector<double, 2> centre_to_vertex =
mpDelaunayMesh->GetVectorFromAtoB(vectorA, vectorB);
121 double angle = atan2(centre_to_vertex(1), centre_to_vertex(0));
122 unsigned global_index =
mElements[elem_index]->GetNodeGlobalIndex(local_index);
124 std::pair<double, unsigned> pair(angle, global_index);
125 index_angle_list.push_back(pair);
129 sort(index_angle_list.begin(), index_angle_list.end());
133 for (
unsigned count = 0; count < index_angle_list.size(); count++)
135 unsigned local_index = count>1 ? count-1 : 0;
136 p_new_element->
AddNode(
mNodes[index_angle_list[count].second], local_index);
159 c_vector<double, 2> vector = rLocation2 - rLocation1;
160 vector[0] = fmod(vector[0],
mWidth);
163 if (vector[0] > 0.5*
mWidth)
167 else if (vector[0] < -0.5*
mWidth)
184 else if (x_coord < 0.0)
197 assert(rDimension==0 || rDimension==1);
215 SetNode(node_index, new_node_point);
222 assert(zScale == 1.0);
234 std::vector<Node<2>*> temp_nodes(2*num_nodes);
235 std::vector<VertexElement<2, 2>*> elements;
238 for (
unsigned index=0; index<num_nodes; index++)
240 c_vector<double, 2> location;
241 location =
GetNode(index)->rGetLocation();
244 Node<2>* p_node =
new Node<2>(index,
false, location[0], location[1]);
245 temp_nodes[index] = p_node;
248 p_node =
new Node<2>(num_nodes + index,
false, location[0] +
mWidth, location[1]);
249 temp_nodes[num_nodes + index] = p_node;
257 unsigned elem_index = elem_iter->
GetIndex();
258 unsigned num_nodes_in_elem = elem_iter->GetNumNodes();
260 std::vector<Node<2>*> elem_nodes;
263 bool element_straddles_left_right_boundary =
false;
265 const c_vector<double, 2>& r_this_node_location = elem_iter->GetNode(0)->rGetLocation();
266 for (
unsigned local_index=0; local_index<num_nodes_in_elem; local_index++)
268 const c_vector<double, 2>& r_next_node_location = elem_iter->GetNode((local_index+1)%num_nodes_in_elem)->rGetLocation();
269 c_vector<double, 2> vector;
270 vector = r_next_node_location - r_this_node_location;
272 if (fabs(vector[0]) > 0.5*
mWidth)
274 element_straddles_left_right_boundary =
true;
279 for (
unsigned local_index=0; local_index<num_nodes_in_elem; local_index++)
281 unsigned this_node_index = elem_iter->GetNodeGlobalIndex(local_index);
284 if (element_straddles_left_right_boundary)
287 bool node_is_right_of_centre = (elem_iter->GetNode(local_index)->rGetLocation()[0] - 0.5*
mWidth > 0);
288 if (!node_is_right_of_centre)
291 this_node_index += num_nodes;
295 elem_nodes.push_back(temp_nodes[this_node_index]);
299 elements.push_back(p_element);
303 std::vector<Node<2>*> nodes;
305 for (
unsigned index=0; index<temp_nodes.size(); index++)
307 unsigned num_elems_containing_this_node = temp_nodes[index]->rGetContainingElementIndices().size();
309 if (num_elems_containing_this_node == 0)
312 delete temp_nodes[index];
317 nodes.push_back(temp_nodes[index]);
c_vector< double, DIM > & rGetLocation()
void SetIndex(unsigned index)
unsigned AddNode(Node< 2 > *pNewNode)
Node< SPACE_DIM > * GetNode(unsigned index) const
unsigned AddNode(Node< SPACE_DIM > *pNewNode)
double GetWidth(const unsigned &rDimension) const
void GenerateVerticesFromElementCircumcentres(TetrahedralMesh< ELEMENT_DIM, SPACE_DIM > &rMesh)
double mCellRearrangementThreshold
Cylindrical2dVertexMesh()
bool mMeshChangesDuringSimulation
void SetNode(unsigned nodeIndex, ChastePoint< 2 > point)
void AddNode(Node< SPACE_DIM > *pNode, const unsigned &rIndex)
std::vector< Node< SPACE_DIM > * > mNodes
VertexElementIterator GetElementIteratorBegin(bool skipDeletedElements=true)
void SetCoordinate(unsigned i, double value)
virtual void SetNode(unsigned nodeIndex, ChastePoint< SPACE_DIM > point)
c_vector< double, 2 > GetVectorFromAtoB(const c_vector< double, 2 > &rLocation1, const c_vector< double, 2 > &rLocation2)
unsigned GetNumNodes() const
std::vector< VertexElement< ELEMENT_DIM, SPACE_DIM > * > mElements
ChastePoint< SPACE_DIM > GetPoint() const
virtual double GetWidth(const unsigned &rDimension) const
~Cylindrical2dVertexMesh()
#define CHASTE_CLASS_EXPORT(T)
virtual void Scale(const double xFactor=1.0, const double yFactor=1.0, const double zFactor=1.0)
unsigned GetIndex() const
VertexElementIterator GetElementIteratorEnd()
MutableVertexMesh< 2, 2 > * GetMeshForVtk()
TetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * mpDelaunayMesh
void Scale(const double xScale=1.0, const double yScale=1.0, const double zScale=1.0)