forces.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "forces.H"
00028 #include "volFields.H"
00029 #include "dictionary.H"
00030 #include "Time.H"
00031
00032 #include "incompressible/singlePhaseTransportModel/singlePhaseTransportModel.H"
00033 #include "incompressible/RAS/RASModel/RASModel.H"
00034 #include "incompressible/LES/LESModel/LESModel.H"
00035
00036 #include "basicThermo.H"
00037 #include "compressible/RAS/RASModel/RASModel.H"
00038 #include "compressible/LES/LESModel/LESModel.H"
00039
00040
00041
00042
00043 namespace Foam
00044 {
00045 defineTypeNameAndDebug(forces, 0);
00046 }
00047
00048
00049
00050 Foam::tmp<Foam::volSymmTensorField> Foam::forces::devRhoReff() const
00051 {
00052 if (obr_.foundObject<compressible::RASModel>("RASProperties"))
00053 {
00054 const compressible::RASModel& ras
00055 = obr_.lookupObject<compressible::RASModel>("RASProperties");
00056
00057 return ras.devRhoReff();
00058 }
00059 else if (obr_.foundObject<incompressible::RASModel>("RASProperties"))
00060 {
00061 const incompressible::RASModel& ras
00062 = obr_.lookupObject<incompressible::RASModel>("RASProperties");
00063
00064 return rhoRef_*ras.devReff();
00065 }
00066 else if (obr_.foundObject<compressible::LESModel>("LESProperties"))
00067 {
00068 const compressible::LESModel& les =
00069 obr_.lookupObject<compressible::LESModel>("LESProperties");
00070
00071 return les.devRhoBeff();
00072 }
00073 else if (obr_.foundObject<incompressible::LESModel>("LESProperties"))
00074 {
00075 const incompressible::LESModel& les
00076 = obr_.lookupObject<incompressible::LESModel>("LESProperties");
00077
00078 return rhoRef_*les.devBeff();
00079 }
00080 else if (obr_.foundObject<basicThermo>("thermophysicalProperties"))
00081 {
00082 const basicThermo& thermo =
00083 obr_.lookupObject<basicThermo>("thermophysicalProperties");
00084
00085 const volVectorField& U = obr_.lookupObject<volVectorField>(UName_);
00086
00087 return -thermo.mu()*dev(twoSymm(fvc::grad(U)));
00088 }
00089 else if
00090 (
00091 obr_.foundObject<singlePhaseTransportModel>("transportProperties")
00092 )
00093 {
00094 const singlePhaseTransportModel& laminarT =
00095 obr_.lookupObject<singlePhaseTransportModel>
00096 ("transportProperties");
00097
00098 const volVectorField& U = obr_.lookupObject<volVectorField>(UName_);
00099
00100 return -rhoRef_*laminarT.nu()*dev(twoSymm(fvc::grad(U)));
00101 }
00102 else if (obr_.foundObject<dictionary>("transportProperties"))
00103 {
00104 const dictionary& transportProperties =
00105 obr_.lookupObject<dictionary>("transportProperties");
00106
00107 dimensionedScalar nu(transportProperties.lookup("nu"));
00108
00109 const volVectorField& U = obr_.lookupObject<volVectorField>(UName_);
00110
00111 return -rhoRef_*nu*dev(twoSymm(fvc::grad(U)));
00112 }
00113 else
00114 {
00115 FatalErrorIn("forces::devRhoReff()")
00116 << "No valid model for viscous stress calculation."
00117 << exit(FatalError);
00118
00119 return volSymmTensorField::null();
00120 }
00121 }
00122
00123
00124 Foam::scalar Foam::forces::rho(const volScalarField& p) const
00125 {
00126 if (p.dimensions() == dimPressure)
00127 {
00128 return 1.0;
00129 }
00130 else
00131 {
00132 return rhoRef_;
00133 }
00134 }
00135
00136
00137
00138
00139 Foam::forces::forces
00140 (
00141 const word& name,
00142 const objectRegistry& obr,
00143 const dictionary& dict,
00144 const bool loadFromFiles
00145 )
00146 :
00147 name_(name),
00148 obr_(obr),
00149 active_(true),
00150 log_(false),
00151 patchSet_(),
00152 pName_(""),
00153 UName_(""),
00154 directForceDensity_(false),
00155 fDName_(""),
00156 rhoRef_(0),
00157 CofR_(vector::zero),
00158 forcesFilePtr_(NULL)
00159 {
00160
00161 if (!isA<fvMesh>(obr_))
00162 {
00163 active_ = false;
00164 WarningIn
00165 (
00166 "Foam::forces::forces"
00167 "("
00168 "const word&, "
00169 "const objectRegistry&, "
00170 "const dictionary&, "
00171 "const bool"
00172 ")"
00173 ) << "No fvMesh available, deactivating."
00174 << endl;
00175 }
00176
00177 read(dict);
00178 }
00179
00180
00181
00182
00183 Foam::forces::~forces()
00184 {}
00185
00186
00187
00188
00189 void Foam::forces::read(const dictionary& dict)
00190 {
00191 if (active_)
00192 {
00193 log_ = dict.lookupOrDefault<Switch>("log", false);
00194
00195 const fvMesh& mesh = refCast<const fvMesh>(obr_);
00196
00197 patchSet_ =
00198 mesh.boundaryMesh().patchSet(wordList(dict.lookup("patches")));
00199
00200 dict.readIfPresent("directForceDensity", directForceDensity_);
00201
00202 if (directForceDensity_)
00203 {
00204
00205 fDName_ = dict.lookupOrDefault<word>("fDName", "fD");
00206
00207
00208 if
00209 (
00210 !obr_.foundObject<volVectorField>(fDName_)
00211 )
00212 {
00213 active_ = false;
00214 WarningIn("void forces::read(const dictionary& dict)")
00215 << "Could not find " << fDName_ << " in database." << nl
00216 << " De-activating forces."
00217 << endl;
00218 }
00219 }
00220 else
00221 {
00222
00223 pName_ = dict.lookupOrDefault<word>("pName", "p");
00224 UName_ = dict.lookupOrDefault<word>("UName", "U");
00225
00226
00227 if
00228 (
00229 !obr_.foundObject<volVectorField>(UName_)
00230 || !obr_.foundObject<volScalarField>(pName_)
00231 )
00232 {
00233 active_ = false;
00234 WarningIn("void forces::read(const dictionary& dict)")
00235 << "Could not find " << UName_ << " or "
00236 << pName_ << " in database." << nl
00237 << " De-activating forces."
00238 << endl;
00239 }
00240
00241
00242 rhoRef_ = readScalar(dict.lookup("rhoInf"));
00243 }
00244
00245
00246 CofR_ = dict.lookup("CofR");
00247 }
00248 }
00249
00250
00251 void Foam::forces::makeFile()
00252 {
00253
00254 if (forcesFilePtr_.empty())
00255 {
00256 if (debug)
00257 {
00258 Info<< "Creating forces file." << endl;
00259 }
00260
00261
00262 if (Pstream::master())
00263 {
00264 fileName forcesDir;
00265 if (Pstream::parRun())
00266 {
00267
00268
00269 forcesDir =
00270 obr_.time().path()/".."/name_/obr_.time().timeName();
00271 }
00272 else
00273 {
00274 forcesDir = obr_.time().path()/name_/obr_.time().timeName();
00275 }
00276
00277
00278 mkDir(forcesDir);
00279
00280
00281 forcesFilePtr_.reset(new OFstream(forcesDir/(type() + ".dat")));
00282
00283
00284 writeFileHeader();
00285 }
00286 }
00287 }
00288
00289
00290 void Foam::forces::writeFileHeader()
00291 {
00292 if (forcesFilePtr_.valid())
00293 {
00294 forcesFilePtr_()
00295 << "# Time" << tab
00296 << "forces(pressure, viscous) moment(pressure, viscous)"
00297 << endl;
00298 }
00299 }
00300
00301
00302 void Foam::forces::execute()
00303 {
00304
00305 }
00306
00307
00308 void Foam::forces::end()
00309 {
00310
00311 }
00312
00313
00314 void Foam::forces::write()
00315 {
00316 if (active_)
00317 {
00318
00319 makeFile();
00320
00321 forcesMoments fm = calcForcesMoment();
00322
00323 if (Pstream::master())
00324 {
00325 forcesFilePtr_() << obr_.time().value() << tab << fm << endl;
00326
00327 if (log_)
00328 {
00329 Info<< "forces output:" << nl
00330 << " forces(pressure, viscous)" << fm.first() << nl
00331 << " moment(pressure, viscous)" << fm.second() << nl
00332 << endl;
00333 }
00334 }
00335 }
00336 }
00337
00338
00339 Foam::forces::forcesMoments Foam::forces::calcForcesMoment() const
00340 {
00341 forcesMoments fm
00342 (
00343 pressureViscous(vector::zero, vector::zero),
00344 pressureViscous(vector::zero, vector::zero)
00345 );
00346
00347 if (directForceDensity_)
00348 {
00349 const volVectorField& fD = obr_.lookupObject<volVectorField>(fDName_);
00350
00351 const fvMesh& mesh = fD.mesh();
00352
00353 const surfaceVectorField::GeometricBoundaryField& Sfb =
00354 mesh.Sf().boundaryField();
00355
00356 forAllConstIter(labelHashSet, patchSet_, iter)
00357 {
00358 label patchi = iter.key();
00359
00360 vectorField Md = mesh.C().boundaryField()[patchi] - CofR_;
00361
00362 scalarField sA = mag(Sfb[patchi]);
00363
00364
00365 vectorField fN =
00366 Sfb[patchi]/sA
00367 *(
00368 Sfb[patchi] & fD.boundaryField()[patchi]
00369 );
00370
00371 fm.first().first() += sum(fN);
00372 fm.second().first() += sum(Md ^ fN);
00373
00374
00375 vectorField fT = sA*fD.boundaryField()[patchi] - fN;
00376
00377 fm.first().second() += sum(fT);
00378 fm.second().second() += sum(Md ^ fT);
00379 }
00380 }
00381 else
00382 {
00383 const volVectorField& U = obr_.lookupObject<volVectorField>(UName_);
00384 const volScalarField& p = obr_.lookupObject<volScalarField>(pName_);
00385
00386 const fvMesh& mesh = U.mesh();
00387
00388 const surfaceVectorField::GeometricBoundaryField& Sfb =
00389 mesh.Sf().boundaryField();
00390
00391 tmp<volSymmTensorField> tdevRhoReff = devRhoReff();
00392 const volSymmTensorField::GeometricBoundaryField& devRhoReffb
00393 = tdevRhoReff().boundaryField();
00394
00395 forAllConstIter(labelHashSet, patchSet_, iter)
00396 {
00397 label patchi = iter.key();
00398
00399 vectorField Md = mesh.C().boundaryField()[patchi] - CofR_;
00400
00401 vectorField pf = Sfb[patchi]*p.boundaryField()[patchi];
00402
00403 fm.first().first() += rho(p)*sum(pf);
00404 fm.second().first() += rho(p)*sum(Md ^ pf);
00405
00406 vectorField vf = Sfb[patchi] & devRhoReffb[patchi];
00407
00408 fm.first().second() += sum(vf);
00409 fm.second().second() += sum(Md ^ vf);
00410 }
00411 }
00412
00413 reduce(fm, sumOp());
00414
00415 return fm;
00416 }
00417
00418
00419
Copyright © 2000-2009 OpenCFD Ltd