55 : mWidth(rMesh.GetWidth(0)),
56 mHeight(rMesh.GetWidth(1)),
70 this->
mNodes.reserve(num_nodes);
75 for (
unsigned elem_index=0; elem_index<num_elements; elem_index++)
85 for (
unsigned i=0; i<num_nodes; i++)
91 for (
unsigned i=0; i<num_nodes; i++)
95 for (
unsigned local_index=0; local_index<3; local_index++)
97 unsigned elem_index =
mpDelaunayMesh->GetElement(i)->GetNodeGlobalIndex(local_index);
98 unsigned num_nodes_in_elem =
mElements[elem_index]->GetNumNodes();
99 unsigned end_index = num_nodes_in_elem>0 ? num_nodes_in_elem-1 : 0;
108 std::vector<Node<2> *> nodes;
113 nodes.push_back(
new Node<2>(node_iter->GetIndex(), node_iter->rGetLocation(),node_iter->IsBoundaryNode()));
122 bool bad_element =
false;
123 double edge_threshold = 1.5;
125 for (
unsigned j=0; j<3; j++)
138 for (
unsigned j=0; j<3; j++)
144 double edge_length = norm_2(edge);
147 if (edge_length<edge_threshold)
150 c_vector<double,2> normal_vector;
153 normal_vector[0]= edge[1];
154 normal_vector[1]= -edge[0];
156 double dij = norm_2(normal_vector);
158 normal_vector /= dij;
160 double bound_offset = 0.5;
161 c_vector<double,2> new_node_location = -bound_offset*normal_vector + p_node_a->
rGetLocation() + 0.5*edge;
163 nodes.push_back(
new Node<2>(new_node_index, new_node_location));
167 unsigned num_sections = 1;
168 for (
unsigned section=0; section <= num_sections; section++)
170 double ratio = (
double)section/(
double)num_sections;
171 c_vector<double,2> new_node_location = -normal_vector + ratio*p_node_a->
rGetLocation() + (1-ratio)*p_node_b->
rGetLocation();
174 double node_clearance = 0.3;
178 nodes.push_back(
new Node<2>(new_node_index, new_node_location));
188 for (
unsigned i=0; i<nodes.size(); i++)
199 this->
mNodes.reserve(num_nodes);
203 for (
unsigned elem_index = 0; elem_index < num_elements; elem_index++)
213 for (
unsigned i=0; i<num_nodes; i++)
220 for (
unsigned i = 0; i < num_nodes; i++)
224 for (
unsigned local_index = 0; local_index < 3; local_index++)
226 unsigned elem_index = extended_mesh.
GetElement(i)->GetNodeGlobalIndex(local_index);
228 if (elem_index < num_elements)
230 unsigned num_nodes_in_elem =
mElements[elem_index]->GetNumNodes();
231 unsigned end_index = num_nodes_in_elem > 0 ? num_nodes_in_elem - 1 : 0;
240 for (
unsigned elem_index=0; elem_index<
mElements.size(); elem_index++)
247 std::vector<std::pair<double, unsigned> > index_angle_list;
248 for (
unsigned local_index=0; local_index<
mElements[elem_index]->GetNumNodes(); local_index++)
250 c_vector<double, 2> vectorA =
mpDelaunayMesh->GetNode(elem_index)->rGetLocation();
251 c_vector<double, 2> vectorB =
mElements[elem_index]->GetNodeLocation(local_index);
252 c_vector<double, 2> centre_to_vertex =
mpDelaunayMesh->GetVectorFromAtoB(vectorA, vectorB);
254 double angle = atan2(centre_to_vertex(1), centre_to_vertex(0));
255 unsigned global_index =
mElements[elem_index]->GetNodeGlobalIndex(local_index);
257 std::pair<double, unsigned> pair(angle, global_index);
258 index_angle_list.push_back(pair);
262 sort(index_angle_list.begin(), index_angle_list.end());
266 for (
unsigned count = 0; count < index_angle_list.size(); count++)
268 unsigned local_index = count>1 ? count-1 : 0;
269 p_new_element->
AddNode(
mNodes[index_angle_list[count].second], local_index);
416 std::vector<Node<2>*> temp_nodes;
417 std::vector<VertexElement<2, 2>*> elements;
421 temp_nodes.resize(4 * num_nodes);
424 for (
unsigned index = 0; index < num_nodes; index++)
426 c_vector<double, 2> location;
427 location =
GetNode(index)->rGetLocation();
430 Node<2>* p_node =
new Node<2>(index,
false, location[0], location[1]);
431 temp_nodes[index] = p_node;
434 p_node =
new Node<2>(num_nodes + index,
false, location[0] +
mWidth, location[1]);
435 temp_nodes[num_nodes + index] = p_node;
438 p_node =
new Node<2>(2*num_nodes + index,
false, location[0], location[1] +
mHeight);
439 temp_nodes[2*num_nodes + index] = p_node;
443 temp_nodes[3*num_nodes + index] = p_node;
451 unsigned elem_index = elem_iter->
GetIndex();
452 unsigned num_nodes_in_elem = elem_iter->GetNumNodes();
454 std::vector<Node<2>*> elem_nodes;
457 bool element_straddles_left_right_boundary =
false;
458 bool element_straddles_top_bottom_boundary =
false;
460 const c_vector<double, 2>& r_this_node_location = elem_iter->GetNode(0)->rGetLocation();
461 for (
unsigned local_index=0; local_index<num_nodes_in_elem; local_index++)
463 const c_vector<double, 2>& r_next_node_location = elem_iter->GetNode((local_index+1)%num_nodes_in_elem)->rGetLocation();
464 c_vector<double, 2> vector;
465 vector = r_next_node_location - r_this_node_location;
467 if (fabs(vector[0]) > 0.5*
mWidth)
469 element_straddles_left_right_boundary =
true;
471 if (fabs(vector[1]) > 0.5*
mHeight)
473 element_straddles_top_bottom_boundary =
true;
478 for (
unsigned local_index=0; local_index<num_nodes_in_elem; local_index++)
480 unsigned this_node_index = elem_iter->GetNodeGlobalIndex(local_index);
483 if (element_straddles_left_right_boundary)
486 bool node_is_right_of_centre = (elem_iter->GetNode(local_index)->rGetLocation()[0] - 0.5*
mWidth > 0);
487 if (!node_is_right_of_centre)
490 this_node_index += num_nodes;
495 if (element_straddles_top_bottom_boundary)
498 bool node_is_above_centre = (elem_iter->GetNode(local_index)->rGetLocation()[1] - 0.5*
mHeight > 0);
499 if (!node_is_above_centre)
502 this_node_index += 2*num_nodes;
506 elem_nodes.push_back(temp_nodes[this_node_index]);
510 elements.push_back(p_element);
515 temp_nodes.resize(9*num_nodes);
518 for (
unsigned index=0; index<num_nodes; index++)
520 c_vector<double, 2> location;
521 location =
GetNode(index)->rGetLocation();
524 Node<2>* p_node =
new Node<2>(index,
false, location[0], location[1]);
525 temp_nodes[index] = p_node;
528 p_node =
new Node<2>(num_nodes + index,
false, location[0] +
mWidth, location[1]);
529 temp_nodes[num_nodes + index] = p_node;
533 temp_nodes[2*num_nodes + index] = p_node;
536 p_node =
new Node<2>(3*num_nodes + index,
false, location[0], location[1] +
mHeight);
537 temp_nodes[3*num_nodes + index] = p_node;
541 temp_nodes[4*num_nodes + index] = p_node;
544 p_node =
new Node<2>(5*num_nodes + index,
false, location[0] -
mWidth, location[1]);
545 temp_nodes[5*num_nodes + index] = p_node;
549 temp_nodes[6*num_nodes + index] = p_node;
552 p_node =
new Node<2>(7*num_nodes + index,
false, location[0], location[1] -
mHeight);
553 temp_nodes[7*num_nodes + index] = p_node;
557 temp_nodes[8*num_nodes + index] = p_node;
565 unsigned elem_index = elem_iter->
GetIndex();
566 unsigned num_nodes_in_elem = elem_iter->GetNumNodes();
568 std::vector<Node<2>*> elem_nodes;
571 bool element_straddles_left_right_boundary =
false;
572 bool element_straddles_top_bottom_boundary =
false;
574 const c_vector<double, 2>& r_this_node_location = elem_iter->GetNode(0)->rGetLocation();
575 for (
unsigned local_index=0; local_index<num_nodes_in_elem; local_index++)
577 const c_vector<double, 2>& r_next_node_location = elem_iter->GetNode((local_index+1)%num_nodes_in_elem)->rGetLocation();
578 c_vector<double, 2> vector;
579 vector = r_next_node_location - r_this_node_location;
581 if (fabs(vector[0]) > 0.5*
mWidth)
583 element_straddles_left_right_boundary =
true;
585 if (fabs(vector[1]) > 0.5*
mHeight)
587 element_straddles_top_bottom_boundary =
true;
593 bool element_centre_on_right =
true;
594 bool element_centre_on_top =
true;
597 double element_centre_x_location = this->
mpDelaunayMesh->GetNode(delaunay_index)->rGetLocation()[0];
598 double element_centre_y_location = this->
mpDelaunayMesh->GetNode(delaunay_index)->rGetLocation()[1];
600 if (element_centre_x_location < 0.5*
mWidth)
602 element_centre_on_right =
false;
604 if (element_centre_y_location < 0.5*
mHeight)
606 element_centre_on_top =
false;
610 for (
unsigned local_index=0; local_index<num_nodes_in_elem; local_index++)
612 unsigned this_node_index = elem_iter->GetNodeGlobalIndex(local_index);
615 if (element_straddles_left_right_boundary && !element_straddles_top_bottom_boundary)
618 bool node_is_right_of_centre = (elem_iter->GetNode(local_index)->rGetLocation()[0] - 0.5*
mWidth > 0);
619 if (!node_is_right_of_centre && element_centre_on_right)
622 this_node_index += num_nodes;
624 else if (node_is_right_of_centre && !element_centre_on_right)
627 this_node_index += 5*num_nodes;
630 else if (!element_straddles_left_right_boundary && element_straddles_top_bottom_boundary)
633 bool node_is_top_of_centre = (elem_iter->GetNode(local_index)->rGetLocation()[1] - 0.5*
mHeight > 0);
634 if (!node_is_top_of_centre && element_centre_on_top)
637 this_node_index += 3*num_nodes;
639 else if (node_is_top_of_centre && !element_centre_on_top)
642 this_node_index += 7*num_nodes;
645 else if (element_straddles_left_right_boundary && element_straddles_top_bottom_boundary)
647 bool node_is_right_of_centre = (elem_iter->GetNode(local_index)->rGetLocation()[0] - 0.5*
mWidth > 0);
648 bool node_is_top_of_centre = (elem_iter->GetNode(local_index)->rGetLocation()[1] - 0.5*
mHeight > 0);
650 if (!node_is_top_of_centre && element_centre_on_top)
652 if (!node_is_right_of_centre && element_centre_on_right)
654 this_node_index += 2*num_nodes;
656 else if (node_is_right_of_centre && !element_centre_on_right)
658 this_node_index += 4*num_nodes;
662 this_node_index += 3*num_nodes;
665 else if (node_is_top_of_centre && !element_centre_on_top)
667 if (!node_is_right_of_centre && element_centre_on_right)
669 this_node_index += 8*num_nodes;
671 else if (node_is_right_of_centre && !element_centre_on_right)
673 this_node_index += 6*num_nodes;
677 this_node_index += 7*num_nodes;
682 if (!node_is_right_of_centre && element_centre_on_right)
684 this_node_index += num_nodes;
686 else if (node_is_right_of_centre && !element_centre_on_right)
688 this_node_index += 5*num_nodes;
705 elem_nodes.push_back(temp_nodes[this_node_index]);
709 elements.push_back(p_element);
714 std::vector<Node<2>*> nodes;
716 for (
unsigned index=0; index<temp_nodes.size(); index++)
718 unsigned num_elems_containing_this_node = temp_nodes[index]->rGetContainingElementIndices().size();
720 if (num_elems_containing_this_node == 0)
723 delete temp_nodes[index];
727 temp_nodes[index]->SetIndex(count);
728 nodes.push_back(temp_nodes[index]);