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 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_.empty())
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.lookupOrDefault("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 cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
104 
105  if (!cstrIter.found())
106  {
108  (
109  dict,
110  "type",
111  modelType,
112  *dictionaryConstructorTablePtr_
113  ) << exit(FatalError);
114  }
115 
116  return autoPtr<optMeshMovement>(cstrIter()(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 " << gAverage(cellNonOrtho())
162  << " " << gMax(cellNonOrtho()) << endl;
163  Info<< "Average, Max cell skewness " << gAverage(cellSkewness())
164  << " " << gMax(cellSkewness()) << endl;
165  autoPtr<volScalarField> nonOrthoPtr
166  (
167  createZeroFieldPtr<scalar>(mesh_, "nonOrtho", dimless)
168  );
169  autoPtr<volScalarField> skewnessPtr
170  (
171  createZeroFieldPtr<scalar>(mesh_, "skewness", dimless)
172  );
173  nonOrthoPtr().primitiveFieldRef() = cellNonOrtho();
174  skewnessPtr().primitiveFieldRef() = cellSkewness();
175  nonOrthoPtr().write();
176  skewnessPtr().write();
177  }
178 }
179 
180 
182 {
183  pointsInit_ = mesh_.points();
184 }
185 
186 
188 {
189  Info<< "optMeshMovement:: reseting mesh points" << endl;
190  mesh_.movePoints(pointsInit_);
191 }
192 
193 
195 {
196  return maxAllowedDisplacement_.valid();
197 }
198 
199 
201 {
203  return labelList(0);
204 }
205 
206 
207 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1038
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Definition: dimensionSets.H:50
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::optMeshMovement::getActiveDesignVariables
virtual labelList getActiveDesignVariables() const
Return active design variables.
Definition: optMeshMovement.C:200
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
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: dictionary.C:359
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:181
Foam::cellQuality::skewness
tmp< scalarField > skewness() const
Return cell skewness.
Definition: cellQuality.C:104
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::correction
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix.
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:81
Foam::dictionary::lookupOrDefault
T lookupOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.H:1241
Foam::cellQuality
Class calculates cell quality measures.
Definition: cellQuality.H:51
Foam::autoPtr::empty
bool empty() const noexcept
True if the managed pointer is null.
Definition: autoPtrI.H:100
Foam::optMeshMovement::maxAllowedDisplacementSet
bool maxAllowedDisplacementSet() const
Whether maxAllowedDisplacement has been set.
Definition: optMeshMovement.C:194
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:419
FatalIOErrorInLookup
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:380
Foam::Field< scalar >
createZeroField.H
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
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:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
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:355
Foam::optMeshMovement::moveMesh
virtual void moveMesh()
Definition: optMeshMovement.C:128
Foam::nl
constexpr char nl
Definition: Ostream.H:372
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::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
optMeshMovement.H
Foam::optMeshMovement::resetDesignVariables
virtual void resetDesignVariables()
Reset to starting point of line search.
Definition: optMeshMovement.C:187
Foam::gMax
Type gMax(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:592