46 void Foam::motionSmootherAlgo::testSyncPositions
59 point(GREAT,GREAT,GREAT)
64 if (
mag(syncedFld[i] - fld[i]) > maxMag)
67 <<
"On point " << i <<
" point:" << fld[i]
68 <<
" synchronised point:" << syncedFld[i]
79 const scalar val = fld[pointi];
81 if ((val > -GREAT) && (val < GREAT))
86 <<
"Problem : point:" << pointi <<
" value:" << val
102 const face& f = mesh_.faces()[iter.key()];
106 usedPoints.insert(f[fp]);
119 const edgeList& edges = mesh_.edges();
121 tmp<scalarField> twght(
new scalarField(edges.size()));
126 wght[edgeI] = 1.0/(edges[edgeI].mag(points)+SMALL);
133 void Foam::motionSmootherAlgo::minSmooth
136 const PackedBoolList& isAffectedPoint,
142 tmp<pointScalarField> tavgFld = avg
151 label pointi = meshPoints[i];
152 if (isAffectedPoint.get(pointi) == 1)
157 0.5*fld[pointi] + 0.5*avgFld[pointi]
168 void Foam::motionSmootherAlgo::minSmooth
171 const PackedBoolList& isAffectedPoint,
176 tmp<pointScalarField> tavgFld = avg
185 if (isAffectedPoint.get(pointi) == 1 && isInternalPoint(pointi))
190 0.5*fld[pointi] + 0.5*avgFld[pointi]
202 void Foam::motionSmootherAlgo::scaleField
211 if (isInternalPoint(iter.key()))
213 fld[iter.key()] *= scale;
223 void Foam::motionSmootherAlgo::scaleField
233 label pointi = meshPoints[i];
235 if (pointLabels.found(pointi))
237 fld[pointi] *= scale;
244 void Foam::motionSmootherAlgo::subtractField
253 if (isInternalPoint(iter.key()))
255 fld[iter.key()] =
max(0.0, fld[iter.key()]-
f);
265 void Foam::motionSmootherAlgo::subtractField
275 label pointi = meshPoints[i];
277 if (pointLabels.found(pointi))
279 fld[pointi] =
max(0.0, fld[pointi]-f);
285 bool Foam::motionSmootherAlgo::isInternalPoint(
const label pointi)
const 287 return isInternalPoint_.get(pointi) == 1;
291 void Foam::motionSmootherAlgo::getAffectedFacesAndPoints
293 const label nPointIter,
294 const faceSet& wrongFaces,
297 PackedBoolList& isAffectedPoint
300 isAffectedPoint.setSize(mesh_.nPoints());
303 faceSet nbrFaces(mesh_,
"checkFaces", wrongFaces);
310 for (
label i = 0; i < nPointIter; i++)
312 pointSet nbrPoints(mesh_,
"grownPoints", getPoints(nbrFaces.toc()));
316 const labelList& pCells = mesh_.pointCells(iter.key());
320 const cell& cFaces = mesh_.cells()[pCells[pCelli]];
324 nbrFaces.insert(cFaces[cFacei]);
328 nbrFaces.sync(mesh_);
330 if (i == nPointIter - 2)
334 const face& f = mesh_.faces()[iter.key()];
337 isAffectedPoint.set(f[fp], 1);
343 affectedFaces = nbrFaces.toc();
349 Foam::motionSmootherAlgo::motionSmootherAlgo
358 const dictionary& paramDict
364 displacement_(displacement),
366 oldPoints_(oldPoints),
367 adaptPatchIDs_(adaptPatchIDs),
368 paramDict_(paramDict),
369 isInternalPoint_(mesh_.
nPoints(), 1)
403 return adaptPatchIDs_;
415 oldPoints_ = mesh_.
points();
431 pointVectorField::Boundary& displacementBf =
441 displacementBf[
patchi].patchInternalField();
453 forAll(patchSchedule, patchEvalI)
457 if (!adaptPatchSet.
found(patchi))
459 if (patchSchedule[patchEvalI].init)
483 displacementBf[
patchi].patchInternalField();
519 forAll(ppMeshPoints, patchPointi)
521 displacement[ppMeshPoints[patchPointi]] = patchDisp[patchPointi];
544 forAll(ppMeshPoints, patchPointi)
546 const vector& newDisp = displacement[ppMeshPoints[patchPointi]];
548 if (
mag(newDisp-patchDisp[patchPointi]) > SMALL)
550 const point& pt = mesh.
points()[ppMeshPoints[patchPointi]];
559 Pout<<
"Written " << nVerts <<
" points that are changed to file " 564 forAll(ppMeshPoints, patchPointi)
566 patchDisp[patchPointi] = displacement[ppMeshPoints[patchPointi]];
587 pointVectorField::Boundary& displacementBf =
591 forAll(patchSchedule, patchEvalI)
595 if (adaptPatchSet.
found(patchi))
597 if (patchSchedule[patchEvalI].init)
612 forAll(patchSchedule, patchEvalI)
616 if (!adaptPatchSet.
found(patchi))
618 if (patchSchedule[patchEvalI].init)
653 Info<<
"Correcting 2-D mesh motion";
658 <<
"2D mesh-motion probably not correct in parallel" <<
endl;
670 const edge&
e = edges[neIndices[i]];
674 pStart += pn*(pn & (oldPoints[e.
start()] - pStart));
678 pEnd += pn*(pn & (oldPoints[e.
end()] - pEnd));
688 Pout<<
"motionSmootherAlgo::modifyMotionPoints :" 689 <<
" testing sync of newPoints." 691 testSyncPositions(newPoints, 1
e-6*mesh_.
bounds().
mag());
707 const scalar errorReduction
712 paramDict_.
remove(
"errorReduction");
713 paramDict_.
add(
"errorReduction", errorReduction);
715 return oldErrorReduction;
722 const bool smoothMesh,
723 const label nAllowableErrors
741 const bool smoothMesh,
742 const label nAllowableErrors
774 const pointVectorField::Boundary& pfld =
776 actualPatchFieldTypes.
setSize(pfld.size());
782 actualPatchFieldTypes[
patchi] =
803 scale_*displacement_,
804 actualPatchFieldTypes,
811 Pout<<
"scaleMesh : testing sync of totalDisplacement" <<
endl;
836 const bool smoothMesh,
837 const label nAllowableErrors
840 if (!smoothMesh && adaptPatchIDs_.
empty())
843 <<
"You specified both no movement on the internal mesh points" 844 <<
" (smoothMesh = false)" <<
nl 845 <<
"and no movement on the patch (adaptPatchIDs is empty)" <<
nl 846 <<
"Hence nothing to adapt." 855 Pout<<
"Entering scaleMesh : coupled patches:" <<
endl;
858 if (patches[
patchi].coupled())
861 refCast<const coupledPolyPatch>(patches[
patchi]);
872 const scalar errorReduction =
874 const label nSmoothScale =
888 Info<<
"Moving mesh using displacement scaling :" 902 faceSet wrongFaces(mesh_,
"wrongFaces", mesh_.
nFaces()/100+100);
903 checkMesh(
false, mesh_, meshQualityDict, checkFaces, baffles, wrongFaces);
912 wrongFaces.sync(mesh_);
918 if (
mag(errorReduction) < SMALL)
924 const cell& ownFaces = mesh_.
cells()[own];
928 newWrongFaces.
insert(ownFaces[cfI]);
934 const cell& neiFaces = mesh_.
cells()[nei];
938 newWrongFaces.
insert(neiFaces[cfI]);
942 wrongFaces.transfer(newWrongFaces);
943 wrongFaces.sync(mesh_);
950 pointSet usedPoints(mesh_,
"usedPoints", getPoints(wrongFaces));
951 usedPoints.
sync(mesh_);
959 getAffectedFacesAndPoints
969 Pout<<
"Faces in error:" << wrongFaces.size()
970 <<
" with points:" << usedPoints.
size()
974 if (adaptPatchIDs_.
size())
977 scaleField(pp_.
meshPoints(), usedPoints, errorReduction, scale_);
983 scaleField(usedPoints, errorReduction, scale_);
989 for (
label i = 0; i < nSmoothScale; i++)
991 if (adaptPatchIDs_.
size())
1009 minSmooth(eWeights, isAffectedPoint, oldScale, scale_);
1025 Pout<<
"scale_ after smoothing :" 1041 forAll(adaptPatchIDs_, i)
1047 !isA<fixedValuePointPatchVectorField>
1054 <<
"Patch " << patches[
patchi].name()
1055 <<
" has wrong boundary condition " 1057 <<
" on field " << displacement_.
name() <<
nl 1058 <<
"Only type allowed is " 1059 << fixedValuePointPatchVectorField::typeName
1072 isInternalPoint_.
unset(meshPoints[i]);
GeometricField< scalar, pointPatchField, pointMesh > pointScalarField
static bool checkMesh(const bool report, const polyMesh &mesh, const dictionary &dict, labelHashSet &wrongFaces)
Check mesh with mesh settings in dict. Collects incorrect faces.
bool isA(const Type &t)
Check if a dynamic_cast to typeid is possible.
label end() const
Return end vertex label.
const Time & time() const
Return time.
A HashTable with keys but without contents.
virtual tmp< scalarField > movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
#define forAll(list, i)
Loop across all elements in list.
bool remove(const word &)
Remove an entry specified by keyword.
virtual void movePoints(const Field< PointType > &)
Correct patch after moving points.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
const objectRegistry & db() const
Return the local objectRegistry.
errorManipArg< error, int > exit(error &err, const int errNo=1)
const boundBox & bounds() const
Return mesh bounding box.
const double e
Elementary charge.
const labelList & meshPoints() const
Return labelList of mesh points in patch. They are constructed.
A list of keyword definitions, which are a keyword followed by any number of values (e...
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Type gMin(const FieldField< Field, Type > &f)
bool empty() const
Return true if the UList is empty (ie, size() is zero)
static void setDisplacement(const labelList &patchIDs, const indirectPrimitivePatch &pp, pointField &patchDisp, pointVectorField &displacement)
Set displacement field from displacement on patch points.
const vector & planeNormal() const
Return plane normal.
bool scaleMesh(labelList &checkFaces, const bool smoothMesh=true, const label nAllow=0)
Move mesh with given scale. Return true if mesh ok or has.
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
void size(const label)
Override size to be inconsistent with allocated storage.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const Internal::FieldType & primitiveField() const
Return a const-reference to the internal field.
The coupledPolyPatch is an abstract base class for patches that couple regions of the computational d...
label size() const
Return number of elements in table.
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
const indirectPrimitivePatch & patch() const
Reference to patch.
bool required() const
Is 2D correction required, i.e. is the mesh a wedge or slab.
void movePoints()
Update for new mesh geometry.
PrimitivePatch< face, IndirectList, const pointField & > indirectPrimitivePatch
Foam::indirectPrimitivePatch.
bool insert(const Key &key)
Insert a new entry.
const cellList & cells() const
const pointBoundaryMesh & boundary() const
Return reference to boundary mesh.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
const lduSchedule & patchSchedule() const
Order in which the patches should be initialised/evaluated.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
void clearAdditionalGeom()
Clear geometry not used for CFD (cellTree, tetBasePtIs)
void constrain(GeometricField< Type, pointPatchField, pointMesh > &pf, const bool overrideValue=false) const
Apply boundary conditions (single-patch constraints) and.
virtual const pointField & points() const
Return raw points.
static const pointConstraints & New(const pointMesh &mesh)
Mesh representing a set of points created from polyMesh.
void correct()
Take over existing mesh position.
fileName path() const
Return complete path.
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
scalar mag() const
The magnitude of the bounding box span.
A list of faces which address into the list of points.
virtual bool separated() const
Are the planes separated.
const labelList & adaptPatchIDs() const
Patch labels that are being adapted.
vectorField pointField
pointField is a vectorField.
scalar setErrorReduction(const scalar)
Set the errorReduction (by how much to scale the displacement.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
void setDisplacementPatchFields()
Set patch fields on displacement to be consistent with.
Class applies a two-dimensional correction to mesh motion point field.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual const fileName & name() const
Return the name of the stream.
List< label > labelList
A List of labels.
virtual bool parallel() const
Are the cyclic planes parallel.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
const word & name() const
Return name.
const dictionary & paramDict() const
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
errorManip< error > abort(error &err)
label readLabel(Istream &is)
const labelList & normalEdgeIndices() const
Return indices of normal edges.
bool found(const Key &) const
Return true if hashedEntry is found in table.
const globalMeshData & globalData() const
Return parallel info.
void modifyMotionPoints(pointField &newPoints) const
Apply optional point constraint (2d correction)
prefixOSstream Pout(cout,"Pout")
label start() const
Return start vertex label.
const indirectPrimitivePatch & coupledPatch() const
Return patch of all coupled faces.
Type gMax(const FieldField< Field, Type > &f)
const polyMesh & mesh() const
Reference to mesh.
defineTypeNameAndDebug(combustionModel, 0)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
void setSize(const label)
Reset size of List.
virtual const labelList & faceNeighbour() const
Return face neighbour.
vector point
Point is a vector.
#define WarningInFunction
Report a warning using Foam::Warning.
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
const Mesh & mesh() const
Return mesh.
A cell is defined as a list of faces with extra functionality.
void correctBoundaryConditions(pointVectorField &) const
Special correctBoundaryConditions which evaluates fixedValue.
const pointMesh & pMesh() const
Reference to pointMesh.
GeometricField< vector, pointPatchField, pointMesh > pointVectorField
void unset(const PackedList< 1 > &)
Unset specified bits.
virtual const tensorField & forwardT() const
Return face transformation tensor.
dimensioned< scalar > mag(const dimensioned< Type > &)
void updateMesh()
Update for new mesh topology.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Mesh consisting of general polyhedral cells.
static const Vector< scalar > zero
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches. Adds coupled points to set.
A class for managing temporary objects.
virtual const labelList & faceOwner() const
Return face owner.
void correctPoints(pointField &p) const
Correct motion points.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
bool parallel() const
Does the mesh contain processor patches? (also valid when.
label nInternalFaces() const
const word & name() const
Return name.
tmp< pointField > curPoints() const
Get the current points (oldPoints+scale*displacement)
~motionSmootherAlgo()
Destructor.
label size() const
Return the number of elements in the UPtrList.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.