cuboid.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) 2016-2026 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 "cuboid.H"
27 #include "primitiveFields.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace RBD
35 {
38 }
39 }
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
45 {
46  return autoPtr<rigidBody>(new cuboid(*this));
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
51 
53 {}
54 
55 
56 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
57 
59 (
60  const direction axis,
61  const scalarField& distances
62 ) const
63 {
64  tmp<scalarField> tResult
65  (
66  new scalarField(distances.size() - 1, scalar(0))
67  );
68  scalarField& result = tResult.ref();
69 
70  const scalar rho = m()/cmptProduct(L_);
71  const vector pMin = c() - L_/2;
72  const vector pMax = c() + L_/2;
73 
74  forAll(result, i)
75  {
76  vector p0 = pMin, p1 = pMax;
77  p0[axis] = min(max(distances[i], pMin[axis]), pMax[axis]);
78  p1[axis] = min(max(distances[i + 1], pMin[axis]), pMax[axis]);
79 
80  result[i] = cmptProduct(p1 - p0)*rho;
81  }
82 
83  return tResult;
84 }
85 
86 
88 (
89  const direction axis,
90  const scalarField& distances
91 ) const
92 {
93  tmp<vectorField> tResult
94  (
95  new vectorField(distances.size() - 1, vector::zero)
96  );
97  vectorField& result = tResult.ref();
98 
99  const scalar rho = m()/cmptProduct(L_);
100  const vector pMin = c() - L_/2;
101  const vector pMax = c() + L_/2;
102 
103  forAll(result, i)
104  {
105  vector p0 = pMin, p1 = pMax;
106  p0[axis] = min(max(distances[i], pMin[axis]), pMax[axis]);
107  p1[axis] = min(max(distances[i + 1], pMin[axis]), pMax[axis]);
108 
109  result[i] = cmptProduct(p1 - p0)*rho*(p0 + p1)/2;
110  }
111 
112  return tResult;
113 }
114 
115 
117 (
118  const direction axis,
119  const scalarField& distances
120 ) const
121 {
122  tmp<symmTensorField> tResult
123  (
124  new symmTensorField(distances.size() - 1, symmTensor::zero)
125  );
126  symmTensorField& result = tResult.ref();
127 
128  const scalar rho = m()/cmptProduct(L_);
129  const vector pMin = c() - L_/2;
130  const vector pMax = c() + L_/2;
131 
132  forAll(result, i)
133  {
134  vector p0 = pMin, p1 = pMax;
135  p0[axis] = min(max(distances[i], pMin[axis]), pMax[axis]);
136  p1[axis] = min(max(distances[i + 1], pMin[axis]), pMax[axis]);
137 
138  const vector d1 = p1 - p0;
139  const vector d2 =
140  (
141  cmptMultiply(p1, p1)
142  - cmptMultiply(p0, p0)
143  )/2;
144  const vector d3 =
145  (
146  cmptMultiply(p1, cmptMultiply(p1, p1))
147  - cmptMultiply(p0, cmptMultiply(p0, p0))
148  )/3;
149 
150  result[i].xx() = d3.x()*d1.y()*d1.z()*rho;
151  result[i].xy() = d2.x()*d2.y()*d1.z()*rho;
152  result[i].xz() = d2.x()*d1.y()*d2.z()*rho;
153  result[i].yy() = d1.x()*d3.y()*d1.z()*rho;
154  result[i].yz() = d1.x()*d2.y()*d2.z()*rho;
155  result[i].zz() = d1.x()*d1.y()*d3.z()*rho;
156  }
157 
158  return tResult;
159 }
160 
161 
163 {
164  writeEntry(os, "type", type());
165 
166  writeEntry(os, "mass", m());
167 
168  writeEntry(os, "L", L());
169 }
170 
171 
172 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Specialisation of rigidBody to construct a cuboid given the mass and lengths of the sides.
Definition: cuboid.H:55
virtual tmp< vectorField > sectionMu1s(const direction axis, const scalarField &distances) const
Return the first moments of the sections of the body between.
Definition: cuboid.C:88
virtual void write(Ostream &) const
Write.
Definition: cuboid.C:162
virtual ~cuboid()
Destructor.
Definition: cuboid.C:52
virtual tmp< symmTensorField > sectionMu2s(const direction axis, const scalarField &distances) const
Return the second moments of the sections of the body between.
Definition: cuboid.C:117
virtual autoPtr< rigidBody > clone() const
Return clone of this cuboid.
Definition: cuboid.C:44
cuboid(const word &name, const scalar m, const vector &c, const vector &L)
Construct from name, mass, centre of mass and lengths of the sides.
Definition: cuboidI.H:51
virtual tmp< scalarField > sectionMu0s(const direction axis, const scalarField &distances) const
Return the zeroth moments of the sections of the body between.
Definition: cuboid.C:59
static const Form zero
Definition: VectorSpace.H:118
const Cmpt & z() const
Definition: VectorI.H:87
const Cmpt & y() const
Definition: VectorI.H:81
const Cmpt & x() const
Definition: VectorI.H:75
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
rho
Definition: pEqn.H:1
addToRunTimeSelectionTable(rigidBody, cuboid, dictionary)
defineTypeNameAndDebug(cuboid, 0)
const dimensionedScalar c
Speed of light in a vacuum.
Namespace for OpenFOAM.
tmp< DimensionedField< Type, GeoMesh, Field > > cmptMultiply(const DimensionedField< Type, GeoMesh, PrimitiveField1 > &df1, const DimensionedField< Type, GeoMesh, PrimitiveField2 > &df2)
Cmpt cmptProduct(const VectorSpace< Form, Cmpt, Ncmpts > &vs)
Definition: VectorSpaceI.H:528
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensioned< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
Field< vector > vectorField
Specialisation of Field<T> for vector.
Field< symmTensor > symmTensorField
Specialisation of Field<T> for symmTensor.
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
uint8_t direction
Definition: direction.H:45
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
Specialisations of Field<T> for scalar, vector and tensor.