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();
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
710 scalar oldErrorReduction = paramDict_.
lookup<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]);
870 const scalar errorReduction =
871 paramDict.
lookup<scalar>(
"errorReduction");
873 const label nSmoothScale =
887 Info<<
"Moving mesh using displacement scaling :" 901 faceSet wrongFaces(mesh_,
"wrongFaces", mesh_.
nFaces()/100+100);
902 checkMesh(
false, mesh_, meshQualityDict, checkFaces, baffles, wrongFaces);
911 wrongFaces.sync(mesh_);
917 if (
mag(errorReduction) < small)
923 const cell& ownFaces = mesh_.
cells()[own];
927 newWrongFaces.
insert(ownFaces[cfI]);
933 const cell& neiFaces = mesh_.
cells()[nei];
937 newWrongFaces.
insert(neiFaces[cfI]);
941 wrongFaces.transfer(newWrongFaces);
942 wrongFaces.sync(mesh_);
949 pointSet usedPoints(mesh_,
"usedPoints", getPoints(wrongFaces));
950 usedPoints.
sync(mesh_);
958 getAffectedFacesAndPoints
968 Pout<<
"Faces in error:" << wrongFaces.size()
969 <<
" with points:" << usedPoints.
size()
973 if (adaptPatchIDs_.
size())
976 scaleField(pp_.
meshPoints(), usedPoints, errorReduction, scale_);
982 scaleField(usedPoints, errorReduction, scale_);
988 for (
label i = 0; i < nSmoothScale; i++)
990 if (adaptPatchIDs_.
size())
1008 minSmooth(eWeights, isAffectedPoint, oldScale, scale_);
1024 Pout<<
"scale_ after smoothing :" 1040 forAll(adaptPatchIDs_, i)
1046 !isA<fixedValuePointPatchVectorField>
1053 <<
"Patch " << patches[
patchi].name()
1054 <<
" has wrong boundary condition " 1056 <<
" on field " << displacement_.
name() <<
nl 1057 <<
"Only type allowed is " 1058 << fixedValuePointPatchVectorField::typeName
1071 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.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
bool isA(const Type &t)
Check if a dynamic_cast to typeid is possible.
virtual const fileName & name() const
Return the name of the stream.
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 empty() const
Return true if the UList is empty (ie, size() is zero)
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 polyMesh & mesh() const
Reference to mesh.
const word & name() const
Return name.
const word & name() const
Return name.
motionSmootherAlgo(polyMesh &, pointMesh &, indirectPrimitivePatch &pp, pointVectorField &displacement, pointScalarField &scale, pointField &oldPoints, const labelList &adaptPatchIDs, const dictionary ¶mDict)
Construct from mesh, patches to work on and smoothing parameters.
errorManipArg< error, int > exit(error &err, const int errNo=1)
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)
label nInternalFaces() const
static void setDisplacement(const labelList &patchIDs, const indirectPrimitivePatch &pp, pointField &patchDisp, pointVectorField &displacement)
Set displacement field from displacement on patch points.
virtual const labelList & faceNeighbour() const
Return face neighbour.
const lduSchedule & patchSchedule() const
Order in which the patches should be initialised/evaluated.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
void correctBoundaryConditions(pointVectorField &) const
Special correctBoundaryConditions which evaluates fixedValue.
bool scaleMesh(labelList &checkFaces, const bool smoothMesh=true, const label nAllow=0)
Move mesh with given scale. Return true if mesh ok or has.
void size(const label)
Override size to be inconsistent with allocated storage.
const pointMesh & pMesh() const
Reference to pointMesh.
const dictionary & paramDict() const
const labelList & normalEdgeIndices() const
Return indices of normal edges.
Ostream & endl(Ostream &os)
Add newline and flush stream.
The coupledPolyPatch is an abstract base class for patches that couple regions of the computational d...
const Internal::FieldType & primitiveField() const
Return a const-reference to the internal field.
const cellList & cells() const
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
virtual const transformer & transform() const =0
Return transformation between the coupled patches.
void movePoints()
Update for new mesh geometry.
bool parallel() const
Does the mesh contain processor patches? (also valid when.
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
Foam::indirectPrimitivePatch.
bool insert(const Key &key)
Insert a new entry.
label size() const
Return number of elements in table.
const labelList & meshPoints() const
Return labelList of mesh points in patch. They are constructed.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
fileName path() const
Return complete path.
virtual const pointField & points() const
Return raw points.
Mesh representing a set of points created from polyMesh.
void correctPoints(pointField &p) const
Correct motion points.
void correct()
Take over existing mesh position.
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
A list of faces which address into the list of points.
vectorField pointField
pointField is a vectorField.
scalar setErrorReduction(const scalar)
Set the errorReduction (by how much to scale the displacement.
bool required() const
Is 2D correction required, i.e. is the mesh a wedge or slab.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
bool found(const Key &) const
Return true if hashedEntry is found in table.
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.
scalar mag() const
The magnitude of the bounding box span.
virtual const labelList & faceOwner() const
Return face owner.
const globalMeshData & globalData() const
Return parallel info.
List< label > labelList
A List of labels.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
errorManip< error > abort(error &err)
void modifyMotionPoints(pointField &newPoints) const
Apply optional point constraint (2d correction)
const Mesh & mesh() const
Return mesh.
Type gMax(const FieldField< Field, Type > &f)
const vector & planeNormal() const
Return plane normal.
const Time & time() const
Return time.
defineTypeNameAndDebug(combustionModel, 0)
const indirectPrimitivePatch & patch() const
Reference to patch.
static pointConstraints & New(pointMesh &mesh)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
void clearTetBasePtIs()
Clear tet base points.
label size() const
Return the number of elements in the UPtrList.
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
const indirectPrimitivePatch & coupledPatch() const
Return patch of all coupled faces.
void setSize(const label)
Reset size of List.
const boundBox & bounds() const
Return mesh bounding box.
vector point
Point is a vector.
#define WarningInFunction
Report a warning using Foam::Warning.
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
tmp< pointField > curPoints() const
Get the current points (oldPoints+scale*displacement)
label end() const
Return end vertex label.
A cell is defined as a list of faces with extra functionality.
prefixOSstream Pout(cout, "Pout")
GeometricField< vector, pointPatchField, pointMesh > pointVectorField
void unset(const PackedList< 1 > &)
Unset specified bits.
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)
const doubleScalar e
Elementary charge.
Mesh consisting of general polyhedral cells.
const labelList & adaptPatchIDs() const
Patch labels that are being adapted.
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches. Adds coupled points to set.
A class for managing temporary objects.
const objectRegistry & db() const
Return the local objectRegistry.
const pointBoundaryMesh & boundary() const
Return reference to boundary mesh.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
void constrain(GeometricField< Type, pointPatchField, pointMesh > &pf, const bool overrideValue=false) const
Apply boundary conditions (single-patch constraints) and.
static const Vector< scalar > zero
label start() const
Return start vertex label.
~motionSmootherAlgo()
Destructor.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.