topODesignVariables.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) 2007-2023 PCOpt/NTUA
9  Copyright (C) 2013-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 
28 Class
29  Foam::topODesignVariables
30 
31 Description
32  Design variables for porosity-based topology optimisation (topO) problems
33 
34  Reference:
35  \verbatim
36  The main idea behind porosity-based topO can be found in
37 
38  Papoutsis-Kiachagias, E. M., & Giannakoglou, K. C. (2014).
39  Continuous Adjoint Methods for Turbulent Flows, Applied to Shape
40  and Topology Optimization: Industrial Applications.
41  Archives of Computational Methods in Engineering, 23(2), 255-299.
42  http://doi.org/10.1007/s11831-014-9141-9
43 
44  with regularisation and projection approaches following
45 
46  Lazarov, B. S., & Sigmund O. (2010).
47  Filters in topology optimization based on Helmholtz-type
48  differential equations.
49  International Journal for Numerical Methods in Engineering,
50  86(6), 765-781.
51  https://doi.org/10.1002/nme.3072
52  \endverbatim
53 
54 SourceFiles
55  topODesignVariables.C
56 
57 \*---------------------------------------------------------------------------*/
58 
59 #ifndef topODesignVariables_H
60 #define topODesignVariables_H
61 
62 #include "designVariables.H"
63 #include "topOVariablesBase.H"
64 #include "fieldRegularisation.H"
65 
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 
68 namespace Foam
69 {
70 
71 /*---------------------------------------------------------------------------*\
72  Class topODesignVariables Declaration
73 \*---------------------------------------------------------------------------*/
74 
76 :
77  public topOVariablesBase,
78  public designVariables
79 {
80 protected:
81 
82  // Protected data
83 
84  //- A subfield of the design variables corresponding to the porosity
85  //- field.
86  // Usually the same as *this
88 
89  //- Mechanism to regularise the field of design variables
91 
92  //- Write all fields related to imposition of the Brinkman
93  //- penalisation (i.e. design variables, regularised design variables
94  //- and the indicator field)
95  bool writeAllFields_;
96 
97  //- Add the fvOptions necessary for topO automatically
98  // WIP
99  bool addFvOptions_;
100 
101 
102  // Protected Member Functions
103 
104  //- Update the design variables given their correction
105  virtual void updateField
106  (
107  const scalarField& correction,
108  const label fluidID = 0
109  );
110 
111  //- Apply fixed values in certain zones
112  void applyFixedValues();
113 
114  //- Set active design variables
115  virtual void setActiveDesignVariables
116  (
117  const label fluidID = 0,
118  const bool activeIO = false
119  );
120 
121  //- Read field with (path of) the design variables and store input
122  //- in the design variables list with optional offset
123  void readField
124  (
125  const word& name,
126  const label fluidID = 0,
127  const bool setIOValues = false
128  );
129 
130  //- Part of the constructor initialisation
131  virtual void initialize();
132 
133 
134 private:
135 
136  // Private Member Functions
137 
138  //- Disallow default bitwise copy construct
139  topODesignVariables(const topODesignVariables&) = delete;
140 
141  //- Disallow default bitwise assignment
142  void operator=(const topODesignVariables&) = delete;
143 
144 
145 public:
146 
147  //- Runtime type information
148  TypeName("topO");
149 
150  // Constructors
151 
152  //- Construct from dictionary
154  (
155  fvMesh& mesh,
156  const dictionary& dict
157  );
158 
159  //- Construct from dictionary and size
161  (
162  fvMesh& mesh,
163  const dictionary& dict,
164  const label size
165  );
166 
167 
168  // Selectors
169 
170  //- Construct and return the selected design variables
172  (
173  fvMesh& mesh,
174  const dictionary& dict
175  );
176 
177 
178  //- Destructor
179  virtual ~topODesignVariables() = default;
180 
181 
182  // Member Functions
183 
184  //- Get the indicator field
185  virtual const volScalarField& beta() const;
186 
187  //- Return interpolant.
188  // Defaults to beta in mono-fluid topO optimization
189  virtual const scalarField& interpolationField
190  (
191  const word& interpolationFieldName = "beta"
192  ) const;
193 
194  //- Interpolate between the given field and solid values
195  virtual void interpolate
196  (
198  const topOInterpolationFunction& interpolationFunc,
199  const FieldField<Field, scalar>& fluidValues,
200  const scalarField& solidValues,
201  const label fieldi,
202  const word& interpolationFieldName = "beta"
203  ) const;
204 
205  //- Post-processing sensitivities due to interpolations based on
206  //- the indicator fields
207  virtual void interpolationSensitivities
208  (
209  scalarField& sens,
210  const topOInterpolationFunction& interpolationFunc,
211  const FieldField<Field, scalar>& fluidValues,
212  const scalarField& solidValues,
213  const label fieldi,
214  const word& designVariablesName,
215  const word& interpolationFieldName = "beta"
216  ) const;
217 
218  //- Nullify given field in the solid domain
219  virtual void nullifyInSolid
220  (
222  const topOInterpolationFunction& interpolationFunc
223  ) const;
224 
225  //- Nullify given field in the solid domain
226  virtual void nullifyInSolidSensitivities
227  (
228  scalarField& sens,
229  const topOInterpolationFunction& interpolationFunc,
230  const word& designVariablesName
231  ) const;
232 
233  //- Return the Brinkman penalisation term
234  virtual tmp<scalarField> penalty
235  (
236  const word& interpolationFieldName,
237  const topOInterpolationFunction& interpolationFunc
238  ) const;
239 
240  //- Return the penalty term derivative
242  (
243  const word& interpolationFieldName,
244  const topOInterpolationFunction& interpolationFunc
245  ) const;
246 
247  //- Update design variables based on a given correction
248  virtual void update(scalarField& correction);
249 
250  //- Compute eta if not set in the first step
251  virtual scalar computeEta(scalarField& correction);
252 
253  //- Whether to use global sum when computing matrix-vector products
254  //- in update methods
255  virtual bool globalSum() const;
256 
257  //- Assemble sensitivity derivatives, by combining the part related
258  //- to the primal and adjoint solution with the part related to the
259  //- design variables.
260  // Takes into consideration the adjoint to the regularisation process
261  // and the derivative of the interpolationFunc
263  (
264  adjointSensitivity& sens
265  );
266 
267  //- Set initial values of the design variables
268  // For design variables sets that need to be initialised after the
269  // construction of the primal fields.
270  virtual void setInitialValues();
271 
272  //- Automatically add fvOptions depending on the design variables
273  //- to the primal and adjoint solvers
274  // WIP
275  virtual void addFvOptions
276  (
279  );
280 
281  //- Get access to the regularisation object
283  {
284  return regularisation_;
285  }
286 
287  //- Write porosity field to file
288  virtual void writeDesignVars();
289 
290  //- The writeData function required by the regIOobject write operation
291  virtual bool writeData(Ostream&) const;
292 };
293 
294 
295 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
296 
297 } // End namespace Foam
298 
299 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
300 
301 #endif
302 
303 // ************************************************************************* //
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix by subtracting the matrix multiplied by the current fi...
virtual tmp< scalarField > assembleSensitivities(adjointSensitivity &sens)
Assemble sensitivity derivatives, by combining the part related to the primal and adjoint solution wi...
dictionary dict
virtual void interpolationSensitivities(scalarField &sens, const topOInterpolationFunction &interpolationFunc, const FieldField< Field, scalar > &fluidValues, const scalarField &solidValues, const label fieldi, const word &designVariablesName, const word &interpolationFieldName="beta") const
Post-processing sensitivities due to interpolations based on the indicator fields.
rDeltaTY field()
virtual tmp< scalarField > penaltySensitivities(const word &interpolationFieldName, const topOInterpolationFunction &interpolationFunc) const
Return the penalty term derivative.
bool addFvOptions_
Add the fvOptions necessary for topO automatically.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Abstract base class for adjoint-based sensitivities.
Base class for primal solvers.
Definition: primalSolver.H:46
virtual void interpolate(volScalarField &field, const topOInterpolationFunction &interpolationFunc, const FieldField< Field, scalar > &fluidValues, const scalarField &solidValues, const label fieldi, const word &interpolationFieldName="beta") const
Interpolate between the given field and solid values.
Design variables for porosity-based topology optimisation (topO) problems.
virtual const volScalarField & beta() const
Get the indicator field.
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:51
virtual ~topODesignVariables()=default
Destructor.
virtual scalar computeEta(scalarField &correction)
Compute eta if not set in the first step.
dynamicFvMesh & mesh
fieldRegularisation & getRegularisation()
Get access to the regularisation object.
virtual const scalarField & interpolationField(const word &interpolationFieldName="beta") const
Return interpolant.
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual void writeDesignVars()
Write porosity field to file.
virtual void nullifyInSolidSensitivities(scalarField &sens, const topOInterpolationFunction &interpolationFunc, const word &designVariablesName) const
Nullify given field in the solid domain.
static autoPtr< topODesignVariables > New(fvMesh &mesh, const dictionary &dict)
Construct and return the selected design variables.
const word & name() const
Name function is needed to disambiguate those inherited from regIOobject and dictionary.
fieldRegularisation regularisation_
Mechanism to regularise the field of design variables.
virtual void setActiveDesignVariables(const label fluidID=0, const bool activeIO=false)
Set active design variables.
SubField< scalar > alpha_
A subfield of the design variables corresponding to the porosity field.
virtual void update(scalarField &correction)
Update design variables based on a given correction.
virtual bool writeData(Ostream &) const
The writeData function required by the regIOobject write operation.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
label size() const noexcept
The number of elements in the container.
Definition: UList.H:671
void applyFixedValues()
Apply fixed values in certain zones.
virtual void nullifyInSolid(scalarField &field, const topOInterpolationFunction &interpolationFunc) const
Nullify given field in the solid domain.
virtual void setInitialValues()
Set initial values of the design variables.
virtual void updateField(const scalarField &correction, const label fluidID=0)
Update the design variables given their correction.
TypeName("topO")
Runtime type information.
Abstract base class for defining design variables.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
virtual tmp< scalarField > penalty(const word &interpolationFieldName, const topOInterpolationFunction &interpolationFunc) const
Return the Brinkman penalisation term.
bool writeAllFields_
Write all fields related to imposition of the Brinkman penalisation (i.e. design variables, regularised design variables and the indicator field)
virtual void initialize()
Part of the constructor initialisation.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
virtual void addFvOptions(const PtrList< primalSolver > &primalSolver, const PtrList< adjointSolverManager > &adjointSolverManagers)
Automatically add fvOptions depending on the design variables to the primal and adjoint solvers...
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Base class for all design variables related to topology optimisation (topO). Provides the lookup func...
PtrList< adjointSolverManager > & adjointSolverManagers
Definition: createFields.H:8
virtual bool globalSum() const
Whether to use global sum when computing matrix-vector products in update methods.
Namespace for OpenFOAM.
void readField(const word &name, const label fluidID=0, const bool setIOValues=false)
Read field with (path of) the design variables and store input in the design variables list with opti...