1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #ifndef pistonRefine_H
28 #define pistonRefine_H
30 #include "engineTopoChangerMesh.H"
31 #include "simpleEnginePiston.H"
32 #include "motionSolver.H"
33 #include "polyPatchID.H"
35 #include "volPointInterpolation.H"
37 #include "dynamicFvMesh.H"
39 #include "PackedList.H"
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 // Class forward declarations
49 /*---------------------------------------------------------------------------*\
50 Class pistonRefine Declaration
51 \*---------------------------------------------------------------------------*/
55 public engineTopoChangerMesh
61 simpleEnginePiston piston_;
64 scalar pistonPosition_;
69 //- Mesh cutting engine
72 //- Dump cellLevel for postprocessing
76 List<Pair<word> > correctFluxes_;
78 //- Number of refinement/unrefinement steps done so far.
79 label nRefinementIterations_;
81 //- Protected cells (usually since not hexes)
82 PackedList<1> protectedCell_;
85 // Private Member Functions
87 //- Count set/unset elements in packedlist.
88 static label count(const PackedList<1>&, const unsigned int);
90 //- Calculate cells that cannot be refined since would trigger
91 // refinement of protectedCell_ (since 2:1 refinement cascade)
92 void calculateProtectedCells(PackedList<1>& unrefineableCell) const;
94 //- Read the projection parameters from dictionary
98 //- Refine cells. Update mesh and fields.
99 autoPtr<mapPolyMesh> refine(const labelList&);
101 //- Unrefine cells. Gets passed in centre points of cells to combine.
102 autoPtr<mapPolyMesh> unrefine(const labelList&);
105 // Selection of cells to un/refine
107 //- Calculates approximate value for refinement level so
108 // we don't go above maxCell
109 scalar getRefineLevel
111 const label maxCells,
112 const label maxRefinement,
113 const scalar refineLevel,
117 //- Get per cell max of connected point
118 scalarField maxPointField(const scalarField&) const;
120 //- Get point min of connected cell
121 scalarField minCellField(const volScalarField&) const;
123 scalarField cellToPoint(const scalarField& vFld) const;
127 const scalarField& fld,
128 const scalar minLevel,
129 const scalar maxLevel
132 //- Select candidate cells for refinement
133 virtual void selectRefineCandidates
135 const scalar lowerRefineLevel,
136 const scalar upperRefineLevel,
137 const scalarField& vFld,
138 PackedList<1>& candidateCell
141 //- Subset candidate cells for refinement
142 virtual labelList selectRefineCells
144 const label maxCells,
145 const label maxRefinement,
146 const PackedList<1>& candidateCell
149 //- Select points that can be unrefined.
150 virtual labelList selectUnrefinePoints
152 const scalar unrefineLevel,
153 const PackedList<1>& markedCell,
154 const scalarField& pFld
157 //- Extend markedCell with cell-face-cell.
158 void extendMarkedCells(PackedList<1>& markedCell) const;
162 //- Disallow default bitwise copy construct
163 dynamicRefineFvMesh(const dynamicRefineFvMesh&);
165 //- Disallow default bitwise assignment
166 void operator=(const dynamicRefineFvMesh&);
169 //////////////////////////////////////////////// // Private data
172 // Private Member Functions
174 //- Disallow default bitwise copy construct
175 pistonRefine(const pistonRefine&);
177 //- Disallow default bitwise assignment
178 void operator=(const pistonRefine&);
180 //- Check if all patches exist, then calculate virtualPistonPosition,
181 //- pistonPosition and deckHeight for the first time
182 void checkAndCalculate();
184 //- Add valve and piston zones and modifiers
185 // void addZonesAndModifiers(){}
189 //- Runtime type information
190 TypeName("pistonRefine");
195 //- Construct from database
196 explicit pistonRefine(const IOobject& io);
201 virtual ~pistonRefine();
205 //- Direct access to the refinement engine
206 const hexRef8& meshCutter() const
211 //- Cells which should not be refined/unrefined
212 const PackedList<1>& protectedCell() const
214 return protectedCell_;
217 //- Cells which should not be refined/unrefined
218 PackedList<1>& protectedCell()
220 return protectedCell_;
226 const scalar& pistonPosition() const
228 return pistonPosition_;
231 scalar& pistonPosition()
233 return pistonPosition_;
237 const scalar& deckHeight() const
248 const simpleEnginePiston& piston() const
255 virtual bool update();
257 //- Set boundary velocities
258 void setBoundaryVelocity(volVectorField& U);
262 //- Write using given format, version and compression
263 virtual bool writeObject
265 IOstream::streamFormat fmt,
266 IOstream::versionNumber ver,
267 IOstream::compressionType cmp
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274 } // End namespace Foam
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 // ************************************************************************* //