256 unsigned num_nodes = this->mrMesh.GetNumNodes();
259 if (this->mIterateRandomlyOverUpdateRuleCollection)
262 p_gen->
Shuffle(this->mUpdateRuleCollection);
265 for (
unsigned i=0; i<num_nodes*mNumSweepsPerTimestep; i++)
269 if (this->mUpdateNodesInRandomOrder)
271 node_index = p_gen->
randMod(num_nodes);
276 node_index = i%num_nodes;
279 Node<DIM>* p_node = this->mrMesh.GetNode(node_index);
285 std::set<unsigned> neighbouring_node_indices = mpPottsMesh->GetMooreNeighbouringNodeIndices(node_index);
286 unsigned neighbour_location_index;
288 if (!neighbouring_node_indices.empty())
290 unsigned num_neighbours = neighbouring_node_indices.size();
291 unsigned chosen_neighbour = p_gen->
randMod(num_neighbours);
293 std::set<unsigned>::iterator neighbour_iter = neighbouring_node_indices.begin();
294 for (
unsigned j=0; j<chosen_neighbour; j++)
299 neighbour_location_index = *neighbour_iter;
302 std::set<unsigned> neighbour_containing_elements = GetNode(neighbour_location_index)->rGetContainingElementIndices();
304 if ((!containing_elements.empty() && neighbour_containing_elements.empty())
305 || (containing_elements.empty() && !neighbour_containing_elements.empty())
306 || (!containing_elements.empty() && !neighbour_containing_elements.empty() && *containing_elements.begin() != *neighbour_containing_elements.begin()))
308 double delta_H = 0.0;
311 for (
typename std::vector<boost::shared_ptr<
AbstractUpdateRule<DIM> > >::iterator iter = this->mUpdateRuleCollection.begin();
312 iter != this->mUpdateRuleCollection.end();
316 double dH = (boost::static_pointer_cast<AbstractPottsUpdateRule<DIM> >(*iter))->EvaluateHamiltonianContribution(neighbour_location_index, p_node->
GetIndex(), *
this);
321 double random_number = p_gen->
ranf();
323 double p = exp(-delta_H/mTemperature);
324 if (delta_H <= 0 || random_number < p)
329 for (std::set<unsigned>::iterator iter = containing_elements.begin();
330 iter != containing_elements.end();
333 GetElement(*iter)->DeleteNode(GetElement(*iter)->GetNodeLocalIndex(node_index));
339 for (std::set<unsigned>::iterator iter = neighbour_containing_elements.begin();
340 iter != neighbour_containing_elements.end();
343 GetElement(*iter)->AddNode(this->mrMesh.GetNode(node_index));
525 std::stringstream time;
526 time << num_timesteps;
532 unsigned num_nodes = GetNumNodes();
534 cell_writer_iter != this->mCellWriters.end();
538 std::vector<double> vtk_cell_data(num_nodes);
542 iter != mpPottsMesh->GetNodeIteratorEnd();
546 unsigned node_index = iter->GetIndex();
547 std::set<unsigned> element_indices = iter->rGetContainingElementIndices();
550 if (element_indices.empty())
553 vtk_cell_data[node_index] = -1.0;
558 assert(element_indices.size() == 1);
559 unsigned elem_index = *(element_indices.begin());
560 CellPtr p_cell = this->GetCellUsingLocationIndex(elem_index);
563 vtk_cell_data[node_index] = (*cell_writer_iter)->GetCellDataForVtkOutput(p_cell,
this);
567 mesh_writer.
AddPointData((*cell_writer_iter)->GetVtkCellDataName(), vtk_cell_data);
571 unsigned num_cell_data_items = this->Begin()->GetCellData()->GetNumItems();
572 std::vector<std::string> cell_data_names = this->Begin()->GetCellData()->GetKeys();
574 std::vector<std::vector<double> > cell_data;
575 for (
unsigned var=0; var<num_cell_data_items; var++)
577 std::vector<double> cell_data_var(num_nodes);
578 cell_data.push_back(cell_data_var);
582 iter != mpPottsMesh->GetNodeIteratorEnd();
586 unsigned node_index = iter->GetIndex();
587 std::set<unsigned> element_indices = iter->rGetContainingElementIndices();
590 if (element_indices.empty())
592 for (
unsigned var=0; var<num_cell_data_items; var++)
594 cell_data[var][node_index] = -1.0;
600 assert(element_indices.size() == 1);
601 unsigned elem_index = *(element_indices.begin());
602 CellPtr p_cell = this->GetCellUsingLocationIndex(elem_index);
604 for (
unsigned var=0; var<num_cell_data_items; var++)
606 cell_data[var][node_index] = p_cell->GetCellData()->GetItem(cell_data_names[var]);
610 for (
unsigned var=0; var<cell_data.size(); var++)
612 mesh_writer.
AddPointData(cell_data_names[var], cell_data[var]);
624 *(this->mpVtkMetaFile) <<
" <DataSet timestep=\"";
625 *(this->mpVtkMetaFile) << num_timesteps;
626 *(this->mpVtkMetaFile) <<
"\" group=\"\" part=\"0\" file=\"results_";
627 *(this->mpVtkMetaFile) << num_timesteps;
628 *(this->mpVtkMetaFile) <<
".vtu\"/>\n";
633 std::vector<Node<2>*> outline_nodes;
634 std::vector<VertexElement<2,2>*> outline_elements;
636 unsigned outline_node_index = 0;
637 unsigned outline_element_index = 0;
639 iter != mpPottsMesh->GetNodeIteratorEnd();
643 unsigned node_index = iter->GetIndex();
644 std::set<unsigned> element_indices = iter->rGetContainingElementIndices();
646 std::set<unsigned> target_neighbouring_node_indices = this->rGetMesh().GetVonNeumannNeighbouringNodeIndices(node_index);
648 for (std::set<unsigned>::iterator neighbour_iter = target_neighbouring_node_indices.begin();
649 neighbour_iter != target_neighbouring_node_indices.end();
652 std::set<unsigned> neighbouring_element_indices = this->rGetMesh().GetNode(*neighbour_iter)->rGetContainingElementIndices();
655 if (element_indices != neighbouring_element_indices)
657 std::vector<Node<2>*> element_nodes;
659 const c_vector<double, 2>& r_node_location = this->mrMesh.GetNode(node_index)->rGetLocation();
660 const c_vector<double, 2>& r_neighbour_node_location = this->mrMesh.GetNode(*neighbour_iter)->rGetLocation();
662 c_vector<double, 2> unit_tangent = r_neighbour_node_location - r_node_location;
664 if (norm_2(unit_tangent) > 1.0)
666 c_vector<double, 2> mid_point = 0.5*(r_node_location + r_neighbour_node_location);
667 if (unit_tangent(0) == 0)
669 if (r_node_location(1) < r_neighbour_node_location(1))
671 mid_point(1) = r_node_location(1) - 0.5;
675 mid_point(1) = r_node_location(1) + 0.5;
680 assert(unit_tangent(1) == 0);
682 if (r_node_location(0) < r_neighbour_node_location(0))
684 mid_point(0) = r_node_location(0) - 0.5;
688 mid_point(0) = r_node_location(0) + 0.5;
691 assert(norm_2(unit_tangent) > 0);
692 unit_tangent = unit_tangent/norm_2(unit_tangent);
694 c_vector<double, DIM> unit_normal;
695 unit_normal(0) = -unit_tangent(1);
696 unit_normal(1) = unit_tangent(0);
698 std::vector<Node<2>*> element_nodes;
701 Node<2>* p_node_1 =
new Node<2>(outline_node_index, mid_point - 0.5*unit_normal);
702 outline_nodes.push_back(p_node_1);
703 element_nodes.push_back(outline_nodes[outline_node_index]);
704 outline_node_index++;
707 outline_nodes.push_back(p_node_2);
708 element_nodes.push_back(outline_nodes[outline_node_index]);
709 outline_node_index++;
711 Node<2>* p_node_3 =
new Node<2>(outline_node_index, mid_point + 0.5*unit_normal);
712 outline_nodes.push_back(p_node_3);
713 element_nodes.push_back(outline_nodes[outline_node_index]);
714 outline_node_index++;
717 outline_elements.push_back(p_element);
718 outline_element_index++;
723 c_vector<double, 2> mid_point = 0.5*(r_node_location + r_neighbour_node_location);
725 assert(norm_2(unit_tangent) > 0);
726 unit_tangent = unit_tangent/norm_2(unit_tangent);
728 c_vector<double, 2> unit_normal;
729 unit_normal(0) = -unit_tangent(1);
730 unit_normal(1) = unit_tangent(0);
732 std::vector<Node<2>*> element_nodes;
735 Node<2>* p_node_1 =
new Node<2>(outline_node_index, mid_point - 0.5*unit_normal);
736 outline_nodes.push_back(p_node_1);
737 element_nodes.push_back(outline_nodes[outline_node_index]);
738 outline_node_index++;
741 outline_nodes.push_back(p_node_2);
742 element_nodes.push_back(outline_nodes[outline_node_index]);
743 outline_node_index++;
745 Node<2>* p_node_3 =
new Node<2>(outline_node_index, mid_point + 0.5*unit_normal);
746 outline_nodes.push_back(p_node_3);
747 element_nodes.push_back(outline_nodes[outline_node_index]);
748 outline_node_index++;
751 outline_elements.push_back(p_element);
752 outline_element_index++;