46 void Foam::motionSmootherAlgo::testSyncPositions
59 point(GREAT,GREAT,GREAT)
64 if (
mag(syncedFld[i] - fld[i]) > maxMag)
68 "motionSmootherAlgo::testSyncPositions" 73 ) <<
"On point " << i <<
" point:" << fld[i]
74 <<
" synchronised point:" << syncedFld[i]
85 const scalar val = fld[pointI];
87 if ((val > -GREAT) && (val < GREAT))
93 "motionSmootherAlgo::checkFld" 94 "(const pointScalarField&)" 95 ) <<
"Problem : point:" << pointI <<
" value:" << val
111 const face& f = mesh_.faces()[iter.key()];
115 usedPoints.insert(f[fp]);
128 const edgeList& edges = mesh_.edges();
130 tmp<scalarField> twght(
new scalarField(edges.size()));
135 wght[edgeI] = 1.0/(edges[edgeI].mag(points)+SMALL);
142 void Foam::motionSmootherAlgo::minSmooth
145 const PackedBoolList& isAffectedPoint,
151 tmp<pointScalarField> tavgFld = avg
160 label pointI = meshPoints[i];
161 if (isAffectedPoint.get(pointI) == 1)
166 0.5*fld[pointI] + 0.5*avgFld[pointI]
177 void Foam::motionSmootherAlgo::minSmooth
180 const PackedBoolList& isAffectedPoint,
185 tmp<pointScalarField> tavgFld = avg
194 if (isAffectedPoint.get(pointI) == 1 && isInternalPoint(pointI))
199 0.5*fld[pointI] + 0.5*avgFld[pointI]
211 void Foam::motionSmootherAlgo::scaleField
220 if (isInternalPoint(iter.key()))
222 fld[iter.key()] *= scale;
232 void Foam::motionSmootherAlgo::scaleField
242 label pointI = meshPoints[i];
244 if (pointLabels.found(pointI))
246 fld[pointI] *= scale;
253 void Foam::motionSmootherAlgo::subtractField
262 if (isInternalPoint(iter.key()))
264 fld[iter.key()] =
max(0.0, fld[iter.key()]-
f);
274 void Foam::motionSmootherAlgo::subtractField
284 label pointI = meshPoints[i];
286 if (pointLabels.found(pointI))
288 fld[pointI] =
max(0.0, fld[pointI]-f);
294 bool Foam::motionSmootherAlgo::isInternalPoint(
const label pointI)
const 296 return isInternalPoint_.get(pointI) == 1;
300 void Foam::motionSmootherAlgo::getAffectedFacesAndPoints
302 const label nPointIter,
303 const faceSet& wrongFaces,
306 PackedBoolList& isAffectedPoint
309 isAffectedPoint.setSize(mesh_.nPoints());
312 faceSet nbrFaces(mesh_,
"checkFaces", wrongFaces);
319 for (
label i = 0; i < nPointIter; i++)
321 pointSet nbrPoints(mesh_,
"grownPoints", getPoints(nbrFaces.toc()));
325 const labelList& pCells = mesh_.pointCells(iter.key());
329 const cell& cFaces = mesh_.cells()[pCells[pCellI]];
333 nbrFaces.insert(cFaces[cFaceI]);
337 nbrFaces.sync(mesh_);
339 if (i == nPointIter - 2)
343 const face& f = mesh_.faces()[iter.key()];
346 isAffectedPoint.set(f[fp], 1);
352 affectedFaces = nbrFaces.toc();
358 Foam::motionSmootherAlgo::motionSmootherAlgo
367 const dictionary& paramDict
373 displacement_(displacement),
375 oldPoints_(oldPoints),
376 adaptPatchIDs_(adaptPatchIDs),
377 paramDict_(paramDict),
378 isInternalPoint_(mesh_.
nPoints(), 1)
412 return adaptPatchIDs_;
424 oldPoints_ = mesh_.
points();
444 label patchI = patchIDs[i];
459 forAll(patchSchedule, patchEvalI)
461 label patchI = patchSchedule[patchEvalI].patch;
463 if (!adaptPatchSet.
found(patchI))
465 if (patchSchedule[patchEvalI].init)
486 label patchI = patchIDs[i];
525 forAll(ppMeshPoints, patchPointI)
527 displacement[ppMeshPoints[patchPointI]] = patchDisp[patchPointI];
550 forAll(ppMeshPoints, patchPointI)
552 const vector& newDisp = displacement[ppMeshPoints[patchPointI]];
554 if (
mag(newDisp-patchDisp[patchPointI]) > SMALL)
556 const point& pt = mesh.
points()[ppMeshPoints[patchPointI]];
565 Pout<<
"Written " << nVerts <<
" points that are changed to file " 570 forAll(ppMeshPoints, patchPointI)
572 patchDisp[patchPointI] = displacement[ppMeshPoints[patchPointI]];
594 forAll(patchSchedule, patchEvalI)
596 label patchI = patchSchedule[patchEvalI].patch;
598 if (adaptPatchSet.
found(patchI))
600 if (patchSchedule[patchEvalI].init)
615 forAll(patchSchedule, patchEvalI)
617 label patchI = patchSchedule[patchEvalI].patch;
619 if (!adaptPatchSet.
found(patchI))
621 if (patchSchedule[patchEvalI].init)
656 Info<<
"Correcting 2-D mesh motion";
660 WarningIn(
"motionSmootherAlgo::modifyMotionPoints(pointField&)")
661 <<
"2D mesh-motion probably not correct in parallel" <<
endl;
673 const edge&
e = edges[neIndices[i]];
677 pStart += pn*(pn & (oldPoints[e.
start()] - pStart));
681 pEnd += pn*(pn & (oldPoints[e.
end()] - pEnd));
691 Pout<<
"motionSmootherAlgo::modifyMotionPoints :" 692 <<
" testing sync of newPoints." 694 testSyncPositions(newPoints, 1
e-6*mesh_.
bounds().
mag());
710 const scalar errorReduction
715 paramDict_.
remove(
"errorReduction");
716 paramDict_.
add(
"errorReduction", errorReduction);
718 return oldErrorReduction;
725 const bool smoothMesh,
726 const label nAllowableErrors
744 const bool smoothMesh,
745 const label nAllowableErrors
771 actualPatchTypes[patchI] = pbm[patchI].type();
777 const pointVectorField::GeometricBoundaryField& pfld =
779 actualPatchFieldTypes.
setSize(pfld.size());
785 actualPatchFieldTypes[patchI] =
790 actualPatchFieldTypes[patchI] = pfld[patchI].type();
806 scale_*displacement_,
807 actualPatchFieldTypes,
814 Pout<<
"scaleMesh : testing sync of totalDisplacement" <<
endl;
839 const bool smoothMesh,
840 const label nAllowableErrors
843 if (!smoothMesh && adaptPatchIDs_.
empty())
847 "motionSmootherAlgo::scaleMesh" 850 "const List<labelPair>&, " 851 "const dictionary&, " 852 "const dictionary&, " 857 <<
"You specified both no movement on the internal mesh points" 858 <<
" (smoothMesh = false)" <<
nl 859 <<
"and no movement on the patch (adaptPatchIDs is empty)" <<
nl 860 <<
"Hence nothing to adapt." 869 Pout<<
"Entering scaleMesh : coupled patches:" <<
endl;
872 if (patches[patchI].coupled())
875 refCast<const coupledPolyPatch>(patches[patchI]);
877 Pout<<
'\t' << patchI <<
'\t' << pp.
name()
886 const scalar errorReduction =
888 const label nSmoothScale =
902 Info<<
"Moving mesh using displacement scaling :" 916 faceSet wrongFaces(mesh_,
"wrongFaces", mesh_.
nFaces()/100+100);
917 checkMesh(
false, mesh_, meshQualityDict, checkFaces, baffles, wrongFaces);
926 wrongFaces.sync(mesh_);
932 if (
mag(errorReduction) < SMALL)
938 const cell& ownFaces = mesh_.
cells()[own];
942 newWrongFaces.
insert(ownFaces[cfI]);
948 const cell& neiFaces = mesh_.
cells()[nei];
952 newWrongFaces.
insert(neiFaces[cfI]);
956 wrongFaces.transfer(newWrongFaces);
957 wrongFaces.sync(mesh_);
964 pointSet usedPoints(mesh_,
"usedPoints", getPoints(wrongFaces));
965 usedPoints.
sync(mesh_);
973 getAffectedFacesAndPoints
983 Pout<<
"Faces in error:" << wrongFaces.size()
984 <<
" with points:" << usedPoints.
size()
988 if (adaptPatchIDs_.
size())
991 scaleField(pp_.
meshPoints(), usedPoints, errorReduction, scale_);
997 scaleField(usedPoints, errorReduction, scale_);
1001 scalarField eWeights(calcEdgeWeights(oldPoints_));
1003 for (
label i = 0; i < nSmoothScale; i++)
1005 if (adaptPatchIDs_.
size())
1023 minSmooth(eWeights, isAffectedPoint, oldScale, scale_);
1039 Pout<<
"scale_ after smoothing :" 1055 forAll(adaptPatchIDs_, i)
1057 label patchI = adaptPatchIDs_[i];
1061 !isA<fixedValuePointPatchVectorField>
1069 "motionSmootherAlgo::updateMesh" 1070 ) <<
"Patch " << patches[patchI].name()
1071 <<
" has wrong boundary condition " 1073 <<
" on field " << displacement_.
name() <<
nl 1074 <<
"Only type allowed is " 1075 << fixedValuePointPatchVectorField::typeName
1088 isInternalPoint_.
unset(meshPoints[i]);
void constrain(GeometricField< Type, pointPatchField, pointMesh > &pf, const bool overrideValue=false) const
Apply boundary conditions (single-patch constraints) and.
void updateMesh()
Update for new mesh topology.
virtual const tensorField & forwardT() const
Return face transformation tensor.
virtual tmp< scalarField > movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
void setDisplacementPatchFields()
Set patch fields on displacement to be consistent with.
label size() const
Return the number of elements in the PtrList.
virtual bool separated() const
Are the planes separated.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
vector point
Point is a vector.
const indirectPrimitivePatch & coupledPatch() const
Return patch of all coupled faces.
void correctPoints(pointField &p) const
Correct motion points.
const word & name() const
Return name.
void unset(const PackedList< 1 > &)
Unset specified bits.
dimensioned< scalar > mag(const dimensioned< Type > &)
GeometricBoundaryField & boundaryField()
Return reference to GeometricBoundaryField.
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
A cell is defined as a list of faces with extra functionality.
scalar mag() const
The magnitude of the bounding box span.
bool empty() const
Return true if the UList is empty (ie, size() is zero).
static bool checkMesh(const bool report, const polyMesh &mesh, const dictionary &dict, labelHashSet &wrongFaces)
Check mesh with mesh settings in dict. Collects incorrect faces.
static const pointConstraints & New(const pointMesh &mesh)
bool remove(const word &)
Remove an entry specified by keyword.
const pointMesh & pMesh() const
Reference to pointMesh.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
void size(const label)
Override size to be inconsistent with allocated storage.
void movePoints()
Update for new mesh geometry.
errorManipArg< error, int > exit(error &err, const int errNo=1)
static PackedBoolList getMasterEdges(const polyMesh &)
Get per edge whether it is uncoupled or a master of a.
InternalField & internalField()
Return internal field.
const cellList & cells() const
PrimitivePatch< face, IndirectList, const pointField & > indirectPrimitivePatch
Foam::indirectPrimitivePatch.
Mesh representing a set of points created from polyMesh.
const Mesh & mesh() const
Return mesh.
A list of keyword definitions, which are a keyword followed by any number of values (e...
bool scaleMesh(labelList &checkFaces, const bool smoothMesh=true, const label nAllow=0)
Move mesh with given scale. Return true if mesh ok or has.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
vectorField pointField
pointField is a vectorField.
const dictionary & paramDict() const
label readLabel(Istream &is)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
void modifyMotionPoints(pointField &newPoints) const
Apply optional point constraint (2d correction)
const labelList & adaptPatchIDs() const
Patch labels that are being adapted.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Class applies a two-dimensional correction to mesh motion point field.
fileName path() const
Return complete path.
void clearAdditionalGeom()
Clear geometry not used for CFD (cellTree, tetBasePtIs)
const vector & planeNormal() const
Return plane normal.
const double e
Elementary charge.
void setSize(const label)
Reset size of List.
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual bool parallel() const
Are the cyclic planes parallel.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
#define WarningIn(functionName)
Report a warning using Foam::Warning.
tmp< pointField > curPoints() const
Get the current points (oldPoints+scale*displacement)
virtual const pointField & points() const
Return raw points.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
const labelList & meshPoints() const
Return labelList of mesh points in patch. They are constructed.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
const pointBoundaryMesh & boundary() const
Return reference to boundary mesh.
const labelList & normalEdgeIndices() const
Return indices of normal edges.
void correct()
Take over existing mesh position.
label size() const
Return number of elements in table.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
void correctBoundaryConditions(pointVectorField &) const
Special correctBoundaryConditions which evaluates fixedValue.
errorManip< error > abort(error &err)
const word & name() const
Return name.
virtual const labelList & faceOwner() const
Return face owner.
Type gMin(const FieldField< Field, Type > &f)
static void syncPointList(const polyMesh &, List< T > &, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
virtual const fileName & name() const
Return the name of the stream.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
static void syncPointPositions(const polyMesh &mesh, List< point > &l, const CombineOp &cop, const point &nullValue)
Synchronize locations on all mesh points.
const indirectPrimitivePatch & patch() const
Reference to patch.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
A list of faces which address into the list of points.
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches. Adds coupled points to set.
label nInternalFaces() const
Mesh consisting of general polyhedral cells.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
const boundBox & bounds() const
Return mesh bounding box.
label end() const
Return end vertex label.
List< label > labelList
A List of labels.
~motionSmootherAlgo()
Destructor.
bool parallel() const
Does the mesh contain processor patches? (also valid when.
GeometricField< vector, pointPatchField, pointMesh > pointVectorField
const polyMesh & mesh() const
Reference to mesh.
const Time & time() const
Return time.
label start() const
Return start vertex label.
const lduSchedule & patchSchedule() const
Order in which the patches should be initialised/evaluated.
GeometricField< scalar, pointPatchField, pointMesh > pointScalarField
virtual void movePoints(const Field< PointType > &)
Correct patch after moving points.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
The coupledPolyPatch is an abstract base class for patches that couple regions of the computational d...
virtual const labelList & faceNeighbour() const
Return face neighbour.
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of point.
const objectRegistry & db() const
Return the local objectRegistry.
scalar setErrorReduction(const scalar)
Set the errorReduction (by how much to scale the displacement.
bool isA(const Type &t)
Check if a dynamic_cast to typeid is possible.
Type gMax(const FieldField< Field, Type > &f)
bool found(const Key &) const
Return true if hashedEntry is found in table.
A class for managing temporary objects.
static void setDisplacement(const labelList &patchIDs, const indirectPrimitivePatch &pp, pointField &patchDisp, pointVectorField &displacement)
Set displacement field from displacement on patch points.
const globalMeshData & globalData() const
Return parallel info.
bool required() const
Is 2D correction required, i.e. is the mesh a wedge or slab.
defineTypeNameAndDebug(combustionModel, 0)
prefixOSstream Pout(cout,"Pout")
bool insert(const Key &key)
Insert a new entry.