65 for(
label i=1;i<=nLayers;++i)
69 transferCoordinates.
clear();
73 if( refineBox[leafI] == i )
74 activeLeaves.
append(leafI);
77 # pragma omp parallel for private(neiLeaves) schedule(dynamic, 20)
81 const label leafI = activeLeaves[lI];
86 octree_.findAllLeafNeighbours(oc, neiLeaves);
90 const label neiLabel = neiLeaves[posI];
98 if( !transferCoordinates.
found(leafI) )
100 processorChecks.
append(oc);
101 transferCoordinates.
insert(leafI);
111 if( !refineBox[neiLabel] )
112 refineBox[neiLabel] = i+1;
116 if( octree_.neiProcs().size() )
119 octree_.exchangeRequestsWithNeighbourProcessors
127 # pragma omp parallel for if( receivedCoords.size() > 1000 ) \
128 schedule(dynamic, 20) private(neiLeaves)
130 forAll(receivedCoords, ccI)
132 octree_.findAllLeafNeighbours(receivedCoords[ccI], neiLeaves);
136 if( neiLeaves[posI] < 0 )
139 if( !refineBox[neiLeaves[posI]] )
140 refineBox[neiLeaves[posI]] = i+1;
160 for(
label i=1;i<=nLayers;++i)
164 transferCoordinates.
clear();
168 if( refineBox[leafI] == i )
169 activeLeaves.
append(leafI);
172 # pragma omp parallel for private(neiLeaves) schedule(dynamic, 20)
176 const label leafI = activeLeaves[lI];
181 octree_.findNeighboursForLeaf(oc, neiLeaves);
185 const label neiLabel = neiLeaves[posI];
190 # pragma omp critical
193 if( !transferCoordinates.
found(leafI) )
195 processorChecks.
append(oc);
196 transferCoordinates.
insert(leafI);
206 if( !refineBox[neiLabel] )
207 refineBox[neiLabel] = i+1;
211 if( octree_.neiProcs().size() )
214 octree_.exchangeRequestsWithNeighbourProcessors
222 # pragma omp parallel for if( receivedCoords.size() > 1000 ) \
223 schedule(dynamic, 20) private(neiLeaves)
225 forAll(receivedCoords, ccI)
228 octree_.findNeighboursForLeaf(receivedCoords[ccI], neiLeaves);
232 if( neiLeaves[posI] < 0 )
235 if( !refineBox[neiLeaves[posI]] )
236 refineBox[neiLeaves[posI]] = i+1;
254 forAll(markedBoxes, leafI)
255 if( markedBoxes[leafI] == layer )
256 activeLeaves.
append(leafI);
261 file <<
"# vtk DataFile Version 3.0\n";
262 file <<
"vtk output\n";
264 file <<
"DATASET POLYDATA\n";
267 file <<
"POINTS " << (8 * activeLeaves.
size()) <<
" float\n";
270 const label leafI = activeLeaves[i];
276 const point&
p = vertices[vI];
278 file <<
p.x() <<
' ' <<
p.y() <<
' ' <<
p.z() <<
nl;
283 file <<
"\nPOLYGONS " << (6*activeLeaves.
size())
284 <<
" " << 30*activeLeaves.
size() <<
nl;
287 const label startNode = 8 * i;
288 for(
label fI=0;fI<6;++fI)
292 for(
label pI=0;pI<4;++pI)
313 Info <<
"Marking additional layers " <<
endl;
323 if( nLayers[leafI] < 1 )
326 leavesForLayer[nLayers[leafI]].
append(leafI);
343 # pragma omp parallel
349 # pragma omp for schedule(dynamic, 50)
355 # pragma omp critical
365 for(
direction levelI=maxLevel;levelI>0;--levelI)
371 # pragma omp parallel for reduction(+:counter)
375 const label leafI = activeLeaves[lI];
377 if( targetRefLevel[leafI] == levelI )
379 markedBoxes[leafI] = 1;
388 markAdditionalLayersOfFaceNeighbours(markedBoxes, layerI);
391 for(
label i=1;i<(layerI+1);++i)
394 writeLeaves(fName, octree_, markedBoxes, i);
397 Info <<
"LayerI " << layerI <<
endl;
402 # pragma omp parallel for schedule(dynamic, 100) \
405 forAll(markedBoxes, leafI)
407 if( markedBoxes[leafI] < 2 )
410 if( leaves[leafI]->level() >= levelI )
413 if( !refineBox[leafI] )
415 refineBox[leafI] |= 1;
430 const bool hexRefinement
434 const scalar
startTime = omp_get_wtime();
440 ensureCorrectRegularity(refineBox);
441 }
while( hexRefinement && ensureCorrectRegularitySons(refineBox) );
444 const scalar regTime = omp_get_wtime();
449 const boundBox& rootBox = octree_.rootBox();
459 # pragma omp parallel num_threads(octree_.dataSlots_.size())
463 meshOctreeSlot* slotPtr = &octree_.dataSlots_[omp_get_thread_num()];
468 if( !octree_.isQuadtree() )
471 # pragma omp for schedule(dynamic, 100)
475 if( refineBox[leafI] )
476 leaves[leafI]->refineCube(
surface, rootBox, slotPtr);
482 # pragma omp for schedule(dynamic, 100)
486 if( refineBox[leafI] )
487 leaves[leafI]->refineCube2D(
surface, rootBox, slotPtr);
492 createListOfLeaves();
495 Info <<
"Time for actual refinement " << (omp_get_wtime()-regTime) <<
endl;
507 typedef std::pair<direction, label> mapKey;
508 typedef std::map<mapKey, LongList<meshOctreeCube*> > lMap;
512 Info <<
"Refining leaves and additional layers" <<
endl;
519 # pragma omp parallel
525 if( refineBox[leafI] )
529 # pragma omp critical
535 if( refineBox[leafI] )
536 maxLevel =
Foam::max(maxLevel, leaves[leafI]->level());
548 if( !refineBox[leafI] )
551 leavesForLevel[leaves[leafI]->level()].
append(leafI);
565 # pragma omp parallel
567 label localMaxNLayers(0);
571 const label leafI = activeLeaves[i];
573 const scalar cs = leaves[leafI]->
size(octree_.rootBox());
575 nLayersForActive[i] =
Foam::max(ceil(refThickness[leafI]/cs), 1);
578 Foam::max(localMaxNLayers, nLayersForActive[i]);
581 # pragma omp critical
582 maxNLayers =
Foam::max(maxNLayers, localMaxNLayers);
587 const label leafI = activeLeaves[i];
589 const scalar cs = leaves[leafI]->
size(octree_.rootBox());
591 nLayersForActive[i] =
Foam::max(ceil(refThickness[leafI]/cs), 1);
593 maxNLayers =
Foam::max(maxNLayers, nLayersForActive[i]);
600 for(
label layerI=0;layerI<=maxNLayers;++layerI)
602 mapKey key(levelI, layerI);
609 mapKey key(levelI, nLayersForActive[i]);
610 leavesMap[key].append(leaves[activeLeaves[i]]);
617 const label nLayers = it->first.second;
618 const direction levelI = it->first.first;
627 Info <<
"Target num layer " << nLayers <<
endl;
628 Info <<
"Num selected leaves " << selectedLeaves.
size() <<
endl;
640 # pragma omp parallel for schedule(dynamic, 50) reduction(+:nMarked)
644 if( !selectedLeaves[i]->isLeaf() )
647 markedLeaves[selectedLeaves[i]->cubeLabel()] = 1;
658 markAdditionalLayers(markedLeaves, nLayers);
662 forAll(markedLeaves, leafI)
664 if( markedLeaves[leafI] )
665 activeLeaves.
append(leafI);
669 bool hasLowerLevel(
false);
672 # pragma omp parallel for schedule(guided)
676 const direction level = leaves[activeLeaves[i]]->level();
680 hasLowerLevel =
true;
682 else if( level > levelI )
686 markedLeaves[activeLeaves[i]] = 0;
696 # pragma omp parallel for schedule(guided)
700 if( leaves[activeLeaves[i]]->level() == levelI )
701 markedLeaves[activeLeaves[i]] = 0;
706 refineSelectedBoxes(markedLeaves);