288 if constexpr (SPACE_DIM == 2)
290 FindElementOverlaps(rMesh);
293 vtkPoints* p_pts = vtkPoints::New(VTK_DOUBLE);
294 p_pts->GetData()->SetName(
"Vertex positions");
297 unsigned num_pts_added = 0;
302 unsigned elem_idx = iter->GetIndex();
303 unsigned num_nodes = iter->GetNumNodes();
306 if (mElementParts.size() == 0 || mElementParts[elem_idx].empty())
308 vtkCell* p_cell = vtkPolygon::New();
309 vtkIdList* p_cell_id_list = p_cell->GetPointIds();
310 p_cell_id_list->SetNumberOfIds(num_nodes);
312 for (
unsigned node_local_idx = 0; node_local_idx < num_nodes; ++node_local_idx)
315 unsigned global_idx = iter->GetNode(node_local_idx)->GetIndex();
316 const auto& r_location = iter->GetNode(node_local_idx)->rGetLocation();
318 p_pts->InsertPoint(global_idx, r_location[0], r_location[1], 0.0);
319 p_cell_id_list->SetId(node_local_idx, global_idx);
322 mpVtkUnstructedMesh->InsertNextCell(p_cell->GetCellType(), p_cell_id_list);
328 const std::vector<unsigned>& start_idx_each_part = mElementParts[iter->GetIndex()];
331 const auto num_parts = start_idx_each_part.size();
333 for (
unsigned part = 0; part < num_parts; ++part)
335 const long this_start = start_idx_each_part[part];
336 const long next_start = start_idx_each_part[AdvanceMod(part, 1, num_parts)];
338 const long num_nodes_this_part = next_start > this_start ? next_start - this_start : num_nodes + next_start - this_start;
341 std::vector<c_vector<double, SPACE_DIM>> extra_locations;
345 const auto& r_start_pos = iter->GetNode(this_start)->rGetLocation();
346 const auto& r_end_pos = iter->GetNode(AdvanceMod(this_start, -1, num_nodes))->rGetLocation();
348 const c_vector<double, SPACE_DIM> vec_a2b = rMesh.
GetVectorFromAtoB(r_start_pos, r_end_pos);
349 extra_locations.emplace_back(GetIntersectionOfEdgeWithBoundary(r_start_pos, r_start_pos + vec_a2b));
354 const auto& r_start_pos = iter->GetNode(AdvanceMod(next_start, -1, num_nodes))->rGetLocation();
355 const auto& r_end_pos = iter->GetNode(next_start)->rGetLocation();
357 const c_vector<double, SPACE_DIM> vec_a2b = rMesh.
GetVectorFromAtoB(r_start_pos, r_end_pos);
358 extra_locations.emplace_back(GetIntersectionOfEdgeWithBoundary(r_start_pos, r_start_pos + vec_a2b));
362 if (std::fabs(extra_locations.front()[0] - extra_locations.back()[0]) > DBL_EPSILON &&
363 std::fabs(extra_locations.front()[1] - extra_locations.back()[1]) > DBL_EPSILON)
365 extra_locations.emplace_back(GetNearestCorner(extra_locations.front(), extra_locations.back()));
368 vtkCell* p_cell = vtkPolygon::New();
369 vtkIdList* p_cell_id_list = p_cell->GetPointIds();
370 p_cell_id_list->SetNumberOfIds(num_nodes_this_part + extra_locations.size());
372 for (
long idx = 0; idx < num_nodes_this_part; ++idx)
374 unsigned node_idx = AdvanceMod(idx, this_start, num_nodes);
377 unsigned global_idx = iter->GetNode(node_idx)->GetIndex();
378 const auto& r_location = iter->GetNode(node_idx)->rGetLocation();
380 p_pts->InsertPoint(global_idx, r_location[0], r_location[1], 0.0);
381 p_cell_id_list->SetId(idx, global_idx);
385 if (extra_locations.size() == 2)
387 const unsigned global_index = rMesh.
GetNumNodes() + num_pts_added;
389 p_pts->InsertPoint(global_index, extra_locations[1][0], extra_locations[1][1], 0.0);
390 p_pts->InsertPoint(global_index + 1, extra_locations[0][0], extra_locations[0][1], 0.0);
392 p_cell_id_list->SetId(num_nodes_this_part, global_index);
393 p_cell_id_list->SetId(num_nodes_this_part + 1, global_index + 1);
397 else if (extra_locations.size() == 3)
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[2][0], extra_locations[2][1], 0.0);
403 p_pts->InsertPoint(global_index + 2, extra_locations[0][0], extra_locations[0][1], 0.0);
405 p_cell_id_list->SetId(num_nodes_this_part, global_index);
406 p_cell_id_list->SetId(num_nodes_this_part + 1, global_index + 1);
407 p_cell_id_list->SetId(num_nodes_this_part + 2, global_index + 2);
416 mpVtkUnstructedMesh->InsertNextCell(p_cell->GetCellType(), p_cell_id_list);
427 unsigned num_nodes = iter->GetNumNodes();
429 vtkCell* p_cell = vtkPolygon::New();
430 vtkIdList* p_cell_id_list = p_cell->GetPointIds();
431 p_cell_id_list->SetNumberOfIds(num_nodes);
433 for (
unsigned node_idx = 0; node_idx < num_nodes; node_idx++)
437 unsigned global_idx = p_node->
GetIndex();
439 c_vector<double, SPACE_DIM> position = p_node->
rGetLocation();
440 p_pts->InsertPoint(global_idx, position[0], position[1], 0.0);
442 p_cell_id_list->SetId(node_idx, global_idx);
445 mpVtkUnstructedMesh->InsertNextCell(3, p_cell_id_list);
449 mpVtkUnstructedMesh->SetPoints(p_pts);
527 std::string node_file_name = this->mBaseName +
".node";
528 out_stream p_node_file = this->mpOutputFileHandler->OpenOutputFile(node_file_name);
531 unsigned num_attr = 0;
532 unsigned max_bdy_marker = 1;
533 unsigned num_nodes = this->GetNumNodes();
535 *p_node_file << num_nodes <<
"\t";
536 *p_node_file << SPACE_DIM <<
"\t";
537 *p_node_file << num_attr <<
"\t";
538 *p_node_file << mpMesh->GetCharacteristicNodeSpacing() <<
"\t";
539 *p_node_file << max_bdy_marker <<
"\n";
540 *p_node_file << std::setprecision(6);
543 for (
unsigned item_num=0; item_num<num_nodes; item_num++)
545 std::vector<double> current_item = this->GetNextNode();
546 *p_node_file << item_num;
547 for (
unsigned i=0; i<SPACE_DIM+1; i++)
549 *p_node_file <<
"\t" << current_item[i];
551 *p_node_file <<
"\n";
553 *p_node_file << comment <<
"\n";
554 p_node_file->close();
557 std::string element_file_name = this->mBaseName +
".elem";
558 out_stream p_element_file = this->mpOutputFileHandler->OpenOutputFile(element_file_name);
562 unsigned num_elements = this->GetNumElements();
563 *p_element_file << num_elements <<
"\t" << num_attr <<
"\n";
566 for (
unsigned item_num=0; item_num<num_elements; item_num++)
574 std::vector<unsigned> node_indices = elem_data.
NodeIndices;
577 *p_element_file << item_num <<
"\t" << node_indices.size();
580 for (
unsigned node_index : node_indices)
582 *p_element_file <<
"\t" << node_index;
599 *p_element_file <<
"\t" << nodeIndex;
609 *p_element_file <<
"\n";
615 *p_element_file << comment <<
"\n";
616 p_element_file->close();
619 std::string lamina_file_name = this->mBaseName +
".lam";
620 out_stream p_lamina_file = this->mpOutputFileHandler->OpenOutputFile(lamina_file_name);
624 unsigned num_laminas = mpMesh->GetNumLaminas();
625 *p_lamina_file << num_laminas <<
"\t" << num_attr <<
"\n";
628 for (
unsigned item_num=0; item_num<num_laminas; item_num++)
636 std::vector<unsigned> node_indices = lamina_data.
NodeIndices;
639 *p_lamina_file << item_num <<
"\t" << node_indices.size();
642 for (
unsigned i=0; i<node_indices.size(); i++)
644 *p_lamina_file <<
"\t" << node_indices[i];
661 *p_lamina_file <<
"\t" << nodeIndex;
672 *p_lamina_file <<
"\n";
678 *p_lamina_file << comment <<
"\n";
679 p_lamina_file->close();
682 std::string grid_file_name = this->mBaseName +
".grid";
683 out_stream p_grid_file = this->mpOutputFileHandler->OpenOutputFile(grid_file_name);
686 unsigned num_gridpts_x = mpMesh->GetNumGridPtsX();
687 unsigned num_gridpts_y = mpMesh->GetNumGridPtsY();
689 *p_grid_file << num_gridpts_x <<
"\t" << num_gridpts_y <<
"\n";
692 const multi_array<double, 3>& vel_grids = mpMesh->rGet2dVelocityGrids();
694 for (
unsigned y_idx = 0; y_idx < num_gridpts_y; y_idx ++)
696 for (
unsigned x_idx = 0; x_idx < num_gridpts_x; x_idx ++)
698 *p_grid_file << vel_grids[0][x_idx][y_idx] <<
"\t";
700 *p_grid_file <<
"\n";
703 for (
unsigned y_idx = 0; y_idx < num_gridpts_y; y_idx ++)
705 for (
unsigned x_idx = 0; x_idx < num_gridpts_x; x_idx ++)
707 *p_grid_file << vel_grids[1][x_idx][y_idx] <<
"\t";
709 *p_grid_file <<
"\n";
712 *p_grid_file << comment <<
"\n";
713 p_grid_file->close();