From 07eb4beb9b54ec82aa6b23f4b9d570238582ab00 Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 13 Mar 2009 16:37:07 +0000 Subject: [PATCH] new functionality for dsmc --- src/postProcessing/forces/forces/IOforces.H | 2 +- src/postProcessing/forces/forces/forces.C | 145 +++++++++++++++------ src/postProcessing/forces/forces/forces.H | 12 +- .../forces/forces/forcesFunctionObject.C | 2 +- .../forces/forces/forcesFunctionObject.H | 2 +- 5 files changed, 115 insertions(+), 48 deletions(-) diff --git a/src/postProcessing/forces/forces/IOforces.H b/src/postProcessing/forces/forces/IOforces.H index 522dbd8..a32a69d 100644 --- a/src/postProcessing/forces/forces/IOforces.H +++ b/src/postProcessing/forces/forces/IOforces.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd. + \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License diff --git a/src/postProcessing/forces/forces/forces.C b/src/postProcessing/forces/forces/forces.C index 433ef1e..f60d8ac 100644 --- a/src/postProcessing/forces/forces/forces.C +++ b/src/postProcessing/forces/forces/forces.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd. + \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -81,7 +81,7 @@ Foam::tmp Foam::forces::devRhoReff() const const basicThermo& thermo = obr_.lookupObject("thermophysicalProperties"); - const volVectorField& U = obr_.lookupObject(Uname_); + const volVectorField& U = obr_.lookupObject(UName_); return -thermo.mu()*dev(twoSymm(fvc::grad(U))); } @@ -94,7 +94,7 @@ Foam::tmp Foam::forces::devRhoReff() const obr_.lookupObject ("transportProperties"); - const volVectorField& U = obr_.lookupObject(Uname_); + const volVectorField& U = obr_.lookupObject(UName_); return -rhoRef_*laminarT.nu()*dev(twoSymm(fvc::grad(U))); } @@ -105,7 +105,7 @@ Foam::tmp Foam::forces::devRhoReff() const dimensionedScalar nu(transportProperties.lookup("nu")); - const volVectorField& U = obr_.lookupObject(Uname_); + const volVectorField& U = obr_.lookupObject(UName_); return -rhoRef_*nu*dev(twoSymm(fvc::grad(U))); } @@ -149,7 +149,9 @@ Foam::forces::forces log_(false), patchSet_(), pName_(""), - Uname_(""), + UName_(""), + directForceDensity_(false), + fDName_(""), rhoRef_(0), CofR_(vector::zero), forcesFilePtr_(NULL) @@ -188,27 +190,50 @@ void Foam::forces::read(const dictionary& dict) patchSet_ = mesh.boundaryMesh().patchSet(wordList(dict.lookup("patches"))); - // Optional entries U and p - pName_ = dict.lookupOrDefault("pName", "p"); - Uname_ = dict.lookupOrDefault("Uname", "U"); + dict.readIfPresent("directForceDensity", directForceDensity_); - // Check whether Uname and pName exists, if not deactivate forces - if - ( - !obr_.foundObject(Uname_) - || !obr_.foundObject(pName_) - ) + if (directForceDensity_) { - active_ = false; - WarningIn("void forces::read(const dictionary& dict)") - << "Could not find " << Uname_ << " or " - << pName_ << " in database." << nl - << " De-activating forces." - << endl; + // Optional entry for fDName + fDName_ = dict.lookupOrDefault("fDName", "fD"); + + // Check whether fDName exists, if not deactivate forces + if + ( + !obr_.foundObject(fDName_) + ) + { + active_ = false; + WarningIn("void forces::read(const dictionary& dict)") + << "Could not find " << fDName_ << " in database." << nl + << " De-activating forces." + << endl; + } } + else + { + // Optional entries U and p + pName_ = dict.lookupOrDefault("pName", "p"); + UName_ = dict.lookupOrDefault("UName", "U"); + + // Check whether UName and pName exists, if not deactivate forces + if + ( + !obr_.foundObject(UName_) + || !obr_.foundObject(pName_) + ) + { + active_ = false; + WarningIn("void forces::read(const dictionary& dict)") + << "Could not find " << UName_ << " or " + << pName_ << " in database." << nl + << " De-activating forces." + << endl; + } - // Reference density needed for incompressible calculations - rhoRef_ = readScalar(dict.lookup("rhoInf")); + // Reference density needed for incompressible calculations + rhoRef_ = readScalar(dict.lookup("rhoInf")); + } // Centre of rotation for moment calculations CofR_ = dict.lookup("CofR"); @@ -294,40 +319,76 @@ void Foam::forces::write() Foam::forces::forcesMoments Foam::forces::calcForcesMoment() const { - const volVectorField& U = obr_.lookupObject(Uname_); - const volScalarField& p = obr_.lookupObject(pName_); - - const fvMesh& mesh = U.mesh(); - forcesMoments fm ( pressureViscous(vector::zero, vector::zero), pressureViscous(vector::zero, vector::zero) ); - const surfaceVectorField::GeometricBoundaryField& Sfb = - mesh.Sf().boundaryField(); + if (directForceDensity_) + { + const volVectorField& fD = obr_.lookupObject(fDName_); - tmp tdevRhoReff = devRhoReff(); - const volSymmTensorField::GeometricBoundaryField& devRhoReffb - = tdevRhoReff().boundaryField(); + const fvMesh& mesh = fD.mesh(); + + const surfaceVectorField::GeometricBoundaryField& Sfb = + mesh.Sf().boundaryField(); + + forAllConstIter(labelHashSet, patchSet_, iter) + { + label patchi = iter.key(); - forAllConstIter(labelHashSet, patchSet_, iter) + vectorField Md = mesh.C().boundaryField()[patchi] - CofR_; + + scalarField sA = mag(Sfb[patchi]); + + // Normal force = surfaceUnitNormal * (surfaceNormal & forceDensity) + vectorField fN = + Sfb[patchi]/sA + *( + Sfb[patchi] & fD.boundaryField()[patchi] + ); + + fm.first().first() += sum(fN); + fm.second().first() += sum(Md ^ fN); + + // Tangential force (total force minus normal fN) + vectorField fT = sA*fD.boundaryField()[patchi] - fN; + + fm.first().second() += sum(fT); + fm.second().second() += sum(Md ^ fT); + } + } + else { - label patchi = iter.key(); + const volVectorField& U = obr_.lookupObject(UName_); + const volScalarField& p = obr_.lookupObject(pName_); + + const fvMesh& mesh = U.mesh(); - vectorField Md = mesh.C().boundaryField()[patchi] - CofR_; + const surfaceVectorField::GeometricBoundaryField& Sfb = + mesh.Sf().boundaryField(); - vectorField pf = - mesh.Sf().boundaryField()[patchi]*p.boundaryField()[patchi]; + tmp tdevRhoReff = devRhoReff(); + const volSymmTensorField::GeometricBoundaryField& devRhoReffb + = tdevRhoReff().boundaryField(); + + forAllConstIter(labelHashSet, patchSet_, iter) + { + label patchi = iter.key(); - fm.first().first() += rho(p)*sum(pf); - fm.second().first() += rho(p)*sum(Md ^ pf); + vectorField Md = mesh.C().boundaryField()[patchi] - CofR_; - vectorField vf = Sfb[patchi] & devRhoReffb[patchi]; + vectorField pf = Sfb[patchi]*p.boundaryField()[patchi]; - fm.first().second() += sum(vf); - fm.second().second() += sum(Md ^ vf); + fm.first().first() += rho(p)*sum(pf); + fm.second().first() += rho(p)*sum(Md ^ pf); + + vectorField vf = Sfb[patchi] & devRhoReffb[patchi]; + + fm.first().second() += sum(vf); + fm.second().second() += sum(Md ^ vf); + } } reduce(fm, sumOp()); diff --git a/src/postProcessing/forces/forces/forces.H b/src/postProcessing/forces/forces/forces.H index 7b03805..e16567f 100644 --- a/src/postProcessing/forces/forces/forces.H +++ b/src/postProcessing/forces/forces/forces.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd. + \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -121,7 +121,7 @@ protected: //- Switch to send output to Info as well as to file Switch log_; - // Read from dictonary + // Read from dictionary //- Patches to integrate forces over labelHashSet patchSet_; @@ -130,7 +130,13 @@ protected: word pName_; //- Name of velocity field - word Uname_; + word UName_; + + //- Is the force density being supplied directly? + Switch directForceDensity_; + + //- The name of the force density (fD) field + word fDName_; //- Reference density needed for incompressible calculations scalar rhoRef_; diff --git a/src/postProcessing/forces/forces/forcesFunctionObject.C b/src/postProcessing/forces/forces/forcesFunctionObject.C index f798123..de77062 100644 --- a/src/postProcessing/forces/forces/forcesFunctionObject.C +++ b/src/postProcessing/forces/forces/forcesFunctionObject.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd. + \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License diff --git a/src/postProcessing/forces/forces/forcesFunctionObject.H b/src/postProcessing/forces/forces/forcesFunctionObject.H index a8529e2..6cf8bb9 100644 --- a/src/postProcessing/forces/forces/forcesFunctionObject.H +++ b/src/postProcessing/forces/forces/forcesFunctionObject.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd. + \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License -- 2.11.4.GIT