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 "porousZone.H"
00028 #include "fvMesh.H"
00029 #include "fvMatrices.H"
00030 #include "oneField.H"
00031
00032
00033
00034
00035 void Foam::porousZone::adjustNegativeResistance(dimensionedVector& resist)
00036 {
00037 scalar maxCmpt = max(0, cmptMax(resist.value()));
00038
00039 if (maxCmpt < 0)
00040 {
00041 FatalErrorIn
00042 (
00043 "Foam::porousZone::porousZone::adjustNegativeResistance"
00044 "(dimensionedVector&)"
00045 ) << "negative resistances! " << resist
00046 << exit(FatalError);
00047 }
00048 else
00049 {
00050 vector& val = resist.value();
00051 for (label cmpt=0; cmpt < vector::nComponents; ++cmpt)
00052 {
00053 if (val[cmpt] < 0)
00054 {
00055 val[cmpt] *= -maxCmpt;
00056 }
00057 }
00058 }
00059 }
00060
00061
00062
00063
00064 Foam::porousZone::porousZone
00065 (
00066 const word& name,
00067 const fvMesh& mesh,
00068 const dictionary& dict
00069 )
00070 :
00071 name_(name),
00072 mesh_(mesh),
00073 dict_(dict),
00074 cellZoneID_(mesh_.cellZones().findZoneID(name)),
00075 coordSys_(dict, mesh),
00076 porosity_(1),
00077 C0_(0),
00078 C1_(0),
00079 D_("D", dimensionSet(0, -2, 0, 0, 0), tensor::zero),
00080 F_("F", dimensionSet(0, -1, 0, 0, 0), tensor::zero)
00081 {
00082 Info<< "Creating porous zone: " << name_ << endl;
00083
00084 if (cellZoneID_ == -1 && !Pstream::parRun())
00085 {
00086 FatalErrorIn
00087 (
00088 "Foam::porousZone::porousZone"
00089 "(const fvMesh&, const word&, const dictionary&)"
00090 ) << "cannot find porous cellZone " << name_
00091 << exit(FatalError);
00092 }
00093
00094
00095 if (dict_.readIfPresent("porosity", porosity_))
00096 {
00097 if (porosity_ <= 0.0 || porosity_ > 1.0)
00098 {
00099 FatalIOErrorIn
00100 (
00101 "Foam::porousZone::porousZone"
00102 "(const fvMesh&, const word&, const dictionary&)",
00103 dict_
00104 )
00105 << "out-of-range porosity value " << porosity_
00106 << exit(FatalIOError);
00107 }
00108 }
00109
00110
00111 if (const dictionary* dictPtr = dict_.subDictPtr("powerLaw"))
00112 {
00113 dictPtr->readIfPresent("C0", C0_);
00114 dictPtr->readIfPresent("C1", C1_);
00115 }
00116
00117
00118 if (const dictionary* dictPtr = dict_.subDictPtr("Darcy"))
00119 {
00120
00121 const tensor& E = coordSys_.R();
00122
00123 dimensionedVector d(vector::zero);
00124 if (dictPtr->readIfPresent("d", d))
00125 {
00126 if (D_.dimensions() != d.dimensions())
00127 {
00128 FatalIOErrorIn
00129 (
00130 "Foam::porousZone::porousZone"
00131 "(const fvMesh&, const word&, const dictionary&)",
00132 dict_
00133 ) << "incorrect dimensions for d: " << d.dimensions()
00134 << " should be " << D_.dimensions()
00135 << exit(FatalIOError);
00136 }
00137
00138 adjustNegativeResistance(d);
00139
00140 D_.value().xx() = d.value().x();
00141 D_.value().yy() = d.value().y();
00142 D_.value().zz() = d.value().z();
00143 D_.value() = (E & D_ & E.T()).value();
00144 }
00145
00146 dimensionedVector f(vector::zero);
00147 if (dictPtr->readIfPresent("f", f))
00148 {
00149 if (F_.dimensions() != f.dimensions())
00150 {
00151 FatalIOErrorIn
00152 (
00153 "Foam::porousZone::porousZone"
00154 "(const fvMesh&, const word&, const dictionary&)",
00155 dict_
00156 ) << "incorrect dimensions for f: " << f.dimensions()
00157 << " should be " << F_.dimensions()
00158 << exit(FatalIOError);
00159 }
00160
00161 adjustNegativeResistance(f);
00162
00163
00164 F_.value().xx() = 0.5*f.value().x();
00165 F_.value().yy() = 0.5*f.value().y();
00166 F_.value().zz() = 0.5*f.value().z();
00167 F_.value() = (E & F_ & E.T()).value();
00168 }
00169 }
00170
00171
00172
00173
00174
00175 if
00176 (
00177 C0_ <= VSMALL
00178 && magSqr(D_.value()) <= VSMALL
00179 && magSqr(F_.value()) <= VSMALL
00180 )
00181 {
00182 FatalIOErrorIn
00183 (
00184 "Foam::porousZone::porousZone"
00185 "(const fvMesh&, const word&, const dictionary&)",
00186 dict_
00187 ) << "neither powerLaw (C0/C1) "
00188 "nor Darcy-Forchheimer law (d/f) specified"
00189 << exit(FatalIOError);
00190 }
00191 }
00192
00193
00194
00195
00196 void Foam::porousZone::addResistance(fvVectorMatrix& UEqn) const
00197 {
00198 if (cellZoneID_ == -1)
00199 {
00200 return;
00201 }
00202
00203 bool compressible = false;
00204 if (UEqn.dimensions() == dimensionSet(1, 1, -2, 0, 0))
00205 {
00206 compressible = true;
00207 }
00208
00209 const labelList& cells = mesh_.cellZones()[cellZoneID_];
00210 const scalarField& V = mesh_.V();
00211 scalarField& Udiag = UEqn.diag();
00212 vectorField& Usource = UEqn.source();
00213 const vectorField& U = UEqn.psi();
00214
00215 if (C0_ > VSMALL)
00216 {
00217 if (compressible)
00218 {
00219 addPowerLawResistance
00220 (
00221 Udiag,
00222 cells,
00223 V,
00224 mesh_.lookupObject<volScalarField>("rho"),
00225 U
00226 );
00227 }
00228 else
00229 {
00230 addPowerLawResistance
00231 (
00232 Udiag,
00233 cells,
00234 V,
00235 oneField(),
00236 U
00237 );
00238 }
00239 }
00240
00241 const tensor& D = D_.value();
00242 const tensor& F = F_.value();
00243
00244 if (magSqr(D) > VSMALL || magSqr(F) > VSMALL)
00245 {
00246 if (compressible)
00247 {
00248 addViscousInertialResistance
00249 (
00250 Udiag,
00251 Usource,
00252 cells,
00253 V,
00254 mesh_.lookupObject<volScalarField>("rho"),
00255 mesh_.lookupObject<volScalarField>("mu"),
00256 U
00257 );
00258 }
00259 else
00260 {
00261 addViscousInertialResistance
00262 (
00263 Udiag,
00264 Usource,
00265 cells,
00266 V,
00267 oneField(),
00268 mesh_.lookupObject<volScalarField>("nu"),
00269 U
00270 );
00271 }
00272 }
00273 }
00274
00275
00276 void Foam::porousZone::addResistance
00277 (
00278 const fvVectorMatrix& UEqn,
00279 volTensorField& AU,
00280 bool correctAUprocBC
00281 ) const
00282 {
00283 if (cellZoneID_ == -1)
00284 {
00285 return;
00286 }
00287
00288 bool compressible = false;
00289 if (UEqn.dimensions() == dimensionSet(1, 1, -2, 0, 0))
00290 {
00291 compressible = true;
00292 }
00293
00294 const labelList& cells = mesh_.cellZones()[cellZoneID_];
00295 const vectorField& U = UEqn.psi();
00296
00297 if (C0_ > VSMALL)
00298 {
00299 if (compressible)
00300 {
00301 addPowerLawResistance
00302 (
00303 AU,
00304 cells,
00305 mesh_.lookupObject<volScalarField>("rho"),
00306 U
00307 );
00308 }
00309 else
00310 {
00311 addPowerLawResistance
00312 (
00313 AU,
00314 cells,
00315 oneField(),
00316 U
00317 );
00318 }
00319 }
00320
00321 const tensor& D = D_.value();
00322 const tensor& F = F_.value();
00323
00324 if (magSqr(D) > VSMALL || magSqr(F) > VSMALL)
00325 {
00326 if (compressible)
00327 {
00328 addViscousInertialResistance
00329 (
00330 AU,
00331 cells,
00332 mesh_.lookupObject<volScalarField>("rho"),
00333 mesh_.lookupObject<volScalarField>("mu"),
00334 U
00335 );
00336 }
00337 else
00338 {
00339 addViscousInertialResistance
00340 (
00341 AU,
00342 cells,
00343 oneField(),
00344 mesh_.lookupObject<volScalarField>("nu"),
00345 U
00346 );
00347 }
00348 }
00349
00350 if (correctAUprocBC)
00351 {
00352
00353
00354
00355 AU.correctBoundaryConditions();
00356 }
00357 }
00358
00359
00360 void Foam::porousZone::writeDict(Ostream& os, bool subDict) const
00361 {
00362 if (subDict)
00363 {
00364 os << indent << token::BEGIN_BLOCK << incrIndent << nl;
00365 os.writeKeyword("name") << zoneName() << token::END_STATEMENT << nl;
00366 }
00367 else
00368 {
00369 os << indent << zoneName() << nl
00370 << indent << token::BEGIN_BLOCK << incrIndent << nl;
00371 }
00372
00373 if (dict_.found("note"))
00374 {
00375 os.writeKeyword("note") << string(dict_.lookup("note"))
00376 << token::END_STATEMENT << nl;
00377 }
00378
00379 coordSys_.writeDict(os, true);
00380
00381 if (dict_.found("porosity"))
00382 {
00383 os.writeKeyword("porosity") << porosity() << token::END_STATEMENT << nl;
00384 }
00385
00386
00387 if (const dictionary* dictPtr = dict_.subDictPtr("powerLaw"))
00388 {
00389 os << indent << "powerLaw";
00390 dictPtr->write(os);
00391 }
00392
00393
00394 if (const dictionary* dictPtr = dict_.subDictPtr("Darcy"))
00395 {
00396 os << indent << "Darcy";
00397 dictPtr->write(os);
00398 }
00399
00400 os << decrIndent << indent << token::END_BLOCK << endl;
00401 }
00402
00403
00404
00405
00406 Foam::Ostream& Foam::operator<<(Ostream& os, const porousZone& pZone)
00407 {
00408 pZone.writeDict(os);
00409 return os;
00410 }
00411
00412