From 1dd11b0f79ba3685d234ebc968d687c21f4ca52b Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 7 Aug 2009 14:56:10 +0100 Subject: [PATCH 01/10] avoid potential div0's --- .../mutURoughWallFunctionFvPatchScalarField.C | 9 ++++----- .../mutUSpaldingWallFunctionFvPatchScalarField.C | 13 ++++++------- .../nutURoughWallFunctionFvPatchScalarField.C | 2 +- .../nutUSpaldingWallFunctionFvPatchScalarField.C | 14 +++++++------- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/mutWallFunctions/mutURoughWallFunction/mutURoughWallFunctionFvPatchScalarField.C b/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/mutWallFunctions/mutURoughWallFunction/mutURoughWallFunctionFvPatchScalarField.C index 7bc772eead..c848c2b413 100644 --- a/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/mutWallFunctions/mutURoughWallFunction/mutURoughWallFunctionFvPatchScalarField.C +++ b/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/mutWallFunctions/mutURoughWallFunction/mutURoughWallFunctionFvPatchScalarField.C @@ -70,8 +70,7 @@ tmp mutURoughWallFunctionFvPatchScalarField::calcYPlus // of the wall will depend on yPlus forAll(yPlus, facei) { - const scalar magUpara = magUp[facei]; - const scalar Re = rho[facei]*magUpara*y[facei]/muw[facei]; + const scalar Re = rho[facei]*magUp[facei]*y[facei]/muw[facei]; const scalar kappaRe = kappa_*Re; scalar yp = yPlusLam_; @@ -142,8 +141,7 @@ tmp mutURoughWallFunctionFvPatchScalarField::calcYPlus // Smooth Walls forAll(yPlus, facei) { - const scalar magUpara = magUp[facei]; - const scalar Re = rho[facei]*magUpara*y[facei]/muw[facei]; + const scalar Re = rho[facei]*magUp[facei]*y[facei]/muw[facei]; const scalar kappaRe = kappa_*Re; scalar yp = yPlusLam_; @@ -193,7 +191,8 @@ tmp mutURoughWallFunctionFvPatchScalarField::calcMut() const { if (yPlus[facei] > yPlusLam_) { - const scalar Re = rho[facei]*magUp[facei]*y[facei]/muw[facei]; + const scalar Re = + rho[facei]*magUp[facei]*y[facei]/muw[facei] + ROOTVSMALL; mutw[facei] = muw[facei]*(sqr(yPlus[facei])/Re - 1); } } diff --git a/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/mutWallFunctions/mutUSpaldingWallFunction/mutUSpaldingWallFunctionFvPatchScalarField.C b/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/mutWallFunctions/mutUSpaldingWallFunction/mutUSpaldingWallFunctionFvPatchScalarField.C index 0fcfe72c4c..0c63d7c8a0 100644 --- a/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/mutWallFunctions/mutUSpaldingWallFunction/mutUSpaldingWallFunctionFvPatchScalarField.C +++ b/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/mutWallFunctions/mutUSpaldingWallFunction/mutUSpaldingWallFunctionFvPatchScalarField.C @@ -66,10 +66,9 @@ tmp mutUSpaldingWallFunctionFvPatchScalarField::calcUTau forAll(mutw, faceI) { - scalar magUpara = magUp[faceI]; - scalar ut = - sqrt((mutw[faceI] + muw[faceI])*magGradU[faceI]/rhow[faceI]); + sqrt((mutw[faceI] + muw[faceI])*magGradU[faceI]/rhow[faceI]) + + ROOTVSMALL; if (ut > VSMALL) { @@ -78,17 +77,17 @@ tmp mutUSpaldingWallFunctionFvPatchScalarField::calcUTau do { - scalar kUu = min(kappa_*magUpara/ut, 50); + scalar kUu = min(kappa_*magUp[faceI]/ut, 50); scalar fkUu = exp(kUu) - 1 - kUu*(1 + 0.5*kUu); scalar f = - ut*y[faceI]/(muw[faceI]/rhow[faceI]) - + magUpara/ut + + magUp[faceI]/ut + 1/E_*(fkUu - 1.0/6.0*kUu*sqr(kUu)); scalar df = y[faceI]/(muw[faceI]/rhow[faceI]) - + magUpara/sqr(ut) + + magUp[faceI]/sqr(ut) + 1/E_*kUu*fkUu/ut; scalar uTauNew = ut + f/df; @@ -111,7 +110,7 @@ tmp mutUSpaldingWallFunctionFvPatchScalarField::calcMut() const const RASModel& rasModel = db().lookupObject("RASProperties"); const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI]; - const scalarField magGradU = mag(Uw.snGrad()); + const scalarField magGradU = mag(Uw.snGrad()) + ROOTVSMALL; const scalarField& rhow = rasModel.rho().boundaryField()[patchI]; const scalarField& muw = rasModel.mu().boundaryField()[patchI]; diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutURoughWallFunction/nutURoughWallFunctionFvPatchScalarField.C b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutURoughWallFunction/nutURoughWallFunctionFvPatchScalarField.C index a85c647467..c202ac479c 100644 --- a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutURoughWallFunction/nutURoughWallFunctionFvPatchScalarField.C +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutURoughWallFunction/nutURoughWallFunctionFvPatchScalarField.C @@ -63,7 +63,7 @@ tmp nutURoughWallFunctionFvPatchScalarField::calcNut() const { if (yPlus[facei] > yPlusLam_) { - const scalar Re = magUp[facei]*y[facei]/nuw[facei]; + const scalar Re = magUp[facei]*y[facei]/nuw[facei] + ROOTVSMALL; nutw[facei] = nuw[facei]*(sqr(yPlus[facei])/Re - 1); } } diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutUSpaldingWallFunction/nutUSpaldingWallFunctionFvPatchScalarField.C b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutUSpaldingWallFunction/nutUSpaldingWallFunctionFvPatchScalarField.C index f24001bc6e..4adf3227ab 100644 --- a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutUSpaldingWallFunction/nutUSpaldingWallFunctionFvPatchScalarField.C +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutUSpaldingWallFunction/nutUSpaldingWallFunctionFvPatchScalarField.C @@ -47,7 +47,7 @@ tmp nutUSpaldingWallFunctionFvPatchScalarField::calcNut() const const RASModel& rasModel = db().lookupObject("RASProperties"); const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI]; - const scalarField magGradU = mag(Uw.snGrad()); + const scalarField magGradU = mag(Uw.snGrad()) + ROOTVSMALL; const scalarField& nuw = rasModel.nu().boundaryField()[patchI]; return max(scalar(0), sqr(calcUTau(magGradU))/magGradU - nuw); @@ -74,9 +74,8 @@ tmp nutUSpaldingWallFunctionFvPatchScalarField::calcUTau forAll(uTau, facei) { - scalar magUpara = magUp[facei]; - - scalar ut = sqrt((nutw[facei] + nuw[facei])*magGradU[facei]); + scalar ut = + sqrt((nutw[facei] + nuw[facei])*magGradU[facei]) + ROOTVSMALL; if (ut > VSMALL) { @@ -85,17 +84,17 @@ tmp nutUSpaldingWallFunctionFvPatchScalarField::calcUTau do { - scalar kUu = min(kappa_*magUpara/ut, 50); + scalar kUu = min(kappa_*magUp[facei]/ut, 50); scalar fkUu = exp(kUu) - 1 - kUu*(1 + 0.5*kUu); scalar f = - ut*y[facei]/nuw[facei] - + magUpara/ut + + magUp[facei]/ut + 1/E_*(fkUu - 1.0/6.0*kUu*sqr(kUu)); scalar df = y[facei]/nuw[facei] - + magUpara/sqr(ut) + + magUp[facei]/sqr(ut) + 1/E_*kUu*fkUu/ut; scalar uTauNew = ut + f/df; @@ -103,6 +102,7 @@ tmp nutUSpaldingWallFunctionFvPatchScalarField::calcUTau ut = uTauNew; } while (ut > VSMALL && err > 0.01 && ++iter < 10); + uTau[facei] = max(0.0, ut); } } From c832d635b159ee26497ee245c99d161df598319f Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 11 Aug 2009 11:55:46 +0200 Subject: [PATCH 02/10] ISstream::read improvements - following Andy's idea to return values as label whenever possible eg, 1.2e6 -> 1200000 but left it commented out - avoid buffer overflow in ISstream::read(word&). Is the 'if (fail())' check itself actually in the correct place?? - other minor cosmetic changes --- applications/test/tokenizeTest/tokenizeTest.C | 86 +++++--- src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C | 197 +++++++++--------- src/OpenFOAM/global/argList/argList.C | 12 +- 3 files changed, 171 insertions(+), 124 deletions(-) diff --git a/applications/test/tokenizeTest/tokenizeTest.C b/applications/test/tokenizeTest/tokenizeTest.C index deb675ee00..99bc599984 100644 --- a/applications/test/tokenizeTest/tokenizeTest.C +++ b/applications/test/tokenizeTest/tokenizeTest.C @@ -33,6 +33,7 @@ Description #include "IOstreams.H" #include "IFstream.H" #include "IStringStream.H" +#include "cpuTime.H" using namespace Foam; @@ -44,41 +45,76 @@ int main(int argc, char *argv[]) argList::noParallel(); argList::validArgs.insert("string .. stringN"); argList::validOptions.insert("file", "name"); + argList::validOptions.insert("repeat", "count"); argList args(argc, argv, false, true); - forAll(args.additionalArgs(), argI) - { - const string& rawArg = args.additionalArgs()[argI]; - Info<< "input string: " << rawArg << nl; + label repeat = 1; + args.optionReadIfPresent