36 #include "Cylindrical2dVertexMesh.hpp"
37 #include "Cylindrical2dMesh.hpp"
42 double cellRearrangementThreshold,
44 :
MutableVertexMesh<2,2>(nodes, vertexElements, cellRearrangementThreshold, t2Threshold),
53 : mWidth(rMesh.GetWidth(0)),
65 this->
mNodes.reserve(num_nodes);
70 for (
unsigned elem_index=0; elem_index<num_elements; elem_index++)
80 for (
unsigned i=0; i<num_nodes; i++)
82 double x_location =
mNodes[i]->rGetLocation()[0];
85 mNodes[i]->rGetModifiableLocation()[0] = x_location +
mWidth;
87 else if (x_location >
mWidth)
89 mNodes[i]->rGetModifiableLocation()[0] = x_location -
mWidth;
94 for (
unsigned i=0; i<num_nodes; i++)
98 for (
unsigned local_index=0; local_index<3; local_index++)
100 unsigned elem_index =
mpDelaunayMesh->GetElement(i)->GetNodeGlobalIndex(local_index);
101 unsigned num_nodes_in_elem =
mElements[elem_index]->GetNumNodes();
102 unsigned end_index = num_nodes_in_elem>0 ? num_nodes_in_elem-1 : 0;
109 for (
unsigned elem_index=0; elem_index<
mElements.size(); elem_index++)
116 std::vector<std::pair<double, unsigned> > index_angle_list;
117 for (
unsigned local_index=0; local_index<
mElements[elem_index]->GetNumNodes(); local_index++)
119 c_vector<double, 2> vectorA =
mpDelaunayMesh->GetNode(elem_index)->rGetLocation();
120 c_vector<double, 2> vectorB =
mElements[elem_index]->GetNodeLocation(local_index);
121 c_vector<double, 2> centre_to_vertex =
mpDelaunayMesh->GetVectorFromAtoB(vectorA, vectorB);
123 double angle = atan2(centre_to_vertex(1), centre_to_vertex(0));
124 unsigned global_index =
mElements[elem_index]->GetNodeGlobalIndex(local_index);
126 std::pair<double, unsigned> pair(angle, global_index);
127 index_angle_list.push_back(pair);
131 sort(index_angle_list.begin(), index_angle_list.end());
135 for (
unsigned count = 0; count < index_angle_list.size(); count++)
137 unsigned local_index = count>1 ? count-1 : 0;
138 p_new_element->
AddNode(
mNodes[index_angle_list[count].second], local_index);
150 : mpMeshForVtk(nullptr)
166 c_vector<double, 2> vector = rLocation2 - rLocation1;
167 vector[0] = fmod(vector[0],
mWidth);
170 if (vector[0] > 0.5*
mWidth)
174 else if (vector[0] < -0.5*
mWidth)
191 else if (x_coord < 0.0)
204 assert(rDimension==0 || rDimension==1);
222 SetNode(node_index, new_node_point);
229 assert(zScale == 1.0);
241 std::vector<Node<2>*> temp_nodes(2*num_nodes);
242 std::vector<VertexElement<2, 2>*> elements;
245 for (
unsigned index=0; index<num_nodes; index++)
247 c_vector<double, 2> location;
248 location =
GetNode(index)->rGetLocation();
251 Node<2>* p_node =
new Node<2>(index,
false, location[0], location[1]);
252 temp_nodes[index] = p_node;
255 p_node =
new Node<2>(num_nodes + index,
false, location[0] +
mWidth, location[1]);
256 temp_nodes[num_nodes + index] = p_node;
264 unsigned elem_index = elem_iter->
GetIndex();
265 unsigned num_nodes_in_elem = elem_iter->GetNumNodes();
267 std::vector<Node<2>*> elem_nodes;
270 bool element_straddles_left_right_boundary =
false;
272 const c_vector<double, 2>& r_this_node_location = elem_iter->GetNode(0)->rGetLocation();
273 for (
unsigned local_index=0; local_index<num_nodes_in_elem; local_index++)
275 const c_vector<double, 2>& r_next_node_location = elem_iter->GetNode((local_index+1)%num_nodes_in_elem)->rGetLocation();
276 c_vector<double, 2> vector;
277 vector = r_next_node_location - r_this_node_location;
279 if (fabs(vector[0]) > 0.5*
mWidth)
281 element_straddles_left_right_boundary =
true;
286 for (
unsigned local_index=0; local_index<num_nodes_in_elem; local_index++)
288 unsigned this_node_index = elem_iter->GetNodeGlobalIndex(local_index);
291 if (element_straddles_left_right_boundary)
294 bool node_is_right_of_centre = (elem_iter->GetNode(local_index)->rGetLocation()[0] - 0.5*
mWidth > 0);
295 if (!node_is_right_of_centre)
298 this_node_index += num_nodes;
302 elem_nodes.push_back(temp_nodes[this_node_index]);
306 elements.push_back(p_element);
310 std::vector<Node<2>*> nodes;
312 for (
unsigned index=0; index<temp_nodes.size(); index++)
314 unsigned num_elems_containing_this_node = temp_nodes[index]->rGetContainingElementIndices().size();
316 if (num_elems_containing_this_node == 0)
319 delete temp_nodes[index];
324 nodes.push_back(temp_nodes[index]);
c_vector< double, DIM > & rGetLocation()
void SetIndex(unsigned index)
VertexMesh< 2, 2 > * mpMeshForVtk
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)
Cylindrical2dVertexMesh()
VertexMesh< 2, 2 > * GetMeshForVtk()
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()
TetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * mpDelaunayMesh
void Scale(const double xScale=1.0, const double yScale=1.0, const double zScale=1.0)