Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
28Class
29 Foam::topODesignVariables
30
31Description
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
54SourceFiles
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
68namespace Foam
69{
71/*---------------------------------------------------------------------------*\
72 Class topODesignVariables Declaration
73\*---------------------------------------------------------------------------*/
74
75class topODesignVariables
76:
77 public topOVariablesBase,
78 public designVariables
79{
80protected:
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
134private:
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
145public:
146
147 //- Runtime type information
148 TypeName("topO");
149
150 // Constructors
151
152 //- Construct from dictionary
153 topODesignVariables
154 (
155 fvMesh& mesh,
156 const dictionary& dict
157 );
158
159 //- Construct from dictionary and size
160 topODesignVariables
161 (
162 fvMesh& mesh,
163 const dictionary& dict,
164 const label size
165 );
166
167
168 // Selectors
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
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
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 (
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// ************************************************************************* //
A field of fields is a PtrList of fields with reference counting.
Definition FieldField.H:77
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition PtrList.H:67
SubField is a Field obtained as a section of another Field, without its own allocation....
Definition SubField.H:58
void size(const label n)
Definition UList.H:118
Abstract base class for adjoint-based sensitivities.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Base class for primal solvers.
A class for managing temporary objects.
Definition tmp.H:75
TypeName("topO")
Runtime type information.
virtual void updateField(const scalarField &correction, const label fluidID=0)
Update the design variables given their correction.
virtual const scalarField & interpolationField(const word &interpolationFieldName="beta") const
Return interpolant.
fieldRegularisation & getRegularisation()
Get access to the regularisation object.
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...
fieldRegularisation regularisation_
Mechanism to regularise the field of design variables.
virtual scalar computeEta(scalarField &correction)
Compute eta if not set in the first step.
virtual bool writeData(Ostream &) const
The writeData function required by the regIOobject write operation.
virtual void initialize()
Part of the constructor initialisation.
virtual tmp< scalarField > assembleSensitivities(adjointSensitivity &sens)
Assemble sensitivity derivatives, by combining the part related to the primal and adjoint solution wi...
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.
virtual void nullifyInSolidSensitivities(scalarField &sens, const topOInterpolationFunction &interpolationFunc, const word &designVariablesName) const
Nullify given field in the solid domain.
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.
SubField< scalar > alpha_
A subfield of the design variables corresponding to the porosity field.
static autoPtr< topODesignVariables > New(fvMesh &mesh, const dictionary &dict)
Construct and return the selected design variables.
virtual void setActiveDesignVariables(const label fluidID=0, const bool activeIO=false)
Set active design variables.
bool writeAllFields_
Write all fields related to imposition of the Brinkman penalisation (i.e. design variables,...
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.
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.
virtual const volScalarField & beta() const
Get the indicator field.
virtual void setInitialValues()
Set initial values of the design variables.
virtual bool globalSum() const
Whether to use global sum when computing matrix-vector products in update methods.
virtual ~topODesignVariables()=default
Destructor.
void applyFixedValues()
Apply fixed values in certain zones.
virtual tmp< scalarField > penalty(const word &interpolationFieldName, const topOInterpolationFunction &interpolationFunc) const
Return the Brinkman penalisation term.
virtual void nullifyInSolid(scalarField &field, const topOInterpolationFunction &interpolationFunc) const
Nullify given field in the solid domain.
virtual void writeDesignVars()
Write porosity field to file.
A class for handling words, derived from Foam::string.
Definition word.H:66
rDeltaTY field()
mesh update()
dynamicFvMesh & mesh
Namespace for OpenFOAM.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix by subtracting the matrix multiplied by the current fi...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68
PtrList< adjointSolverManager > & adjointSolverManagers
Definition createFields.H:8