CrankNicolson.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 | Copyright (C) 2016 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 "CrankNicolson.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 namespace RBD
34 {
35 namespace rigidBodySolvers
36 {
39 }
40 }
41 }
42 
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
47 (
48  rigidBodyMotion& body,
49  const dictionary& dict
50 )
51 :
52  rigidBodySolver(body),
53  aoc_(dict.lookupOrDefault<scalar>("aoc", 0.5)),
54  voc_(dict.lookupOrDefault<scalar>("voc", 0.5))
55 {}
56 
57 
58 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
59 
61 {}
62 
63 
64 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
65 
67 (
68  const scalarField& tau,
69  const Field<spatialVector>& fx
70 )
71 {
72  // Accumulate the restraint forces
73  scalarField rtau(tau);
74  Field<spatialVector> rfx(fx);
75  model_.applyRestraints(rtau, rfx);
76 
77  // Calculate the accelerations for the given state and forces
78  model_.forwardDynamics(state(), rtau, rfx);
79 
80  // Correct velocity
81  qDot() = qDot0() + deltaT()*(aoc_*qDdot() + (1 - aoc_)*qDdot0());
82 
83  // Correct position
84  q() = q0() + deltaT()*(voc_*qDot() + (1 - voc_)*qDot0());
85 
86  correctQuaternionJoints();
87 }
88 
89 
90 // ************************************************************************* //
addToRunTimeSelectionTable(rigidBodySolver, CrankNicolson, dictionary)
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
defineTypeNameAndDebug(CrankNicolson, 0)
Crank-Nicolson 2nd-order time-integrator for 6DoF solid-body motion.
Definition: CrankNicolson.H:71
CrankNicolson(rigidBodyMotion &body, const dictionary &dict)
Construct for the given body from dictionary.
Definition: CrankNicolson.C:47
Macros for easy insertion into run-time selection tables.
Six degree of freedom motion for a rigid body.
virtual void solve(const scalarField &tau, const Field< spatialVector > &fx)
Integrate the rigid-body motion for one time-step.
Definition: CrankNicolson.C:67
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Namespace for OpenFOAM.