potentialFoam.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) 2011-2020 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 Application
25  potentialFoam
26 
27 Description
28  Potential flow solver which solves for the velocity potential, to
29  calculate the flux-field, from which the velocity field is obtained by
30  reconstructing the flux.
31 
32  This application is particularly useful to generate starting fields for
33  Navier-Stokes codes.
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #include "fvCFD.H"
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 int main(int argc, char *argv[])
43 {
44  argList::addOption
45  (
46  "pName",
47  "pName",
48  "Name of the pressure field"
49  );
50 
51  argList::addBoolOption
52  (
53  "initialiseUBCs",
54  "Initialise U boundary conditions"
55  );
56 
57  argList::addBoolOption
58  (
59  "writePhi",
60  "Write the velocity potential field"
61  );
62 
63  argList::addBoolOption
64  (
65  "writep",
66  "Calculate and write the pressure field"
67  );
68 
69  argList::addBoolOption
70  (
71  "withFunctionObjects",
72  "execute functionObjects"
73  );
74 
75  #include "setRootCaseLists.H"
76  #include "createTime.H"
77  #include "createMesh.H"
78 
79  nonOrthogonalSolutionControl potentialFlow(mesh, "potentialFlow");
80 
81  #include "createFields.H"
82 
83  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
84 
85  Info<< nl << "Calculating potential flow" << endl;
86 
87  // Since solver contains no time loop it would never execute
88  // function objects so do it ourselves
89  runTime.functionObjects().start();
90 
91  MRF.makeRelative(phi);
92  adjustPhi(phi, U, p);
93 
94  // Non-orthogonal velocity potential corrector loop
95  while (potentialFlow.correctNonOrthogonal())
96  {
97  fvScalarMatrix PhiEqn
98  (
100  ==
101  fvc::div(phi)
102  );
103 
104  PhiEqn.setReference(PhiRefCell, PhiRefValue);
105  PhiEqn.solve();
106 
107  if (potentialFlow.finalNonOrthogonalIter())
108  {
109  phi -= PhiEqn.flux();
110  }
111  }
112 
113  Info<< "Continuity error = "
114  << mag(fvc::div(phi))().weightedAverage(mesh.V()).value()
115  << endl;
116 
117  U = fvc::reconstruct(MRF.absolute(phi));
118  U.correctBoundaryConditions();
119 
120  Info<< "Interpolated velocity error = "
121  << (
122  sqrt(sum(sqr(fvc::flux(U) - MRF.absolute(phi))))
123  /sum(mesh.magSf())
124  ).value()
125  << endl;
126 
127  // Write U and phi
128  U.write();
129  phi.write();
130 
131  // Optionally write Phi
132  if (args.optionFound("writePhi"))
133  {
134  Phi.write();
135  }
136 
137  // Calculate the pressure field
138  if (args.optionFound("writep"))
139  {
140  Info<< nl << "Calculating approximate pressure field" << endl;
141 
142  label pRefCell = 0;
143  scalar pRefValue = 0.0;
144  setRefCell
145  (
146  p,
147  potentialFlow.dict(),
148  pRefCell,
149  pRefValue
150  );
151 
152  // Calculate the flow-direction filter tensor
153  volScalarField magSqrU(magSqr(U));
154  volSymmTensorField F(sqr(U)/(magSqrU + small*average(magSqrU)));
155 
156  // Calculate the divergence of the flow-direction filtered div(U*U)
157  // Filtering with the flow-direction generates a more reasonable
158  // pressure distribution in regions of high velocity gradient in the
159  // direction of the flow
160  volScalarField divDivUU
161  (
162  fvc::div
163  (
164  F & fvc::div(phi, U),
165  "div(div(phi,U))"
166  )
167  );
168 
169  // Solve a Poisson equation for the approximate pressure
170  while (potentialFlow.correctNonOrthogonal())
171  {
172  fvScalarMatrix pEqn
173  (
174  fvm::laplacian(p) + divDivUU
175  );
176 
177  pEqn.setReference(pRefCell, pRefValue);
178  pEqn.solve();
179  }
180 
181  p.write();
182  }
183 
184  runTime.functionObjects().end();
185 
186  Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
187  << " ClockTime = " << runTime.elapsedClockTime() << " s"
188  << nl << endl;
189 
190  Info<< "End\n" << endl;
191 
192  return 0;
193 }
194 
195 
196 // ************************************************************************* //
GeometricField< symmTensor, fvPatchField, volMesh > volSymmTensorField
Definition: volFieldsFwd.H:61
const dimensionedScalar & F
Faraday constant: default SI units: [C/mol].
fvMatrix< scalar > fvScalarMatrix
Definition: fvMatricesFwd.H:42
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
IOMRFZoneList & MRF
dimensionedSymmTensor sqr(const dimensionedVector &dv)
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcDiv.C:47
engineTime & runTime
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:114
const dictionary & potentialFlow(mesh.solutionDict().subDict("potentialFlow"))
tmp< GeometricField< Type, fvPatchField, volMesh > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcLaplacian.C:45
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
phi
Definition: pEqn.H:104
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
bool adjustPhi(surfaceScalarField &phi, const volVectorField &U, volScalarField &p)
Adjust the balance of fluxes to obey continuity.
dynamicFvMesh & mesh
dimensioned< scalar > magSqr(const dimensioned< Type > &)
static const char nl
Definition: Ostream.H:260
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> reconstruct(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
U
Definition: pEqn.H:72
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
label pRefCell
Definition: createFields.H:106
messageStream Info
tmp< GeometricField< Type, fvPatchField, volMesh > > average(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Area-weighted average a surfaceField creating a volField.
Definition: fvcAverage.C:46
dimensioned< scalar > mag(const dimensioned< Type > &)
volScalarField & p
tmp< surfaceScalarField > flux(const volVectorField &vvf)
Return the face-flux field obtained from the given volVectorField.
Definition: fvcFlux.C:32
Foam::argList args(argc, argv)
bool setRefCell(const volScalarField &field, const volScalarField &fieldRef, const dictionary &dict, label &refCelli, scalar &refValue, const bool forceReference=false)
If the field fieldRef needs referencing find the reference cell nearest.
Definition: findRefCell.C:31
scalar pRefValue
Definition: createFields.H:107