36 #include "Cylindrical2dVertexMesh.hpp"
37 #include "Cylindrical2dMesh.hpp"
43 double cellRearrangementThreshold,
45 :
MutableVertexMesh<2,2>(nodes, vertexElements, cellRearrangementThreshold, t2Threshold),
53 : mWidth(rMesh.GetWidth(0))
64 this->
mNodes.reserve(num_nodes);
69 for (
unsigned elem_index=0; elem_index<num_elements; elem_index++)
79 for (
unsigned i=0; i<num_nodes; i++)
81 double x_location =
mNodes[i]->rGetLocation()[0];
84 mNodes[i]->rGetModifiableLocation()[0] = x_location +
mWidth;
86 else if (x_location >
mWidth )
88 mNodes[i]->rGetModifiableLocation()[0] = x_location -
mWidth;
93 for (
unsigned i=0; i<num_nodes; i++)
97 for (
unsigned local_index=0; local_index<3; local_index++)
99 unsigned elem_index =
mpDelaunayMesh->GetElement(i)->GetNodeGlobalIndex(local_index);
100 unsigned num_nodes_in_elem =
mElements[elem_index]->GetNumNodes();
101 unsigned end_index = num_nodes_in_elem>0 ? num_nodes_in_elem-1 : 0;
108 for (
unsigned elem_index=0; elem_index<
mElements.size(); elem_index++)
115 std::vector<std::pair<double, unsigned> > index_angle_list;
116 for (
unsigned local_index=0; local_index<
mElements[elem_index]->GetNumNodes(); local_index++)
118 c_vector<double, 2> vectorA =
mpDelaunayMesh->GetNode(elem_index)->rGetLocation();
119 c_vector<double, 2> vectorB =
mElements[elem_index]->GetNodeLocation(local_index);
120 c_vector<double, 2> centre_to_vertex =
mpDelaunayMesh->GetVectorFromAtoB(vectorA, vectorB);
122 double angle = atan2(centre_to_vertex(1), centre_to_vertex(0));
123 unsigned global_index =
mElements[elem_index]->GetNodeGlobalIndex(local_index);
125 std::pair<double, unsigned> pair(angle, global_index);
126 index_angle_list.push_back(pair);
130 sort(index_angle_list.begin(), index_angle_list.end());
134 for (
unsigned count = 0; count < index_angle_list.size(); count++)
136 unsigned local_index = count>1 ? count-1 : 0;
137 p_new_element->
AddNode(
mNodes[index_angle_list[count].second], local_index);
160 c_vector<double, 2> vector = rLocation2 - rLocation1;
161 vector[0] = fmod(vector[0],
mWidth);
164 if (vector[0] > 0.5*
mWidth)
168 else if (vector[0] < -0.5*
mWidth)
185 else if (x_coord < 0.0)
198 assert(rDimension==0 || rDimension==1);
216 SetNode(node_index, new_node_point);
223 assert(zScale == 1.0);
235 std::vector<Node<2>*> temp_nodes(2*num_nodes);
236 std::vector<VertexElement<2, 2>*> elements;
239 for (
unsigned index=0; index<num_nodes; index++)
241 c_vector<double, 2> 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 c_vector<double, 2> this_node_location = elem_iter->GetNode(0)->rGetLocation();
266 for (
unsigned local_index=0; local_index<num_nodes_in_elem; local_index++)
268 c_vector<double, 2> next_node_location = elem_iter->GetNode((local_index+1)%num_nodes_in_elem)->rGetLocation();
269 c_vector<double, 2> vector = next_node_location - this_node_location;
271 if (fabs(vector[0]) > 0.5*
mWidth)
273 element_straddles_left_right_boundary =
true;
278 for (
unsigned local_index=0; local_index<num_nodes_in_elem; local_index++)
280 unsigned this_node_index = elem_iter->GetNodeGlobalIndex(local_index);
283 if (element_straddles_left_right_boundary)
286 bool node_is_right_of_centre = (elem_iter->GetNode(local_index)->rGetLocation()[0] - 0.5*
mWidth > 0);
287 if (!node_is_right_of_centre)
290 this_node_index += num_nodes;
294 elem_nodes.push_back(temp_nodes[this_node_index]);
298 elements.push_back(p_element);
302 std::vector<Node<2>*> nodes;
304 for (
unsigned index=0; index<temp_nodes.size(); index++)
306 unsigned num_elems_containing_this_node = temp_nodes[index]->rGetContainingElementIndices().size();
308 if (num_elems_containing_this_node == 0)
311 delete temp_nodes[index];
316 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)