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 -------------------------------------------------------------------------------
12 License
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 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(optMeshMovement, 0);
39  defineRunTimeSelectionTable(optMeshMovement, dictionary);
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 
60 Foam::optMeshMovement::optMeshMovement
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 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1069
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::optMeshMovement::getActiveDesignVariables
virtual labelList getActiveDesignVariables() const
Return active design variables.
Definition: optMeshMovement.C:201
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::dictionary::found
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
Foam::gAverage
Type gAverage(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:604
Foam::optMeshMovement::getPatchIDs
const labelList & getPatchIDs()
Return patchIDs.
Definition: optMeshMovement.C:148
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Foam::optMeshMovement::New
static autoPtr< optMeshMovement > New(fvMesh &mesh, const dictionary &dict, const labelList &patchIDs)
Definition: optMeshMovement.C:93
Foam::cellQuality::nonOrthogonality
tmp< scalarField > nonOrthogonality() const
Return cell non-orthogonality.
Definition: cellQuality.C:42
Foam::optMeshMovement::storeDesignVariables
virtual void storeDesignVariables()
Definition: optMeshMovement.C:182
Foam::cellQuality::skewness
tmp< scalarField > skewness() const
Return cell skewness.
Definition: cellQuality.C:104
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::correction
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
Foam::cellQuality
Class calculates cell quality measures.
Definition: cellQuality.H:51
Foam::optMeshMovement::maxAllowedDisplacementSet
bool maxAllowedDisplacementSet() const
Whether maxAllowedDisplacement has been set.
Definition: optMeshMovement.C:195
Foam::optMeshMovement::returnDisplacementMethod
autoPtr< displacementMethod > & returnDisplacementMethod()
Return displacementMethod.
Definition: optMeshMovement.C:142
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
FatalIOErrorInLookup
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:478
Foam::Field< scalar >
createZeroField.H
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
cellQuality.H
Foam::autoPtr< Foam::optMeshMovement >
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::optMeshMovement::moveMesh
virtual void moveMesh()
Definition: optMeshMovement.C:128
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::List< label >
Foam::optMeshMovement::setCorrection
void setCorrection(const scalarField &correction)
Set design variable correction.
Definition: optMeshMovement.C:122
Foam::optMeshMovement::getMaxAllowedDisplacement
scalar getMaxAllowedDisplacement() const
Get maxAllowedDisplacement, is set.
Definition: optMeshMovement.C:45
Foam::displacementMethod::New
static autoPtr< displacementMethod > New(fvMesh &mesh, const labelList &patchIDs)
Return a reference to the selected turbulence model.
Definition: displacementMethod.C:59
Foam::optMeshMovement::writeMeshQualityMetrics
void writeMeshQualityMetrics()
Write mesh quality metrics.
Definition: optMeshMovement.C:154
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:148
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
optMeshMovement.H
Foam::optMeshMovement::resetDesignVariables
virtual void resetDesignVariables()
Reset to starting point of line search.
Definition: optMeshMovement.C:188
Foam::gMax
Type gMax(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:592
Foam::dimless
const dimensionSet dimless
Dimensionless.
Definition: dimensionSets.C:189