ENH: support relative expansion for PDRblockMesh (#1655)

This commit is contained in:
Mark Olesen
2020-03-31 16:59:53 +02:00
parent 9b1c0786ce
commit 95f14621de
2 changed files with 118 additions and 41 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -29,6 +29,25 @@ License
#include "ListOps.H" #include "ListOps.H"
#include "emptyPolyPatch.H" #include "emptyPolyPatch.H"
// Output when verbosity is enabled
#undef Log
#define Log if (verbose_) Info
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::Enum
<
Foam::PDRblock::expansionType
>
Foam::PDRblock::expansionNames_
({
{ expansionType::EXPAND_UNIFORM, "uniform" },
{ expansionType::EXPAND_RATIO, "ratio" },
{ expansionType::EXPAND_RELATIVE, "relative"}
});
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam namespace Foam
@ -38,7 +57,18 @@ namespace Foam
{ {
return nDiv > 1 ? pow(expRatio, 1.0/(nDiv - 1)) : 0.0; return nDiv > 1 ? pow(expRatio, 1.0/(nDiv - 1)) : 0.0;
} }
}
//- Calculate geometric ratio from relative ratio
inline scalar relativeToGeometricRatio
(
const scalar expRatio,
const label nDiv
)
{
return nDiv > 1 ? pow(expRatio, (nDiv - 1)) : 1.0;
}
} // End namespace Foam
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
@ -132,7 +162,8 @@ void Foam::PDRblock::readGridControl
( (
const direction cmpt, const direction cmpt,
const dictionary& dict, const dictionary& dict,
const scalar scaleFactor const scalar scaleFactor,
expansionType expandType
) )
{ {
//- The begin/end nodes for each segment //- The begin/end nodes for each segment
@ -144,11 +175,8 @@ void Foam::PDRblock::readGridControl
// The expansion ratio per segment // The expansion ratio per segment
scalarList expansion; scalarList expansion;
if (verbose_) Log << "Reading grid control for "
{ << vector::componentNames[cmpt] << " direction" << nl;
Info<< "Reading grid control for "
<< vector::componentNames[cmpt] << " direction" << nl;
}
// Points // Points
// ~~~~~~ // ~~~~~~
@ -178,10 +206,7 @@ void Foam::PDRblock::readGridControl
// Do points increase monotonically? // Do points increase monotonically?
checkMonotonic(cmpt, knots); checkMonotonic(cmpt, knots);
if (verbose_) Log << " points : " << flatOutput(knots) << nl;
{
Info<< " points : " << flatOutput(knots) << nl;
}
// Divisions // Divisions
@ -221,11 +246,7 @@ void Foam::PDRblock::readGridControl
<< exit(FatalIOError); << exit(FatalIOError);
} }
Log << " nCells : " << flatOutput(divisions) << nl;
if (verbose_)
{
Info<< " nCells : " << flatOutput(divisions) << nl;
}
// Expansion ratios // Expansion ratios
@ -242,7 +263,7 @@ void Foam::PDRblock::readGridControl
} }
} }
if (expansion.size() && expansion.size() != nSegments) if (expansion.size() && divisions.size() != expansion.size())
{ {
FatalIOErrorInFunction(dict) FatalIOErrorInFunction(dict)
<< "Mismatch in number of expansion ratios and divisions:" << "Mismatch in number of expansion ratios and divisions:"
@ -255,22 +276,48 @@ void Foam::PDRblock::readGridControl
{ {
expansion.resize(nSegments, scalar(1)); expansion.resize(nSegments, scalar(1));
if (verbose_) if (expandType != expansionType::EXPAND_UNIFORM)
{ {
Info<< "Warning: 'ratios' not specified, using constant spacing" expandType = expansionType::EXPAND_UNIFORM;
<< nl;
Log << "Warning: no 'ratios', use uniform spacing" << nl;
} }
} }
else else
{ {
if (verbose_) switch (expandType)
{ {
Info<< " ratios : " << flatOutput(expansion) << nl; case expansionType::EXPAND_UNIFORM:
{
expansion = scalar(1);
break;
}
case expansionType::EXPAND_RATIO:
{
Log << " ratios : " << flatOutput(expansion) << nl;
break;
}
case expansionType::EXPAND_RELATIVE:
{
Log << " relative : " << flatOutput(expansion) << nl;
auto divIter = divisions.cbegin();
for (scalar& expRatio : expansion)
{
expRatio = relativeToGeometricRatio(expRatio, *divIter);
++divIter;
}
Log << " ratios : " << flatOutput(expansion) << nl;
break;
}
} }
} }
// Define the grid points // Define the grid points
scalarList& gridPoint = grid_[cmpt]; scalarList& gridPoint = grid_[cmpt];
@ -291,7 +338,11 @@ void Foam::PDRblock::readGridControl
const scalar dist = (subPoint.last() - subPoint.first()); const scalar dist = (subPoint.last() - subPoint.first());
if (equal(expRatio, 1)) if
(
expandType == expansionType::EXPAND_UNIFORM
|| equal(expRatio, 1)
)
{ {
for (label i=1; i < nDiv; ++i) for (label i=1; i < nDiv; ++i)
{ {
@ -318,10 +369,7 @@ void Foam::PDRblock::readGridControl
void Foam::PDRblock::readBoundary(const dictionary& dict) void Foam::PDRblock::readBoundary(const dictionary& dict)
{ {
if (verbose_) Log << "Reading boundary entries" << nl;
{
Info<< "Reading boundary entries" << nl;
}
PtrList<entry> patchEntries; PtrList<entry> patchEntries;
@ -507,12 +555,21 @@ Foam::PDRblock::PDRblock(const dictionary& dict, bool verbose)
bool Foam::PDRblock::read(const dictionary& dict) bool Foam::PDRblock::read(const dictionary& dict)
{ {
// Mark no scaling with invalid value const scalar scaleFactor(dict.getOrDefault<scalar>("scale", -1));
const scalar scaleFactor = dict.lookupOrDefault<scalar>("scale", -1);
readGridControl(0, dict.subDict("x"), scaleFactor); expansionType expandType
readGridControl(1, dict.subDict("y"), scaleFactor); (
readGridControl(2, dict.subDict("z"), scaleFactor); expansionNames_.getOrDefault
(
"expansion",
dict,
expansionType::EXPAND_RATIO
)
);
readGridControl(0, dict.subDict("x"), scaleFactor, expandType);
readGridControl(1, dict.subDict("y"), scaleFactor, expandType);
readGridControl(2, dict.subDict("z"), scaleFactor, expandType);
adjustSizes(); adjustSizes();

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -40,6 +40,7 @@ Description
y | Y-direction grid specification | yes | y | Y-direction grid specification | yes |
z | Z-direction grid specification | yes | z | Z-direction grid specification | yes |
scale | Point scaling | no | 1.0 scale | Point scaling | no | 1.0
expansion | Type of expansion (ratio/relative) | no | ratio
boundary | Boundary patches | yes | boundary | Boundary patches | yes |
defaultPatch | Default patch specification | no | defaultPatch | Default patch specification | no |
\endtable \endtable
@ -49,12 +50,13 @@ Description
Property| Description | Required | Default Property| Description | Required | Default
points | Locations defining the mesh segment | yes | points | Locations defining the mesh segment | yes |
nCells | Divisions per mesh segment | yes | nCells | Divisions per mesh segment | yes |
ratios | Expansion ratio (end/start) per segment | no | uniform ratios | Expansion values per segment | no |
\endtable \endtable
The expansion ratios are defined as per blockMesh and represent the ratio A negative expansion value is trapped and treated as its reciprocal.
of end-size / start-size for the section. A negative value is trapped by default, the expansion is as per blockMesh and represents the ratio
and treated as its reciprocal. of end-size / start-size for the section.
Alternatively, the relative size can be given.
SourceFiles SourceFiles
PDRblockI.H PDRblockI.H
@ -70,6 +72,7 @@ SourceFiles
#include "boundBox.H" #include "boundBox.H"
#include "pointField.H" #include "pointField.H"
#include "faceList.H" #include "faceList.H"
#include "Enum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -88,9 +91,19 @@ class PDRblock
: :
public ijkMesh public ijkMesh
{ {
public: public:
// Data Types
//- The expansion type
enum expansionType
{
EXPAND_UNIFORM, //!< Uniform expansion (ie, no expansion)
EXPAND_RATIO, //!< End/start ratio
EXPAND_RELATIVE //!< Relative expansion ratio
};
// Public Classes // Public Classes
//- Grid locations in an axis direction. //- Grid locations in an axis direction.
@ -151,6 +164,12 @@ public:
private: private:
// Data Types
//- Named enumerations for the expansion type
const static Enum<expansionType> expansionNames_;
// Private Classes // Private Classes
//- Extracted patch settings //- Extracted patch settings
@ -205,7 +224,8 @@ private:
( (
const direction cmpt, const direction cmpt,
const dictionary& dict, const dictionary& dict,
const scalar scaleFactor = -1 const scalar scaleFactor = -1,
expansionType expandType = expansionType::EXPAND_RATIO
); );
//- Read "boundary" information //- Read "boundary" information