NURBS3DVolume.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-2021 PCOpt/NTUA
9 Copyright (C) 2013-2021 FOSS GP
10 Copyright (C) 2019-2020 OpenCFD Ltd.
11-------------------------------------------------------------------------------
12License
13 This file is part of OpenFOAM.
14
15 OpenFOAM is free software: you can redistribute it and/or modify it
16 under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 3 of the License, or
18 (at your option) any later version.
19
20 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27
28Class
29 Foam::NURBS3DVolume
30
31Description
32 NURBS3DVolume morpher. Includes support functions for gradient computations
33 Base class providing support for different coordinate systems
34
35 Reference:
36 \verbatim
37 For a short introduction to a volumetric B-Splines morpher and its use
38 in shape optimisation
39
40 Papoutsis-Kiachagias, E., Magoulas, N., Mueller, J.,
41 Othmer, C., & Giannakoglou, K. (2015).
42 Noise reduction in car aerodynamics using a surrogate objective
43 function and the continuous adjoint method with wall functions.
44 Computers & Fluids, 122, 223-232.
45 http://doi.org/10.1016/j.compfluid.2015.09.002
46 \endverbatim
47
48SourceFiles
49 NURBS3DVolume.C
50 NURBS3DVolumeI.H
51
52\*---------------------------------------------------------------------------*/
53
54#ifndef NURBS3DVolume_H
55#define NURBS3DVolume_H
56
57#include "NURBSbasis.H"
58#include "boolVector.H"
59#include "localIOdictionary.H"
60#include "pointMesh.H"
61#include "pointPatchField.H"
62#include "pointPatchFieldsFwd.H"
63#include "boundaryFieldsFwd.H"
64
65// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66
67namespace Foam
68{
69
70/*---------------------------------------------------------------------------*\
71 Class NURBS3DVolume Declaration
72\*---------------------------------------------------------------------------*/
74class NURBS3DVolume
75:
77{
78protected:
79
80 // Protected Data
84 const fvMesh& mesh_;
86 word name_;
87 //- NURBS basis functions
91
92 //- Max iterations for Newton-Raphson
93 label maxIter_;
94
95 //- Tolerance for Newton-Raphson
96 scalar tolerance_;
97
98 //- How many times to bound parametric coordinates until deciding it is
99 //- outside the box
100 label nMaxBound_;
101
102 //- The volumetric B-Splines control points
104
105 //- Map of points-in-box to mesh points
107
108 //- Map of mesh points to points-in-box
109 // Return -1 if point not within the box
111
112 //- Parametric coordinates of pointsInBox
114
115 //- Coordinates in the local system for which CPs are defined
117
118 //- Confine movement in certain directions and control points. Refers
119 //- to the local system
120 label confineUMovement_;
122 label confineVMovement_;
124 label confineWMovement_;
127
128 //- Which movement components to freeze in each plane
140
141 //- Which of the cps are moved in an optimisation
143
144 //- Which design variables are changed in an optimisation
146
147 //- Folder to store control points
148 string cpsFolder_;
149
150 //- Read parametric coordinates from file if present in the folder
151 bool readStoredData_;
152
153
154 // Protected Member Functions
155
156 //- Find points within control points box
157 void findPointsInBox(const vectorField& meshPoints);
158
159 //- Compute parametric coordinates in order to match a given set
160 //- of coordinates, based on the cps of the class
161 // Uses a Newton-Raphson loop.
162 // Argument is the points residing in the box
164
166
167 //- Bound components to certain limits
168 bool bound
169 (
170 vector& vec,
171 scalar minValue = 1e-7,
172 scalar maxValue = 0.999999
173 );
174
175 //- Create lists with active design variables and control points
177
178 //- Confine movement in boundary control points if necessary
180
181 //- Confine control point movement to maintain user-defined continuity
183
184 //- Confine movement in all control points for user-defined directions
186
187 //- Confine all three movements for a prescribed control point
188 void confineControlPoint(const label cpI);
189
190 //- Confine specific movements for a prescribed control point
191 void confineControlPoint(const label cpI, const boolVector&);
192
193 //- Create folders to store cps and derivatives
194 void makeFolders();
195
196 //- Transform a point from its coordinate system to a cartesian system
198 (
199 const vector& localCoordinates
200 ) const = 0;
201
202 //- Transformation tensor for dxdb, from local coordinate system to
203 //- cartesian
204 virtual tensor transformationTensorDxDb(label globalPointIndex) = 0;
205
206 //- Update coordinates in the local system based on the cartesian points
207 virtual void updateLocalCoordinateSystem
208 (
209 const vectorField& cartesianPoints
210 ) = 0;
211
212
213public:
214
215 //- Runtime type information
216 TypeName("NURBS3DVolume");
217
218
219 // Declare run-time constructor selection table
222 (
223 autoPtr,
226 (
227 const dictionary& dict,
228 const fvMesh& mesh,
229 bool computeParamCoors
230 ),
231 (dict, mesh, computeParamCoors)
232 );
233
234 // Constructors
235
236 //- Construct from dictionary
238 (
239 const dictionary& dict,
240 const fvMesh& mesh,
241 bool computeParamCoors = true
242 );
243
244 //- Construct as copy
246
247
248 // Selectors
249
250 //- Return a reference to the selected NURBS model
252 (
253 const dictionary& dict,
254 const fvMesh& mesh,
255 bool computeParamCoors = true
256 );
257
258
259 //- Destructor
260 virtual ~NURBS3DVolume() = default;
261
262
263 // Member Functions
264
265 // Derivatives wrt parametric coordinates
266
267 //- Volume point derivative wrt u at point u,v,w
269 (
270 const scalar u,
271 const scalar v,
272 const scalar w
273 ) const;
274
275 //- Volume point derivative wrt v at point u,v,w
277 (
278 const scalar u,
279 const scalar v,
280 const scalar w
281 ) const;
282
283 //- Volume point derivative wrt w at point u,v,w
285 (
286 const scalar u,
287 const scalar v,
288 const scalar w
289 ) const;
290
291 //- Jacobian matrix wrt to the volume parametric coordinates
292 tensor JacobianUVW(const vector& u) const;
293
294
295 // Derivatives wrt to control points
296
297 //- Volume point derivative wrt to control point cpI at point u,v,w
298 // Scalar since in the local system!
299 scalar volumeDerivativeCP(const vector& u, const label cpI) const;
300
301 //- Control point sensitivities computed using point-based surface
302 //- sensitivities
304 (
305 const pointVectorField& pointSens,
306 const labelList& sensitivityPatchIDs
307 );
308
309 //- Control point sensitivities computed using face-based surface
310 //- sensitivities
312 (
313 const volVectorField& faceSens,
314 const labelList& sensitivityPatchIDs
315 );
316
317 //- Control point sensitivities computed using face-based surface
318 //- sensitivities
320 (
321 const boundaryVectorField& faceSens,
322 const labelList& sensitivityPatchIDs
323 );
324
325 //- Control point sensitivities computed using face-based surface
326 //- sensitivities
328 (
329 const vectorField& faceSens,
330 const label patchI,
331 const label cpI
332 );
333
334 //- Part of control point sensitivities related to the face normal
335 //- variations
337 (
338 const label patchI,
339 const label cpI,
340 bool DimensionedNormalSens = true
341 );
342
343 //- Get patch dx/db
345 (
346 const label patchI,
347 const label cpI
348 );
349
350 //- Get patch dx/db
352 (
353 const label patchI,
354 const label cpI
355 );
356
357
358 // Cartesian coordinates
359
360 //- Compute cartesian coordinates based on control points
361 //- and parametric coordinates
362 tmp<vectorField> coordinates(const vectorField& uVector) const;
363
364 //- The same, for a specific point
365 vector coordinates(const vector& uVector) const;
366
367 //- Mesh movement based on given control point movement
369 (
370 const vectorField& controlPointsMovement
371 );
372
373 //- Boundary mesh movement based on given control point movement
375 (
376 const vectorField& controlPointsMovement,
377 const labelList& patchesToBeMoved,
378 const bool moveCPs = true
379 );
380
381
382 // Control points management
383
384 //- Get control point ID from its I-J-K coordinates
385 label getCPID(const label i, const label j, const label k) const;
386
387 //- Set new control points
388 // New values should be on the coordinates system original CPs
389 // were defined
390 void setControlPoints(const vectorField& newCps);
391
392
393 //- Bound control points movement in the boundary control points
394 //- and in certain directions if needed
396 (
397 vectorField& controlPointsMovement
398 ) const;
399
400 //- Compute max. displacement at the boundary
402 (
403 const vectorField& controlPointsMovement,
404 const labelList& patchesToBeMoved
405 );
406
407
408 // Access Functions
409
410 // Functions triggering calculations
411
412 //- Get mesh points that reside within the control points box
414
415 //- Get map of points in box to mesh points
416 const labelList& getMap();
417
418 //- Get map of mesh points to points in box.
419 //- Return -1 if point is outside the box
420 const labelList& getReverseMap();
421
422 //- Get parametric coordinates
424
425 //- Get dxCartesiandb for a certain control point
426 tmp<pointTensorField> getDxDb(const label cpI);
427
428 //- Get dxCartesiandb for a certain control point on cells
429 tmp<volTensorField> getDxCellsDb(const label cpI);
430
431 //- Get number of variables if CPs are moved symmetrically in U
432 label nUSymmetry() const;
433
434 //- Get number of variables if CPs are moved symmetrically in V
435 label nVSymmetry() const;
436
437 //- Get number of variables if CPs are moved symmetrically in W
438 label nWSymmetry() const;
439
440 //- Get number of variables per direction,
441 //- if CPs are moved symmetrically
442 Vector<label> nSymmetry() const;
443
444
445 // Inline access functions
446
447 //- Get box name
448 inline const word& name() const;
449
450 //- Which control points are active?
451 // A control point is active if at least one component can move
452 inline const boolList& getActiveCPs() const;
453
454 //- Which design variables are active?
455 // Numbering is (X1,Y1,Z1), (X2,Y2,Z2) ...
456 inline const boolList& getActiveDesignVariables() const;
457
458 //- Get control points
459 inline const vectorField& getControlPoints() const;
460
462
463 //- Get confine movements
464 inline bool confineUMovement() const;
465
466 inline bool confineVMovement() const;
467
468 inline bool confineWMovement() const;
469
470 //- Get basis functions
471 inline const NURBSbasis& basisU() const;
472
473 inline const NURBSbasis& basisV() const;
474
475 inline const NURBSbasis& basisW() const;
476
477 //- Get number of control points per direction
478 inline Vector<label> nCPsPerDirection() const;
479
480 //- Get mesh
481 inline const fvMesh& mesh() const;
482
483 //- Get dictionary
484 inline const dictionary& dict() const;
485
486
487 // Write Functions
488
489 //- Write control points on a cartesian coordinates system for
490 //- visualization
491 void writeCps
492 (
493 const fileName& = "cpsFile",
494 const bool transform = true
495 ) const;
496
497 //- Write parametric coordinates
498 void writeParamCoordinates() const;
499
500 //- Write the control points to support restart
501 virtual bool writeData(Ostream& os) const;
502};
503
504
505// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
506
507} // End namespace Foam
508
509// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
510
511#include "NURBS3DVolumeI.H"
512
513// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
514
515#endif
516
517// ************************************************************************* //
scalar maxValue
scalar minValue
label k
Useful typenames for fields defined only at the boundaries.
Generic GeometricBoundaryField class.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
NURBS3DVolume morpher. Includes support functions for gradient computations Base class providing supp...
Definition: NURBS3DVolume.H:76
bool readStoredData_
Read parametric coordinates from file if present in the folder.
label maxIter_
Max iterations for Newton-Raphson.
Definition: NURBS3DVolume.H:92
virtual void updateLocalCoordinateSystem(const vectorField &cartesianPoints)=0
Update coordinates in the local system based on the cartesian points.
boolVectorList confineWMinCPs_
static autoPtr< NURBS3DVolume > New(const dictionary &dict, const fvMesh &mesh, bool computeParamCoors=true)
Return a reference to the selected NURBS model.
boolVectorList confineVMinCPs_
tmp< tensorField > patchDxDbFace(const label patchI, const label cpI)
Get patch dx/db.
void computeParametricCoordinates(const vectorField &points)
bool bound(vector &vec, scalar minValue=1e-7, scalar maxValue=0.999999)
Bound components to certain limits.
label nUSymmetry() const
Get number of variables if CPs are moved symmetrically in U.
const fvMesh & mesh_
Definition: NURBS3DVolume.H:83
autoPtr< labelList > mapPtr_
Map of points-in-box to mesh points.
declareRunTimeSelectionTable(autoPtr, NURBS3DVolume, dictionary,(const dictionary &dict, const fvMesh &mesh, bool computeParamCoors),(dict, mesh, computeParamCoors))
vector volumeDerivativeU(const scalar u, const scalar v, const scalar w) const
Volume point derivative wrt u at point u,v,w.
void confineBoundaryControlPoints()
Confine movement in boundary control points if necessary.
const labelList & getMap()
Get map of points in box to mesh points.
scalar tolerance_
Tolerance for Newton-Raphson.
Definition: NURBS3DVolume.H:95
Vector< label > nCPsPerDirection() const
Get number of control points per direction.
virtual bool writeData(Ostream &os) const
Write the control points to support restart.
scalar computeMaxBoundaryDisplacement(const vectorField &controlPointsMovement, const labelList &patchesToBeMoved)
Compute max. displacement at the boundary.
boolVectorList confineVMaxCPs_
void findPointsInBox(const vectorField &meshPoints)
Find points within control points box.
Definition: NURBS3DVolume.C:50
tmp< vectorField > computeNewBoundaryPoints(const vectorField &controlPointsMovement, const labelList &patchesToBeMoved, const bool moveCPs=true)
Boundary mesh movement based on given control point movement.
boolVectorList confineWMaxCPs_
const boolList & getActiveDesignVariables() const
Which design variables are active?
vectorField localSystemCoordinates_
Coordinates in the local system for which CPs are defined.
boolVectorList confineUMaxCPs_
vectorField computeControlPointSensitivities(const pointVectorField &pointSens, const labelList &sensitivityPatchIDs)
boolVectorList confineUMinCPs_
Which movement components to freeze in each plane.
const pointVectorField & getParametricCoordinates()
Get parametric coordinates.
tmp< volTensorField > getDxCellsDb(const label cpI)
Get dxCartesiandb for a certain control point on cells.
virtual tensor transformationTensorDxDb(label globalPointIndex)=0
autoPtr< labelList > reverseMapPtr_
Map of mesh points to points-in-box.
label nVSymmetry() const
Get number of variables if CPs are moved symmetrically in V.
tmp< pointTensorField > getDxDb(const label cpI)
Get dxCartesiandb for a certain control point.
NURBS3DVolume(const NURBS3DVolume &)
Construct as copy.
virtual ~NURBS3DVolume()=default
Destructor.
bool confineVMovement() const
void makeFolders()
Create folders to store cps and derivatives.
void writeCps(const fileName &="cpsFile", const bool transform=true) const
boolList activeDesignVariables_
Which design variables are changed in an optimisation.
tmp< tensorField > patchDxDb(const label patchI, const label cpI)
Get patch dx/db.
tmp< vectorField > getPointsInBox()
Get mesh points that reside within the control points box.
vector volumeDerivativeV(const scalar u, const scalar v, const scalar w) const
Volume point derivative wrt v at point u,v,w.
virtual vector transformPointToCartesian(const vector &localCoordinates) const =0
Transform a point from its coordinate system to a cartesian system.
tmp< tensorField > dndbBasedSensitivities(const label patchI, const label cpI, bool DimensionedNormalSens=true)
string cpsFolder_
Folder to store control points.
NURBSbasis basisU_
NURBS basis functions.
Definition: NURBS3DVolume.H:87
void confineControlPoint(const label cpI)
Confine all three movements for a prescribed control point.
bool confineWMovement() const
const dictionary & dict() const
Get dictionary.
Vector< label > nSymmetry() const
vectorField cps_
The volumetric B-Splines control points.
const NURBSbasis & basisV() const
void boundControlPointMovement(vectorField &controlPointsMovement) const
void continuityRealatedConfinement()
Confine control point movement to maintain user-defined continuity.
label getCPID(const label i, const label j, const label k) const
Get control point ID from its I-J-K coordinates.
autoPtr< pointVectorField > parametricCoordinatesPtr_
Parametric coordinates of pointsInBox.
scalar volumeDerivativeCP(const vector &u, const label cpI) const
Volume point derivative wrt to control point cpI at point u,v,w.
label confineBoundaryControlPoints_
const NURBSbasis & basisW() const
const fvMesh & mesh() const
Get mesh.
label nWSymmetry() const
Get number of variables if CPs are moved symmetrically in W.
void writeParamCoordinates() const
Write parametric coordinates.
void determineActiveDesignVariablesAndPoints()
Create lists with active design variables and control points.
tmp< vectorField > coordinates(const vectorField &uVector) const
tmp< vectorField > computeNewPoints(const vectorField &controlPointsMovement)
Mesh movement based on given control point movement.
const word & name() const
Get box name.
List< boolVector > boolVectorList
Definition: NURBS3DVolume.H:81
bool confineUMovement() const
Get confine movements.
const boolList & getActiveCPs() const
Which control points are active?
tensor JacobianUVW(const vector &u) const
Jacobian matrix wrt to the volume parametric coordinates.
void setControlPoints(const vectorField &newCps)
Set new control points.
boolList activeControlPoints_
Which of the cps are moved in an optimisation.
const labelList & getReverseMap()
TypeName("NURBS3DVolume")
Runtime type information.
const NURBSbasis & basisU() const
Get basis functions.
const vectorField & getControlPoints() const
Get control points.
vector volumeDerivativeW(const scalar u, const scalar v, const scalar w) const
Volume point derivative wrt w at point u,v,w.
void confineControlPointsDirections()
Confine movement in all control points for user-defined directions.
NURBSbasis function. Used to construct NURBS curves, surfaces and volumes.
Definition: NURBSbasis.H:56
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Specialized bundling of boolean values as a vector of 3 components, element access using x(),...
Definition: boolVector.H:59
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for handling file names.
Definition: fileName.H:76
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
localIOdictionary is derived from IOdictionary but excludes parallel master reading.
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
const pointField & points
Namespace for OpenFOAM.
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:536
#define declareRunTimeSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection (variables and adder classes)
volScalarField & e
Definition: createFields.H:11
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73