piston.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-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 \*---------------------------------------------------------------------------*/
25 
26 #include "multiValveEngine.H"
27 #include "pointDist.H"
28 
29 /* * * * * * * * * * * * * Static Private Data * * * * * * * * * * * */
30 
32 (
33  "pistonBowl"
34 );
35 
36 
37 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
38 
39 void Foam::fvMeshMovers::multiValveEngine::pistonObject::calculateBore()
40 {
41  const polyBoundaryMesh& pbm = meshMover_.mesh().poly().boundary();
42 
43  // Find the maximum and minimum coordinates of the piston patch-set
44  vector pistonMax(vector::min);
45  vector pistonMin(vector::max);
46 
48  {
49  const label patchi = iter.key();
50  if (pbm[patchi].localPoints().size())
51  {
52  pistonMax = max(pistonMax, max(pbm[patchi].localPoints()));
53  pistonMin = min(pistonMin, min(pbm[patchi].localPoints()));
54  }
55  }
56 
57  reduce(pistonMax, maxOp<point>());
58  reduce(pistonMin, minOp<point>());
59 
60  // Assuming the piston moves in the positive axis direction
61  // remove the axis_ component to find the lateral extent of the piston
62  pistonMax -= (axis & pistonMax)*axis;
63  pistonMin -= (axis & pistonMin)*axis;
64 
65  bore_ = mag(pistonMax - pistonMin)/sqrt(2.0);
66  centre_ = (pistonMax + pistonMin)/2;
67 }
68 
69 
70 void Foam::fvMeshMovers::multiValveEngine::pistonObject::correctClearance()
71 {
72  const polyBoundaryMesh& pbm = meshMover_.mesh().poly().boundary();
73 
74  // Find the maximum and minimum coordinate of the liner patch-sets
75  scalar linerMax(-great);
76  scalar linerMin(great);
77 
78  forAllConstIter(labelHashSet, meshMover_.linerPatchSet_, iter)
79  {
80  const label patchi = iter.key();
81  if (pbm[patchi].localPoints().size())
82  {
83  linerMax = max(linerMax, axis & max(pbm[patchi].localPoints()));
84  linerMin = min(linerMin, axis & min(pbm[patchi].localPoints()));
85  }
86  }
87 
88  reduce(linerMax, maxOp<scalar>());
89  reduce(linerMin, minOp<scalar>());
90 
91  clearance_ = linerMax - linerMin;
92 }
93 
94 
95 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
96 
98 (
99  const word& name,
100  const multiValveEngine& engine,
101  const dictionary& dict
102 )
103 :
104  movingObject(name, engine, dict),
105  clearance_(0)
106 {
107  calculateBore();
108 }
109 
110 
111 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
112 
114 {
115  return bore_;
116 }
117 
118 
120 {
121  return centre_;
122 }
123 
124 
126 (
127  const scalar theta
128 ) const
129 {
130  return motion_->value(theta);
131 }
132 
133 
134 Foam::scalar
136 {
137  return position(meshMover_.userTime());
138 }
139 
140 
141 Foam::scalar
143 {
144  return
145  position(meshMover_.userTime() - meshMover_.userDeltaT())
146  - position();
147 }
148 
149 
151 {
152  return displacement()/(meshMover_.mesh().time().deltaTValue() + vSmall);
153 }
154 
155 
156 Foam::scalar
158 {
159  if (mag(position() - position0_) > travelInterval_)
160  {
161  return clearance_;
162  }
163  else
164  {
165  // Note, valve movement is not considered as valveSet may include
166  // other valves than ones related to ports. Furthermore, this value
167  // is only an estimate and updated rather frequently anyway.
168  return clearance_ - displacement();
169  }
170 }
171 
172 
174 (
175  pointField& newPoints
176 )
177 {
178  const scalar position = this->position();
179 
180  // Update a cached scale_ field if needed
181  if
182  (
183  executionCount_ == 0
184  || mag(position - position0_) > travelInterval_
185  )
186  {
187  Info << " Updating scale field" << endl;
188 
189  const pointMesh& pMesh = pointMesh::New(meshMover_.mesh());
190  const pointField& points(meshMover_.mesh().points());
191 
192  pointDist pDistMoving
193  (
194  pMesh,
195  patchSet,
196  movingPointZones(),
197  staticPatchSet_,
198  staticPointZones(),
199  points,
200  maxMotionDistance_
201  );
202 
203  pointDist pDistStatic
204  (
205  pMesh,
206  staticPatchSet_,
207  staticPointZones(),
208  patchSet,
209  movingPointZones(),
210  points,
211  maxMotionDistance_
212  );
213 
214  // Update the clearance from the distance to piston field
215  correctClearance();
216 
217  calcScale
218  (
219  pMesh,
220  pDistMoving,
221  pDistStatic,
222  movingFrozenLayerThickness_,
223  maxMotionDistance_,
224  staticFrozenLayerThickness_
225  );
226 
227  position0_ = position;
228  }
229 
230  const vector translationVector(displacement()*axis);
231  transformPoints(newPoints, translationVector);
232 }
233 
234 
236 (
237  const polyMeshMap& map
238 )
239 {
241 }
242 
243 
244 // ************************************************************************* //
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:492
static pointMesh & New(const word &name, const polyMesh &mesh)
Construct and return the named DemandDrivenMeshObject.
static const Form max
Definition: VectorSpace.H:120
static const Form min
Definition: VectorSpace.H:121
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
fvMesh & mesh()
Return the fvMesh.
Definition: fvMeshMover.H:102
const multiValveEngine & meshMover_
Reference to engine mesh mover.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: movingObject.C:336
const labelHashSet & patchSet
Object patchSet.
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
A mesh mover using explicit node translation based on scaled distance functions per moving object....
const polyMesh & poly() const
Return reference to polyMesh.
Definition: fvMesh.H:456
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:52
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
const polyBoundaryMesh & boundary() const
Return boundary mesh.
Definition: polyMesh.H:393
A class for handling words, derived from string.
Definition: word.H:63
label patchi
const pointField & points
point position(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label facei, const label faceTrii, const scalar stepFraction)
Return the position given the coordinates and tet topology.
Definition: trackingI.H:224
void transformPoints(vectorField &, const spatialTransform &, const vectorField &)
Transform given vectorField of coordinates with the given spatialTransform.
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
messageStream Info
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
dimensioned< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:213
tmp< DimensionedField< scalar, GeoMesh, Field > > mag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
dictionary dict