optMeshMovementVolumetricBSplinesExternalMotionSolver.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-2020 PCOpt/NTUA
9  Copyright (C) 2013-2020 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 
32 
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
39  (
40  optMeshMovementVolumetricBSplinesExternalMotionSolver,
41  0
42  );
44  (
45  optMeshMovement,
46  optMeshMovementVolumetricBSplinesExternalMotionSolver,
47  dictionary
48  );
49 }
50 
51 
52 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
53 
56 (
57  const scalarField& correction
58 )
59 {
60  const label nCPs(volBSplinesBase_.getTotalControlPointsNumber());
61  dx_.primitiveFieldRef() = vector::zero;
62  cpMovement_ = vector::zero;
63 
64  for (label iCP = 0; iCP < nCPs; iCP++)
65  {
66  cpMovement_[iCP].x() = correction[3*iCP];
67  cpMovement_[iCP].y() = correction[3*iCP + 1];
68  cpMovement_[iCP].z() = correction[3*iCP + 2];
69  }
70 
71  // Bound control point movement for non-active CPs
72  volBSplinesBase_.boundControlPointMovement(cpMovement_);
73 
74  // Compute boundary movement
75  label passedCPs(0);
76  PtrList<NURBS3DVolume>& boxes = volBSplinesBase_.boxesRef();
77  forAll(boxes, iNURB)
78  {
79  const label nb = boxes[iNURB].getControlPoints().size();
80  for (label cpI = 0; cpI < nb; ++cpI)
81  {
82  const label globalCP = passedCPs + cpI;
83  forAll(patchIDs_, pI)
84  {
85  const label patchI = patchIDs_[pI];
86  vectorField boundaryMovement
87  (
88  boxes[iNURB].patchDxDb(patchI, cpI)
89  & cpMovement_[globalCP]
90  );
91  dx_.boundaryField()[patchI].addToInternalField
92  (
93  dx_.primitiveFieldRef(),
94  boundaryMovement
95  );
96  }
97  }
98 
99  // Increment number of passed sensitivities
100  passedCPs += nb;
101  }
102 }
103 
104 
105 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
106 
107 Foam::optMeshMovementVolumetricBSplinesExternalMotionSolver::
108 optMeshMovementVolumetricBSplinesExternalMotionSolver
109 (
110  fvMesh& mesh,
111  const dictionary& dict,
112  const labelList& patchIDs
113 )
114 :
115  optMeshMovement(mesh, dict, patchIDs),
116  volBSplinesBase_
117  (
119  ),
120  dx_
121  (
122  IOobject
123  (
124  "dx",
125  mesh.time().timeName(),
126  mesh,
127  IOobject::NO_READ,
128  IOobject::NO_WRITE,
129  false
130  ),
133  ),
134  cpMovement_(volBSplinesBase_.getTotalControlPointsNumber(), Zero)
135 {}
136 
137 
138 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
139 
141 {
142  // Compute boundary movement
144 
145  // Set boundary movement of motion solver
146  displMethodPtr_->setMotionField(dx_);
147 
148  // Positions of control points have not changed since only the boundary dx
149  // has been computed.
150  // Use correction to update them
152 
153  // Write control points to files
155 
156  // Move the mesh and check quality
158 }
159 
160 
161 Foam::scalar
163 (
164  const scalarField& correction
165 )
166 {
167  computeBoundaryMovement(correction);
168 
169  // Get maximum boundary movement
170  scalar maxDisplacement = gMax(mag(dx_.primitiveField()));
171 
172  // Compute eta value
173  Info<< "maxAllowedDisplacement/maxDisplacement \t"
174  << getMaxAllowedDisplacement() << "/" << maxDisplacement << endl;
175  scalar eta = getMaxAllowedDisplacement() / maxDisplacement;
176  Info<< "Setting eta value to " << eta << endl;
177 
178  return eta;
179 }
180 
181 
184 const
185 {
186  return volBSplinesBase_.getActiveDesignVariables();
187 }
188 
189 
190 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::optMeshMovement::displMethodPtr_
autoPtr< displacementMethod > displMethodPtr_
Definition: optMeshMovement.H:91
Foam::volBSplinesBase
Class constructing a number of volumetric B-Splines boxes, read from dynamicMeshDict....
Definition: volBSplinesBase.H:59
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::correction
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Foam::optMeshMovementVolumetricBSplinesExternalMotionSolver::cpMovement_
vectorField cpMovement_
Movement of control points.
Definition: optMeshMovementVolumetricBSplinesExternalMotionSolver.H:70
Foam::volBSplinesBase::moveControlPoints
void moveControlPoints(const vectorField &controlPointsMovement)
Move control points. No effect on mesh.
Definition: volBSplinesBase.C:284
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::dimensionedVector
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
Definition: dimensionedVector.H:50
Foam::optMeshMovementVolumetricBSplinesExternalMotionSolver::computeEta
virtual scalar computeEta(const scalarField &correction)
Compute eta value based on max displacement.
Definition: optMeshMovementVolumetricBSplinesExternalMotionSolver.C:163
Foam::optMeshMovementVolumetricBSplinesExternalMotionSolver::getActiveDesignVariables
virtual labelList getActiveDesignVariables() const
Return active design variables.
Definition: optMeshMovementVolumetricBSplinesExternalMotionSolver.C:183
Foam::Field< scalar >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::optMeshMovementVolumetricBSplinesExternalMotionSolver::volBSplinesBase_
volBSplinesBase & volBSplinesBase_
Reference to underlaying volumetric B-Splines morpher.
Definition: optMeshMovementVolumetricBSplinesExternalMotionSolver.H:64
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
optMeshMovementVolumetricBSplinesExternalMotionSolver.H
Foam::optMeshMovementVolumetricBSplinesExternalMotionSolver::moveMesh
void moveMesh()
Calculates surface mesh movement.
Definition: optMeshMovementVolumetricBSplinesExternalMotionSolver.C:140
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::optMeshMovementVolumetricBSplinesExternalMotionSolver::dx_
pointVectorField dx_
Boundary movement due to change of NURBS control points.
Definition: optMeshMovementVolumetricBSplinesExternalMotionSolver.H:67
Foam::optMeshMovement::moveMesh
virtual void moveMesh()
Definition: optMeshMovement.C:128
Foam::optMeshMovementVolumetricBSplinesExternalMotionSolver::computeBoundaryMovement
void computeBoundaryMovement(const scalarField &correction)
Definition: optMeshMovementVolumetricBSplinesExternalMotionSolver.C:56
Foam::List< label >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::optMeshMovement::correction_
scalarField correction_
Correction of design variables.
Definition: optMeshMovement.H:81
Foam::optMeshMovement
Abstract base class for translating an update of the design variables into mesh movement.
Definition: optMeshMovement.H:54
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::gMax
Type gMax(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:592
Foam::dimless
const dimensionSet dimless
Dimensionless.
Definition: dimensionSets.C:189
Foam::volBSplinesBase::writeControlPoints
void writeControlPoints() const
Write control points to constant and optimisation folders.
Definition: volBSplinesBase.C:314