multiValveEngine.H
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-2025 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 Class
25  Foam::fvMeshMovers::multiValveEngine
26 
27 Description
28  A mesh mover using explicit node translation based on scaled distance
29  functions per moving object. The mover supports any number of valves
30  together with piston motion and following features:
31 
32  - Piston motion: Function1 of user-time, may be set to
33  crankConnectingRodMotion for standard crank and connecting rod motion.
34 
35  - Valve motion: Function1, may be set to table if the valve lift date is
36  provided in the form of a table.
37 
38  - Smooth mesh motion between a moving object and other patches.
39 
40  - linerPatches: the set of patches corresponding to the cylinder liner
41  Used by zoneGenerators::cylinderHeadPoints
42 
43  - slidingPatches: a set of patches along which mesh is allowed
44  to deform. For example, on the cylinder liner, it is desired to
45  slide mesh nodes while piston is moving.
46 
47  - frozenZones: list of pointZones the points of which are frozen,
48  i.e. do not move with respect to any moving object.
49 
50  - Run-time clearance estimation based on patch-to-patch distances printed.
51 
52  - Supports cellZone definitions to restrict mesh motion.
53 
54  - Supports domains with nonConformalCoupling (NCC) interfaces,
55  enabling e.g. nodes to slide along with the interface.
56 
57  - Closing the valve can be achieved by meshToMesh mapping onto a new
58  grid with closed valve geometry at user given time.
59 
60  - Mesh motion can be controlled per moving object by setting:
61 
62  - patches: list of patches defining the object.
63 
64  - motion: a Function1 which returns the object position
65  as a function of time.
66 
67  - movingZones: list of pointZones the points of which move with the
68  object.
69 
70  - frozenZones: list of pointZones the points of which are frozen,
71  i.e. do not move with respect to this moving object.
72 
73  - maxMotionDistance: a distance away from the moving object
74  after nodes are not allowed to move. (Default inf.)
75 
76  - movingFrozenLayerThickness: thickness of layer in which points move
77  with the moving object. (Default 0)
78 
79  - staticFrozenLayerThickness: thickness of layer in which points
80  are fixed with respect to static patches (e.g. walls). (Default 0)
81 
82  - cosineScale: scaling factor between 0 and 1 for cosine scaling applied
83  to the motion. A value of 0 means linear weighting, a value of 1 means
84  full cosine scaling (much less deformation near the moving object) and
85  sustains e.g. boundary layer. (Default 0, i.e. linear weighting)
86 
87  - travelInterval: part of the stroke travelled after
88  which the cached motion scaling weights are recalculated
89 
90  For valve object only:
91 
92  - minLift: a minimum valve lift value after considered closed.
93 
94 
95  Some of the above parameters are highlighted in a given schematic
96  piston-valve configuration w.r.t entries used to control piston motion.
97  Furthermore, an example dictionary entries are provided below.
98  \verbatim
99  | | | |
100  | | | |
101  | | S | |
102  | | T | |
103  | | E | |
104  | | M | |
105  / | | \
106  / | | \
107  / | | \
108  _____________/ | | \_____________
109  | : | | : |
110  | : /``````````````` ```````````````\ : |
111  | : / VALVE HEAD \ : |
112  | L : /_____________________________________________\ : |
113  | I : /\ : |
114  | N : || staticFrozenLayerThickness : |
115  | E : NCC (optional) \/ (w.r.t. piston motion) : |
116  | R : `````````` : |
117  | : : |
118  | : : |
119  |........:.......................................................:........|
120  | : /\ : |
121  | : || movingFrozenLayerThickness : |
122  |________:_________________________\/____________________________:________|
123  PISTON
124  \endverbatim
125 
126  \verbatim
127  mover
128  {
129  type multiValveEngine;
130  libs ("libfvMeshMoversMultiValveEngine.so");
131 
132  frozenZones (frozenZone1 frozenZone2);
133 
134  slidingPatches
135  (
136  liner
137  valveStem
138  "nonCouple.*"
139  );
140 
141  linerPatches (liner);
142 
143  piston
144  {
145  patches (piston);
146  axis (0 0 1);
147 
148  motion
149  {
150  type crankConnectingRodMotion;
151 
152  conRodLength 1e3;
153  stroke 1.0;
154  }
155 
156  // Move the points in the piston bowl with the piston
157  movingZones (pistonBowl);
158 
159  // Freeze the points in the cylinder head
160  frozenZones (cylinderHead);
161 
162  // Optional
163  maxMotionDistance 1e30;
164  movingFrozenLayerThickness 0;
165  staticFrozenLayerThickness 0;
166 
167  travelInterval 0.1;
168 
169  cosineScale 0.5;
170  }
171 
172  valves
173  {
174  iv
175  {
176  patches (valveHead);
177  axis (0 0 1);
178 
179  // Optional
180  maxMotionDistance 1e30;
181  movingFrozenLayerThickness 0;
182  staticFrozenLayerThickness 0;
183 
184  travelInterval 0.01;
185 
186  cosineScale 1;
187 
188  minLift 0.001;
189 
190  motion
191  {
192  type table;
193  values
194  (
195  (0 0)
196  (480 0.1)
197  (720 0)
198  );
199  // For multi-cycle simulations, use repeat
200  outOfBounds repeat;
201  interpolationScheme linear;
202  }
203  }
204  }
205  }
206  \endverbatim
207 
208  Note:
209  The implementation utilises pointDist objects for distance computation,
210  resulting distance fields do not propagate through NCC interfaces. Hence,
211  there should be no horizontal NCC interface separating piston from
212  cylinder head as it would result in potentially ill defined mesh
213  deformation. Due to same feature, in a schematic case setup above, valve
214  motion affects only cells between NCC patches even though no cellZone is
215  explicitly defined.
216 
217 SourceFiles
218  multiValveEngine.C
219 
220 \*---------------------------------------------------------------------------*/
221 
222 #ifndef multiValveEngine_H
223 #define multiValveEngine_H
224 
225 #include "fvMeshMover.H"
226 #include "Function1.H"
227 #include "pointFields.H"
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
231 namespace Foam
232 {
233 
234 // Forward declaration of classes
235 class pointDist;
236 
237 namespace fvMeshMovers
238 {
239 
240 /*---------------------------------------------------------------------------*\
241  Class multiValveEngine Declaration
242 \*---------------------------------------------------------------------------*/
243 
244 class multiValveEngine
245 :
246  public fvMeshMover
247 {
248 public:
249 
250  class movingObject
251  {
252  friend class multiValveEngine;
253 
254  protected:
255 
256  // Protected member data
257 
258  //- Reference to engine mesh mover
260 
261 
262  public:
263 
264  //- Name of the object
265  const word name;
266 
267  //- Axis
268  const vector axis;
269 
270 
271  protected:
272 
273  // Protected member data
274 
275  //- Piston motion function
277 
278  //- Object patchNames
280 
281  //- Object patchSet
283 
284  //- Patches which must not deform during mesh motion
286 
287  //- Distance from object beyond which the mesh does not deform
288  scalar maxMotionDistance_;
289 
290  //- Distance from object within mesh nodes move
291  // along with the patch
293 
294  //- Distance from static wall patch at domain perimeter
295  // within mesh nodes do not move
297 
299 
301 
302  //- Points to move when cell zone is supplied
304 
305  //- Interpolation scale (1 at moving patches, 0 at far-field)
307 
308  //- Cosine scale for the boundary point motion, between 0 and 1
309  const scalar cosineScale_;
310 
311  //- Update the scale_ field when the travel exceeds travelInterval
312  const scalar travelInterval_;
313 
314  //- Count of the scale_ field updates
315  mutable label executionCount_;
316 
317  //- Position at last scale update
318  mutable scalar position0_;
319 
320 
321  // Protected Member Functions
322 
323  //- Scale the mesh point deformation with distance functions
324  // w.r.t. moving patches, static patches and a frozen zones.
325  void calcScale
326  (
327  const pointMesh& pMesh,
328  const scalarField& pDistMoving,
329  const scalarField& pDistStatic,
330  scalar dMoving,
331  scalar dMax,
332  scalar dStatic
333  );
334 
335  void transformPoints
336  (
337  pointField& newPoints,
338  const vector& translationVector
339  );
340 
341  //- Generate staticPatchSet_ based on patch entries
342  void createStaticPatchSet();
343 
344  //- Patch-set construction
345  void initPatchSets();
346 
348 
350 
351 
352  public:
353 
354  //- Object patchSet
355  const labelHashSet& patchSet;
356 
357  // Constructors
358 
359  //- Construct from dictionary
361  (
362  const word& name,
363  const multiValveEngine& engine,
364  const dictionary& dict
365  );
366 
367  //- Destructor
368  virtual ~movingObject()
369  {}
370 
371 
372  // Member Functions
373 
374  //- Update from another mesh using the given map
375  virtual void mapMesh(const polyMeshMap&);
376  };
377 
378 
379  class pistonObject
380  :
381  public movingObject
382  {
383  // Private member data
384 
385  //- Bore
386  scalar bore_;
387 
388  //- Clearance
389  scalar clearance_;
390 
391 
392  // Private member functions
393 
394  //- Return the bore
395  // calculated from the lateral extent of the piston
396  scalar bore() const;
397 
398  //- Calculate clearance estimate based on minimum distance
399  // between piston and any other patch excluding slidingPatches.
400  void correctClearance(pointDist&);
401 
402 
403  public:
404 
405  //- Name of the piston bowl pointZone
406  static word pistonBowlName;
407 
408  // Constructors
409 
410  //- Construct from dictionary
412  (
413  const word& name,
414  const multiValveEngine& engine,
415  const dictionary& dict
416  );
417 
418 
419  // Member Functions
420 
421  //- Return the piston position for the given CA theta
422  scalar position(const scalar theta) const;
423 
424  //- Return the current piston position
425  scalar position() const;
426 
427  //- Return piston displacement for current time-step
428  scalar displacement() const;
429 
430  //- Return piston position for current time-step
431  scalar speed() const;
432 
433  //- Return clearance estimate
434  scalar clearance() const;
435 
436  //- update points due to piston motion
437  void updatePoints(pointField&);
438 
439  //- Update from another mesh using the given map
440  virtual void mapMesh(const polyMeshMap&);
441  };
442 
443 
444  class valveObject
445  :
446  public movingObject
447  {
448  // Private member data
449 
450  //- Minimum valve lift.
451  // On this lift the valve is considered closed
452  const scalar minLift_;
453 
454 
455  // Private member functions
456 
457 
458  public:
459 
460  // Constructors
461 
462  //- Construct from dictionary
464  (
465  const word& name,
466  const multiValveEngine& engine,
467  const dictionary& dict
468  );
469 
470  //- Dummy clone function for PtrList
472  {
474  return autoPtr<valveObject>(nullptr);
475  }
476 
477 
478  // Member Functions
479 
480  // Valve position and velocity
481 
482  //- Return valve position for the given time
483  scalar lift(const scalar theta) const;
484 
485  //- Return current valve position
486  scalar lift() const;
487 
488  //- Return current valve speed
489  scalar speed() const;
490 
491  //- Return valve displacement for current time-step
492  scalar displacement() const;
493 
494  //- Is the valve open?
495  bool isOpen() const;
496 
497 
498  //- update points due to valve motion
499  void updatePoints(pointField&);
500  };
501 
502 
503  class valveList
504  :
505  public PtrList<valveObject>
506  {
507  public:
508 
509  // Constructors
510 
511  //- Construct from Istream
512  valveList
513  (
514  const multiValveEngine& engine,
515  const dictionary& dict
516  );
517  };
518 
519 
520  friend class movingObject;
521  friend class pistonObject;
522  friend class valveObject;
523 
524 
525 private:
526 
527  // Private member data
528 
529  //- User-defined liner patches
530  wordReList linerPatches_;
531 
532  //- User-defined liner patch set
533  labelHashSet linerPatchSet_;
534 
535  //- User-defined patches which the mesh can slide along
536  wordReList slidingPatches_;
537 
538  //- User-defined patch set which the mesh can slide along
539  labelHashSet slidingPatchSet_;
540 
541  //- Piston object
542  pistonObject piston_;
543 
544  //- Container for all valves
545  valveList valves_;
546 
547  //- Static patch set
548  labelHashSet staticPatchSet_;
549 
550  wordReList frozenPointZones_;
551 
552 
553  // Private member functions
554 
555  //- Lookup and return the liner patch set
556  labelHashSet findLinerPatchSet() const;
557 
558  //- Lookup and return the sliding patch set
559  labelHashSet findSlidingPatchSet();
560 
561  //- Find and return the static patch set
562  labelHashSet findStaticPatchSet();
563 
564 
565 public:
566 
567  //- Runtime type information
568  TypeName("multiValveEngine");
569 
570  //- Name of the cylinder head pointZone
571  static word cylinderHeadName;
572 
573  // Constant access to member data
574 
575  //- User-defined liner patches
577 
578  //- User-defined patches which the mesh can slide along
580 
581  //- Piston object
582  const pistonObject& piston;
583 
584  //- Container for all valves
585  const valveList& valves;
586 
587  //- Static patch set
589 
590 
591  // Constructors
592 
593  //- Construct from fvMesh
595 
596  //- Disallow default bitwise copy construction
597  multiValveEngine(const multiValveEngine&) = delete;
598 
599 
600  //- Destructor
602 
603 
604  // Member Functions
605 
606  //- Return current user-time, CAD, s or ...
607  scalar userTime() const;
608 
609  //- Return current user-time-step, CAD, s, ...
610  scalar userDeltaT() const;
611 
612  //- Update the mesh for both mesh motion and topology change
613  virtual bool update();
614 
615  //- Update corresponding to the given map
616  virtual void topoChange(const polyTopoChangeMap&);
617 
618  //- Update from another mesh using the given map
619  virtual void mapMesh(const polyMeshMap&);
620 
621  //- Update corresponding to the given distribution map
622  virtual void distribute(const polyDistributionMap&);
623 
624 
625  // Member Operators
626 
627  //- Disallow default bitwise assignment
628  void operator=(const multiValveEngine&) = delete;
629 };
630 
631 
632 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
633 } // End namespace fvMeshMovers
634 } // End namespace Foam
635 
636 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
637 
638 #endif
639 
640 // ************************************************************************* //
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Abstract base class for fvMesh movers.
Definition: fvMeshMover.H:53
fvMesh & mesh()
Return the fvMesh.
Definition: fvMeshMover.H:129
labelList pointIDs_
Points to move when cell zone is supplied.
const multiValveEngine & meshMover_
Reference to engine mesh mover.
label executionCount_
Count of the scale_ field updates.
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:33
void createStaticPatchSet()
Generate staticPatchSet_ based on patch entries.
Definition: movingObject.C:142
movingObject(const word &name, const multiValveEngine &engine, const dictionary &dict)
Construct from dictionary.
Definition: movingObject.C:265
pointScalarField scale_
Interpolation scale (1 at moving patches, 0 at far-field)
scalar position0_
Position at last scale update.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: movingObject.C:336
autoPtr< Function1< scalar > > motion_
Piston motion function.
const labelHashSet & patchSet
Object patchSet.
void transformPoints(pointField &newPoints, const vector &translationVector)
Definition: movingObject.C:117
const scalar cosineScale_
Cosine scale for the boundary point motion, between 0 and 1.
const scalar travelInterval_
Update the scale_ field when the travel exceeds travelInterval.
scalar movingFrozenLayerThickness_
Distance from object within mesh nodes move.
scalar staticFrozenLayerThickness_
Distance from static wall patch at domain perimeter.
labelHashSet staticPatchSet_
Patches which must not deform during mesh motion.
scalar maxMotionDistance_
Distance from object beyond which the mesh does not deform.
pistonObject(const word &name, const multiValveEngine &engine, const dictionary &dict)
Construct from dictionary.
Definition: piston.C:95
static word pistonBowlName
Name of the piston bowl pointZone.
scalar position() const
Return the current piston position.
Definition: piston.C:119
scalar clearance() const
Return clearance estimate.
Definition: piston.C:141
scalar displacement() const
Return piston displacement for current time-step.
Definition: piston.C:126
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: piston.C:216
void updatePoints(pointField &)
update points due to piston motion
Definition: piston.C:158
scalar speed() const
Return piston position for current time-step.
Definition: piston.C:134
valveList(const multiValveEngine &engine, const dictionary &dict)
Construct from Istream.
Definition: valveList.C:31
bool isOpen() const
Is the valve open?
Definition: valve.C:54
valveObject(const word &name, const multiValveEngine &engine, const dictionary &dict)
Construct from dictionary.
Definition: valve.C:32
scalar displacement() const
Return valve displacement for current time-step.
Definition: valve.C:85
void updatePoints(pointField &)
update points due to valve motion
Definition: valve.C:94
autoPtr< valveObject > clone() const
Dummy clone function for PtrList.
scalar speed() const
Return current valve speed.
Definition: valve.C:70
scalar lift() const
Return current valve position.
Definition: valve.C:60
A mesh mover using explicit node translation based on scaled distance functions per moving object....
TypeName("multiValveEngine")
Runtime type information.
void operator=(const multiValveEngine &)=delete
Disallow default bitwise assignment.
multiValveEngine(fvMesh &mesh, const dictionary &dict)
Construct from fvMesh.
scalar userTime() const
Return current user-time, CAD, s or ...
virtual void topoChange(const polyTopoChangeMap &)
Update corresponding to the given map.
const labelHashSet & staticPatchSet
Static patch set.
virtual void distribute(const polyDistributionMap &)
Update corresponding to the given distribution map.
const labelHashSet & linerPatchSet
User-defined liner patches.
const valveList & valves
Container for all valves.
const pistonObject & piston
Piston object.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
static word cylinderHeadName
Name of the cylinder head pointZone.
virtual bool update()
Update the mesh for both mesh motion and topology change.
const labelHashSet & slidingPatchSet
User-defined patches which the mesh can slide along.
scalar userDeltaT() const
Return current user-time-step, CAD, s, ...
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:96
Calculates the distance to the specified sets of patch and pointZone points or for all points.
Definition: pointDist.H:54
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:53
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
A class for handling words, derived from string.
Definition: word.H:62
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
dictionary dict