DAMotionTranslationCoupled.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(DAMotionTranslationCoupled, 0);
16 addToRunTimeSelectionTable(DAMotion, DAMotionTranslationCoupled, dictionary);
17 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
18 
20  const dynamicFvMesh& mesh,
21  const DAOption& daOption)
22  : DAMotion(
23  mesh,
24  daOption)
25 {
26  M_ = daOption_.getAllOptions().subDict("rigidBodyMotion").getScalar("mass");
27  C_ = daOption_.getAllOptions().subDict("rigidBodyMotion").getScalar("damping");
28  K_ = daOption_.getAllOptions().subDict("rigidBodyMotion").getScalar("stiffness");
29  forceScale_ = daOption_.getAllOptions().subDict("rigidBodyMotion").getScalar("forceScale");
30  y0_ = daOption_.getAllOptions().subDict("rigidBodyMotion").lookupOrDefault<scalar>("y0", 0.0);
31  V0_ = daOption_.getAllOptions().subDict("rigidBodyMotion").lookupOrDefault<scalar>("V0", 0.0);
32  scalarList dirList;
33  daOption_.getAllOptions().subDict("rigidBodyMotion").readEntry<scalarList>("direction", dirList);
34  direction_[0] = dirList[0];
35  direction_[1] = dirList[1];
36  direction_[2] = dirList[2];
37  daOption_.getAllOptions().subDict("rigidBodyMotion").readEntry<wordList>("patchNames", patchNames_);
38  t_ = 0.0;
39 }
40 
42 {
43  volVectorField& cellDisp =
44  const_cast<volVectorField&>(mesh_.thisDb().lookupObject<volVectorField>("cellDisplacement"));
45 
46  scalar dT = mesh_.time().deltaT().value();
47 
48  vector force = this->getForce(mesh_);
49  // NOTE: we scale the force here. This can be useful if we simulate a 2D geometry and
50  // want to scale the force to the full 3D model for spring dynamics
51  scalar yForce = force & direction_ * forceScale_;
52 
53  // RK2 method to solve the mass-spring-damper model
54  scalar ym = y0_ + 0.5 * dT * V0_;
55  scalar Vm = V0_ + 0.5 * dT * (yForce - C_ * V0_ - K_ * y0_) / M_;
56  y_ = y0_ + dT * Vm;
57  V_ = V0_ + dT * (yForce - C_ * Vm - K_ * ym) / M_;
58 
59  y0_ = y_;
60  V0_ = V_;
61 
62  forAll(patchNames_, idxI)
63  {
64  const word& patchName = patchNames_[idxI];
65  label patchI = mesh_.boundaryMesh().findPatchID(patchName);
66 
67  forAll(cellDisp.boundaryField()[patchI], faceI)
68  {
69  cellDisp.boundaryFieldRef()[patchI][faceI] = y_ * direction_;
70  }
71  }
72 
73  t_ += dT;
74 
75  // print information
76  Info << "Time: " << t_ << " yForce: " << yForce << " y: " << y_ << " V: " << V_ << endl;
77 }
78 
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
80 
81 } // End namespace Foam
82 
83 // ************************************************************************* //
Foam::DAMotionTranslationCoupled::V_
scalar V_
velocity for the current step
Definition: DAMotionTranslationCoupled.H:66
DAMotionTranslationCoupled.H
forAll
forAll(pseudoP.boundaryField(), patchI)
Definition: solvePseudoPEqn.H:10
Foam::DAMotionTranslationCoupled::y_
scalar y_
location for the current step
Definition: DAMotionTranslationCoupled.H:63
Foam::DAMotionTranslationCoupled::t_
scalar t_
the simulation time based on dT and it should be same as the runtime
Definition: DAMotionTranslationCoupled.H:75
Foam::DAMotion::mesh_
const dynamicFvMesh & mesh_
fvMesh
Definition: DAMotion.H:41
Foam::DAOption
Definition: DAOption.H:29
Foam::DAMotionTranslationCoupled::y0_
scalar y0_
location from the previous step
Definition: DAMotionTranslationCoupled.H:69
daOption
DAOption daOption(mesh, pyOptions_)
Foam::DAMotionTranslationCoupled::forceScale_
scalar forceScale_
scaling factor for force
Definition: DAMotionTranslationCoupled.H:57
Foam::DAMotionTranslationCoupled::correct
virtual void correct()
update the cell displacement
Definition: DAMotionTranslationCoupled.C:41
Foam::DAMotionTranslationCoupled::DAMotionTranslationCoupled
DAMotionTranslationCoupled(const dynamicFvMesh &mesh, const DAOption &daOption)
Definition: DAMotionTranslationCoupled.C:19
Foam::DAMotion::daOption_
const DAOption & daOption_
DAOption object.
Definition: DAMotion.H:44
Foam::DAOption::getAllOptions
const dictionary & getAllOptions() const
return a reference of allOptions_ dictionary
Definition: DAOption.H:56
mesh
fvMesh & mesh
Definition: createRefsHeatTransfer.H:4
Foam::DAMotionTranslationCoupled::C_
scalar C_
spring damping coefficient
Definition: DAMotionTranslationCoupled.H:51
Foam::DAMotion::patchNames_
wordList patchNames_
patch names for the moving body
Definition: DAMotion.H:47
Foam::DAMotion
Definition: DAMotion.H:29
Foam::DAMotionTranslationCoupled::M_
scalar M_
mass of the object
Definition: DAMotionTranslationCoupled.H:48
Foam::DAMotion::getForce
vector getForce(const dynamicFvMesh &mesh)
calculate the force
Definition: DAMotion.C:72
Foam
Definition: multiFreqScalarFvPatchField.C:144
Foam::DAMotionTranslationCoupled::K_
scalar K_
spring stiffness constant
Definition: DAMotionTranslationCoupled.H:54
Foam::DAMotionTranslationCoupled::V0_
scalar V0_
velocity from the previous step
Definition: DAMotionTranslationCoupled.H:72
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(DAFvSource, 0)
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(DAFvSource, DAFvSourceActuatorDisk, dictionary)
Foam::DAMotionTranslationCoupled::direction_
vector direction_
spring oscillation direction
Definition: DAMotionTranslationCoupled.H:60