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));
524 std::stringstream time;
525 time << num_timesteps;
531 unsigned num_nodes = GetNumNodes();
533 cell_writer_iter != this->mCellWriters.end();
537 std::vector<double> vtk_cell_data(num_nodes);
541 iter != mpPottsMesh->GetNodeIteratorEnd();
545 unsigned node_index = iter->GetIndex();
546 std::set<unsigned> element_indices = iter->rGetContainingElementIndices();
549 if (element_indices.empty())
552 vtk_cell_data[node_index] = -1.0;
557 assert(element_indices.size() == 1);
558 unsigned elem_index = *(element_indices.begin());
559 CellPtr p_cell = this->GetCellUsingLocationIndex(elem_index);
562 vtk_cell_data[node_index] = (*cell_writer_iter)->GetCellDataForVtkOutput(p_cell,
this);
566 mesh_writer.
AddPointData((*cell_writer_iter)->GetVtkCellDataName(), vtk_cell_data);
570 unsigned num_cell_data_items = this->Begin()->GetCellData()->GetNumItems();
571 std::vector<std::string> cell_data_names = this->Begin()->GetCellData()->GetKeys();
573 std::vector<std::vector<double> > cell_data;
574 for (
unsigned var=0; var<num_cell_data_items; var++)
576 std::vector<double> cell_data_var(num_nodes);
577 cell_data.push_back(cell_data_var);
581 iter != mpPottsMesh->GetNodeIteratorEnd();
585 unsigned node_index = iter->GetIndex();
586 std::set<unsigned> element_indices = iter->rGetContainingElementIndices();
589 if (element_indices.empty())
591 for (
unsigned var=0; var<num_cell_data_items; var++)
593 cell_data[var][node_index] = -1.0;
599 assert(element_indices.size() == 1);
600 unsigned elem_index = *(element_indices.begin());
601 CellPtr p_cell = this->GetCellUsingLocationIndex(elem_index);
603 for (
unsigned var=0; var<num_cell_data_items; var++)
605 cell_data[var][node_index] = p_cell->GetCellData()->GetItem(cell_data_names[var]);
609 for (
unsigned var=0; var<cell_data.size(); var++)
611 mesh_writer.
AddPointData(cell_data_names[var], cell_data[var]);
623 *(this->mpVtkMetaFile) <<
" <DataSet timestep=\"";
624 *(this->mpVtkMetaFile) << num_timesteps;
625 *(this->mpVtkMetaFile) <<
"\" group=\"\" part=\"0\" file=\"results_";
626 *(this->mpVtkMetaFile) << num_timesteps;
627 *(this->mpVtkMetaFile) <<
".vtu\"/>\n";
632 std::vector<Node<2>*> outline_nodes;
633 std::vector<VertexElement<2,2>*> outline_elements;
635 unsigned outline_node_index = 0;
636 unsigned outline_element_index = 0;
638 iter != mpPottsMesh->GetNodeIteratorEnd();
642 unsigned node_index = iter->GetIndex();
643 std::set<unsigned> element_indices = iter->rGetContainingElementIndices();
645 std::set<unsigned> target_neighbouring_node_indices = this->rGetMesh().GetVonNeumannNeighbouringNodeIndices(node_index);
647 for (std::set<unsigned>::iterator neighbour_iter = target_neighbouring_node_indices.begin();
648 neighbour_iter != target_neighbouring_node_indices.end();
651 std::set<unsigned> neighbouring_element_indices = this->rGetMesh().GetNode(*neighbour_iter)->rGetContainingElementIndices();
654 if (element_indices != neighbouring_element_indices)
656 std::vector<Node<2>*> element_nodes;
658 const c_vector<double, 2>& r_node_location = this->mrMesh.GetNode(node_index)->rGetLocation();
659 const c_vector<double, 2>& r_neighbour_node_location = this->mrMesh.GetNode(*neighbour_iter)->rGetLocation();
661 c_vector<double, 2> unit_tangent = r_neighbour_node_location - r_node_location;
663 if (norm_2(unit_tangent) > 1.0)
665 c_vector<double, 2> mid_point = 0.5*(r_node_location + r_neighbour_node_location);
666 if (unit_tangent(0) == 0)
668 if (r_node_location(1) < r_neighbour_node_location(1))
670 mid_point(1) = r_node_location(1) - 0.5;
674 mid_point(1) = r_node_location(1) + 0.5;
679 assert(unit_tangent(1) == 0);
681 if (r_node_location(0) < r_neighbour_node_location(0))
683 mid_point(0) = r_node_location(0) - 0.5;
687 mid_point(0) = r_node_location(0) + 0.5;
690 assert(norm_2(unit_tangent) > 0);
691 unit_tangent = unit_tangent/norm_2(unit_tangent);
693 c_vector<double, DIM> unit_normal;
694 unit_normal(0) = -unit_tangent(1);
695 unit_normal(1) = unit_tangent(0);
697 std::vector<Node<2>*> element_nodes;
700 Node<2>* p_node_1 =
new Node<2>(outline_node_index, mid_point - 0.5*unit_normal);
701 outline_nodes.push_back(p_node_1);
702 element_nodes.push_back(outline_nodes[outline_node_index]);
703 outline_node_index++;
706 outline_nodes.push_back(p_node_2);
707 element_nodes.push_back(outline_nodes[outline_node_index]);
708 outline_node_index++;
710 Node<2>* p_node_3 =
new Node<2>(outline_node_index, mid_point + 0.5*unit_normal);
711 outline_nodes.push_back(p_node_3);
712 element_nodes.push_back(outline_nodes[outline_node_index]);
713 outline_node_index++;
716 outline_elements.push_back(p_element);
717 outline_element_index++;
722 c_vector<double, 2> mid_point = 0.5*(r_node_location + r_neighbour_node_location);
724 assert(norm_2(unit_tangent) > 0);
725 unit_tangent = unit_tangent/norm_2(unit_tangent);
727 c_vector<double, 2> unit_normal;
728 unit_normal(0) = -unit_tangent(1);
729 unit_normal(1) = unit_tangent(0);
731 std::vector<Node<2>*> element_nodes;
734 Node<2>* p_node_1 =
new Node<2>(outline_node_index, mid_point - 0.5*unit_normal);
735 outline_nodes.push_back(p_node_1);
736 element_nodes.push_back(outline_nodes[outline_node_index]);
737 outline_node_index++;
740 outline_nodes.push_back(p_node_2);
741 element_nodes.push_back(outline_nodes[outline_node_index]);
742 outline_node_index++;
744 Node<2>* p_node_3 =
new Node<2>(outline_node_index, mid_point + 0.5*unit_normal);
745 outline_nodes.push_back(p_node_3);
746 element_nodes.push_back(outline_nodes[outline_node_index]);
747 outline_node_index++;
750 outline_elements.push_back(p_element);
751 outline_element_index++;