From f30b28155a334f31dffa3a49da9126be89b91f81 Mon Sep 17 00:00:00 2001 From: Oliver Gloth Date: Fri, 30 Apr 2010 22:45:16 +0200 Subject: [PATCH] implemented mirror mesh, still not working for vol. cells --- src/egvtkobject.cpp | 1 + src/egvtkobject.h | 1 - src/gridsmoother.cpp | 2 +- src/guimirrormesh.cpp | 27 ++++++++++++++++++++++--- src/meshpartition.cpp | 3 +-- src/operation.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/operation.h | 7 +++++++ 7 files changed, 90 insertions(+), 7 deletions(-) diff --git a/src/egvtkobject.cpp b/src/egvtkobject.cpp index 0873122..b8745b2 100644 --- a/src/egvtkobject.cpp +++ b/src/egvtkobject.cpp @@ -1190,3 +1190,4 @@ vtkIdType EgVtkObject::addGrid(vtkUnstructuredGrid *main_grid, vtkUnstructuredGr } return( offset + grid_to_add->GetNumberOfPoints() ); } + diff --git a/src/egvtkobject.h b/src/egvtkobject.h index 4faee74..81e78b9 100644 --- a/src/egvtkobject.h +++ b/src/egvtkobject.h @@ -513,7 +513,6 @@ protected: // methods */ void getEdgeOfCell(vtkUnstructuredGrid *grid, vtkIdType id_cell, int i_edge, QVector &ids); - public: // methods EgVtkObject() { DebugLevel = 0; } diff --git a/src/gridsmoother.cpp b/src/gridsmoother.cpp index 99cb4c2..a7c3f4c 100644 --- a/src/gridsmoother.cpp +++ b/src/gridsmoother.cpp @@ -38,7 +38,7 @@ GridSmoother::GridSmoother() getSet("boundary layer", "use strict prism checking", false, m_StrictPrismChecking); getSet("boundary layer", "number of normal vector relax iterations", 10, m_NumNormalRelaxations); getSet("boundary layer", "number of layer height relax iterations", 3, m_NumHeightRelaxations); - getSet("boundary layer", "radar angle", 60, m_RadarAngle); + getSet("boundary layer", "radar angle", 30, m_RadarAngle); getSet("boundary layer", "maximal layer height in gaps", 0.2, m_MaxHeightInGaps); //m_CritAngle = GeometryTools::deg2rad(m_CritAngle); diff --git a/src/guimirrormesh.cpp b/src/guimirrormesh.cpp index 7e547c7..cbd9897 100644 --- a/src/guimirrormesh.cpp +++ b/src/guimirrormesh.cpp @@ -39,7 +39,6 @@ void GuiMirrorMesh::operate() m_Grid->GetPoint(id_node, x.data()); double h = n*(x-x0); vec3_t xm = x - 2*h*n; - //cout << x << ", " << xm << endl; mirror_grid->GetPoints()->SetPoint(id_node, xm.data()); copyNodeData(m_Grid, id_node, mirror_grid, id_node); } @@ -48,8 +47,29 @@ void GuiMirrorMesh::operate() vtkIdType N_pts, *pts; m_Grid->GetCellPoints(id_cell, N_pts, pts); vtkIdType new_pts[N_pts]; - for (int i = 0; i < N_pts; ++i) { - new_pts[i] = pts[N_pts - i - 1]; + vtkIdType cell_type = m_Grid->GetCellType(id_cell); + if (cell_type == VTK_WEDGE) { + new_pts[0] = pts[3]; + new_pts[1] = pts[4]; + new_pts[2] = pts[5]; + new_pts[3] = pts[0]; + new_pts[4] = pts[1]; + new_pts[5] = pts[2]; + } else if (cell_type == VTK_HEXAHEDRON) { + new_pts[0] = pts[4]; + new_pts[1] = pts[5]; + new_pts[2] = pts[6]; + new_pts[3] = pts[7]; + new_pts[4] = pts[0]; + new_pts[5] = pts[1]; + new_pts[6] = pts[2]; + new_pts[7] = pts[3]; + } else if (cell_type == VTK_PYRAMID) { + EG_BUG; + } else { + for (int i = 0; i < N_pts; ++i) { + new_pts[i] = pts[N_pts - i - 1]; + } } id_new_cell = mirror_grid->InsertNextCell(m_Grid->GetCellType(id_cell), N_pts, new_pts); copyCellData(m_Grid, id_cell, mirror_grid, id_new_cell); @@ -57,5 +77,6 @@ void GuiMirrorMesh::operate() MeshPartition part1(m_Grid, true); MeshPartition part2(mirror_grid, true); part1.addPartition(part2); + eliminateDuplicateCells(); } diff --git a/src/meshpartition.cpp b/src/meshpartition.cpp index b3290a7..631db41 100644 --- a/src/meshpartition.cpp +++ b/src/meshpartition.cpp @@ -167,7 +167,6 @@ void MeshPartition::addPartition(const MeshPartition& part) setCells(new_cells); } else { double tol = 1e-3*min(getSmallestEdgeLength(), part.getSmallestEdgeLength()); - cout << tol << endl; EG_VTKSP(vtkUnstructuredGrid, new_grid); EG_VTKSP(vtkKdTreePointLocator,loc); loc->SetDataSet(m_Grid); @@ -186,7 +185,6 @@ void MeshPartition::addPartition(const MeshPartition& part) ++N; } } - cout << m_Grid->GetNumberOfCells() + part.m_Cells.size() << ", " << N << endl; allocateGrid(new_grid, m_Grid->GetNumberOfCells() + part.m_Cells.size(), N); for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) { vec3_t x; @@ -290,3 +288,4 @@ double MeshPartition::getSmallestEdgeLength() const } return L; } + diff --git a/src/operation.cpp b/src/operation.cpp index 4f12be8..5c2a0c8 100644 --- a/src/operation.cpp +++ b/src/operation.cpp @@ -232,3 +232,59 @@ void Operation::populateVolumes(QListWidget *lw) lwi->setText(V.getName()); } } + +void Operation::eliminateDuplicateCells(bool surf_only) +{ + QVector cells; + if (surf_only) { + getAllSurfaceCells(cells, m_Grid); + } else { + getAllCells(cells, m_Grid); + } + QVector > cell_nodes(cells.size()); + + for (int i_cells = 0; i_cells < cells.size(); ++i_cells) { + vtkIdType id_cell = cells[i_cells]; + if (!surf_only || isSurface(id_cell, m_Grid)) { + vtkIdType N_pts, *pts; + m_Grid->GetCellPoints(id_cell, N_pts, pts); + QVector nodes(N_pts); + for (int i = 0; i < N_pts; ++i) { + nodes[i] = pts[i]; + } + qSort(nodes); + cell_nodes[i_cells] = nodes; + } + } + QList new_cells; + for (int i_cells = 0; i_cells < cells.size(); ++i_cells) { + vtkIdType id_cell1 = cells[i_cells]; + bool duplicate_cell = false; + if (!surf_only || isSurface(id_cell1, m_Grid)) { + for (int j_cells = 0; j_cells < cells.size(); ++j_cells) { + vtkIdType id_cell2 = cells[j_cells]; + if (i_cells != j_cells) { + if (!surf_only || isSurface(id_cell2, m_Grid)) { + if (cell_nodes[i_cells] == cell_nodes[j_cells]) { + duplicate_cell = true; + break; + } + } + } + } + } + if (!duplicate_cell) { + new_cells.append(id_cell1); + } + } + if (surf_only) { + QVector vol_cells; + getAllVolumeCells(vol_cells, m_Grid); + foreach(vtkIdType id_cell, vol_cells) { + new_cells.append(id_cell); + } + } + EG_VTKSP(vtkUnstructuredGrid, new_grid); + makeCopy(m_Grid, new_grid, new_cells); + makeCopy(new_grid, m_Grid); +} diff --git a/src/operation.h b/src/operation.h index bb2728e..1da4c13 100644 --- a/src/operation.h +++ b/src/operation.h @@ -108,6 +108,13 @@ protected: // methods virtual void operate() = 0; void setTypeName(QString name); + /** + * Eliminate cells with identical node indices. + * @param surf_only if set to false all cells will be checked, otherwise surface cells only. + * Careful with eliminating volume cells -- this can be extremely slow. + */ + void eliminateDuplicateCells(bool surf_only = true); + l2g_t getPartNodes() { return m_Part.getNodes(); } l2g_t getPartCells() const { return m_Part.getCells(); } g2l_t getPartLocalNodes() { return m_Part.getLocalNodes(); } -- 2.11.4.GIT