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 "demandDrivenData.H"
30 #include "meshOctree.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 void tetCreatorOctree::createTetsAroundEdges()
43 Info << "Creating tets around edges" << endl;
45 const labelList& cubeLabel = *cubeLabelPtr_;
46 const VRWGraph& nodeLabels = octreeCheck_.nodeLabels();
47 const FRWGraph<label, 8>& pLeaves = octreeCheck_.nodeLeaves();
48 const VRWGraph& subNodeLabels = *subNodeLabelsPtr_;
49 const VRWGraph& faceCentreLabel = *faceCentreLabelPtr_;
50 const meshOctree& octree = octreeCheck_.octree();
51 const FixedList<FixedList<meshOctreeCubeCoordinates, 8>, 8>& vlPos =
52 octree.positionsOfLeavesAtNodes();
54 //- find maximum refinement level of octree leaves attached to each vertex
55 List<direction> nodeLevel(octreeCheck_.numberOfNodes());
57 forAll(pLeaves, nodeI)
61 for(label plI=0;plI<8;++plI)
63 const label leafI = pLeaves(nodeI, plI);
68 level = Foam::max(level, octree.returnLeaf(leafI).level());
71 nodeLevel[nodeI] = level;
74 //- start creating tets around edges which have both vertices at the same
75 //- refinement level which is equal to the max refinement level of boxes
76 //- incident to such edges
77 forAllReverse(sortedLeaves_, levelI)
79 const labelLongList& curLevelLeaves = sortedLeaves_[levelI];
81 forAll(curLevelLeaves, leafI)
83 const label curLeaf = curLevelLeaves[leafI];
85 if( cubeLabel[curLeaf] == -1 )
88 const meshOctreeCubeCoordinates& cc =
89 octree.returnLeaf(curLeaf).coordinates();
92 Info << "Search cube " << curLeaf << " has coordinates "
93 << octree.returnLeaf(curLeaf).coordinates() << endl;
94 Info << "Node labels for cube are " << nodeLabels[curLeaf] << endl;
97 //- start checking edges
98 for(label eI=0;eI<12;++eI)
100 const label startNode =
101 meshOctreeCubeCoordinates::edgeNodes_[eI][0];
103 const label start = nodeLabels(curLeaf, startNode);
108 meshOctreeCubeCoordinates::edgeNodes_[eI][1]
112 Info << "Creating tets around edge " << eI << endl;
113 Info << "Edge nodes are " << start << " and " << end << endl;
114 Info << "Coordinates start " << tetPoints_[start]
115 << " end " << tetPoints_[end] << endl;
121 (nodeLevel[start] == direction(levelI)) &&
122 (nodeLevel[end] == direction(levelI))
125 //- edge has both vertices at the same refinement level
126 //- as the current leaf
127 FixedList<label, 4> edgeCubes;
128 const label fI = 2*(eI/4)+1;
130 const label* fNodes =
131 meshOctreeCubeCoordinates::faceNodes_[fI];
133 //- store octree leaves at this edge
134 //- they are all adjacent to the start point
135 for(label i=0;i<4;++i)
136 edgeCubes[i] = pLeaves(start, fNodes[i]);
141 Info << "Cube " << i << " is " << edgeCubes[i] << endl;
143 if( edgeCubes[i] < 0 )
146 Info << "Cubes has node labels "
147 << nodeLabels[edgeCubes[i]] << endl;
151 DynList<label> centreNodes;
155 const label cLabel = edgeCubes[i];
157 if( (cLabel == -1) || (cubeLabel[cLabel] == -1) )
159 centreNodes.append(-1);
163 const meshOctreeCubeCoordinates& oc =
164 octree.returnLeaf(cLabel).coordinates();
167 Info << "Edge cube " << i << " is " << oc << endl;
168 Info << "Node labels ";
169 forAllRow(nodeLabels, cLabel, k)
170 Info << nodeLabels(cLabel, k) << " ";
174 if( oc.level() == direction(levelI) )
176 if( cLabel < curLeaf )
183 Info << "Adding centre label " << cubeLabel[cLabel]
187 centreNodes.append(cubeLabel[cLabel]);
189 //- adding face centre labels
190 if( faceCentreLabel.sizeOfRow(cLabel) != 0 )
192 const label helpFace = eI/4;
198 faceCentreHelper_[helpFace][i]
202 centreNodes.append(fcl);
206 Info << "Centre nodes after cube " << i
207 << " are " << centreNodes << endl;
210 else if( oc.level() < direction(levelI) )
213 Info << "Edge cube " << cLabel << endl;
214 Info << "cc " << cc << endl;
215 Info << "oc " << oc << endl;
216 Info << "Adding pos "
217 << vlPos[startNode][fNodes[i]] << endl;
220 const meshOctreeCubeCoordinates sc
222 cc + vlPos[startNode][fNodes[i]]
226 Info << "sc " << sc << endl;
231 for(label j=0;j<8;j++)
233 if( sc == oc.refineForPosition(j) )
243 "void tetCreatorOctree::"
244 "createTetsAroundEdges()"
245 ) << "Cannot find cube position"
246 << abort(FatalError);
249 Info << "Pos " << pos << endl;
252 centreNodes.append(subNodeLabels(cLabel, pos));
255 Info << "Centre node " << i << " is "
256 << subNodeLabels(cLabel, pos)
258 << tetPoints_[subNodeLabels(cLabel, pos)]
264 //- create tets around this edge
267 const label nCentres = centreNodes.size();
269 forAll(centreNodes, i)
271 if( centreNodes[i] == -1 )
273 if( centreNodes[(i+1)%nCentres] == -1 )
279 centreNodes[(i+1)%nCentres],
287 Info << "Last added tet "
288 << tets_.size()-1 <<" is "
289 << tets_[tets_.size()-1] << endl;
299 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
301 } // End namespace Foam
303 // ************************************************************************* //