externalForce.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) 2019-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 "externalForce.H"
27 #include "rigidBodyModel.H"
28 #include "rigidBodyModelState.H"
29 #include "OneConstant.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace RBD
37 {
38 namespace restraints
39 {
41 
43  (
44  restraint,
47  );
48 }
49 }
50 }
51 
52 
53 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54 
56 (
57  const word& name,
58  const dictionary& dict,
59  const rigidBodyModel& model
60 )
61 :
62  restraint(name, dict, model),
63  externalForce_(nullptr)
64 {
65  read(dict);
66 }
67 
68 
69 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
70 
72 {}
73 
74 
75 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
76 
78 (
79  scalarField& tau,
81  const rigidBodyModelState& state
82 ) const
83 {
84  const vector force = externalForce_().value(state.t());
85  const vector moment(location_ ^ force);
86 
87  if (model_.debug)
88  {
89  Info<< " location " << location_
90  << " force " << force
91  << " moment " << moment
92  << endl;
93  }
94 
95  // Accumulate the force for the restrained body
96  fx[masterBodyIndex_] += spatialVector(moment, force);
97 }
98 
99 
101 (
102  const dictionary& dict
103 )
104 {
106 
107  coeffs_.lookup("location") >> location_;
108 
109  externalForce_ =
110  Function1<vector>::New("force", dimTime, dimForce, coeffs_);
111 
112  return true;
113 }
114 
115 
117 (
118  Ostream& os
119 ) const
120 {
121  restraint::write(os);
122 
123  writeEntry(os, "location", location_);
124 
125  writeEntry(os, externalForce_());
126 }
127 
128 
129 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
static autoPtr< Function1< Type > > New(const word &name, const Function1s::unitConversions &units, const dictionary &dict)
Select from dictionary.
Definition: Function1New.C:32
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Base class for defining restraints for rigid-body dynamics.
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
virtual void write(Ostream &) const =0
Write.
Time-dependent external force restraint using Function1.
Definition: externalForce.H:71
virtual void write(Ostream &) const
Write.
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
virtual void restrain(scalarField &tau, Field< spatialVector > &fx, const rigidBodyModelState &state) const
Accumulate the retraint internal joint forces into the tau field and.
Definition: externalForce.C:78
externalForce(const word &name, const dictionary &dict, const rigidBodyModel &model)
Construct from components.
Definition: externalForce.C:56
virtual ~externalForce()
Destructor.
Definition: externalForce.C:71
Holds the motion state of rigid-body model.
scalar t() const
Return access to the time.
Basic rigid-body model representing a system of rigid-bodies connected by 1-6 DoF joints.
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
addToRunTimeSelectionTable(restraint, externalForce, dictionary)
defineTypeNameAndDebug(externalForce, 0)
Namespace for OpenFOAM.
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
messageStream Info
const dimensionSet dimForce
const dimensionSet dimTime
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
SpatialVector< scalar > spatialVector
SpatialVector of scalars.
Definition: spatialVector.H:47
dictionary dict