From 6459a1d179cacd1af249f95dee91b2ef8ecd0f8a Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 11 Apr 2014 12:11:36 +0100 Subject: [PATCH 1/5] BUG: heat transfer Boussinesq solvers - added fvOptions MRF support - mantis #1267 --- .../solvers/heatTransfer/buoyantBoussinesqPimpleFoam/pEqn.H | 4 +++- .../solvers/heatTransfer/buoyantBoussinesqSimpleFoam/pEqn.H | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/applications/solvers/heatTransfer/buoyantBoussinesqPimpleFoam/pEqn.H b/applications/solvers/heatTransfer/buoyantBoussinesqPimpleFoam/pEqn.H index d77eb12b..b73e5c88 100644 --- a/applications/solvers/heatTransfer/buoyantBoussinesqPimpleFoam/pEqn.H +++ b/applications/solvers/heatTransfer/buoyantBoussinesqPimpleFoam/pEqn.H @@ -15,13 +15,15 @@ + phig ); + fvOptions.makeRelative(phiHbyA); + // Update the fixedFluxPressure BCs to ensure flux consistency setSnGrad ( p_rgh.boundaryField(), ( phiHbyA.boundaryField() - - (mesh.Sf().boundaryField() & U.boundaryField()) + - fvOptions.relative(mesh.Sf().boundaryField() & U.boundaryField()) )/(mesh.magSf().boundaryField()*rAUf.boundaryField()) ); diff --git a/applications/solvers/heatTransfer/buoyantBoussinesqSimpleFoam/pEqn.H b/applications/solvers/heatTransfer/buoyantBoussinesqSimpleFoam/pEqn.H index bae1bcef..ae104e8f 100644 --- a/applications/solvers/heatTransfer/buoyantBoussinesqSimpleFoam/pEqn.H +++ b/applications/solvers/heatTransfer/buoyantBoussinesqSimpleFoam/pEqn.H @@ -14,6 +14,8 @@ (fvc::interpolate(HbyA) & mesh.Sf()) ); + fvOptions.makeRelative(phiHbyA); + adjustPhi(phiHbyA, U, p_rgh); phiHbyA += phig; @@ -24,7 +26,7 @@ p_rgh.boundaryField(), ( phiHbyA.boundaryField() - - (mesh.Sf().boundaryField() & U.boundaryField()) + - fvOptions.relative(mesh.Sf().boundaryField() & U.boundaryField()) )/(mesh.magSf().boundaryField()*rAUf.boundaryField()) ); From 36fdb4787770b0387e112383c729f9d4af0827d2 Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 11 Apr 2014 14:32:31 +0100 Subject: [PATCH 2/5] ENH: porosity model updates for moving meshes --- .../DarcyForchheimer/DarcyForchheimer.C | 54 ++++++++++-- .../porosityModel/fixedCoeff/fixedCoeff.C | 18 ++-- src/meshTools/coordinateSystems/cartesianCS.C | 4 +- .../EulerCoordinateRotation.H | 8 +- .../STARCDCoordinateRotation.H | 8 +- .../coordinateRotation/axesRotation.C | 70 +++++++++------ .../coordinateRotation/axesRotation.H | 14 +-- .../coordinateRotation/coordinateRotation.H | 10 ++- .../coordinateRotation/localAxesRotation.C | 86 +++++++++++-------- .../coordinateRotation/localAxesRotation.H | 9 +- .../coordinateSystems/coordinateSystem.C | 13 +-- .../coordinateSystems/coordinateSystem.H | 33 ++++--- 12 files changed, 219 insertions(+), 108 deletions(-) diff --git a/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimer.C b/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimer.C index 3036baff..4af4c9f8 100644 --- a/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimer.C +++ b/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimer.C @@ -81,9 +81,10 @@ void Foam::porosityModels::DarcyForchheimer::calcTranformModelData() { forAll (cellZoneIDs_, zoneI) { - D_[zoneI].setSize(1, tensor::zero); - F_[zoneI].setSize(1, tensor::zero); + D_[zoneI].setSize(1); + F_[zoneI].setSize(1); + D_[zoneI][0] = tensor::zero; D_[zoneI][0].xx() = dXYZ_.value().x(); D_[zoneI][0].yy() = dXYZ_.value().y(); D_[zoneI][0].zz() = dXYZ_.value().z(); @@ -91,6 +92,7 @@ void Foam::porosityModels::DarcyForchheimer::calcTranformModelData() D_[zoneI][0] = coordSys_.R().transformTensor(D_[zoneI][0]); // leading 0.5 is from 1/2*rho + F_[zoneI][0] = tensor::zero; F_[zoneI][0].xx() = 0.5*fXYZ_.value().x(); F_[zoneI][0].yy() = 0.5*fXYZ_.value().y(); F_[zoneI][0].zz() = 0.5*fXYZ_.value().z(); @@ -104,25 +106,65 @@ void Foam::porosityModels::DarcyForchheimer::calcTranformModelData() { const labelList& cells = mesh_.cellZones()[cellZoneIDs_[zoneI]]; - D_[zoneI].setSize(cells.size(), tensor::zero); - F_[zoneI].setSize(cells.size(), tensor::zero); + D_[zoneI].setSize(cells.size()); + F_[zoneI].setSize(cells.size()); forAll(cells, i) { + D_[zoneI][i] = tensor::zero; D_[zoneI][i].xx() = dXYZ_.value().x(); D_[zoneI][i].yy() = dXYZ_.value().y(); D_[zoneI][i].zz() = dXYZ_.value().z(); // leading 0.5 is from 1/2*rho + F_[zoneI][i] = tensor::zero; F_[zoneI][i].xx() = 0.5*fXYZ_.value().x(); F_[zoneI][i].yy() = 0.5*fXYZ_.value().y(); F_[zoneI][i].zz() = 0.5*fXYZ_.value().z(); } - D_[zoneI] = coordSys_.R().transformTensor(D_[zoneI], cells); - F_[zoneI] = coordSys_.R().transformTensor(F_[zoneI], cells); + const coordinateRotation& R = coordSys_.R(mesh_, cells); + + D_[zoneI] = R.transformTensor(D_[zoneI], cells); + F_[zoneI] = R.transformTensor(F_[zoneI], cells); } } + + if (debug && mesh_.time().outputTime()) + { + volTensorField Dout + ( + IOobject + ( + typeName + ":D", + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh_, + dimensionedTensor("0", dXYZ_.dimensions(), tensor::zero) + ); + volTensorField Fout + ( + IOobject + ( + typeName + ":F", + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh_, + dimensionedTensor("0", fXYZ_.dimensions(), tensor::zero) + ); + + UIndirectList(Dout, mesh_.cellZones()[cellZoneIDs_[0]]) = D_[0]; + UIndirectList(Fout, mesh_.cellZones()[cellZoneIDs_[0]]) = F_[0]; + + Dout.write(); + Fout.write(); + } } diff --git a/src/finiteVolume/cfdTools/general/porosityModel/fixedCoeff/fixedCoeff.C b/src/finiteVolume/cfdTools/general/porosityModel/fixedCoeff/fixedCoeff.C index c3ef2826..c858fc28 100644 --- a/src/finiteVolume/cfdTools/general/porosityModel/fixedCoeff/fixedCoeff.C +++ b/src/finiteVolume/cfdTools/general/porosityModel/fixedCoeff/fixedCoeff.C @@ -137,14 +137,16 @@ void Foam::porosityModels::fixedCoeff::calcTranformModelData() { forAll (cellZoneIDs_, zoneI) { - alpha_[zoneI].setSize(1, tensor::zero); - beta_[zoneI].setSize(1, tensor::zero); + alpha_[zoneI].setSize(1); + beta_[zoneI].setSize(1); + alpha_[zoneI][0] = tensor::zero; alpha_[zoneI][0].xx() = alphaXYZ_.value().x(); alpha_[zoneI][0].yy() = alphaXYZ_.value().y(); alpha_[zoneI][0].zz() = alphaXYZ_.value().z(); alpha_[zoneI][0] = coordSys_.R().transformTensor(alpha_[zoneI][0]); + beta_[zoneI][0] = tensor::zero; beta_[zoneI][0].xx() = betaXYZ_.value().x(); beta_[zoneI][0].yy() = betaXYZ_.value().y(); beta_[zoneI][0].zz() = betaXYZ_.value().z(); @@ -157,24 +159,26 @@ void Foam::porosityModels::fixedCoeff::calcTranformModelData() { const labelList& cells = mesh_.cellZones()[cellZoneIDs_[zoneI]]; - alpha_[zoneI].setSize(cells.size(), tensor::zero); - beta_[zoneI].setSize(cells.size(), tensor::zero); + alpha_[zoneI].setSize(cells.size()); + beta_[zoneI].setSize(cells.size()); forAll(cells, i) { + alpha_[zoneI][i] = tensor::zero; alpha_[zoneI][i].xx() = alphaXYZ_.value().x(); alpha_[zoneI][i].yy() = alphaXYZ_.value().y(); alpha_[zoneI][i].zz() = alphaXYZ_.value().z(); + beta_[zoneI][i] = tensor::zero; beta_[zoneI][i].xx() = betaXYZ_.value().x(); beta_[zoneI][i].yy() = betaXYZ_.value().y(); beta_[zoneI][i].zz() = betaXYZ_.value().z(); } - alpha_[zoneI] = - coordSys_.R().transformTensor(alpha_[zoneI], cells); + const coordinateRotation& R = coordSys_.R(mesh_, cells); - beta_[zoneI] = coordSys_.R().transformTensor(beta_[zoneI], cells); + alpha_[zoneI] = R.transformTensor(alpha_[zoneI], cells); + beta_[zoneI] = R.transformTensor(beta_[zoneI], cells); } } } diff --git a/src/meshTools/coordinateSystems/cartesianCS.C b/src/meshTools/coordinateSystems/cartesianCS.C index b80a69f5..f01bc18c 100644 --- a/src/meshTools/coordinateSystems/cartesianCS.C +++ b/src/meshTools/coordinateSystems/cartesianCS.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -157,6 +157,4 @@ Foam::tmp Foam::cartesianCS::globalToLocal } - - // ************************************************************************* // diff --git a/src/meshTools/coordinateSystems/coordinateRotation/EulerCoordinateRotation.H b/src/meshTools/coordinateSystems/coordinateRotation/EulerCoordinateRotation.H index a0be41cc..362c846f 100644 --- a/src/meshTools/coordinateSystems/coordinateRotation/EulerCoordinateRotation.H +++ b/src/meshTools/coordinateSystems/coordinateRotation/EulerCoordinateRotation.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -130,6 +130,12 @@ public: Rtr_ = sphericalTensor::I; } + //- Update the rotation for a list of cells + virtual void updateCells(const polyMesh&, const labelList&) + { + // do nothing + } + //- Return local-to-global transformation tensor virtual const tensor& R() const { diff --git a/src/meshTools/coordinateSystems/coordinateRotation/STARCDCoordinateRotation.H b/src/meshTools/coordinateSystems/coordinateRotation/STARCDCoordinateRotation.H index e034517c..1b73f71e 100644 --- a/src/meshTools/coordinateSystems/coordinateRotation/STARCDCoordinateRotation.H +++ b/src/meshTools/coordinateSystems/coordinateRotation/STARCDCoordinateRotation.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -126,6 +126,12 @@ public: Rtr_ = sphericalTensor::I; } + //- Update the rotation for a list of cells + virtual void updateCells(const polyMesh&, const labelList&) + { + // do nothing + } + //- Return local-to-global transformation tensor virtual const tensor& R() const { diff --git a/src/meshTools/coordinateSystems/coordinateRotation/axesRotation.C b/src/meshTools/coordinateSystems/coordinateRotation/axesRotation.C index a502eb02..f5d0fa0d 100644 --- a/src/meshTools/coordinateSystems/coordinateRotation/axesRotation.C +++ b/src/meshTools/coordinateSystems/coordinateRotation/axesRotation.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -50,10 +50,9 @@ void Foam::axesRotation::calcTransform const axisOrder& order ) { - vector a = axis1 / mag(axis1); + vector a = axis1/mag(axis1); vector b = axis2; - // Absorb minor nonorthogonality into axis2 b = b - (b & a)*a; if (mag(b) < SMALL) @@ -64,36 +63,49 @@ void Foam::axesRotation::calcTransform << abort(FatalError); } - b = b / mag(b); - vector c = a ^ b; + b = b/mag(b); + vector c = a^b; tensor Rtr; switch (order) { case e1e2: + { Rtr = tensor(a, b, c); break; - + } case e2e3: + { Rtr = tensor(c, a, b); break; - + } case e3e1: + { Rtr = tensor(b, c, a); break; - + } default: - FatalErrorIn("axesRotation::calcTransform()") - << "programmer error" << endl + { + FatalErrorIn + ( + "axesRotation::calcTransform" + "(" + "const vector&," + "const vector&," + "const axisOrder&" + ")" + ) + << "Unhandled axes specifictation" << endl << abort(FatalError); Rtr = tensor::zero; break; + } } - // the global -> local transformation + // the global->local transformation Rtr_ = Rtr; - // the local -> global transformation + // the local->global transformation R_ = Rtr.T(); } @@ -154,15 +166,13 @@ Foam::axesRotation::axesRotation(const tensor& R) // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // -Foam::vector Foam::axesRotation::transform(const vector& st) const +const Foam::tensorField& Foam::axesRotation::Tr() const { - return (R_ & st); -} - - -Foam::vector Foam::axesRotation::invTransform(const vector& st) const -{ - return (Rtr_ & st); + notImplemented + ( + "const Foam::tensorField& axesRotation::Tr() const" + ); + return *reinterpret_cast(0); } @@ -175,6 +185,12 @@ Foam::tmp Foam::axesRotation::transform } +Foam::vector Foam::axesRotation::transform(const vector& st) const +{ + return (R_ & st); +} + + Foam::tmp Foam::axesRotation::invTransform ( const vectorField& st @@ -184,13 +200,9 @@ Foam::tmp Foam::axesRotation::invTransform } -const Foam::tensorField& Foam::axesRotation::Tr() const +Foam::vector Foam::axesRotation::invTransform(const vector& st) const { - notImplemented - ( - "const Foam::tensorField& axesRotation::Tr() const" - ); - return *reinterpret_cast(0); + return (Rtr_ & st); } @@ -225,13 +237,15 @@ Foam::tmp Foam::axesRotation::transformTensor notImplemented ( "tmp axesRotation::transformTensor " - " const tensorField& st," - " const labelList& cellMap " + "(" + "const tensorField&," + "const labelList&" ") const" ); return tmp(NULL); } + Foam::tmp Foam::axesRotation::transformVector ( const vectorField& st diff --git a/src/meshTools/coordinateSystems/coordinateRotation/axesRotation.H b/src/meshTools/coordinateSystems/coordinateRotation/axesRotation.H index c7558010..1478e445 100644 --- a/src/meshTools/coordinateSystems/coordinateRotation/axesRotation.H +++ b/src/meshTools/coordinateSystems/coordinateRotation/axesRotation.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -99,11 +99,7 @@ public: axesRotation(); //- Construct from 2 axes - axesRotation - ( - const vector& axis, - const vector& dir - ); + axesRotation(const vector& axis, const vector& dir); //- Construct from dictionary axesRotation(const dictionary&); @@ -135,6 +131,12 @@ public: Rtr_ = sphericalTensor::I; } + //- Update the rotation for a list of cells + virtual void updateCells(const polyMesh&, const labelList&) + { + // do nothing + } + //- Return local-to-global transformation tensor virtual const tensor& R() const { diff --git a/src/meshTools/coordinateSystems/coordinateRotation/coordinateRotation.H b/src/meshTools/coordinateSystems/coordinateRotation/coordinateRotation.H index 7564696c..0e90d7aa 100644 --- a/src/meshTools/coordinateSystems/coordinateRotation/coordinateRotation.H +++ b/src/meshTools/coordinateSystems/coordinateRotation/coordinateRotation.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -55,6 +55,7 @@ Description #include "dictionary.H" #include "runTimeSelectionTables.H" #include "objectRegistry.H" +#include "polyMesh.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -135,6 +136,13 @@ public: //- Reset rotation to an identity rotation virtual void clear() = 0; + //- Update the rotation for a list of cells + virtual void updateCells + ( + const polyMesh& mesh, + const labelList& cells + ) = 0; + //- Return local-to-global transformation tensor virtual const tensor& R() const = 0; diff --git a/src/meshTools/coordinateSystems/coordinateRotation/localAxesRotation.C b/src/meshTools/coordinateSystems/coordinateRotation/localAxesRotation.C index 71902622..cbe68e44 100644 --- a/src/meshTools/coordinateSystems/coordinateRotation/localAxesRotation.C +++ b/src/meshTools/coordinateSystems/coordinateRotation/localAxesRotation.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -48,12 +48,33 @@ namespace Foam ); } + +// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // + +void Foam::localAxesRotation::init(const objectRegistry& obr) +{ + const polyMesh& mesh = refCast(obr); + const vectorField& cc = mesh.cellCentres(); + + tensorField& R = Rptr_(); + forAll(cc, cellI) + { + vector dir = cc[cellI] - origin_; + dir /= mag(dir) + VSMALL; + + const axesRotation ar(e3_, dir); + + R[cellI] = ar.R(); + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::localAxesRotation::localAxesRotation ( const dictionary& dict, - const objectRegistry& orb + const objectRegistry& obr ) : Rptr_(), @@ -69,27 +90,21 @@ Foam::localAxesRotation::localAxesRotation // rotation axis dict.lookup("e3") >> e3_; - const polyMesh& mesh = refCast(orb); + const polyMesh& mesh = refCast(obr); - Rptr_.reset - ( - new tensorField(mesh.nCells()) - ); - init(dict, orb); + Rptr_.reset(new tensorField(mesh.nCells())); + init(obr); } -Foam::localAxesRotation::localAxesRotation -( - const dictionary& dict -) +Foam::localAxesRotation::localAxesRotation(const dictionary& dict) : Rptr_(), origin_(), e3_() { FatalErrorIn("localAxesRotation(const dictionary&)") - << " localAxesRotation can not be constructed from dictionary " + << " localAxesRotation can not be constructed from dictionary " << " use the construtctor : " "(" " const dictionary&, const objectRegistry&" @@ -109,6 +124,23 @@ void Foam::localAxesRotation::clear() } +void Foam::localAxesRotation::updateCells +( + const polyMesh& mesh, + const labelList& cells +) +{ + forAll(cells, i) + { + label cellI = cells[i]; + vector dir = mesh.cellCentres()[cellI] - origin_; + dir /= mag(dir) + VSMALL; + + Rptr_()[cellI] = axesRotation(e3_, dir).R(); + } +} + + Foam::vector Foam::localAxesRotation::transform(const vector& st) const { notImplemented @@ -212,14 +244,16 @@ Foam::tmp Foam::localAxesRotation::transformTensor << abort(FatalError); } - const tensorField Rtr(Rptr_().T()); + const tensorField& R = Rptr_(); + const tensorField Rtr(R.T()); tmp tt(new tensorField(cellMap.size())); tensorField& t = tt(); forAll(cellMap, i) { const label cellI = cellMap[i]; - t[i] = Rptr_()[cellI] & st[i] & Rtr[cellI]; + t[i] = R[cellI] & st[i] & Rtr[cellI]; } + return tt; } @@ -239,9 +273,10 @@ Foam::tmp Foam::localAxesRotation::transformVector tmp tfld(new symmTensorField(Rptr_->size())); symmTensorField& fld = tfld(); + const tensorField& R = Rptr_(); forAll(fld, i) { - fld[i] = transformPrincipal(Rptr_()[i], st[i]); + fld[i] = transformPrincipal(R[i], st[i]); } return tfld; } @@ -260,25 +295,6 @@ Foam::symmTensor Foam::localAxesRotation::transformVector } -// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // - -void Foam::localAxesRotation::init -( - const dictionary& dict, - const objectRegistry& obr -) -{ - const polyMesh& mesh = refCast(obr); - forAll(mesh.cellCentres(), cellI) - { - vector dir = mesh.cellCentres()[cellI] - origin_; - dir /= mag(dir) + VSMALL; - - Rptr_()[cellI] = axesRotation(e3_, dir).R(); - } -} - - void Foam::localAxesRotation::write(Ostream& os) const { os.writeKeyword("e3") << e3() << token::END_STATEMENT << nl; diff --git a/src/meshTools/coordinateSystems/coordinateRotation/localAxesRotation.H b/src/meshTools/coordinateSystems/coordinateRotation/localAxesRotation.H index 8d335a62..d6eb7c63 100644 --- a/src/meshTools/coordinateSystems/coordinateRotation/localAxesRotation.H +++ b/src/meshTools/coordinateSystems/coordinateRotation/localAxesRotation.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -74,8 +74,8 @@ class localAxesRotation // Private members - //- Init transformation tensor - void init(const dictionary& dict, const objectRegistry& obr); + //- Init transformation tensor field + void init(const objectRegistry& obr); public: @@ -108,6 +108,9 @@ public: //- Reset rotation to an identity rotation virtual void clear(); + //- Update the rotation for a list of cells + virtual void updateCells(const polyMesh& mesh, const labelList& cells); + //- Return local-to-global transformation tensor virtual const tensor& R() const { diff --git a/src/meshTools/coordinateSystems/coordinateSystem.C b/src/meshTools/coordinateSystems/coordinateSystem.C index 16e6983a..a63423aa 100644 --- a/src/meshTools/coordinateSystems/coordinateSystem.C +++ b/src/meshTools/coordinateSystems/coordinateSystem.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -127,7 +127,6 @@ Foam::coordinateSystem::coordinateSystem origin_(point::zero), R_() { - const entry* entryPtr = dict.lookupEntryPtr(typeName_(), false, false); // non-dictionary entry is a lookup into global coordinateSystems @@ -141,7 +140,7 @@ Foam::coordinateSystem::coordinateSystem if (debug) { Info<< "coordinateSystem::coordinateSystem" - "(const dictionary&, const objectRegistry&):" + "(const objectRegistry&, const dictionary&):" << nl << "using global coordinate system: " << key << "=" << index << endl; } @@ -151,7 +150,7 @@ Foam::coordinateSystem::coordinateSystem FatalErrorIn ( "coordinateSystem::coordinateSystem" - "(const dictionary&, const objectRegistry&)" + "(const objectRegistry&, const dictionary&):" ) << "could not find coordinate system: " << key << nl << "available coordinate systems: " << lst.toc() << nl << nl << exit(FatalError); @@ -344,7 +343,11 @@ void Foam::coordinateSystem::init { if (debug) { - Pout<< "coordinateSystem::operator=(const dictionary&) : " + Pout<< "coordinateSystem::operator=" + "(" + "const dictionary&, " + "const objectRegistry&" + ") : " << "assign from " << rhs << endl; } diff --git a/src/meshTools/coordinateSystems/coordinateSystem.H b/src/meshTools/coordinateSystems/coordinateSystem.H index 47847c8b..196395cd 100644 --- a/src/meshTools/coordinateSystems/coordinateSystem.H +++ b/src/meshTools/coordinateSystems/coordinateSystem.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,10 +25,9 @@ Class Foam::coordinateSystem Description - Base class for other coordinate - system specifications. + Base class for other coordinate system specifications. - All systems are defined by an origin point and a coordinateRotation. + All systems are defined by an origin point and a co-ordinate rotation. \verbatim coordinateSystem @@ -37,8 +36,8 @@ Description origin (0 0 0); coordinateRotation { - type STARCDRotation; - rotation (0 0 90); + type localAxesRotation; + e3 (0 0 1); } } \endverbatim @@ -49,16 +48,17 @@ Description 3) localAxesRotation 4) EulerCoordinateRotation - Type of coordinates: + Type of co-ordinates: 1) cartesian - 2) cylindricalCS + 2) cylindrical See Also coordinateSystem and coordinateSystem::New SourceFiles coordinateSystem.C - newCoordinateSystem.C + coordinateSystemNew.C + \*---------------------------------------------------------------------------*/ #ifndef coordinateSystem_H @@ -231,7 +231,6 @@ public: // Member Functions - // Access //- Return name @@ -258,18 +257,28 @@ public: return origin_; } - //- Return const reference to coordinate rotation + //- Return const reference to co-ordinate rotation const coordinateRotation& R() const { return R_(); } - //- Return non const reference to coordinate rotation + //- Return non const reference to co-ordinate rotation coordinateRotation& R() { return R_(); } + //- Update and return the co-ordinate roation for a list of cells + const coordinateRotation& R + ( + const polyMesh& mesh, + const labelList& cells + ) + { + R_->updateCells(mesh, cells); + return R_(); + } //- Return as dictionary of entries // \param [in] ignoreType drop type (cartesian, cylindrical, etc) From 5597f1da7e9695cec85f0b4f8a0b4e6322c22028 Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 15 Apr 2014 12:42:28 +0100 Subject: [PATCH 3/5] interRegionHeatTransferModel: Corrected semi-implicit treatment of energy h and e, non-constant Cp/Cv and non-zero origin now supported --- .../interRegionHeatTransferModel.C | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/fvOptions/sources/interRegion/interRegionHeatTransferModel/interRegionHeatTransferModel/interRegionHeatTransferModel.C b/src/fvOptions/sources/interRegion/interRegionHeatTransferModel/interRegionHeatTransferModel/interRegionHeatTransferModel.C index 25b18606..6dd8c3f0 100644 --- a/src/fvOptions/sources/interRegion/interRegionHeatTransferModel/interRegionHeatTransferModel/interRegionHeatTransferModel.C +++ b/src/fvOptions/sources/interRegion/interRegionHeatTransferModel/interRegionHeatTransferModel/interRegionHeatTransferModel.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -170,7 +170,7 @@ void Foam::fv::interRegionHeatTransferModel::addSup correct(); - const volScalarField& h = eqn.psi(); + const volScalarField& he = eqn.psi(); const volScalarField& T = mesh_.lookupObject(TName_); @@ -214,19 +214,21 @@ void Foam::fv::interRegionHeatTransferModel::addSup if (semiImplicit_) { - if (h.dimensions() == dimEnergy/dimMass) + if (he.dimensions() == dimEnergy/dimMass) { if (mesh_.foundObject("thermophysicalProperties")) { const basicThermo& thermo = mesh_.lookupObject("thermophysicalProperties"); - eqn += htc_*Tmapped - fvm::SuSp(htc_/thermo.Cp(), h); + volScalarField htcByCpv(htc_/thermo.Cpv()); + + eqn += htc_*(Tmapped - T) + htcByCpv*he - fvm::Sp(htcByCpv, he); if (debug) { const dimensionedScalar energy = - fvc::domainIntegrate(htc_*(h/thermo.Cp() - Tmapped)); + fvc::domainIntegrate(htc_*(he/thermo.Cp() - Tmapped)); Info<< "Energy exchange from region " << nbrMesh.name() << " To " << mesh_.name() << " : " << energy.value() @@ -251,9 +253,9 @@ void Foam::fv::interRegionHeatTransferModel::addSup << exit(FatalError); } } - else if (h.dimensions() == dimTemperature) + else if (he.dimensions() == dimTemperature) { - eqn += htc_*Tmapped - fvm::SuSp(htc_, h); + eqn += htc_*Tmapped - fvm::Sp(htc_, he); } } else From 1115c18a8140c83894bcbf9d739dee0b7ac4feb5 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 15 Apr 2014 16:38:06 +0100 Subject: [PATCH 4/5] BUG: Mantis #1259: created lagrangian turbulence library for new turbulent structure --- .../lagrangian/DPMFoam/MPPICFoam/Make/options | 1 + .../solvers/lagrangian/DPMFoam/Make/options | 1 + src/lagrangian/Allwmake | 1 + src/lagrangian/Turbulence/Make/files | 10 + src/lagrangian/Turbulence/Make/options | 45 ++++ ...keBasicKinematicCollidingParcelSubmodels.C | 37 ++++ .../makeBasicKinematicMPPICParcelSubmodels.C | 37 ++++ .../makeParcelTurbulenceDispersionModels.H | 53 +++++ .../DispersionRASModel/DispersionRASModel.C | 201 ++++++++++++++++++ .../DispersionRASModel/DispersionRASModel.H | 135 ++++++++++++ .../GradientDispersionRAS.C | 169 +++++++++++++++ .../GradientDispersionRAS.H | 126 +++++++++++ .../StochasticDispersionRAS.C | 127 +++++++++++ .../StochasticDispersionRAS.H | 110 ++++++++++ 14 files changed, 1053 insertions(+) create mode 100644 src/lagrangian/Turbulence/Make/files create mode 100644 src/lagrangian/Turbulence/Make/options create mode 100644 src/lagrangian/Turbulence/parcels/derived/basicKinematicCollidingParcel/makeBasicKinematicCollidingParcelSubmodels.C create mode 100644 src/lagrangian/Turbulence/parcels/derived/basicKinematicMPPICParcel/makeBasicKinematicMPPICParcelSubmodels.C create mode 100644 src/lagrangian/Turbulence/parcels/include/makeParcelTurbulenceDispersionModels.H create mode 100644 src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/DispersionRASModel/DispersionRASModel.C create mode 100644 src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/DispersionRASModel/DispersionRASModel.H create mode 100644 src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/GradientDispersionRAS/GradientDispersionRAS.C create mode 100644 src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/GradientDispersionRAS/GradientDispersionRAS.H create mode 100644 src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/StochasticDispersionRAS/StochasticDispersionRAS.C create mode 100644 src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/StochasticDispersionRAS/StochasticDispersionRAS.H diff --git a/applications/solvers/lagrangian/DPMFoam/MPPICFoam/Make/options b/applications/solvers/lagrangian/DPMFoam/MPPICFoam/Make/options index 948df098..4a0c3a56 100644 --- a/applications/solvers/lagrangian/DPMFoam/MPPICFoam/Make/options +++ b/applications/solvers/lagrangian/DPMFoam/MPPICFoam/Make/options @@ -22,6 +22,7 @@ EXE_LIBS = \ -lmeshTools \ -llagrangian \ -llagrangianIntermediate \ + -llagrangianTurbulentSubModels \ -lthermophysicalFunctions \ -lspecie \ -lradiationModels \ diff --git a/applications/solvers/lagrangian/DPMFoam/Make/options b/applications/solvers/lagrangian/DPMFoam/Make/options index e9524dfc..83684e57 100644 --- a/applications/solvers/lagrangian/DPMFoam/Make/options +++ b/applications/solvers/lagrangian/DPMFoam/Make/options @@ -21,6 +21,7 @@ EXE_LIBS = \ -lmeshTools \ -llagrangian \ -llagrangianIntermediate \ + -llagrangianTurbulentSubModels \ -lthermophysicalFunctions \ -lspecie \ -lradiationModels \ diff --git a/src/lagrangian/Allwmake b/src/lagrangian/Allwmake index 5310b3c8..104d3723 100755 --- a/src/lagrangian/Allwmake +++ b/src/lagrangian/Allwmake @@ -8,6 +8,7 @@ wmake $makeType basic wmake $makeType solidParticle wmake $makeType intermediate wmake $makeType turbulence +wmake $makeType Turbulence wmake $makeType spray wmake $makeType dsmc wmake $makeType coalCombustion diff --git a/src/lagrangian/Turbulence/Make/files b/src/lagrangian/Turbulence/Make/files new file mode 100644 index 00000000..72a84068 --- /dev/null +++ b/src/lagrangian/Turbulence/Make/files @@ -0,0 +1,10 @@ +PARCELS=parcels +DERIVEDPARCELS=$(PARCELS)/derived + +KINEMATICCOLLIDINGPARCEL=$(DERIVEDPARCELS)/basicKinematicCollidingParcel +$(KINEMATICCOLLIDINGPARCEL)/makeBasicKinematicCollidingParcelSubmodels.C + +KINEMATICMPPICPARCEL=$(DERIVEDPARCELS)/basicKinematicMPPICParcel +$(KINEMATICMPPICPARCEL)/makeBasicKinematicMPPICParcelSubmodels.C + +LIB = $(FOAM_LIBBIN)/liblagrangianTurbulentSubModels diff --git a/src/lagrangian/Turbulence/Make/options b/src/lagrangian/Turbulence/Make/options new file mode 100644 index 00000000..504394bf --- /dev/null +++ b/src/lagrangian/Turbulence/Make/options @@ -0,0 +1,45 @@ +EXE_INC = \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude \ + -I$(LIB_SRC)/lagrangian/basic/lnInclude \ + -I$(LIB_SRC)/lagrangian/intermediate/lnInclude \ + -I$(LIB_SRC)/lagrangian/distributionModels/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/properties/liquidProperties/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/properties/liquidMixtureProperties/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/properties/solidProperties/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/properties/solidMixtureProperties/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/reactionThermo/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/SLGThermo/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/radiationModels/lnInclude \ + -I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude \ + -I$(LIB_SRC)/transportModels \ + -I$(LIB_SRC)/regionModels/regionModel/lnInclude \ + -I$(LIB_SRC)/regionModels/surfaceFilmModels/lnInclude \ + -I$(LIB_SRC)/dynamicFvMesh/lnInclude \ + -I$(LIB_SRC)/sampling/lnInclude + +LIB_LIBS = \ + -lfiniteVolume \ + -lmeshTools \ + -llagrangian \ + -llagrangianIntermediate \ + -ldistributionModels \ + -lspecie \ + -lfluidThermophysicalModels \ + -lliquidProperties \ + -lliquidMixtureProperties \ + -lsolidProperties \ + -lsolidMixtureProperties \ + -lreactionThermophysicalModels \ + -lSLGThermo \ + -lradiationModels \ + -lturbulenceModels \ + -lincompressibleTurbulenceModels \ + -lcompressibleTurbulenceModels \ + -lincompressibleTransportModels \ + -lregionModels \ + -lsurfaceFilmModels \ + -ldynamicFvMesh \ + -lsampling diff --git a/src/lagrangian/Turbulence/parcels/derived/basicKinematicCollidingParcel/makeBasicKinematicCollidingParcelSubmodels.C b/src/lagrangian/Turbulence/parcels/derived/basicKinematicCollidingParcel/makeBasicKinematicCollidingParcelSubmodels.C new file mode 100644 index 00000000..c0d2f76c --- /dev/null +++ b/src/lagrangian/Turbulence/parcels/derived/basicKinematicCollidingParcel/makeBasicKinematicCollidingParcelSubmodels.C @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2014 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 . + +\*---------------------------------------------------------------------------*/ + +#include "basicKinematicCollidingCloud.H" +#include "makeParcelTurbulenceDispersionModels.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makeParcelTurbulenceDispersionModels(basicKinematicCollidingCloud); +} + + +// ************************************************************************* // diff --git a/src/lagrangian/Turbulence/parcels/derived/basicKinematicMPPICParcel/makeBasicKinematicMPPICParcelSubmodels.C b/src/lagrangian/Turbulence/parcels/derived/basicKinematicMPPICParcel/makeBasicKinematicMPPICParcelSubmodels.C new file mode 100644 index 00000000..60ed0310 --- /dev/null +++ b/src/lagrangian/Turbulence/parcels/derived/basicKinematicMPPICParcel/makeBasicKinematicMPPICParcelSubmodels.C @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2014 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 . + +\*---------------------------------------------------------------------------*/ + +#include "basicKinematicMPPICCloud.H" +#include "makeParcelTurbulenceDispersionModels.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makeParcelTurbulenceDispersionModels(basicKinematicMPPICCloud); +} + + +// ************************************************************************* // diff --git a/src/lagrangian/Turbulence/parcels/include/makeParcelTurbulenceDispersionModels.H b/src/lagrangian/Turbulence/parcels/include/makeParcelTurbulenceDispersionModels.H new file mode 100644 index 00000000..d2428ba4 --- /dev/null +++ b/src/lagrangian/Turbulence/parcels/include/makeParcelTurbulenceDispersionModels.H @@ -0,0 +1,53 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2014 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 . + +\*---------------------------------------------------------------------------*/ + +#ifndef makeParcelTurbulenceDispersionModels_h +#define makeParcelTurbulenceDispersionModels_h + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "GradientDispersionRAS.H" +#include "StochasticDispersionRAS.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#define makeParcelTurbulenceDispersionModels(CloudType) \ + \ + typedef CloudType::kinematicCloudType kinematicCloudType; \ + defineNamedTemplateTypeNameAndDebug \ + ( \ + DispersionRASModel, \ + 0 \ + ); \ + \ + makeDispersionModelType(GradientDispersionRAS, CloudType); \ + makeDispersionModelType(StochasticDispersionRAS, CloudType); \ + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/DispersionRASModel/DispersionRASModel.C b/src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/DispersionRASModel/DispersionRASModel.C new file mode 100644 index 00000000..43b1b366 --- /dev/null +++ b/src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/DispersionRASModel/DispersionRASModel.C @@ -0,0 +1,201 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2014 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 . + +\*---------------------------------------------------------------------------*/ + +#include "DispersionRASModel.H" +#include "demandDrivenData.H" +#include "turbulenceModel.H" + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +template +Foam::tmp +Foam::DispersionRASModel::kModel() const +{ + const objectRegistry& obr = this->owner().mesh(); + const word turbName = + IOobject::groupName + ( + turbulenceModel::propertiesName, + this->owner().U().group() + ); + + if (obr.foundObject(turbName)) + { + const turbulenceModel& model = + obr.lookupObject(turbName); + return model.k(); + } + else + { + FatalErrorIn + ( + "Foam::tmp" + "Foam::DispersionRASModel::kModel() const" + ) + << "Turbulence model not found in mesh database" << nl + << "Database objects include: " << obr.sortedToc() + << abort(FatalError); + + return tmp(NULL); + } +} + + +template +Foam::tmp +Foam::DispersionRASModel::epsilonModel() const +{ + const objectRegistry& obr = this->owner().mesh(); + const word turbName = + IOobject::groupName + ( + turbulenceModel::propertiesName, + this->owner().U().group() + ); + + if (obr.foundObject(turbName)) + { + const turbulenceModel& model = + obr.lookupObject(turbName); + return model.epsilon(); + } + else + { + FatalErrorIn + ( + "Foam::tmp" + "Foam::DispersionRASModel::epsilonModel() const" + ) + << "Turbulence model not found in mesh database" << nl + << "Database objects include: " << obr.sortedToc() + << abort(FatalError); + + return tmp(NULL); + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::DispersionRASModel::DispersionRASModel +( + const dictionary&, + CloudType& owner +) +: + DispersionModel(owner), + kPtr_(NULL), + ownK_(false), + epsilonPtr_(NULL), + ownEpsilon_(false) +{} + + +template +Foam::DispersionRASModel::DispersionRASModel +( + DispersionRASModel& dm +) +: + DispersionModel(dm), + kPtr_(dm.kPtr_), + ownK_(dm.ownK_), + epsilonPtr_(dm.epsilonPtr_), + ownEpsilon_(dm.ownEpsilon_) +{ + dm.ownK_ = false; + dm.ownEpsilon_ = false; +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::DispersionRASModel::~DispersionRASModel() +{ + cacheFields(false); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::DispersionRASModel::cacheFields(const bool store) +{ + if (store) + { + tmp tk = this->kModel(); + if (tk.isTmp()) + { + kPtr_ = tk.ptr(); + ownK_ = true; + } + else + { + kPtr_ = tk.operator->(); + ownK_ = false; + } + + tmp tepsilon = this->epsilonModel(); + if (tepsilon.isTmp()) + { + epsilonPtr_ = tepsilon.ptr(); + ownEpsilon_ = true; + } + else + { + epsilonPtr_ = tepsilon.operator->(); + ownEpsilon_ = false; + } + } + else + { + if (ownK_ && kPtr_) + { + deleteDemandDrivenData(kPtr_); + ownK_ = false; + } + if (ownEpsilon_ && epsilonPtr_) + { + deleteDemandDrivenData(epsilonPtr_); + ownEpsilon_ = false; + } + } +} + + +template +void Foam::DispersionRASModel::write(Ostream& os) const +{ + DispersionModel::write(os); + + os.writeKeyword("ownK") << ownK_ << token::END_STATEMENT << endl; + os.writeKeyword("ownEpsilon") << ownEpsilon_ << token::END_STATEMENT + << endl; +} + + +// ************************************************************************* // diff --git a/src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/DispersionRASModel/DispersionRASModel.H b/src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/DispersionRASModel/DispersionRASModel.H new file mode 100644 index 00000000..84967663 --- /dev/null +++ b/src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/DispersionRASModel/DispersionRASModel.H @@ -0,0 +1,135 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2014 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 . + +Class + Foam::DispersionRASModel + +Description + Base class for particle dispersion models based on RAS turbulence. + +\*---------------------------------------------------------------------------*/ + +#ifndef DispersionRASModel_H +#define DispersionRASModel_H + +#include "DispersionModel.H" + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class DispersionRASModel Declaration +\*---------------------------------------------------------------------------*/ + +template +class DispersionRASModel +: + public DispersionModel +{ +protected: + + // Protected data + + // Locally cached turbulence fields + + //- Turbulence k + const volScalarField* kPtr_; + + //- Take ownership of the k field + bool ownK_; + + //- Turbulence epsilon + const volScalarField* epsilonPtr_; + + //- Take ownership of the epsilon field + bool ownEpsilon_; + + + // Protected Functions + + //- Return the k field from the turbulence model + tmp kModel() const; + + //- Return the epsilon field from the turbulence model + tmp epsilonModel() const; + + +public: + + //- Runtime type information + TypeName("dispersionRASModel"); + + + // Constructors + + //- Construct from components + DispersionRASModel(const dictionary& dict, CloudType& owner); + + //- Construct copy + DispersionRASModel(DispersionRASModel& dm); + + //- Construct and return a clone + virtual autoPtr > clone() + { + return autoPtr > + ( + new DispersionRASModel(*this) + ); + } + + + //- Destructor + virtual ~DispersionRASModel(); + + + // Member Functions + + //- Cache carrier fields + virtual void cacheFields(const bool store); + + + // I-O + + //- Write + virtual void write(Ostream& os) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "DispersionRASModel.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/GradientDispersionRAS/GradientDispersionRAS.C b/src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/GradientDispersionRAS/GradientDispersionRAS.C new file mode 100644 index 00000000..06fa810a --- /dev/null +++ b/src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/GradientDispersionRAS/GradientDispersionRAS.C @@ -0,0 +1,169 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2014 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 . + +\*---------------------------------------------------------------------------*/ + +#include "GradientDispersionRAS.H" +#include "demandDrivenData.H" +#include "fvcGrad.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::GradientDispersionRAS::GradientDispersionRAS +( + const dictionary& dict, + CloudType& owner +) +: + DispersionRASModel(dict, owner), + gradkPtr_(NULL), + ownGradK_(false) +{} + + +template +Foam::GradientDispersionRAS::GradientDispersionRAS +( + GradientDispersionRAS& dm +) +: + DispersionRASModel(dm), + gradkPtr_(dm.gradkPtr_), + ownGradK_(dm.ownGradK_) +{ + dm.ownGradK_ = false; +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::GradientDispersionRAS::~GradientDispersionRAS() +{ + cacheFields(false); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::GradientDispersionRAS::cacheFields(const bool store) +{ + DispersionRASModel::cacheFields(store); + + if (store) + { + gradkPtr_ = fvc::grad(*this->kPtr_).ptr(); + ownGradK_ = true; + } + else + { + if (ownGradK_) + { + deleteDemandDrivenData(gradkPtr_); + gradkPtr_ = NULL; + ownGradK_ = false; + } + } +} + + +template +Foam::vector Foam::GradientDispersionRAS::update +( + const scalar dt, + const label cellI, + const vector& U, + const vector& Uc, + vector& UTurb, + scalar& tTurb +) +{ + cachedRandom& rnd = this->owner().rndGen(); + + const scalar cps = 0.16432; + + const scalar k = this->kPtr_->internalField()[cellI]; + const scalar epsilon = + this->epsilonPtr_->internalField()[cellI] + ROOTVSMALL; + const vector& gradk = this->gradkPtr_->internalField()[cellI]; + + const scalar UrelMag = mag(U - Uc - UTurb); + + const scalar tTurbLoc = + min(k/epsilon, cps*pow(k, 1.5)/epsilon/(UrelMag + SMALL)); + + + // Parcel is perturbed by the turbulence + if (dt < tTurbLoc) + { + tTurb += dt; + + if (tTurb > tTurbLoc) + { + tTurb = 0.0; + + scalar sigma = sqrt(2.0*k/3.0); + vector dir = -gradk/(mag(gradk) + SMALL); + + // Numerical Recipes... Ch. 7. Random Numbers... + scalar x1 = 0.0; + scalar x2 = 0.0; + scalar rsq = 10.0; + while ((rsq > 1.0) || (rsq == 0.0)) + { + x1 = 2.0*rnd.sample01() - 1.0; + x2 = 2.0*rnd.sample01() - 1.0; + rsq = x1*x1 + x2*x2; + } + + scalar fac = sqrt(-2.0*log(rsq)/rsq); + + // In 2D calculations the -grad(k) is always + // away from the axis of symmetry + // This creates a 'hole' in the spray and to + // prevent this we let x1 be both negative/positive + if (this->owner().mesh().nSolutionD() == 2) + { + fac *= x1; + } + else + { + fac *= mag(x1); + } + + UTurb = sigma*fac*dir; + } + } + else + { + tTurb = GREAT; + UTurb = vector::zero; + } + + return Uc + UTurb; +} + + +// ************************************************************************* // diff --git a/src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/GradientDispersionRAS/GradientDispersionRAS.H b/src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/GradientDispersionRAS/GradientDispersionRAS.H new file mode 100644 index 00000000..b9ccfac5 --- /dev/null +++ b/src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/GradientDispersionRAS/GradientDispersionRAS.H @@ -0,0 +1,126 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2014 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 . + +Class + Foam::GradientDispersionRAS + +Description + The velocity is perturbed in the direction of -grad(k), with a + Gaussian random number distribution with variance sigma. + where sigma is defined below + +\*---------------------------------------------------------------------------*/ + +#ifndef GradientDispersionRAS_H +#define GradientDispersionRAS_H + +#include "DispersionRASModel.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class GradientDispersionRAS Declaration +\*---------------------------------------------------------------------------*/ + +template +class GradientDispersionRAS +: + public DispersionRASModel +{ +protected: + + // Protected data + + // Locally cached turbulence fields + + //- Gradient of k + const volVectorField* gradkPtr_; + + //- Take ownership of the grad(k) + bool ownGradK_; + + +public: + + //- Runtime type information + TypeName("gradientDispersionRAS"); + + + // Constructors + + //- Construct from components + GradientDispersionRAS(const dictionary& dict, CloudType& owner); + + //- Construct copy + GradientDispersionRAS(GradientDispersionRAS& dm); + + //- Construct and return a clone + virtual autoPtr > clone() + { + return autoPtr > + ( + new GradientDispersionRAS(*this) + ); + } + + + //- Destructor + virtual ~GradientDispersionRAS(); + + + // Member Functions + + //- Cache carrier fields + virtual void cacheFields(const bool store); + + //- Update (disperse particles) + virtual vector update + ( + const scalar dt, + const label cellI, + const vector& U, + const vector& Uc, + vector& UTurb, + scalar& tTurb + ); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "GradientDispersionRAS.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/StochasticDispersionRAS/StochasticDispersionRAS.C b/src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/StochasticDispersionRAS/StochasticDispersionRAS.C new file mode 100644 index 00000000..badebbc1 --- /dev/null +++ b/src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/StochasticDispersionRAS/StochasticDispersionRAS.C @@ -0,0 +1,127 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2014 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 . + +\*---------------------------------------------------------------------------*/ + +#include "StochasticDispersionRAS.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::StochasticDispersionRAS::StochasticDispersionRAS +( + const dictionary& dict, + CloudType& owner +) +: + DispersionRASModel(dict, owner) +{} + + +template +Foam::StochasticDispersionRAS::StochasticDispersionRAS +( + StochasticDispersionRAS& dm +) +: + DispersionRASModel(dm) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::StochasticDispersionRAS::~StochasticDispersionRAS() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +Foam::vector Foam::StochasticDispersionRAS::update +( + const scalar dt, + const label cellI, + const vector& U, + const vector& Uc, + vector& UTurb, + scalar& tTurb +) +{ + cachedRandom& rnd = this->owner().rndGen(); + + const scalar cps = 0.16432; + + const scalar k = this->kPtr_->internalField()[cellI]; + const scalar epsilon = + this->epsilonPtr_->internalField()[cellI] + ROOTVSMALL; + + const scalar UrelMag = mag(U - Uc - UTurb); + + const scalar tTurbLoc = + min(k/epsilon, cps*pow(k, 1.5)/epsilon/(UrelMag + SMALL)); + + + // Parcel is perturbed by the turbulence + if (dt < tTurbLoc) + { + tTurb += dt; + + if (tTurb > tTurbLoc) + { + tTurb = 0.0; + + scalar sigma = sqrt(2.0*k/3.0); + vector dir = 2.0*rnd.sample01() - vector::one; + dir /= mag(dir) + SMALL; + + // Numerical Recipes... Ch. 7. Random Numbers... + scalar x1 = 0.0; + scalar x2 = 0.0; + scalar rsq = 10.0; + while ((rsq > 1.0) || (rsq == 0.0)) + { + x1 = 2.0*rnd.sample01() - 1.0; + x2 = 2.0*rnd.sample01() - 1.0; + rsq = x1*x1 + x2*x2; + } + + scalar fac = sqrt(-2.0*log(rsq)/rsq); + + fac *= mag(x1); + + UTurb = sigma*fac*dir; + + } + } + else + { + tTurb = GREAT; + UTurb = vector::zero; + } + + return Uc + UTurb; +} + + +// ************************************************************************* // diff --git a/src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/StochasticDispersionRAS/StochasticDispersionRAS.H b/src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/StochasticDispersionRAS/StochasticDispersionRAS.H new file mode 100644 index 00000000..d1c87d04 --- /dev/null +++ b/src/lagrangian/Turbulence/submodels/Kinematic/DispersionModel/StochasticDispersionRAS/StochasticDispersionRAS.H @@ -0,0 +1,110 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2014 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 . + +Class + Foam::StochasticDispersionRAS + +Description + The velocity is perturbed in random direction, with a + Gaussian random number distribution with variance sigma. + where sigma is defined below + +\*---------------------------------------------------------------------------*/ + +#ifndef StochasticDispersionRAS_H +#define StochasticDispersionRAS_H + +#include "DispersionRASModel.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class StochasticDispersionRAS Declaration +\*---------------------------------------------------------------------------*/ + +template +class StochasticDispersionRAS +: + public DispersionRASModel +{ +public: + + //- Runtime type information + TypeName("stochasticDispersionRAS"); + + + // Constructors + + //- Construct from components + StochasticDispersionRAS(const dictionary& dict, CloudType& owner); + + //- Construct copy + StochasticDispersionRAS(StochasticDispersionRAS& dm); + + //- Construct and return a clone + virtual autoPtr > clone() + { + return autoPtr > + ( + new StochasticDispersionRAS(*this) + ); + } + + + //- Destructor + virtual ~StochasticDispersionRAS(); + + + // Member Functions + + //- Update (disperse particles) + virtual vector update + ( + const scalar dt, + const label cellI, + const vector& U, + const vector& Uc, + vector& UTurb, + scalar& tTurb + ); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "StochasticDispersionRAS.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // From 58a338955bc62e1ff05362895556c9f3eb03a73b Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 15 Apr 2014 20:22:21 +0100 Subject: [PATCH 5/5] DarcyForchheimer: Added support for phase properties --- .../DarcyForchheimer/DarcyForchheimer.C | 60 ++++++++++++++----- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimer.C b/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimer.C index 4af4c9f8..1ce0a838 100644 --- a/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimer.C +++ b/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimer.C @@ -191,26 +191,40 @@ void Foam::porosityModels::DarcyForchheimer::correct fvVectorMatrix& UEqn ) const { - const vectorField& U = UEqn.psi(); + const volVectorField& U = UEqn.psi(); const scalarField& V = mesh_.V(); scalarField& Udiag = UEqn.diag(); vectorField& Usource = UEqn.source(); + word rhoName(IOobject::groupName(rhoName_, U.group())); + word muName(IOobject::groupName(muName_, U.group())); + word nuName(IOobject::groupName(nuName_, U.group())); + if (UEqn.dimensions() == dimForce) { - const volScalarField& rho = - mesh_.lookupObject(rhoName_); - const volScalarField& mu = - mesh_.lookupObject(muName_); + const volScalarField& rho = mesh_.lookupObject(rhoName); + const volScalarField& mu = mesh_.lookupObject(muName); apply(Udiag, Usource, V, rho, mu, U); } else { - const volScalarField& nu = - mesh_.lookupObject(nuName_); + if (mesh_.foundObject(nuName)) + { + const volScalarField& nu = + mesh_.lookupObject(nuName); - apply(Udiag, Usource, V, geometricOneField(), nu, U); + apply(Udiag, Usource, V, geometricOneField(), nu, U); + } + else + { + const volScalarField& rho = + mesh_.lookupObject(rhoName); + const volScalarField& mu = + mesh_.lookupObject(muName); + + apply(Udiag, Usource, V, geometricOneField(), mu/rho, U); + } } } @@ -237,23 +251,37 @@ void Foam::porosityModels::DarcyForchheimer::correct volTensorField& AU ) const { - const vectorField& U = UEqn.psi(); + const volVectorField& U = UEqn.psi(); + + word rhoName(IOobject::groupName(rhoName_, U.group())); + word muName(IOobject::groupName(muName_, U.group())); + word nuName(IOobject::groupName(nuName_, U.group())); if (UEqn.dimensions() == dimForce) { - const volScalarField& rho = - mesh_.lookupObject(rhoName_); - const volScalarField& mu = - mesh_.lookupObject(muName_); + const volScalarField& rho = mesh_.lookupObject(rhoName); + const volScalarField& mu = mesh_.lookupObject(muName); apply(AU, rho, mu, U); } else { - const volScalarField& nu = - mesh_.lookupObject(nuName_); + if (mesh_.foundObject(nuName)) + { + const volScalarField& nu = + mesh_.lookupObject(nuName); - apply(AU, geometricOneField(), nu, U); + apply(AU, geometricOneField(), nu, U); + } + else + { + const volScalarField& rho = + mesh_.lookupObject(rhoName); + const volScalarField& mu = + mesh_.lookupObject(muName); + + apply(AU, geometricOneField(), mu/rho, U); + } } }