299 if constexpr (SPACE_DIM == 2)
301 FindElementOverlaps(rMesh);
304 vtkPoints* p_pts = vtkPoints::New(VTK_DOUBLE);
305 p_pts->GetData()->SetName(
"Vertex positions");
308 unsigned num_pts_added = 0;
313 unsigned elem_idx = iter->GetIndex();
314 unsigned num_nodes = iter->GetNumNodes();
317 if (mElementParts.size() == 0 || mElementParts[elem_idx].empty())
319 vtkCell* p_cell = vtkPolygon::New();
320 vtkIdList* p_cell_id_list = p_cell->GetPointIds();
321 p_cell_id_list->SetNumberOfIds(num_nodes);
323 for (
unsigned node_local_idx = 0; node_local_idx < num_nodes; ++node_local_idx)
326 unsigned global_idx = iter->GetNode(node_local_idx)->GetIndex();
327 const auto& r_location = iter->GetNode(node_local_idx)->rGetLocation();
329 p_pts->InsertPoint(global_idx, r_location[0], r_location[1], 0.0);
330 p_cell_id_list->SetId(node_local_idx, global_idx);
333 mpVtkUnstructedMesh->InsertNextCell(p_cell->GetCellType(), p_cell_id_list);
339 const std::vector<unsigned>& start_idx_each_part = mElementParts[iter->GetIndex()];
342 const auto num_parts = start_idx_each_part.size();
344 for (
unsigned part = 0; part < num_parts; ++part)
346 const long this_start = start_idx_each_part[part];
347 const long next_start = start_idx_each_part[AdvanceMod(part, 1, num_parts)];
349 const long num_nodes_this_part = next_start > this_start ? next_start - this_start : num_nodes + next_start - this_start;
352 std::vector<c_vector<double, SPACE_DIM>> extra_locations;
356 const auto& r_start_pos = iter->GetNode(this_start)->rGetLocation();
357 const auto& r_end_pos = iter->GetNode(AdvanceMod(this_start, -1, num_nodes))->rGetLocation();
359 const c_vector<double, SPACE_DIM> vec_a2b = rMesh.
GetVectorFromAtoB(r_start_pos, r_end_pos);
360 extra_locations.emplace_back(GetIntersectionOfEdgeWithBoundary(r_start_pos, r_start_pos + vec_a2b));
365 const auto& r_start_pos = iter->GetNode(AdvanceMod(next_start, -1, num_nodes))->rGetLocation();
366 const auto& r_end_pos = iter->GetNode(next_start)->rGetLocation();
368 const c_vector<double, SPACE_DIM> vec_a2b = rMesh.
GetVectorFromAtoB(r_start_pos, r_end_pos);
369 extra_locations.emplace_back(GetIntersectionOfEdgeWithBoundary(r_start_pos, r_start_pos + vec_a2b));
373 if (std::fabs(extra_locations.front()[0] - extra_locations.back()[0]) > DBL_EPSILON &&
374 std::fabs(extra_locations.front()[1] - extra_locations.back()[1]) > DBL_EPSILON)
376 extra_locations.emplace_back(GetNearestCorner(extra_locations.front(), extra_locations.back()));
379 vtkCell* p_cell = vtkPolygon::New();
380 vtkIdList* p_cell_id_list = p_cell->GetPointIds();
381 p_cell_id_list->SetNumberOfIds(num_nodes_this_part + extra_locations.size());
383 for (
long idx = 0; idx < num_nodes_this_part; ++idx)
385 unsigned node_idx = AdvanceMod(idx, this_start, num_nodes);
388 unsigned global_idx = iter->GetNode(node_idx)->GetIndex();
389 const auto& r_location = iter->GetNode(node_idx)->rGetLocation();
391 p_pts->InsertPoint(global_idx, r_location[0], r_location[1], 0.0);
392 p_cell_id_list->SetId(idx, global_idx);
396 if (extra_locations.size() == 2)
398 const unsigned global_index = rMesh.
GetNumNodes() + num_pts_added;
400 p_pts->InsertPoint(global_index, extra_locations[1][0], extra_locations[1][1], 0.0);
401 p_pts->InsertPoint(global_index + 1, extra_locations[0][0], extra_locations[0][1], 0.0);
403 p_cell_id_list->SetId(num_nodes_this_part, global_index);
404 p_cell_id_list->SetId(num_nodes_this_part + 1, global_index + 1);
408 else if (extra_locations.size() == 3)
410 const unsigned global_index = rMesh.
GetNumNodes() + num_pts_added;
412 p_pts->InsertPoint(global_index, extra_locations[1][0], extra_locations[1][1], 0.0);
413 p_pts->InsertPoint(global_index + 1, extra_locations[2][0], extra_locations[2][1], 0.0);
414 p_pts->InsertPoint(global_index + 2, extra_locations[0][0], extra_locations[0][1], 0.0);
416 p_cell_id_list->SetId(num_nodes_this_part, global_index);
417 p_cell_id_list->SetId(num_nodes_this_part + 1, global_index + 1);
418 p_cell_id_list->SetId(num_nodes_this_part + 2, global_index + 2);
427 mpVtkUnstructedMesh->InsertNextCell(p_cell->GetCellType(), p_cell_id_list);
438 unsigned num_nodes = iter->GetNumNodes();
440 vtkCell* p_cell = vtkPolygon::New();
441 vtkIdList* p_cell_id_list = p_cell->GetPointIds();
442 p_cell_id_list->SetNumberOfIds(num_nodes);
444 for (
unsigned node_idx = 0; node_idx < num_nodes; node_idx++)
448 unsigned global_idx = p_node->
GetIndex();
450 c_vector<double, SPACE_DIM> position = p_node->
rGetLocation();
451 p_pts->InsertPoint(global_idx, position[0], position[1], 0.0);
453 p_cell_id_list->SetId(node_idx, global_idx);
456 mpVtkUnstructedMesh->InsertNextCell(3, p_cell_id_list);
460 mpVtkUnstructedMesh->SetPoints(p_pts);
543 std::string node_file_name = this->mBaseName +
".node";
544 out_stream p_node_file = this->mpOutputFileHandler->OpenOutputFile(node_file_name);
547 unsigned num_attr = 0;
548 unsigned max_bdy_marker = 1;
549 unsigned num_nodes = this->GetNumNodes();
551 *p_node_file << num_nodes <<
"\t";
552 *p_node_file << SPACE_DIM <<
"\t";
553 *p_node_file << num_attr <<
"\t";
554 *p_node_file << mpMesh->GetCharacteristicNodeSpacing() <<
"\t";
555 *p_node_file << max_bdy_marker <<
"\n";
556 *p_node_file << std::setprecision(6);
559 for (
unsigned item_num=0; item_num<num_nodes; item_num++)
561 std::vector<double> current_item = this->GetNextNode();
562 *p_node_file << item_num;
563 for (
unsigned i=0; i<SPACE_DIM+1; i++)
565 *p_node_file <<
"\t" << current_item[i];
567 *p_node_file <<
"\n";
569 *p_node_file << comment <<
"\n";
570 p_node_file->close();
573 std::string element_file_name = this->mBaseName +
".elem";
574 out_stream p_element_file = this->mpOutputFileHandler->OpenOutputFile(element_file_name);
578 unsigned num_elements = this->GetNumElements();
579 *p_element_file << num_elements <<
"\t" << num_attr <<
"\n";
582 for (
unsigned item_num=0; item_num<num_elements; item_num++)
590 std::vector<unsigned> node_indices = elem_data.
NodeIndices;
593 *p_element_file << item_num <<
"\t" << node_indices.size();
596 for (
unsigned node_index : node_indices)
598 *p_element_file <<
"\t" << node_index;
615 *p_element_file <<
"\t" << nodeIndex;
625 *p_element_file <<
"\n";
631 *p_element_file << comment <<
"\n";
632 p_element_file->close();
635 std::string lamina_file_name = this->mBaseName +
".lam";
636 out_stream p_lamina_file = this->mpOutputFileHandler->OpenOutputFile(lamina_file_name);
640 unsigned num_laminas = mpMesh->GetNumLaminas();
641 *p_lamina_file << num_laminas <<
"\t" << num_attr <<
"\n";
644 for (
unsigned item_num=0; item_num<num_laminas; item_num++)
652 std::vector<unsigned> node_indices = lamina_data.
NodeIndices;
655 *p_lamina_file << item_num <<
"\t" << node_indices.size();
658 for (
unsigned i=0; i<node_indices.size(); i++)
660 *p_lamina_file <<
"\t" << node_indices[i];
677 *p_lamina_file <<
"\t" << nodeIndex;
688 *p_lamina_file <<
"\n";
694 *p_lamina_file << comment <<
"\n";
695 p_lamina_file->close();
698 std::string grid_file_name = this->mBaseName +
".grid";
699 out_stream p_grid_file = this->mpOutputFileHandler->OpenOutputFile(grid_file_name);
702 unsigned num_gridpts_x = mpMesh->GetNumGridPtsX();
703 unsigned num_gridpts_y = mpMesh->GetNumGridPtsY();
705 *p_grid_file << num_gridpts_x <<
"\t" << num_gridpts_y <<
"\n";
708 const multi_array<double, 3>& vel_grids = mpMesh->rGet2dVelocityGrids();
710 for (
unsigned y_idx = 0; y_idx < num_gridpts_y; y_idx ++)
712 for (
unsigned x_idx = 0; x_idx < num_gridpts_x; x_idx ++)
714 *p_grid_file << vel_grids[0][x_idx][y_idx] <<
"\t";
716 *p_grid_file <<
"\n";
719 for (
unsigned y_idx = 0; y_idx < num_gridpts_y; y_idx ++)
721 for (
unsigned x_idx = 0; x_idx < num_gridpts_x; x_idx ++)
723 *p_grid_file << vel_grids[1][x_idx][y_idx] <<
"\t";
725 *p_grid_file <<
"\n";
728 *p_grid_file << comment <<
"\n";
729 p_grid_file->close();