DAObjFuncCenterOfPressure.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v3
5 
6 \*---------------------------------------------------------------------------*/
7 
9 
10 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
11 
12 namespace Foam
13 {
14 
15 defineTypeNameAndDebug(DAObjFuncCenterOfPressure, 0);
16 addToRunTimeSelectionTable(DAObjFunc, DAObjFuncCenterOfPressure, dictionary);
17 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
18 
20  const fvMesh& mesh,
21  const DAOption& daOption,
22  const DAModel& daModel,
23  const DAIndex& daIndex,
24  const DAResidual& daResidual,
25  const word objFuncName,
26  const word objFuncPart,
27  const dictionary& objFuncDict)
28  : DAObjFunc(
29  mesh,
30  daOption,
31  daModel,
32  daIndex,
33  daResidual,
34  objFuncName,
35  objFuncPart,
36  objFuncDict)
37 {
38 
39  // for computing center of pressure, first read in some parameters from objFuncDict_
40  // these parameters are only for moment center of pressure objective
41 
42  // Assign type, this is common for all objectives
43  objFuncDict_.readEntry<word>("type", objFuncType_);
44 
45  scalarList axisList;
46  objFuncDict_.readEntry<scalarList>("axis", axisList);
47  axis_[0] = axisList[0];
48  axis_[1] = axisList[1];
49  axis_[2] = axisList[2];
50  // normalize
51  axis_ /= mag(axis_);
52 
53  scalarList forceAxisList;
54  objFuncDict_.readEntry<scalarList>("forceAxis", forceAxisList);
55  forceAxis_[0] = forceAxisList[0];
56  forceAxis_[1] = forceAxisList[1];
57  forceAxis_[2] = forceAxisList[2];
58  // normalize
59  forceAxis_ /= mag(forceAxis_);
60 
61  if (fabs(axis_ & forceAxis_) > 1e-8)
62  {
63  FatalErrorIn(" ") << "axis and forceAxis vectors need to be orthogonal! "
64  << abort(FatalError);
65  }
66 
67  scalarList centerList;
68  objFuncDict_.readEntry<scalarList>("center", centerList);
69  center_[0] = centerList[0];
70  center_[1] = centerList[1];
71  center_[2] = centerList[2];
72 
73  objFuncDict_.readEntry<scalar>("scale", scale_);
74 }
75 
78  const labelList& objFuncFaceSources,
79  const labelList& objFuncCellSources,
80  scalarList& objFuncFaceValues,
81  scalarList& objFuncCellValues,
82  scalar& objFuncValue)
83 {
84  /*
85  Description:
86  Calculate the average location of pressure applied to the body.
87 
88  Input:
89  objFuncFaceSources: List of face source (index) for this objective
90 
91  Output:
92  objFuncValue: the sum of objective along a chosen "axis", reduced across all processors and scaled by "scale"
93  */
94 
95  // initialize objFuncValue
96  objFuncValue = 0.0;
97  scalar weightedPressure = 0.0;
98  scalar totalPressure = 0.0;
99 
100  const objectRegistry& db = mesh_.thisDb();
101  const volScalarField& p = db.lookupObject<volScalarField>("p");
102 
103  const surfaceVectorField::Boundary& Sfb = mesh_.Sf().boundaryField();
104 
105  // calculate discrete force for each objFuncFace
106  forAll(objFuncFaceSources, idxI)
107  {
108  const label& objFuncFaceI = objFuncFaceSources[idxI];
109  label bFaceI = objFuncFaceI - daIndex_.nLocalInternalFaces;
110  const label patchI = daIndex_.bFacePatchI[bFaceI];
111  const label faceI = daIndex_.bFaceFaceI[bFaceI];
112 
113  // normal force
114  vector fN(Sfb[patchI][faceI] * p.boundaryField()[patchI][faceI]);
115  // r vector projected to the axis vector
116  scalar r = (mesh_.Cf().boundaryField()[patchI][faceI] - center_) & axis_;
117  // force projected to force axis vector
118  scalar f = fN & forceAxis_;
119  // force weighted by distance
120  weightedPressure += r * f;
121  // total force
122  totalPressure += f;
123  }
124 
125  // need to reduce the sum of force across all processors
126  reduce(weightedPressure, sumOp<scalar>());
127  reduce(totalPressure, sumOp<scalar>());
128 
129  objFuncValue = scale_ * (weightedPressure / totalPressure + (center_ & axis_));
130 
131  return;
132 }
133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
134 
135 } // End namespace Foam
136 
137 // ************************************************************************* //
Foam::DAObjFunc::objFuncType_
word objFuncType_
the type of the objective function
Definition: DAObjFunc.H:66
forAll
forAll(pseudoP.boundaryField(), patchI)
Definition: solvePseudoPEqn.H:10
Foam::DAIndex::bFacePatchI
labelList bFacePatchI
Definition: DAIndex.H:110
Foam::DAOption
Definition: DAOption.H:29
Foam::DAObjFunc::daIndex_
const DAIndex & daIndex_
DAIndex object.
Definition: DAObjFunc.H:54
daOption
DAOption daOption(mesh, pyOptions_)
Foam::DAObjFuncCenterOfPressure::forceAxis_
vector forceAxis_
the direction to project the force onto
Definition: DAObjFuncCenterOfPressure.H:36
p
volScalarField & p
Definition: createRefsPimple.H:6
mesh
fvMesh & mesh
Definition: createRefsHeatTransfer.H:4
Foam::DAObjFunc::mesh_
const fvMesh & mesh_
fvMesh
Definition: DAObjFunc.H:45
Foam::DAIndex
Definition: DAIndex.H:32
Foam::DAObjFuncCenterOfPressure::calcObjFunc
virtual void calcObjFunc(const labelList &objFuncFaceSources, const labelList &objFuncCellSources, scalarList &objFuncFaceValues, scalarList &objFuncCellValues, scalar &objFuncValue)
calculate the value of objective function
Definition: DAObjFuncCenterOfPressure.C:77
Foam::DAModel
Definition: DAModel.H:59
DAObjFuncCenterOfPressure.H
Foam
Definition: multiFreqScalarFvPatchField.C:144
Foam::DAObjFuncCenterOfPressure::axis_
vector axis_
the direction to project the center of pressure onto
Definition: DAObjFuncCenterOfPressure.H:33
Foam::DAIndex::nLocalInternalFaces
label nLocalInternalFaces
local internal face size
Definition: DAIndex.H:98
Foam::DAResidual
Definition: DAResidual.H:35
Foam::DAObjFuncCenterOfPressure::DAObjFuncCenterOfPressure
DAObjFuncCenterOfPressure(const fvMesh &mesh, const DAOption &daOption, const DAModel &daModel, const DAIndex &daIndex, const DAResidual &daResidual, const word objFuncName, const word objFuncPart, const dictionary &objFuncDict)
Definition: DAObjFuncCenterOfPressure.C:19
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(DAFvSource, 0)
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(DAFvSource, DAFvSourceActuatorDisk, dictionary)
Foam::DAObjFunc::scale_
scalar scale_
scale of the objective function
Definition: DAObjFunc.H:87
daModel
DAModel daModel(mesh, daOption)
daIndex
DAIndex daIndex(mesh, daOption, daModel)
Foam::DAObjFunc::objFuncDict_
const dictionary & objFuncDict_
dictionary containing the information for the objective function
Definition: DAObjFunc.H:69
Foam::DAObjFuncCenterOfPressure::center_
vector center_
The point to compute center of pressure about.
Definition: DAObjFuncCenterOfPressure.H:39
Foam::DAIndex::bFaceFaceI
labelList bFaceFaceI
Definition: DAIndex.H:116
Foam::DAObjFunc
Definition: DAObjFunc.H:33