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"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(optMeshMovementBezier, 0);
38  (
39  optMeshMovement,
40  optMeshMovementBezier,
41  dictionary
42  );
43 }
44 
45 
46 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
47 
49 (
50  const scalarField& correction
51 )
52 {
53  // Re-initialize movement to zero
54  dx_.primitiveFieldRef() = vector::zero;
55 
56  // Compute boundary mesh movement using derivatives of the control points
57  // and parameterization information
58  const label nBezier = Bezier_.nBezier();
59  const boolList& confineXmovement = Bezier_.confineXmovement();
60  const boolList& confineYmovement = Bezier_.confineYmovement();
61  const boolList& confineZmovement = Bezier_.confineZmovement();
62  vectorField actualMovement(nBezier, Zero);
63  for (label iCP = 0; iCP < nBezier; iCP++)
64  {
65  // Confine x movement
66  if (!confineXmovement[iCP])
67  {
68  actualMovement[iCP].x() = correction[iCP];
69  }
70  // Confine y movement
71  if (!confineYmovement[iCP])
72  {
73  actualMovement[iCP].y() = correction[iCP + nBezier];
74  }
75  // Confine z movement
76  if (!confineZmovement[iCP])
77  {
78  actualMovement[iCP].z() = correction[iCP + 2*nBezier];
79  }
80  dx_ += Bezier_.dxidXj()[iCP] & actualMovement[iCP];
81  }
82 
83  // Add to cumulative control point change (wrong in the first optimisation
84  // cycle if initial eta not set)
85  cumulativeChange_ += actualMovement;
86  Info<< "Cumulative control point change " << cumulativeChange_ << endl;
87 }
88 
89 
90 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
91 
92 Foam::optMeshMovementBezier::optMeshMovementBezier
93 (
94  fvMesh& mesh,
95  const dictionary& dict,
96  const labelList& patchIDs
97 )
98 :
99  optMeshMovement(mesh, dict, patchIDs),
100  Bezier_(mesh, mesh.lookupObject<IOdictionary>("optimisationDict")),
101  dx_
102  (
103  IOobject
104  (
105  "dx",
106  mesh_.time().timeName(),
107  mesh_,
108  IOobject::NO_READ,
109  IOobject::NO_WRITE,
110  false
111  ),
114  ),
115  cumulativeChange_(Bezier_.nBezier(), Zero)
116 {}
117 
118 
119 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120 
122 {
123  // Update the boundary movement
125 
126  // Set boundary movement of motion solver
127  displMethodPtr_->setMotionField(dx_);
128 
129  // Move the mesh and check quality
131 }
132 
133 
134 Foam::scalar
136 {
137  // Set unscaled correction
138  computeBoundaryMovement(correction);
139 
140  // Get maximum boundary movement
141  const scalar maxDisplacement = gMax(mag(dx_.primitiveField()));
142 
143  // Compute eta value
144  Info<< "maxAllowedDisplacement/maxDisplacement \t"
145  << getMaxAllowedDisplacement() << "/" << maxDisplacement << endl;
146  const scalar eta = getMaxAllowedDisplacement()/maxDisplacement;
147  Info<< "Setting eta value to " << eta << endl;
148 
149  return eta;
150 }
151 
152 
154 {
155  return Bezier_.getActiveDesignVariables();
156 }
157 
158 
159 // ************************************************************************* //
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:104
Foam::optMeshMovement::displMethodPtr_
autoPtr< displacementMethod > displMethodPtr_
Definition: optMeshMovement.H:91
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Definition: dimensionSets.H:50
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:350
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 (uses stdout - output is on the master only)
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:121
Foam::optMeshMovementBezier::computeEta
virtual scalar computeEta(const scalarField &correction)
Compute eta value based on max displacement.
Definition: optMeshMovementBezier.C:135
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
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:153
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:121
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:49
Foam::gMax
Type gMax(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:592