From dfa74d978cc4d41e71a03554951c634bbe41345f Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 20 Sep 2012 14:21:40 +0100 Subject: [PATCH] ENH: flowRateInletVelocity: different keywords for volumetric and mass --- applications/test/dataEntry/Make/files | 3 + applications/test/dataEntry/Make/options | 1 + applications/test/dataEntry/Test-DataEntry.C | 60 ++++- .../flowRateInletVelocityFvPatchVectorField.C | 144 ++++++++---- .../flowRateInletVelocityFvPatchVectorField.H | 35 ++- .../displacementSBRStressFvMotionSolver.C | 34 ++- .../displacementSBRStressFvMotionSolver.H | 3 +- .../autoHexMeshDriver/autoLayerDriverShrink.C | 206 +++++++++--------- .../fireFoam/les/oppositeBurningPanels/0/U | 2 +- .../rhoPimpleFoam/ras/angledDuct/0/U | 2 +- .../rhoPimplecFoam/angledDuct/0/U | 4 +- .../angledDuct/system/controlDict | 2 +- .../rhoPorousMRFLTSPimpleFoam/angledDuct/0/U | 2 +- .../angledDuctImplicit/0/U | 2 +- .../rhoSimplecFoam/squareBend/0/U | 4 +- .../squareBend/system/controlDict | 2 +- .../constant/polyMesh/blockMeshDict | 10 +- .../constant/polyMesh/boundary | 15 +- .../iglooWithFridges/system/snappyHexMeshDict | 88 ++++---- .../mixerVessel2D/constant/polyMesh/boundary | 2 + .../cavity/constant/polyMesh/blockMeshDict | 2 + .../pimpleDyMFoam/propeller/system/fvSchemes | 4 +- .../motorBike/system/decomposeParDict | 2 +- .../porousSimpleFoam/angledDuctImplicit/0/U | 3 +- .../angledDuctImplicit/system/controlDict | 2 +- .../oscillatingBox/system/controlDict | 3 +- .../turbineSiting/system/controlDict | 2 + .../verticalChannel/0.org/U | 4 +- .../LTSReactingParcelFoam/verticalChannel/0/U | 4 +- .../verticalChannel/0.org/U | 4 +- .../verticalChannel/0/U | 4 +- .../constant/triSurface/domain.stl | 2 +- .../SnakeRiverCanyon/constant/dynamicMeshDict | 1 + .../constant/polyMesh/blockMeshDict | 3 +- .../constant/polyMesh/boundary | 26 +-- .../SnakeRiverCanyon/system/controlDict | 8 +- .../snappyHexMesh/flange/system/controlDict | 2 +- .../flange/system/snappyHexMeshDict | 24 +- .../ras/sloshingTank2D/system/controlDict | 3 - .../ras/sloshingTank2D3DoF/system/controlDict | 3 - .../multiphase/interFoam/ras/waterChannel/0/U | 3 +- wmake/rules/linux64Gcc/c | 2 +- wmake/rules/linux64Gcc/c++ | 2 +- 43 files changed, 446 insertions(+), 288 deletions(-) diff --git a/applications/test/dataEntry/Make/files b/applications/test/dataEntry/Make/files index c514002f99..a88ccad3bc 100644 --- a/applications/test/dataEntry/Make/files +++ b/applications/test/dataEntry/Make/files @@ -1,3 +1,6 @@ Test-DataEntry.C +interpolationWeights.C +splineInterpolationWeights.C +linearInterpolationWeights.C EXE = $(FOAM_USER_APPBIN)/Test-DataEntry diff --git a/applications/test/dataEntry/Make/options b/applications/test/dataEntry/Make/options index a071d9557c..72cae9f645 100644 --- a/applications/test/dataEntry/Make/options +++ b/applications/test/dataEntry/Make/options @@ -1,4 +1,5 @@ EXE_INC = \ + -DFULLDEBUG -g -O0 \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/lagrangian/intermediate/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/radiationModels/lnInclude \ diff --git a/applications/test/dataEntry/Test-DataEntry.C b/applications/test/dataEntry/Test-DataEntry.C index 92761b1d01..a47a29be24 100644 --- a/applications/test/dataEntry/Test-DataEntry.C +++ b/applications/test/dataEntry/Test-DataEntry.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -32,6 +32,8 @@ Description #include "fvCFD.H" #include "DataEntry.H" #include "IOdictionary.H" +#include "linearInterpolationWeights.H" +#include "splineInterpolationWeights.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -41,6 +43,62 @@ int main(int argc, char *argv[]) # include "createTime.H" # include "createMesh.H" +{ + scalarField samples(4); + samples[0] = 0; + samples[1] = 1; + samples[2] = 2; + samples[3] = 3; + scalarField values(4); + values = 1.0; + //values[0] = 0.0; + //values[1] = 1.0; + + //linearInterpolationWeights interpolator + splineInterpolationWeights interpolator + ( + samples, + interpolationWeights::WARN + ); + labelList indices; + scalarField weights; + + interpolator.integrationWeights(1.1, 1.2, indices, weights); + Pout<< "indices:" << indices << endl; + Pout<< "weights:" << weights << endl; + + scalar baseSum = interpolator.weightedSum + ( + weights, + UIndirectList(values, indices) + ); + Pout<< "baseSum=" << baseSum << nl << nl << endl; + + +// interpolator.integrationWeights(-0.01, 0, indices, weights); +// scalar partialSum = interpolator.weightedSum +// ( +// weights, +// UIndirectList(values, indices) +// ); +// Pout<< "partialSum=" << partialSum << nl << nl << endl; +// +// +// interpolator.integrationWeights(-0.01, 1, indices, weights); +// //Pout<< "samples:" << samples << endl; +// //Pout<< "indices:" << indices << endl; +// //Pout<< "weights:" << weights << endl; +// scalar sum = interpolator.weightedSum +// ( +// weights, +// UIndirectList(values, indices) +// ); +// Pout<< "integrand=" << sum << nl << nl << endl; + + + return 1; +} + IOdictionary dataEntryProperties ( IOobject diff --git a/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.C index bbd50fa4de..9b72859c9d 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.C @@ -40,8 +40,9 @@ flowRateInletVelocityFvPatchVectorField : fixedValueFvPatchField(p, iF), flowRate_(), - phiName_("phi"), - rhoName_("rho") + volumetric_(false), + rhoName_("rho"), + rhoInlet_(0.0) {} @@ -56,8 +57,9 @@ flowRateInletVelocityFvPatchVectorField : fixedValueFvPatchField(ptf, p, iF, mapper), flowRate_(ptf.flowRate_().clone().ptr()), - phiName_(ptf.phiName_), - rhoName_(ptf.rhoName_) + volumetric_(ptf.volumetric_), + rhoName_(ptf.rhoName_), + rhoInlet_(ptf.rhoInlet_) {} @@ -69,11 +71,52 @@ flowRateInletVelocityFvPatchVectorField const dictionary& dict ) : - fixedValueFvPatchField(p, iF, dict), - flowRate_(DataEntry::New("flowRate", dict)), - phiName_(dict.lookupOrDefault("phi", "phi")), - rhoName_(dict.lookupOrDefault("rho", "rho")) -{} + fixedValueFvPatchField(p, iF), + rhoInlet_(0.0) +{ + if (dict.found("volumetricFlowRate")) + { + volumetric_ = true; + flowRate_ = DataEntry::New("volumetricFlowRate", dict); + rhoName_ = "rho"; + } + else if (dict.found("massFlowRate")) + { + volumetric_ = false; + flowRate_ = DataEntry::New("massFlowRate", dict); + rhoName_ = word(dict.lookupOrDefault("rho", "rho")); + } + else + { + FatalIOErrorIn + ( + "flowRateInletVelocityFvPatchVectorField::" + "flowRateInletVelocityFvPatchVectorField" + "(const fvPatch&, const DimensionedField&," + " const dictionary&)", + dict + ) << "Please supply either 'volumetricFlowRate' or" + << " 'massFlowRate' and 'rho'" << exit(FatalIOError); + } + + // Value field require if mass based + if (dict.found("value")) + { + fvPatchField::operator= + ( + vectorField("value", dict, p.size()) + ); + } + else if (volumetric_) + { + evaluate(Pstream::blocking); + } + else + { + rhoInlet_ = readScalar(dict.lookup("rhoInlet")); + updateCoeffs(rhoInlet_); + } +} Foam::flowRateInletVelocityFvPatchVectorField:: @@ -84,8 +127,9 @@ flowRateInletVelocityFvPatchVectorField : fixedValueFvPatchField(ptf), flowRate_(ptf.flowRate_().clone().ptr()), - phiName_(ptf.phiName_), - rhoName_(ptf.rhoName_) + volumetric_(ptf.volumetric_), + rhoName_(ptf.rhoName_), + rhoInlet_(ptf.rhoInlet_) {} @@ -98,13 +142,44 @@ flowRateInletVelocityFvPatchVectorField : fixedValueFvPatchField(ptf, iF), flowRate_(ptf.flowRate_().clone().ptr()), - phiName_(ptf.phiName_), - rhoName_(ptf.rhoName_) + volumetric_(ptf.volumetric_), + rhoName_(ptf.rhoName_), + rhoInlet_(ptf.rhoInlet_) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +void Foam::flowRateInletVelocityFvPatchVectorField::updateCoeffs +( + const scalar uniformRho +) +{ + if (updated()) + { + return; + } + + const scalar t = db().time().timeOutputValue(); + + // a simpler way of doing this would be nice + const scalar avgU = -flowRate_->value(t)/gSum(patch().magSf()); + + tmp n = patch().nf(); + + if (volumetric_ || rhoName_ == "none") + { + // volumetric flow-rate + operator==(n*avgU); + } + else + { + // mass flow-rate + operator==(n*avgU/uniformRho); + } +} + + void Foam::flowRateInletVelocityFvPatchVectorField::updateCoeffs() { if (updated()) @@ -119,40 +194,18 @@ void Foam::flowRateInletVelocityFvPatchVectorField::updateCoeffs() tmp n = patch().nf(); - const surfaceScalarField& phi = - db().lookupObject(phiName_); - - if (phi.dimensions() == dimVelocity*dimArea) + if (volumetric_ || rhoName_ == "none") { - // volumetric flow-rate + // volumetric flow-rate or density not given operator==(n*avgU); } - else if (phi.dimensions() == dimDensity*dimVelocity*dimArea) - { - if (rhoName_ == "none") - { - // volumetric flow-rate if density not given - operator==(n*avgU); - } - else - { - // mass flow-rate - const fvPatchField& rhop = - patch().lookupPatchField(rhoName_); - - operator==(n*avgU/rhop); - } - } else { - FatalErrorIn - ( - "flowRateInletVelocityFvPatchVectorField::updateCoeffs()" - ) << "dimensions of " << phiName_ << " are incorrect" << nl - << " on patch " << this->patch().name() - << " of field " << this->dimensionedInternalField().name() - << " in file " << this->dimensionedInternalField().objectPath() - << nl << exit(FatalError); + // mass flow-rate + const fvPatchField& rhop = + patch().lookupPatchField(rhoName_); + + operator==(n*avgU/rhop); } fixedValueFvPatchField::updateCoeffs(); @@ -163,8 +216,11 @@ void Foam::flowRateInletVelocityFvPatchVectorField::write(Ostream& os) const { fvPatchField::write(os); flowRate_->writeData(os); - writeEntryIfDifferent(os, "phi", "phi", phiName_); - writeEntryIfDifferent(os, "rho", "rho", rhoName_); + if (!volumetric_) + { + writeEntryIfDifferent(os, "rho", "rho", rhoName_); + os.writeKeyword("rhoInlet") << rhoInlet_ << token::END_STATEMENT << nl; + } writeEntry("value", os); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.H b/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.H index a4b48c7629..192e14b7d1 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.H @@ -28,21 +28,25 @@ Description Describes a volumetric/mass flow normal vector boundary condition by its magnitude as an integral over its area. - The basis of the patch (volumetric or mass) is determined by the - dimensions of the flux, phi. - - If the flux is mass-based - - the current density is used to correct the velocity - - volumetric flow rate can be applied by setting the 'rho' entry to 'none' + Either specify 'volumetricFlowRate' or 'massFlowRate' (requires additional + 'rho' entry). Example of the boundary condition specification: \verbatim inlet { - type flowRateInletVelocity; - flowRate 0.2; // Volumetric/mass flow rate [m3/s or kg/s] - rho rho; // none | rho [m3/s or kg/s] - value uniform (0 0 0); // placeholder + type flowRateInletVelocity; + volumetricFlowRate 0.2; // Volumetric [m3/s] + } + \endverbatim + + \verbatim + inlet + { + type flowRateInletVelocity; + volumetricFlowRate 0.2; // mass flow rate [kg/s] + rho rho; // rho [m3/s or kg/s] + value uniform (0 0 0); // placeholder } \endverbatim @@ -79,12 +83,15 @@ class flowRateInletVelocityFvPatchVectorField //- Inlet integral flow rate autoPtr > flowRate_; - //- Name of the flux transporting the field - word phiName_; + //- Is volumetric? + bool volumetric_; //- Name of the density field used to normalize the mass flux word rhoName_; + //- Rho initialisation value (for start; if value not supplied) + scalar rhoInlet_; + public: @@ -157,6 +164,10 @@ public: // Member functions + //- Update the coefficients associated with the patch field given + // uniform density field + void updateCoeffs(const scalar uniformRho); + //- Update the coefficients associated with the patch field virtual void updateCoeffs(); diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C b/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C index 04edda45ee..2b5e23e9a9 100644 --- a/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C @@ -81,8 +81,14 @@ Foam::displacementSBRStressFvMotionSolver::displacementSBRStressFvMotionSolver diffusivityPtr_ ( motionDiffusivity::New(fvMesh_, coeffDict().lookup("diffusivity")) - ) -{} + ), + solveOnPoints0_(coeffDict().lookupOrDefault("solveOnPoints0", false)) +{ + if (solveOnPoints0_) + { + Info<< type() << " : solving on points0" << endl; + } +} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // @@ -123,11 +129,18 @@ void Foam::displacementSBRStressFvMotionSolver::solve() diffusivityPtr_->correct(); pointDisplacement_.boundaryField().updateCoeffs(); + pointField oldPoints; + if (solveOnPoints0_) + { + oldPoints = fvMesh_.points(); + movePoints(points0()); + } + surfaceScalarField Df(diffusivityPtr_->operator()()); volTensorField gradCd(fvc::grad(cellDisplacement_)); - Foam::solve + tmp > laplacianDf ( fvm::laplacian ( @@ -135,7 +148,16 @@ void Foam::displacementSBRStressFvMotionSolver::solve() cellDisplacement_, "laplacian(diffusivity,cellDisplacement)" ) + ); +// if (solveOnPoints0_) +// { +// movePoints(oldPoints); +// } + + Foam::solve + ( + laplacianDf + fvc::div ( Df @@ -173,6 +195,12 @@ void Foam::displacementSBRStressFvMotionSolver::solve() ) */ ); + + if (solveOnPoints0_) + { + movePoints(points0()); + } + } diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.H b/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.H index db98e1a7cc..4d68cfc421 100644 --- a/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.H +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.H @@ -53,7 +53,6 @@ class motionDiffusivity; class displacementSBRStressFvMotionSolver : -// public displacementFvMotionSolver public displacementMotionSolver, public fvMotionSolverCore { @@ -65,6 +64,8 @@ class displacementSBRStressFvMotionSolver //- Diffusivity used to control the motion autoPtr diffusivityPtr_; + //- Solve on base mesh + Switch solveOnPoints0_; // Private Member Functions diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriverShrink.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriverShrink.C index 58725470e1..db246ba1f2 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriverShrink.C +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriverShrink.C @@ -99,76 +99,6 @@ void Foam::autoLayerDriver::sumWeights // Smooth field on moving patch -//void Foam::autoLayerDriver::smoothField -//( -// const motionSmoother& meshMover, -// const PackedBoolList& isMasterEdge, -// const labelList& meshEdges, -// const scalarField& fieldMin, -// const label nSmoothDisp, -// scalarField& field -//) const -//{ -// const indirectPrimitivePatch& pp = meshMover.patch(); -// const edgeList& edges = pp.edges(); -// const labelList& meshPoints = pp.meshPoints(); -// -// scalarField invSumWeight(pp.nPoints()); -// sumWeights -// ( -// isMasterEdge, -// meshEdges, -// meshPoints, -// edges, -// invSumWeight -// ); -// -// // Get smoothly varying patch field. -// Info<< "shrinkMeshDistance : Smoothing field ..." << endl; -// -// for (label iter = 0; iter < nSmoothDisp; iter++) -// { -// scalarField average(pp.nPoints()); -// averageNeighbours -// ( -// meshMover.mesh(), -// isMasterEdge, -// meshEdges, -// meshPoints, -// pp.edges(), -// invSumWeight, -// field, -// average -// ); -// -// // Transfer to field -// forAll(field, pointI) -// { -// //full smoothing neighbours + point value -// average[pointI] = 0.5*(field[pointI]+average[pointI]); -// -// // perform monotonic smoothing -// if -// ( -// average[pointI] < field[pointI] -// && average[pointI] >= fieldMin[pointI] -// ) -// { -// field[pointI] = average[pointI]; -// } -// } -// -// // Do residual calculation every so often. -// if ((iter % 10) == 0) -// { -// Info<< " Iteration " << iter << " residual " -// << gSum(mag(field-average)) -// /returnReduce(average.size(), sumOp