1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "restricttoavailablevolumecells.h"
22 #include "guimainwindow.h"
24 void RestrictToAvailableVolumeCells::operate()
26 QList
<vtkIdType
> vol_cells
, surf_cells
;
27 for (vtkIdType id_cell
= 0; id_cell
< m_Grid
->GetNumberOfCells(); ++id_cell
) {
28 if (isVolume(id_cell
, m_Grid
)) {
29 vol_cells
.append(id_cell
);
32 foreach (vtkIdType id_cell
, vol_cells
) {
33 for (int i
= 0; i
< m_Part
.c2cGSize(id_cell
); ++i
) {
34 vtkIdType id_neigh
= m_Part
.c2cGG(id_cell
, i
);
36 if (isSurface(id_neigh
, m_Grid
)) {
37 surf_cells
.append(id_neigh
);
42 MeshPartition
vol_part(m_Grid
);
43 vol_part
.setCells(vol_cells
+ surf_cells
);
44 EG_VTKSP(vtkUnstructuredGrid
, new_grid1
);
45 vol_part
.extractToVtkGrid(new_grid1
);
46 MeshPartition
new_part1(new_grid1
, true);
47 QList
<QVector
<vtkIdType
> > new_faces
;
48 for (vtkIdType id_cell
= 0; id_cell
< new_grid1
->GetNumberOfCells(); ++id_cell
) {
49 if (isVolume(id_cell
, new_grid1
)) {
50 for (int i
= 0; i
< new_part1
.c2cGSize(id_cell
); ++i
) {
51 vtkIdType id_neigh
= new_part1
.c2cGG(id_cell
, i
);
53 QVector
<vtkIdType
> pts
;
54 getFaceOfCell(new_grid1
, id_cell
, i
, pts
);
55 new_faces
.append(pts
);
60 EG_VTKSP(vtkUnstructuredGrid
, new_grid2
);
61 allocateGrid(new_grid2
, new_grid1
->GetNumberOfCells() + new_faces
.size(), new_grid1
->GetNumberOfPoints());
62 EG_VTKDCC(vtkIntArray
, cell_code1
, new_grid1
, "cell_code");
63 EG_VTKDCC(vtkIntArray
, cell_code2
, new_grid2
, "cell_code");
64 for (vtkIdType id_node
= 0; id_node
< new_grid1
->GetNumberOfPoints(); ++id_node
) {
66 new_grid1
->GetPoint(id_node
, x
.data());
67 new_grid2
->GetPoints()->SetPoint(id_node
, x
.data());
68 copyNodeData(new_grid1
, id_node
, new_grid2
, id_node
);
71 for (vtkIdType id_cell
= 0; id_cell
< new_grid1
->GetNumberOfCells(); ++id_cell
) {
72 copyCell(new_grid1
, id_cell
, new_grid2
);
73 copyCellData(new_grid1
, id_cell
, new_grid2
, id_cell
);
74 if (isSurface(id_cell
, new_grid1
)) {
75 bc_new
= max(bc_new
, cell_code1
->GetValue(id_cell
) + 1);
77 cell_code2
->SetValue(id_cell
, 0);
80 foreach (QVector
<vtkIdType
> face
, new_faces
) {
81 vtkIdType type
= VTK_POLYGON
;
82 if (face
.size() == 3) {
84 } else if (face
.size() == 4) {
87 vtkIdType id_cell
= new_grid2
->InsertNextCell(type
, face
.size(), face
.data());
88 cell_code2
->SetValue(id_cell
, bc_new
);
90 makeCopy(new_grid2
, m_Grid
);
91 GuiMainWindow::pointer()->addBC(bc_new
, BoundaryCondition("ami_blayer", "cyclic_AMI"));
92 UpdateCellIndex(m_Grid
);
93 GuiMainWindow::pointer()->updateBoundaryCodes(true);