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"
32 #include "OneConstant.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 namespace RBD
40 {
41 namespace restraints
42 {
44 
46  (
47  restraint,
50  );
51 }
52 }
53 }
54 
55 
56 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
57 
59 (
60  const word& name,
61  const dictionary& dict,
62  const rigidBodyModel& model
63 )
64 :
65  restraint(name, dict, model),
66  externalForce_(nullptr),
67  location_(Zero)
68 {
69  read(dict);
70 }
71 
72 
73 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
74 
76 {}
77 
78 
79 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
80 
82 (
83  scalarField& tau,
85  const rigidBodyModelState& state
86 ) const
87 {
88  const vector force = externalForce_().value(state.t());
89  const vector moment(location_ ^ force);
90 
91  if (model_.debug)
92  {
93  Info<< " location " << location_
94  << " force " << force
95  << " moment " << moment
96  << endl;
97  }
98 
99  // Accumulate the force for the restrained body
100  fx[bodyIndex_] += spatialVector(moment, force);
101 }
102 
103 
105 (
106  const dictionary& dict
107 )
108 {
110 
111  coeffs_.readEntry("location", location_);
112 
113  externalForce_ = Function1<vector>::New("force", coeffs_);
114 
115  return true;
116 }
117 
118 
120 (
121  Ostream& os
122 ) const
123 {
124  restraint::write(os);
125 
126  os.writeEntry("location", location_);
127 
128  externalForce_().writeData(os);
129 }
130 
131 
132 // ************************************************************************* //
Foam::RBD::restraints::addToRunTimeSelectionTable
addToRunTimeSelectionTable(restraint, externalForce, dictionary)
Foam::RBD::restraints::defineTypeNameAndDebug
defineTypeNameAndDebug(externalForce, 0)
Foam::RBD::rigidBodyModelState
Holds the motion state of rigid-body model.
Definition: rigidBodyModelState.H:67
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::RBD::restraints::externalForce::read
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
Definition: externalForce.C:105
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:86
rigidBodyModel.H
Foam::RBD::rigidBodyModelState::t
scalar t() const
Return access to the time.
Definition: rigidBodyModelStateI.H:48
Foam::Field< scalar >
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::RBD::restraint::read
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
Definition: rigidBodyRestraint.C:74
Foam::RBD::restraints::externalForce::~externalForce
virtual ~externalForce()
Destructor.
Definition: externalForce.C:75
Foam::blockMeshTools::read
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:33
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::RBD::rigidBodyModel
Basic rigid-body model representing a system of rigid-bodies connected by 1-6 DoF joints.
Definition: rigidBodyModel.H:83
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::RBD::restraints::externalForce::restrain
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:82
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
rigidBodyModelState.H
Foam::RBD::restraints::externalForce
Time-dependent external force restraint using Function1.
Definition: externalForce.H:73
Foam::RBD::restraints::externalForce::externalForce
externalForce(const word &name, const dictionary &dict, const rigidBodyModel &model)
Construct from components.
Definition: externalForce.C:59
Foam::Vector< scalar >
OneConstant.H
Foam::RBD::restraint::write
virtual void write(Ostream &) const =0
Write.
Definition: rigidBodyRestraint.C:81
Foam::RBD::restraints::externalForce::write
virtual void write(Ostream &) const
Write.
Definition: externalForce.C:120
Foam::RBD::restraint
Base class for defining restraints for rigid-body dynamics.
Definition: rigidBodyRestraint.H:68
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:232
externalForce.H
Foam::spatialVector
SpatialVector< scalar > spatialVector
SpatialVector of scalars.
Definition: spatialVector.H:50
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56