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-2026 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 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 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 Data
384 
385  //- Cylinder bore
386  scalar bore_;
387 
388  //- Cylinder centre
389  vector centre_;
390 
391  //- Clearance
392  scalar clearance_;
393 
394 
395  // Private Member Functions
396 
397  //- Calculate and bore and centre
398  // calculated from the lateral extent of the piston
399  void calculateBore();
400 
401  //- Calculate clearance from the liner extent
402  void correctClearance();
403 
404 
405  public:
406 
407  //- Name of the piston bowl pointZone
408  static word pistonBowlName;
409 
410  // Constructors
411 
412  //- Construct from dictionary
414  (
415  const word& name,
416  const multiValveEngine& engine,
417  const dictionary& dict
418  );
419 
420 
421  // Member Functions
422 
423  //- Return the bore
424  scalar bore() const;
425 
426  //- Return the piston centre
427  vector centre() const;
428 
429  //- Return the piston position for the given CA theta
430  scalar position(const scalar theta) const;
431 
432  //- Return the current piston position
433  scalar position() const;
434 
435  //- Return piston displacement for current time-step
436  scalar displacement() const;
437 
438  //- Return piston position for current time-step
439  scalar speed() const;
440 
441  //- Return clearance estimate
442  scalar clearance() const;
443 
444  //- update points due to piston motion
445  void updatePoints(pointField&);
446 
447  //- Update from another mesh using the given map
448  virtual void mapMesh(const polyMeshMap&);
449  };
450 
451 
452  class valveObject
453  :
454  public movingObject
455  {
456  // Private Data
457 
458  //- Minimum valve lift.
459  // On this lift the valve is considered closed
460  const scalar minLift_;
461 
462 
463  // Private Member Functions
464 
465 
466  public:
467 
468  // Constructors
469 
470  //- Construct from dictionary
472  (
473  const word& name,
474  const multiValveEngine& engine,
475  const dictionary& dict
476  );
477 
478  //- Dummy clone function for PtrList
480  {
482  return autoPtr<valveObject>(nullptr);
483  }
484 
485 
486  // Member Functions
487 
488  // Valve position and velocity
489 
490  //- Return valve position for the given time
491  scalar lift(const scalar theta) const;
492 
493  //- Return current valve position
494  scalar lift() const;
495 
496  //- Return current valve speed
497  scalar speed() const;
498 
499  //- Return valve displacement for current time-step
500  scalar displacement() const;
501 
502  //- Is the valve open?
503  bool isOpen() const;
504 
505 
506  //- update points due to valve motion
507  void updatePoints(pointField&);
508  };
509 
510 
511  class valveList
512  :
513  public PtrList<valveObject>
514  {
515  public:
516 
517  // Constructors
518 
519  //- Construct from Istream
520  valveList
521  (
522  const multiValveEngine& engine,
523  const dictionary& dict
524  );
525  };
526 
527 
528  friend class movingObject;
529  friend class pistonObject;
530  friend class valveObject;
531 
532 
533 private:
534 
535  // Private Data
536 
537  //- User-defined liner patches
538  wordReList linerPatches_;
539 
540  //- User-defined liner patch set
541  labelHashSet linerPatchSet_;
542 
543  //- User-defined patches which the mesh can slide along
544  wordReList slidingPatches_;
545 
546  //- User-defined patch set which the mesh can slide along
547  labelHashSet slidingPatchSet_;
548 
549  //- Piston object
550  pistonObject piston_;
551 
552  //- Container for all valves
553  valveList valves_;
554 
555  //- Static patch set
556  labelHashSet staticPatchSet_;
557 
558  wordReList frozenPointZones_;
559 
560 
561  // Private Member Functions
562 
563  //- Lookup and return the liner patch set
564  labelHashSet findLinerPatchSet() const;
565 
566  //- Lookup and return the sliding patch set
567  labelHashSet findSlidingPatchSet();
568 
569  //- Find and return the static patch set
570  labelHashSet findStaticPatchSet();
571 
572 
573 public:
574 
575  //- Runtime type information
576  TypeName("multiValveEngine");
577 
578  //- Name of the cylinder head pointZone
579  static word cylinderHeadName;
580 
581  // Constant access to member data
582 
583  //- User-defined liner patches
585 
586  //- User-defined patches which the mesh can slide along
588 
589  //- Piston object
590  const pistonObject& piston;
591 
592  //- Container for all valves
593  const valveList& valves;
594 
595  //- Static patch set
597 
598 
599  // Constructors
600 
601  //- Construct from fvMesh
603 
604  //- Disallow default bitwise copy construction
605  multiValveEngine(const multiValveEngine&) = delete;
606 
607 
608  //- Destructor
610 
611 
612  // Member Functions
613 
614  //- Return current user-time, CAD, s or ...
615  scalar userTime() const;
616 
617  //- Return current user-time-step, CAD, s, ...
618  scalar userDeltaT() const;
619 
620  //- Update the mesh for both mesh motion and topology change
621  virtual bool update();
622 
623  //- Update corresponding to the given map
624  virtual void topoChange(const polyTopoChangeMap&);
625 
626  //- Update from another mesh using the given map
627  virtual void mapMesh(const polyMeshMap&);
628 
629  //- Update corresponding to the given distribution map
630  virtual void distribute(const polyDistributionMap&);
631 
632 
633  // Member Operators
634 
635  //- Disallow default bitwise assignment
636  void operator=(const multiValveEngine&) = delete;
637 };
638 
639 
640 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
641 } // End namespace fvMeshMovers
642 } // End namespace Foam
643 
644 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
645 
646 #endif
647 
648 // ************************************************************************* //
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:102
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:98
static word pistonBowlName
Name of the piston bowl pointZone.
scalar bore() const
Return the bore.
Definition: piston.C:113
scalar position() const
Return the current piston position.
Definition: piston.C:135
scalar clearance() const
Return clearance estimate.
Definition: piston.C:157
scalar displacement() const
Return piston displacement for current time-step.
Definition: piston.C:142
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: piston.C:236
vector centre() const
Return the piston centre.
Definition: piston.C:119
void updatePoints(pointField &)
update points due to piston motion
Definition: piston.C:174
scalar speed() const
Return piston position for current time-step.
Definition: piston.C:150
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:98
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:52
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:63
#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