movingObject.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "multiValveEngine.H"
27 #include "pointConstraints.H"
28 #include "polyCellSet.H"
29 #include "syncTools.H"
30 
31 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
32 
34 (
35  const pointMesh& pMesh,
36  const scalarField& pDistMoving,
37  const scalarField& pDistStatic,
38  scalar dMoving,
39  scalar dMax,
40  scalar dStatic
41 )
42 {
44 
45  forAll(scale, pi)
46  {
47  // If original dMoving and dStatic regions overlay set to zero.
48  // This may happen when e.g. valve-piston distance becomes small.
49  if
50  (
51  ((pDistMoving[pi] - dMoving) <= 0) &&
52  ((pDistStatic[pi] - dStatic) <= 0)
53  )
54  {
55  dMoving = 0;
56  dStatic = 0;
57  }
58 
59  // - Near static patches
60  if (pDistStatic[pi] - dStatic <= 0)
61  {
62  scale[pi] = 0;
63  }
64  // - Near object
65  else if (pDistMoving[pi] - dMoving <= 0)
66  {
67  scale[pi] = 1;
68  }
69  // - Outside outer boundary
70  else if (dMax - pDistMoving[pi] <= 0)
71  {
72  scale[pi] = 0;
73  }
74  // Linear scaling from the moving patch:
75  // patch->dMoving: 1
76  // dMoving->min(dMax, min(dStatic - dh, dFrozenZone)): linear 1->0
77  else
78  {
79  const scalar d1 = pDistMoving[pi] - dMoving;
80  const scalar d2 = min
81  (
82  dMax - pDistMoving[pi],
83  pDistStatic[pi] - dStatic
84  );
85  scale[pi] = 1 - d1/(d1 + d2 + rootVSmall);
86  }
87  }
88 
89  // Convert the scale function to a cosine
90  if (cosine_)
91  {
92  scale =
93  min
94  (
95  max
96  (
97  0.5
98  - 0.5
100  scalar(0)
101  ),
102  scalar(1)
103  );
104  }
105 
107 
108  if (debug)
109  {
110  scale_.write();
111  }
112 }
113 
114 
116 (
117  pointField& newPoints,
118  const vector& translationVector
119 )
120 {
121  // Explicit filtering of displacement to avoid pointMesh looping
122  if (mag(translationVector) < small)
123  {
124  executionCount_++;
125  return;
126  }
127 
128  forAll(newPoints, pi)
129  {
130  const point displacementVector = scale_[pi]*translationVector;
131  if (mag(displacementVector) > small)
132  {
133  newPoints[pi] += displacementVector;
134  }
135  }
136 
137  executionCount_++;
138 }
139 
140 
142 {
143  staticPatchSet_.clear();
144 
145  forAll(meshMover_.mesh().boundaryMesh(), patchI)
146  {
147  const polyPatch& pp = meshMover_.mesh().boundaryMesh()[patchI];
148 
149  // Exclude non-static patches
150  if
151  (
152  !polyPatch::constraintType(pp.type())
153  && !meshMover_.slidingPatchSet_.found(pp.index())
154  && !patchSet.found(pp.index())
155  )
156  {
157  staticPatchSet_.insert(pp.index());
158  }
159  }
160 }
161 
162 
164 {
165  // Set patch-sets
166  patchSet_ = meshMover_.mesh().boundaryMesh().patchSet
167  (
168  wordReList(dict_.lookup("patches"))
169  );
170 
171  if (patchSet_.empty())
172  {
174  << "Empty patchSet in " << dict_.name()
175  << exit(FatalError);
176  }
177 
178  createStaticPatchSet();
179 }
180 
181 
184 {
185  labelHashSet movingPointZones;
186 
187  if (movingPointZones_.size())
188  {
189  forAll(movingPointZones_, i)
190  {
191  const labelList indices
192  (
193  meshMover_.mesh().pointZones().findIndices(movingPointZones_[i])
194  );
195 
196  if (indices.size())
197  {
198  movingPointZones.insert(indices);
199  Info<< " pointZone " << movingPointZones_[i]
200  << " will move with the object " << name << endl;
201  }
202  else
203  {
204  Info<< " movingZone " << movingPointZones_[i]
205  << " not found in pointZones" << endl;
206  }
207  }
208  }
209 
210  return movingPointZones;
211 }
212 
213 
216 {
217  labelHashSet staticPointZones;
218 
219  if (frozenPointZones_.size())
220  {
221  forAll(frozenPointZones_, i)
222  {
223  const labelList indices
224  (
225  meshMover_.mesh().pointZones().findIndices(frozenPointZones_[i])
226  );
227 
228  if (indices.size())
229  {
230  staticPointZones.insert(indices);
231  Info<< " pointZone " << frozenPointZones_[i]
232  << " is frozen (stationary)" << endl;
233  }
234  else
235  {
236  Info<< " frozenZone " << frozenPointZones_[i]
237  << " not found in pointZones" << endl;
238  }
239  }
240  }
241 
242  if (meshMover_.frozenPointZones_.size())
243  {
244  forAll(meshMover_.frozenPointZones_, i)
245  {
246  const labelList indices
247  (
248  meshMover_.mesh().pointZones().findIndices
249  (
250  meshMover_.frozenPointZones_[i]
251  )
252  );
253 
254  if (indices.size())
255  {
256  staticPointZones.insert(indices);
257  Info<< " pointZone " << meshMover_.frozenPointZones_[i]
258  << " is frozen (stationary)" << endl;
259  }
260  else
261  {
262  Info<< " frozenZone " << meshMover_.frozenPointZones_[i]
263  << " not found in pointZones" << endl;
264  }
265  }
266  }
267 
268  return staticPointZones;
269 }
270 
271 
272 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
273 
275 (
276  const word& objectName,
277  const multiValveEngine& engine,
278  const dictionary& dict
279 )
280 :
281  dict_(dict),
282  meshMover_(engine),
283  name(objectName),
284  axis(dict.lookup<vector>("axis", dimless)),
285  motion_(Function1<scalar>::New("motion", unitNone, dimLength, dict)),
286  maxMotionDistance_
287  (
288  dict.lookupOrDefault<scalar>("maxMotionDistance", dimLength, great)
289  ),
290  movingFrozenLayerThickness_
291  (
292  dict.lookupOrDefault<scalar>("movingFrozenLayerThickness", dimLength, 0)
293  ),
294  staticFrozenLayerThickness_
295  (
296  dict.lookupOrDefault<scalar>("staticFrozenLayerThickness", dimLength, 0)
297  ),
298  movingPointZones_
299  (
300  dict.lookupOrDefault("movingZones", wordReList::null())
301  ),
302  frozenPointZones_
303  (
304  dict.lookupOrDefault("frozenZones", wordReList::null())
305  ),
306  scale_
307  (
308  IOobject
309  (
310  "motionScale_" + name,
311  meshMover_.mesh().time().name(),
312  meshMover_.mesh(),
313  IOobject::NO_READ,
314  IOobject::NO_WRITE
315  ),
316  pointMesh::New(meshMover_.mesh()),
318  ),
319  cosine_(dict.lookupOrDefault("cosineScaling", false)),
320  travelInterval_
321  (
322  dict.lookupOrDefault<scalar>("travelInterval", dimLength, great)
323  ),
324  executionCount_(0),
325  position0_(-great),
326  patchSet(patchSet_)
327 {
328  Info << indent << "Setting motion for " << name << endl;
329 
330  initPatchSets();
331 }
332 
333 
334 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
335 
337 (
338  const polyMeshMap&
339 )
340 {
341  // Reset patch sets.
342  initPatchSets();
343 
344  // scale_ is resized by the meshToMesh mapper
345  scale_ = Zero;
346 
347  // Reset count of the scale_ field updates
348  executionCount_ = 0;
349 
350  // Reset position at last scale update
351  position0_ = -great;
352 }
353 
354 
355 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
static pointConstraints & New(const word &name, const pointMesh &mesh)
Construct and return the named DemandDrivenMeshObject.
Run-time selectable general function of one variable.
Definition: Function1.H:125
Internal::FieldType & primitiveFieldRef()
Return a reference to the primitive field.
const Internal::FieldType & primitiveField() const
Return a const-reference to the primitive field.
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:109
void clear()
Clear all entries from table.
Definition: HashTable.C:542
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
const dictionary & dict() const
Return the dynamicMeshDict/mover dict.
Definition: fvMeshMover.H:144
fvMesh & mesh()
Return the fvMesh.
Definition: fvMeshMover.H:132
static autoPtr< fvMeshMover > New(fvMesh &)
Select, construct and return the fvMeshMover.
void calcScale(const pointMesh &pMesh, const scalarField &pDistMoving, const scalarField &pDistStatic, scalar dMoving, scalar dMax, scalar dStatic)
Scale the mesh point deformation with distance functions.
Definition: movingObject.C:34
void createStaticPatchSet()
Generate staticPatchSet_ based on patch entries.
Definition: movingObject.C:141
movingObject(const word &name, const multiValveEngine &engine, const dictionary &dict)
Construct from dictionary.
Definition: movingObject.C:275
pointScalarField scale_
Interpolation scale (1 at moving patches, 0 at far-field)
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: movingObject.C:337
void transformPoints(pointField &newPoints, const vector &translationVector)
Definition: movingObject.C:116
Switch cosine_
Switch to use cosine-based scaling.
A mesh mover using explicit node translation based on scaled distance functions per moving object....
label index() const
Return the index of this patch in the boundaryMesh.
void constrain(PointField< Type > &pf, const bool overrideValue=false) const
Apply boundary conditions (single-patch constraints) and.
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:53
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:270
static bool constraintType(const word &pt)
Return true if the given type is a constraint type.
Definition: polyPatch.C:238
virtual bool write(const bool write=true) const
Write using setting from DB.
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static const zero Zero
Definition: zero.H:97
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
const dimensionSet dimless
messageStream Info
const dimensionSet dimLength
const unitConversion unitNone
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
dimensioned< scalar > mag(const dimensioned< Type > &)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
List< wordRe > wordReList
A List of wordRe (word or regular expression)
Definition: wordReList.H:50
error FatalError
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:227
dimensionedScalar cos(const dimensionedScalar &ds)