externalForce.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2019 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "externalForce.H"
30 #include "rigidBodyModel.H"
31 #include "rigidBodyModelState.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace RBD
39 {
40 namespace restraints
41 {
43 
45  (
46  restraint,
49  );
50 }
51 }
52 }
53 
54 
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 
58 (
59  const word& name,
60  const dictionary& dict,
61  const rigidBodyModel& model
62 )
63 :
64  restraint(name, dict, model),
65  externalForce_(nullptr),
66  location_(Zero)
67 {
68  read(dict);
69 }
70 
71 
72 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
73 
75 {}
76 
77 
78 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
79 
81 (
82  scalarField& tau,
84  const rigidBodyModelState& state
85 ) const
86 {
87  const vector force = externalForce_().value(state.t());
88  const vector moment(location_ ^ force);
89 
90  if (model_.debug)
91  {
92  Info<< " location " << location_
93  << " force " << force
94  << " moment " << moment
95  << endl;
96  }
97 
98  // Accumulate the force for the restrained body
99  fx[bodyIndex_] += spatialVector(moment, force);
100 }
101 
102 
104 (
105  const dictionary& dict
106 )
107 {
109 
110  coeffs_.readEntry("location", location_);
111 
112  externalForce_ = Function1<vector>::New("force", coeffs_);
113 
114  return true;
115 }
116 
117 
119 (
120  Ostream& os
121 ) const
122 {
124 
125  os.writeEntry("location", location_);
126 
127  externalForce_().writeData(os);
128 }
129 
130 
131 // ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
dictionary dict
virtual void write(Ostream &) const
Write.
addToRunTimeSelectionTable(restraint, externalForce, dictionary)
defineTypeNameAndDebug(externalForce, 0)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Base class for defining restraints for rigid-body dynamics.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
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:74
Macros for easy insertion into run-time selection tables.
Holds the motion state of rigid-body model.
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
externalForce(const word &name, const dictionary &dict, const rigidBodyModel &model)
Construct from components.
Definition: externalForce.C:51
scalar t() const
Return access to the time.
A class for handling words, derived from Foam::string.
Definition: word.H:63
SpatialVector< scalar > spatialVector
SpatialVector of scalars.
Definition: spatialVector.H:46
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
OBJstream os(runTime.globalPath()/outputName)
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
Definition: externalForce.C:97
Basic rigid-body model representing a system of rigid-bodies connected by 1-6 DoF joints...
virtual void write(Ostream &) const =0
Write.
Time-dependent external force restraint using Function1.
Definition: externalForce.H:69
virtual ~externalForce()
Destructor.
Definition: externalForce.C:67
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127