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 :
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  ),
115  ),
116  cumulativeChange_(Bezier_.nBezier(), Zero)
117 {}
118 
119 
120 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121 
123 {
124  // Update the boundary movement
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:54
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::optMeshMovement::displMethodPtr_
autoPtr< displacementMethod > displMethodPtr_
Definition: optMeshMovement.H:91
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
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::dimensionedVector
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
Definition: dimensionedVector.H:50
Foam::Field< scalar >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::optMeshMovementBezier::dx_
pointVectorField dx_
Boundary movement due to change of NURBS control points.
Definition: optMeshMovementBezier.H:66
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:123
Foam::optMeshMovementBezier::computeEta
virtual scalar computeEta(const scalarField &correction)
Compute eta value based on max displacement.
Definition: optMeshMovementBezier.C:136
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::optMeshMovement::moveMesh
virtual void moveMesh()
Definition: optMeshMovement.C:128
Foam::optMeshMovementBezier::getActiveDesignVariables
virtual labelList getActiveDesignVariables() const
Return active design variables.
Definition: optMeshMovementBezier.C:154
Foam::List< bool >
optMeshMovementBezier.H
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::optMeshMovement::correction_
scalarField correction_
Correction of design variables.
Definition: optMeshMovement.H:81
Foam::optMeshMovementBezier::moveMesh
void moveMesh()
Calculates surface mesh movement.
Definition: optMeshMovementBezier.C:122
Foam::optMeshMovement
Abstract base class for translating an update of the design variables into mesh movement.
Definition: optMeshMovement.H:54
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::optMeshMovementBezier::computeBoundaryMovement
void computeBoundaryMovement(const scalarField &correction)
Definition: optMeshMovementBezier.C:50
Foam::gMax
Type gMax(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:592
Foam::dimless
const dimensionSet dimless
Dimensionless.
Definition: dimensionSets.C:189