DAMotion.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v3
5 
6 \*---------------------------------------------------------------------------*/
7 
8 #include "DAMotion.H"
9 
10 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
11 
12 namespace Foam
13 {
14 
15 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
16 
17 defineTypeNameAndDebug(DAMotion, 0);
18 defineRunTimeSelectionTable(DAMotion, dictionary);
19 
20 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
21 
22 DAMotion::DAMotion(
23  const dynamicFvMesh& mesh,
24  const DAOption& daOption)
25  : mesh_(mesh),
26  daOption_(daOption)
27 {
28 }
29 
30 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
31 
32 autoPtr<DAMotion> DAMotion::New(
33  const dynamicFvMesh& mesh,
34  const DAOption& daOption)
35 {
36  // standard setup for runtime selectable classes
37 
38  // look up the solver name
39  word modelType = daOption.getAllOptions().subDict("rigidBodyMotion").getWord("mode");
40 
41  if (daOption.getAllOptions().lookupOrDefault<label>("debug", 0))
42  {
43  Info << "Selecting type: " << modelType << " for DAMotion. " << endl;
44  }
45 
46  dictionaryConstructorTable::iterator cstrIter =
47  dictionaryConstructorTablePtr_->find(modelType);
48 
49  // if the solver name is not found in any child class, print an error
50  if (cstrIter == dictionaryConstructorTablePtr_->end())
51  {
52  FatalErrorIn(
53  "DAMotion::New"
54  "("
55  " const dynamicFvMesh&,"
56  " const DAOption&,"
57  ")")
58  << "Unknown DAMotion type "
59  << modelType << nl << nl
60  << "Valid DAMotion types:" << endl
61  << dictionaryConstructorTablePtr_->sortedToc()
62  << exit(FatalError);
63  }
64 
65  // child class found
66  return autoPtr<DAMotion>(
67  cstrIter()(mesh,
68  daOption));
69 }
70 
71 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
72 vector DAMotion::getForce(const dynamicFvMesh& mesh)
73 {
74 
75  const objectRegistry& db = mesh.thisDb();
76  const volScalarField& p = db.lookupObject<volScalarField>("p");
77  const volScalarField& nut = db.lookupObject<volScalarField>("nut");
78  const volScalarField& nu = db.lookupObject<volScalarField>("nu");
79  const volVectorField& U = db.lookupObject<volVectorField>("U");
80 
81  volSymmTensorField tdevRhoReff("devRhoReff", -(nu + nut) * dev(twoSymm(fvc::grad(U))));
82 
83  const volSymmTensorField::Boundary& devRhoReffb = tdevRhoReff.boundaryField();
84 
85  // iterate over patches and extract boundary surface forces
86  vector force(vector::zero);
87  forAll(patchNames_, idxI)
88  {
89  // get the patch id label
90  label patchI = mesh.boundaryMesh().findPatchID(patchNames_[idxI]);
91  // normal force
92  vectorField fN(mesh.Sf().boundaryField()[patchI] * p.boundaryField()[patchI]);
93  // tangential force
94  vectorField fT(mesh.Sf().boundaryField()[patchI] & devRhoReffb[patchI]);
95  // sum them up
96  forAll(mesh.boundaryMesh()[patchI], faceI)
97  {
98  force += fN[faceI] + fT[faceI];
99  }
100  }
101 
102  reduce(force[0], sumOp<scalar>());
103  reduce(force[1], sumOp<scalar>());
104  reduce(force[2], sumOp<scalar>());
105 
106  return force;
107 }
108 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
109 
110 } // End namespace Foam
111 
112 // ************************************************************************* //
U
U
Definition: pEqnPimpleDyM.H:60
forAll
forAll(pseudoP.boundaryField(), patchI)
Definition: solvePseudoPEqn.H:10
Foam::DAOption
Definition: DAOption.H:29
daOption
DAOption daOption(mesh, pyOptions_)
Foam::DAMotion::New
static autoPtr< DAMotion > New(const dynamicFvMesh &mesh, const DAOption &daOption)
Definition: DAMotion.C:32
p
volScalarField & p
Definition: createRefsPimple.H:6
mesh
fvMesh & mesh
Definition: createRefsHeatTransfer.H:4
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(DAFvSource, dictionary)
DAMotion.H
Foam::DAMotion::patchNames_
wordList patchNames_
patch names for the moving body
Definition: DAMotion.H:47
Foam::DAMotion::getForce
vector getForce(const dynamicFvMesh &mesh)
calculate the force
Definition: DAMotion.C:72
Foam
Definition: multiFreqScalarFvPatchField.C:144
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(DAFvSource, 0)