Commit 243c27d5 authored by Franjo's avatar Franjo
Browse files

Polished version

parent c888040e
......@@ -73,7 +73,6 @@ void meshOctreeCreator::refineBoundary()
labelList refineCubes(leaves.size(), 0);
scalarList rThickness(leaves.size(), 0.0);
List<direction> targetLevel(leaves.size(), direction(0));
bool useNLayers(false);
//- select boxes which need to be refined
......@@ -114,9 +113,6 @@ void meshOctreeCreator::refineBoundary()
rThickness[leafI],
surfRefThickness_[triI]
);
targetLevel[leafI] =
Foam::max(targetLevel[leafI], surfRefLevel_[triI]);
}
}
......@@ -137,8 +133,7 @@ void meshOctreeCreator::refineBoundary()
octreeModifier.refineSelectedBoxesAndAdditionalLayers
(
refineCubes,
rThickness,
targetLevel
rThickness
);
}
else if( changed )
......@@ -296,7 +291,6 @@ void meshOctreeCreator::refineBoxesContainedInObjects()
labelList refineCubes(leaves.size(), 0);
scalarList rThickness(leaves.size(), 0.0);
List<direction> targetRefLevel(leaves.size(), direction(0));
bool useNLayers(false);
//- select boxes which need to be refined
......@@ -339,8 +333,6 @@ void meshOctreeCreator::refineBoxesContainedInObjects()
rThickness[leafI] =
Foam::max(rThickness[leafI], refThickness[oI]);
targetRefLevel[leafI] =
Foam::max(targetRefLevel[leafI], refLevels[oI]);
useNLayers = true;
}
}
......@@ -362,8 +354,7 @@ void meshOctreeCreator::refineBoxesContainedInObjects()
octreeModifier.refineSelectedBoxesAndAdditionalLayers
(
refineCubes,
rThickness,
targetRefLevel
rThickness
);
}
else if( changed )
......@@ -509,7 +500,6 @@ void meshOctreeCreator::refineBoxesIntersectingSurfaces()
labelList refineCubes(leaves.size(), 0);
labelList nLayers(leaves.size(), 0);
List<direction> targetRefLevel(leaves.size(), direction(0));
scalarField rThickness(leaves.size(), 0.0);
bool useNLayers(false);
......@@ -582,14 +572,9 @@ void meshOctreeCreator::refineBoxesIntersectingSurfaces()
Foam::max(numLayers, 1)
);
rThickness[leafI] = max(rThickness[leafI], sThickness);
rThickness[leafI] =
max(rThickness[leafI], sThickness);
targetRefLevel[leafI] =
Foam::max
(
targetRefLevel[leafI],
surfLevel
);
}
}
}
......@@ -606,12 +591,8 @@ void meshOctreeCreator::refineBoxesIntersectingSurfaces()
octreeModifier.refineSelectedBoxesAndAdditionalLayers
(
refineCubes,
rThickness,
targetRefLevel
rThickness
);
if( nMarked != 0 )
changed = true;
}
else if( changed )
{
......@@ -750,7 +731,6 @@ void meshOctreeCreator::refineBoxesIntersectingEdgeMeshes()
labelList refineCubes(leaves.size(), 0);
scalarList rThickness(leaves.size(), 0.0);
List<direction> targetRefLevel(leaves.size(), direction(0));
bool useNLayers(false);
//- select boxes which need to be refined
......@@ -817,13 +797,6 @@ void meshOctreeCreator::refineBoxesIntersectingEdgeMeshes()
rThickness[leafI] =
Foam::max(rThickness[leafI], refThickness[emI]);
targetRefLevel[leafI] =
Foam::max
(
targetRefLevel[leafI],
refLevels[emI]
);
}
}
}
......@@ -838,8 +811,7 @@ void meshOctreeCreator::refineBoxesIntersectingEdgeMeshes()
octreeModifier.refineSelectedBoxesAndAdditionalLayers
(
refineCubes,
rThickness,
targetRefLevel
rThickness
);
}
else if( changed )
......
......@@ -160,8 +160,7 @@ public:
void refineSelectedBoxesAndAdditionalLayers
(
labelList& refineBox,
const scalarList& refThickness,
const List<direction>& targetRefLevel
const scalarList& refThickness
);
// functions for parallel runs
......
......@@ -499,8 +499,7 @@ void meshOctreeModifier::refineSelectedBoxes
void meshOctreeModifier::refineSelectedBoxesAndAdditionalLayers
(
labelList& refineBox,
const scalarList& refThickness,
const List<direction>& targetRefLevel
const scalarList& refThickness
)
{
const LongList<meshOctreeCube*>& leaves = octree_.leaves_;
......@@ -510,32 +509,46 @@ void meshOctreeModifier::refineSelectedBoxesAndAdditionalLayers
lMap leavesMap;
# ifdef DEBUGSearch
Info << "Marking additional layers " << endl;
Info << "Refining leaves and additional layers" << endl;
# endif
LongList<meshOctreeCube*> refLeaves;
//- find the maximum refinement level of leaves marked for refinement
direction maxLevel(0);
# ifdef USE_OMP
# pragma omp parallel
{
direction localMax(0);
forAll(refineBox, leafI)
{
if( refineBox[leafI] )
localMax = Foam::max(localMax, leaves[leafI]->level());
}
# pragma omp critical
maxLevel = Foam::max(maxLevel, localMax);
}
# else
forAll(refineBox, leafI)
{
if( refineBox[leafI] )
{
//const scalar cs = leaves[leafI]->size(octree_.rootBox());
maxLevel = Foam::max(maxLevel, leaves[leafI]->level());
refLeaves.append(leaves[leafI]);
//refNLayers.append(Foam::max(ceil(refThickness[leafI]/cs), 1));
}
}
# endif
label ml = maxLevel;
reduce(ml, maxOp<label>());
maxLevel = ml;
//- sort leaves based on the current level
Info << "Max level " << ml << endl;
List<labelLongList> leavesForLevel(maxLevel+1);
forAll(refLeaves, i)
forAll(refineBox, leafI)
{
leavesForLevel[refLeaves[i]->level()].append(refLeaves[i]->cubeLabel());
if( !refineBox[leafI] )
continue;
leavesForLevel[leaves[leafI]->level()].append(leafI);
}
//- find leaves with the same number of additional layers
......@@ -548,6 +561,27 @@ void meshOctreeModifier::refineSelectedBoxesAndAdditionalLayers
labelLongList nLayersForActive(activeLeaves.size());
label maxNLayers(0);
# ifdef USE_OMP
# pragma omp parallel
{
label localMaxNLayers(0);
forAll(activeLeaves, i)
{
const label leafI = activeLeaves[i];
const scalar cs = leaves[leafI]->size(octree_.rootBox());
nLayersForActive[i] = Foam::max(ceil(refThickness[leafI]/cs), 1);
localMaxNLayers =
Foam::max(localMaxNLayers, nLayersForActive[i]);
}
# pragma omp critical
maxNLayers = Foam::max(maxNLayers, localMaxNLayers);
}
# else
forAll(activeLeaves, i)
{
const label leafI = activeLeaves[i];
......@@ -558,6 +592,7 @@ void meshOctreeModifier::refineSelectedBoxesAndAdditionalLayers
maxNLayers = Foam::max(maxNLayers, nLayersForActive[i]);
}
# endif
for(label layerI=0;layerI<=maxNLayers;++layerI)
{
......@@ -584,9 +619,11 @@ void meshOctreeModifier::refineSelectedBoxesAndAdditionalLayers
if( returnReduce(selectedLeaves.size(), sumOp<label>()) == 0 )
continue;
# ifdef DEBUGSearch
Info << "Target level " << label(levelI) << endl;
Info << "Target num layer " << nLayers << endl;
Info << "Num selected leaves " << selectedLeaves.size() << endl;
# endif
label nMarked;
do
......@@ -603,8 +640,6 @@ void meshOctreeModifier::refineSelectedBoxesAndAdditionalLayers
{
if( !selectedLeaves[i]->isLeaf() )
continue;
//if( selectedLeaves[i]->level() > levelI )
// continue;
markedLeaves[selectedLeaves[i]->cubeLabel()] = 1;
++nMarked;
......@@ -635,11 +670,23 @@ void meshOctreeModifier::refineSelectedBoxesAndAdditionalLayers
# endif
forAll(activeLeaves, i)
{
if( leaves[activeLeaves[i]]->level() < levelI )
const direction level = leaves[activeLeaves[i]]->level();
if( level < levelI )
{
//- found a neighbour at a lower refinement level
hasLowerLevel = true;
}
else if( level > levelI )
{
//- do not allow refinement of leaves at higher
//- refinement level
markedLeaves[activeLeaves[i]] = 0;
}
}
//- deselect leaves at larger levels
reduce(hasLowerLevel, maxOp<bool>());
//- deselect leaves at the current level
if( hasLowerLevel )
{
# ifdef USE_OMP
......@@ -653,12 +700,9 @@ void meshOctreeModifier::refineSelectedBoxesAndAdditionalLayers
}
//- refine selected octree boxes
Info << "Refining leaves" << endl;
refineSelectedBoxes(markedLeaves);
} while( nMarked );
}
Info << "Finished refining leaves" << endl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment