multiRegionSimpleFoam.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 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  chtMultiRegionSimpleFoam
26 
27  Group
28  grpHeatTransferSolvers
29 
30  Description
31  Steady-state version of MultiRegionSimpleFoam
32 
33  \*---------------------------------------------------------------------------*/
34 
35 #include "fvCFD.H"
36 #include "regionProperties.H"
37 #include "fvOptions.H"
38 #include "simpleControl.H"
41 //#include "turbulentBoundaryCoupledFvPatchScalarField.H"
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 int main(int argc, char *argv[])
45 {
46 #include "setRootCase.H"
47 #include "createTime.H"
48 
49  regionProperties rp(runTime);
50 
51  //#include "createFluidMeshes.H"
52  const wordList fluidNames(rp["fluid"]);
54  Info << "there are " << fluidNames.size() << " regions." << endl<< endl;
55  forAll(fluidNames, i)
56  {
57  Info<< "Create fluid mesh for region " << fluidNames[i]
58  << " for time = " << runTime.timeName() << nl << endl;
59 
60  fluidRegions.set
61  (
62  i,
63  new fvMesh
64  (
65  IOobject
66  (
67  fluidNames[i],
68  runTime.timeName(),
69  runTime,
70  IOobject::MUST_READ
71  )
72  )
73  );
74  }
75  //=======================================
76 
77  PtrList<simpleControl> simpleFluid(fluidRegions.size());
78 
79  //#include "createFluidFields.H"
80  // Initialise fluid field pointer lists
87  PtrList<singlePhaseTransportModel> laminarTransportFluid(fluidRegions.size());
88 
94 
95 
96  // Populate fluid field pointer lists
98  {
99  Info << "this is region Num:" << i << endl;
100  Info<< "*** Reading fluid mesh properties for region "
101  << fluidRegions[i].name() << nl << endl;
102 
103  Info<< " Adding to UFluid\n" << endl;
104  UFluid.set
105  (
106  i,
107  new volVectorField
108  (
109  IOobject
110  (
111  "U",
112  runTime.timeName(),
113  fluidRegions[i],
114  IOobject::MUST_READ,
115  IOobject::AUTO_WRITE
116  ),
117  fluidRegions[i]
118  )
119  );
120 
121  Info<< " Adding to phiFluid\n" << endl;
122  phiFluid.set
123  (
124  i,
126  (
127  IOobject
128  (
129  "phi",
130  runTime.timeName(),
131  fluidRegions[i],
132  IOobject::READ_IF_PRESENT,
133  IOobject::AUTO_WRITE
134  ),
136  & fluidRegions[i].Sf()
137  )
138  );
139 
140  Info<< " Adding to pFluid\n" << endl;
141  pFluid.set
142  (
143  i,
144  new volScalarField
145  (
146  IOobject
147  (
148  "p",
149  runTime.timeName(),
150  fluidRegions[i],
151  IOobject::MUST_READ,
152  IOobject::AUTO_WRITE
153  ),
154  fluidRegions[i]
155  )
156  );
157 
158  Info<< " Adding to p_rghFluid\n" << endl;
159  p_rghFluid.set
160  (
161  i,
162  new volScalarField
163  (
164  IOobject
165  (
166  "p_rgh",
167  runTime.timeName(),
168  fluidRegions[i],
169  IOobject::MUST_READ,
170  IOobject::AUTO_WRITE
171  ),
172  fluidRegions[i]
173  )
174  );
175 
176  Info<< " Adding to TFluid\n" << endl;
177  TFluid.set
178  (
179  i,
180  new volScalarField
181  (
182  IOobject
183  (
184  "T",
185  runTime.timeName(),
186  fluidRegions[i],
187  IOobject::MUST_READ,
188  IOobject::AUTO_WRITE
189  ),
190  fluidRegions[i]
191  )
192  );
193 
194  Info<< " Adding to simpleControl\n" << endl;
195  simpleFluid.set
196  (
197  i,
198  new simpleControl
199  (
200  fluidRegions[i]
201  )
202  );
203 
204 
205 
206 
207 
208  Info << " set refcell for pRefCell and pRefValue" << endl;
209  setRefCell(pFluid[i],simpleFluid[i].dict(),pRefCellFluid[i],pRefValueFluid[i]);
210  fluidRegions[i].setFluxRequired(pFluid[i].name());
211 
212 
213  Info<< " Adding to laminaRransportFluid\n" << endl;
214  laminarTransportFluid.set
215  (
216  i,
218  (
219  UFluid[i],phiFluid[i]
220  )
221  );
222 
223 
224  Info<< " Adding to turbulenceFluid\n" << endl;
225  turbulenceFluid.set
226  (
227  i,
228  incompressible::turbulenceModel::New(UFluid[i],phiFluid[i],laminarTransportFluid[i])
229  );
230 
231  // autoPtr<incompressible::turbulenceModel> turbulence[i]
232  // (
233  // incompressible::turbulenceModel::New(UFluid[i],phiFluid[i],laminarTransportFluid[i])
234  // );
235 
236 
237  // createMRF.h
238  Info<< " Adding MRF\n" << endl;
239  MRFfluid.set
240  (
241  i,
243  );
244 
245  //createFvOptions
246  Info<< " Adding fvOptions\n" << endl;
247  fluidFvOptions.set
248  (
249  i,
250  new fv::options(fluidRegions[i])
251  );
252 
253 
254  Info << "Number" << i << "region is reading." <<endl<<endl;
255  Info << turbulenceFluid[i] <<endl<<endl;
256  //Info << turbulenceFluid[i].validate() <<endl<<endl;
257  turbulenceFluid[i].validate();
258  Info << "Number" << i << "region is read." <<endl<<endl;
259  }
260 
261 
262 
263 #include "initContinuityErrs.H"
264 
265 
266  while (runTime.loop())
267  {
268  Info<< "Time = " << runTime.timeName() << nl << endl;
269 
270  forAll(fluidRegions, i)
271  {
272  Info<< "\nSolving for fluid region "
273  << fluidRegions[i].name() << endl;
274  //
275  //
276  //
277  //
278  // #include "setRegionFluidFields.H"
279  // 这里按顺序给新的引用,下面pEqn和UEqn需要使用
280 
281  const fvMesh& mesh = fluidRegions[i];
282  volVectorField& U = UFluid[i];
283  volScalarField& p = pFluid[i];
285  incompressible::turbulenceModel& turbulence = turbulenceFluid[i];
286  IOMRFZoneList& MRF = MRFfluid[i];
288  const label pRefCell = pRefCellFluid[i];
289  const scalar pRefValue = pRefValueFluid[i];
290 
291  simpleControl& simple= simpleFluid[i];
292  singlePhaseTransportModel& laminarTransport=laminarTransportFluid[i];
293 
294  // #include "readFluidMultiRegionSIMPLEControls.H"
295  // const dictionary& simple = fluidRegions[i].solutionDict().subDict("SIMPLE");
296  // const int nNonOrthCorr =
297  // simple.lookupOrDefault<int>("nNonOrthogonalCorrectors", 0);
298 
299 
300 
301 
302 
303  // Info << " set refcell for pRefCell and pRefValue" << endl;
304  // setRefCell(p,simple.dict(),pRefCell,pRefValue,false);
305  // mesh.setFluxRequired(p.name());
306 
307 
308 
309 
310 
311  // #include "solveFluid.H"
312  // Pressure-velocity SIMPLE corrector
313  {
314  // p_rgh.storePrevIter();
315 
316 #include "UEqn.H"
317 #include "pEqn.H" //P方程中使用了非正交修正nNonOrthCorr
319  turbulence.correct();
320  }
321  }
322  runTime.write();
323 
324  Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
325  << " ClockTime = " << runTime.elapsedClockTime() << " s"
326  << nl << endl;
327  }
328 
329  Info<< "End\n" << endl;
330 
331  return 0;
332 }
333 
334 
335 // ************************************************************************* //
pRefCell
const label pRefCell
Definition: setRegionFluidFields.H:27
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
pRefValueFluid
List< scalar > pRefValueFluid(fluidRegions.size(), 0.0)
p
p
Definition: pEqn.H:62
fvOptions.H
Foam::compressible::New
autoPtr< BasicCompressibleTurbulenceModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleTurbulenceModel::transportModel &transport, const word &propertiesName)
Definition: turbulentFluidThermoModel.C:36
regionProperties.H
UEqn.H
Foam::simpleControl
SIMPLE control class to supply convergence information/checks for the SIMPLE loop.
Definition: simpleControl.H:46
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
singlePhaseTransportModel.H
phi
surfaceScalarField & phi
Definition: setRegionFluidFields.H:8
pEqn.H
turbulentTransportModel.H
initialMassFluid
List< scalar > initialMassFluid(fluidRegions.size())
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::singlePhaseTransportModel
A simple single-phase transport model based on viscosityModel.
Definition: singlePhaseTransportModel.H:55
simple
Simple relative velocity model.
U
U
Definition: pEqn.H:46
fluidRegions
PtrList< fvMesh > fluidRegions(fluidNames.size())
main
int main(int argc, char *argv[])
Definition: multiRegionSimpleFoam.C:44
Foam::PtrList::set
bool set(const label) const
Is element set.
Foam::label
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
turbulence
autoPtr< compressible::turbulenceModel > turbulence
Definition: createFields.H:23
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::setRefCell
void 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
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
simpleControl.H
Foam::regionProperties
Simple class to hold region information for coupled region simulations.
Definition: regionProperties.H:53
phiFluid
PtrList< surfaceScalarField > phiFluid(fluidRegions.size())
Foam::fv::options
Finite-volume options.
Definition: fvOptions.H:52
p_rghFluid
PtrList< volScalarField > p_rghFluid(fluidRegions.size())
dict
dictionary dict
Definition: searchingEngine.H:14
MRF
IOMRFZoneList & MRF
Definition: setRegionFluidFields.H:15
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
MRFfluid
PtrList< IOMRFZoneList > MRFfluid(fluidRegions.size())
setRootCase.H
laminarTransport
singlePhaseTransportModel laminarTransport(U, phi)
fluidNames
const wordList fluidNames(rp["fluid"])
Foam::linearInterpolate
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > linearInterpolate(const GeometricField< Type, fvPatchField, volMesh > &vf)
Definition: linear.H:107
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
pRefCellFluid
List< label > pRefCellFluid(fluidRegions.size(), 0)
Foam::IOMRFZoneList
List of MRF zones with IO functionality. MRF zones are specified by a list of dictionary entries,...
Definition: IOMRFZoneList.H:66
createTime.H
Foam::singlePhaseTransportModel::correct
virtual void correct()
Correct the laminar viscosity.
Definition: singlePhaseTransportModel.C:76
fvCFD.H
Foam::IncompressibleTurbulenceModel
Templated abstract base class for single-phase incompressible turbulence models.
Definition: IncompressibleTurbulenceModel.H:52
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
pRefValue
const scalar pRefValue
Definition: setRegionFluidFields.H:28
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
fvOptions
fv::options & fvOptions
Definition: setRegionFluidFields.H:16
UFluid
PtrList< volVectorField > UFluid(fluidRegions.size())
fluidFvOptions
PtrList< fv::options > fluidFvOptions(fluidRegions.size())