functionDot.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "functionDot.H"
27 #include "rigidBodyModelState.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace RBD
35 {
36 namespace joints
37 {
38  defineTypeNameAndDebug(functionDot, 0);
39 
41  (
42  joint,
43  functionDot,
44  dictionary
45  );
46 }
47 }
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
54 (
55  const rigidBodyModel& model,
56  const dictionary& dict
57 )
58 :
59  joint(model, 0),
60  f_(Function1<scalar>::New("function", dict)),
61  delta_(dict.lookupOrDefault<scalar>("delta", rootSmall))
62 {}
63 
64 
66 {
67  return autoPtr<joint>(new functionDot(*this));
68 }
69 
70 
71 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
72 
74 {}
75 
76 
77 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
78 
80 (
81  joint::XSvc& J,
82  const rigidBodyModelState& state
83 ) const
84 {
85  const label lambda = model_.lambda()[index_];
86  const joint& parent = model_.joints()[lambda];
87 
88  spatialVector x(Zero), v(Zero), c(Zero);
89  for(label i = 0; i < model_.joints()[lambda].nDoF(); ++ i)
90  {
91  const scalar qDot = state.qDot()[parent.qIndex() + i];
92  const scalar qDdot = state.qDdot()[parent.qIndex() + i];
93  const scalar qDddot = 0; // the third derivative is not stored
94 
95  const scalar f = f_->value(qDot);
96  const scalar fMinusDf = f_->value(qDot - delta_/2);
97  const scalar fPlusDf = f_->value(qDot + delta_/2);
98  const scalar dfdqDot = (fPlusDf - fMinusDf)/delta_;
99  const scalar d2fdqDot2 = (fPlusDf - 2*f + fMinusDf)/sqr(delta_);
100 
101  const spatialVector& s = parent.S()[i];
102 
103  x += f*s;
104  v += dfdqDot*qDdot*s;
105  c += (dfdqDot*qDddot + d2fdqDot2*sqr(qDdot))*s;
106  }
107 
108  const scalar magW = mag(x.w());
109 
110  const tensor X(magW > vSmall ? quaternion(x.w(), magW).R() : tensor::I);
111 
112  J.X = spatialTransform(X, x.l());
113  J.S = Zero;
114  J.S1 = Zero;
115  J.v = v;
116  J.c = c;
117 }
118 
119 
120 // ************************************************************************* //
Abstract base-class for all rigid-body joints.
Definition: joint.H:80
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:53
Joint in which the position is a function of the parent joint&#39;s velocity.
Definition: functionDot.H:61
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
spatialVector v
The constrained joint velocity.
Definition: joint.H:137
spatialVector S1
The joint motion sub-space (1-DoF)
Definition: joint.H:134
compactSpatialTensor S
The joint motion sub-space (3-DoF)
Definition: joint.H:131
dimensionedSymmTensor sqr(const dimensionedVector &dv)
functionDot(const rigidBodyModel &model, const dictionary &dict)
Construct for given model from dictionary.
Definition: functionDot.C:54
defineTypeNameAndDebug(composite, 0)
addToRunTimeSelectionTable(joint, composite, dictionary)
spatialVector c
The constrained joint acceleration correction.
Definition: joint.H:141
Macros for easy insertion into run-time selection tables.
Holds the motion state of rigid-body model.
Joint state returned by jcalc.
Definition: joint.H:123
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
const scalarField & qDot() const
Return access to the joint velocity.
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:60
static const zero Zero
Definition: zero.H:97
static const Tensor I
Definition: Tensor.H:80
const List< spatialVector > & S() const
Return the joint motion sub-space.
Definition: jointI.H:59
labelList f(nPoints)
spatialTransform X
The joint transformation.
Definition: joint.H:128
virtual void jcalc(joint::XSvc &J, const rigidBodyModelState &state) const
Update the model state for this joint.
Definition: functionDot.C:80
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
#define R(A, B, C, D, E, F, K, M)
virtual ~functionDot()
Destructor.
Definition: functionDot.C:73
const dimensionedScalar c
Speed of light in a vacuum.
dimensionedScalar lambda(laminarTransport.lookup("lambda"))
dimensioned< scalar > mag(const dimensioned< Type > &)
Compact representation of the Pl├╝cker spatial transformation tensor in terms of the rotation tensor E...
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
virtual autoPtr< joint > clone() const
Clone this joint.
Definition: functionDot.C:65
Basic rigid-body model representing a system of rigid-bodies connected by 1-6 DoF joints...
const scalarField & qDdot() const
Return access to the joint acceleration.
Namespace for OpenFOAM.