rigidBody.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) 2016-2026 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 "rigidBody.H"
27 #include "subBody.H"
28 #include "primitiveFields.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace RBD
36 {
40 }
41 }
42 
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
47 {
48  return autoPtr<rigidBody>(new rigidBody(*this));
49 }
50 
51 
52 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
53 
55 (
56  const word& name,
57  const scalar& m,
58  const vector& c,
59  const symmTensor& Ic
60 )
61 {
62  return autoPtr<rigidBody>(new rigidBody(name, m, c, Ic));
63 }
64 
65 
67 (
68  const word& name,
69  const dictionary& dict
70 )
71 {
72  const word bodyType(dict.lookup("type"));
73 
74  dictionaryConstructorTable::iterator cstrIter =
75  dictionaryConstructorTablePtr_->find(bodyType);
76 
77  if (cstrIter == dictionaryConstructorTablePtr_->end())
78  {
80  << "Unknown rigidBody type "
81  << bodyType << nl << nl
82  << "Valid rigidBody types are : " << endl
83  << dictionaryConstructorTablePtr_->sortedToc()
84  << exit(FatalError);
85  }
86 
87  return autoPtr<rigidBody>(cstrIter()(name, dict));
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
92 
94 {}
95 
96 
97 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
98 
100 {
101  return false;
102 }
103 
104 
106 {
107  *this = rigidBody
108  (
109  name(),
110  *this + transform(subBody.masterXT(), subBody.body())
111  );
112 }
113 
114 
116 (
117  const direction axis,
118  const scalarField& distances
119 ) const
120 {
122  << "Rigid body " << name() << " of type " << type()
123  << " does not support the calculation of sectional moments"
124  << exit(FatalError);
125  return tmp<scalarField>(nullptr);
126 }
127 
128 
130 (
131  const direction axis,
132  const scalarField& distances
133 ) const
134 {
135  sectionMu0s(axis, distances);
136  return tmp<vectorField>(nullptr);
137 }
138 
139 
141 (
142  const direction axis,
143  const scalarField& distances
144 ) const
145 {
146  sectionMu0s(axis, distances);
147  return tmp<symmTensorField>(nullptr);
148 }
149 
150 
152 {
153  writeEntry(os, "type", type());
154 
155  writeEntry(os, "mass", m());
156 
157  writeEntry(os, "centreOfMass", c());
158 
159  writeEntry(os, "inertia", Ic());
160 }
161 
162 
163 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
static autoPtr< rigidBody > New(const word &name, const scalar &m, const vector &c, const symmTensor &Ic)
Select constructed from components.
Definition: rigidBody.C:55
virtual tmp< vectorField > sectionMu1s(const direction axis, const scalarField &distances) const
Return the first moments of the sections of the body between.
Definition: rigidBody.C:130
virtual void write(Ostream &) const
Write.
Definition: rigidBody.C:151
virtual bool massless() const
Return false as this body is not massless.
Definition: rigidBody.C:99
void merge(const subBody &)
Merge a body into this parent body.
Definition: rigidBody.C:105
rigidBody(const word &name, const scalar &m, const vector &c, const symmTensor &Ic)
Construct from mass, centre of mass and moment of inertia tensor.
Definition: rigidBodyI.H:29
virtual ~rigidBody()
Destructor.
Definition: rigidBody.C:93
virtual tmp< symmTensorField > sectionMu2s(const direction axis, const scalarField &distances) const
Return the second moments of the sections of the body between.
Definition: rigidBody.C:141
virtual autoPtr< rigidBody > clone() const
Return clone of this rigidBody.
Definition: rigidBody.C:46
virtual tmp< scalarField > sectionMu0s(const direction axis, const scalarField &distances) const
Return the zeroth moments of the sections of the body between.
Definition: rigidBody.C:116
This specialised rigidBody holds the original body after it has been merged into a master.
Definition: subBody.H:53
const spatialTransform & masterXT() const
Return the transform with respect to the master body.
Definition: subBodyI.H:75
const rigidBody & body() const
Return the original body from which this sub-body was constructed.
Definition: subBodyI.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
rigidBodyInertia transform(const spatialTransform &X, const rigidBodyInertia &I)
Return (^BX_A)^* I ^AX_B.
defineRunTimeSelectionTable(rigidBody, dictionary)
addToRunTimeSelectionTable(rigidBody, cuboid, dictionary)
defineTypeNameAndDebug(cuboid, 0)
const dimensionedScalar c
Speed of light in a vacuum.
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
static const char nl
Definition: Ostream.H:297
uint8_t direction
Definition: direction.H:45
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
Specialisations of Field<T> for scalar, vector and tensor.
dictionary dict