topOVariablesBase.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::topOVariablesBase
30 
31 Description
32  Base class for all design variables related to topology optimisation (topO).
33  Provides the lookup functionality necessary for all fvOptions associated
34  with topO and access to topOZones.
35 
36 SourceFiles
37  topOVariablesBase.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef topOVariablesBase_H
42 #define topOVariablesBase_H
43 
44 #include "localIOdictionary.H"
45 #include "topOZones.H"
47 #include "FaceCellWave.H"
48 #include "wallPointData.H"
49 #include "cutFaceIso.H"
50 #include "cutCellIso.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 /*---------------------------------------------------------------------------*\
58  Class topOVariablesBase Declaration
59 \*---------------------------------------------------------------------------*/
60 
62 :
63  public localIOdictionary
64 {
65 protected:
66 
67  // Protected data
68 
69  //- Cell zones useful for defining the constant and changing parts
70  //- of the domain in topO
72 
73  //- Folder name holding the zero level-set iso-surface
75 
76  //- Map between iso-surface and mesh faces (internal and boundary)
78 
79  //- Per cutting face, the changed faces owned by it
80  //labelListList changedFacesPerCuttingFace_;
81 
82  //- Iso-surface points
84 
85  //- Iso-surface faces
87 
88 
89  // Protected Member Functions
90 
91  //- Based on the current pseudo-distance field y, identity the zero
92  //- level-set iso-surface, write it to files for post-processing and
93  //- set the seeds for the distance calculation from this iso-surface
95  (
96  const volScalarField& y,
97  labelList& changedFaces,
98  List<wallPointData<label>>& changedFacesInfo
99  ) const;
100 
101  //- Construct facesFaces for a given boundary face
102  DynamicList<label> faceFaces(const label facei) const;
103 
104  //- Check whether the cutFace intersects the boundary of the initial
105  //- domain and add fluid part of the intersected face to the isoline
107  (
108  const label facei,
109  const cutFaceIso& cutFace,
110  DynamicList<vector>& isoSurfPts,
111  DynamicList<face>& isoSurfFaces,
113  List<DynamicList<label>>& cuttingFacesPerMeshFace
114  ) const;
115 
116  bool isDuplicatePoint
117  (
118  const label pointID,
119  const vector& pointi,
120  const DynamicList<label>& cuttingFaces,
121  const DynamicList<point>& isoSurfPts,
122  const DynamicList<face>& isoSurfFaces,
123  labelList& uniquePointIDs
124  ) const;
125 
126  //- Add the cutting face to the zero level-set iso-surface
128  (
129  const DynamicList<point>& facePoints,
130  const label nSerialPatches,
131  const DynamicList<label>& cellCutFaces,
132  const List<DynamicList<label>>& cuttingFacesPerMeshFace,
133  DynamicList<vector>& isoSurfPts,
134  DynamicList<face>& isoSurfFaces,
136  ) const;
137 
138  //- Check whether the boundary faces of the initial domain belong
139  //- to the fluid part and add them to the surface describing the
140  //- fluid domain.
141  // Used only to close the output surface, does not set distance seeds
143  (
144  const pointScalarField& pointY,
145  const Map<label>& addedFaces,
146  const scalar isoValue,
147  DynamicList<vector>& isoSurfPts,
148  DynamicList<face>& isoSurfFaces,
150  label& nChangedFaces,
151  labelList& changedFaces,
152  List<wallPointData<label>>& changedFacesInfo,
153  labelList& changedFaceToCutFace,
154  List<DynamicList<label>>& cuttingFacesPerMeshFace
155  );
156 
157  //- Write the surface describing the fluid domain to stl and vtp files
158  void writeSurfaceFiles
159  (
160  const pointField& pts,
161  const faceList& faces,
162  const labelList& zoneIds,
163  const label nSerialPatches
164  ) const;
165 
166 
167 private:
168 
169  // Private Member Functions
170 
171  //- Disallow default bitwise copy construct
172  topOVariablesBase(const topOVariablesBase&) = delete;
173 
174  //- Disallow default bitwise assignment
175  void operator=(const topOVariablesBase&) = delete;
176 
177 
178 public:
179 
180  //- Runtime type information
181  TypeName("topOVariablesBase");
182 
183  // Constructors
184 
185  //- Construct from dictionary
187  (
188  fvMesh& mesh,
189  const dictionary& dict
190  );
191 
192 
193  //- Destructor
194  virtual ~topOVariablesBase() = default;
195 
196 
197  // Member Functions
198 
199  //- Get topOZones
200  inline const topOZones& getTopOZones() const
201  {
202  return zones_;
203  }
204 
205  //- Get betaMax value
206  inline scalar getBetaMax() const
207  {
208  return zones_.getBetaMax();
209  }
210 
211  //inline const labelListList& changedFacesPerCuttingFace() const
212  //{
213  // return changedFacesPerCuttingFace_;
214  //}
215 
216  inline const pointField& surfacePoints() const
217  {
218  return surfPoints_;
219  }
220 
221  inline const faceList& surfaceFaces() const
222  {
223  return surfFaces_;
224  }
225 
226  //- Get field used for physical interpolations
227  virtual const volScalarField& beta() const = 0;
228 
229  //- Populate source terms for the flow equations
230  virtual void sourceTerm
231  (
232  DimensionedField<scalar, volMesh>& field,
233  const topOInterpolationFunction& interpolationFunc,
234  const scalar betaMax,
235  const word& interpolationFieldName = "beta"
236  ) const;
237 
238  //- Post-processing sensitivities due to interpolations based on
239  //- the indicator fields
240  virtual void sourceTermSensitivities
241  (
242  scalarField& sens,
243  const topOInterpolationFunction& interpolationFunc,
244  const scalar betaMax,
245  const word& designVariablesName,
246  const word& interpolationFieldName = "beta"
247  ) const;
248 
249  //- Write the fluid-solid interface to files.
250  // The interface is computed as an isoValue contour of the indicator
251  // field
252  // - 0 distance contour for levelSet or
253  // - 0.5 beta contour for porosity-based topO.
254  // For levelSet topO, the process of identifying the contour sets also
255  // the seeds for computing the distance field in the entire domain
257  (
258  const volScalarField& indicator,
259  const scalar isoValue,
260  labelList& changedFaces,
261  List<wallPointData<label>>& changedFacesInfo
262  );
263 };
264 
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 } // End namespace Foam
269 
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271 
272 #endif
273 
274 // ************************************************************************* //
virtual ~topOVariablesBase()=default
Destructor.
bool addCuttingFaceToIsoline(const DynamicList< point > &facePoints, const label nSerialPatches, const DynamicList< label > &cellCutFaces, const List< DynamicList< label >> &cuttingFacesPerMeshFace, DynamicList< vector > &isoSurfPts, DynamicList< face > &isoSurfFaces, DynamicList< label > &zoneIDs) const
Add the cutting face to the zero level-set iso-surface.
TypeName("topOVariablesBase")
Runtime type information.
dictionary dict
const labelIOList & zoneIDs
Definition: correctPhi.H:59
rDeltaTY field()
A class for handling file names.
Definition: fileName.H:72
scalar getBetaMax() const
Get betaMax value.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
const topOZones & getTopOZones() const
Get topOZones.
topOZones zones_
Cell zones useful for defining the constant and changing parts of the domain in topO.
Class for cutting a face, faceI, of an fvMesh, mesh_, at its intersection with an isosurface defined ...
Definition: cutFaceIso.H:64
bool isDuplicatePoint(const label pointID, const vector &pointi, const DynamicList< label > &cuttingFaces, const DynamicList< point > &isoSurfPts, const DynamicList< face > &isoSurfFaces, labelList &uniquePointIDs) const
DynamicList< label > faceFaces(const label facei) const
Construct facesFaces for a given boundary face.
localIOdictionary is derived from IOdictionary but excludes parallel master reading.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:81
List< face > faceList
List of faces.
Definition: faceListFwd.H:39
scalar y
Base class for cutting a face, faceI, of an fvMesh, mesh_, at its intersections.
Definition: cutFace.H:55
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
dynamicFvMesh & mesh
virtual void sourceTerm(DimensionedField< scalar, volMesh > &field, const topOInterpolationFunction &interpolationFunc, const scalar betaMax, const word &interpolationFieldName="beta") const
Populate source terms for the flow equations.
A class for handling words, derived from Foam::string.
Definition: word.H:63
fileName isoSurfFolder_
Folder name holding the zero level-set iso-surface.
virtual void sourceTermSensitivities(scalarField &sens, const topOInterpolationFunction &interpolationFunc, const scalar betaMax, const word &designVariablesName, const word &interpolationFieldName="beta") const
Post-processing sensitivities due to interpolations based on the indicator fields.
faceList surfFaces_
Iso-surface faces.
virtual const volScalarField & beta() const =0
Get field used for physical interpolations.
pointField surfPoints_
Per cutting face, the changed faces owned by it.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
Base class for selecting the betaMax value, i.e. the value multiplying the Brinkman penalisation term...
Definition: betaMax.H:49
scalar getBetaMax() const
Get betaMax.
Definition: topOZones.H:217
void writeFluidSolidInterface(const volScalarField &indicator, const scalar isoValue, labelList &changedFaces, List< wallPointData< label >> &changedFacesInfo)
Write the fluid-solid interface to files.
const pointField & surfacePoints() const
Holds information (coordinate and normal) regarding nearest wall point.
Definition: wallPointData.H:48
const faceList & surfaceFaces() const
void addBoundaryFacesToIsoline(const pointScalarField &pointY, const Map< label > &addedFaces, const scalar isoValue, DynamicList< vector > &isoSurfPts, DynamicList< face > &isoSurfFaces, DynamicList< label > &zoneIDs, label &nChangedFaces, labelList &changedFaces, List< wallPointData< label >> &changedFacesInfo, labelList &changedFaceToCutFace, List< DynamicList< label >> &cuttingFacesPerMeshFace)
Check whether the boundary faces of the initial domain belong to the fluid part and add them to the s...
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Map< label > meshFaceToChangedFace_
Map between iso-surface and mesh faces (internal and boundary)
bool addCutBoundaryFaceToIsoline(const label facei, const cutFaceIso &cutFace, DynamicList< vector > &isoSurfPts, DynamicList< face > &isoSurfFaces, DynamicList< label > &zoneIDs, List< DynamicList< label >> &cuttingFacesPerMeshFace) const
Check whether the cutFace intersects the boundary of the initial domain and add fluid part of the int...
void writeSurfaceFiles(const pointField &pts, const faceList &faces, const labelList &zoneIds, const label nSerialPatches) const
Write the surface describing the fluid domain to stl and vtp files.
Base class for all design variables related to topology optimisation (topO). Provides the lookup func...
Namespace for OpenFOAM.
const pointField & pts
void setCutInterfaceFaces(const volScalarField &y, labelList &changedFaces, List< wallPointData< label >> &changedFacesInfo) const
Based on the current pseudo-distance field y, identity the zero level-set iso-surface, write it to files for post-processing and set the seeds for the distance calculation from this iso-surface.