300 if constexpr (SPACE_DIM == 2)
302 FindElementOverlaps(rMesh);
305 vtkPoints* p_pts = vtkPoints::New(VTK_DOUBLE);
306 p_pts->GetData()->SetName(
"Vertex positions");
309 unsigned num_pts_added = 0;
314 unsigned elem_idx = iter->GetIndex();
315 unsigned num_nodes = iter->GetNumNodes();
318 if (mElementParts.size() == 0 || mElementParts[elem_idx].empty())
320 vtkCell* p_cell = vtkPolygon::New();
321 vtkIdList* p_cell_id_list = p_cell->GetPointIds();
322 p_cell_id_list->SetNumberOfIds(num_nodes);
324 for (
unsigned node_local_idx = 0; node_local_idx < num_nodes; ++node_local_idx)
327 unsigned global_idx = iter->GetNode(node_local_idx)->GetIndex();
328 const auto& r_location = iter->GetNode(node_local_idx)->rGetLocation();
330 p_pts->InsertPoint(global_idx, r_location[0], r_location[1], 0.0);
331 p_cell_id_list->SetId(node_local_idx, global_idx);
334 mpVtkUnstructedMesh->InsertNextCell(p_cell->GetCellType(), p_cell_id_list);
340 const std::vector<unsigned>& start_idx_each_part = mElementParts[iter->GetIndex()];
343 const auto num_parts = start_idx_each_part.size();
345 for (
unsigned part = 0; part < num_parts; ++part)
347 const long this_start = start_idx_each_part[part];
348 const long next_start = start_idx_each_part[AdvanceMod(part, 1, num_parts)];
350 const long num_nodes_this_part = next_start > this_start ? next_start - this_start : num_nodes + next_start - this_start;
353 std::vector<c_vector<double, SPACE_DIM>> extra_locations;
357 const auto& r_start_pos = iter->GetNode(this_start)->rGetLocation();
358 const auto& r_end_pos = iter->GetNode(AdvanceMod(this_start, -1, num_nodes))->rGetLocation();
360 const c_vector<double, SPACE_DIM> vec_a2b = rMesh.
GetVectorFromAtoB(r_start_pos, r_end_pos);
361 extra_locations.emplace_back(GetIntersectionOfEdgeWithBoundary(r_start_pos, r_start_pos + vec_a2b));
366 const auto& r_start_pos = iter->GetNode(AdvanceMod(next_start, -1, num_nodes))->rGetLocation();
367 const auto& r_end_pos = iter->GetNode(next_start)->rGetLocation();
369 const c_vector<double, SPACE_DIM> vec_a2b = rMesh.
GetVectorFromAtoB(r_start_pos, r_end_pos);
370 extra_locations.emplace_back(GetIntersectionOfEdgeWithBoundary(r_start_pos, r_start_pos + vec_a2b));
374 if (std::fabs(extra_locations.front()[0] - extra_locations.back()[0]) > DBL_EPSILON &&
375 std::fabs(extra_locations.front()[1] - extra_locations.back()[1]) > DBL_EPSILON)
377 extra_locations.emplace_back(GetNearestCorner(extra_locations.front(), extra_locations.back()));
380 vtkCell* p_cell = vtkPolygon::New();
381 vtkIdList* p_cell_id_list = p_cell->GetPointIds();
382 p_cell_id_list->SetNumberOfIds(num_nodes_this_part + extra_locations.size());
384 for (
long idx = 0; idx < num_nodes_this_part; ++idx)
386 unsigned node_idx = AdvanceMod(idx, this_start, num_nodes);
389 unsigned global_idx = iter->GetNode(node_idx)->GetIndex();
390 const auto& r_location = iter->GetNode(node_idx)->rGetLocation();
392 p_pts->InsertPoint(global_idx, r_location[0], r_location[1], 0.0);
393 p_cell_id_list->SetId(idx, global_idx);
397 if (extra_locations.size() == 2)
399 const unsigned global_index = rMesh.
GetNumNodes() + num_pts_added;
401 p_pts->InsertPoint(global_index, extra_locations[1][0], extra_locations[1][1], 0.0);
402 p_pts->InsertPoint(global_index + 1, extra_locations[0][0], extra_locations[0][1], 0.0);
404 p_cell_id_list->SetId(num_nodes_this_part, global_index);
405 p_cell_id_list->SetId(num_nodes_this_part + 1, global_index + 1);
409 else if (extra_locations.size() == 3)
411 const unsigned global_index = rMesh.
GetNumNodes() + num_pts_added;
413 p_pts->InsertPoint(global_index, extra_locations[1][0], extra_locations[1][1], 0.0);
414 p_pts->InsertPoint(global_index + 1, extra_locations[2][0], extra_locations[2][1], 0.0);
415 p_pts->InsertPoint(global_index + 2, extra_locations[0][0], extra_locations[0][1], 0.0);
417 p_cell_id_list->SetId(num_nodes_this_part, global_index);
418 p_cell_id_list->SetId(num_nodes_this_part + 1, global_index + 1);
419 p_cell_id_list->SetId(num_nodes_this_part + 2, global_index + 2);
428 mpVtkUnstructedMesh->InsertNextCell(p_cell->GetCellType(), p_cell_id_list);
439 unsigned num_nodes = iter->GetNumNodes();
441 vtkCell* p_cell = vtkPolygon::New();
442 vtkIdList* p_cell_id_list = p_cell->GetPointIds();
443 p_cell_id_list->SetNumberOfIds(num_nodes);
445 for (
unsigned node_idx = 0; node_idx < num_nodes; node_idx++)
449 unsigned global_idx = p_node->
GetIndex();
450 c_vector<double, SPACE_DIM> position = p_node->
rGetLocation();
452 p_pts->InsertPoint(global_idx, position[0], position[1], 0.0);
454 p_cell_id_list->SetId(node_idx, global_idx);
457 mpVtkUnstructedMesh->InsertNextCell(3, p_cell_id_list);
461 mpVtkUnstructedMesh->SetPoints(p_pts);
544 std::string node_file_name = this->mBaseName +
".node";
545 out_stream p_node_file = this->mpOutputFileHandler->OpenOutputFile(node_file_name);
548 unsigned num_attr = 0;
549 unsigned max_bdy_marker = 1;
550 unsigned num_nodes = this->GetNumNodes();
552 *p_node_file << num_nodes <<
"\t";
553 *p_node_file << SPACE_DIM <<
"\t";
554 *p_node_file << num_attr <<
"\t";
555 *p_node_file << mpMesh->GetCharacteristicNodeSpacing() <<
"\t";
556 *p_node_file << max_bdy_marker <<
"\n";
557 *p_node_file << std::setprecision(6);
560 for (
unsigned item_num=0; item_num<num_nodes; item_num++)
562 std::vector<double> current_item = this->GetNextNode();
563 *p_node_file << item_num;
564 for (
unsigned i=0; i<SPACE_DIM+1; i++)
566 *p_node_file <<
"\t" << current_item[i];
568 *p_node_file <<
"\n";
570 *p_node_file << comment <<
"\n";
571 p_node_file->close();
574 std::string element_file_name = this->mBaseName +
".elem";
575 out_stream p_element_file = this->mpOutputFileHandler->OpenOutputFile(element_file_name);
579 unsigned num_elements = this->GetNumElements();
580 *p_element_file << num_elements <<
"\t" << num_attr <<
"\n";
583 for (
unsigned item_num=0; item_num<num_elements; item_num++)
591 std::vector<unsigned> node_indices = elem_data.
NodeIndices;
594 *p_element_file << item_num <<
"\t" << node_indices.size();
597 for (
unsigned node_index : node_indices)
599 *p_element_file <<
"\t" << node_index;
616 *p_element_file <<
"\t" << nodeIndex;
626 *p_element_file <<
"\n";
632 *p_element_file << comment <<
"\n";
633 p_element_file->close();
636 std::string lamina_file_name = this->mBaseName +
".lam";
637 out_stream p_lamina_file = this->mpOutputFileHandler->OpenOutputFile(lamina_file_name);
641 unsigned num_laminas = mpMesh->GetNumLaminas();
642 *p_lamina_file << num_laminas <<
"\t" << num_attr <<
"\n";
645 for (
unsigned item_num=0; item_num<num_laminas; item_num++)
653 std::vector<unsigned> node_indices = lamina_data.
NodeIndices;
656 *p_lamina_file << item_num <<
"\t" << node_indices.size();
659 for (
unsigned i=0; i<node_indices.size(); i++)
661 *p_lamina_file <<
"\t" << node_indices[i];
678 *p_lamina_file <<
"\t" << nodeIndex;
689 *p_lamina_file <<
"\n";
695 *p_lamina_file << comment <<
"\n";
696 p_lamina_file->close();
699 std::string grid_file_name = this->mBaseName +
".grid";
700 out_stream p_grid_file = this->mpOutputFileHandler->OpenOutputFile(grid_file_name);
703 unsigned num_gridpts_x = mpMesh->GetNumGridPtsX();
704 unsigned num_gridpts_y = mpMesh->GetNumGridPtsY();
706 *p_grid_file << num_gridpts_x <<
"\t" << num_gridpts_y <<
"\n";
709 const multi_array<double, 3>& vel_grids = mpMesh->rGet2dVelocityGrids();
711 for (
unsigned y_idx = 0; y_idx < num_gridpts_y; y_idx ++)
713 for (
unsigned x_idx = 0; x_idx < num_gridpts_x; x_idx ++)
715 *p_grid_file << vel_grids[0][x_idx][y_idx] <<
"\t";
717 *p_grid_file <<
"\n";
720 for (
unsigned y_idx = 0; y_idx < num_gridpts_y; y_idx ++)
722 for (
unsigned x_idx = 0; x_idx < num_gridpts_x; x_idx ++)
724 *p_grid_file << vel_grids[1][x_idx][y_idx] <<
"\t";
726 *p_grid_file <<
"\n";
729 *p_grid_file << comment <<
"\n";
730 p_grid_file->close();