sensitivitySurfacePointsIncompressible.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-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 \*---------------------------------------------------------------------------*/
29 
32 #include "syncTools.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 namespace incompressible
40 {
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 defineTypeNameAndDebug(sensitivitySurfacePoints, 0);
46 (
47  adjointSensitivity,
48  sensitivitySurfacePoints,
49  dictionary
50 );
51 
52 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
53 
55 {
57  dict().getOrDefault<bool>("includeSurfaceArea", false);
59  dict().getOrDefault<bool>("includePressure", true);
61  dict().getOrDefault<bool>("includeGradStressTerm", true);
63  dict().getOrDefault<bool>("includeTransposeStresses", true);
65  dict().getOrDefault<bool>("useSnGradInTranposeStresses", false);
67  dict().getOrDefault<bool>("includeDivTerm", false);
69  dict().getOrDefault<bool>
70  (
71  "includeDistance",
72  adjointVars_.adjointTurbulence().ref().includeDistance()
73  );
75  dict().getOrDefault<bool>("includeMeshMovement", true);
77  dict().getOrDefault<bool>("includeObjectiveContribution", true);
78 
79  // Allocate new solvers if necessary
81  {
82  eikonalSolver_.reset
83  (
85  (
86  mesh_,
87  dict(),
90  sensitivityPatchIDs_
91  )
92  );
93  }
94 
96  {
98  (
100  (
101  mesh_,
102  dict(),
103  *this,
104  sensitivityPatchIDs_,
106  )
107  );
108  }
109 }
110 
111 
113 {
114  // Solve extra equations if necessary
115  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116  autoPtr<boundaryVectorField> distanceSensPtr(nullptr);
117  if (includeDistance_)
118  {
119  eikonalSolver_->solve();
120  distanceSensPtr.reset(createZeroBoundaryPtr<vector>(mesh_));
121  const boundaryVectorField& sens =
122  eikonalSolver_->distanceSensitivities();
123  for (const label patchI : sensitivityPatchIDs_)
124  {
125  distanceSensPtr()[patchI] = sens[patchI];
126  }
127  }
128 
129  autoPtr<boundaryVectorField> meshMovementSensPtr(nullptr);
131  {
132  meshMovementSolver_->solve();
133  meshMovementSensPtr.reset(createZeroBoundaryPtr<vector>(mesh_));
134  const boundaryVectorField& sens =
135  meshMovementSolver_->meshMovementSensitivities();
136  for (const label patchI : sensitivityPatchIDs_)
137  {
138  meshMovementSensPtr()[patchI] = sens[patchI];
139  }
140  }
141 
142  // Add to other terms multiplying dxFace/dxPoints
143  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144  for (const label patchI : sensitivityPatchIDs_)
145  {
146  const fvPatch& patch = mesh_.boundary()[patchI];
147  tmp<vectorField> tnf = patch.nf();
148  const scalarField& magSf = patch.magSf();
149  // Distance related terms
150  if (includeDistance_)
151  {
152  wallFaceSens_()[patchI] += distanceSensPtr()[patchI];
153  }
154 
155  // Mesh movement related terms
157  {
158  wallFaceSens_()[patchI] += meshMovementSensPtr()[patchI];
159  }
160 
161  // Add local face area
162  //~~~~~~~~~~~~~~~~~~~~
163  // Sensitivities DO include locale surface area, to get
164  // the correct weighting from the contributions of various faces.
165  // Normalized at the end.
166  // dSfdbMult already includes the local area. No need to re-multiply
167  wallFaceSens_()[patchI] *= magSf;
168  dnfdbMult_()[patchI] *= magSf;
169  }
170 }
171 
172 
174 {
175  // Geometric (or "direct") sensitivities are better computed directly on
176  // the points. Compute them and add the ones that depend on dxFace/dxPoint
177  for (const label patchI : sensitivityPatchIDs_)
178  {
179  const fvPatch& patch = mesh_.boundary()[patchI];
180  vectorField nf(patch.nf());
181 
182  // Point sens result for patch
183  vectorField& pointPatchSens = wallPointSensVecPtr_()[patchI];
184 
185  // Face sens for patch
186  const vectorField& facePatchSens = wallFaceSens_()[patchI];
187 
188  // Geometry variances
189  const vectorField& dSfdbMultPatch = dSfdbMult_()[patchI];
190  const vectorField& dnfdbMultPatch = dnfdbMult_()[patchI];
191 
192  // Correspondance of local point addressing to global point addressing
193  const labelList& meshPoints = patch.patch().meshPoints();
194 
195  // List with mesh faces. Global addressing
196  const faceList& faces = mesh_.faces();
197 
198  // Each local patch point belongs to these local patch faces
199  // (local numbering)
200  const labelListList& patchPointFaces = patch.patch().pointFaces();
201 
202  // Index of first face in patch
203  const label patchStartIndex = patch.start();
204 
205  // Geometry differentiation engine
206  deltaBoundary dBoundary(mesh_);
207 
208  // Loop over patch points.
209  // Collect contributions from each boundary face this point belongs to
210  forAll(meshPoints, ppI)
211  {
212  const labelList& pointFaces = patchPointFaces[ppI];
213  forAll(pointFaces, pfI)
214  {
215  label localFaceIndex = pointFaces[pfI];
216  label globalFaceIndex = patchStartIndex + localFaceIndex;
217  const face& faceI = faces[globalFaceIndex];
218 
219  // Point coordinates. All indices in global numbering
220  pointField p(faceI.points(mesh_.points()));
221  tensorField p_d(faceI.size(), Zero);
222  forAll(faceI, facePointI)
223  {
224  if (faceI[facePointI] == meshPoints[ppI])
225  {
226  p_d[facePointI] = tensor::I;
227  }
228  }
229  tensorField deltaNormals =
230  dBoundary.makeFaceCentresAndAreas_d(p, p_d);
231 
232  // Element [0] is the variation in the face center
233  // (dxFace/dxPoint)
234  const tensor& deltaCf = deltaNormals[0];
235  pointPatchSens[ppI] += facePatchSens[localFaceIndex] & deltaCf;
236 
237  // Term multiplying d(Sf)/d(point displacement) and
238  // d(nf)/d(point displacement)
239  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
240  if (includeObjective_)
241  {
242  // Element [1] is the variation in the (dimensional) normal
243  const tensor& deltaSf = deltaNormals[1];
244  pointPatchSens[ppI] +=
245  dSfdbMultPatch[localFaceIndex] & deltaSf;
246 
247  // Element [2] is the variation in the unit normal
248  const tensor& deltaNf = deltaNormals[2];
249  pointPatchSens[ppI] +=
250  dnfdbMultPatch[localFaceIndex] & deltaNf;
251  }
252  }
253  }
254  }
255 }
256 
257 
259 (
260  vectorField& pointNormals,
261  scalarField& pointMagSf
262 )
263 {
264  for (const label patchI : sensitivityPatchIDs_)
265  {
266  const fvPatch& patch = mesh_.boundary()[patchI];
267  const scalarField& magSf = patch.magSf();
268  vectorField nf(patch.nf());
269 
270  // Correspondance of local point addressing to global point addressing
271  const labelList& meshPoints = patch.patch().meshPoints();
272 
273  // Each local patch point belongs to these local patch faces
274  // (local numbering)
275  const labelListList& patchPointFaces = patch.patch().pointFaces();
276 
277  // Loop over patch points
278  forAll(meshPoints, ppI)
279  {
280  const labelList& pointFaces = patchPointFaces[ppI];
281  forAll(pointFaces, pfI)
282  {
283  const label localFaceIndex = pointFaces[pfI];
284 
285  // Accumulate information for point normals
286  pointNormals[meshPoints[ppI]] += nf[localFaceIndex];
287  pointMagSf[meshPoints[ppI]] += magSf[localFaceIndex];
288  }
289  }
290  }
291 
293  (
294  mesh_,
295  pointNormals,
298  );
300  (
301  mesh_,
302  pointMagSf,
304  scalar(0)
305  );
306 }
307 
308 
310 {
311  word suffix(dict().getOrDefault<word>("suffix", word::null));
312  // Determine suffix for fields holding the sens
314  {
316  (
317  adjointVars_.solverName() + "ESI" + suffix
318  );
319  }
320  else
321  {
323  (
324  adjointVars_.solverName() + "SI" + suffix
325  );
326  }
327 }
328 
329 
330 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
331 
332 sensitivitySurfacePoints::sensitivitySurfacePoints
333 (
334  const fvMesh& mesh,
335  const dictionary& dict,
336  incompressibleVars& primalVars,
337  incompressibleAdjointVars& adjointVars,
339 )
340 :
342  (
343  mesh,
344  dict,
345  primalVars,
346  adjointVars,
348  ),
350  includeSurfaceArea_(false),
351  includePressureTerm_(false),
352  includeGradStressTerm_(false),
353  includeTransposeStresses_(false),
354  useSnGradInTranposeStresses_(false),
355  includeDivTerm_(false),
356  includeDistance_(false),
357  includeMeshMovement_(false),
358  includeObjective_(false),
359  eikonalSolver_(nullptr),
360  meshMovementSolver_(nullptr),
361  wallFaceSens_(createZeroBoundaryPtr<vector>(mesh_)),
362  dSfdbMult_(createZeroBoundaryPtr<vector>(mesh_)),
363  dnfdbMult_(createZeroBoundaryPtr<vector>(mesh_))
364 
365 {
366  read();
367 
368  // Allocate boundary field pointer
369  wallPointSensVecPtr_.reset(createZeroBoundaryPointFieldPtr<vector>(mesh_));
370  wallPointSensNormalPtr_.reset
371  (
372  createZeroBoundaryPointFieldPtr<scalar>(mesh_)
373  );
374  wallPointSensNormalVecPtr_.reset
375  (
376  createZeroBoundaryPointFieldPtr<vector>(mesh_)
377  );
378 
379  // Allocate appropriate space for sensitivities
380  label nTotalPoints(0);
381  for (const label patchI : sensitivityPatchIDs_)
382  {
383  label nPoints = mesh_.boundaryMesh()[patchI].nPoints();
384  nTotalPoints += returnReduce(nPoints, sumOp<label>());
385  }
386 
387  // Derivatives for all (x,y,z) components of the displacement are kept
388  derivatives_ = scalarField(3*nTotalPoints, Zero);
389 }
390 
391 
392 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
393 
395 {
397  {
398  if (eikonalSolver_)
399  {
400  eikonalSolver_().readDict(dict);
401  }
402 
404  {
405  meshMovementSolver_().readDict(dict);
406  }
407 
408  return true;
409  }
410 
411  return false;
412 }
413 
414 
416 {
417  // Grab references
418  const volScalarField& p = primalVars_.p();
419  const volVectorField& U = primalVars_.U();
420 
421  const volScalarField& pa = adjointVars_.pa();
422  const volVectorField& Ua = adjointVars_.Ua();
425 
426  DebugInfo
427  << " Calculating auxilary quantities " << endl;
428 
429  // Fields needed to calculate adjoint sensitivities
430  volScalarField nuEff(adjointTurbulence->nuEff());
431  volTensorField gradUa(fvc::grad(Ua));
432  volTensorField gradU(fvc::grad(U));
433 
434  // Explicitly correct the boundary gradient to get rid of the
435  // tangential component
436  forAll(mesh_.boundary(), patchI)
437  {
438  const fvPatch& patch = mesh_.boundary()[patchI];
439  if (isA<wallFvPatch>(patch))
440  {
441  tmp<vectorField> tnf = mesh_.boundary()[patchI].nf();
442  const vectorField& nf = tnf();
443  gradU.boundaryFieldRef()[patchI] =
444  nf*U.boundaryField()[patchI].snGrad();
445  }
446  }
447 
448  // Auxiliary terms
449  volVectorField gradp(fvc::grad(p));
450  volTensorField stress(nuEff*(gradU + T(gradU)));
451  autoPtr<volVectorField> stressXPtr
452  (
453  createZeroFieldPtr<vector>(mesh_, "stressX", stress.dimensions())
454  );
455  autoPtr<volVectorField> stressYPtr
456  (
457  createZeroFieldPtr<vector>(mesh_, "stressY", stress.dimensions())
458  );
459  autoPtr<volVectorField> stressZPtr
460  (
461  createZeroFieldPtr<vector>(mesh_, "stressZ", stress.dimensions())
462  );
463 
464  stressXPtr().replace(0, stress.component(0));
465  stressXPtr().replace(1, stress.component(1));
466  stressXPtr().replace(2, stress.component(2));
467 
468  stressYPtr().replace(0, stress.component(3));
469  stressYPtr().replace(1, stress.component(4));
470  stressYPtr().replace(2, stress.component(5));
471 
472  stressZPtr().replace(0, stress.component(6));
473  stressZPtr().replace(1, stress.component(7));
474  stressZPtr().replace(2, stress.component(8));
475 
476  volTensorField gradStressX(fvc::grad(stressXPtr()));
477  volTensorField gradStressY(fvc::grad(stressYPtr()));
478  volTensorField gradStressZ(fvc::grad(stressZPtr()));
479 
480  // Solve extra equations if necessary
481  if (includeDistance_)
482  {
483  eikonalSolver_->accumulateIntegrand(dt);
484  }
485 
486  autoPtr<boundaryVectorField> meshMovementSensPtr(nullptr);
488  {
489  meshMovementSolver_->accumulateIntegrand(dt);
490  }
491 
492  // Terms from the adjoint turbulence model
493  const boundaryVectorField& adjointTMsensitivities =
494  adjointTurbulence->wallShapeSensitivities();
495 
496  // Objective references
498 
499  DebugInfo
500  << " Calculating adjoint sensitivity. " << endl;
501 
502  // The face-based part of the sensitivities, i.e. terms that multiply
503  // dxFace/dxPoint.
504  for (const label patchI : sensitivityPatchIDs_)
505  {
506  const fvPatch& patch = mesh_.boundary()[patchI];
507  tmp<vectorField> tnf = patch.nf();
508  const vectorField& nf = tnf();
509 
510  // Adjoint stress term
511  // vectorField stressTerm
512  // (
513  // -(nf & DUa.boundaryField()[patchI])
514  // *nuEff.boundaryField()[patchI]
515  // & gradU.boundaryField()[patchI].T();
516  // )
517 
518  vectorField stressTerm
519  (
520  - (
521  Ua.boundaryField()[patchI].snGrad()
522  & U.boundaryField()[patchI].snGrad()
523  )
524  * nuEff.boundaryField()[patchI]
525  * nf
526  );
527 
528  vectorField gradStressTerm(patch.size(), Zero);
530  {
531  // Terms corresponding to contributions from converting delta to
532  // thetas are added through the corresponding adjoint boundary
533  // conditions instead of grabing contributions from the objective
534  // function. Useful to have a unified formulation for low- and
535  // high-re meshes
536  const fvPatchVectorField& Uab = Ua.boundaryField()[patchI];
537  gradStressTerm = (-((Uab & nf)*gradp.boundaryField()[patchI]));
538  gradStressTerm +=
539  (
540  Uab.component(0)*gradStressX.boundaryField()[patchI]
541  + Uab.component(1)*gradStressY.boundaryField()[patchI]
542  + Uab.component(2)*gradStressZ.boundaryField()[patchI]
543  ) & nf;
544  }
545 
547  {
548  vectorField gradUaNf
549  (
551  (Ua.boundaryField()[patchI].snGrad() & nf)*nf :
552  (gradUa.boundaryField()[patchI] & nf)
553  );
554  stressTerm -=
555  nuEff.boundaryField()[patchI]
556  *(gradUaNf & U.boundaryField()[patchI].snGrad())
557  *nf;
558  }
559 
560  if (includeDivTerm_)
561  {
562  stressTerm +=
563  scalar(1./3.)*nuEff.boundaryField()[patchI]
564  * (
565  ((Ua.boundaryField()[patchI].snGrad() &nf)*nf)
566  & U.boundaryField()[patchI].snGrad()
567  )
568  *nf;
569  }
570 
571  // Adjoint pressure terms
572  vectorField pressureTerm(patch.size(), Zero);
574  {
575  pressureTerm =
576  (
577  (nf * pa.boundaryField()[patchI])
578  & U.boundaryField()[patchI].snGrad()
579  )
580  *nf;
581  }
582 
583  vectorField dxdbMultiplierTot(patch.size(), Zero);
584  if (includeObjective_)
585  {
586  // Term from objectives multiplying dxdb
587  forAll(functions, funcI)
588  {
589  const scalar wei = functions[funcI].weight();
590  // dt added in wallFaceSens_
591  dxdbMultiplierTot +=
592  wei*functions[funcI].dxdbDirectMultiplier(patchI);
593 
594  // Fill in multipliers of d(Sf)/db and d(nf)/db
595  dSfdbMult_()[patchI] +=
596  wei*dt*functions[funcI].dSdbMultiplier(patchI);
597  dnfdbMult_()[patchI] +=
598  wei*dt*functions[funcI].dndbMultiplier(patchI);
599  }
600  }
601 
602  // Fill in dxFace/dxPoint multiplier.
603  // Missing geometric contributions which are directly computed on the
604  // points
605  wallFaceSens_()[patchI] +=
606  (
607  stressTerm
608  + gradStressTerm
609  + pressureTerm
610  + adjointTMsensitivities[patchI]
611  + dxdbMultiplierTot
612  )*dt;
613  }
614 }
615 
616 
618 {
619  // Add remaining parts to term multiplying dxFace/dxPoints
620  // Solves for post-processing PDEs
622 
623  // Geometric (or "direct") sensitivities are better computed directly on
624  // the points. Compute them and add the ones that depend on dxFace/dxPoint
626 
627  // polyPatch::pointNormals will give the wrong result for points
628  // belonging to multiple patches or patch-processorPatch intersections.
629  // Keeping a mesh-wide field to allow easy reduction using syncTools.
630  // A bit expensive? Better way?
631  vectorField pointNormals(mesh_.nPoints(), Zero);
632  scalarField pointMagSf(mesh_.nPoints(), Zero);
633  constructGlobalPointNormalsAndAreas(pointNormals, pointMagSf);
634 
635  // Do parallel communications to avoid wrong values at processor boundaries
636  // Global field for accumulation
637  vectorField pointSensGlobal(mesh_.nPoints(), Zero);
638  for (const label patchI : sensitivityPatchIDs_)
639  {
640  const labelList& meshPoints = mesh_.boundaryMesh()[patchI].meshPoints();
641  forAll(meshPoints, ppI)
642  {
643  const label globaPointI = meshPoints[ppI];
644  pointSensGlobal[globaPointI] +=
645  wallPointSensVecPtr_()[patchI][ppI];
646  }
647  }
648 
649  // Accumulate dJ/dx_i
651  (
652  mesh_,
653  pointSensGlobal,
656  );
657 
658  // Transfer back to local fields
659  for (const label patchI : sensitivityPatchIDs_)
660  {
661  const labelList& meshPoints =
662  mesh_.boundaryMesh()[patchI].meshPoints();
663  wallPointSensVecPtr_()[patchI].map(pointSensGlobal, meshPoints);
664  }
665 
666  // Compute normal sens and append to return field
667  label nPassedDVs(0);
668  for (const label patchI : sensitivityPatchIDs_)
669  {
670  const polyPatch& patch = mesh_.boundaryMesh()[patchI];
671  List<scalarField> procPatchSens(Pstream::nProcs());
672  //if (patch.size()>0)
673  {
674  const labelList& meshPoints = patch.meshPoints();
675 
676  // Avoid storing unit point normals in the global list since we
677  // might divide multiple times with the number of faces belonging
678  // to the point. Instead do the division locally, per patch use
679  vectorField patchPointNormals(pointNormals, meshPoints);
680  patchPointNormals /= mag(patchPointNormals) + VSMALL;
681  if (!includeSurfaceArea_)
682  {
683  wallPointSensVecPtr_()[patchI] /=
684  scalarField(pointMagSf, meshPoints);
685  }
686  wallPointSensNormalPtr_()[patchI] =
687  wallPointSensVecPtr_()[patchI]
688  & patchPointNormals;
689  wallPointSensNormalVecPtr_()[patchI] =
690  wallPointSensNormalPtr_()[patchI]
691  *patchPointNormals;
692 
693  // 1. Gather sens from all processors for this patch and communicate
694  // them back. Potentially large memory overhead but the rest of the
695  // code structure assumes that all procs know all sensitivity
696  // derivatives
697  //
698  // 2. Transfer vectorial sensitivities to scalarField.
699  // Needed since the normal point vector is wrongly computed at patch
700  // boundaries and cannot be used to reconstruct a vectorial movement
701  // from just its normal component
702  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
703 
704  procPatchSens[Pstream::myProcNo()].setSize
705  (
706  3*wallPointSensNormalVecPtr_()[patchI].size()
707  );
708  scalarField& patchScalarSens = procPatchSens[Pstream::myProcNo()];
709  forAll(wallPointSensNormalVecPtr_()[patchI], ptI)
710  {
711  patchScalarSens[3*ptI] =
712  wallPointSensNormalVecPtr_()[patchI][ptI].x();
713  patchScalarSens[3*ptI + 1] =
714  wallPointSensNormalVecPtr_()[patchI][ptI].y();
715  patchScalarSens[3*ptI + 2] =
716  wallPointSensNormalVecPtr_()[patchI][ptI].z();
717  }
718  Pstream::gatherList(procPatchSens);
719  Pstream::scatterList(procPatchSens);
720 
721  forAll(procPatchSens, procI)
722  {
723  const scalarField& procSens = procPatchSens[procI];
724  forAll(procSens, dvI)
725  {
726  derivatives_[nPassedDVs + dvI] = procSens[dvI];
727  }
728  nPassedDVs += procSens.size();
729  }
730  }
731  }
732 }
733 
734 
736 {
737  // Reset terms in post-processing PDEs
738  if (includeDistance_)
739  {
740  eikonalSolver_->reset();
741  }
743  {
744  meshMovementSolver_->reset();
745  }
746 
747  // Reset local fields to zero
751 
752  // Reset sensitivity fields
755 }
756 
757 
759 {
760  setSuffixName();
763 }
764 
765 
766 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
767 
768 } // End namespace Foam
769 } // End namespace incompressible
770 
771 // ************************************************************************* //
Foam::fvPatchField< vector >
Foam::incompressible::sensitivitySurfacePoints::wallFaceSens_
autoPtr< boundaryVectorField > wallFaceSens_
The face-based part of the sensitivities.
Definition: sensitivitySurfacePointsIncompressible.H:105
Foam::sensitivity::dict
const dictionary & dict() const
Return the construction dictionary.
Definition: sensitivity.C:57
Foam::incompressible::adjointSensitivity::derivatives_
scalarField derivatives_
Definition: adjointSensitivityIncompressible.H:83
Foam::Tensor< scalar >
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1069
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::objectiveManager
class for managing incompressible objective functions.
Definition: objectiveManager.H:54
Foam::incompressible::sensitivitySurfacePoints::includeTransposeStresses_
bool includeTransposeStresses_
Include the transpose part of the adjoint stresses.
Definition: sensitivitySurfacePointsIncompressible.H:79
Foam::GeometricField::component
tmp< GeometricField< cmptType, PatchField, GeoMesh > > component(const direction) const
Return a component of the field.
Foam::variablesSet::solverName
const word & solverName() const
Return solver name.
Definition: variablesSet.C:84
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::fvc::grad
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:54
Foam::deltaBoundary
Differentiation of the mesh data structure.
Definition: deltaBoundary.H:58
sensitivitySurfacePointsIncompressible.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::incompressible::sensitivitySurfacePoints::dnfdbMult_
autoPtr< boundaryVectorField > dnfdbMult_
Definition: sensitivitySurfacePointsIncompressible.H:109
Foam::Tensor::I
static const Tensor I
Definition: Tensor.H:85
Foam::incompressible::defineTypeNameAndDebug
defineTypeNameAndDebug(adjointEikonalSolver, 0)
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::incompressible::sensitivitySurfacePoints::accumulateIntegrand
virtual void accumulateIntegrand(const scalar dt)
Accumulate sensitivity integrands.
Definition: sensitivitySurfacePointsIncompressible.C:415
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::incompressible::sensitivitySurfacePoints::constructGlobalPointNormalsAndAreas
void constructGlobalPointNormalsAndAreas(vectorField &pointNormals, scalarField &pointMagSf)
Construct globally correct point normals and point areas.
Definition: sensitivitySurfacePointsIncompressible.C:259
Foam::Pstream::scatterList
static void scatterList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Scatter data. Reverse of gatherList.
Definition: gatherScatterList.C:215
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::incompressible::sensitivitySurfacePoints::includePressureTerm_
bool includePressureTerm_
Include the adjoint pressure term in sens computation.
Definition: sensitivitySurfacePointsIncompressible.H:73
Foam::incompressible::sensitivitySurfacePoints::meshMovementSolver_
autoPtr< adjointMeshMovementSolver > meshMovementSolver_
Definition: sensitivitySurfacePointsIncompressible.H:98
Foam::incompressible::sensitivitySurfacePoints::useSnGradInTranposeStresses_
bool useSnGradInTranposeStresses_
Use snGrad in the transpose part of the adjoint stresses.
Definition: sensitivitySurfacePointsIncompressible.H:82
Foam::incompressible::sensitivitySurfacePoints::dSfdbMult_
autoPtr< boundaryVectorField > dSfdbMult_
Multipliers of d(Sf)/db and d(nf)/db.
Definition: sensitivitySurfacePointsIncompressible.H:108
Foam::incompressible::sensitivitySurfacePoints::read
void read()
Read controls and update solver pointers if necessary.
Definition: sensitivitySurfacePointsIncompressible.C:54
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::incompressibleVars::p
const volScalarField & p() const
Return const reference to pressure.
Definition: incompressibleVars.C:305
syncTools.H
Foam::incompressibleAdjointVars
Class including all adjoint fields for incompressible flows.
Definition: incompressibleAdjointVars.H:52
Foam::syncTools::syncPointList
static void syncPointList(const polyMesh &mesh, List< T > &pointValues, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
Definition: syncToolsTemplates.C:721
Foam::sumOp
Definition: ops.H:213
Foam::primitiveMesh::nPoints
label nPoints() const noexcept
Number of mesh points.
Definition: primitiveMeshI.H:37
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::incompressibleVars::RASModelVariables
const autoPtr< incompressible::RASModelVariables > & RASModelVariables() const
Return const reference to the turbulence model variables.
Definition: incompressibleVars.C:444
Foam::shapeSensitivitiesBase
Definition: shapeSensitivitiesBase.H:63
Foam::incompressible::sensitivitySurfacePoints::includeDivTerm_
bool includeDivTerm_
Include the term from the deviatoric part of the stresses.
Definition: sensitivitySurfacePointsIncompressible.H:85
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::incompressible::adjointEikonalSolver
Solver of the adjoint to the eikonal PDE.
Definition: adjointEikonalSolverIncompressible.H:146
Foam::incompressible::addToRunTimeSelectionTable
addToRunTimeSelectionTable(adjointSensitivity, sensitivityBezier, dictionary)
Foam::shapeSensitivitiesBase::write
void write()
Write sensitivity fields.
Definition: shapeSensitivitiesBase.C:216
Foam::incompressible::adjointSensitivity
Abstract base class for adjoint-based sensitivities in incompressible flows.
Definition: adjointSensitivityIncompressible.H:75
Foam::sensitivity::mesh_
const fvMesh & mesh_
Definition: sensitivity.H:69
Foam::Field< scalar >
Foam::sensitivity::readDict
virtual bool readDict(const dictionary &dict)
Read dictionary if changed.
Definition: sensitivity.C:63
Foam::incompressible::sensitivitySurfacePoints::eikonalSolver_
autoPtr< adjointEikonalSolver > eikonalSolver_
Definition: sensitivitySurfacePointsIncompressible.H:96
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
Foam::incompressible::sensitivitySurfacePoints::readDict
virtual bool readDict(const dictionary &dict)
Read dict if changed.
Definition: sensitivitySurfacePointsIncompressible.C:394
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::incompressibleAdjointMeanFlowVars::pa
const volScalarField & pa() const
Return const reference to pressure.
Definition: incompressibleAdjointMeanFlowVars.C:147
Foam::incompressibleVars::U
const volVectorField & U() const
Return const reference to velocity.
Definition: incompressibleVars.C:331
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
Foam::incompressible::adjointSensitivity::clearSensitivities
virtual void clearSensitivities()
Zero sensitivity fields and their constituents.
Definition: adjointSensitivityIncompressible.C:127
Foam::incompressible::sensitivitySurfacePoints::includeMeshMovement_
bool includeMeshMovement_
Include mesh movement variation in sens computation.
Definition: sensitivitySurfacePointsIncompressible.H:91
Foam::incompressibleAdjointMeanFlowVars::Ua
const volVectorField & Ua() const
Return const reference to velocity.
Definition: incompressibleAdjointMeanFlowVars.C:173
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::incompressible::sensitivitySurfacePoints::includeSurfaceArea_
bool includeSurfaceArea_
Include surface area in sens computation.
Definition: sensitivitySurfacePointsIncompressible.H:70
Foam::incompressible::sensitivitySurfacePoints::includeObjective_
bool includeObjective_
Include terms directly emerging from the objective function.
Definition: sensitivitySurfacePointsIncompressible.H:94
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::deltaBoundary::makeFaceCentresAndAreas_d
vectorField makeFaceCentresAndAreas_d(const pointField &p, const pointField &p_d)
Definition: deltaBoundary.C:72
Foam::incompressible::adjointSensitivity::adjointVars_
incompressibleAdjointVars & adjointVars_
Definition: adjointSensitivityIncompressible.H:85
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::incompressible::adjointSensitivity::primalVars_
incompressibleVars & primalVars_
Definition: adjointSensitivityIncompressible.H:84
Foam::incompressible::sensitivitySurfacePoints::write
virtual void write(const word &baseName=word::null)
Write sensitivity fields.
Definition: sensitivitySurfacePointsIncompressible.C:758
Foam::autoPtr::reset
void reset(autoPtr< T > &&other) noexcept
Delete managed object and set to new given pointer.
Definition: autoPtrI.H:117
Foam::fvMesh::boundary
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:685
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
U
U
Definition: pEqn.H:72
Foam::incompressible::sensitivitySurfacePoints::includeDistance_
bool includeDistance_
Include distance variation in sens computation.
Definition: sensitivitySurfacePointsIncompressible.H:88
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1094
Foam::Pstream::gatherList
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
Definition: gatherScatterList.C:52
Foam::incompressible::sensitivitySurfacePoints::includeGradStressTerm_
bool includeGradStressTerm_
Include the term containing the grad of the stress at the boundary.
Definition: sensitivitySurfacePointsIncompressible.H:76
Foam::GeometricField::Boundary
The boundary fields.
Definition: GeometricField.H:115
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:382
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:463
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::GeometricField::boundaryFieldRef
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
Definition: GeometricField.C:783
Foam::incompressibleAdjointVars::adjointTurbulence
const autoPtr< incompressibleAdjoint::adjointRASModel > & adjointTurbulence() const
Return const reference to the adjointRASModel.
Definition: incompressibleAdjointVars.C:70
Foam::List< label >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::incompressible::adjointMeshMovementSolver
Solver of the adjoint to the Laplace grid displacement equation.
Definition: adjointMeshMovementSolverIncompressible.H:68
Foam::shapeSensitivitiesBase::clearSensitivities
void clearSensitivities()
Zero sensitivity fields and their constituents.
Definition: shapeSensitivitiesBase.C:175
Foam::face::points
pointField points(const UList< point > &pts) const
Return the points corresponding to this face.
Definition: faceI.H:87
Foam::word::null
static const word null
An empty word.
Definition: word.H:80
Foam::incompressible::sensitivitySurfacePoints::setSuffixName
void setSuffixName()
Set suffix name for sensitivity fields.
Definition: sensitivitySurfacePointsIncompressible.C:309
Foam::VectorSpace< Vector< scalar >, scalar, 3 >::zero
static const Vector< scalar > zero
Definition: VectorSpace.H:115
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
Foam::plusEqOp
Definition: ops.H:72
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:148
Foam::shapeSensitivitiesBase::setSuffix
void setSuffix(const word &suffix)
Set suffix.
Definition: shapeSensitivitiesBase.C:223
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::incompressible::sensitivitySurfacePoints::finaliseFaceMultiplier
void finaliseFaceMultiplier()
Definition: sensitivitySurfacePointsIncompressible.C:112
Foam::incompressible::sensitivitySurfacePoints::clearSensitivities
virtual void clearSensitivities()
Zero sensitivity fields and their constituents.
Definition: sensitivitySurfacePointsIncompressible.C:735
Foam::incompressible::sensitivitySurfacePoints::finalisePointSensitivities
void finalisePointSensitivities()
Definition: sensitivitySurfacePointsIncompressible.C:173
Foam::UPstream::nProcs
static label nProcs(const label communicator=worldComm)
Number of processes in parallel run, and 1 for serial run.
Definition: UPstream.H:445
Foam::incompressible::sensitivitySurfacePoints::assembleSensitivities
virtual void assembleSensitivities()
Assemble sensitivities.
Definition: sensitivitySurfacePointsIncompressible.C:617
Foam::incompressibleVars
Base class for solution control classes.
Definition: incompressibleVars.H:54
Foam::GeometricField::boundaryField
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Definition: GeometricFieldI.H:62
Foam::incompressible::adjointSensitivity::write
virtual void write(const word &baseName=word::null)
Write sensitivity fields.
Definition: adjointSensitivityIncompressible.C:137
Foam::objectiveManager::getObjectiveFunctions
PtrList< objective > & getObjectiveFunctions()
Return reference to objective functions.
Definition: objectiveManager.C:296
Foam::incompressible::adjointSensitivity::objectiveManager_
objectiveManager & objectiveManager_
Definition: adjointSensitivityIncompressible.H:86