cellSizeFunction.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2012-2017 OpenFOAM Foundation
9 Copyright (C) 2019-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "cellSizeFunction.H"
31
32// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33
34namespace Foam
35{
36 defineTypeNameAndDebug(cellSizeFunction, 0);
37 defineRunTimeSelectionTable(cellSizeFunction, dictionary);
38}
39
41
42
43// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44
46(
47 const word& type,
48 const dictionary& cellSizeFunctionDict,
49 const searchableSurface& surface,
50 const scalar& defaultCellSize,
51 const labelList regionIndices
52)
53:
54 dictionary(cellSizeFunctionDict),
55 surface_(surface),
56 surfaceCellSizeFunction_
57 (
58 surfaceCellSizeFunction::New
59 (
60 cellSizeFunctionDict,
61 surface,
62 defaultCellSize
63 )
64 ),
65 coeffsDict_(optionalSubDict(type + "Coeffs")),
66 defaultCellSize_(defaultCellSize),
67 regionIndices_(regionIndices),
68 sideMode_(),
69 priority_
70 (
71 cellSizeFunctionDict.get<label>("priority", keyType::REGEX_RECURSIVE)
72 )
73{
74 const word mode =
75 cellSizeFunctionDict.get<word>("mode", keyType::REGEX_RECURSIVE);
76
77 if (surface_.hasVolumeType())
78 {
79 if (mode == "inside")
80 {
81 sideMode_ = smInside;
82 }
83 else if (mode == "outside")
84 {
85 sideMode_ = smOutside;
86 }
87 else if (mode == "bothSides")
88 {
89 sideMode_ = rmBothsides;
90 }
91 else
92 {
94 << "Unknown mode, expected: inside, outside or bothSides" << nl
95 << exit(FatalError);
96 }
97 }
98 else
99 {
100 if (mode != "bothSides")
101 {
103 << "surface does not support volumeType, defaulting mode to "
104 << "bothSides."
105 << endl;
106 }
107
108 sideMode_ = rmBothsides;
109 }
110
111 if (debug)
112 {
113 Info<< nl
114 << "Cell size function for surface " << surface.name()
115 << ", " << mode
116 << ", priority = " << priority_
117 << ", regions = " << regionIndices_
118 << endl;
119 }
120}
121
122
123// * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
124
126(
127 const dictionary& dict,
128 const searchableSurface& surface,
129 const scalar& defaultCellSize,
130 const labelList regionIndices
131)
132{
133 const word modelType(dict.get<word>("cellSizeFunction"));
134
135 Info<< indent << "Selecting cellSizeFunction " << modelType << endl;
136
137 auto* ctorPtr = dictionaryConstructorTable(modelType);
138
139 if (!ctorPtr)
140 {
142 (
143 dict,
144 "cellSizeFunction",
145 modelType,
146 *dictionaryConstructorTablePtr_
147 ) << exit(FatalIOError);
148 }
149
150 return autoPtr<cellSizeFunction>
151 (
152 ctorPtr
153 (
154 dict,
155 surface,
156 defaultCellSize,
157 regionIndices
158 )
159 );
160}
161
162
163// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
164
166{}
167
168
169// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Abstract base class for specifying target cell sizes.
static scalar snapToSurfaceTol_
Point closeness tolerance to a surface where the function "snaps" to.
virtual ~cellSizeFunction()
Destructor.
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:478
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
#define WarningInFunction
Report a warning using Foam::Warning.
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
const wordList surface
Standard surface field types (scalar, vector, tensor, etc)
type
Types of root.
Definition: Roots.H:55
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
Definition: MSwindows.C:572
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:342
IOerror FatalIOError
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
dictionary dict
volScalarField & e
Definition: createFields.H:11