46 averageNeighbourFvGeometryScheme,
56 const scalar minRatio,
69 for (label facei = 0; facei <
mesh_.
nFaces(); facei++)
74 const vector& fcCorr = faceCorrection[facei];
82 const vector& fn = faceNormals[facei];
83 const point& fc = faceCentres[facei];
99 faceCorrection[facei] = vector::zero;
117 faceCorrection[facei] = vector::zero;
140 ownHeight.setSize(mesh_.nFaces());
141 neiHeight.setSize(mesh_.nInternalFaces());
143 const labelList& own = mesh_.faceOwner();
144 const labelList& nei = mesh_.faceNeighbour();
146 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
153 ownHeight[facei] = ((fc-ownCc)&
n);
154 neiHeight[facei] = ((neiCc-fc)&
n);
157 for (label facei = mesh_.nInternalFaces(); facei < mesh_.nFaces(); facei++)
163 ownHeight[facei] = ((fc-ownCc)&
n);
183 const labelList& own = mesh_.faceOwner();
184 const labelList& nei = mesh_.faceNeighbour();
187 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
193 const vector&
n = faceNormals[facei];
194 const point& fc = faceCentres[facei];
197 const label ownCelli = own[facei];
201 const scalar ownHeight = ((fc-ownCc)&
n);
202 if (ownHeight < minOwnHeight[facei])
214 const label neiCelli = nei[facei];
218 const scalar neiHeight = ((neiCc-fc)&
n);
219 if (neiHeight < minNeiHeight[facei])
232 for (label facei = mesh_.nInternalFaces(); facei < mesh_.nFaces(); facei++)
238 const vector&
n = faceNormals[facei];
239 const point& fc = faceCentres[facei];
242 const label ownCelli = own[facei];
246 const scalar ownHeight = ((fc-ownCc)&
n);
247 if (ownHeight < minOwnHeight[facei])
271 const labelList& own = mesh_.faceOwner();
272 const labelList& nei = mesh_.faceNeighbour();
278 Field<solveScalar> cellWeights(mesh_.nCells(),
Zero);
281 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
286 const vector&
n = faceNormals[facei];
288 const point& ownCc = cellCentres[own[facei]];
289 const point& neiCc = cellCentres[nei[facei]];
303 const scalar w = 0.5*faceWeights[facei];
304 cc[own[facei]] +=
point(w*d);
305 cellWeights[own[facei]] += w;
307 cc[nei[facei]] -=
point(w*d);
308 cellWeights[nei[facei]] += w;
316 const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
317 for (
const polyPatch& pp : pbm)
325 const label meshFacei = pp.start()+i;
326 const label bFacei = meshFacei-mesh_.nInternalFaces();
331 const vector&
n = faceNormals[meshFacei];
334 const point& ownCc = cellCentres[fc[i]];
335 const point& neiCc = neiCellCentres[bFacei];
348 const scalar w = 0.5*faceWeights[meshFacei];
349 cc[fc[i]] +=
point(w*d);
350 cellWeights[fc[i]] += w;
358 if (cellWeights[celli] > VSMALL)
360 cc[celli] = cellCentres[celli] + cc[celli]/cellWeights[celli];
364 cc[celli] = cellCentres[celli];
381 const labelList& own = mesh_.faceOwner();
382 const labelList& nei = mesh_.faceNeighbour();
389 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
395 const vector&
n = faceNormals[facei];
396 const point& oldFc = faceCentres[facei];
416 const solveScalar
f = (deltaFc&
n)/(deltaCc&
n);
428 newFc[facei] = oldFc + d;
436 const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
437 for (
const polyPatch& pp : pbm)
446 const label facei = pp.start()+i;
447 const label bFacei = facei-mesh_.nInternalFaces();
453 const vector&
n = faceNormals[facei];
454 const point& oldFc = faceCentres[facei];
464 const solveScalar
f = (deltaFc&
n)/(deltaCc&
n);
472 newFc[facei] = oldFc + d;
480 const label facei = pp.start()+i;
486 const vector&
n = faceNormals[facei];
487 const point& oldFc = faceCentres[facei];
497 newFc[facei] = oldFc+d;
534 faceWeights.setSize(cosAngles.size());
541 const scalar cosAngle = cosAngles[facei];
542 if (cosAngle < minCos)
544 faceWeights[facei] = 1.0;
546 else if (cosAngle > maxCos)
548 faceWeights[facei] = 0.0;
553 1.0-(cosAngle-minCos)/(maxCos-minCos);
562 Foam::averageNeighbourFvGeometryScheme::averageNeighbourFvGeometryScheme
565 const dictionary&
dict 568 highAspectRatioFvGeometryScheme(
mesh,
dict),
571 dict.getCheckOrDefault<label>
575 [](label val) {
return val >= 0; }
583 [](scalar val) { return val > 0 && val <= 1; }
592 [](scalar val) { return val >= 0 && val <= 1; }
598 Pout<<
"averageNeighbourFvGeometryScheme :" 599 <<
" nIters:" << nIters_
600 <<
" relax:" << relax_
601 <<
" minRatio:" << minRatio_ <<
endl;
615 Pout<<
"averageNeighbourFvGeometryScheme::movePoints() : " 616 <<
"recalculating primitiveMesh centres" <<
endl;
634 const vectorField faceNormals(faceAreas/magFaceAreas);
641 calcAspectRatioWeights(cellWeight, faceWeight);
644 cellWeight *= relax_;
661 minOwnHeight *= minRatio_;
662 minNeiHeight *= minRatio_;
666 autoPtr<OBJstream> osPtr;
667 autoPtr<surfaceWriter> writerPtr;
674 mesh_.time().timePath()
675 /
"cellCentre_correction.obj" 678 Pout<<
"averageNeighbourFvGeometryScheme::movePoints() :" 679 <<
" writing cell centre path to " << osPtr().
name() <<
endl;
685 mesh_.time().globalPath()
687 / mesh_.pointsInstance()
697 writerPtr->useTimeDir(
true);
699 writerPtr->beginTime(mesh_.time());
705 (outputDir /
"cosAngle"),
709 writerPtr->endTime();
718 for (label iter = 0; iter < nIters_; iter++)
751 writerPtr->beginTime(instant(scalar(iter)));
752 writerPtr->write(
"cosAngles", cosAngles);
753 writerPtr->endTime();
762 Pout<<
" face:" << facei
763 <<
" at:" << mesh_.faceCentres()[facei]
764 <<
" cosAngle:" << cosAngles[facei]
765 <<
" faceWeight:" << faceWeights[facei]
771 tcc = averageNeighbourCentres
785 const label nClipped = clipPyramids
801 forAll(cellCentres, celli)
803 const point& cc = cellCentres[celli];
828 Pout<<
" iter:" << iter
829 <<
" nClipped:" << nClipped
830 <<
" average displacement:" <<
gAverage(magCorrection)
831 <<
" non-ortho angle : average:" <<
gAverage(nonOrthoAngle)
832 <<
" max:" <<
gMax(nonOrthoAngle) <<
endl;
845 vectorField faceCorrection(faceWeight*(tfc-mesh_.faceCentres()));
855 vectorField faceCentres(mesh_.faceCentres() + faceCorrection);
859 Pout<<
"averageNeighbourFvGeometryScheme::movePoints() :" 860 <<
" averageNeighbour weight" 861 <<
" max:" <<
gMax(cellWeight) <<
" min:" <<
gMin(cellWeight)
865 const fileName tp(mesh_.time().timePath());
867 OBJstream str(tp/
"averageNeighbourCellCentres.obj");
868 Pout<<
"Writing lines from old to new cell centre to " << str.
name()
870 forAll(mesh_.cellCentres(), celli)
872 const point& oldCc = mesh_.cellCentres()[celli];
873 const point& newCc = cellCentres[celli];
874 str.writeLine(oldCc, newCc);
880 const fileName tp(mesh_.time().timePath());
881 OBJstream str(tp/
"averageFaceCentres.obj");
882 Pout<<
"Writing lines from old to new face centre to " << str.
name()
884 forAll(mesh_.faceCentres(), facei)
886 const point& oldFc = mesh_.faceCentres()[facei];
887 const point& newFc = faceCentres[facei];
888 str.writeLine(oldFc, newFc);
898 std::move(faceCentres),
899 std::move(faceAreas),
900 std::move(cellCentres),
901 std::move(cellVolumes)
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix by subtracting the matrix multiplied by the current fi...
virtual const fileName & name() const
Get the name of the output serial stream. (eg, the name of the Fstream file name) ...
dimensionedScalar acos(const dimensionedScalar &ds)
const fvMesh & mesh_
Hold reference to mesh.
A face is a list of labels corresponding to mesh vertices.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Type gMin(const FieldField< Field, Type > &f)
tmp< pointField > averageCentres(const pointField &cellCentres, const pointField &faceCentres, const vectorField &faceNormals) const
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Unit conversion functions.
T getCheck(const word &keyword, const Predicate &pred, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T with additional checking FatalIOError if not found, or if the number of tokens is...
Ostream & endl(Ostream &os)
Add newline and flush stream.
label nFaces() const noexcept
Number of mesh faces.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Macros for easy insertion into run-time selection tables.
UList< label > labelUList
A UList of labels.
virtual const pointField & points() const
Return raw points.
#define forAll(list, i)
Loop across all elements in list.
Vector< solveScalar > solveVector
void resetGeometry(pointField &&faceCentres, pointField &&faceAreas, pointField &&cellCentres, scalarField &&cellVolumes)
Reset the local geometry.
vectorField pointField
pointField is a vectorField.
virtual void movePoints()
Do what is necessary if the mesh has moved.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
dimensionedScalar cos(const dimensionedScalar &ds)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
T getCheckOrDefault(const word &keyword, const T &deflt, const Predicate &pred, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
virtual const faceList & faces() const
Return raw faces.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
tmp< pointField > averageNeighbourCentres(const pointField &cellCentres, const vectorField &faceNormals, const scalarField &faceWeights) const
Average neighbouring cell centres to minimise non-ortho.
Templated 3D Vector derived from VectorSpace adding construction from 3 components, element access using x(), y() and z() member functions and the inner-product (dot-product) and cross-product operators.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
int debug
Static debugging option.
label clipFaceTet(const scalar minRatio, const vectorField &faceCentres, const vectorField &faceNormals, vectorField &faceCorrection) const
Clip face-centre correction vector if new triangle area would get below min. Return number of clipped...
Type gMax(const FieldField< Field, Type > &f)
defineTypeNameAndDebug(combustionModel, 0)
void makeNonOrthoWeights(const pointField &cellCentres, const vectorField &faceNormals, scalarField &cosAngles, scalarField &faceWeights) const
Make weights based on non-orthogonality.
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
vector point
Point is a vector.
Type gAverage(const FieldField< Field, Type > &f)
constexpr scalar radToDeg(const scalar rad) noexcept
Conversion from radians to degrees.
label clipPyramids(const pointField &cellCentres, const vectorField &faceCentres, const vectorField &faceNormals, const scalarField &minOwnHeight, const scalarField &minNeiHeight, vectorField &correction) const
Clip correction vector if new pyramid height would get below min. Return number of clipped cells...
static word outputPrefix
Directory prefix.
Field< vector > vectorField
Specialisation of Field<T> for vector.
List< label > labelList
A List of labels.
A class for managing temporary objects.
constexpr scalar degToRad(const scalar deg) noexcept
Conversion from degrees to radians.
virtual void movePoints()
Do what is necessary if the mesh has moved.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
static autoPtr< surfaceWriter > New(const word &writeType)
Return a reference to the selected surfaceWriter.
static const Vector< Cmpt > zero
void makePyrHeights(const pointField &cellCentres, const vectorField &faceCentres, const vectorField &faceNormals, scalarField &ownHeight, scalarField &neiHeight) const
Calculate pyramid heights.
static constexpr const zero Zero
Global zero (0)