optMeshMovement.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) 2007-2019 PCOpt/NTUA
9 Copyright (C) 2013-2019 FOSS GP
10 Copyright (C) 2019-2021 OpenCFD Ltd.
11-------------------------------------------------------------------------------
12License
13 This file is part of OpenFOAM.
14
15 OpenFOAM is free software: you can redistribute it and/or modify it
16 under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 3 of the License, or
18 (at your option) any later version.
19
20 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27
28\*---------------------------------------------------------------------------*/
29
30#include "optMeshMovement.H"
31#include "cellQuality.H"
32#include "createZeroField.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
40}
41
42
43// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
44
46{
47 if (!maxAllowedDisplacement_)
48 {
50 << "maxAllowedDisplacement requested but not set" << nl
51 << exit(FatalError);
52 }
53
54 return maxAllowedDisplacement_();
55}
56
57
58// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
59
61(
62 fvMesh& mesh,
63 const dictionary& dict,
64 const labelList& patchIDs
65)
66:
67 maxAllowedDisplacement_(nullptr),
68 mesh_(mesh),
69 dict_(dict),
70 correction_(0),
71 patchIDs_(patchIDs),
72 pointsInit_(mesh.points()),
73 displMethodPtr_(displacementMethod::New(mesh_, patchIDs_)),
74 writeMeshQualityMetrics_
75 (
76 dict.getOrDefault("writeMeshQualityMetrics", false)
77 )
78{
79 // Set maxAllowedDisplacement if provided
80 if (dict.found("maxAllowedDisplacement"))
81 {
82 maxAllowedDisplacement_.reset
83 (
84 new scalar(dict.get<scalar>("maxAllowedDisplacement"))
85 );
86 }
87}
88
89
90// * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
91
93(
94 fvMesh& mesh,
95 const dictionary& dict,
96 const labelList& patchIDs
97)
98{
99 const word modelType(dict.get<word>("type"));
100
101 Info<< "optMeshMovement type : " << modelType << endl;
102
103 auto* ctorPtr = dictionaryConstructorTable(modelType);
104
105 if (!ctorPtr)
106 {
108 (
109 dict,
110 "type",
111 modelType,
112 *dictionaryConstructorTablePtr_
113 ) << exit(FatalIOError);
114 }
115
116 return autoPtr<optMeshMovement>(ctorPtr(mesh, dict, patchIDs));
117}
118
119
120// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * //
121
123{
124 correction_ = correction;
125}
126
127
129{
130 // Move mesh
131 displMethodPtr_->update();
132
133 // Check mesh quality
134 mesh_.checkMesh(true);
135
136 // If needed, plot mesh quality metrics
137 writeMeshQualityMetrics();
138}
139
140
143{
144 return displMethodPtr_;
145}
146
147
149{
150 return patchIDs_;
151}
152
153
155{
156 if (writeMeshQualityMetrics_)
157 {
158 cellQuality cellQualityEngine(mesh_);
159 tmp<scalarField> cellNonOrtho(cellQualityEngine.nonOrthogonality());
160 tmp<scalarField> cellSkewness(cellQualityEngine.skewness());
161 Info<< "Average, Max cell non - orthogonality "
162 << gAverage(cellNonOrtho())
163 << " " << gMax(cellNonOrtho()) << endl;
164 Info<< "Average, Max cell skewness " << gAverage(cellSkewness())
165 << " " << gMax(cellSkewness()) << endl;
166 autoPtr<volScalarField> nonOrthoPtr
167 (
168 createZeroFieldPtr<scalar>(mesh_, "nonOrtho", dimless)
169 );
170 autoPtr<volScalarField> skewnessPtr
171 (
172 createZeroFieldPtr<scalar>(mesh_, "skewness", dimless)
173 );
174 nonOrthoPtr().primitiveFieldRef() = cellNonOrtho();
175 skewnessPtr().primitiveFieldRef() = cellSkewness();
176 nonOrthoPtr().write();
177 skewnessPtr().write();
178 }
179}
180
181
183{
184 pointsInit_ = mesh_.points();
185}
186
187
189{
190 Info<< "optMeshMovement:: resetting mesh points" << endl;
191 mesh_.movePoints(pointsInit_);
192}
193
194
196{
197 return maxAllowedDisplacement_.valid();
198}
199
200
202{
204 return labelList(0);
205}
206
207
208// ************************************************************************* //
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
void reset(autoPtr< T > &&other) noexcept
Delete managed object and set to new given pointer.
Definition: autoPtrI.H:117
Class calculates cell quality measures.
Definition: cellQuality.H:52
tmp< scalarField > nonOrthogonality() const
Return cell non-orthogonality.
Definition: cellQuality.C:42
tmp< scalarField > skewness() const
Return cell skewness.
Definition: cellQuality.C:104
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
Abstract base class for displacement methods, which are a set or wrapper classes allowing to change t...
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
Abstract base class for translating an update of the design variables into mesh movement.
virtual void resetDesignVariables()
Reset to starting point of line search.
void setCorrection(const scalarField &correction)
Set design variable correction.
virtual void moveMesh()
virtual labelList getActiveDesignVariables() const
Return active design variables.
const labelList & getPatchIDs()
Return patchIDs.
bool maxAllowedDisplacementSet() const
Whether maxAllowedDisplacement has been set.
scalar getMaxAllowedDisplacement() const
Get maxAllowedDisplacement, is set.
void writeMeshQualityMetrics()
Write mesh quality metrics.
autoPtr< displacementMethod > & returnDisplacementMethod()
Return displacementMethod.
virtual void storeDesignVariables()
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:478
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const pointField & points
Namespace for OpenFOAM.
const dimensionSet dimless
Dimensionless.
List< label > labelList
A List of labels.
Definition: List.H:66
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
IOerror FatalIOError
Type gAverage(const FieldField< Field, Type > &f)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Type gMax(const FieldField< Field, Type > &f)
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
dictionary dict