VoFSolver.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) 2022-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 "VoFSolver.H"
27 #include "localEulerDdtScheme.H"
28 #include "linear.H"
29 #include "fvcDiv.H"
30 #include "fvcMeshPhi.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace solvers
37 {
39 }
40 }
41 
42 
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 
46 {
48 }
49 
50 
51 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
52 
54 {
55  if (rAU.valid())
56  {
57  rAU() = 1.0/UEqn.A();
58  }
59  else
60  {
61  rAU = (1.0/UEqn.A()).ptr();
62  }
63 }
64 
65 
67 {
68  if (!(correctPhi || mesh.topoChanging()))
69  {
70  rAU.clear();
71  }
72 }
73 
74 
76 {
77  basicFluidSolver::correctCoNum(phi);
78 }
79 
80 
81 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
82 
84 (
85  fvMesh& mesh,
86  autoPtr<VoFMixture> mixturePtr
87 )
88 :
90 
91  mixturePtr_(mixturePtr),
92  mixture_(mixturePtr_()),
93 
94  divAlphaName("div(phi,alpha)"),
95 
96  U_
97  (
98  IOobject
99  (
100  "U",
101  runTime.name(),
102  mesh,
103  IOobject::MUST_READ,
104  IOobject::AUTO_WRITE
105  ),
106  mesh,
107  dimensions::velocity
108  ),
109 
110  phi_
111  (
112  IOobject
113  (
114  "phi",
115  runTime.name(),
116  mesh,
117  IOobject::READ_IF_PRESENT,
118  IOobject::AUTO_WRITE
119  ),
120  linearInterpolate(U_) & mesh.Sf()
121  ),
122 
123  buoyancy(mesh),
124 
125  p_rgh_(buoyancy.p_rgh),
126 
127  rho(mixture_.rho()),
128 
129  rhoPhi
130  (
131  IOobject
132  (
133  "rhoPhi",
134  runTime.name(),
135  mesh,
136  IOobject::NO_READ,
137  IOobject::NO_WRITE
138  ),
139  fvc::interpolate(rho)*phi_
140  ),
141 
142  MRF(MRFZones::New(mesh)),
143 
144  mixture(mixture_),
145  p_rgh(p_rgh_),
146  U(U_),
147  phi(phi_)
148 {
150 
151  if (LTS)
152  {
153  Info<< "Using LTS" << endl;
154 
156  (
157  new volScalarField
158  (
159  IOobject
160  (
162  runTime.name(),
163  mesh,
166  ),
167  mesh,
170  )
171  );
172  }
173 }
174 
175 
176 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
177 
179 {}
180 
181 
182 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
183 
185 {
186  const scalar maxAlphaCo =
187  runTime.controlDict().lookup<scalar>("maxAlphaCo");
188 
189  scalar deltaT = basicFluidSolver::maxDeltaT();
190 
191  if (alphaCoNum > small)
192  {
193  deltaT = min(deltaT, maxAlphaCo/alphaCoNum*runTime.deltaTValue());
194  }
195 
196  return deltaT;
197 }
198 
199 
201 {
202  if ((mesh.dynamic() || MRF.size()) && !Uf.valid())
203  {
204  Info<< "Constructing face momentum Uf" << endl;
205 
206  // Ensure the U BCs are up-to-date before constructing Uf
207  U_.correctBoundaryConditions();
208 
209  Uf = new surfaceVectorField
210  (
211  IOobject
212  (
213  "Uf",
214  runTime.name(),
215  mesh,
218  ),
219  fvc::interpolate(U_)
220  );
221  }
222 
223  if (transient())
224  {
225  correctCoNum();
226  }
227  else if (LTS)
228  {
229  setRDeltaT();
230  }
231 
233 
234  // Store divU from the previous mesh so that it can be mapped
235  // and used in correctPhi to ensure the corrected phi has the
236  // same divergence
237  if (correctPhi && divergent())
238  {
239  // Construct and register divU for mapping
240  divU = new volScalarField
241  (
242  "divU0",
243  fvc::div(fvc::absolute(phi, U))
244  );
245  }
246 
247  // Update the mesh for topology change, mesh to mesh mapping
248  mesh_.update();
249 }
250 
251 
253 {
254  divU.clear();
255 }
256 
257 
258 // ************************************************************************* //
Generic GeometricField class.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
const word & name() const
Return name.
Definition: IOobject.H:307
MRF zones DemandDrivenMeshObject read from MRFProperties dictionary.
Definition: MRFZones.H:76
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
const word & name() const
Return const reference to name.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:118
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:98
const fvSchemes & schemes() const
Return the fvSchemes.
Definition: fvMesh.C:1795
bool dynamic() const
Is this mesh dynamic?
Definition: fvMesh.C:697
bool topoChanging() const
Does the mesh topology change?
Definition: fvMesh.C:685
virtual void preUpdateMesh()
Prepare for mesh update.
Definition: fvModels.C:258
void setFluxRequired(const word &name) const
Definition: fvSchemes.C:434
static word rDeltaTName
Name of the reciprocal local time-step field.
bool LTS
Switch for local time step transient operation.
Definition: solver.H:70
const Time & runTime
Time.
Definition: solver.H:104
const fvMesh & mesh
Region mesh.
Definition: solver.H:101
Base solver module base-class for the solution of immiscible fluids using a VOF (volume of fluid) pha...
Definition: VoFSolver.H:73
const surfaceScalarField & phi
Reference to the mass-flux field.
Definition: VoFSolver.H:216
virtual void postSolve()
Called after the PIMPLE loop at the end of the time-step.
Definition: VoFSolver.C:252
tmp< volScalarField > trDeltaT
Optional LTS reciprocal time-step field.
Definition: VoFSolver.H:141
virtual scalar maxDeltaT() const
Return the current maximum time-step for stable solution.
Definition: VoFSolver.C:184
VoFSolver(fvMesh &mesh, autoPtr< VoFMixture >)
Construct from region mesh.
Definition: VoFSolver.C:84
void clearrAU()
Clear the cached rAU is no longer needed.
Definition: VoFSolver.C:66
virtual ~VoFSolver()
Destructor.
Definition: VoFSolver.C:178
volScalarField & p_rgh_
Reference to the buoyant pressure for buoyant cases.
Definition: VoFSolver.H:107
void continuityErrors()
Calculate and print the continuity errors.
Definition: VoFSolver.C:45
virtual void preSolve()
Called at the start of the time-step, before the PIMPLE loop.
Definition: VoFSolver.C:200
virtual void correctCoNum()=0
Correct the cached Courant numbers.
Definition: VoFSolver.C:75
void setrAU(const fvVectorMatrix &UEqn)
Set or update the cached rAU.
Definition: VoFSolver.C:53
Base solver module for fluid solvers.
void continuityErrors(const surfaceScalarField &phi)
Calculate and print the continuity errors.
virtual scalar maxDeltaT() const
Return the current maximum time-step for stable solution.
Buoyancy related data for the Foam::solvers::isothermalFluid solver module when solving buoyant cases...
Definition: buoyancy.H:70
A class for managing temporary objects.
Definition: tmp.H:55
fvVectorMatrix & UEqn
Definition: UEqn.H:11
Foam::fvModels & fvModels(Foam::fvModels::New(mesh))
const Foam::MRFZones & MRF(Foam::MRFZones::New(mesh))
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
Calculate the divergence of the given field.
Calculate the mesh motion flux and convert fluxes from absolute to relative and back.
volScalarField rAU(1.0/UEqn.A())
U
Definition: pEqn.H:72
rho
Definition: pEqn.H:1
const dimensionSet velocity
const dimensionSet dimless
static tmp< SurfaceField< Type > > interpolate(const VolField< Type > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
tmp< VolField< Type > > div(const SurfaceField< Type > &ssf)
Definition: fvcDiv.C:47
tmp< surfaceScalarField > absolute(const tmp< surfaceScalarField > &tphi, const volVectorField &U)
Return the given relative flux in absolute form.
Definition: fvcMeshPhi.C:202
defineTypeNameAndDebug(basicFluidSolver, 0)
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
messageStream Info
tmp< SurfaceField< Type > > linearInterpolate(const VolField< Type > &vf)
Definition: linear.H:108
const dimensionSet & dimTime
Definition: dimensions.C:277
VolField< scalar > volScalarField
Definition: volFieldsFwd.H:62
dimensioned< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
SurfaceField< vector > surfaceVectorField
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
correctPhi