All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2019 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 {
36  defineTypeNameAndDebug(rigidBody, 0);
37  defineRunTimeSelectionTable(rigidBody, dictionary);
38 
40  (
41  rigidBody,
42  rigidBody,
43  dictionary
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 // ************************************************************************* //
static autoPtr< rigidBody > New(const word &name, const scalar &m, const vector &c, const symmTensor &Ic)
Select constructed from components.
Definition: rigidBody.C:60
dictionary dict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
addToRunTimeSelectionTable(rigidBody, cuboid, dictionary)
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
virtual void write(Ostream &) const
Write.
Definition: rigidBody.C:120
void merge(const subBody &)
Merge a body into this parent body.
Definition: rigidBody.C:110
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
const dimensionedScalar & c
Speed of light in a vacuum.
virtual autoPtr< rigidBody > clone() const
Return clone of this rigidBody.
Definition: rigidBody.C:51
Macros for easy insertion into run-time selection tables.
const rigidBody & body() const
Return the original body from which this sub-body was constructed.
Definition: subBodyI.H:51
This specialized rigidBody holds the original body after it has been merged into a master...
Definition: subBody.H:52
A class for handling words, derived from string.
Definition: word.H:59
virtual bool massless() const
Return false as this body is not massless.
Definition: rigidBody.C:104
defineTypeNameAndDebug(cuboid, 0)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
defineRunTimeSelectionTable(rigidBody, dictionary)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
rigidBodyInertia transform(const spatialTransform &X, const rigidBodyInertia &I)
Return (^BX_A)^* I ^AX_B.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
virtual ~rigidBody()
Destructor.
Definition: rigidBody.C:98
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:812
const spatialTransform & masterXT() const
Return the transform with respect to the master body.
Definition: subBodyI.H:75