49 int main(
int argc,
char *argv[])
55 "Calculates the inertia tensor and principal axes and moments "
56 "of the specified surface.\n"
57 "Inertia can either be of the solid body or of a thin shell."
64 "inertia of a thin shell"
72 "kg/m3 for solid properties, kg/m2 for shell properties"
79 "Inertia relative to this point, not the centre of mass"
108 <<
"Negative mass detected, the surface may be inside-out." <<
endl;
114 bool showTransform =
true;
118 (
mag(eVec.
x() ^ eVec.
y()) > (1.0 - small))
119 && (
mag(eVec.
y() ^ eVec.
z()) > (1.0 - small))
120 && (
mag(eVec.
z() ^ eVec.
x()) > (1.0 - small))
128 eVec.
z() *
sign((eVec.
x() ^ eVec.
y()) & eVec.
z())
137 cartesian[0] =
vector(1, 0, 0);
138 cartesian[1] =
vector(0, 1, 0);
139 cartesian[2] =
vector(0, 0, 1);
145 principal[0] = eVec.
x();
146 principal[1] = eVec.
y();
147 principal[2] = eVec.
z();
149 scalar maxMagDotProduct = -great;
159 scalar magDotProduct =
mag(cartesian[cI] & principal[pI]);
161 if (magDotProduct > maxMagDotProduct)
163 maxMagDotProduct = magDotProduct;
172 cartesian[match.first()] & principal[match.second()]
182 tPrincipal[match.second()] *= -1;
184 tPrincipal[(match.second() + 1) % 3] =
185 principal[(match.second() + 2) % 3];
187 tPrincipal[(match.second() + 2) % 3] =
188 principal[(match.second() + 1) % 3];
190 principal = tPrincipal;
193 tEVal[(match.second() + 1) % 3] = eVal[(match.second() + 2) % 3];
194 tEVal[(match.second() + 2) % 3] = eVal[(match.second() + 1) % 3];
199 label permutationDelta = match.second() - match.first();
201 if (permutationDelta != 0)
205 permutationDelta += 3;
210 for (
label i = 0; i < 3; i++)
212 tPrincipal[i] = principal[(i + permutationDelta) % 3];
213 tEVal[i] = eVal[(i + permutationDelta) % 3];
216 principal = tPrincipal;
220 label matchedAlready = match.first();
224 maxMagDotProduct = -great;
228 if (cI == matchedAlready)
235 if (pI == matchedAlready)
240 scalar magDotProduct =
mag(cartesian[cI] & principal[pI]);
242 if (magDotProduct > maxMagDotProduct)
244 maxMagDotProduct = magDotProduct;
254 cartesian[match.first()] & principal[match.second()]
257 if (sense < 0 || (match.second() - match.first()) != 0)
259 principal[match.second()] *= -1;
263 tPrincipal[(matchedAlready + 1) % 3] =
264 principal[(matchedAlready + 2) % 3]*-sense;
266 tPrincipal[(matchedAlready + 2) % 3] =
267 principal[(matchedAlready + 1) % 3]*-sense;
269 principal = tPrincipal;
272 tEVal[(matchedAlready + 1) % 3] = eVal[(matchedAlready + 2) % 3];
273 tEVal[(matchedAlready + 2) % 3] = eVal[(matchedAlready + 1) % 3];
278 eVec =
tensor(principal[0], principal[1], principal[2]);
283 <<
"Non-unique eigenvectors, cannot compute transformation "
284 <<
"from Cartesian axes" <<
endl;
286 showTransform =
false;
291 scalar surfaceArea = 0;
297 if (
f[0] ==
f[1] ||
f[0] ==
f[2] ||
f[1] ==
f[2])
300 <<
"Illegal triangle " << facei <<
" vertices " <<
f
301 <<
" coords " <<
f.points(surf.points()) <<
endl;
315 <<
"Density: " << density <<
nl
316 <<
"Mass: " << m <<
nl
317 <<
"Centre of mass: " << cM <<
nl
318 <<
"Surface area: " << surfaceArea <<
nl
319 <<
"Inertia tensor around centre of mass: " <<
nl << J <<
nl
320 <<
"eigenValues (principal moments): " << eVal <<
nl
321 <<
"eigenVectors (principal axes): " <<
nl
322 << eVec.
x() <<
nl << eVec.
y() <<
nl << eVec.
z() <<
endl;
326 Info<<
"Transform tensor from reference state (orientation):" <<
nl
328 <<
"Rotation tensor required to transform "
329 "from the body reference frame to the global "
330 "reference frame, i.e.:" <<
nl
331 <<
"globalVector = orientation & bodyLocalVector"
335 <<
"Entries for sixDoFRigidBodyDisplacement boundary condition:"
346 Info<<
nl <<
"Inertia tensor relative to " << refPt <<
": " <<
nl
353 Info<<
nl <<
"Writing scaled principal axes at centre of mass of "
354 << surfFileName <<
" to " << str.
name() <<
endl;
363 for (
label i = 1; i < 4; i++)
365 str <<
"l " << 1 <<
' ' << i + 1 <<
endl;
Istream and Ostream manipulators taking arguments.
Various functions to operate on Lists.
#define forAll(list, i)
Loop across all elements in list.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Tensor< Cmpt > T() const
Return transpose.
const Cmpt & component(const direction) const
Extract command arguments and options from the supplied argc and argv parameters.
static void addOption(const word &opt, const string ¶m="", const string &usage="")
Add to an option to validOptions with usage information.
static void addNote(const string &)
Add extra notes for the usage information.
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
bool optionFound(const word &opt) const
Return true if the named option is found.
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
static SLList< string > validArgs
A list of valid (mandatory) arguments.
T optionLookupOrDefault(const word &opt, const T &deflt) const
Read a value from the named option if present.
A class for handling file names.
word name() const
Return file name (part beyond last /)
Triangle with additional region number.
static void massPropertiesSolid(const pointField &pts, const triFaceList &triFaces, scalar density, scalar &mass, vector &cM, symmTensor &J)
static tensor applyParallelAxisTheorem(scalar mass, const vector &cM, const symmTensor &J, const vector &refPt)
static void massPropertiesShell(const pointField &pts, const triFaceList &triFaces, scalar density, scalar &mass, vector &cM, symmTensor &J)
Triangulated surface description with patch information.
int main(int argc, char *argv[])
#define WarningInFunction
Report a warning using Foam::Warning.
Omanip< int > setprecision(const int i)
dimensionedScalar sign(const dimensionedScalar &ds)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Tensor< scalar > tensor
Tensor of scalars.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void eigenValues(LagrangianPatchField< vector > &f, const LagrangianPatchField< tensor > &f1)
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
Vector< scalar > vector
A scalar version of the templated Vector.
void eigenVectors(LagrangianPatchField< tensor > &f, const LagrangianPatchField< tensor > &f1)
label findMin(const ListType &, const label start=0)
Find index of min element (and less than given element).
triangle< point, const point & > triPointRef
Foam::argList args(argc, argv)