Newer
Older
/*---------------------------------------------------------------------------*\
========= |
\\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
\\/ M anipulation | Copyright (C) Creative Fields, Ltd.
-------------------------------------------------------------------------------
License
cfMesh is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
cfMesh is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with cfMesh. If not, see <http://www.gnu.org/licenses/>.
Description
\*---------------------------------------------------------------------------*/
#include "meshOctreeCreator.H"
#include "triSurf.H"
#include "boundBox.H"
#include "demandDrivenData.H"
#include "objectRefinementList.H"
#include "VRWGraph.H"
#include "meshOctreeModifier.H"
#include "surfaceMeshGeometryModification.H"
# ifdef USE_OMP
# endif
//#define OCTREETiming
//#define DEBUGSearch
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void meshOctreeCreator::refineBoundary()
{
meshOctreeModifier octreeModifier(octree_);
const LongList<meshOctreeCube*>& leaves = octreeModifier.leavesAccess();
//- refine DATA boxes to the given level
Info << "Refining boundary boxes to the given size" << endl;
bool changed;
changed = false;
# ifdef OCTREETiming
const scalar startIter = omp_get_wtime();
# endif
labelList refineCubes(leaves.size(), 0);
scalarList rThickness(leaves.size(), 0.0);
# ifdef USE_OMP
# pragma omp parallel for schedule(dynamic, 100)
# endif
forAll(leaves, leafI)
{
const meshOctreeCube& oc = *leaves[leafI];
# ifdef DEBUGSearch
Info << "Checking leaf " << oc << endl;
Info << "Leaf has elements " << oc.hasContainedElements() << endl;
# endif
if( oc.hasContainedElements() )
{
const label elRowI = oc.containedElements();
const VRWGraph& containedTriangles =
oc.slotPtr()->containedTriangles_;
forAllRow(containedTriangles, elRowI, tI)
{
const label triI = containedTriangles(elRowI, tI);
if( surfRefLevel_[triI] > oc.level() )
{
refine = true;
}
if( surfRefThickness_[triI] > VSMALL )
{
useNLayers = true;
rThickness[leafI] =
rThickness[leafI],
surfRefThickness_[triI]
if( refine )
{
refineCubes[leafI] = 1;
changed = true;
//- mark additional boxes for refinement to achieve
//- correct refinement distance
reduce(useNLayers, maxOp<label>());
reduce(changed, maxOp<bool>());
if( useNLayers && changed )
octreeModifier.refineSelectedBoxesAndAdditionalLayers
(
refineCubes,
);
}
else if( changed )
{
//- refine boxes
octreeModifier.refineSelectedBoxes(refineCubes, hexRefinement_);
# ifdef OCTREETiming
const scalar refTime = omp_get_wtime();
Info << "Time for refinement " << (refTime-startIter) << endl;
# endif
if( Pstream::parRun() )
{
if( changed )
{
octreeModifier.distributeLeavesToProcessors();
# ifdef OCTREETiming
const scalar distTime = omp_get_wtime();
Info << "Time for distributing data to processors "
<< (distTime-refTime) << endl;
# endif
loadDistribution();
# ifdef OCTREETiming
Info << "Time for load distribution "
<< (omp_get_wtime()-distTime) << endl;
# endif
}
}
} while( changed );
Info << "Finished refining boundary boxes" << endl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void meshOctreeCreator::refineBoxesContainedInObjects()
{
if( !meshDictPtr_ || !meshDictPtr_->found("objectRefinements") )
{
return;
}
Info << "Refining boxes inside objects" << endl;
objectRefinementList refObjects;
if( meshDictPtr_->isDict("objectRefinements") )
{
const dictionary& dict = meshDictPtr_->subDict("objectRefinements");
const wordList objectNames = dict.toc();
refObjects.setSize(objectNames.size());
forAll(refObjects, objectI)
{
const entry& objectEntry =
dict.lookupEntry(objectNames[objectI], false, false);
refObjects.set
objectI,
objectRefinement::New
(
objectEntry.keyword(),
objectEntry.dict()
)
);
}
else
{
Istream& is = meshDictPtr_->lookup("objectRefinements");
PtrList<entry> objectEntries(is);
refObjects.setSize(objectEntries.size());
forAll(refObjects, objectI)
{
refObjects.set
(
objectI,
objectRefinement::New
(
objectEntries[objectI].keyword(),
objectEntries[objectI].dict()
)
);
}
objectEntries.clear();
}
coordinateModifier* cModPtr = NULL;
if( meshDictPtr_->found("anisotropicSources") )
{
cModPtr =
new coordinateModifier
(
meshDictPtr_->subDict("anisotropicSources")
);
}
//- calculate refinement levels
const scalar s(readScalar(meshDictPtr_->lookup("maxCellSize")));
List<direction> refLevels(refObjects.size(), globalRefLevel_);
//- calculate additional refinement levels from cell size
refObjects[oI].calculateAdditionalRefLevels(s);
refLevels[oI] += refObjects[oI].additionalRefinementLevels();
}
//- read refinement thickness
scalarList refThickness(refObjects.size(), 0.0);
forAll(refThickness, oI)
refThickness[oI] = refObjects[oI].refinementThickness();
forAll(refLevels, i)
Info << "Ref level for object " << refObjects[i].name()
<< " is " << label(refLevels[i])
<< " refinement thickness " << refThickness[i] << endl;
if( octree_.neiProcs().size() )
forAll(refObjects, oI)
{
label l = refLevels[oI];
reduce(l, maxOp<label>());
refLevels[oI] = l;
}
//- start refining boxes inside the objects
const boundBox& rootBox = octree_.rootBox();
meshOctreeModifier octreeModifier(octree_);
const LongList<meshOctreeCube*>& leaves = octreeModifier.leavesAccess();
bool changed;
do
{
# ifdef OCTREETiming
const scalar startIter = omp_get_wtime();
# endif
changed = false;
labelList refineCubes(leaves.size(), 0);
scalarList rThickness(leaves.size(), 0.0);
# ifdef USE_OMP
schedule(dynamic, 20)
# endif
forAll(leaves, leafI)
{
const meshOctreeCube& oc = *leaves[leafI];
if( oc.cubeType() & meshOctreeCubeBasic::OUTSIDE )
continue;
boundBox bb;
oc.cubeBox(rootBox, bb.min(), bb.max());
if( cModPtr )
{
//- transform bounding boxes into non-modified coordinates
bb.min() = cModPtr->backwardModifiedPoint(bb.min());
bb.max() = cModPtr->backwardModifiedPoint(bb.max());
}
{
# ifdef DEBUGSearch
Info << "Marking leaf " << leafI
<< " for refinement" << endl;
# endif
if( refThickness[oI] > VSMALL )
{
rThickness[leafI] =
Foam::max(rThickness[leafI], refThickness[oI]);
}
if( refine )
{
refineCubes[leafI] = 1;
changed = true;
}
}
//- mark additional boxes for refinement to achieve
//- correct refinement distance
reduce(useNLayers, maxOp<label>());
reduce(changed, maxOp<bool>());
if( useNLayers && changed )
octreeModifier.refineSelectedBoxesAndAdditionalLayers
(
refineCubes,
);
}
else if( changed )
{
//- refine boxes
octreeModifier.refineSelectedBoxes(refineCubes, hexRefinement_);
}
# ifdef OCTREETiming
const scalar refTime = omp_get_wtime();
Info << "Time for refinement " << (refTime-startIter) << endl;
# endif
if( octree_.neiProcs().size() != 0 )
{
if( changed )
{
octreeModifier.distributeLeavesToProcessors();
# ifdef OCTREETiming
const scalar distTime = omp_get_wtime();
Info << "Time for distributing data to processors "
<< (distTime-refTime) << endl;
# endif
loadDistribution(false);
# ifdef OCTREETiming
Info << "Time for load distribution "
<< (omp_get_wtime()-distTime) << endl;
# endif
}
}
} while( changed );
//- delete coordinate modifier if it exists
deleteDemandDrivenData(cModPtr);
Info << "Finished refinement of boxes inside objects" << endl;
//- set up inside-outside information
createInsideOutsideInformation();
}
void meshOctreeCreator::refineBoxesIntersectingSurfaces()
{
if( !meshDictPtr_ || !meshDictPtr_->found("surfaceMeshRefinement") )
{
return;
}
Info << "Refining boxes intersecting surface meshes" << endl;
label nMarked;
//- read surface meshes and calculate the refinement level for each
//- surface mesh
const dictionary& surfDict = meshDictPtr_->subDict("surfaceMeshRefinement");
const wordList surfaces = surfDict.toc();
PtrList<const triSurf> surfaceMeshesPtr(surfaces.size());
List<direction> refLevels(surfaces.size(), globalRefLevel_);
scalarList refThickness(surfaces.size(), 0.0);
forAll(surfaces, surfI)
{
const dictionary& dict = surfDict.subDict(surfaces[surfI]);
const fileName fName(dict.lookup("surfaceFile"));
if( meshDictPtr_->found("anisotropicSources") )
{
triSurf origSurf(fName);
surfaceMeshGeometryModification surfMod(origSurf, *meshDictPtr_);
surfaceMeshesPtr.set(surfI, surfMod.modifyGeometry());
}
else
{
surfaceMeshesPtr.set(surfI, new triSurf(fName));
}
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
direction addLevel(0);
if( dict.found("cellSize") )
{
scalar s(readScalar(meshDictPtr_->lookup("maxCellSize")));
const scalar cs = readScalar(dict.lookup("cellSize"));
do
{
nMarked = 0;
if( cs <= s * (1.+SMALL) )
{
++nMarked;
++addLevel;
}
s /= 2.0;
} while( nMarked != 0 );
}
else if( dict.found("additionalRefinementLevels") )
{
addLevel =
readLabel(dict.lookup("additionalRefinementLevels"));
}
if( dict.found("refinementThickness") )
{
refThickness[surfI] =
readScalar(dict.lookup("refinementThickness"));
}
//- set the refinement level for the current surface
refLevels[surfI] += addLevel;
}
if( octree_.neiProcs().size() )
forAll(refLevels, oI)
{
label l = refLevels[oI];
reduce(l, maxOp<label>());
refLevels[oI] = l;
}
//- start refining boxes intersecting triangles in each refinement surface
const boundBox& rootBox = octree_.rootBox();
const vector tol = SMALL * rootBox.span();
meshOctreeModifier octreeModifier(octree_);
const LongList<meshOctreeCube*>& leaves = octreeModifier.leavesAccess();
do
{
# ifdef OCTREETiming
const scalar startIter = omp_get_wtime();
# endif
labelList refineCubes(leaves.size(), 0);
scalarField rThickness(leaves.size(), 0.0);
forAll(surfaceMeshesPtr, surfI)
{
const triSurf& surf = surfaceMeshesPtr[surfI];
const pointField& points = surf.points();
const direction surfLevel = refLevels[surfI];
const scalar sThickness = refThickness[surfI];
# ifdef USE_OMP
# pragma omp parallel for \
reduction( + : nMarked) schedule(dynamic, 10) private(leavesInBox)
# endif
forAll(surf, triI)
{
//- find the bounding box of the current triangle
const labelledTri& tri = surf[triI];
boundBox triBB(points[tri[0]], points[tri[0]]);
for(label pI=1;pI<3;++pI)
{
triBB.min() = Foam::min(triBB.min(), points[tri[pI]]);
triBB.max() = Foam::max(triBB.max(), points[tri[pI]]);
}
triBB.min() -= tol;
triBB.max() += tol;
//- find octree leaves inside the bounding box
leavesInBox.clear();
octree_.findLeavesContainedInBox(triBB, leavesInBox);
//- check which of the leaves are intersected by the triangle
forAll(leavesInBox, i)
{
const label leafI = leavesInBox[i];
const meshOctreeCube& oc = *leaves[leafI];
if( oc.intersectsTriangleExact(surf, rootBox, triI) )
# ifdef DEBUGSearch
Info << "Marking leaf " << leafI
<< " with coordinates " << oc
<< " for refinement" << endl;
# endif
if( oc.level() < surfLevel )
{
//- mark boxes for refinement
if( sThickness > VSMALL )
{
useNLayers = true;
const scalar cs = oc.size(rootBox);
const label numLayers =
ceil(sThickness / cs);
nLayers[leafI] =
Foam::max
(
nLayers[leafI],
Foam::max(numLayers, 1)
);
//- mark additional boxes for refinement to achieve
//- correct refinement distance
reduce(useNLayers, maxOp<label>());
reduce(changed, maxOp<bool>());
if( useNLayers && changed )
octreeModifier.refineSelectedBoxesAndAdditionalLayers
}
else if( changed )
{
//- refine boxes
octreeModifier.refineSelectedBoxes(refineCubes, hexRefinement_);
}
# ifdef OCTREETiming
const scalar refTime = omp_get_wtime();
Info << "Time for refinement " << (refTime-startIter) << endl;
# endif
if( octree_.neiProcs().size() != 0 )
{
reduce(changed, maxOp<bool>());
if( changed )
{
octreeModifier.distributeLeavesToProcessors();
# ifdef OCTREETiming
const scalar distTime = omp_get_wtime();
Info << "Time for distributing data to processors "
<< (distTime-refTime) << endl;
# endif
loadDistribution(false);
# ifdef OCTREETiming
Info << "Time for load distribution "
<< (omp_get_wtime()-distTime) << endl;
# endif
}
}
Info << "Finished refinement of boxes intersecting surface meshes" << endl;
}
void meshOctreeCreator::refineBoxesIntersectingEdgeMeshes()
{
if( !meshDictPtr_ || !meshDictPtr_->found("edgeMeshRefinement") )
{
return;
}
Info << "Refining boxes intersecting edge meshes" << endl;
//- read edge meshes and calculate the refinement level for each
//- edge mesh
const dictionary& edgeDict = meshDictPtr_->subDict("edgeMeshRefinement");
const wordList edgeMeshNames = edgeDict.toc();
PtrList<const edgeMesh> edgeMeshesPtr(edgeMeshNames.size());
List<direction> refLevels(edgeMeshNames.size(), globalRefLevel_);
scalarList refThickness(edgeMeshNames.size(), 0.0);
//- load edge meshes into memory
{
const dictionary& dict = edgeDict.subDict(edgeMeshNames[emI]);
const fileName fName(dict.lookup("edgeFile"));
if( meshDictPtr_->found("anisotropicSources") )
{
edgeMesh origEdgeMesh(fName);
edgeMeshGeometryModification edgeMod(origEdgeMesh, *meshDictPtr_);
}
else
{
edgeMeshesPtr.set(emI, new edgeMesh(fName));
}
label nMarked;
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
direction addLevel(0);
if( dict.found("cellSize") )
{
scalar s(readScalar(meshDictPtr_->lookup("maxCellSize")));
const scalar cs = readScalar(dict.lookup("cellSize"));
do
{
nMarked = 0;
if( cs <= s * (1.+SMALL) )
{
++nMarked;
++addLevel;
}
s /= 2.0;
} while( nMarked != 0 );
}
else if( dict.found("additionalRefinementLevels") )
{
addLevel =
readLabel(dict.lookup("additionalRefinementLevels"));
}
if( dict.found("refinementThickness") )
{
refThickness[emI] =
readScalar(dict.lookup("refinementThickness"));
}
//- set the refinement level for the current mesh
refLevels[emI] += addLevel;
}
if( octree_.neiProcs().size() )
forAll(refLevels, oI)
{
label l = refLevels[oI];
reduce(l, maxOp<label>());
refLevels[oI] = l;
}
//- start refining boxes intersecting triangles in each refinement surface
const boundBox& rootBox = octree_.rootBox();
const vector tol = SMALL * rootBox.span();
meshOctreeModifier octreeModifier(octree_);
const LongList<meshOctreeCube*>& leaves = octreeModifier.leavesAccess();
DynList<label> leavesInBox, intersectedLeaves;
bool changed;
changed = false;
# ifdef OCTREETiming
const scalar startIter = omp_get_wtime();
# endif
labelList refineCubes(leaves.size(), 0);
scalarList rThickness(leaves.size(), 0.0);
bool useNLayers(false);
//- select boxes which need to be refined
{
const edgeMesh& edgeMesh = edgeMeshesPtr[emI];
const pointField& points = edgeMesh.points();
const edgeList& edges = edgeMesh.edges();
# ifdef USE_OMP
# pragma omp parallel for schedule(dynamic, 10) \
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
private(leavesInBox,intersectedLeaves)
# endif
forAll(edges, edgeI)
{
//- find the bounding box of the current triangle
const edge& e = edges[edgeI];
const point& sp = points[e.start()];
const point& ep = points[e.end()];
boundBox edgeBB(sp, ep);
edgeBB.min() -= tol;
edgeBB.max() += tol;
//- find octree leaves inside the bounding box
leavesInBox.clear();
octree_.findLeavesContainedInBox(edgeBB, leavesInBox);
//- check which of the leaves are intersected by the triangle
intersectedLeaves.clear();
forAll(leavesInBox, i)
{
const label leafI = leavesInBox[i];
const meshOctreeCube& oc = *leaves[leafI];
if( oc.intersectsLine(rootBox, sp, ep) )
{
intersectedLeaves.append(leafI);
if( oc.level() < refLevels[emI] )
{
# ifdef DEBUGSearch
Info << "Marking leaf " << leafI
<< " with coordinates " << oc
<< " for refinement" << endl;
# endif
refineCubes[leafI] = 1;
changed = true;
}
}
}
if( refThickness[emI] > VSMALL )
{
useNLayers = true;
forAll(intersectedLeaves, i)
{
const label leafI = intersectedLeaves[i];
rThickness[leafI] =
Foam::max(rThickness[leafI], refThickness[emI]);
}
}
}
}
//- mark additional boxes for refinement to achieve
//- correct refinement distance
reduce(useNLayers, maxOp<label>());
reduce(changed, maxOp<bool>());
if( useNLayers && changed )
octreeModifier.refineSelectedBoxesAndAdditionalLayers
(
refineCubes,
);
}
else if( changed )
{
//- refine boxes
octreeModifier.refineSelectedBoxes(refineCubes, hexRefinement_);
# ifdef OCTREETiming
const scalar refTime = omp_get_wtime();
Info << "Time for refinement " << (refTime-startIter) << endl;
# endif
if( octree_.neiProcs().size() != 0 )
{
if( changed )
{
octreeModifier.distributeLeavesToProcessors();
# ifdef OCTREETiming
const scalar distTime = omp_get_wtime();
Info << "Time for distributing data to processors "
<< (distTime-refTime) << endl;
# endif
loadDistribution(false);
# ifdef OCTREETiming
Info << "Time for load distribution "
<< (omp_get_wtime()-distTime) << endl;
# endif
}
}
} while( changed );
Info << "Finished refinement of boxes intersecting edge meshes" << endl;
void meshOctreeCreator::refineBoxesNearDataBoxes(const label nLayers)
{
# ifdef OCTREETiming
const scalar startTime = omp_get_wtime();
# endif
const FixedList<meshOctreeCubeCoordinates, 26>& rp =
octree_.regularityPositions();
Info << "Refining boxes near DATA boxes" << endl;
//- ensure one to one matching with unknown boxes
meshOctreeModifier octreeModifier(octree_);
const LongList<meshOctreeCube*>& leaves = octreeModifier.leavesAccess();
# ifdef DEBUGSearch
forAll(leaves, leafI)
Info << "Leaf " << leafI << " is " << *leaves[leafI]
<< " type " << label(leaves[leafI]->cubeType()) << endl;
# endif
labelList refineBox(leaves.size(), 0);
labelHashSet transferCoordinates;
LongList<meshOctreeCubeCoordinates> checkCoordinates;
# ifdef USE_OMP
# pragma omp parallel for if( leaves.size() > 1000 ) \
schedule(dynamic, 20)
# endif
forAll(leaves, leafI)
{
if( leaves[leafI]->hasContainedElements() )
{
const meshOctreeCube& oc = *leaves[leafI];
# ifdef DEBUGSearch
Info << "Refining boxes near box " << leafI
<< " with coordinates " << oc << endl;
# endif
for(label k=0;k<26;++k)
{
const label neiLabel =
octree_.findLeafLabelForPosition
(
oc.coordinates() + rp[k]
);
if( neiLabel == meshOctreeCube::OTHERPROC )
{
# ifdef USE_OMP
# endif
{
if( !transferCoordinates.found(leafI) )
{
transferCoordinates.insert(leafI);
checkCoordinates.append(oc.coordinates());
}
}
continue;
}
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
if( neiLabel == -1 )
continue;
const meshOctreeCube* nei = leaves[neiLabel];
if( nei->level() == oc.level() )
continue;
if( nei->cubeType() & meshOctreeCubeBasic::OUTSIDE )
continue;
# ifdef DEBUGSearch
Info << "Adding neighbour " << *nei << " of type"
<< label(nei->cubeType()) << endl;
# endif
refineBox[nei->cubeLabel()] = 1;
}
}
}
if( octree_.neiProcs().size() )
{
LongList<meshOctreeCubeCoordinates> receivedCoordinates;
octree_.exchangeRequestsWithNeighbourProcessors
(
checkCoordinates,
receivedCoordinates
);
# ifdef USE_OMP
# pragma omp parallel for if( receivedCoordinates.size() > 1000 ) \
schedule(dynamic, 20)
# endif
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
forAll(receivedCoordinates, ccI)
{
const meshOctreeCubeCoordinates& cc = receivedCoordinates[ccI];
for(label k=0;k<26;++k)
{
const label neiLabel =
octree_.findLeafLabelForPosition(cc + rp[k]);
if( neiLabel < 0 )
continue;
const meshOctreeCube* nei = leaves[neiLabel];
if( nei->level() == cc.level() )
continue;
if( nei->cubeType() & meshOctreeCubeBasic::OUTSIDE )
continue;
# ifdef DEBUGSearch
Info << "Adding neighbour " << *nei << " of type"
<< label(nei->cubeType()) << endl;
# endif
refineBox[nei->cubeLabel()] = 1;
}
}
}
{
if( Pstream::parRun() )
{
checkCoordinates.clear();
transferCoordinates.clear();
}
# ifdef USE_OMP
# pragma omp parallel for if( leaves.size() > 1000 ) \
schedule(dynamic, 20)
# endif
forAll(leaves, leafI)
{
if( refineBox[leafI] == i )
{
const meshOctreeCube& oc = *leaves[leafI];
# ifdef DEBUGSearch
Info << "Refining boxes near box " << leafI
<< " with coordinates " << oc << endl;
# endif
for(label k=0;k<26;++k)
{
const label neiLabel =
octree_.findLeafLabelForPosition
(
oc.coordinates() + rp[k]
);
if( neiLabel == meshOctreeCube::OTHERPROC )
{
# ifdef USE_OMP
# endif
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
{
if( !transferCoordinates.found(leafI) )
{
transferCoordinates.insert(leafI);
checkCoordinates.append(oc.coordinates());
}
}
continue;
}
if( neiLabel == -1 )
continue;
const meshOctreeCube* nei = leaves[neiLabel];
if( nei->level() == oc.level() )
continue;
if( nei->cubeType() & meshOctreeCubeBasic::OUTSIDE )
continue;
# ifdef DEBUGSearch
Info << "Layer " << label(i) << endl;
Info << "Adding neighbour " << *nei << " of type"
<< label(nei->cubeType()) << endl;
# endif
refineBox[nei->cubeLabel()] = i + 1;
}
}
}
if( octree_.neiProcs().size() )
{
LongList<meshOctreeCubeCoordinates> receivedCoordinates;
octree_.exchangeRequestsWithNeighbourProcessors
(
checkCoordinates,
receivedCoordinates
);
# ifdef USE_OMP
# pragma omp parallel for if( receivedCoordinates.size() > 1000 ) \
schedule(dynamic, 20)
# endif
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
forAll(receivedCoordinates, ccI)
{
const meshOctreeCubeCoordinates& cc = receivedCoordinates[ccI];
for(label k=0;k<26;++k)
{
const label neiLabel =
octree_.findLeafLabelForPosition(cc + rp[k]);
if( neiLabel < 0 )
continue;
const meshOctreeCube* nei = leaves[neiLabel];
if( nei->level() == cc.level() )
continue;
if( nei->cubeType() & meshOctreeCubeBasic::OUTSIDE )
continue;
# ifdef DEBUGSearch
Info << "Adding neighbour " << *nei << " of type"
<< label(nei->cubeType()) << endl;
# endif
refineBox[nei->cubeLabel()] = i + 1;
}
}
}
}
//- refine cubes
octreeModifier.refineSelectedBoxes(refineBox, hexRefinement_);
# ifdef OCTREETiming
const scalar refTime = omp_get_wtime();
Info << "Time for refinement " << (refTime-startTime) << endl;
# endif
if( Pstream::parRun() )
{
octreeModifier.distributeLeavesToProcessors();
loadDistribution();
}
# ifdef OCTREETiming
const scalar distTime = omp_get_wtime();
Info << "Time for load balancing " << (distTime-refTime) << endl;
# endif
//- set up inside-outside information
createInsideOutsideInformation();
# ifdef OCTREETiming
Info << "Time for calculation of inside/outside information "
<< (omp_get_wtime()-distTime) << endl;
# endif
Info << "Finished refining boxes near DATA boxes" << endl;
}
void meshOctreeCreator::refineBoxes
(
const direction refLevel,
const direction cubeType
)
{
label nRefined;
meshOctreeModifier octreeMod(octree_);
do
{
# ifdef OCTREETiming
const scalar startIter = omp_get_wtime();
# endif
nRefined = 0;
const LongList<meshOctreeCube*>& leaves = octreeMod.leavesAccess();
labelList refineCubes(leaves.size(), direction(0));
# ifdef USE_OMP
# pragma omp parallel for if( leaves.size() > 1000 ) \
reduction(+ : nRefined) schedule(dynamic, 20)
# endif
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
forAll(leaves, leafI)
{
const meshOctreeCube& oc = *leaves[leafI];
if( (oc.cubeType() & cubeType) && (oc.level() < refLevel) )
{
refineCubes[leafI] = 1;
++nRefined;
}
}
//- refine selected cubes
octreeMod.refineSelectedBoxes(refineCubes, hexRefinement_);
# ifdef OCTREETiming
const scalar refTime = omp_get_wtime();
Info << "Time for refinement " << (refTime-startIter) << endl;
# endif
if( Pstream::parRun() )
{
reduce(nRefined, sumOp<label>());
if( nRefined )
{
octreeMod.distributeLeavesToProcessors();
# ifdef OCTREETiming
const scalar distTime = omp_get_wtime();
Info << "Time for distributing data to processors "
<< (distTime-refTime) << endl;
# endif
loadDistribution();
# ifdef OCTREETiming
Info << "Time for load distribution "
<< (omp_get_wtime()-distTime) << endl;
# endif
}
}
} while( nRefined != 0 );
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //