49void Foam::motionSmootherAlgo::testSyncPositions
51 const pointField&
fld,
62 point(GREAT,GREAT,GREAT)
67 if (
mag(syncedFld[i] -
fld[i]) > maxMag)
70 <<
"On point " << i <<
" point:" <<
fld[i]
71 <<
" synchronised point:" << syncedFld[i]
82 const scalar val =
fld[pointi];
84 if ((val > -GREAT) && (val < GREAT))
89 <<
"Problem : point:" << pointi <<
" value:" << val
105 usedPoints.insert(mesh_.faces()[
faceId]);
112Foam::tmp<Foam::scalarField> Foam::motionSmootherAlgo::calcEdgeWeights
117 const edgeList& edges = mesh_.edges();
120 auto& wght = twght.ref();
124 wght[edgei] = 1.0/(edges[edgei].mag(
points)+SMALL);
131void Foam::motionSmootherAlgo::minSmooth
134 const bitSet& isAffectedPoint,
147 for (
const label pointi : meshPoints)
149 if (isAffectedPoint.test(pointi))
154 0.5*
fld[pointi] + 0.5*avgFld[pointi]
165void Foam::motionSmootherAlgo::minSmooth
168 const bitSet& isAffectedPoint,
182 if (isAffectedPoint.test(pointi) && isInternalPoint_.test(pointi))
187 0.5*
fld[pointi] + 0.5*avgFld[pointi]
199void Foam::motionSmootherAlgo::scaleField
208 if (isInternalPoint_.test(pointi))
210 fld[pointi] *= scale;
220void Foam::motionSmootherAlgo::scaleField
228 for (
const label pointi : meshPoints)
232 fld[pointi] *= scale;
239void Foam::motionSmootherAlgo::subtractField
248 if (isInternalPoint_.test(pointi))
260void Foam::motionSmootherAlgo::subtractField
268 for (
const label pointi : meshPoints)
278void Foam::motionSmootherAlgo::getAffectedFacesAndPoints
280 const label nPointIter,
287 isAffectedPoint.reset();
288 isAffectedPoint.resize(mesh_.nPoints());
290 faceSet nbrFaces(mesh_,
"checkFaces", wrongFaces);
297 for (label i = 0; i < nPointIter; i++)
299 pointSet nbrPoints(mesh_,
"grownPoints", getPoints(nbrFaces));
301 for (
const label pointi : nbrPoints)
303 for (
const label celli : mesh_.pointCells(pointi))
305 nbrFaces.set(mesh_.cells()[celli]);
308 nbrFaces.sync(mesh_);
310 if (i == nPointIter - 2)
312 for (
const label facei : nbrFaces)
314 isAffectedPoint.set(mesh_.faces()[facei]);
319 affectedFaces = nbrFaces.toc();
325Foam::motionSmootherAlgo::motionSmootherAlgo
341 displacement_(displacement),
343 oldPoints_(oldPoints),
344 adaptPatchIDs_(adaptPatchIDs),
345 paramDict_(paramDict),
347 isInternalPoint_(mesh_.
nPoints(), true)
381 return adaptPatchIDs_;
393 oldPoints_ = mesh_.points();
419 for (
auto& pfld : displacementBf)
421 if (!adaptPatchSet.
found(pfld.patch().index()))
429 for (
auto& pfld : displacementBf)
431 const label patchi = pfld.patch().index();
432 if (!adaptPatchSet.
found(patchi))
447 displacement.
mesh()(),
449 minMagSqrEqOp<vector>(),
458 displacementBf[patchi] == displacementBf[patchi].patchInternalField();
484 mesh.globalData().coupledPatch().meshPoints();
500 bitSet isPatchPoint(
mesh.nPoints(), ppMeshPoints);
501 const bitSet oldPatchPoint(isPatchPoint);
512 for (
const label pointi : cppMeshPoints)
514 if (isPatchPoint.test(pointi))
522 forAll(ppMeshPoints, patchPointi)
524 displacement[ppMeshPoints[patchPointi]] = patchDisp[patchPointi];
530 setDisplacementPatchFields(
patchIDs, displacementFld);
536 displacementBf[patchi] == displacementBf[patchi].patchInternalField();
544 forAll(ppMeshPoints, patchPointi)
546 const vector& newDisp = displacement[ppMeshPoints[patchPointi]];
548 if (
mag(newDisp-patchDisp[patchPointi]) > SMALL)
559 Pout<<
"Written " << nVerts <<
" points that are changed to file "
560 << str.name() <<
endl;
566 patchDisp[patchPointi] = displacement[ppMeshPoints[patchPointi]];
592 for (
const label patchi : adaptPatchIDs_)
594 displacementBf[patchi].initEvaluate
602 for (
const label patchi : adaptPatchIDs_)
611 for (
auto& pfld : displacementBf)
613 const label patchi = pfld.patch().index();
614 if (!adaptPatchSet.found(patchi))
622 for (
auto& pfld : displacementBf)
624 const label patchi = pfld.patch().index();
625 if (!adaptPatchSet.found(patchi))
653 Info<<
"Correcting 2-D mesh motion";
655 if (mesh_.globalData().parallel())
658 <<
"2D mesh-motion probably not correct in parallel" <<
endl;
663 const edgeList& edges = mesh_.edges();
668 for (
const label edgei : neIndices)
671 const edge&
e = edges[edgei];
673 point& pStart = newPoints[
e.start()];
675 pStart += pn*(pn & (oldPoints[
e.start()] - pStart));
677 point& pEnd = newPoints[
e.end()];
679 pEnd += pn*(pn & (oldPoints[
e.end()] - pEnd));
689 Pout<<
"motionSmootherAlgo::modifyMotionPoints :"
690 <<
" testing sync of newPoints."
692 testSyncPositions(newPoints, 1
e-6*mesh_.bounds().mag());
701 mesh_.clearTetBasePtIs();
702 pp_.movePoints(mesh_.points());
708 const scalar errorReduction
711 scalar old = paramDict_.get<scalar>(
"errorReduction");
713 paramDict_.remove(
"errorReduction");
714 paramDict_.add(
"errorReduction", errorReduction);
723 const bool smoothMesh,
724 const label nAllowableErrors
742 const bool smoothMesh,
743 const label nAllowableErrors
769 actualPatchTypes[patchi] =
pbm[patchi].type();
776 displacement_.boundaryField();
777 actualPatchFieldTypes.setSize(pfld.size());
783 actualPatchFieldTypes[patchi] =
788 actualPatchFieldTypes[patchi] = pfld[patchi].type();
798 mesh_.time().timeName(),
804 scale_*displacement_,
805 actualPatchFieldTypes,
812 Pout<<
"scaleMesh : testing sync of totalDisplacement" <<
endl;
818 1
e-6*mesh_.bounds().mag()
822 tmp<pointField> tnewPoints(oldPoints_ + totalDisplacement.primitiveField());
837 const bool smoothMesh,
838 const label nAllowableErrors
841 if (!smoothMesh && adaptPatchIDs_.empty())
844 <<
"You specified both no movement on the internal mesh points"
845 <<
" (smoothMesh = false)" <<
nl
846 <<
"and no movement on the patch (adaptPatchIDs is empty)" <<
nl
847 <<
"Hence nothing to adapt."
854 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
856 Pout<<
"Entering scaleMesh : coupled patches:" <<
endl;
861 const coupledPolyPatch&
pp =
864 Pout<<
'\t' << patchi <<
'\t' <<
pp.name()
865 <<
" parallel:" <<
pp.parallel()
866 <<
" separated:" <<
pp.separated()
867 <<
" forwardT:" <<
pp.forwardT().size()
873 const scalar errorReduction = get<scalar>
877 const label nSmoothScale = get<label>
894 Info<<
"Moving mesh using displacement scaling :"
895 <<
" min:" <<
limits.min()
896 <<
" max:" <<
limits.max()
904 mesh_.movePoints(newPoints);
908 faceSet wrongFaces(mesh_,
"wrongFaces", mesh_.nFaces()/100+100);
927 wrongFaces.sync(mesh_);
933 if (
mag(errorReduction) < SMALL)
936 for (
const label facei : wrongFaces)
938 const label own = mesh_.faceOwner()[facei];
939 const cell& ownFaces = mesh_.cells()[own];
941 newWrongFaces.insert(ownFaces);
943 if (facei < mesh_.nInternalFaces())
945 const label nei = mesh_.faceNeighbour()[facei];
946 const cell& neiFaces = mesh_.cells()[nei];
948 newWrongFaces.insert(neiFaces);
951 wrongFaces.transfer(newWrongFaces);
952 wrongFaces.sync(mesh_);
959 pointSet usedPoints(mesh_,
"usedPoints", getPoints(wrongFaces));
960 usedPoints.sync(mesh_);
966 bitSet isAffectedPoint(mesh_.nPoints());
967 getAffectedFacesAndPoints
977 Pout<<
"Faces in error:" << wrongFaces.size()
978 <<
" with points:" << usedPoints.size()
982 if (adaptPatchIDs_.size())
985 scaleField(pp_.meshPoints(), usedPoints, errorReduction, scale_);
991 scaleField(usedPoints, errorReduction, scale_);
997 for (label i = 0; i < nSmoothScale; ++i)
999 if (adaptPatchIDs_.size())
1017 minSmooth(eWeights, isAffectedPoint, oldScale, scale_);
1035 Pout<<
"scale_ after smoothing :"
1036 <<
" min:" <<
limits.min()
1037 <<
" max:" <<
limits.max()
1051 for (
const label patchi : adaptPatchIDs_)
1057 displacement_.boundaryField()[patchi]
1063 <<
" has wrong boundary condition "
1064 << displacement_.boundaryField()[patchi].type()
1065 <<
" on field " << displacement_.name() <<
nl
1066 <<
"Only type allowed is "
1067 << fixedValuePointPatchVectorField::typeName
1076 isInternalPoint_.unset(pp_.meshPoints());
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
labelList faceLabels(nFaceLabels)
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
const polyBoundaryMesh & pbm
const Mesh & mesh() const noexcept
Return const reference to mesh.
static const char *const typeName
Typename for Field.
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
GeometricBoundaryField< vector, pointPatchField, pointMesh > Boundary
const Internal::FieldType & primitiveField() const noexcept
Return a const-reference to the internal field values.
Internal & internalFieldRef(const bool updateAccessTime=true)
Return a reference to the dimensioned internal field.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
bool found(const Key &key) const
Same as contains().
label size() const noexcept
The number of elements in table.
@ NO_REGISTER
Do not request registration (bool: false).
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
const word & name() const noexcept
Return the object name.
const objectRegistry & db() const noexcept
Return the local objectRegistry.
fileName path() const
The complete path for the object (with instance, local,...).
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void setSize(label n)
Alias for resize().
static FOAM_NO_DANGLING_REFERENCE const pointConstraints & New(const pointMesh &mesh, Args &&... args)
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
virtual const fileName & name() const override
Read/write access to the name of the stream.
bool found(const T &val, label pos=0) const
Same as contains().
static label nRequests() noexcept
Number of outstanding requests (on the internal list of requests).
@ nonBlocking
"nonBlocking" (immediate) : (MPI_Isend, MPI_Irecv)
static void waitRequests()
Wait for all requests to finish.
label size() const noexcept
The number of entries in the list.
static Form uniform(const Cmpt &s)
Return a VectorSpace with all elements = s.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
bool test(const label pos) const
Test for True value at specified position, never auto-vivify entries.
A cell is defined as a list of faces with extra functionality.
The coupledPolyPatch is an abstract base class for patches that couple regions of the computational d...
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
virtual void sync(const polyMesh &mesh)
Sync faceSet across coupled patches.
A FixedValue boundary condition for pointField.
Given a displacement moves the mesh by scaling the displacement back until there are no more mesh err...
~motionSmootherAlgo()
Destructor.
void setDisplacementPatchFields()
Set patch fields on displacement to be consistent with.
tmp< pointField > curPoints() const
Get the current points (oldPoints+scale*displacement).
scalar setErrorReduction(const scalar)
Set the errorReduction (by how much to scale the displacement.
const labelList & adaptPatchIDs() const
Patch labels that are being adapted.
static void setDisplacement(const labelList &patchIDs, const indirectPrimitivePatch &pp, pointField &patchDisp, pointVectorField &displacement)
Set displacement field from displacement on patch points.
static Type get(const dictionary &dict, const word &keyword, const bool noExit, enum keyType::option matchOpt, const Type &defaultValue=Zero)
Wrapper around dictionary::get which does not exit.
void correct()
Take over existing mesh position.
const polyMesh & mesh() const
Reference to mesh.
void movePoints()
Update for new mesh geometry.
const indirectPrimitivePatch & patch() const
Reference to patch.
const pointMesh & pMesh() const
Reference to pointMesh.
static bool checkMesh(const bool report, const polyMesh &mesh, const dictionary &dict, labelHashSet &wrongFaces, const bool dryRun=false)
Check mesh with mesh settings in dict. Collects incorrect faces.
const dictionary & paramDict() const
void correctBoundaryConditions(pointVectorField &) const
Special correctBoundaryConditions which evaluates fixedValue.
static void setDisplacementPatchFields(const labelList &patchIDs, pointVectorField &pointDisplacement)
Set patch fields on patchIDs to be consistent with.
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 updateMesh()
Update for new mesh topology.
void modifyMotionPoints(pointField &newPoints) const
Apply optional point constraint (2d correction).
A pointBoundaryMesh is a pointPatch list with registered IO, a reference to the associated pointMesh,...
void constrain(GeometricField< Type, pointPatchField, pointMesh > &pf, const bool overrideValue=false) const
Apply boundary conditions (single-patch constraints) and.
void constrainCorners(GeometricField< Type, pointPatchField, pointMesh > &pf) const
Apply patch-patch constraints only.
Mesh representing a set of points created from polyMesh.
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches. Adds coupled points to set.
A polyBoundaryMesh is a polyPatch list with registered IO, a reference to the associated polyMesh,...
Mesh consisting of general polyhedral cells.
virtual const pointField & points() const
Return raw points.
A class for managing temporary objects.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Class applies a two-dimensional correction to mesh motion point field.
bool required() const
Is 2D correction required, i.e. is the mesh a wedge or slab.
void correctPoints(pointField &p) const
Correct motion points.
const labelList & normalEdgeIndices() const
Return indices of normal edges.
const vector & planeNormal() const
Return plane normal.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
const polyBoundaryMesh & patches
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for handling debugging switches.
List< edge > edgeList
List of edge.
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
List< word > wordList
List of word.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
GeometricField< scalar, pointPatchField, pointMesh > pointScalarField
List< label > labelList
A List of labels.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
messageStream Info
Information stream (stdout output on master, null elsewhere).
GeometricField< vector, pointPatchField, pointMesh > pointVectorField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
A PrimitivePatch with an IndirectList for the faces, const reference for the point field.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
errorManip< error > abort(error &err)
vector point
Point is a vector.
MinMax< Type > gMinMax(const FieldField< Field, Type > &f)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
vectorField pointField
pointField is a vectorField.
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).
labelList pointLabels(nPoints, -1)
cellMask correctBoundaryConditions()
#define forAll(list, i)
Loop across all elements in list.