53 : mWidth(rMesh.GetWidth(0)),
67 this->
mNodes.reserve(num_nodes);
72 for (
unsigned elem_index=0; elem_index<num_elements; elem_index++)
82 for (
unsigned i=0; i<
mNodes.size(); i++)
88 for (
unsigned i=0; i<num_nodes; i++)
92 for (
unsigned local_index=0; local_index<3; local_index++)
94 unsigned elem_index =
mpDelaunayMesh->GetElement(i)->GetNodeGlobalIndex(local_index);
95 unsigned num_nodes_in_elem =
mElements[elem_index]->GetNumNodes();
96 unsigned end_index = num_nodes_in_elem>0 ? num_nodes_in_elem-1 : 0;
105 std::vector<Node<2> *> nodes;
110 nodes.push_back(
new Node<2>(node_iter->GetIndex(), node_iter->rGetLocation(),node_iter->IsBoundaryNode()));
119 for (
unsigned j=0; j<3; j++)
127 std::set<unsigned> shared_elements;
128 std::set_intersection(node_a_element_indices.begin(),
129 node_a_element_indices.end(),
130 node_b_element_indices.begin(),
131 node_b_element_indices.end(),
132 std::inserter(shared_elements, shared_elements.begin()));
143 if (shared_elements.size() == 1)
146 c_vector<double,2> normal_vector;
148 normal_vector[0]= edge[1];
149 normal_vector[1]= -edge[0];
151 double dij = norm_2(normal_vector);
153 normal_vector /= dij;
166 c_vector<double,2> new_node_location = normal_vector + p_node_a->
rGetLocation() + ratio * edge;
169 double node_clearance = 0.01;
173 nodes.push_back(
new Node<2>(new_node_index, new_node_location));
185 bool bad_element =
false;
186 double edge_threshold = 1.5;
188 for (
unsigned j=0; j<3; j++)
201 for (
unsigned j=0; j<3; j++)
207 double edge_length = norm_2(edge);
210 if (edge_length<edge_threshold)
223 c_vector<double,2> normal_vector;
226 normal_vector[0]= edge[1];
227 normal_vector[1]= -edge[0];
229 double dij = norm_2(normal_vector);
231 normal_vector /= dij;
233 double bound_offset = 1.0;
234 c_vector<double,2> new_node_location = -bound_offset*normal_vector + p_node_a->
rGetLocation() + 0.5 * edge;
236 nodes.push_back(
new Node<2>(new_node_index, new_node_location));
244 for (
unsigned i=0; i<nodes.size(); i++)
255 this->
mNodes.reserve(num_nodes);
259 for (
unsigned elem_index = 0; elem_index < num_elements; elem_index++)
269 for (
unsigned i=0; i<
mNodes.size(); i++)
274 for (
unsigned i = 0; i < num_nodes; i++)
278 for (
unsigned local_index = 0; local_index < 3; local_index++)
280 unsigned elem_index = extended_mesh.
GetElement(i)->GetNodeGlobalIndex(local_index);
282 if (elem_index < num_elements)
284 unsigned num_nodes_in_elem =
mElements[elem_index]->GetNumNodes();
285 unsigned end_index = num_nodes_in_elem > 0 ? num_nodes_in_elem - 1 : 0;
294 for (
unsigned elem_index=0; elem_index<
mElements.size(); elem_index++)
301 std::vector<std::pair<double, unsigned> > index_angle_list;
302 for (
unsigned local_index=0; local_index<
mElements[elem_index]->GetNumNodes(); local_index++)
304 c_vector<double, 2> vectorA =
mpDelaunayMesh->GetNode(elem_index)->rGetLocation();
305 c_vector<double, 2> vectorB =
mElements[elem_index]->GetNodeLocation(local_index);
306 c_vector<double, 2> centre_to_vertex =
mpDelaunayMesh->GetVectorFromAtoB(vectorA, vectorB);
308 double angle = atan2(centre_to_vertex(1), centre_to_vertex(0));
309 unsigned global_index =
mElements[elem_index]->GetNodeGlobalIndex(local_index);
311 std::pair<double, unsigned> pair(angle, global_index);
312 index_angle_list.push_back(pair);
316 sort(index_angle_list.begin(), index_angle_list.end());
320 for (
unsigned count = 0; count < index_angle_list.size(); count++)
322 unsigned local_index = count>1 ? count-1 : 0;
323 p_new_element->
AddNode(
mNodes[index_angle_list[count].second], local_index);
437 std::vector<Node<2>*> temp_nodes(3 * num_nodes);
438 std::vector<VertexElement<2, 2>*> elements;
441 for (
unsigned index=0; index<num_nodes; index++)
443 c_vector<double, 2> location;
444 location =
GetNode(index)->rGetLocation();
447 Node<2>* p_node =
new Node<2>(index,
false, location[0], location[1]);
448 temp_nodes[index] = p_node;
451 p_node =
new Node<2>(num_nodes + index,
false, location[0] +
mWidth, location[1]);
452 temp_nodes[num_nodes + index] = p_node;
455 p_node =
new Node<2>(2 * num_nodes + index,
false, location[0] -
mWidth, location[1]);
456 temp_nodes[2*num_nodes + index] = p_node;
464 unsigned elem_index = elem_iter->
GetIndex();
465 unsigned num_nodes_in_elem = elem_iter->GetNumNodes();
467 std::vector<Node<2>*> elem_nodes;
470 bool element_straddles_left_right_boundary =
false;
472 const c_vector<double, 2>& r_this_node_location = elem_iter->GetNode(0)->rGetLocation();
473 for (
unsigned local_index=0; local_index<num_nodes_in_elem; local_index++)
475 const c_vector<double, 2>& r_next_node_location = elem_iter->GetNode((local_index+1)%num_nodes_in_elem)->rGetLocation();
476 c_vector<double, 2> vector;
477 vector = r_next_node_location - r_this_node_location;
479 if (fabs(vector[0]) > 0.5 *
mWidth)
481 element_straddles_left_right_boundary =
true;
488 bool element_centre_on_right =
true;
492 double element_centre_x_location = this->
mpDelaunayMesh->GetNode(delaunay_index)->rGetLocation()[0];
493 if (element_centre_x_location < 0.5 *
mWidth)
495 element_centre_on_right =
false;
500 for (
unsigned local_index=0; local_index<num_nodes_in_elem; local_index++)
502 unsigned this_node_index = elem_iter->GetNodeGlobalIndex(local_index);
505 if (element_straddles_left_right_boundary)
508 bool node_is_right_of_centre = (elem_iter->GetNode(local_index)->rGetLocation()[0] - 0.5 *
mWidth > 0);
509 if (!node_is_right_of_centre && element_centre_on_right)
512 this_node_index += num_nodes;
514 else if (node_is_right_of_centre && !element_centre_on_right)
517 this_node_index += 2 * num_nodes;
521 elem_nodes.push_back(temp_nodes[this_node_index]);
525 elements.push_back(p_element);
529 std::vector<Node<2>*> nodes;
531 for (
unsigned index=0; index<temp_nodes.size(); index++)
533 unsigned num_elems_containing_this_node = temp_nodes[index]->rGetContainingElementIndices().size();
535 if (num_elems_containing_this_node == 0)
538 delete temp_nodes[index];
542 temp_nodes[index]->SetIndex(count);
543 nodes.push_back(temp_nodes[index]);