From 01ddfede1f7c050ada2983209e2367933c281cd1 Mon Sep 17 00:00:00 2001 From: sergio Date: Wed, 15 Feb 2012 16:16:59 +0000 Subject: [PATCH] ENH: Adding surface fields to probes and patchProbes --- src/sampling/probes/patchProbes.C | 9 +- src/sampling/probes/patchProbes.H | 21 ++++ src/sampling/probes/patchProbesTemplates.C | 111 +++++++++++++++++++ src/sampling/probes/probes.C | 76 ++++++++++++- src/sampling/probes/probes.H | 41 ++++++- src/sampling/probes/probesGrouping.C | 32 ++++++ src/sampling/probes/probesTemplates.C | 118 ++++++++++++++++++++- 7 files changed, 397 insertions(+), 11 deletions(-) diff --git a/src/sampling/probes/patchProbes.C b/src/sampling/probes/patchProbes.C index 3b56f6d229..4d81b9a661 100644 --- a/src/sampling/probes/patchProbes.C +++ b/src/sampling/probes/patchProbes.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -202,6 +202,7 @@ Foam::patchProbes::patchProbes // Not easy to workaround (apart from feeding through flag into constructor) // so clear out any cells found for now. elementList_.clear(); + faceList_.clear(); read(dict); } @@ -222,6 +223,12 @@ void Foam::patchProbes::write() sampleAndWrite(sphericalTensorFields_); sampleAndWrite(symmTensorFields_); sampleAndWrite(tensorFields_); + + sampleAndWriteSurfaceFields(surfaceScalarFields_); + sampleAndWriteSurfaceFields(surfaceVectorFields_); + sampleAndWriteSurfaceFields(surfaceSphericalTensorFields_); + sampleAndWriteSurfaceFields(surfaceSymmTensorFields_); + sampleAndWriteSurfaceFields(surfaceTensorFields_); } } diff --git a/src/sampling/probes/patchProbes.H b/src/sampling/probes/patchProbes.H index 8371d8b9c2..096015f19a 100644 --- a/src/sampling/probes/patchProbes.H +++ b/src/sampling/probes/patchProbes.H @@ -74,11 +74,24 @@ class patchProbes ); + //- Sample and write a particular surface field + template + void sampleAndWrite + ( + const GeometricField& + ); + + //- Sample and write all the fields of the given type template void sampleAndWrite(const fieldGroup&); + //- Sample and write all the surface fields of the given type + template + void sampleAndWriteSurfaceFields(const fieldGroup&); + + //- Sample a volume field at all locations template tmp > sample @@ -87,6 +100,14 @@ class patchProbes ) const; + //- Sample a surface field at all locations + template + tmp > sample + ( + const GeometricField& + ) const; + + //- Sample a single field on all sample locations template tmp > sample(const word& fieldName) const; diff --git a/src/sampling/probes/patchProbesTemplates.C b/src/sampling/probes/patchProbesTemplates.C index 48d3c44b4d..898fdf254c 100644 --- a/src/sampling/probes/patchProbesTemplates.C +++ b/src/sampling/probes/patchProbesTemplates.C @@ -54,6 +54,30 @@ void Foam::patchProbes::sampleAndWrite } +template +void Foam::patchProbes::sampleAndWrite +( + const GeometricField& sField +) +{ + Field values(sample(sField)); + + if (Pstream::master()) + { + unsigned int w = IOstream::defaultPrecision() + 7; + OFstream& probeStream = *probeFilePtrs_[sField.name()]; + + probeStream << setw(w) << sField.time().value(); + + forAll(values, probeI) + { + probeStream << ' ' << setw(w) << values[probeI]; + } + probeStream << endl; + } +} + + template void Foam::patchProbes::sampleAndWrite ( @@ -106,6 +130,58 @@ void Foam::patchProbes::sampleAndWrite } +template +void Foam::patchProbes::sampleAndWriteSurfaceFields +( + const fieldGroup& fields +) +{ + forAll(fields, fieldI) + { + if (loadFromFiles_) + { + sampleAndWrite + ( + GeometricField + ( + IOobject + ( + fields[fieldI], + mesh_.time().timeName(), + mesh_, + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ), + mesh_ + ) + ); + } + else + { + objectRegistry::const_iterator iter = mesh_.find(fields[fieldI]); + + if + ( + iter != objectRegistry::end() + && iter()->type() + == GeometricField::typeName + ) + { + sampleAndWrite + ( + mesh_.lookupObject + > + ( + fields[fieldI] + ) + ); + } + } + } +} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template @@ -159,4 +235,39 @@ Foam::patchProbes::sample(const word& fieldName) const } +template +Foam::tmp > +Foam::patchProbes::sample +( + const GeometricField& sField +) const +{ + const Type unsetVal(-VGREAT*pTraits::one); + + tmp > tValues + ( + new Field(this->size(), unsetVal) + ); + + Field& values = tValues(); + + const polyBoundaryMesh& patches = mesh_.boundaryMesh(); + + forAll(*this, probeI) + { + label faceI = elementList_[probeI]; + + if (faceI >= 0) + { + label patchI = patches.whichPatch(faceI); + label localFaceI = patches[patchI].whichFace(faceI); + values[probeI] = sField.boundaryField()[patchI][localFaceI]; + } + } + + Pstream::listCombineGather(values, isNotEqOp()); + Pstream::listCombineScatter(values); + + return tValues; +} // ************************************************************************* // diff --git a/src/sampling/probes/probes.C b/src/sampling/probes/probes.C index b0a073e1e4..f15a1f5575 100644 --- a/src/sampling/probes/probes.C +++ b/src/sampling/probes/probes.C @@ -41,16 +41,45 @@ void Foam::probes::findElements(const fvMesh& mesh) elementList_.clear(); elementList_.setSize(size()); + faceList_.clear(); + faceList_.setSize(size()); + forAll(*this, probeI) { const vector& location = operator[](probeI); - elementList_[probeI] = mesh.findCell(location); + const label cellI = mesh.findCell(location); - if (debug && elementList_[probeI] != -1) + elementList_[probeI] = cellI; + + if (cellI != -1) + { + const labelList& cellFaces = mesh.cells()[cellI]; + const vector& cellCentre = mesh.cellCentres()[cellI]; + scalar minDistance = GREAT; + label minFaceID = -1; + forAll (cellFaces, i) + { + label faceI = cellFaces[i]; + vector dist = mesh.faceCentres()[faceI] - cellCentre; + if (mag(dist) < minDistance) + { + minDistance = mag(dist); + minFaceID = faceI; + } + } + faceList_[probeI] = minFaceID; + } + else + { + faceList_[probeI] = -1; + } + + if (debug && (elementList_[probeI] != -1 || faceList_[probeI] != -1)) { Pout<< "probes : found point " << location - << " in cell " << elementList_[probeI] << endl; + << " in cell " << elementList_[probeI] + << " and face " << faceList_[probeI] << endl; } } @@ -60,25 +89,36 @@ void Foam::probes::findElements(const fvMesh& mesh) { const vector& location = operator[](probeI); label cellI = elementList_[probeI]; + label faceI = faceList_[probeI]; // Check at least one processor with cell. reduce(cellI, maxOp