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
55  dx_.primitiveFieldRef() = vector::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 :
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  IOobject::NO_REGISTER
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_);
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 // ************************************************************************* //
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix by subtracting the matrix multiplied by the current fi...
dictionary dict
const labelList patchIDs(pbm.patchSet(polyPatchNames, false, true).sortedToc())
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
Abstract base class for translating an update of the design variables into mesh movement.
pointVectorField dx_
Boundary movement due to change of NURBS control points.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
const boolList & confineXmovement() const
Confine x movement.
Definition: Bezier.C:132
const dimensionSet dimless
Dimensionless.
virtual scalar computeEta(const scalarField &correction)
Compute eta value based on max displacement.
Macros for easy insertion into run-time selection tables.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:45
word timeName
Definition: getTimeIndex.H:3
dynamicFvMesh & mesh
vectorField cumulativeChange_
Cumulative change of control points.
virtual labelList getActiveDesignVariables() const
Return active design variables.
label nBezier() const
Number of Bezier control points.
Definition: Bezier.C:120
void moveMesh()
Calculates surface mesh movement.
Type gMax(const FieldField< Field, Type > &f)
defineTypeNameAndDebug(combustionModel, 0)
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
const boolList & confineYmovement() const
Confine y movement.
Definition: Bezier.C:138
Bezier Bezier_
Parameterization based on NURBS curves.
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field values.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:79
void computeBoundaryMovement(const scalarField &correction)
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual void moveMesh()
Calculates mesh movemnt based on the correction of the design variables.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:171
Namespace for OpenFOAM.
const boolList & confineZmovement() const
Confine z movement.
Definition: Bezier.C:144
PtrList< pointTensorField > & dxidXj()
dx/db tensor for all control points
Definition: Bezier.C:126
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:133