47 void Foam::motionSmootherAlgo::testSyncPositions
60 point(great,great,great)
65 if (
mag(syncedFld[i] -
fld[i]) > maxMag)
68 <<
"On point " << i <<
" point:" <<
fld[i]
69 <<
" synchronised point:" << syncedFld[i]
80 const scalar val =
fld[pointi];
82 if ((val > -great) && (val < great))
87 <<
"Problem : point:" << pointi <<
" value:" << val
103 const face&
f = mesh_.faces()[iter.key()];
107 usedPoints.insert(
f[fp]);
120 const edgeList& edges = mesh_.edges();
122 tmp<scalarField> twght(
new scalarField(edges.size()));
127 wght[edgeI] = 1.0/(edges[edgeI].mag(
points)+small);
134 void Foam::motionSmootherAlgo::minSmooth
137 const PackedBoolList& isAffectedPoint,
143 tmp<pointScalarField> tavgFld = avg
152 label pointi = meshPoints[i];
153 if (isAffectedPoint.get(pointi) == 1)
158 0.5*
fld[pointi] + 0.5*avgFld[pointi]
169 void Foam::motionSmootherAlgo::minSmooth
172 const PackedBoolList& isAffectedPoint,
177 tmp<pointScalarField> tavgFld = avg
186 if (isAffectedPoint.get(pointi) == 1 && isInternalPoint(pointi))
191 0.5*
fld[pointi] + 0.5*avgFld[pointi]
203 void Foam::motionSmootherAlgo::scaleField
212 if (isInternalPoint(iter.key()))
214 fld[iter.key()] *= scale;
224 void Foam::motionSmootherAlgo::scaleField
234 label pointi = meshPoints[i];
238 fld[pointi] *= scale;
245 void Foam::motionSmootherAlgo::subtractField
254 if (isInternalPoint(iter.key()))
256 fld[iter.key()] =
max(0.0,
fld[iter.key()]-
f);
266 void Foam::motionSmootherAlgo::subtractField
276 label pointi = meshPoints[i];
286 bool Foam::motionSmootherAlgo::isInternalPoint(
const label pointi)
const
288 return isInternalPoint_.get(pointi) == 1;
292 void Foam::motionSmootherAlgo::getAffectedFacesAndPoints
294 const label nPointIter,
295 const faceSet& wrongFaces,
298 PackedBoolList& isAffectedPoint
301 isAffectedPoint.setSize(mesh_.nPoints());
304 faceSet nbrFaces(mesh_,
"checkFaces", wrongFaces);
311 for (
label i = 0; i < nPointIter; i++)
313 pointSet nbrPoints(mesh_,
"grownPoints", getPoints(nbrFaces.toc()));
317 const labelList& pCells = mesh_.pointCells(iter.key());
321 const cell& cFaces = mesh_.cells()[pCells[pCelli]];
325 nbrFaces.insert(cFaces[cFacei]);
329 nbrFaces.sync(mesh_);
331 if (i == nPointIter - 2)
335 const face&
f = mesh_.faces()[iter.key()];
338 isAffectedPoint.set(
f[fp], 1);
344 affectedFaces = nbrFaces.toc();
365 displacement_(displacement),
367 oldPoints_(oldPoints),
368 adaptPatchIndices_(adaptPatchIDs),
369 paramDict_(paramDict),
370 isInternalPoint_(mesh_.
nPoints(), 1)
404 return adaptPatchIndices_;
416 oldPoints_ = mesh_.points();
442 displacementBf[
patchi].patchInternalField();
454 forAll(patchSchedule, patchEvalI)
460 if (patchSchedule[patchEvalI].init)
484 displacementBf[
patchi].patchInternalField();
491 setDisplacementPatchFields(adaptPatchIndices_, displacement_);
520 forAll(ppMeshPoints, patchPointi)
522 displacement[ppMeshPoints[patchPointi]] = patchDisp[patchPointi];
538 setDisplacementPatchFields(patchIDs, displacement);
545 forAll(ppMeshPoints, patchPointi)
547 const vector& newDisp = displacement[ppMeshPoints[patchPointi]];
549 if (
mag(newDisp-patchDisp[patchPointi]) > small)
551 const point& pt = mesh.
points()[ppMeshPoints[patchPointi]];
560 Pout<<
"Written " << nVerts <<
" points that are changed to file "
565 forAll(ppMeshPoints, patchPointi)
567 patchDisp[patchPointi] = displacement[ppMeshPoints[patchPointi]];
574 setDisplacement(adaptPatchIndices_, pp_, patchDisp, displacement_);
586 const lduSchedule& patchSchedule = mesh_.globalData().patchSchedule();
592 forAll(patchSchedule, patchEvalI)
598 if (patchSchedule[patchEvalI].init)
613 forAll(patchSchedule, patchEvalI)
619 if (patchSchedule[patchEvalI].init)
654 Info<<
"Correcting 2-D mesh motion";
656 if (mesh_.globalData().parallel())
659 <<
"2D mesh-motion probably not correct in parallel" <<
endl;
664 const edgeList& edges = mesh_.edges();
671 const edge&
e = edges[neIndices[i]];
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();
708 const scalar errorReduction
711 scalar oldErrorReduction = paramDict_.lookup<scalar>(
"errorReduction");
713 paramDict_.remove(
"errorReduction");
714 paramDict_.add(
"errorReduction", errorReduction);
716 return oldErrorReduction;
723 const bool smoothMesh,
724 const label nAllowableErrors
742 const bool smoothMesh,
743 const label nAllowableErrors
776 displacement_.boundaryField();
783 actualPatchFieldTypes[
patchi] =
804 scale_*displacement_,
805 actualPatchFieldTypes,
812 Pout<<
"scaleMesh : testing sync of totalDisplacement" <<
endl;
818 1
e-6*mesh_.bounds().mag()
825 modifyMotionPoints(tnewPoints.
ref());
837 const bool smoothMesh,
838 const label nAllowableErrors
841 if (!smoothMesh && adaptPatchIndices_.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."
856 Pout<<
"Entering scaleMesh : coupled patches:" <<
endl;
871 const scalar errorReduction =
872 paramDict.
lookup<scalar>(
"errorReduction");
874 const label nSmoothScale =
888 Info<<
"Moving mesh using displacement scaling :"
889 <<
" min:" <<
gMin(scale_.primitiveField())
890 <<
" max:" <<
gMax(scale_.primitiveField())
897 mesh_.setPoints(newPoints);
902 faceSet wrongFaces(mesh_,
"wrongFaces", mesh_.nFaces()/100+100);
920 wrongFaces.
sync(mesh_);
926 if (
mag(errorReduction) < small)
931 label own = mesh_.faceOwner()[iter.key()];
932 const cell& ownFaces = mesh_.cells()[own];
936 newWrongFaces.
insert(ownFaces[cfI]);
939 if (iter.key() < mesh_.nInternalFaces())
941 label nei = mesh_.faceNeighbour()[iter.key()];
942 const cell& neiFaces = mesh_.cells()[nei];
946 newWrongFaces.
insert(neiFaces[cfI]);
951 wrongFaces.
sync(mesh_);
958 pointSet usedPoints(mesh_,
"usedPoints", getPoints(wrongFaces));
959 usedPoints.
sync(mesh_);
968 getAffectedFacesAndPoints
978 Pout<<
"Faces in error:" << wrongFaces.
size()
979 <<
" with points:" << usedPoints.
size()
983 if (adaptPatchIndices_.size())
986 scaleField(pp_.meshPoints(), usedPoints, errorReduction, scale_);
992 scaleField(usedPoints, errorReduction, scale_);
998 for (
label i = 0; i < nSmoothScale; i++)
1000 if (adaptPatchIndices_.size())
1018 minSmooth(eWeights, isAffectedPoint, oldScale, scale_);
1034 Pout<<
"scale_ after smoothing :"
1050 forAll(adaptPatchIndices_, i)
1056 !isA<fixedValuePointPatchVectorField>
1058 displacement_.boundaryField()[
patchi]
1064 <<
" has wrong boundary condition "
1065 << displacement_.boundaryField()[
patchi].type()
1066 <<
" on field " << displacement_.name() <<
nl
1067 <<
"Only type allowed is "
1068 << fixedValuePointPatchVectorField::typeName
1077 const labelList& meshPoints = pp_.meshPoints();
1081 isInternalPoint_.unset(meshPoints[i]);
#define forAll(list, i)
Loop across all elements in list.
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
static pointConstraints & New(const word &name, const pointMesh &mesh)
Construct and return the named DemandDrivenMeshObject.
const Mesh & mesh() const
Return mesh.
Generic GeometricBoundaryField class.
void evaluate()
Evaluate boundary conditions.
const Internal::FieldType & primitiveField() const
Return a const-reference to the primitive field.
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
bool insert(const Key &key)
Insert a new entry.
void transfer(HashTable< T, Key, Hash > &)
Transfer the contents of the argument table into this table.
label size() const
Return number of elements in table.
bool found(const Key &) const
Return true if hashedEntry is found in table.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
const objectRegistry & db() const
Return the local objectRegistry.
void setSize(const label)
Reset size of List.
const fileName & name() const
Return the name of the stream.
const labelList & meshPoints() const
Return labelList of mesh points in patch. They are constructed.
label size() const
Return the number of elements in the UPtrList.
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...
virtual const transformer & transform() const =0
Return transformation between the coupled patches.
A list of keyword definitions, which are a keyword followed by any number of values (e....
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
virtual void sync(const polyMesh &mesh)
Sync faceSet across coupled patches.
const indirectPrimitivePatch & coupledPatch() const
Return patch of all coupled faces.
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.
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.
tmp< pointField > curPoints() const
Get the current points (oldPoints+scale*displacement)
void topoChange()
Update for new mesh topology.
scalar setErrorReduction(const scalar)
Set the errorReduction (by how much to scale the displacement.
static void setDisplacement(const labelList &patchIDs, const indirectPrimitivePatch &pp, pointField &patchDisp, pointVectorField &displacement)
Set displacement field from displacement on patch points.
void correct()
Take over existing mesh position.
const polyMesh & mesh() const
Reference to mesh.
bool scaleMesh(const labelList &checkFaces, const bool smoothMesh=true, const label nAllow=0)
Move mesh with given scale. Return true if mesh ok or has.
void movePoints()
Update for new mesh geometry.
const indirectPrimitivePatch & patch() const
Reference to patch.
const pointMesh & pMesh() const
Reference to pointMesh.
const labelList & adaptPatchIndices() const
Patch labels that are being adapted.
const dictionary & paramDict() const
void correctBoundaryConditions(pointVectorField &) const
Special correctBoundaryConditions which evaluates fixedValue.
void modifyMotionPoints(pointField &newPoints) const
Apply optional point constraint (2d correction)
fileName path(const word &instance, const fileName &local="") const
Return complete path with alternative instance and local.
const word & name() const
Return name.
const pointMesh & mesh() const
Return the mesh reference.
void constrain(PointField< Type > &pf, const bool overrideValue=false) const
Apply boundary conditions (single-patch constraints) and.
void constrainCorners(PointField< Type > &pf) const
Apply patch-patch constraints only.
Mesh representing a set of points created from polyMesh.
const pointBoundaryMesh & boundary() const
Return reference to boundary mesh.
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches. Adds coupled points to set.
Mesh consisting of general polyhedral cells.
const globalMeshData & globalData() const
Return parallel info.
virtual const pointField & points() const
Return raw points.
A class for managing temporary objects.
T & ref() const
Return non-const reference or generate a fatal error.
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.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
gmvFile<< "tracers "<< particles.size()<< nl;{ pointField positions(particles.size());label particlei=0;forAllConstIter(Cloud< passiveParticle >, particles, iter) { positions[particlei++]=iter().position(mesh);} for(i=0;i< pTraits< point >::nComponents;i++) { forAll(positions, particlei) { gmvFile<< component(positions[particlei], i)<< ' ';} gmvFile<< nl;}}forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
const fvPatchList & patches
U correctBoundaryConditions()
Functions for checking mesh topology and geometry.
#define WarningInFunction
Report a warning using Foam::Warning.
bool checkMesh(const bool report, const polyMesh &mesh, const dictionary &dict, const labelList &checkFaces, const List< labelPair > &baffles, labelHashSet &wrongFaces)
Check (subset of mesh including baffles) with mesh settings in dict.
errorManipArg< error, int > exit(error &err, const int errNo=1)
List< label > labelList
A List of labels.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
vectorField pointField
pointField is a vectorField.
vector point
Point is a vector.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
PointField< scalar > pointScalarField
bool isA(const Type &t)
Check if a dynamic_cast to typeid is possible.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
dimensioned< scalar > mag(const dimensioned< Type > &)
defineTypeNameAndDebug(combustionModel, 0)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
prefixOSstream Pout(cout, "Pout")
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Type gMin(const FieldField< Field, Type > &f)
Type gMax(const FieldField< Field, Type > &f)
labelList pointLabels(nPoints, -1)