Merge commit 'OpenCFD/master' into olesenm

This commit is contained in:
Mark Olesen
2009-03-18 14:49:37 +01:00
26 changed files with 241 additions and 104 deletions

View File

@ -68,8 +68,7 @@ int main(int argc, char *argv[])
mesh mesh
); );
pointMesh pMesh(mesh); const volPointInterpolation& pInterp = volPointInterpolation::New(mesh);
volPointInterpolation pInterp(mesh, pMesh);
pointScalarField pp(pInterp.interpolate(p)); pointScalarField pp(pInterp.interpolate(p));
pp.write(); pp.write();

View File

@ -100,6 +100,7 @@ void processorPointPatchField<Type>::initSwapAdd(Field<Type>& pField) const
{ {
if (Pstream::parRun()) if (Pstream::parRun())
{ {
// Get internal field into my point order
Field<Type> pf(this->patchInternalField(pField)); Field<Type> pf(this->patchInternalField(pField));
OPstream::write OPstream::write
@ -130,11 +131,7 @@ void processorPointPatchField<Type>::swapAdd(Field<Type>& pField) const
if (doTransform()) if (doTransform())
{ {
const labelList& nonGlobalPatchPoints =
procPatch_.nonGlobalPatchPoints();
const processorPolyPatch& ppp = procPatch_.procPolyPatch(); const processorPolyPatch& ppp = procPatch_.procPolyPatch();
const labelListList& pointFaces = ppp.pointFaces();
const tensorField& forwardT = ppp.forwardT(); const tensorField& forwardT = ppp.forwardT();
if (forwardT.size() == 1) if (forwardT.size() == 1)
@ -143,6 +140,10 @@ void processorPointPatchField<Type>::swapAdd(Field<Type>& pField) const
} }
else else
{ {
const labelList& nonGlobalPatchPoints =
procPatch_.nonGlobalPatchPoints();
const labelListList& pointFaces = ppp.pointFaces();
forAll(nonGlobalPatchPoints, pfi) forAll(nonGlobalPatchPoints, pfi)
{ {
pnf[pfi] = transform pnf[pfi] = transform

View File

@ -330,7 +330,9 @@ public:
// Addressing into mesh // Addressing into mesh
//- Return labelList of mesh points in patch //- Return labelList of mesh points in patch. They are constructed
// walking through the faces in incremental order and not sorted
// anymore.
const labelList& meshPoints() const; const labelList& meshPoints() const;
//- Mesh point map. Given the global point index find its //- Mesh point map. Given the global point index find its

View File

@ -67,30 +67,56 @@ calcMeshData() const
// number of faces in the patch // number of faces in the patch
Map<label> markedPoints(4*this->size()); Map<label> markedPoints(4*this->size());
// if the point is used, set the mark to 1
// Important:
// ~~~~~~~~~~
// In <= 1.5 the meshPoints would be in increasing order but this gives
// problems in processor point synchronisation where we have to find out
// how the opposite side would have allocated points.
////- 1.5 code:
//// if the point is used, set the mark to 1
//forAll (*this, faceI)
//{
// const Face& curPoints = this->operator[](faceI);
//
// forAll (curPoints, pointI)
// {
// markedPoints.insert(curPoints[pointI], -1);
// }
//}
//
//// Create the storage and store the meshPoints. Mesh points are
//// the ones marked by the usage loop above
//meshPointsPtr_ = new labelList(markedPoints.toc());
//labelList& pointPatch = *meshPointsPtr_;
//
//// Sort the list to preserve compatibility with the old ordering
//sort(pointPatch);
//
//// For every point in map give it its label in mesh points
//forAll (pointPatch, pointI)
//{
// markedPoints.find(pointPatch[pointI])() = pointI;
//}
//- Unsorted version:
DynamicList<label> meshPoints(2*this->size());
forAll (*this, faceI) forAll (*this, faceI)
{ {
const Face& curPoints = this->operator[](faceI); const Face& curPoints = this->operator[](faceI);
forAll (curPoints, pointI) forAll (curPoints, pointI)
{ {
markedPoints.insert(curPoints[pointI], -1); if (markedPoints.insert(curPoints[pointI], meshPoints.size()))
}
}
// Create the storage and store the meshPoints. Mesh points are
// the ones marked by the usage loop above
meshPointsPtr_ = new labelList(markedPoints.toc());
labelList& pointPatch = *meshPointsPtr_;
// Sort the list to preserve compatibility with the old ordering
sort(pointPatch);
// For every point in map give it its label in mesh points
forAll (pointPatch, pointI)
{ {
markedPoints.find(pointPatch[pointI])() = pointI; meshPoints.append(curPoints[pointI]);
} }
}
}
// Transfer to straight list (reuses storage)
meshPointsPtr_ = new labelList(meshPoints, true);
// Create local faces. Note that we start off from copy of original face // Create local faces. Note that we start off from copy of original face
// list (even though vertices are overwritten below). This is done so // list (even though vertices are overwritten below). This is done so

View File

@ -38,7 +38,6 @@ SourceFiles
#include "autoPtr.H" #include "autoPtr.H"
#include "dictionary.H" #include "dictionary.H"
#include "pointField.H"
#include "boolList.H" #include "boolList.H"
#include "wallPoint.H" #include "wallPoint.H"
#include "searchableSurfaces.H" #include "searchableSurfaces.H"

View File

@ -29,7 +29,6 @@ Description
#include "autoSnapDriver.H" #include "autoSnapDriver.H"
#include "Time.H" #include "Time.H"
#include "pointFields.H"
#include "motionSmoother.H" #include "motionSmoother.H"
#include "polyTopoChange.H" #include "polyTopoChange.H"
#include "OFstream.H" #include "OFstream.H"
@ -1389,11 +1388,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::autoSnapDriver::repatchToSurface
} }
} }
pointField localFaceCentres(pp.size()); pointField localFaceCentres(mesh.faceCentres(), pp.addressing());
forAll(pp, i)
{
localFaceCentres[i] = mesh.faceCentres()[pp.addressing()[i]];
}
// Get nearest surface and region // Get nearest surface and region
labelList hitSurface; labelList hitSurface;

View File

@ -1242,7 +1242,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::refine
// Do refinement of consistent set of cells followed by truncation and // Do refinement of consistent set of cells followed by truncation and
// load balancing. // load balancing.
Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::autoPtr<Foam::mapDistributePolyMesh>
Foam::meshRefinement::refineAndBalance Foam::meshRefinement::refineAndBalance
( (
const string& msg, const string& msg,
decompositionMethod& decomposer, decompositionMethod& decomposer,

View File

@ -193,7 +193,7 @@ void Foam::shellSurfaces::orient()
if (hasSurface) if (hasSurface)
{ {
const point outsidePt = 2 * overallBb.span(); const point outsidePt = overallBb.max() + overallBb.span();
//Info<< "Using point " << outsidePt << " to orient shells" << endl; //Info<< "Using point " << outsidePt << " to orient shells" << endl;

View File

@ -120,6 +120,29 @@ const Foam::fileName& Foam::triSurfaceMesh::checkFile
} }
bool Foam::triSurfaceMesh::addFaceToEdge
(
const edge& e,
EdgeMap<label>& facesPerEdge
)
{
EdgeMap<label>::iterator eFnd = facesPerEdge.find(e);
if (eFnd != facesPerEdge.end())
{
if (eFnd() == 2)
{
return false;
}
eFnd()++;
}
else
{
facesPerEdge.insert(e, 1);
}
return true;
}
bool Foam::triSurfaceMesh::isSurfaceClosed() const bool Foam::triSurfaceMesh::isSurfaceClosed() const
{ {
// Construct pointFaces. Let's hope surface has compact point // Construct pointFaces. Let's hope surface has compact point
@ -142,49 +165,42 @@ bool Foam::triSurfaceMesh::isSurfaceClosed() const
const labelledTri& f = triSurface::operator[](pFaces[i]); const labelledTri& f = triSurface::operator[](pFaces[i]);
label fp = findIndex(f, pointI); label fp = findIndex(f, pointI);
// Forward edge // Something weird: if I expand the code of addFaceToEdge in both
{ // below instances it gives a segmentation violation on some
label p1 = f[f.fcIndex(fp)]; // surfaces. Compiler (4.3.2) problem?
if (p1 > pointI)
// Forward edge
label nextPointI = f[f.fcIndex(fp)];
if (nextPointI > pointI)
{ {
const edge e(pointI, p1); bool okFace = addFaceToEdge
EdgeMap<label>::iterator eFnd = facesPerEdge.find(e); (
if (eFnd != facesPerEdge.end()) edge(pointI, nextPointI),
{ facesPerEdge
if (eFnd() == 2) );
if (!okFace)
{ {
return false; return false;
} }
eFnd()++;
}
else
{
facesPerEdge.insert(e, 1);
}
}
} }
// Reverse edge // Reverse edge
{ label prevPointI = f[f.rcIndex(fp)];
label p1 = f[f.rcIndex(fp)];
if (p1 > pointI) if (prevPointI > pointI)
{ {
const edge e(pointI, p1); bool okFace = addFaceToEdge
EdgeMap<label>::iterator eFnd = facesPerEdge.find(e); (
if (eFnd != facesPerEdge.end()) edge(pointI, prevPointI),
{ facesPerEdge
if (eFnd() == 2) );
if (!okFace)
{ {
return false; return false;
} }
eFnd()++;
}
else
{
facesPerEdge.insert(e, 1);
}
}
} }
} }

View File

@ -42,6 +42,7 @@ SourceFiles
#include "indexedOctree.H" #include "indexedOctree.H"
#include "treeDataTriSurface.H" #include "treeDataTriSurface.H"
#include "treeDataEdge.H" #include "treeDataEdge.H"
#include "EdgeMap.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -91,6 +92,13 @@ private:
const fileName& objectName const fileName& objectName
); );
//- Helper function for isSurfaceClosed
static bool addFaceToEdge
(
const edge&,
EdgeMap<label>&
);
//- Check whether surface is closed without calculating any permanent //- Check whether surface is closed without calculating any permanent
// addressing. // addressing.
bool isSurfaceClosed() const; bool isSurfaceClosed() const;

View File

@ -175,6 +175,51 @@ Foam::labelList Foam::orientedSurface::edgeToFace
} }
void Foam::orientedSurface::walkSurface
(
const triSurface& s,
const label startFaceI,
labelList& flipState
)
{
// List of faces that were changed in the last iteration.
labelList changedFaces(1, startFaceI);
// List of edges that were changed in the last iteration.
labelList changedEdges;
while(true)
{
changedEdges = faceToEdge(s, changedFaces);
if (debug)
{
Pout<< "From changedFaces:" << changedFaces.size()
<< " to changedEdges:" << changedEdges.size()
<< endl;
}
if (changedEdges.empty())
{
break;
}
changedFaces = edgeToFace(s, changedEdges, flipState);
if (debug)
{
Pout<< "From changedEdges:" << changedEdges.size()
<< " to changedFaces:" << changedFaces.size()
<< endl;
}
if (changedFaces.empty())
{
break;
}
}
}
void Foam::orientedSurface::propagateOrientation void Foam::orientedSurface::propagateOrientation
( (
const triSurface& s, const triSurface& s,
@ -228,42 +273,8 @@ void Foam::orientedSurface::propagateOrientation
<< endl; << endl;
} }
// Walk the surface from nearestFaceI, changing the flipstate.
// List of faces that were changed in the last iteration. walkSurface(s, nearestFaceI, flipState);
labelList changedFaces(1, nearestFaceI);
// List of edges that were changed in the last iteration.
labelList changedEdges;
while(true)
{
changedEdges = faceToEdge(s, changedFaces);
if (debug)
{
Pout<< "From changedFaces:" << changedFaces.size()
<< " to changedEdges:" << changedEdges.size()
<< endl;
}
if (changedEdges.empty())
{
break;
}
changedFaces = edgeToFace(s, changedEdges, flipState);
if (debug)
{
Pout<< "From changedEdges:" << changedEdges.size()
<< " to changedFaces:" << changedFaces.size()
<< endl;
}
if (changedFaces.empty())
{
break;
}
}
} }
@ -352,6 +363,26 @@ bool Foam::orientedSurface::orient
const bool orientOutside const bool orientOutside
) )
{ {
bool anyFlipped = false;
// Do initial flipping to make triangles consistent. Otherwise if the
// nearest is e.g. on an edge inbetween inconsistent triangles it might
// make the wrong decision.
if (s.size() > 0)
{
// Whether face has to be flipped.
// UNVISITED: unvisited
// NOFLIP: no need to flip
// FLIP: need to flip
labelList flipState(s.size(), UNVISITED);
flipState[0] = NOFLIP;
walkSurface(s, 0, flipState);
anyFlipped = flipSurface(s, flipState);
}
// Whether face has to be flipped. // Whether face has to be flipped.
// UNVISITED: unvisited // UNVISITED: unvisited
// NOFLIP: no need to flip // NOFLIP: no need to flip
@ -410,7 +441,9 @@ bool Foam::orientedSurface::orient
} }
// Now finally flip triangles according to flipState. // Now finally flip triangles according to flipState.
return flipSurface(s, flipState); bool geomFlipped = flipSurface(s, flipState);
return anyFlipped || geomFlipped;
} }

View File

@ -94,6 +94,15 @@ class orientedSurface
labelList& flip labelList& flip
); );
//- Walk from face across connected faces. Change orientation to be
// consistent with startFaceI.
static void walkSurface
(
const triSurface& s,
const label startFaceI,
labelList& flipState
);
//- Given nearest point and face check orientation to nearest face //- Given nearest point and face check orientation to nearest face
// and flip if nessecary (only marked in flipState) and propagate. // and flip if nessecary (only marked in flipState) and propagate.
static void propagateOrientation static void propagateOrientation

View File

@ -307,6 +307,48 @@ Foam::tmp<Foam::volScalarField> Foam::sampledIsoSurface::average
} }
Foam::tmp<Foam::pointScalarField> Foam::sampledIsoSurface::average
(
const pointMesh& pMesh,
const volScalarField& fld
) const
{
tmp<pointScalarField> tpointAvg
(
new pointScalarField
(
IOobject
(
"pointAvg",
fld.time().timeName(),
fld.db(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
pMesh,
dimensionedScalar("zero", dimless, scalar(0.0))
)
);
pointScalarField& pointAvg = tpointAvg();
for (label pointI = 0; pointI < fld.mesh().nPoints(); pointI++)
{
const labelList& pCells = fld.mesh().pointCells(pointI);
forAll(pCells, i)
{
pointAvg[pointI] += fld[pCells[i]];
}
pointAvg[pointI] /= pCells.size();
}
// Give value to calculatedFvPatchFields
pointAvg.correctBoundaryConditions();
return tpointAvg;
}
bool Foam::sampledIsoSurface::updateGeometry() const bool Foam::sampledIsoSurface::updateGeometry() const
{ {
const fvMesh& fvm = static_cast<const fvMesh&>(mesh()); const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
@ -407,6 +449,7 @@ bool Foam::sampledIsoSurface::updateGeometry() const
( (
*volFieldPtr_, *volFieldPtr_,
*pointFieldPtr_, *pointFieldPtr_,
//average(pointMesh::New(mesh()), *volFieldPtr_),
isoVal_, isoVal_,
regularise_, regularise_,
mergeTol_ mergeTol_

View File

@ -124,6 +124,12 @@ class sampledIsoSurface
const pointScalarField& const pointScalarField&
) const; ) const;
tmp<pointScalarField> average
(
const pointMesh&,
const volScalarField& fld
) const;
//- Create iso surface (if time has changed) //- Create iso surface (if time has changed)
// Do nothing (and return false) if no update was needed // Do nothing (and return false) if no update was needed
bool updateGeometry() const; bool updateGeometry() const;