sixDoFRigidBodyMotionIO.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) 2011-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 "sixDoFRigidBodyMotion.H"
27 #include "IOstreams.H"
28 
29 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
30 
32 {
33  dict.lookup("mass") >> mass_;
34  dict.lookup("momentOfInertia") >> momentOfInertia_;
35  aRelax_ = dict.lookupOrDefault<scalar>("accelerationRelaxation", 1.0);
36  aDamp_ = dict.lookupOrDefault<scalar>("accelerationDamping", 1.0);
37  report_ = dict.lookupOrDefault<Switch>("report", false);
38 
39  restraints_.clear();
41 
42  constraints_.clear();
44 
45  return true;
46 }
47 
48 
50 {
51  motionState_.write(os);
52 
53  writeEntry(os, "centreOfMass", initialCentreOfMass_);
54  writeEntry(os, "initialOrientation", initialQ_);
55  writeEntry(os, "mass", mass_);
56  writeEntry(os, "momentOfInertia", momentOfInertia_);
57  writeEntry(os, "accelerationRelaxation", aRelax_);
58  writeEntry(os, "accelerationDamping", aDamp_);
59  writeEntry(os, "report", report_);
60 
61  if (!restraints_.empty())
62  {
63  os << indent << "restraints" << nl
65 
66  forAll(restraints_, rI)
67  {
68  word restraintType = restraints_[rI].type();
69 
70  os << indent << restraints_[rI].name() << nl
72 
73  writeEntry(os, "sixDoFRigidBodyMotionRestraint", restraintType);
74 
75  restraints_[rI].write(os);
76 
77  os << decrIndent << indent << token::END_BLOCK << endl;
78  }
79 
80  os << decrIndent << indent << token::END_BLOCK << nl;
81  }
82 
83  if (!constraints_.empty())
84  {
85  os << indent << "constraints" << nl
87 
88  forAll(constraints_, rI)
89  {
90  word constraintType = constraints_[rI].type();
91 
92  os << indent << constraints_[rI].name() << nl
94 
95  writeEntry(os, "sixDoFRigidBodyMotionConstraint", constraintType);
96 
97  constraints_[rI].sixDoFRigidBodyMotionConstraint::write(os);
98 
99  constraints_[rI].write(os);
100 
101  os << decrIndent << indent << token::END_BLOCK << endl;
102  }
103 
104  os << decrIndent << indent << token::END_BLOCK << nl;
105  }
106 }
107 
108 
109 // ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual const fileName & name() const
Return the name of the stream.
Definition: IOstream.H:294
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
void addConstraints(const dictionary &dict)
Add restraints to the motion, public to allow external.
void write(Ostream &) const
Write.
bool read(const dictionary &dict)
Read coefficients dictionary and update system parameters,.
void addRestraints(const dictionary &dict)
Add restraints to the motion, public to allow external.
@ BEGIN_BLOCK
Definition: token.H:113
@ END_BLOCK
Definition: token.H:114
A class for handling words, derived from string.
Definition: word.H:62
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:241
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:234
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:227
static const char nl
Definition: Ostream.H:266
dictionary dict