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 -------------------------------------------------------------------------------
12 License
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 
28 Class
29  Foam::NURBS3DVolume
30 
31 Description
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 
48 SourceFiles
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 
67 namespace Foam
68 {
69 
70 /*---------------------------------------------------------------------------*\
71  Class NURBS3DVolume Declaration
72 \*---------------------------------------------------------------------------*/
73 
74 class NURBS3DVolume
75 :
76  public localIOdictionary
77 {
78 protected:
79 
80  // Protected Data
81 
83 
84  const fvMesh& mesh_;
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
121 
122  label confineVMovement_;
123 
124  label confineWMovement_;
127 
128  //- Which movement components to freeze in each plane
132 
134 
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_;
150  //- Read parametric coordinates from file if present in the folder
152 
154  // Protected Member Functions
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
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 
213 public:
214 
215  //- Runtime type information
216  TypeName("NURBS3DVolume");
217 
218 
219  // Declare run-time constructor selection table
220 
222  (
223  autoPtr,
225  dictionary,
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 
461  inline vectorField& getControlPoints();
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 // ************************************************************************* //
void continuityRealatedConfinement()
Confine control point movement to maintain user-defined continuity.
label maxIter_
Max iterations for Newton-Raphson.
Definition: NURBS3DVolume.H:92
vector volumeDerivativeU(const scalar u, const scalar v, const scalar w) const
Volume point derivative wrt u at point u,v,w.
label nWSymmetry() const
Get number of variables if CPs are moved symmetrically in W.
declareRunTimeSelectionTable(autoPtr, NURBS3DVolume, dictionary,(const dictionary &dict, const fvMesh &mesh, bool computeParamCoors),(dict, mesh, computeParamCoors))
tmp< vectorField > getPointsInBox()
Get mesh points that reside within the control points box.
A class for handling file names.
Definition: fileName.H:71
vectorField localSystemCoordinates_
Coordinates in the local system for which CPs are defined.
string cpsFolder_
Folder to store control points.
autoPtr< labelList > reverseMapPtr_
Map of mesh points to points-in-box.
tmp< tensorField > patchDxDb(const label patchI, const label cpI)
Get patch dx/db.
boolVectorList confineWMinCPs_
bool confineWMovement() const
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
boolVectorList confineWMaxCPs_
void confineControlPoint(const label cpI)
Confine all three movements for a prescribed control point.
scalar minValue
boolVectorList confineVMinCPs_
const fvMesh & mesh() const
Get mesh.
vectorField cps_
The volumetric B-Splines control points.
const NURBSbasis & basisW() const
tmp< tensorField > dndbBasedSensitivities(const label patchI, const label cpI, bool DimensionedNormalSens=true)
Part of control point sensitivities related to the face normal variations.
autoPtr< labelList > mapPtr_
Map of points-in-box to mesh points.
const NURBSbasis & basisU() const
Get basis functions.
tmp< tensorField > patchDxDbFace(const label patchI, const label cpI)
Get patch dx/db.
bool readStoredData_
Read parametric coordinates from file if present in the folder.
label k
Boltzmann constant.
label nUSymmetry() const
Get number of variables if CPs are moved symmetrically in U.
const pointVectorField & getParametricCoordinates()
Get parametric coordinates.
NURBS3DVolume morpher. Includes support functions for gradient computations Base class providing supp...
Definition: NURBS3DVolume.H:69
const boolList & getActiveDesignVariables() const
Which design variables are active?
static autoPtr< NURBS3DVolume > New(const dictionary &dict, const fvMesh &mesh, bool computeParamCoors=true)
Return a reference to the selected NURBS model.
virtual tensor transformationTensorDxDb(label globalPointIndex)=0
Transformation tensor for dxdb, from local coordinate system to cartesian.
localIOdictionary is derived from IOdictionary but excludes parallel master reading.
vectorField computeControlPointSensitivities(const pointVectorField &pointSens, const labelList &sensitivityPatchIDs)
Control point sensitivities computed using point-based surface sensitivities.
void determineActiveDesignVariablesAndPoints()
Create lists with active design variables and control points.
void makeFolders()
Create folders to store cps and derivatives.
scalar maxValue
const fvMesh & mesh_
Definition: NURBS3DVolume.H:79
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
tensor JacobianUVW(const vector &u) const
Jacobian matrix wrt to the volume parametric coordinates.
const pointField & points
void writeParamCoordinates() const
Write parametric coordinates.
A class for handling words, derived from Foam::string.
Definition: word.H:63
boolVectorList confineUMinCPs_
Which movement components to freeze in each plane.
virtual bool writeData(Ostream &os) const
Write the control points to support restart.
void setControlPoints(const vectorField &newCps)
Set new control points.
tmp< vectorField > computeNewBoundaryPoints(const vectorField &controlPointsMovement, const labelList &patchesToBeMoved, const bool moveCPs=true)
Boundary mesh movement based on given control point movement.
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:51
vector volumeDerivativeV(const scalar u, const scalar v, const scalar w) const
Volume point derivative wrt v at point u,v,w.
scalar tolerance_
Tolerance for Newton-Raphson.
Definition: NURBS3DVolume.H:97
void findPointsInBox(const vectorField &meshPoints)
Find points within control points box.
Definition: NURBS3DVolume.C:43
label getCPID(const label i, const label j, const label k) const
Get control point ID from its I-J-K coordinates.
void boundControlPointMovement(vectorField &controlPointsMovement) const
Bound control points movement in the boundary control points and in certain directions if needed...
Vector< label > nCPsPerDirection() const
Get number of control points per direction.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
label nVSymmetry() const
Get number of variables if CPs are moved symmetrically in V.
void writeCps(const fileName &="cpsFile", const bool transform=true) const
Write control points on a cartesian coordinates system for visualization.
Vector< label > nSymmetry() const
Get number of variables per direction, if CPs are moved symmetrically.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
Specialized bundling of boolean values as a vector of 3 components, element access using x()...
Definition: boolVector.H:52
OBJstream os(runTime.globalPath()/outputName)
tmp< vectorField > coordinates(const vectorField &uVector) const
Compute cartesian coordinates based on control points and parametric coordinates. ...
boolVectorList confineVMaxCPs_
void computeParametricCoordinates(const vectorField &points)
Compute parametric coordinates in order to match a given set of coordinates, based on the cps of the ...
Definition: NURBS3DVolume.C:98
label confineBoundaryControlPoints_
virtual void updateLocalCoordinateSystem(const vectorField &cartesianPoints)=0
Update coordinates in the local system based on the cartesian points.
label nMaxBound_
How many times to bound parametric coordinates until deciding it is outside the box.
tmp< vectorField > computeNewPoints(const vectorField &controlPointsMovement)
Mesh movement based on given control point movement.
virtual ~NURBS3DVolume()=default
Destructor.
Useful typenames for fields defined only at the boundaries.
const labelList & getMap()
Get map of points in box to mesh points.
void confineBoundaryControlPoints()
Confine movement in boundary control points if necessary.
TypeName("NURBS3DVolume")
Runtime type information.
autoPtr< pointVectorField > parametricCoordinatesPtr_
Parametric coordinates of pointsInBox.
const NURBSbasis & basisV() const
boolList activeDesignVariables_
Which design variables are changed in an optimisation.
vector volumeDerivativeW(const scalar u, const scalar v, const scalar w) const
Volume point derivative wrt w at point u,v,w.
List< boolVector > boolVectorList
Definition: NURBS3DVolume.H:77
NURBS3DVolume(const dictionary &dict, const fvMesh &mesh, bool computeParamCoors=true)
Construct from dictionary.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:79
const word & name() const
Get box name.
scalar computeMaxBoundaryDisplacement(const vectorField &controlPointsMovement, const labelList &patchesToBeMoved)
Compute max. displacement at the boundary.
bool confineUMovement() const
Get confine movements.
const boolList & getActiveCPs() const
Which control points are active?
const labelList & getReverseMap()
Get map of mesh points to points in box. Return -1 if point is outside the box.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
bool confineVMovement() const
label confineUMovement_
Confine movement in certain directions and control points. Refers to the local system.
tmp< pointTensorField > getDxDb(const label cpI)
Get dxCartesiandb for a certain control point.
tmp< volTensorField > getDxCellsDb(const label cpI)
Get dxCartesiandb for a certain control point on cells.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
boolVectorList confineUMaxCPs_
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:521
Tensor of scalars, i.e. Tensor<scalar>.
NURBSbasis basisU_
NURBS basis functions.
Definition: NURBS3DVolume.H:85
const vectorField & getControlPoints() const
Get control points.
const dictionary & dict() const
Get dictionary.
virtual vector transformPointToCartesian(const vector &localCoordinates) const =0
Transform a point from its coordinate system to a cartesian system.
boolList activeControlPoints_
Which of the cps are moved in an optimisation.
Namespace for OpenFOAM.
bool bound(vector &vec, scalar minValue=1e-7, scalar maxValue=0.999999)
Bound components to certain limits.
scalar volumeDerivativeCP(const vector &u, const label cpI) const
Volume point derivative wrt to control point cpI at point u,v,w.