softWall.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 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "softWall.H"
29 #include "rigidBodyModel.H"
31 #include "Time.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace RBD
38 {
39 namespace restraints
40 {
41  defineTypeNameAndDebug(softWall, 0);
42 
44  (
45  restraint,
46  softWall,
47  dictionary
48  );
49 }
50 }
51 }
52 
53 
54 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55 
57 (
58  const word& name,
59  const dictionary& dict,
60  const rigidBodyModel& model
61 )
62 :
63  restraint(name, dict, model)
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 
85  point p = bodyPoint(refAttachmentPt_);
86 
87  // Current axis of the spring
88  vector r = p - anchor_;
89 
90  vector force = vector::zero;
91  vector moment = vector::zero;
92 
93  vector v = bodyPointVelocity(refAttachmentPt_).l();
94 
95  scalar m = model_.bodies()[bodyID_].m();
96 
97  scalar d = (wallNormal_/mag(wallNormal_)) & r;
98 
99  vector rDir = r/(mag(r) + VSMALL);
100 
101  scalar wn = 3.14/C_;
102  scalar damping = psi_*2*m*wn;
103  scalar stiffness = sqr(wn)*m;
104 
105  if (d < 0)
106  {
107  force =
108  (-damping*(rDir & v) + stiffness*d)*rDir;
109 
110  moment = (p ^ force);
111  }
112 
113  if (model_.debug)
114  {
115  Info<< " stiffness :" << stiffness*d << nl
116  << " damping :" << -damping*mag(rDir & v) << nl
117  << " force : " << force << nl
118  << " d : " << d << nl
119  << " r : " << r << nl
120  << " p : " << p << nl
121  << " velocity : " << v
122  << endl;
123  }
124 
125  // Accumulate the force for the restrained body
126  fx[bodyIndex_] += spatialVector(moment, force);
127 }
128 
129 
131 (
132  const dictionary& dict
133 )
134 {
136 
137  coeffs_.readEntry("anchor", anchor_);
138  coeffs_.readEntry("refAttachmentPt", refAttachmentPt_);
139  coeffs_.readEntry("psi", psi_);
140  coeffs_.readEntry("C", C_);
141  coeffs_.readEntry("wallNormal", wallNormal_);
142 
143  return true;
144 }
145 
146 
148 (
149  Ostream& os
150 ) const
151 {
153 
154  os.writeEntry("anchor", anchor_);
155  os.writeEntry("refAttachmentPt", refAttachmentPt_);
156  os.writeEntry("psi", psi_);
157  os.writeEntry("C", C_);
158  os.writeEntry("wallNormal", wallNormal_);
159 
160 }
161 
162 
163 // ************************************************************************* //
Foam::RBD::restraints::addToRunTimeSelectionTable
addToRunTimeSelectionTable(restraint, externalForce, dictionary)
p
volScalarField & p
Definition: createFieldRefs.H:8
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:65
Foam::RBD::restraints::softWall::read
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
Definition: softWall.C:131
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::RBD::restraints::softWall::~softWall
virtual ~softWall()
Destructor.
Definition: softWall.C:71
rigidBodyModel.H
Foam::RBD::restraints::softWall::write
virtual void write(Ostream &) const
Write.
Definition: softWall.C:148
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
Foam::Field< scalar >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::RBD::restraint::read
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
Definition: rigidBodyRestraint.C:74
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:123
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::RBD::restraints::softWall::softWall
softWall(const word &name, const dictionary &dict, const rigidBodyModel &model)
Construct from components.
Definition: softWall.C:57
Time.H
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::Vector< scalar >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::RBD::restraint::write
virtual void write(Ostream &) const =0
Write.
Definition: rigidBodyRestraint.C:81
Foam::RBD::restraint
Base class for defining restraints for rigid-body dynamics.
Definition: rigidBodyRestraint.H:68
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::VectorSpace< Vector< scalar >, scalar, 3 >::zero
static const Vector< scalar > zero
Definition: VectorSpace.H:115
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
Foam::RBD::restraints::softWall::restrain
virtual void restrain(scalarField &tau, Field< spatialVector > &fx, const rigidBodyModelState &state) const
Accumulate the restraint internal joint forces into the tau field and.
Definition: softWall.C:78
softWall.H