levelSetDesignVariables.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) 2022-2023 PCOpt/NTUA
9  Copyright (C) 2022-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::levelSetDesignVariables
29 
30 Description
31  Signed distance field design variables for level-set based topology
32  optimization (topO).
33 
34  A great reference for various aspects of level-set-based topO can be found
35  in
36 
37  Reference:
38  \verbatim
39  van Dijk, N.P., Maute, K., Langelaar, M., & & van Keulen, F. (2013).
40  Level-set methods for structural topology optimization: a review.
41  Structural and Multidisciplinary Optimization, 48, 437–472.
42  https://doi.org/10.1007/s00158-013-0912-y
43  \endverbatim
44 
45  The implemented approach borrows from the references therein, but does not
46  follow any of them exactly. The underlying field of the design variables
47  is not the level-set field but affects the latter through:
48  a) a regularisation approach similar to that used in porosity-based topO
49  (see the regularisation class and references therein) and
50  b) a re-initialisation strategy. Since solving a modified Hamilton-Jacobi
51  equation poses a number of numerical challenges, the signed distance field
52  is obtained by identifying the zero level-set contour using the
53  cutFaceIso, cutCellIso infrastructure (see references therein for the
54  methodology) and using these "cut-faces" as seeds for meshWave.
55 
56 SourceFiles
57  levelSetDesignVariables.C
58 
59 \*---------------------------------------------------------------------------*/
60 
61 #ifndef levelSetDesignVariables_H
62 #define levelSetDesignVariables_H
63 
64 #include "topOVariablesBase.H"
65 #include "designVariables.H"
66 #include "regularisationRadius.H"
67 #include "regularisationPDE.H"
69 #include "adjointSensitivity.H"
70 
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 
73 namespace Foam
74 {
75 
76 /*---------------------------------------------------------------------------*\
77  Class levelSetDesignVariables Declaration
78 \*---------------------------------------------------------------------------*/
79 
81 :
82  public topOVariablesBase,
83  public designVariables
84 {
85 protected:
86 
87  // Protected Data Members
88 
89  //- The regularisation radius
91 
92  //- Regularisation mechanism
94 
95  //- The regularised field
97 
98  //- The signed distances field
100 
101  //- Function to transorm signed distances to the indicator field beta_
103 
104  //- The indicator field
106 
107  //- Fix aTilda values in fixed{Zero}PorousZones and IOcells
108  bool fixATildaValues_;
109 
110  //- Write all fields related to the distance calculation (debugging)
113  //- Mesh faces acting as the source of MeshWave
115 
116  //- Seed distances to MeshWave and cell distances
117  // The data carried by each wallPoints corresponds to the origin
118  // mesh face ID
121 
123  // Protected Member Functions
124 
125  //- Read the design variables field
126  void readField();
128  //- Apply fixed values in certain zones
130 
131  //- Determine which design variables are active
132  void setActiveDesignVariables(bool activeIO = false);
133 
134  //- Make aTilda a signed distance field based on the zero iso-surface
135  //- of the current aTilda field
137 
138  //- Update the beta field
139  void updateBeta();
140 
141 
142 private:
143 
144  // Private Member Functions
145 
146  //- No copy construct
148 
149  //- No copy assignment
150  void operator=(const levelSetDesignVariables&) = delete;
151 
152 
153 public:
154 
155  //- Runtime type information
156  TypeName("levelSet");
157 
158 
159  // Constructors
160 
161  //- Construct from dictionary
163  (
164  fvMesh& mesh,
165  const dictionary& dict
166  );
167 
168 
169  // Selectors
170 
171  //- Return a reference to the selected turbulence model
173  (
174  fvMesh& mesh,
175  const dictionary& dict
176  );
177 
178 
179  //- Destructor
180  virtual ~levelSetDesignVariables() = default;
181 
182 
183  // Member Functions
184 
185  //- Const reference to the beta field
186  virtual const volScalarField& beta() const;
187 
188  //- Update design variables based on a given correction
189  virtual void update(scalarField& correction);
190 
191  //- Compute eta if not set in the first step
192  virtual scalar computeEta(scalarField& correction);
193 
194  //- Whether to use global sum when computing matrix-vector products
195  //- in update methods
196  virtual bool globalSum() const;
197 
198  //- Add contributions from the adjoint to the regularization PDE,
199  //- the derivative of the interpolation function and the mesh volume
200  //- to the final sensitivities
202  (
203  adjointSensitivity& adjointSens
204  );
205 
206  //- Write useful quantities to files
207  virtual void writeDesignVars();
208 
209  //- The writeData function required by the regIOobject write operation
210  virtual bool writeData(Ostream&) const;
211 };
212 
213 
214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 
216 } // End namespace Foam
217 
218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 
220 #endif
221 
222 // ************************************************************************* //
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
TypeName("levelSet")
Runtime type information.
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.
autoPtr< regularisationPDE > regularisation_
Regularisation mechanism.
virtual bool globalSum() const
Whether to use global sum when computing matrix-vector products in update methods.
volScalarField aTilda_
The regularised field.
void updateSignedDistances()
Make aTilda a signed distance field based on the zero iso-surface of the current aTilda field...
void applyFixedPorosityValues()
Apply fixed values in certain zones.
autoPtr< regularisationRadius > radius_
The regularisation radius.
virtual void update(scalarField &correction)
Update design variables based on a given correction.
volScalarField signedDistances_
The signed distances field.
static autoPtr< levelSetDesignVariables > New(fvMesh &mesh, const dictionary &dict)
Return a reference to the selected turbulence model.
dynamicFvMesh & mesh
autoPtr< topOInterpolationFunction > interpolation_
Function to transorm signed distances to the indicator field beta_.
virtual const volScalarField & beta() const
Const reference to the beta field.
Signed distance field design variables for level-set based topology optimization (topO).
void readField()
Read the design variables field.
labelList changedFaces_
Mesh faces acting as the source of MeshWave.
bool writeAllDistanceFields_
Write all fields related to the distance calculation (debugging)
volScalarField beta_
The indicator field.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
virtual tmp< scalarField > assembleSensitivities(adjointSensitivity &adjointSens)
Add contributions from the adjoint to the regularization PDE, the derivative of the interpolation fun...
Abstract base class for defining design variables.
List< wallPointData< label > > allCellInfo_
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
virtual ~levelSetDesignVariables()=default
Destructor.
void updateBeta()
Update the beta field.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
virtual scalar computeEta(scalarField &correction)
Compute eta if not set in the first step.
List< wallPointData< label > > changedFacesInfo_
Seed distances to MeshWave and cell distances.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
void setActiveDesignVariables(bool activeIO=false)
Determine which design variables are active.
Base class for all design variables related to topology optimisation (topO). Provides the lookup func...
bool fixATildaValues_
Fix aTilda values in fixed{Zero}PorousZones and IOcells.
virtual void writeDesignVars()
Write useful quantities to files.
virtual bool writeData(Ostream &) const
The writeData function required by the regIOobject write operation.
Namespace for OpenFOAM.