interpolatingSolidBodyMotionSolver.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) 2018-2019 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 
28 #include "pointPatchDist.H"
29 #include "pointConstraints.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(interpolatingSolidBodyMotionSolver, 0);
36 
38  (
39  motionSolver,
40  interpolatingSolidBodyMotionSolver,
41  dictionary
42  );
43 }
44 
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
49 (
50  const polyMesh& mesh,
51  const dictionary& dict
52 )
53 :
54  points0MotionSolver(mesh, dict, typeName),
55  SBMFPtr_(solidBodyMotionFunction::New(coeffDict(), mesh.time())),
56  patches_(wordReList(coeffDict().lookup("patches"))),
57  patchSet_(mesh.boundaryMesh().patchSet(patches_)),
58  CofG_(coeffDict().lookup("CofG")),
59  di_(readScalar(coeffDict().lookup("innerDistance"))),
60  do_(readScalar(coeffDict().lookup("outerDistance"))),
61  scale_
62  (
63  IOobject
64  (
65  "motionScale",
66  mesh.time().timeName(),
67  mesh,
70  false
71  ),
72  pointMesh::New(mesh),
74  )
75 {
76  // Calculate scaling factor everywhere
77 
78  {
79  const pointMesh& pMesh = pointMesh::New(mesh);
80 
81  pointPatchDist pDist(pMesh, patchSet_, points0());
82 
83  // Scaling: 1 up to di then linear down to 0 at do away from patches
84  scale_.primitiveFieldRef() =
85  min
86  (
87  max
88  (
89  (do_ - pDist.primitiveField())/(do_ - di_),
90  scalar(0)
91  ),
92  scalar(1)
93  );
94 
95  // Convert the scale function to a cosine
96  scale_.primitiveFieldRef() =
97  min
98  (
99  max
100  (
101  0.5
102  - 0.5
103  *cos(scale_.primitiveField()
105  scalar(0)
106  ),
107  scalar(1)
108  );
109 
110  pointConstraints::New(pMesh).constrain(scale_);
111  scale_.write();
112  }
113 }
114 
115 
116 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
117 
119 {}
120 
121 
122 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
123 
126 {
127  const pointField& points0 = this->points0();
128  const septernion s = SBMFPtr_().transformation();
129 
130  tmp<pointField> tpoints(new pointField(points0));
131  pointField& points = tpoints.ref();
132 
133  forAll(points, pointi)
134  {
135  // Move non-stationary points
136  if (scale_[pointi] > small)
137  {
138  // Use solid-body motion where scale = 1
139  if (scale_[pointi] > 1 - small)
140  {
141  points[pointi] =
142  CofG_ + s.transformPoint(points0[pointi] - CofG_);
143  }
144  // Slerp septernion interpolation
145  else
146  {
147  const septernion ss(slerp(septernion::I, s, scale_[pointi]));
148 
149  points[pointi] =
150  CofG_ + ss.transformPoint(points0[pointi] - CofG_);
151  }
152  }
153  }
154 
155  return tpoints;
156 }
157 
158 
159 // ************************************************************************* //
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:434
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
interpolatingSolidBodyMotionSolver(const polyMesh &, const dictionary &dict)
Construct from polyMesh and dictionary.
const Internal::FieldType & primitiveField() const
Return a const-reference to the internal field.
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:626
Septernion class used to perform translations and rotations in 3D space.
Definition: septernion.H:65
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool usePatchGroups=true) const
Return the set of patch IDs corresponding to the given names.
Macros for easy insertion into run-time selection tables.
static const pointMesh & New(const polyMesh &mesh)
Definition: MeshObject.C:44
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:48
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
stressControl lookup("compactNormalStress") >> compactNormalStress
dynamicFvMesh & mesh
dimensionedScalar cos(const dimensionedScalar &ds)
const pointField & points
static autoPtr< solidBodyMotionFunction > New(const dictionary &SBMFCoeffs, const Time &runTime)
Select constructed from the SBMFCoeffs dictionary and Time.
Calculation of distance to nearest patch for all points.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:68
static const septernion I
Definition: septernion.H:83
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
const Time & time() const
Return time.
defineTypeNameAndDebug(combustionModel, 0)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
virtual tmp< pointField > curPoints() const
Return point location obtained from the current motion field.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Virtual base class for displacement motion solvers.
quaternion slerp(const quaternion &qa, const quaternion &qb, const scalar t)
Spherical linear interpolation of quaternions.
Definition: quaternion.C:55
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
List< wordRe > wordReList
A List of wordRe (word or regular expression)
Definition: wordReList.H:50
A class for managing temporary objects.
Definition: PtrList.H:53
vector transformPoint(const vector &v) const
Transform the given coordinate point.
Definition: septernionI.H:82
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
void constrain(GeometricField< Type, pointPatchField, pointMesh > &pf, const bool overrideValue=false) const
Apply boundary conditions (single-patch constraints) and.
Namespace for OpenFOAM.