optMeshMovementBezier.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 "optMeshMovementBezier.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(optMeshMovementBezier, 0);
39  (
40  optMeshMovement,
41  optMeshMovementBezier,
42  dictionary
43  );
44 }
45 
46 
47 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
48 
50 (
51  const scalarField& correction
52 )
53 {
54  // Re-initialize movement to zero
56 
57  // Compute boundary mesh movement using derivatives of the control points
58  // and parameterization information
59  const label nBezier = Bezier_.nBezier();
60  const boolList& confineXmovement = Bezier_.confineXmovement();
61  const boolList& confineYmovement = Bezier_.confineYmovement();
62  const boolList& confineZmovement = Bezier_.confineZmovement();
63  vectorField actualMovement(nBezier, Zero);
64  for (label iCP = 0; iCP < nBezier; iCP++)
65  {
66  // Confine x movement
67  if (!confineXmovement[iCP])
68  {
69  actualMovement[iCP].x() = correction[iCP];
70  }
71  // Confine y movement
72  if (!confineYmovement[iCP])
73  {
74  actualMovement[iCP].y() = correction[iCP + nBezier];
75  }
76  // Confine z movement
77  if (!confineZmovement[iCP])
78  {
79  actualMovement[iCP].z() = correction[iCP + 2*nBezier];
80  }
81  dx_ += Bezier_.dxidXj()[iCP] & actualMovement[iCP];
82  }
83 
84  // Add to cumulative control point change (wrong in the first optimisation
85  // cycle if initial eta not set)
86  cumulativeChange_ += actualMovement;
87  Info<< "Cumulative control point change " << cumulativeChange_ << endl;
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
92 
93 Foam::optMeshMovementBezier::optMeshMovementBezier
94 (
95  fvMesh& mesh,
96  const dictionary& dict,
97  const labelList& patchIDs
98 )
99 :
100  optMeshMovement(mesh, dict, patchIDs),
101  Bezier_(mesh, mesh.lookupObject<IOdictionary>("optimisationDict")),
102  dx_
103  (
104  IOobject
105  (
106  "dx",
107  mesh_.time().timeName(),
108  mesh_,
109  IOobject::NO_READ,
110  IOobject::NO_WRITE,
111  false
112  ),
113  pointMesh::New(mesh),
115  ),
116  cumulativeChange_(Bezier_.nBezier(), Zero)
117 {}
118 
119 
120 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121 
123 {
124  // Update the boundary movement
125  computeBoundaryMovement(correction_);
126 
127  // Set boundary movement of motion solver
128  displMethodPtr_->setMotionField(dx_);
129 
130  // Move the mesh and check quality
132 }
133 
134 
135 Foam::scalar
137 {
138  // Set unscaled correction
139  computeBoundaryMovement(correction);
140 
141  // Get maximum boundary movement
142  const scalar maxDisplacement = gMax(mag(dx_.primitiveField()));
143 
144  // Compute eta value
145  Info<< "maxAllowedDisplacement/maxDisplacement \t"
146  << getMaxAllowedDisplacement() << "/" << maxDisplacement << endl;
147  const scalar eta = getMaxAllowedDisplacement()/maxDisplacement;
148  Info<< "Setting eta value to " << eta << endl;
149 
150  return eta;
151 }
152 
153 
155 {
156  return Bezier_.getActiveDesignVariables();
157 }
158 
159 
160 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:165
Foam::optMeshMovement::displMethodPtr_
autoPtr< displacementMethod > displMethodPtr_
Definition: optMeshMovement.H:87
Foam::Bezier::confineXmovement
const boolList & confineXmovement() const
Definition: Bezier.C:132
Foam::Zero
static constexpr const zero Zero
Definition: zero.H:131
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
Foam::correction
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Foam::Bezier::confineZmovement
const boolList & confineZmovement() const
Definition: Bezier.C:144
Foam::Bezier::dxidXj
PtrList< pointTensorField > & dxidXj()
Definition: Bezier.C:126
Foam::Bezier::nBezier
label nBezier() const
Definition: Bezier.C:120
Foam::Field
Generic templated field type.
Definition: Field.H:59
Foam::Info
messageStream Info
Foam::optMeshMovementBezier::Bezier_
Bezier Bezier_
Definition: optMeshMovementBezier.H:59
Foam::optMeshMovementBezier::dx_
pointVectorField dx_
Definition: optMeshMovementBezier.H:62
timeName
word timeName
Definition: getTimeIndex.H:3
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:119
Foam::optMeshMovementBezier::computeEta
virtual scalar computeEta(const scalarField &correction)
Definition: optMeshMovementBezier.C:129
Foam::optMeshMovementBezier::cumulativeChange_
vectorField cumulativeChange_
Definition: optMeshMovementBezier.H:65
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:36
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:81
Foam
Definition: atmBoundaryLayer.C:26
Foam::pointMesh
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:45
Foam::GeometricField::primitiveFieldRef
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Definition: GeometricField.C:759
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Definition: DimensionedFieldReuseFunctions.H:100
Foam::optMeshMovement::moveMesh
virtual void moveMesh()
Definition: optMeshMovement.C:121
Foam::optMeshMovementBezier::getActiveDesignVariables
virtual labelList getActiveDesignVariables() const
Definition: optMeshMovementBezier.C:147
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:58
optMeshMovementBezier.H
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::optMeshMovement::correction_
scalarField correction_
Definition: optMeshMovement.H:77
Foam::optMeshMovementBezier::moveMesh
void moveMesh()
Definition: optMeshMovementBezier.C:115
Foam::VectorSpace< Vector< scalar >, scalar, 3 >::zero
static const Form zero
Definition: VectorSpace.H:111
Foam::Bezier::confineYmovement
const boolList & confineYmovement() const
Definition: Bezier.C:138
Foam::optMeshMovement
Abstract base class for translating an update of the design variables into mesh movement.
Definition: optMeshMovement.H:50
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::optMeshMovementBezier::computeBoundaryMovement
void computeBoundaryMovement(const scalarField &correction)
Definition: optMeshMovementBezier.C:43
Foam::gMax
Type gMax(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:585
Foam::dimless
const dimensionSet dimless
Definition: dimensionSets.C:182