Newer
Older
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "fvMesh.H"
#include "Time.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "slicedVolFields.H"
#include "slicedSurfaceFields.H"
#include "SubField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void fvMesh::makeSf() const
{
if (debug)
{
Info<< "void fvMesh::makeSf() : "
<< "assembling face areas"
<< endl;
}
// It is an error to attempt to recalculate
// if the pointer is already set
if (SfPtr_)
{
FatalErrorIn("fvMesh::makeSf()")
<< "face areas already exist"
<< abort(FatalError);
}
SfPtr_ = new slicedSurfaceVectorField
(
IOobject
(
"S",
pointsInstance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
*this,
dimArea,
faceAreas()
);
}
void fvMesh::makeMagSf() const
{
if (debug)
{
Info<< "void fvMesh::makeMagSf() : "
<< "assembling mag face areas"
<< endl;
}
// It is an error to attempt to recalculate
// if the pointer is already set
if (magSfPtr_)
{
FatalErrorIn("void fvMesh::makeMagSf()")
<< "mag face areas already exist"
<< abort(FatalError);
}
// Note: Added stabilisation for faces with exactly zero area.
// These should be caught on mesh checking but at least this stops
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
magSfPtr_ = new surfaceScalarField
(
IOobject
(
"magSf",
pointsInstance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
mag(Sf()) + dimensionedScalar("vs", dimArea, VSMALL)
);
}
void fvMesh::makeC() const
{
if (debug)
{
Info<< "void fvMesh::makeC() : "
<< "assembling cell centres"
<< endl;
}
// It is an error to attempt to recalculate
// if the pointer is already set
if (CPtr_)
{
FatalErrorIn("fvMesh::makeC()")
<< "cell centres already exist"
<< abort(FatalError);
}
// Construct as slices. Only preserve processor (not e.g. cyclic)
CPtr_ = new slicedVolVectorField
(
IOobject
(
"C",
pointsInstance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
*this,
dimLength,
cellCentres(),
faceCentres(),
true, //preserveCouples
true //preserveProcOnly
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
);
}
void fvMesh::makeCf() const
{
if (debug)
{
Info<< "void fvMesh::makeCf() : "
<< "assembling face centres"
<< endl;
}
// It is an error to attempt to recalculate
// if the pointer is already set
if (CfPtr_)
{
FatalErrorIn("fvMesh::makeCf()")
<< "face centres already exist"
<< abort(FatalError);
}
CfPtr_ = new slicedSurfaceVectorField
(
IOobject
(
"Cf",
pointsInstance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
*this,
dimLength,
faceCentres()
);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const volScalarField::DimensionedInternalField& fvMesh::V() const
{
if (!VPtr_)
{
if (debug)
{
Info<< "fvMesh::V() const: "
<< "constructing from primitiveMesh::cellVolumes()"
<< endl;
}
VPtr_ = new slicedVolScalarField::DimensionedInternalField
(
IOobject
(
"V",
time().timeName(),
*this,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
),
*this,
dimVolume,
cellVolumes()
);
}
return *static_cast<slicedVolScalarField::DimensionedInternalField*>(VPtr_);
}
const volScalarField::DimensionedInternalField& fvMesh::V0() const
{
if (!V0Ptr_)
{
FatalErrorIn("fvMesh::V0() const")
<< "V0 is not available"
<< abort(FatalError);
}
return *V0Ptr_;
}
volScalarField::DimensionedInternalField& fvMesh::setV0()
{
if (!V0Ptr_)
{
FatalErrorIn("fvMesh::setV0()")
<< "V0 is not available"
<< abort(FatalError);
}
return *V0Ptr_;
}
const volScalarField::DimensionedInternalField& fvMesh::V00() const
{
if (!V00Ptr_)
{
if (debug)
{
Info<< "fvMesh::V00() const: "
<< "constructing from V0"
<< endl;
}
V00Ptr_ = new DimensionedField<scalar, volMesh>
(
IOobject
(
"V00",
time().timeName(),
*this,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
V0()
);
// If V00 is used then V0 should be stored for restart
V0Ptr_->writeOpt() = IOobject::AUTO_WRITE;
}
return *V00Ptr_;
}
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
tmp<volScalarField::DimensionedInternalField> fvMesh::Vsc() const
{
if (moving() && time().subCycling())
{
const TimeState& ts = time();
const TimeState& ts0 = time().prevTimeState();
scalar tFrac =
(
ts.value() - (ts0.value() - ts0.deltaTValue())
)/ts0.deltaTValue();
if (tFrac < (1 - SMALL))
{
return V0() + tFrac*(V() - V0());
}
else
{
return V();
}
}
else
{
return V();
}
}
tmp<volScalarField::DimensionedInternalField> fvMesh::Vsc0() const
{
if (moving() && time().subCycling())
{
const TimeState& ts = time();
const TimeState& ts0 = time().prevTimeState();
scalar t0Frac =
(
(ts.value() - ts.deltaTValue())
- (ts0.value() - ts0.deltaTValue())
)/ts0.deltaTValue();
if (t0Frac > SMALL)
{
return V0() + t0Frac*(V() - V0());
}
else
{
return V0();
}
}
else
{
return V0();
}
}
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
const surfaceVectorField& fvMesh::Sf() const
{
if (!SfPtr_)
{
makeSf();
}
return *SfPtr_;
}
const surfaceScalarField& fvMesh::magSf() const
{
if (!magSfPtr_)
{
makeMagSf();
}
return *magSfPtr_;
}
const volVectorField& fvMesh::C() const
{
if (!CPtr_)
{
makeC();
}
return *CPtr_;
}
const surfaceVectorField& fvMesh::Cf() const
{
if (!CfPtr_)
{
makeCf();
}
return *CfPtr_;
}
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
tmp<surfaceVectorField> fvMesh::delta() const
{
if (debug)
{
Info<< "void fvMesh::delta() : "
<< "calculating face deltas"
<< endl;
}
tmp<surfaceVectorField> tdelta
(
new surfaceVectorField
(
IOobject
(
"delta",
pointsInstance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
*this,
dimLength
)
);
surfaceVectorField& delta = tdelta();
const volVectorField& C = this->C();
const labelUList& owner = this->owner();
const labelUList& neighbour = this->neighbour();
forAll(owner, facei)
{
delta[facei] = C[neighbour[facei]] - C[owner[facei]];
}
forAll(delta.boundaryField(), patchi)
{
delta.boundaryField()[patchi] = boundary()[patchi].delta();
}
return tdelta;
}
const surfaceScalarField& fvMesh::phi() const
{
if (!phiPtr_)
{
FatalErrorIn("fvMesh::phi()")
<< "mesh flux field does not exist, is the mesh actually moving?"
Henry
committed
<< abort(FatalError);
// mesh motion fluxes if the time has been incremented
if (phiPtr_->timeIndex() != time().timeIndex())
{
(*phiPtr_) = dimensionedScalar("0", dimVolume/dimTime, 0.0);
}
return *phiPtr_;
}
surfaceScalarField& fvMesh::setPhi()
{
if (!phiPtr_)
{
FatalErrorIn("fvMesh::setPhi()")
<< "mesh flux field does not exist, is the mesh actually moving?"
Henry
committed
<< abort(FatalError);
}
return *phiPtr_;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //