493 unsigned num_cells = this->GetNumAllCells();
498 for (
auto cell_writer_iter = this->mCellWriters.begin();
499 cell_writer_iter != this->mCellWriters.end();
503 std::vector<double> vtk_cell_data(num_cells);
506 for (
auto elem_iter = mpMutableVertexMesh->GetElementIteratorBegin();
507 elem_iter != mpMutableVertexMesh->GetElementIteratorEnd();
511 unsigned elem_index = elem_iter->GetIndex();
514 CellPtr p_cell = this->GetCellUsingLocationIndex(elem_index);
518 vtk_cell_data[elem_index] = (*cell_writer_iter)->GetCellDataForVtkOutput(p_cell,
this);
521 mesh_writer.
AddCellData((*cell_writer_iter)->GetVtkCellDataName(), vtk_cell_data);
525 unsigned num_cell_data_items = this->Begin()->GetCellData()->GetNumItems();
526 std::vector<std::string> cell_data_names = this->Begin()->GetCellData()->GetKeys();
528 std::vector<std::vector<double> > cell_data;
529 for (
unsigned var=0; var<num_cell_data_items; var++)
531 std::vector<double> cell_data_var(num_cells);
532 cell_data.push_back(cell_data_var);
536 for (
auto elem_iter = mpMutableVertexMesh->GetElementIteratorBegin();
537 elem_iter != mpMutableVertexMesh->GetElementIteratorEnd();
541 unsigned elem_index = elem_iter->GetIndex();
544 CellPtr p_cell = this->GetCellUsingLocationIndex(elem_index);
547 for (
unsigned var=0; var<num_cell_data_items; var++)
549 cell_data[var][elem_index] = p_cell->GetCellData()->GetItem(cell_data_names[var]);
552 for (
unsigned var=0; var<num_cell_data_items; var++)
554 mesh_writer.
AddCellData(cell_data_names[var], cell_data[var]);
559 std::stringstream time;
560 time << num_timesteps;
564 *(this->mpVtkMetaFile) <<
" <DataSet timestep=\"";
565 *(this->mpVtkMetaFile) << num_timesteps;
566 *(this->mpVtkMetaFile) <<
"\" group=\"\" part=\"0\" file=\"results_";
567 *(this->mpVtkMetaFile) << num_timesteps;
568 *(this->mpVtkMetaFile) <<
".vtu\"/>\n";
583 unsigned num_cells = this->GetNumAllCells();
585 cell_writer_iter != this->mCellWriters.end();
589 std::vector<double> vtk_cell_data(num_cells);
593 elem_iter != mpMutableVertexMesh->GetElementIteratorEnd();
597 unsigned elem_index = elem_iter->GetIndex();
600 CellPtr p_cell = this->GetCellUsingLocationIndex(elem_index);
604 vtk_cell_data[elem_index] = (*cell_writer_iter)->GetCellDataForVtkOutput(p_cell,
this);
607 mesh_writer.
AddCellData((*cell_writer_iter)->GetVtkCellDataName(), vtk_cell_data);
611 unsigned num_cell_data_items = this->Begin()->GetCellData()->GetNumItems();
612 std::vector<std::string> cell_data_names = this->Begin()->GetCellData()->GetKeys();
614 std::vector<std::vector<double> > cell_data;
615 for (
unsigned var=0; var<num_cell_data_items; var++)
617 std::vector<double> cell_data_var(num_cells);
618 cell_data.push_back(cell_data_var);
623 elem_iter != mpMutableVertexMesh->GetElementIteratorEnd();
627 unsigned elem_index = elem_iter->GetIndex();
630 CellPtr p_cell = this->GetCellUsingLocationIndex(elem_index);
633 for (
unsigned var=0; var<num_cell_data_items; var++)
635 cell_data[var][elem_index] = p_cell->GetCellData()->GetItem(cell_data_names[var]);
638 for (
unsigned var=0; var<num_cell_data_items; var++)
640 mesh_writer.
AddCellData(cell_data_names[var], cell_data[var]);
644 std::stringstream time;
645 time << num_timesteps;
649 *(this->mpVtkMetaFile) <<
" <DataSet timestep=\"";
650 *(this->mpVtkMetaFile) << num_timesteps;
651 *(this->mpVtkMetaFile) <<
"\" group=\"\" part=\"0\" file=\"cell_results_";
652 *(this->mpVtkMetaFile) << num_timesteps;
653 *(this->mpVtkMetaFile) <<
".vtu\"/>\n";
657 unsigned num_edges = 0;
660 const unsigned num_cells = this->GetNumElements();
664 std::vector<unsigned> cell_offset_dist(num_cells);
669 for (
unsigned i=1; i<num_cells; ++i)
671 cell_offset_dist[i] = cell_offset_dist[i-1]+this->GetElement(i-1)->GetNumEdges()+1;
672 num_edges += this->GetElement(i)->GetNumEdges();
675 num_edges += this->GetElement(0)->GetNumEdges();
680 for (
auto cell_writer : this->mCellWriters)
683 std::vector<double> vtk_cell_data(num_edges+num_cells);
686 for (
auto elem_iter = mpMutableVertexMesh->GetElementIteratorBegin();
687 elem_iter != mpMutableVertexMesh->GetElementIteratorEnd();
691 unsigned elem_index = elem_iter->GetIndex();
694 CellPtr p_cell = this->GetCellUsingLocationIndex(elem_index);
698 unsigned elem_num_edges = elem_iter->GetNumEdges();
701 for (
unsigned e = 0; e < elem_num_edges; ++e)
704 vtk_cell_data[cell_offset_dist[elem_index]+e] = cell_writer->GetCellDataForVtkOutput(p_cell,
this);
707 vtk_cell_data[cell_offset_dist[elem_index]+elem_num_edges] = cell_writer->GetCellDataForVtkOutput(p_cell,
this);
709 mesh_writer.
AddCellData(cell_writer->GetVtkCellDataName(), vtk_cell_data);
715 const unsigned num_cell_data_items = this->Begin()->GetCellData()->GetNumItems();
716 std::vector<std::string> cell_data_names = this->Begin()->GetCellData()->GetKeys();
718 const unsigned num_edge_data_items = this->Begin()->GetCellEdgeData()->GetNumItems();
719 std::vector<std::string> edge_data_names = this->Begin()->GetCellEdgeData()->GetKeys();
722 const unsigned num_data_items = num_edge_data_items + num_cell_data_items;
723 std::vector<std::string> data_names(num_data_items);
724 for (
unsigned var=0; var<num_edge_data_items; ++var)
726 data_names[var] = edge_data_names[var];
728 for (
unsigned var=num_edge_data_items; var<num_data_items; ++var)
730 data_names[var] = cell_data_names[var-num_edge_data_items];
732 std::vector<std::vector<double> > data_values(num_data_items,
733 std::vector<double>(num_edges + num_cells));
737 for (
auto elem_iter = mpMutableVertexMesh->GetElementIteratorBegin();
738 elem_iter != mpMutableVertexMesh->GetElementIteratorEnd();
741 const unsigned elem_index = elem_iter->GetIndex();
742 CellPtr p_cell = this->GetCellUsingLocationIndex(elem_index);
746 unsigned elem_num_edges = elem_iter->GetNumEdges();
747 for (
unsigned var = 0; var < num_edge_data_items; ++var)
750 for (
unsigned e = 0; e < elem_num_edges; ++e)
752 data_values[var][cell_offset_dist[elem_index]+e] = p_cell->GetCellEdgeData()->GetItem(data_names[var])[e];
755 data_values[var][cell_offset_dist[elem_index]+elem_num_edges] = 0.0;
761 for (
auto elem_iter = mpMutableVertexMesh->GetElementIteratorBegin();
762 elem_iter != mpMutableVertexMesh->GetElementIteratorEnd();
766 unsigned elem_index = elem_iter->GetIndex();
767 unsigned elem_num_edges = elem_iter->GetNumEdges();
770 CellPtr p_cell = this->GetCellUsingLocationIndex(elem_index);
773 for (
unsigned var = num_edge_data_items; var<num_data_items; ++var)
776 for (
unsigned e = 0; e < elem_num_edges; ++e)
778 data_values[var][cell_offset_dist[elem_index]+e] = 0.0;
781 data_values[var][cell_offset_dist[elem_index]+elem_num_edges] = p_cell->GetCellData()->GetItem(data_names[var]);
785 for (
unsigned var=0; var<num_data_items; var++)
787 mesh_writer.
AddCellData(data_names[var], data_values[var]);
791 std::stringstream time;
792 time << num_timesteps;
796 *(this->mpVtkMetaFile) <<
" <DataSet timestep=\"";
797 *(this->mpVtkMetaFile) << num_timesteps;
798 *(this->mpVtkMetaFile) <<
"\" group=\"\" part=\"0\" file=\"results_";
799 *(this->mpVtkMetaFile) << num_timesteps;
800 *(this->mpVtkMetaFile) <<
".vtu\"/>\n";
900 EXCEPTION(
"This function is only valid in 2D");
904 unsigned num_vertex_nodes = mpMutableVertexMesh->GetNumNodes();
905 unsigned num_vertex_elements = mpMutableVertexMesh->GetNumElements();
907 std::string mesh_file_name =
"mesh";
910 std::stringstream pid;
912 OutputFileHandler output_file_handler(
"2D_temporary_tetrahedral_mesh_" + pid.str());
916 unsigned num_tetrahedral_nodes = num_vertex_nodes + num_vertex_elements;
919 out_stream p_node_file = output_file_handler.
OpenOutputFile(mesh_file_name+
".node");
920 (*p_node_file) << std::scientific;
921 (*p_node_file) << std::setprecision(20);
922 (*p_node_file) << num_tetrahedral_nodes <<
"\t2\t0\t1" << std::endl;
925 for (
unsigned node_index=0; node_index<num_vertex_nodes; node_index++)
927 Node<DIM>* p_node = mpMutableVertexMesh->GetNode(node_index);
930 unsigned index = p_node->
GetIndex();
931 const c_vector<double, DIM>& r_location = p_node->
rGetLocation();
934 (*p_node_file) << index <<
"\t" << r_location[0] <<
"\t" << r_location[1] <<
"\t" << is_boundary_node << std::endl;
938 unsigned num_tetrahedral_elements = 0;
939 for (
unsigned vertex_elem_index=0; vertex_elem_index<num_vertex_elements; vertex_elem_index++)
941 unsigned index = num_vertex_nodes + vertex_elem_index;
943 c_vector<double, DIM> location = mpMutableVertexMesh->GetCentroidOfElement(vertex_elem_index);
946 unsigned is_boundary_node = 0;
947 (*p_node_file) << index <<
"\t" << location[0] <<
"\t" << location[1] <<
"\t" << is_boundary_node << std::endl;
950 num_tetrahedral_elements += mpMutableVertexMesh->GetElement(vertex_elem_index)->GetNumNodes();
952 p_node_file->close();
955 out_stream p_elem_file = output_file_handler.
OpenOutputFile(mesh_file_name+
".ele");
956 (*p_elem_file) << std::scientific;
957 (*p_elem_file) << num_tetrahedral_elements <<
"\t3\t0" << std::endl;
959 std::set<std::pair<unsigned, unsigned> > tetrahedral_edges;
961 unsigned tetrahedral_elem_index = 0;
962 for (
unsigned vertex_elem_index=0; vertex_elem_index<num_vertex_elements; vertex_elem_index++)
967 unsigned num_nodes_in_vertex_element = p_vertex_element->
GetNumNodes();
968 for (
unsigned local_index=0; local_index<num_nodes_in_vertex_element; local_index++)
971 unsigned node_1_index = p_vertex_element->
GetNodeGlobalIndex((local_index+1)%num_nodes_in_vertex_element);
972 unsigned node_2_index = num_vertex_nodes + vertex_elem_index;
974 (*p_elem_file) << tetrahedral_elem_index++ <<
"\t" << node_0_index <<
"\t" << node_1_index <<
"\t" << node_2_index << std::endl;
977 std::pair<unsigned, unsigned> edge_0 = this->CreateOrderedPair(node_0_index, node_1_index);
978 std::pair<unsigned, unsigned> edge_1 = this->CreateOrderedPair(node_1_index, node_2_index);
979 std::pair<unsigned, unsigned> edge_2 = this->CreateOrderedPair(node_2_index, node_0_index);
981 tetrahedral_edges.insert(edge_0);
982 tetrahedral_edges.insert(edge_1);
983 tetrahedral_edges.insert(edge_2);
986 p_elem_file->close();
989 out_stream p_edge_file = output_file_handler.
OpenOutputFile(mesh_file_name+
".edge");
990 (*p_edge_file) << std::scientific;
991 (*p_edge_file) << tetrahedral_edges.size() <<
"\t1" << std::endl;
993 unsigned edge_index = 0;
994 for (std::set<std::pair<unsigned, unsigned> >::iterator edge_iter = tetrahedral_edges.begin();
995 edge_iter != tetrahedral_edges.end();
998 std::pair<unsigned, unsigned> this_edge = *edge_iter;
1001 bool is_boundary_edge =
false;
1002 if (this_edge.first < mpMutableVertexMesh->GetNumNodes() &&
1003 this_edge.second < mpMutableVertexMesh->GetNumNodes())
1005 is_boundary_edge = (mpMutableVertexMesh->GetNode(this_edge.first)->IsBoundaryNode() &&
1006 mpMutableVertexMesh->GetNode(this_edge.second)->IsBoundaryNode() );
1008 unsigned is_boundary_edge_unsigned = is_boundary_edge ? 1 : 0;
1010 (*p_edge_file) << edge_index++ <<
"\t" << this_edge.first <<
"\t" << this_edge.second <<
"\t" << is_boundary_edge_unsigned << std::endl;
1012 p_edge_file->close();
1097 unsigned pdeNodeIndex,
1098 std::string& rVariableName,
1099 bool dirichletBoundaryConditionApplies,
1100 double dirichletBoundaryValue)
1102 unsigned num_nodes = this->GetNumNodes();
1107 if (pdeNodeIndex >= num_nodes)
1110 assert(pdeNodeIndex-num_nodes < num_nodes);
1112 CellPtr p_cell = this->GetCellUsingLocationIndex(pdeNodeIndex - num_nodes);
1113 value = p_cell->GetCellData()->GetItem(rVariableName);
1118 if (dirichletBoundaryConditionApplies)
1121 value = dirichletBoundaryValue;
1125 assert(pdeNodeIndex < num_nodes);
1126 Node<DIM>* p_node = this->GetNode(pdeNodeIndex);
1130 for (std::set<unsigned>::iterator index_iter = containing_elements.begin();
1131 index_iter != containing_elements.end();
1134 assert(*index_iter < num_nodes);
1135 CellPtr p_cell = this->GetCellUsingLocationIndex(*index_iter);
1136 value += p_cell->GetCellData()->GetItem(rVariableName);
1138 value /= containing_elements.size();