volBSplinesBase.C
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-2019 PCOpt/NTUA
9  Copyright (C) 2013-2019 FOSS GP
10  Copyright (C) 2019 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 \*---------------------------------------------------------------------------*/
29 
30 #include "volBSplinesBase.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 defineTypeNameAndDebug(volBSplinesBase, 0);
40 
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 
43 volBSplinesBase::volBSplinesBase
44 (
45  const fvMesh& mesh
46 )
47 :
49  volume_(0),
50  activeDesignVariables_(0)
51 {
52  const dictionary NURBSdict
53  (
55  (
56  IOobject
57  (
58  "dynamicMeshDict",
59  mesh.time().constant(),
60  mesh,
63  false
64  )
65  ).subDict("volumetricBSplinesMotionSolverCoeffs")
66  );
67  // Read box names and allocate size
68  wordList controlBoxes(NURBSdict.toc());
69  volume_.setSize(controlBoxes.size());
70 
71  // Populate NURBS volumes
72  label iBox(0);
73  for (const word& boxName : controlBoxes)
74  {
75  if (NURBSdict.isDict(boxName))
76  {
77  volume_.set
78  (
79  iBox,
81  (
82  NURBSdict.subDict(boxName),
83  mesh,
84  true
85  )
86  );
87  volume_[iBox].write();
88  iBox++;
89  }
90  }
91  volume_.setSize(iBox);
92 
93  // Determine active design variables
94  activeDesignVariables_.setSize(3*getTotalControlPointsNumber(), -1);
95  label iActive(0);
96  const labelList startCpID(getStartCpID());
97  forAll(volume_, boxI)
98  {
99  const label start(3*startCpID[boxI]);
100  const boolList& isActiveVar = volume_[boxI].getActiveDesignVariables();
101  forAll(isActiveVar, varI)
102  {
103  if (isActiveVar[varI])
104  {
105  activeDesignVariables_[iActive++] = start + varI;
106  }
107  }
108  }
109  activeDesignVariables_.setSize(iActive);
110 }
111 
112 
113 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114 
116 {
117  return volume_;
118 }
119 
120 
122 {
123  return volume_;
124 }
125 
126 
127 const NURBS3DVolume& volBSplinesBase::box(const label boxI) const
128 {
129  return volume_[boxI];
130 }
131 
132 
134 {
135  return volume_[boxI];
136 }
137 
138 
140 {
141  return volume_[iNURB].getControlPoints();
142 }
143 
144 
146 {
147  vectorField totalCPs(0);
148  forAll(volume_, iNURB)
149  {
150  totalCPs.append(volume_[iNURB].getControlPoints());
151  }
152 
153  return totalCPs;
154 }
155 
156 
158 {
159  label nCPs(0);
160  forAll(volume_, iNURB)
161  {
162  nCPs += volume_[iNURB].getControlPoints().size();
163  }
164 
165  return nCPs;
166 }
167 
168 
170 {
171  return volume_.size();
172 }
173 
174 
176 {
177  // Allocate an extra entry to track in which box a CP might be
178  labelList startID(getNumberOfBoxes() + 1);
179  startID[0] = 0;
180  forAll(volume_, iNURB)
181  {
182  startID[iNURB+1] =
183  startID[iNURB] + volume_[iNURB].getControlPoints().size();
184  }
185 
186  return startID;
187 }
188 
189 
191 {
192  return activeDesignVariables_;
193 }
194 
195 
197 (
198  const vectorField& controlPointsMovement,
199  const labelList& patchesToBeMoved
200 )
201 {
202  scalar maxDisplacement(0);
203  label pastControlPoints(0);
204  forAll(volume_, iNURB)
205  {
206  const label nb = volume_[iNURB].getControlPoints().size();
207  vectorField localControlPointsMovement(nb, Zero);
208 
209  // Set localControlPointsMovement
210  forAll(localControlPointsMovement, iCPM)
211  {
212  localControlPointsMovement[iCPM] =
213  controlPointsMovement[pastControlPoints + iCPM];
214  }
215 
216  maxDisplacement = max
217  (
218  maxDisplacement,
219  volume_[iNURB].computeMaxBoundaryDisplacement
220  (
221  localControlPointsMovement,
222  patchesToBeMoved
223  )
224  );
225 
226  pastControlPoints += nb;
227  }
228 
229  return maxDisplacement;
230 }
231 
232 
234 (
235  vectorField& controlPointsMovement
236 )
237 {
238  label pastControlPoints(0);
239  forAll(volume_, iNURB)
240  {
241  label nb = volume_[iNURB].getControlPoints().size();
242  vectorField localControlPointsMovement(nb, Zero);
243 
244  // set localControlPointsMovement
245  forAll (localControlPointsMovement, iCPM)
246  {
247  localControlPointsMovement[iCPM] =
248  controlPointsMovement[pastControlPoints + iCPM];
249  }
250 
251  volume_[iNURB].boundControlPointMovement(localControlPointsMovement);
252 
253  // transfer bounding back to controlPointMovement
254  forAll(localControlPointsMovement, iCPM)
255  {
256  controlPointsMovement[pastControlPoints + iCPM] =
257  localControlPointsMovement[iCPM];
258  }
259 
260  pastControlPoints += nb;
261  }
262 }
263 
264 
266 (
267  const vectorField& controlPointsMovement
268 )
269 {
270  label pastControlPoints(0);
271  forAll(volume_, iNURB)
272  {
273  const label nb = volume_[iNURB].getControlPoints().size();
274  vectorField localControlPointsMovement(nb, Zero);
275 
276  // set localControlPointsMovement
277  forAll (localControlPointsMovement, iCPM)
278  {
279  localControlPointsMovement[iCPM] =
280  controlPointsMovement[pastControlPoints + iCPM];
281  }
282 
283  const vectorField newCps
284  (
285  volume_[iNURB].getControlPoints()
286  + localControlPointsMovement
287  );
288 
289  volume_[iNURB].setControlPoints(newCps);
290 
291  pastControlPoints += nb;
292  }
293 }
294 
295 
297 {
298  for (const NURBS3DVolume& box : volume_)
299  {
300  box.writeCps("cpsBsplines"+mesh_.time().timeName());
301  box.writeCpsInDict();
302  }
303 }
304 
305 
307 {
308  // Does nothing
309  return true;
310 }
311 
312 
314 {
315  // Does nothing
316 }
317 
318 
319 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
320 
321 } // End namespace Foam
322 
323 // ************************************************************************* //
Foam::volBSplinesBase::activeDesignVariables_
labelList activeDesignVariables_
Active design variables numbering for all boxes.
Definition: volBSplinesBase.H:72
Foam::volBSplinesBase::movePoints
virtual bool movePoints()
Dummy function required by MeshObject.
Definition: volBSplinesBase.C:306
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
Foam::volBSplinesBase::boxRef
NURBS3DVolume & boxRef(const label boxI)
Get non-const reference to a specific box.
Definition: volBSplinesBase.C:133
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::volBSplinesBase::getAllControlPoints
vectorField getAllControlPoints() const
Get control points from all boxes.
Definition: volBSplinesBase.C:145
Foam::NURBS3DVolume
NURBS3DVolume morpher. Includes support functions for gradient computations Base class providing supp...
Definition: NURBS3DVolume.H:71
Foam::volBSplinesBase::box
const NURBS3DVolume & box(const label boxI) const
Get const reference to a specific box.
Definition: volBSplinesBase.C:127
Foam::volBSplinesBase::getActiveDesignVariables
const labelList & getActiveDesignVariables() const
Get active design variables.
Definition: volBSplinesBase.C:190
Foam::volBSplinesBase::moveControlPoints
void moveControlPoints(const vectorField &controlPointsMovement)
Move control points. No effect on mesh.
Definition: volBSplinesBase.C:266
Foam::volBSplinesBase::boxes
const PtrList< NURBS3DVolume > & boxes() const
Get const reference to the vol. B-splines boxes.
Definition: volBSplinesBase.C:115
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::volBSplinesBase::boundControlPointsMovement
void boundControlPointsMovement(vectorField &controlPointsMovement)
Bound control points movement.
Definition: volBSplinesBase.C:234
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::Field< vector >
Foam::volBSplinesBase::getTotalControlPointsNumber
label getTotalControlPointsNumber() const
Get cumulative number of control points from all boxes.
Definition: volBSplinesBase.C:157
Foam::volBSplinesBase::getControlPoints
const vectorField & getControlPoints(const label &iNURB) const
Get reference to control points.
Definition: volBSplinesBase.C:139
Foam::dictionary::subDict
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:523
Foam::volBSplinesBase::getNumberOfBoxes
label getNumberOfBoxes() const
Get number of boxes.
Definition: volBSplinesBase.C:169
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:65
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::volBSplinesBase::boxesRef
PtrList< NURBS3DVolume > & boxesRef()
Get non-const reference to the vol. B-splines boxes.
Definition: volBSplinesBase.C:121
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
volBSplinesBase.H
Foam::volBSplinesBase::volume_
PtrList< NURBS3DVolume > volume_
List with volumetric B-splines boxes.
Definition: volBSplinesBase.H:69
Foam::volBSplinesBase::computeMaxBoundaryDisplacement
scalar computeMaxBoundaryDisplacement(const vectorField &controlPointsMovement, const labelList &patchesToBeMoved)
Definition: volBSplinesBase.C:197
Foam::volBSplinesBase::getStartCpID
labelList getStartCpID() const
Get start CP ID for each box.
Definition: volBSplinesBase.C:175
Foam::List< word >
Foam::start
label ListType::const_reference const label start
Definition: ListOps.H:408
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:121
Foam::volBSplinesBase::updateMesh
virtual void updateMesh(const mapPolyMesh &)
Dummy function required by MeshObject.
Definition: volBSplinesBase.C:313
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:160
Foam::NURBS3DVolume::New
static autoPtr< NURBS3DVolume > New(const dictionary &dict, const fvMesh &mesh, bool computeParamCoors=true)
Return a reference to the selected NURBS model.
Definition: NURBS3DVolume.C:802
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:246
Foam::MeshObject< fvMesh, UpdateableMeshObject, volBSplinesBase >
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:88
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::volBSplinesBase::writeControlPoints
void writeControlPoints() const
Write control points to constant and optimisation folders.
Definition: volBSplinesBase.C:296