From 94ac1b68df001a17bd7d1844fd5511cf6eefd9d1 Mon Sep 17 00:00:00 2001 From: Oliver Gloth Date: Wed, 13 Aug 2014 11:02:23 +0200 Subject: [PATCH] improved boundary layer algorithm --- src/libengrid/createboundarylayershell.cpp | 29 ++++++++++++++++++----------- src/libengrid/createvolumemesh.cpp | 29 ++++++++++++++++------------- src/libengrid/createvolumemesh.h | 3 +++ src/libengrid/guicreatevolumemesh.cpp | 7 ++++++- src/libengrid/guicreatevolumemesh.ui | 8 ++++++++ 5 files changed, 51 insertions(+), 25 deletions(-) diff --git a/src/libengrid/createboundarylayershell.cpp b/src/libengrid/createboundarylayershell.cpp index 6258d3fc..a793ac00 100644 --- a/src/libengrid/createboundarylayershell.cpp +++ b/src/libengrid/createboundarylayershell.cpp @@ -120,7 +120,7 @@ QList CreateBoundaryLayerShell::correctAdjacentBC(int bc, vtkUnstruct QList bad_nodes; while (scal_min < 0.5 && count < 10) { - cout << " iteration " << count + 1 << endl; + //cout << " iteration " << count + 1 << endl; scal_min = 1; bad_nodes.clear(); for (vtkIdType id_node = 0; id_node < grid->GetNumberOfPoints(); ++id_node) { @@ -167,15 +167,17 @@ QList CreateBoundaryLayerShell::correctAdjacentBC(int bc, vtkUnstruct for (int i = 0; i < part.n2cGSize(id_node); ++i) { vtkIdType id_cell = part.n2cGG(id_node, i); if (isSurface(id_cell, grid)) { - CadInterface *cad = GuiMainWindow::pointer()->getCadInterface(cell_code->GetValue(id_cell)); - vec3_t x = cad->snap(cellCentre(grid, id_cell)); - vec3_t n = cellNormal(grid, id_cell); - n.normalise(); - double scal = n*cad->getLastNormal(); - scal_min = min(scal_min, scal); - if (scal < 0.5 && !node_bad) { - bad_nodes << id_node; - node_bad = true; + if (cell_code->GetValue(id_cell) == bc) { + CadInterface *cad = GuiMainWindow::pointer()->getCadInterface(cell_code->GetValue(id_cell)); + cad->snap(cellCentre(grid, id_cell)); + vec3_t n = cellNormal(grid, id_cell); + n.normalise(); + double scal = n*cad->getLastNormal(); + scal_min = min(scal_min, scal); + if (scal < 0.5 && !node_bad) { + bad_nodes << id_node; + node_bad = true; + } } } } @@ -183,7 +185,7 @@ QList CreateBoundaryLayerShell::correctAdjacentBC(int bc, vtkUnstruct } } //reduceSurface(); - cout << " " << bad_nodes.size() << " node defects" << endl; + //cout << " " << bad_nodes.size() << " node defects" << endl; ++count; } if (scal_min < 0.5) { @@ -396,6 +398,11 @@ void CreateBoundaryLayerShell::operate() } } + cout << "bad nodes:" << endl; + foreach (vtkIdType id_node, bad_nodes) { + cout << " " << id_node << endl; + } + DeleteCells del; del.setGrid(m_Grid); del.setCellsToDelete(bad_cells); diff --git a/src/libengrid/createvolumemesh.cpp b/src/libengrid/createvolumemesh.cpp index bc1c5d9f..6969cdc9 100755 --- a/src/libengrid/createvolumemesh.cpp +++ b/src/libengrid/createvolumemesh.cpp @@ -34,6 +34,7 @@ CreateVolumeMesh::CreateVolumeMesh() m_CreateBoundaryLayer = false; m_BackgroundGrid = vtkSmartPointer::New(); m_FirstCall = true; + m_Debug = false; } int CreateVolumeMesh::numVolumeCells() @@ -104,19 +105,21 @@ void CreateVolumeMesh::operate() blayer.setGrid(m_Grid); blayer.setAllCells(); blayer(); - if (blayer.success()) { - createTetMesh(2, true); - vtkUnstructuredGrid *prismatic_grid = blayer.getPrismaticGrid(); - MeshPartition prismatic_part(prismatic_grid, true); - QVector shell_cells; - getSurfaceCells(blayer.getBoundaryLayerCodes(), shell_cells, m_Grid); - DeleteCells delete_cells; - delete_cells.setGrid(m_Grid); - delete_cells.setCellsToDelete(shell_cells); - delete_cells(); - m_Part.addPartition(prismatic_part); - } else { - cout << "An error ocuured while creating the prismatic layers!" << endl; + if (!m_Debug) { + if (blayer.success()) { + createTetMesh(2, true); + vtkUnstructuredGrid *prismatic_grid = blayer.getPrismaticGrid(); + MeshPartition prismatic_part(prismatic_grid, true); + QVector shell_cells; + getSurfaceCells(blayer.getBoundaryLayerCodes(), shell_cells, m_Grid); + DeleteCells delete_cells; + delete_cells.setGrid(m_Grid); + delete_cells.setCellsToDelete(shell_cells); + delete_cells(); + m_Part.addPartition(prismatic_part); + } else { + cout << "An error ocuured while creating the prismatic layers!" << endl; + } } } else { createTetMesh(2, true); diff --git a/src/libengrid/createvolumemesh.h b/src/libengrid/createvolumemesh.h index 664efd72..2c0ce095 100644 --- a/src/libengrid/createvolumemesh.h +++ b/src/libengrid/createvolumemesh.h @@ -34,6 +34,7 @@ private: // attributes bool m_CreateBoundaryLayer; bool m_FirstCall; + bool m_Debug; vtkSmartPointer m_BackgroundGrid; @@ -54,6 +55,8 @@ public: // methods CreateVolumeMesh(); void setBoundaryLayerOn(); + void debugOn() { m_Debug = true; } + void debugOff() { m_Debug = false; } }; diff --git a/src/libengrid/guicreatevolumemesh.cpp b/src/libengrid/guicreatevolumemesh.cpp index 7272f2b6..08766d5a 100644 --- a/src/libengrid/guicreatevolumemesh.cpp +++ b/src/libengrid/guicreatevolumemesh.cpp @@ -50,7 +50,12 @@ void GuiCreateVolumeMesh::operate() rest.extractToVtkGrid(rest_grid); } mesh_volume.setGrid(part_grid); - if (m_Ui.m_CheckBoxBoundaryLayer->isChecked()) mesh_volume.setBoundaryLayerOn(); + if (m_Ui.m_CheckBoxBoundaryLayer->isChecked()) { + mesh_volume.setBoundaryLayerOn(); + } + if (m_Ui.m_CheckBoxDebug->isChecked()) { + mesh_volume.debugOn(); + } mesh_volume(); EG_VTKDCC(vtkIntArray, cell_code, part_grid, "cell_code"); for (vtkIdType id_cell = 0; id_cell < part_grid->GetNumberOfCells(); ++id_cell) { diff --git a/src/libengrid/guicreatevolumemesh.ui b/src/libengrid/guicreatevolumemesh.ui index 0bddbab4..cf474ce2 100644 --- a/src/libengrid/guicreatevolumemesh.ui +++ b/src/libengrid/guicreatevolumemesh.ui @@ -35,6 +35,13 @@ + + + stop before TetGen call (debug) + + + + Qt::Vertical @@ -79,6 +86,7 @@ m_ListWidgetVolumes m_CheckBoxBoundaryLayer + m_CheckBoxDebug buttonBox -- 2.11.4.GIT