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-2024 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"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace RBD
35 {
38 
40  (
41  rigidBody,
42  rigidBody,
44  );
45 }
46 }
47 
48 
49 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 
52 {
53  return autoPtr<rigidBody>(new rigidBody(*this));
54 }
55 
56 
57 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
58 
60 (
61  const word& name,
62  const scalar& m,
63  const vector& c,
64  const symmTensor& Ic
65 )
66 {
67  return autoPtr<rigidBody>(new rigidBody(name, m, c, Ic));
68 }
69 
70 
72 (
73  const word& name,
74  const dictionary& dict
75 )
76 {
77  const word bodyType(dict.lookup("type"));
78 
79  dictionaryConstructorTable::iterator cstrIter =
80  dictionaryConstructorTablePtr_->find(bodyType);
81 
82  if (cstrIter == dictionaryConstructorTablePtr_->end())
83  {
85  << "Unknown rigidBody type "
86  << bodyType << nl << nl
87  << "Valid rigidBody types are : " << endl
88  << dictionaryConstructorTablePtr_->sortedToc()
89  << exit(FatalError);
90  }
91 
92  return autoPtr<rigidBody>(cstrIter()(name, dict));
93 }
94 
95 
96 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
97 
99 {}
100 
101 
102 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
103 
105 {
106  return false;
107 }
108 
109 
111 {
112  *this = rigidBody
113  (
114  name(),
115  *this + transform(subBody.masterXT(), subBody.body())
116  );
117 }
118 
119 
121 {
122  writeEntry(os, "type", type());
123 
124  writeEntry(os, "mass", m());
125 
126  writeEntry(os, "centreOfMass", c());
127 
128  writeEntry(os, "inertia", Ic());
129 }
130 
131 
132 // ************************************************************************* //
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:60
virtual void write(Ostream &) const
Write.
Definition: rigidBody.C:120
virtual bool massless() const
Return false as this body is not massless.
Definition: rigidBody.C:104
void merge(const subBody &)
Merge a body into this parent body.
Definition: rigidBody.C:110
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:98
virtual autoPtr< rigidBody > clone() const
Return clone of this rigidBody.
Definition: rigidBody.C:51
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 keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
A class for handling words, derived from string.
Definition: word.H:62
#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:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
error FatalError
static const char nl
Definition: Ostream.H:266
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict