morphingBoxConstraint.H
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) 2021-2023 PCOpt/NTUA
9  Copyright (C) 2021-2023 FOSS GP
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::morphingBoxConstraint
29 
30 Description
31  Abstract base class for defining constraints for the control points of
32  volumetric B-Splines morphing boxes
33 
34 SourceFiles
35  morphingBoxConstraint.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef morphingBoxConstraint_H
40 #define morphingBoxConstraint_H
41 
42 #include "volBSplinesBase.H"
43 #include "runTimeSelectionTables.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // Forward declaration
51 class volumetricBSplinesDesignVariables;
52 
53 /*---------------------------------------------------------------------------*\
54  Class morphingBoxConstraint Declaration
55 \*---------------------------------------------------------------------------*/
56 
58 {
59 protected:
60 
61  // Protected data
62 
63  //- Mesh reference
64  const fvMesh& mesh_;
65 
66  //- Volumetric B-Splines variables dict
67  const dictionary dict_;
68 
69  //- Reference to underlaying volumetric B-Splines morpher
71 
72  //- Easy access to the volBSplinesBase resting in the designVariables_
74 
75  //- Initial CPs stored in scalarField
77 
78  //- Initialise the design variables
79  bool initialiseVars_;
80 
81  //- Folder holding the twist sensitivities
83 
84 
85  // Protected Member Functions
86 
87  //- Compute sensitivities wrt the design variables (chain rule)
88  void virtual computeDVsSensitivities
89  (
90  scalarField& dvSens,
91  const scalarField& cpSens
92  ) = 0;
93 
94  //- Write sensitivities w.r.t. the design variables
95  void virtual writeDVSensitivities
96  (
97  const scalarField& sens,
98  const word& name
99  );
100 
101 
102 private:
103 
104  // Private Member Functions
105 
106  //- Disallow default bitwise copy construct
108 
109  //- Disallow default bitwise assignment
110  void operator=(const morphingBoxConstraint&) = delete;
111 
112 
113 public:
114 
115  //- Runtime type information
116  TypeName("morphingBoxConstraint");
117 
118 
119  // Declare run-time constructor selection table
120 
122  (
123  autoPtr,
125  dictionary,
126  (
127  const fvMesh& mesh,
128  const dictionary& dict,
130  ),
132  );
133 
134 
135  // Constructors
136 
137  //- Construct from components
139  (
140  const fvMesh& mesh,
141  const dictionary& dict,
143  );
144 
145 
146  // Selectors
147 
148  //- Construct and return the selected morphingBoxConstraint
150  (
151  const fvMesh& mesh,
152  const dictionary& dict,
154  );
155 
156 
157  //- Destructor
158  virtual ~morphingBoxConstraint() = default;
159 
160 
161  // Member Functions
162 
163  //- Compute the active design variables based on the IDs of the
164  //- active control point coordinates
166  (
167  const labelList& activeCPCoors
168  ) = 0;
169 
170  //- Transform bounds from control points to design variables
171  // WIP
172  virtual void computeBounds
173  (
174  autoPtr<scalarField>& lowerBounds,
175  autoPtr<scalarField>& upperBounds
176  );
177 
178  //- Update the bounds of the design variables
179  // WIP
180  virtual void updateBounds
181  (
182  autoPtr<scalarField>& lowerBounds,
183  autoPtr<scalarField>& upperBounds
184  );
185 
186  //- Convert design variables to control points, stored in a scalarField
188  (
190  ) = 0;
191 
192  //- Return the design variables corresponding to the given control
193  //- points
195  (
196  const scalarField& cps
197  ) = 0;
198 
199  //- Convert the correction of the design variables to the correction of
200  //- the control points
202  (
203  const scalarField& correction
204  ) = 0;
205 
206  //- Chain rule from control points to design variables
208  (
209  const scalarField& controlPointSens,
210  const word& adjointSolverName
211  );
212 
213  //- Compute eta if not set in the first step
214  virtual scalar computeEta
215  (
217  const scalar maxInitChange
218  );
219 
220  //- Initialise the design variables?
221  inline bool initialiseVars() const
222  {
223  return initialiseVars_;
224  }
225 
226  //- Append useful information to the design variables IOdictionary
227  virtual bool writeData(Ostream& os) const;
228 };
229 
230 
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 
233 } // End namespace Foam
234 
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 
237 #endif
238 
239 // ************************************************************************* //
virtual labelList computeActiveDesignVariables(const labelList &activeCPCoors)=0
Compute the active design variables based on the IDs of the active control point coordinates.
virtual scalar computeEta(scalarField &correction, const scalar maxInitChange)
Compute eta if not set in the first step.
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
A class for handling file names.
Definition: fileName.H:72
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
const fvMesh & mesh_
Mesh reference.
declareRunTimeSelectionTable(autoPtr, morphingBoxConstraint, dictionary,(const fvMesh &mesh, const dictionary &dict, volumetricBSplinesDesignVariables &designVariables),(mesh, dict, designVariables))
fileName derivativesFolder_
Folder holding the twist sensitivities.
bool initialiseVars() const
Initialise the design variables?
virtual void computeBounds(autoPtr< scalarField > &lowerBounds, autoPtr< scalarField > &upperBounds)
Transform bounds from control points to design variables.
virtual bool writeData(Ostream &os) const
Append useful information to the design variables IOdictionary.
virtual tmp< scalarField > designVariablesToControlPoints(const scalarField &designVariables)=0
Convert design variables to control points, stored in a scalarField.
virtual ~morphingBoxConstraint()=default
Destructor.
volBSplinesBase & volBSplinesBase_
Easy access to the volBSplinesBase resting in the designVariables_.
virtual tmp< scalarField > postProcessSens(const scalarField &controlPointSens, const word &adjointSolverName)
Chain rule from control points to design variables.
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
static autoPtr< morphingBoxConstraint > New(const fvMesh &mesh, const dictionary &dict, volumetricBSplinesDesignVariables &designVariables)
Construct and return the selected morphingBoxConstraint.
A class for handling words, derived from Foam::string.
Definition: word.H:63
Volumetric B-Splines design variables for shape optimisation.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
TypeName("morphingBoxConstraint")
Runtime type information.
virtual tmp< scalarField > correctionCPs(const scalarField &correction)=0
Convert the correction of the design variables to the correction of the control points.
virtual void computeDVsSensitivities(scalarField &dvSens, const scalarField &cpSens)=0
Compute sensitivities wrt the design variables (chain rule)
volumetricBSplinesDesignVariables & designVariables_
Reference to underlaying volumetric B-Splines morpher.
Abstract base class for defining constraints for the control points of volumetric B-Splines morphing ...
Abstract base class for defining design variables.
scalarField initialCPs_
Initial CPs stored in scalarField.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
const dictionary dict_
Volumetric B-Splines variables dict.
virtual void updateBounds(autoPtr< scalarField > &lowerBounds, autoPtr< scalarField > &upperBounds)
Update the bounds of the design variables.
virtual void writeDVSensitivities(const scalarField &sens, const word &name)
Write sensitivities w.r.t. the design variables.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Macros to ease declaration of run-time selection tables.
virtual tmp< scalarField > controlPointsToDesignVariables(const scalarField &cps)=0
Return the design variables corresponding to the given control points.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
bool initialiseVars_
Initialise the design variables.
Namespace for OpenFOAM.
Class constructing a number of volumetric B-Splines boxes, read from dynamicMeshDict. Useful for various sensitivities and optMeshMovement classes.