Commit 88a13ccc authored by franjo_j@hotmail.com's avatar franjo_j@hotmail.com
Browse files

Work in progress on 2D cartesian mesher


git-svn-id: https://pl5.projectlocker.com/igui/meshGeneration/svn@41 fdcce57e-7e00-11e2-b579-49867b4cea03
parent 986e46ff
......@@ -41,16 +41,18 @@ void cartesianMeshExtractor::createPointsAndAddressing()
{
Info << "Creating octree vertices" << endl;
Info << "Octree nodes " << octreeCheck_.numberOfNodes() << endl;
//- set the size of the point field
pointFieldPMG& points = mesh_.points();
points.setSize(octreeCheck_.numberOfNodes());
//- store vertices into the pointField
const pointField& octreePoints = octreeCheck_.octreePoints();
forAll(points, pointI)
points[pointI] = octreePoints[pointI];
Info << "Finished creating octree vertices" << endl;
}
......
......@@ -34,8 +34,7 @@ Description
#include "gzstream.h"
#include "meshOctree.H"
#include "meshOctreeCreator.H"
#include "triSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -43,7 +43,7 @@ namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from surface
meshOctree::meshOctree(const triSurf& ts)
meshOctree::meshOctree(const triSurf& ts, const bool isQuadtree)
:
surface_(ts),
neiProcs_(),
......@@ -57,7 +57,8 @@ meshOctree::meshOctree(const triSurf& ts)
vrtLeavesPos_(),
regularityPositions_(),
dataSlots_(),
leaves_()
leaves_(),
isQuadtree_(isQuadtree)
{
Info << "Constructing octree" << endl;
......@@ -227,15 +228,30 @@ void meshOctree::createInitialOctreeBox()
meshOctreeSlot* slotPtr = &dataSlots_[0];
slotPtr->cubes_.append
(
meshOctreeCube
if( !isQuadtree_ )
{
slotPtr->cubes_.append
(
meshOctreeCube
(
meshOctreeCubeCoordinates(0, 0, 0, 0),
surface_.size(),
slotPtr
)
);
}
else
{
slotPtr->cubes_.append
(
meshOctreeCubeCoordinates(0, 0, 0, 0),
surface_.size(),
slotPtr
)
);
meshOctreeCube
(
meshOctreeCubeCoordinates(0, 0, -10, 0),
surface_.size(),
slotPtr
)
);
}
initialCubePtr_ = &slotPtr->cubes_[0];
......
......@@ -90,6 +90,9 @@ class meshOctree
//- list of cubes which are leaves of the octree
LongList<meshOctreeCube*> leaves_;
//- a flag whether is true if is it a quadtree
bool isQuadtree_;
// Private member functions
//- set data needed for finding neighbours
void setOctantVectorsAndPositions();
......@@ -124,7 +127,7 @@ public:
// Constructors
//- Construct from surface
meshOctree(const triSurf&);
meshOctree(const triSurf&, const bool isQuadtree = false);
// Destructor
......@@ -136,6 +139,9 @@ public:
//- find a cube containing the vertex
label findLeafContainingVertex(const point&) const;
//- is octree a quadtree or an octree
inline bool isQuadtree() const;
//- return octant vectors
inline const FixedList<Vector<label>, 8>& octantVectors() const;
......
......@@ -309,6 +309,7 @@ void meshOctreeAddressing::findUsedBoxes() const
if(
!octree_.hasContainedTriangles(leafI) &&
!octree_.hasContainedEdges(leafI) &&
(leaf.cubeType() & meshOctreeCubeBasic::INSIDE)
)
boxType[leafI] |= MESHCELL;
......@@ -341,7 +342,10 @@ void meshOctreeAddressing::findUsedBoxes() const
forAll(boxType, leafI)
{
if( octree_.hasContainedTriangles(leafI) )
if(
octree_.hasContainedTriangles(leafI) ||
octree_.hasContainedEdges(leafI)
)
boxType[leafI] |= MESHCELL;
}
......
......@@ -128,6 +128,15 @@ public:
~meshOctreeCube();
// Member Functions
//- refine cube in two directions, it is used for generating quadtrees
void refineCube2D
(
const triSurf&,
const boundBox&,
meshOctreeSlot* slotPtr = NULL
);
//- subdivide the octree cube
void refineCube
(
......
......@@ -110,7 +110,7 @@ inline meshOctreeCubeCoordinates meshOctreeCubeCoordinates::refineForPosition
(
2*posX_+addPos[0],
2*posY_+addPos[1],
2*posZ_+addPos[2],
posZ_<0?posZ_:2*posZ_+addPos[2],
level_+1
);
}
......@@ -126,7 +126,7 @@ inline meshOctreeCubeCoordinates meshOctreeCubeCoordinates::reduceLevelBy
(
posX_ / divider,
posY_ / divider,
posZ_ / divider,
posZ_<0?posZ_:posZ_ / divider,
level_ - diff
);
}
......@@ -151,7 +151,7 @@ inline meshOctreeCubeCoordinates meshOctreeCubeCoordinates::increaseToLevelMin
(
posX_ << diff,
posY_ << diff,
posZ_ << diff,
posZ_<0?posZ_:posZ_ << diff,
l
);
}
......@@ -166,7 +166,7 @@ inline meshOctreeCubeCoordinates meshOctreeCubeCoordinates::increaseToLevelMax
(
((posX_ + 1) << diff) - 1,
((posY_ + 1) << diff) - 1,
((posZ_ + 1) << diff) - 1,
posZ_<0?posZ_:((posZ_ + 1) << diff) - 1,
l
);
}
......@@ -178,11 +178,24 @@ inline void meshOctreeCubeCoordinates::cubeBox
point& max
) const
{
const vector dc = (rootBox.max() - rootBox.min()) / (1 << level_);
vector dc = (rootBox.max() - rootBox.min());
const label shift = 1 << level_;
dc.x() /= shift;
dc.y() /= shift;
if( posZ_>=0 )
dc.z() /= shift;
min.x() = rootBox.min().x() + dc.x() * this->posX();
min.y() = rootBox.min().y() + dc.y() * this->posY();
min.z() = rootBox.min().z() + dc.z() * this->posZ();
if( posZ_ >= 0 )
{
min.z() = rootBox.min().z() + dc.z() * this->posZ();
}
else
{
min.z() = rootBox.min().z();
}
max = min + dc;
}
......
......@@ -29,7 +29,7 @@ Description
#include "meshOctreeCube.H"
#include "demandDrivenData.H"
#include "Ostream.H"
#include "../meshOctree.H"
#include "meshOctree.H"
//#define DEBUGSearch
......
......@@ -97,6 +97,127 @@ void meshOctreeCube::findContainedEdges
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void meshOctreeCube::refineCube2D
(
const triSurf& surface,
const boundBox& rootBox,
meshOctreeSlot* slotPtr
)
{
if( !slotPtr )
slotPtr = activeSlotPtr_;
# ifdef DEBUGSearch
Info << "Refining the cube " << *this << endl;
# endif
//- set the cube label to -1
cubeLabel_ = -1;
//- create subCubes
FixedList<meshOctreeCube*, 8> subCubes;
forAll(subCubes, scI)
subCubes[scI] = NULL;
//- create new cubes in the Z-order fashion
for(label scI=0;scI<4;++scI)
{
const label cubeI = slotPtr->cubes_.size();
const meshOctreeCubeCoordinates cc = this->refineForPosition(scI);
slotPtr->cubes_.append(cc);
subCubes[scI] = &slotPtr->cubes_[cubeI];
subCubes[scI]->activeSlotPtr_ = slotPtr;
subCubes[scI]->setCubeType(this->cubeType());
subCubes[scI]->setProcNo(this->procNo());
}
const label subCubesLabel = slotPtr->childCubes_.size();
slotPtr->childCubes_.appendFixedList(subCubes);
subCubesPtr_ = &slotPtr->childCubes_(subCubesLabel, 0);
if( hasContainedElements() )
{
const VRWGraph& containedElements =
activeSlotPtr_->containedTriangles_;
# ifdef DEBUGSearch
Info << "Distributing contained elements "
<< containedElements[containedElementsLabel_] << endl;
# endif
//- check if the subCube contain the element
FixedList<DynList<label, 512>, 4> elementsInSubCubes;
forAllRow(containedElements, containedElementsLabel_, tI)
{
const label elI = containedElements(containedElementsLabel_, tI);
bool used(false);
for(label scI=0;scI<4;++scI)
if(
subCubes[scI]->intersectsTriangleExact
(
surface,
rootBox,
elI
)
)
{
used = true;
elementsInSubCubes[scI].append(elI);
}
if( !used )
{
Warning << "Triangle " << elI
<< " is not transferred to the child cubes!" << endl;
}
}
forAll(elementsInSubCubes, scI)
{
const DynList<label, 512>& elmts = elementsInSubCubes[scI];
if( elmts.size() != 0 )
{
VRWGraph& ct = slotPtr->containedTriangles_;
subCubes[scI]->containedElementsLabel_ = ct.size();
ct.appendList(elmts);
# ifdef DEBUGSearch
Info << "Elements in leaf " << scI << " are "
<< ct[subCubes[scI]->containedElements()]
<< endl;
# endif
}
}
//- find surface edges within the cube
for(label scI=0;scI<4;++scI)
if( subCubes[scI]->hasContainedElements() )
{
subCubes[scI]->findContainedEdges
(
surface,
rootBox
);
}
else if( subCubes[scI]->cubeType() & DATA )
{
subCubes[scI]->setCubeType(UNKNOWN);
}
}
# ifdef DEBUGSearch
for(label scI=0;scI<4;++scI)
Info << "Refined cube " << scI << " is "
<< *subCubes[scI] << endl;
# endif
}
void meshOctreeCube::refineCube
(
const triSurf& surface,
......
......@@ -34,6 +34,11 @@ Description
namespace Foam
{
inline bool meshOctree::isQuadtree() const
{
return isQuadtree_;
}
//- return octant vectors
inline const FixedList<Vector<label>, 8>& meshOctree::octantVectors() const
{
......
......@@ -137,6 +137,7 @@ public:
void refineSelectedBoxes
(
List<direction>& refineBox,
const bool quadtreeRefinement = false,
const bool hexRefinement = false
);
......
......@@ -164,6 +164,7 @@ void meshOctreeModifier::markAdditionalLayers
void meshOctreeModifier::refineSelectedBoxes
(
List<direction>& refineBox,
const bool quadtreeRefinement,
const bool hexRefinement
)
{
......@@ -202,14 +203,27 @@ void meshOctreeModifier::refineSelectedBoxes
meshOctreeSlot* slotPtr = &octree_.dataSlots_[0];
# endif
# ifdef USE_OMP
# pragma omp for \
schedule(dynamic,Foam::min(20, leaves.size()/omp_get_num_threads() + 1))
# endif
forAll(leaves, leafI)
if( !octree_.isQuadtree() )
{
if( refineBox[leafI] )
leaves[leafI]->refineCube(surface, rootBox, slotPtr);
# ifdef USE_OMP
# pragma omp for schedule(dynamic, 100)
# endif
forAll(leaves, leafI)
{
if( refineBox[leafI] )
leaves[leafI]->refineCube(surface, rootBox, slotPtr);
}
}
else
{
# ifdef USE_OMP
# pragma omp for schedule(dynamic, 100)
# endif
forAll(leaves, leafI)
{
if( refineBox[leafI] )
leaves[leafI]->refineCube2D(surface, rootBox, slotPtr);
}
}
}
......
......@@ -73,7 +73,7 @@ label meshOctree::findLeafContainingVertex
scI |= 1;
if( p.y() >= c.y() )
scI |= 2;
if( p.z() >= c.z() )
if( !isQuadtree_ && p.z() >= c.z() )
scI |= 4;
oc = oc->subCube(scI);
......@@ -98,17 +98,18 @@ label meshOctree::findNeighbourOverNode
const label nodeI
) const
{
const meshOctreeCubeCoordinates coords(cc + regularityPositions_[18+nodeI]);
const meshOctreeCubeCoordinates nc(cc + regularityPositions_[18+nodeI]);
const meshOctreeCube* nei = findCubeForPosition(coords);
const meshOctreeCube* nei = findCubeForPosition(nc);
if( !nei )
{
const label levelLimiter = (1 << cc.level());
if(
(coords.posX() >= levelLimiter) || (coords.posX() < 0) ||
(coords.posY() >= levelLimiter) || (coords.posY() < 0) ||
(coords.posZ() >= levelLimiter) || (coords.posZ() < 0)
(nc.posX() >= levelLimiter) || (nc.posX() < 0) ||
(nc.posY() >= levelLimiter) || (nc.posY() < 0) ||
(!isQuadtree_ && (nc.posZ() >= levelLimiter || nc.posZ() < 0)) ||
(isQuadtree_ && (nc.posZ() != initialCubePtr_->posZ()))
)
{
return -1;
......@@ -163,17 +164,18 @@ void meshOctree::findNeighboursOverEdge
DynList<label>& neighbourLeaves
) const
{
const meshOctreeCubeCoordinates coords(cc + regularityPositions_[6+eI]);
const meshOctreeCubeCoordinates nc(cc + regularityPositions_[6+eI]);
const meshOctreeCube* nei = findCubeForPosition(coords);
const meshOctreeCube* nei = findCubeForPosition(nc);
if( !nei )
{
const label levelLimiter = (1 << cc.level());
if(
(coords.posX() >= levelLimiter) || (coords.posX() < 0) ||
(coords.posY() >= levelLimiter) || (coords.posY() < 0) ||
(coords.posZ() >= levelLimiter) || (coords.posZ() < 0)
(nc.posX() >= levelLimiter) || (nc.posX() < 0) ||
(nc.posY() >= levelLimiter) || (nc.posY() < 0) ||
(!isQuadtree_ && (nc.posZ() >= levelLimiter || nc.posZ() < 0)) ||
(isQuadtree_ && (nc.posZ() != initialCubePtr_->posZ()))
)
{
neighbourLeaves.append(-1);
......@@ -271,7 +273,8 @@ void meshOctree::findNeighboursInDirection
if(
(cpx >= levelLimiter) || (cpx < 0) ||
(cpy >= levelLimiter) || (cpy < 0) ||
(cpz >= levelLimiter) || (cpz < 0)
(!isQuadtree_ && (cpz >= levelLimiter || cpz < 0)) ||
(isQuadtree_ && (cpz != initialCubePtr_->posZ()))
)
{
neighbourLeaves.append(-1);
......@@ -403,7 +406,8 @@ meshOctreeCube* meshOctree::findCubeForPosition
if(
(cpx >= levelLimiter) || (cpx < 0) ||
(cpy >= levelLimiter) || (cpy < 0) ||
(cpz >= levelLimiter) || (cpz < 0)
(!isQuadtree_ && (cpz >= levelLimiter || cpz < 0)) ||
(isQuadtree_ && (cpz != initialCubePtr_->posZ()))
)
{
return NULL;
......@@ -423,7 +427,7 @@ meshOctreeCube* meshOctree::findCubeForPosition
scI |= 1;
if( cpy & levelLimiter )
scI |= 2;
if( cpz & levelLimiter )
if( !isQuadtree_ && (cpz & levelLimiter) )
scI |= 4;
nei = nei->subCube(scI);
......@@ -456,9 +460,10 @@ label meshOctree::findLeafLabelForPosition
{
const label levelLimiter = (1 << cc.level());
if(
(cc.posX() < levelLimiter) || (cc.posX() >= 0) ||
(cc.posY() < levelLimiter) || (cc.posY() >= 0) ||
(cc.posZ() < levelLimiter) || (cc.posZ() >= 0)
(cc.posX() < levelLimiter) && (cc.posX() >= 0) &&
(cc.posY() < levelLimiter) && (cc.posY() >= 0) &&
((!isQuadtree_ && (cc.posZ() < levelLimiter && cc.posZ() >= 0)) ||
(isQuadtree_ && (cc.posZ() == initialCubePtr_->posZ())))
)
{
return meshOctreeCubeBasic::OTHERPROC;
......
......@@ -80,11 +80,8 @@ void correctEdgesBetweenPatches::decomposeCorrectedCells()
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from mesh, octree, regions for boundary vertices
correctEdgesBetweenPatches::correctEdgesBetweenPatches
(
polyMeshGen& mesh
)
// Construct from mesh
correctEdgesBetweenPatches::correctEdgesBetweenPatches(polyMeshGen& mesh)
:
mesh_(mesh),
msePtr_(NULL),
......
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