1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of cfMesh.
11 cfMesh is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
16 cfMesh is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with cfMesh. If not, see <http://www.gnu.org/licenses/>.
26 \*---------------------------------------------------------------------------*/
28 #include "tetCreatorOctree.H"
29 #include "meshOctree.H"
30 #include "triSurface.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 void tetCreatorOctree::selectElements()
43 const List<direction>& boxType = octreeCheck_.boxType();
44 const meshOctree& octree = octreeCheck_.octree();
45 const boundBox& rootBox = octree.rootBox();
47 //- store nodeLabels first
48 const VRWGraph& nodeLabels = octreeCheck_.nodeLabels();
49 tetPoints_.setSize(octreeCheck_.numberOfNodes());
51 forAll(nodeLabels, leafI)
52 if( nodeLabels.sizeOfRow(leafI) != 0 )
54 const meshOctreeCubeBasic& oc = octree.returnLeaf(leafI);
55 FixedList<point, 8> lv;
56 oc.vertices(rootBox, lv);
59 tetPoints_[nodeLabels(leafI, vI)] = lv[vI];
62 //- create cubeLabel list
64 cubeLabelPtr_ = new labelList();
65 labelList& cubeLabel = *cubeLabelPtr_;
66 cubeLabel.setSize(octree.numberOfLeaves());
69 forAll(boxType, leafI)
70 if( boxType[leafI] & meshOctreeAddressing::MESHCELL )
72 const meshOctreeCubeBasic& oc = octree.returnLeaf(leafI);
73 cubeLabel[leafI] = tetPoints_.size();
74 tetPoints_.append(oc.centre(rootBox));
78 void tetCreatorOctree::createPointsAndAddressing()
82 const meshOctree& octree = octreeCheck_.octree();
83 const boundBox& rootBox = octree.rootBox();
84 const VRWGraph& nodeLabels = octreeCheck_.nodeLabels();
86 if( !subNodeLabelsPtr_ )
87 subNodeLabelsPtr_ = new VRWGraph(octree.numberOfLeaves());
88 VRWGraph& subNodeLabels = *subNodeLabelsPtr_;
91 direction maxLevel(0);
92 forAll(nodeLabels, leafI)
93 if( octree.returnLeaf(leafI).level() > maxLevel )
94 maxLevel = octree.returnLeaf(leafI).level();
96 sortedLeaves_.setSize(maxLevel+1);
97 forAll(sortedLeaves_, levelI)
98 sortedLeaves_[levelI].clear();
100 forAll(nodeLabels, leafI)
102 const meshOctreeCubeBasic& oc = octree.returnLeaf(leafI);
103 sortedLeaves_[oc.level()].append(leafI);
106 //- create subNodeLabels
107 const FRWGraph<label, 8>& pointLeaves = octreeCheck_.nodeLeaves();
109 forAll(pointLeaves, pointI)
113 for(label i=0;i<8;++i)
115 const label pointLeafI = pointLeaves(pointI, i);
117 if( pointLeafI == -1 )
119 validLeaf[i] = false;
124 for(label j=i+1;j<8;++j)
125 if( pointLeafI == pointLeaves(pointI, j) )
127 validLeaf[i] = false;
128 validLeaf[j] = false;
131 const direction level =
132 octree.returnLeaf(pointLeafI).level();
139 for(label plI=0;plI<8;++plI)
142 const label pointLeafI = pointLeaves(pointI, plI);
144 const meshOctreeCubeBasic& lc =
145 octree.returnLeaf(pointLeafI);
147 if( lc.level() < levelI )
149 if( subNodeLabels.sizeOfRow(pointLeafI) != 8 )
151 subNodeLabels.setRowSize(pointLeafI, 8);
152 forAllRow(subNodeLabels, pointLeafI, k)
153 subNodeLabels(pointLeafI, k) = -1;
156 subNodeLabels(pointLeafI, (7-plI)) = tetPoints_.size();
157 FixedList<point, 8> lv;
158 lc.vertices(rootBox, lv);
162 0.5 * (lv[7-plI] + lc.centre(rootBox))
168 createFaceCentreLabels();
171 forAll(nodeLabels, leafI)
173 forAllRow(nodeLabels, leafI, nlI)
174 if( leafI != pointLeaves(nodeLabels(leafI, nlI), (7-nlI)) )
175 FatalError << "Shit" << abort(FatalError);
180 void tetCreatorOctree::createFaceCentreLabels()
182 Info << "Creating face centre labels " << endl;
183 const labelList& cubeLabel = *cubeLabelPtr_;
184 const VRWGraph& nodeLabels = octreeCheck_.nodeLabels();
185 const FRWGraph<label, 8>& pointLeaves = octreeCheck_.nodeLeaves();
186 const meshOctree& octree = octreeCheck_.octree();
190 Info << "Node labels " << nodeLabels << endl;
193 List<direction> nodeLevel(pointLeaves.size(), direction(0));
194 forAll(nodeLabels, leafI)
196 const direction level = octree.returnLeaf(leafI).level();
198 forAllRow(nodeLabels, leafI, nlI)
200 const label nLabel = nodeLabels(leafI, nlI);
202 Info << "Node label[" << leafI << "][" << nlI << "] "
206 if( nodeLevel[nLabel] < level )
207 nodeLevel[nLabel] = level;
211 if( !faceCentreLabelPtr_ )
212 faceCentreLabelPtr_ = new VRWGraph(cubeLabel.size());
213 VRWGraph& faceCentreLabel = *faceCentreLabelPtr_;
215 forAll(cubeLabel, cubeI)
216 if( cubeLabel[cubeI] != -1 )
218 const direction level = octree.returnLeaf(cubeI).level();
220 for(label i=0;i<6;++i)
223 (faceCentreLabel.sizeOfRow(cubeI) != 0) &&
224 (faceCentreLabel(cubeI, i) != -1)
228 FixedList<label, 4> faceNodes;
229 forAll(faceNodes, fnI)
231 meshOctreeCubeCoordinates::faceNodes_[i][fnI];
233 label highLevelNode(-1);
234 for(label j=0;j<4;++j)
235 if( nodeLevel[nodeLabels(cubeI, faceNodes[j])] > level )
241 if( highLevelNode == -1 )
244 DynList<label> neighbours;
245 octree.findNeighboursInDirection(cubeI, i, neighbours);
247 if( (neighbours.size() != 1) || (neighbours[0] == -1) )
250 if( faceCentreLabel.sizeOfRow(cubeI) == 0 )
252 faceCentreLabel.setRowSize(cubeI, 6);
253 forAllRow(faceCentreLabel, cubeI, colI)
254 faceCentreLabel(cubeI, colI) = -1;
256 const label cNei = neighbours[0];
257 if( faceCentreLabel.sizeOfRow(cNei) == 0 )
259 faceCentreLabel.setRowSize(cNei, 6);
260 forAllRow(faceCentreLabel, cNei, colI)
261 faceCentreLabel(cNei, colI) = -1;
264 faceCentreLabel(cubeI, i) = tetPoints_.size();
269 faceCentreLabel(cNei, 1) = tetPoints_.size();
273 faceCentreLabel(cNei, 0) = tetPoints_.size();
277 faceCentreLabel(cNei, 3) = tetPoints_.size();
281 faceCentreLabel(cNei, 2) = tetPoints_.size();
285 faceCentreLabel(cNei, 5) = tetPoints_.size();
289 faceCentreLabel(cNei, 4) = tetPoints_.size();
293 point p(vector::zero);
294 for(label j=0;j<4;++j)
295 p += tetPoints_[nodeLabels(cubeI, faceNodes[j])];
297 tetPoints_.append(p);
302 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
304 } // End namespace Foam
306 // ************************************************************************* //